B&S2026 model extraction and Figure 4
<skill name="extract-model" location="[REDACTED_LOCAL_PATH]">
References are relative to [REDACTED_LOCAL_PATH]
Extract Model
Use this skill to turn a scientific paper's mathematical model into a reproducible Python extraction workspace. Prioritize physical correctness, source traceability, auditability against the paper, and verification over performance or architectural polish.
The default output is a new uv-managed project directory, not a single module.
Core Principles
- Work in phases:
- Create the workspace, inspect/normalize sources, record source quality/provenance, and write an implementation specification.
- Pause for user review/clarification before implementing the model.
- Implement the model, tests, examples, and verification notebooks only after explicit approval.
- Do not implement model equations until the user explicitly confirms Phase 2.
- Prefer semantic source formats over PDFs.
- Treat PDF/OCR/math extraction as fallible; never silently trust corrupted equations, symbols, units, or tables.
- Preserve the paper's notation in code as closely as Python allows.
- Greek identifiers are fine and encouraged:
ρ,κ,Ω, etc. - Subscripts become underscores:
ρ_{ie}->ρ_ie. - Avoid unnecessarily long identifiers.
- Add ASCII aliases only at public API boundaries if genuinely helpful.
- Prefer literal, equation-by-equation reference implementations over vectorized or optimized code.
- Use comments and docstrings to map code back to paper equations, tables, sections, assumptions, and source/provenance entries.
- Never invent validation data or expected numerical results.
Default Project Layout
For a new extraction, create a uv project with a layout like:
<paper-model>/
pyproject.toml
README.md
sources/
original/ # user-provided PDF, saved HTML bundle, LaTeX/XML, supplements
extracted/
raw/ # generated/re-runnable extraction output
curated/ # manual corrections for ambiguous/corrupted items
provenance.yaml # structured source/provenance/confidence manifest
docs/
SOURCE_QUALITY.md
MODEL_EXTRACTION.md
src/<package>/
__init__.py
core.py # numeric, paper-faithful formulas
units.py # Pint-facing validation/conversion wrappers
constants.py # constants/parameters with source references
tests/
notebooks/
00_source_inspection.ipynb
01_reproduce_key_figures.ipynb
scripts/
inspect_html.py
extract_pdf_text.py
build_extraction_manifest.py
The exact package/project name should be derived from the paper/model and confirmed or chosen sensibly.
Default dependencies can be generous because this is an extraction/verification workspace, not the final production package. Include by default where useful:
numpyscipypandasxarraymatplotlibpintbeautifulsoup4lxmlhtml5libpypdfpyyamlpytestipykerneljupyterlab
External system tools may be used when available, but do not assume they are installed. Check first and document missing tools.
Phase 0: Intake, Workspace, and Source Normalization
0.1 Create the uv workspace
Create a new uv-managed project directory unless the user has already created one. Add the default source/docs/scripts/tests/notebooks layout.
Source-processing scripts are allowed before the Phase 2 pause because they support extraction and reproducibility. They should be safe to rerun. Do not overwrite curated/manual files without explicit confirmation.
0.2 Identify and register source material
Ask for or locate the best available source material. Prefer, in order:
- Semantic source formats:
- arXiv/source LaTeX
- publisher HTML saved locally, including supporting files
- JATS/XML or other publisher XML
- supplementary code/data/notebooks
- Born-digital PDF as visual ground truth and fallback text source.
- Scanned/image PDF with OCR only as a last resort.
- Pasted excerpts when no complete source is available.
If the paper is behind institutional access, ask the user to save the publisher HTML page locally, preferably as a complete webpage including supporting files. Do not bypass access controls or scrape authenticated/paywalled sites yourself.
0.3 Inspect semantic HTML/source quality
For saved HTML or publisher/source formats, inspect whether equations/tables/figures are available in useful semantic form. Use tools such as:
rgfor quick searches (MathJax,mathml,<math, equation labels, table markup)- Python with
beautifulsoup4,lxml, and/orhtml5lib pandocfor.tex,.md,.html,.docx, and similar non-PDF formats when helpful
Check and record:
- whether equations are MathML, embedded TeX/LaTeX, MathJax script data, SVG/images with alt text, or image-only;
- whether equation numbers and cross-references survived;
- whether tables, captions, section headings, and references survived;
- whether figures and supplementary data are present.
Publisher HTML with MathJax/MathML/embedded TeX is usually a better extraction source than PDF. HTML quality still varies; verify important equations against the rendered paper/PDF.
0.4 PDF extraction policy
Pandoc is not a PDF OCR or reliable PDF math-extraction tool. Do not require Pandoc for PDFs and do not recommend it as the PDF path.
For born-digital PDFs, check for pdftotext and try text extraction when useful:
pdftotext -layout paper.pdf sources/extracted/raw/paper.layout.txt
pdftotext -raw paper.pdf sources/extracted/raw/paper.raw.txt
pdftotext can be useful for prose but is only medium-good for math-heavy papers. Equations, symbols, subscripts, superscripts, and tables must be checked when they matter.
For scanned/image PDFs, OCR is a fallback only. Local tools such as ocrmypdf and tesseract can make prose searchable, but normal OCR is not trustworthy for mathematical notation.
For math-heavy PDFs, optional specialized tools may help, for example Mathpix, Nougat, Marker, or similar. Treat their output as draft transcription, not ground truth. Record tool, version/settings, and failures. Cloud/API tools require explicit user permission before uploading any document or snippet, especially for paywalled, institutional, unpublished, copyrighted, or sensitive material. Prefer local/offline tools by default.
0.5 Raw vs curated extracts
Use:
sources/extracted/raw/for generated, reproducible extraction output;sources/extracted/curated/for manual corrections of ambiguous, corrupted, or model-critical extracted material.
Do not require every equation/table to pass through curated files. The default workflow should continue end-to-end when extraction is clear enough. Use curated/manual correction for ambiguous or low-confidence items.
0.6 Source quality and provenance artifacts
Always create/update:
docs/SOURCE_QUALITY.mdsources/extracted/provenance.yaml
SOURCE_QUALITY.md should summarize:
- source files used;
- extraction tools and commands;
- HTML/PDF/OCR quality;
- equation/table/figure extraction quality;
- manual checks performed;
- known risks;
- whether cloud/API tools were used and what permission was given.
provenance.yaml should track, where applicable:
equations:
eq_12:
source: publisher_html
source_file: sources/original/paper.html
paper_location: section 3.2
extraction_method: MathJax TeX from saved HTML
used_extract: raw
manually_checked_against_rendered_source: true
confidence: high
notes: ""
tables:
table_1:
source: pdf
extraction_method: manual transcription
used_extract: curated
manually_checked_against_rendered_source: true
confidence: medium
figures:
figure_3:
data_available: false
reproduction_plan: digitize curve or request data
Use confidence gates:
high: semantic source, clear extraction, no material ambiguity -> proceed.medium: likely interpretation clear but minor formatting risk -> proceed, document risk.low: ambiguity affects implementation -> stop, ask the user, or create a curated correction TODO before implementing that item.blocked: missing/illegible/contradictory source -> stop.
Medium-confidence items may be implemented if visible in docs/provenance and flagged as verification risks. Low-confidence items block implementation unless the user explicitly approves a stated assumption.
Phase 1: Extraction Specification
Always write docs/MODEL_EXTRACTION.md before implementation.
The phase-1 spec must include:
- Paper/source citation
- title, authors, year if available
- source file/path/URL if available
- Source quality summary
- brief summary from
SOURCE_QUALITY.md - which source is considered primary for equations/tables
- known extraction risks
- Implementation goal
- what model or submodel will be implemented
- intended inputs and outputs
- Domain of validity and assumptions
- assumptions stated by the paper
- assumptions inferred from implementation needs, clearly labeled
- Unit strategy
- canonical units expected by the numeric core
- where Pint will be used
- where Pint is intentionally not used
- dimensional assumptions and conversions
- Symbol table
- paper notation
- Python identifier
- units/dimensions
- meaning
- where defined in the paper
- provenance/confidence reference
- Constants and parameters
- values, units, source table/equation
- whether fixed, configurable, or unknown
- provenance/confidence reference
- Equation inventory
- equation number or section reference
- original mathematical expression when possible
- plain-language meaning
- proposed Python function/name
- inputs, outputs, units
- provenance/confidence reference
- Evaluation order / algorithm
- step-by-step order matching the paper as closely as possible
- Numerical methods
- solvers, approximations, discretization, interpolation, convergence criteria, etc.
- note anything unspecified by the paper
- Ambiguities / required user decisions
- missing constants
- undefined symbols
- unclear units
- inconsistent equations
- boundary/initial conditions
- low-confidence or blocked extraction items
- Proposed file layout
- implementation files
- tests
- examples/docs
- notebooks
- Test plan
- dimensional/unit tests
- equation smoke tests
- paper regression/reference tests if data exist
- physical sanity tests only where justified
- Verification inventory
- key figures/tables/equations to reproduce
- required data/parameters/initial conditions
- whether each is available, missing, digitizable, or manually needed
- expected artifact: test, notebook cell, plot, table, or TODO
- status: not started / blocked / attempted / reproduced
- Example plan
- minimal run
- paper scenario, limiting case, table, or figure reproduction if possible
After writing the spec, stop and ask the user to review it, especially ambiguities, low-confidence items, and required decisions. Do not proceed until the user confirms Phase 2.
Placeholder notebooks may be created during Phase 1, but model equations/functions should remain stubs or absent until approval.
Handling Ambiguity
Be strict about gaps in the paper:
- Do not silently fill gaps from common knowledge unless clearly labeled as an assumption.
- If ambiguity blocks implementation, ask the user for clarification in Phase 1.
- If implementation can proceed with placeholders, make them explicit using required parameters, documented TODOs, or
NotImplementedError. - Prefer exposing uncertain constants, closures, parameterizations, and boundary conditions as inputs.
- Never invent validation data or expected numerical results.
Phase 2: Implementation
Proceed only after explicit user approval.
Default architecture
Implement two layers by default:
core.py
- numeric, paper-faithful functions;
- canonical units documented in comments/docstrings;
- minimal internal unit machinery;
- formulas visually close to paper expressions.
units.pyor public API wrappers
- accept/return Pint quantities where useful;
- validate dimensionality;
- convert to canonical numeric units;
- delegate to
core.py.
Use constants.py for constants/parameters with values, units, and source references.
Units policy
Prefer a readable numeric core with unit comments over forcing Pint into every equation.
Example core style:
def saturation_vapor_pressure(T):
"""Eq. (4). T [K] -> e_s [Pa]."""
# T [K]
# returns e_s [Pa]
...
Use Pint for:
- public API wrappers;
- dimensional validation at boundaries;
- tests;
- examples/notebooks where helpful.
Use Pint internally only when it does not obscure the equation. If Pint or NumPy makes units/equations harder to verify, avoid it for that part and comment why.
Implementation style
- Use flat modules with functions and simple dataclasses.
- Prefer pure functions for equations.
- Provide one obvious high-level evaluation function plus lower-level equation functions.
- Keep parameters explicit.
- Implement equations in the same order/structure as the paper where possible.
- Add comments such as
# Eq. (12)at the corresponding code. - Use docstrings for each public function with:
- paper equation/section reference;
- expected canonical units;
- returned units;
- assumptions/limitations;
- provenance reference when useful.
- Use lightweight type hints when they improve clarity.
- Avoid protocols and elaborate generic abstractions unless absolutely necessary.
Tests
Use pytest by default.
Required test categories:
- Dimensional/unit tests
- Pint wrappers accept expected units;
- incompatible units are rejected;
- canonical conversions are correct.
- Equation smoke tests
- simple hand-checkable values for individual equations/functions.
- Reference/regression tests
- use paper tables, figures, examples, or limiting cases when available.
- Physical sanity tests
- conservation, monotonicity, positivity, asymptotic behavior, etc., only when justified by the paper.
If the paper lacks reference outputs, say so explicitly and avoid pretending smoke/sanity tests validate the whole model.
Verification notebooks
Always create notebooks by default:
notebooks/00_source_inspection.ipynbnotebooks/01_reproduce_key_figures.ipynb
The source inspection notebook should summarize source files, extraction quality, and key provenance/confidence issues.
The figure reproduction notebook should:
- list the paper's key figures/tables relevant to the model;
- identify required inputs, data, parameters, and initial/boundary conditions;
- import the implemented model;
- attempt reproduction where feasible;
- clearly state missing data or blocked steps;
- include TODO cells for human verification work.
If no meaningful figures/tables exist, document what would constitute verification instead: limiting cases, example calculations, benchmark values, or conservation checks.
Synthetic examples are allowed only when clearly labeled as non-validation.
Examples
Examples may be scripts and/or notebooks. They should:
- reproduce a paper scenario, table, figure, limiting case, or minimal run when possible;
- map inputs/outputs to paper sections/tables/figures;
- use
matplotlibwhen plots help compare to the paper; - clearly label synthetic examples as non-validation.
Final Response Checklist
When Phase 1 is complete, report:
- project/workspace path;
- path to
docs/SOURCE_QUALITY.md; - path to
sources/extracted/provenance.yaml; - path to
docs/MODEL_EXTRACTION.md; - major ambiguities, low-confidence items, or required decisions;
- whether implementation is currently blocked;
- exact confirmation needed to proceed.
When Phase 2 is complete, report:
- implementation files changed/created;
- tests added and commands run;
- notebooks/examples added;
- validation status against the paper;
- figures/tables attempted or left as TODOs;
- remaining assumptions, medium-confidence risks, or blocked verification items.
</skill>
PDF is in bergner-spichtinger-2026.pdf, HTML is in bergner-spichtinger-2026.html with ancillary files in bergner-spichtinger-2026_files - please create the Python project in this directory.
Phase 1 is complete. I created the uv-managed Python extraction workspace in:
[REDACTED_LOCAL_PATH]
Key artifacts:
- Source quality report:
docs/SOURCE_QUALITY.md - Provenance manifest:
sources/extracted/provenance.yaml - Extraction/specification document:
docs/MODEL_EXTRACTION.md - Raw extraction outputs:
sources/extracted/raw/
Show remaining 23 lines
- Placeholder notebooks:
notebooks/00_source_inspection.ipynbnotebooks/01_reproduce_key_figures.ipynb- Placeholder package files:
src/bergner_spichtinger_2026/core.pysrc/bergner_spichtinger_2026/constants.pysrc/bergner_spichtinger_2026/units.py
I also registered/copied the PDF, HTML, and ancillary files under sources/original/, extracted PDF text with pdftotext, inspected the HTML with a reproducible script, and added scripts for re-running extraction/manifest generation.
Important Phase 1 findings / ambiguities:
- HTML has semantic math/MathJax and is the best primary source, but equations still need final visual checking before implementation.
- Main RHS equations appear implementable, but several constants/functions are marked medium-confidence pending final visual verification, especially
K_T(T)formatting and unit conventions. - Need decision on Phase 2 scope: just the ODE RHS, or also equilibria/Jacobian/bifurcation/figure reproduction.
- Need confirmation whether to implement optional
s <= 1evaporation and Eq. (16) regularization. - Figure reproduction is blocked until data/initial conditions/solver settings are curated; B2SHARE data are referenced but not downloaded.
Implementation is intentionally not started.
To proceed, please confirm something like:
“Proceed to Phase 2. Implement the core ODE RHS first, using SI units and per-dry-air-mass
n; include/exclude evaporation and regularization as follows: …”
Going through the "Ambiguities/required user decisions" in MODEL_EXTRACTION.md:
- Just core ODE RHS and try to reproduce trajectories shown in Figure 4.
- Not sure about the interpretation of n: let's go with what's suggested in the MODEL_EXTRACTION.md.
- I don't think the regularization in Eq. (16) is needed: the paper talks about it as something that "might be applied", but then goes on (end of the same paragraph) to say that in their case they can assume that n and q are positive, which I think means that the regularization isn't required.
- The expression for K_T(T) (Eq. (A34)) is K_T(T) = (a_K T ^ b_K) / (T + T_K 10 ^ (c_K / T)).
- I only need you to replicate Figure 4 to begin with, so the B2SHARE data is not required.
Is that sufficient information to continue?
If so, please proceed with phase 2.
Yes — that was sufficient, and Phase 2 is now implemented.
Created/updated:
src/bergner_spichtinger_2026/constants.pysrc/bergner_spichtinger_2026/core.pysrc/bergner_spichtinger_2026/units.pyscripts/reproduce_figure4.pynotebooks/01_reproduce_key_figures.ipynbtests/test_core.py
Show remaining 28 lines
tests/test_units.pydocs/PHASE2_IMPLEMENTATION.md
Generated:
outputs/figure4_reproduction.png
Validation run:
uv run pytest -q
# 5 passed
Figure 4 reproduction:
uv run python scripts/reproduce_figure4.py
# wrote outputs/figure4_reproduction.png
Notes:
- Implemented the unregularized core ODE RHS only;
n <= 0orq <= 0raisesValueError. - Used
ninternally as per dry-air mass, as proposed. - Used your confirmed
K_T(T)expression. - Did not use/download B2SHARE data.
- Figure 4 reproduction is qualitative: the paper caption doesn’t give initial conditions, so the script uses
x_eq * 0.99, matching the nearby paper text about a 1% perturbation from equilibrium.