Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
- Write machine-readable results to standard output and concise diagnostics to standard error where practical.
- Add tests for numerical rules, invalid input, missing values, non-positive values, and exported files.
- Do not claim the skill is research-ready until scientific fixtures and end-to-end tests pass.
- Keep GeoSkills v1 limited to REE pattern plots; do not add other geochemical diagram types before a versioned scope change.
- Preserve the published v0.1.0 REE workflow. GeoSkills v0.2.0 may add only trace-element spider diagrams; defer TAS, Harker, and other diagram families to later reviewed versions.
33 changes: 25 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,26 @@

GeoSkills 是一个面向地质学与地球化学研究的本地 Agent Skill。

**v1 只做一件事:生成球粒陨石标准化的稀土元素(REE配分图。**
蛛网图、TAS、Harker 图和其他地球化学图解不属于第一个版本
公开的 v0.1.0 只提供球粒陨石标准化 REE 配分图。
`feature/spider-diagram-v0.2` 分支是已完成人工审核的 v0.2.0 发布候选版:保留 REE,并新增原始地幔或 N-MORB 标准化微量元素蛛网图。TAS、Harker 和其他图解仍不在本版本范围内

## v1 可以做什么
## 当前可以做什么

- 读取 `.csv`、逗号或制表符分隔的 `.txt`、以及 `.xlsx`;
- 识别常见的“每行一个样品”表格;
- 在结构明确时,自动转换论文补充材料常见的“样品在列、元素在行”表格;
- 检查样品编号、ppm 单位、缺失值、低于检出限、非数字、零和负数;
- 使用 Sun & McDonough(1989)C1 球粒陨石值标准化 La–Lu;
- 生成投稿尺寸的 REE 配分图,并输出 SVG、PDF、600 dpi TIFF、600 dpi PNG;
- 使用 Sun & McDonough(1989)原始地幔、脚注明确修改的原始地幔或 N-MORB 值生成微量元素蛛网图;
- 对明确标为 wt% 的 `K2O`、`P2O5`、`TiO2` 作可追溯的元素 ppm 换算;
- 生成投稿尺寸的 REE 配分图或蛛网图,并输出 SVG、PDF、600 dpi TIFF、600 dpi PNG;
- 同步输出实际绘图数据 CSV 和机器可读的 JSON 运行报告;
- 可选择完整四边框,以及经过碰撞检查的图内图例;
- 全程在本地处理数据,绘图脚本不请求网络服务。

## 安装到 Codex

可在 Codex 中让 `$skill-installer` 从以下仓库安装 `skills/geoskills`
以下公开仓库的默认分支目前仍是经过审核的 v0.1.0 REE 版本;v0.2.0 蛛网图发布候选版通过功能分支和 Pull Request 接受合并检查

```text
https://github.com/gronbow/GeoSkills
Expand Down Expand Up @@ -58,6 +60,20 @@ py -m venv .venv
.\.venv\Scripts\python.exe skills\geoskills\scripts\plot_ree.py skills\geoskills\examples\synthetic_ree_data.csv --output-dir outputs\ree_figure --axes-frame full --legend-layout inside-auto
```

检查蛛网图示例数据:

```powershell
.\.venv\Scripts\python.exe skills\geoskills\scripts\inspect_spider_data.py skills\geoskills\examples\synthetic_spider_data.csv
```

生成原始地幔标准化蛛网图:

```powershell
.\.venv\Scripts\python.exe skills\geoskills\scripts\plot_spider.py skills\geoskills\examples\synthetic_spider_data.csv --reference pm-sm89-modified --output-dir outputs\spider_figure
```

默认方案为原文脚注推荐的 `pm-sm89-modified`;也可以明确选择 Table 1 印刷版 `pm-sm89` 或 `nmorb-sm89`。程序不会根据曲线形状替用户猜测标准化方案。

程序不会修改原始表格。重复使用同一输出名称时,只有显式加入 `--overwrite` 才会替换已有结果。

## 项目结构
Expand All @@ -80,15 +96,16 @@ GeoSkills/

## 科学与隐私边界

- 当前仅接受明确为 ppm 的 REE 浓度;不会静默换算 wt% 或 ppb
- 缺失值保留为曲线断点;零和负数会阻止对数坐标绘图。
- 直接元素浓度必须明确为 ppm;只有 `K2O`、`P2O5`、`TiO2` 可在明确为 wt% 时换算
- 缺失值和低于检出限状态保留为曲线断点;零和负数会阻止对数坐标绘图。
- 标准化表包含文献、DOI、表格位置、版本和核对记录。
- 原始地幔表保留文献 Table 1 的 Cs、Pb 数值,并明确提示原文脚注中的 modified 版本;程序不会静默混用。
- 图形可以展示富集程度、斜率和平行性,但不能单独证明岩浆源区、部分熔融、分离结晶或构造环境。
- `local_data/` 和 `outputs/` 已排除在 Git 之外;不要提交私人或未发表数据。

## 当前状态

GeoSkills v0.1.0 是仅包含 REE 配分图功能的公开测试版。当前版本已通过 23 项自动测试、真实论文数据端到端测试、投稿导出检查和 Git 历史隐私审计;正式投稿前仍应由研究者核对数据列、单位、标准化方案和最终图件
GeoSkills v0.1.0 是仅包含 REE 配分图的公开测试版。v0.2.0 蛛网图发布候选版已通过全部 41 项自动测试、真实数据测试、导出审计和人工图形复核;远端 CI 与 Pull Request 合并完成后再作为稳定版本发布

## 许可

Expand Down
85 changes: 54 additions & 31 deletions skills/geoskills/SKILL.md
Original file line number Diff line number Diff line change
@@ -1,49 +1,72 @@
---
name: geoskills
description: "Inspect whole-rock geochemical tables and create validated, submission-ready chondrite-normalized rare-earth-element pattern plots from CSV, TXT, or Excel data. Use GeoSkills v1 only for REE pattern workflows: identify La-Lu columns, check ppm units and invalid values, group samples, generate publication REE diagrams, export editable SVG/PDF plus 600 dpi TIFF/PNG and source data, or explain why a geochemical table cannot yet be plotted safely. Do not use v1 for spider diagrams, TAS, Harker diagrams, or other geochemical plots."
description: "Inspect whole-rock geochemical tables and create validated, submission-oriented normalized element-pattern figures from CSV, TXT, or Excel data. Use GeoSkills for chondrite-normalized rare-earth-element patterns or primitive-mantle/N-MORB-normalized trace-element spider diagrams: identify sample, group, element, and supported oxide columns; verify units and invalid values; apply versioned Sun and McDonough (1989) references; export editable SVG/PDF plus 600 dpi TIFF/PNG and source data; or explain why a table cannot yet be plotted safely. Do not use the current version for TAS, Harker, isotope, discrimination, or other geochemical diagrams."
---

# GeoSkills v1: REE Patterns
# GeoSkills v0.2.0 release candidate

Create reproducible REE pattern plots through a deterministic local Python workflow. Keep data processing and normalization in scripts; do not ask a language model to calculate normalized values directly.
Create reproducible REE patterns and trace-element spider diagrams through deterministic local Python scripts. Use the language model to select and explain the workflow, never to calculate normalized ratios manually.

## Development status

Treat GeoSkills v1 as an REE-only functional beta with a publication-oriented export workflow. Do not add or imply spider diagrams, TAS, Harker diagrams, or other plot types in v1. The environment checker, read-only table inspector, confirmed `Chondrite_SM89` reference, normalization command, plotting command, and automated export tests exist. Both flat tables and unambiguous transposed paper supplements are supported. Continue to report caveats and inspect every generated figure visually at its final physical size before submission.
Treat v0.1.0 REE plotting as the stable published baseline. The v0.2.0 spider workflow is a reviewed release candidate: its scientific fixtures, real-data output, export QA, Skill validation, and user review have passed. Do not imply support for TAS, Harker, isotope, or discrimination diagrams.

## Workflow
## Route the request

1. Run `scripts/check_environment.py` with the Python interpreter that will execute the plotting workflow.
2. Run `scripts/inspect_data.py INPUT` to inspect the input file without modifying it. Allow the inspector to adapt an unambiguous elements-by-row paper supplement in memory. For a multi-sheet workbook, rerun it with `--sheet SHEET_NAME` after the user chooses a sheet.
3. Identify the worksheet, sample identifier, optional group column, REE columns, and units.
4. Stop and request clarification when units or column mappings are ambiguous.
5. Validate missing, non-numeric, zero, and negative values before logarithmic plotting.
6. Run `scripts/normalize_ree.py INPUT --output OUTPUT.csv` only after inspection passes. Use the named, versioned reference composition stored in `assets/`; do not copy values into prompts or recalculate them manually.
7. Run `scripts/plot_ree.py INPUT --output-dir OUTPUT_DIR` to generate editable SVG/PDF, 600 dpi LZW-compressed TIFF, 600 dpi PNG, normalized source-data CSV, and a JSON run report from the same figure object. The default `--y-margin 0.08` sets compact, data-led log-axis limits, then rounds them to clean powers or decimal boundaries without clipping data below or above unity. The publication default omits background gridlines; use `--grid-style major` only when a target journal or comparison needs them. Use `--axes-frame full --legend-layout inside-auto` when a four-sided plot frame and a boxed in-axes legend are required; the plotter checks for overlap and safely uses the right-side legend when no clear in-axes position exists.
8. Inspect the PNG or TIFF visually at the declared final size. Confirm readable text, unobstructed data, interpretable grayscale/symbol encoding, correct legend mapping, and that no empty log-scale decade has been retained only for a reference line.
9. Return the publication bundle with its configuration record, validation report, source data, and concise scientific caveats.
- For chondrite-normalized La–Lu patterns, use the REE workflow.
- For multi-element primitive-mantle or N-MORB-normalized patterns, use the spider workflow.
- Stop and clarify when the requested diagram, unit, reference composition, sample column, or group column is ambiguous.

## REE workflow

1. Run `scripts/check_environment.py`.
2. Run `scripts/inspect_data.py INPUT`.
3. Confirm the worksheet, sample identifier, optional group, ppm units, and REE mapping.
4. Run `scripts/normalize_ree.py INPUT --output OUTPUT.csv`.
5. Run `scripts/plot_ree.py INPUT --output-dir OUTPUT_DIR`.
6. Inspect the final-size PNG/TIFF and return the complete figure bundle.

Use `--axes-frame full --legend-layout inside-auto` when a four-sided frame and collision-checked in-axes legend are requested. The plotter safely falls back to an outside-right legend.

## Spider workflow

1. Run `scripts/check_environment.py`.
2. Run `scripts/inspect_spider_data.py INPUT`.
3. Confirm the worksheet, sample identifier, optional group, direct elemental ppm columns, and any supported oxide columns.
4. Choose `pm-sm89`, `pm-sm89-modified`, or `nmorb-sm89`; do not select a reference from the apparent shape of the data.
5. Run `scripts/normalize_spider.py INPUT --reference pm-sm89-modified --output OUTPUT.csv`.
6. Run `scripts/plot_spider.py INPUT --reference pm-sm89-modified --output-dir OUTPUT_DIR`.
7. Inspect the final-size PNG/TIFF, the normalized source-data CSV, conversion records, warnings, and JSON report.

The spider plot defaults to a full frame, no background grid, and `inside-auto` legend placement. It exports editable SVG/PDF, 600 dpi LZW TIFF, 600 dpi PNG, exact normalized source data, and a machine-readable report from the same figure object.

## Scientific guardrails

- Use the REE order `La, Ce, Pr, Nd, Sm, Eu, Gd, Tb, Dy, Ho, Er, Tm, Yb, Lu`; do not require Pm.
- Require concentration units to be known before normalization. The first release targets ppm input.
- Preserve missing values as gaps unless the user explicitly selects and records another policy.
- Reject zero and negative concentrations on a logarithmic axis; report affected samples and elements.
- Set log-axis limits from the finite positive normalized values, with an 8% default visual margin; use clean integer bounds at or above unity and clean decimal bounds below unity, never clip data, and do not retain an empty decade merely to display `y = 1`.
- Keep v1 limited to chondrite-normalized REE patterns. Route requests for other geochemical diagrams to a future version instead of fabricating unsupported boundaries or reference arrays.
- When a full axes frame or in-axes legend is requested, preserve the data hierarchy: show top and right spines without redundant ticks, place the legend only in a collision-free region, and fall back to a separate right-side key rather than cover data.
- Do not invent or silently substitute reference values.
- Describe visible patterns conservatively. Do not infer petrogenesis from an REE plot alone.
- Keep user data local by default and do not make network requests during plotting.
- Require confirmed ppm units for direct element concentrations.
- Convert only explicit `K2O`, `P2O5`, and `TiO2` wt% columns to K, P, and Ti ppm. Record the CIAAW/IUPAC atomic weights, formula, and factor used.
- Preserve blanks and below-detection-limit states as gaps. Never replace them with zero or an invented detection limit.
- Reject finite zero and negative values on logarithmic axes.
- Preserve the cited Sun and McDonough (1989) incompatibility order even when the user selects a subset.
- Use only the versioned local assets `PrimitiveMantle_SM89`, `PrimitiveMantleModified_SM89`, and `NMORB_SM89` for the spider draft.
- Use the source footnote's modified primitive mantle as the spider default. Keep the printed and modified variants separate; do not silently replace Cs or Pb, and warn when an affected element is plotted with the printed variant.
- Set log limits from finite positive ratios, add a declared margin, round to clean decimal bounds without clipping, and show unity only when it lies inside the range.
- Use colour plus line style for groups and sample symbols so colour is not the sole identifier.
- Keep user data local; plotting scripts must not make network requests.
- Describe enrichment, depletion, slopes, and visible anomalies conservatively. Do not assign a unique source, melting process, mineral control, alteration history, or tectonic setting from one normalized pattern.

## Related resources

| Resource | Use it when |
|---|---|
| [scripts/check_environment.py](scripts/check_environment.py) | Check whether the selected Python environment contains the required packages |
| [scripts/inspect_data.py](scripts/inspect_data.py) | Read CSV, TXT, or Excel input and produce a structured validation report |
| [scripts/normalize_ree.py](scripts/normalize_ree.py) | Normalize validated ppm concentrations and create a new ratio table |
| [scripts/plot_ree.py](scripts/plot_ree.py) | Generate the validated REE figure bundle and machine-readable run report |
| [assets/normalization/chondrite-sm89.json](assets/normalization/chondrite-sm89.json) | Audit the exact `Chondrite_SM89` values, source, units, and verification record |
| [references/data-contract.md](references/data-contract.md) | Inspect columns, identifiers, units, missing values, and input errors |
| [references/scientific-method.md](references/scientific-method.md) | Implement or audit normalization, element order, axes, and interpretation limits |
| [scripts/inspect_data.py](scripts/inspect_data.py) | Inspect REE input |
| [scripts/normalize_ree.py](scripts/normalize_ree.py) | Normalize REE to C1 chondrite |
| [scripts/plot_ree.py](scripts/plot_ree.py) | Create the REE figure bundle |
| [scripts/inspect_spider_data.py](scripts/inspect_spider_data.py) | Inspect trace elements, units, BDL states, and supported oxides |
| [scripts/normalize_spider.py](scripts/normalize_spider.py) | Normalize trace elements to primitive mantle or N-MORB |
| [scripts/plot_spider.py](scripts/plot_spider.py) | Create the spider-diagram figure bundle |
| [assets/normalization/primitive-mantle-sm89.json](assets/normalization/primitive-mantle-sm89.json) | Audit primitive-mantle values and the Cs/Pb footnote |
| [assets/normalization/primitive-mantle-modified-sm89.json](assets/normalization/primitive-mantle-modified-sm89.json) | Audit the explicit footnote-modified Cs/Pb variant |
| [assets/normalization/nmorb-sm89.json](assets/normalization/nmorb-sm89.json) | Audit N-MORB values |
| [references/data-contract.md](references/data-contract.md) | Audit the REE input contract |
| [references/scientific-method.md](references/scientific-method.md) | Audit the REE method |
| [references/spider-method.md](references/spider-method.md) | Audit spider input, normalization, conversion, plotting, and interpretation rules |
4 changes: 2 additions & 2 deletions skills/geoskills/agents/openai.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
interface:
display_name: "GeoSkills"
short_description: "Create submission-ready chondrite-normalized REE plots"
default_prompt: "Use $geoskills to inspect my geochemical table and create a submission-ready chondrite-normalized REE pattern figure bundle."
short_description: "Create validated REE and trace-element pattern plots"
default_prompt: "Use $geoskills to inspect my geochemical table and create a validated REE or trace-element spider-plot figure bundle."
136 changes: 136 additions & 0 deletions skills/geoskills/assets/normalization/nmorb-sm89.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
{
"schema_version": "1.0",
"id": "NMORB_SM89",
"display_name": "Sun & McDonough (1989) N-MORB",
"diagram_type": "trace_element_spider",
"unit": "ppm",
"element_order": [
"Cs",
"Tl",
"Rb",
"Ba",
"W",
"Th",
"U",
"Nb",
"Ta",
"K",
"La",
"Ce",
"Pb",
"Pr",
"Mo",
"Sr",
"P",
"Nd",
"F",
"Sm",
"Zr",
"Hf",
"Eu",
"Sn",
"Sb",
"Ti",
"Gd",
"Tb",
"Dy",
"Li",
"Y",
"Ho",
"Er",
"Tm",
"Yb",
"Lu"
],
"default_plot_order": [
"Rb",
"Ba",
"Th",
"U",
"Nb",
"Ta",
"K",
"La",
"Ce",
"Pb",
"Pr",
"Sr",
"P",
"Nd",
"Zr",
"Hf",
"Sm",
"Eu",
"Ti",
"Gd",
"Tb",
"Dy",
"Y",
"Ho",
"Er",
"Tm",
"Yb",
"Lu"
],
"values": {
"Cs": 0.007,
"Tl": 0.0014,
"Rb": 0.56,
"Ba": 6.3,
"W": 0.01,
"Th": 0.12,
"U": 0.047,
"Nb": 2.33,
"Ta": 0.132,
"K": 600,
"La": 2.5,
"Ce": 7.5,
"Pb": 0.3,
"Pr": 1.32,
"Mo": 0.31,
"Sr": 90,
"P": 510,
"Nd": 7.3,
"F": 210,
"Sm": 2.63,
"Zr": 74,
"Hf": 2.05,
"Eu": 1.02,
"Sn": 1.1,
"Sb": 0.01,
"Ti": 7600,
"Gd": 3.68,
"Tb": 0.67,
"Dy": 4.55,
"Li": 4.3,
"Y": 28,
"Ho": 1.01,
"Er": 2.97,
"Tm": 0.456,
"Yb": 3.05,
"Lu": 0.455
},
"source": {
"authors": "S.-s. Sun and W. F. McDonough",
"year": 1989,
"title": "Chemical and isotopic systematics of oceanic basalts: implications for mantle composition and processes",
"publication": "Geological Society, London, Special Publications 42, 313-345",
"doi": "10.1144/GSL.SP.1989.042.01.19",
"table": "Table 1, N-type MORB column",
"note": "The N-type MORB values in Table 1 are literature-survey estimates constrained by internal consistency of elemental ratios."
},
"crosscheck": {
"implementation": "pyrolite NMORB_SunMcDonough1989.csv",
"release": "v0.3.7",
"commit": "ab651b448ecd2ce1bc22d752b80a977a1f4dd1ca",
"url": "https://raw.githubusercontent.com/morganjwilliams/pyrolite/v0.3.7/pyrolite/data/geochem/refcomp/NMORB_SunMcDonough1989.csv"
},
"verification": {
"status": "confirmed",
"verified_on": "2026-07-28",
"methods": [
"transcribed against Sun and McDonough (1989), Table 1",
"cross-checked against pinned pyrolite v0.3.7 reference data"
]
}
}
Loading