# daviddahlbudding/chelio architecture

> Architecture diagram of the GitHub repository daviddahlbudding/chelio, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/daviddahlbudding/chelio
- Repository: https://github.com/daviddahlbudding/chelio

## Overview

1. **What this repository is**
   Chelio is an orchestration layer that couples two external scientific codes: **HELIOS** for 1D radiative transfer / temperature-pressure structure, and **GGchem** for equilibrium chemistry. The repository itself does not implement those solvers; it coordinates them, converts their inputs/outputs, and repeats the exchange until the atmosphere is self-consistent.

2. **Main runtime boundary**
   The core architectural boundary is between **Chelio scripts** and the two external executables. The repo expects `HELIOS_PATH`, `GGCHEM_PATH`, and `CHELIO_PATH` to point to installed locations, so the workflow is built around filesystem-based handoff rather than in-process library calls.

3. **Top-level orchestration**
   `run_coupled.bash` is the main entry point for a single simulation. It accepts physical parameters such as top/bottom pressure, internal temperature, albedo, elemental abundances, and a start iteration index for resuming. This script is the control plane for the iterative HELIOS ↔ GGchem loop.

4. **Parameter-sweep orchestration**
   `multiple_runs.bash` is a batch driver that invokes the single-run workflow repeatedly across arrays of parameter values. Architecturally, this is a thin experiment manager: it expands a grid of atmospheric/chemical cases and produces a set of independent run directories under the output tree.

5. **Coupling data flow**
   The coupling cycle is likely:
   - create or update a pressure-temperature profile,
   - derive elemental abundances and chemistry inputs,
   - run GGchem to compute equilibrium composition,
   - convert chemistry output into HELIOS mixing ratios,
   - run HELIOS to recompute the P–T structure,
   - convert the new P–T profile back for the next GGchem iteration.
   
   The key architectural point is that the loop is mediated by **file conversions** between incompatible formats.

6. **Utility scripts in `source/`**
   The Python scripts in `source/` are the transformation layer:
   - `create_pt.py` generates initial P–T profiles.
   - `calc_abundances.py` computes starting abundances for GGchem.
   - `convert_tp.py` converts HELIOS temperature-pressure output into a GGchem-readable form.
   - `convert_mixfile.py` converts GGchem mixing ratios into the HELIOS mixfile format.
   - `calc_escape.py` performs post-run escape/stability calculations.
   - `mark_bad_last_iters.py` flags problematic iterations in output.
   
   These scripts are the glue that enforces format compatibility and preserve the coupling boundary between the solvers.

7. **Input templates and configuration**
   `ggchem_inputs/` and `helios_inputs/` hold the template files that define each solver’s static configuration, including parameter files and species definitions. These directories are important because they separate **model setup** from **run-specific generated files**. The root-level `pt_helios.in` appears to be a seed profile used at startup or as a template for initial coupling.

8. **Outputs as a run-centric artifact**
   Simulation results are written under `output/` in per-run subdirectories named by `--NAME`. That directory is the primary persistence boundary for both raw solver outputs and derived coupling artifacts. Because runs can be resumed with `--i_min`, the output layout likely encodes iteration history as well as final state.

9. **Analysis layer**
   The `analyze/` directory is a separate post-processing subsystem, not part of the simulation runtime. It contains Jupyter notebooks for common scientific analyses and a small Python package, `analyze_modules`, that centralizes data loading and plotting. This layer consumes files from `output/` and turns them into comparative plots, histograms, and matrices.

10. **Analysis package structure**
    `analyze_modules/data_loader.py` likely abstracts the repository’s output layout so notebooks do not have to know file-by-file details. `plot_utils.py` provides reusable plotting logic. This is a good sign of a deliberate separation between **data access** and **presentation** inside the analysis stack.

11. **Operational model**
    The project is shell- and Python-based rather than service-based: there is no daemon, API server, or database. The architecture is essentially a scientific workflow engine built from scripts, templates, and generated files. Reproducibility comes from fixed inputs, explicit environment variables, and named output folders.

12. **How to draw the architecture**
    A correct diagram should show:
    - user-triggered entry points (`run_coupled.bash`, `multiple_runs.bash`);
    - the Chelio utility scripts as the conversion/initialization layer;
    - HELIOS and GGchem as external executables on either side of the coupling loop;
    - `ggchem_inputs/` and `helios_inputs/` as static templates feeding each solver;
    - `output/` as the shared persistence layer;
    - `analyze/` as a downstream consumer of output data.

Main entry points: [`run_coupled.bash`](https://github.com/daviddahlbudding/chelio/blob/main/run_coupled.bash) (Coupled run), [`analyze`](https://github.com/daviddahlbudding/chelio/tree/main/analyze) (Notebooks), [`source/convert_tp.py`](https://github.com/daviddahlbudding/chelio/blob/main/source/convert_tp.py) (TP convert), [`source/convert_mixfile.py`](https://github.com/daviddahlbudding/chelio/blob/main/source/convert_mixfile.py) (Mix convert)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Simulation runtime"]
  node_run_coupled["Coupled run<br/>bash entrypoint<br/>[run_coupled.bash]"]
  node_multiple_runs["Batch runs<br/>bash driver<br/>[multiple_runs.bash]"]
  node_create_pt["Init PT<br/>python transform<br/>[create_pt.py]"]
  node_calc_abundances["Init abundances<br/>python transform<br/>[calc_abundances.py]"]
  node_convert_tp["TP convert<br/>python transform<br/>[convert_tp.py]"]
  node_convert_mixfile["Mix convert<br/>python transform<br/>[convert_mixfile.py]"]
  node_calc_escape["Escape calc<br/>python analysis<br/>[calc_escape.py]"]
  node_mark_bad_last_iters["Flag bad iters<br/>python utility"]
  node_helios{{"HELIOS<br/>external solver"}}
  node_ggchem{{"GGchem<br/>external solver"}}
end

subgraph group_inputs["Static inputs"]
  node_helios_inputs["HELIOS inputs<br/>config templates"]
  node_ggchem_inputs["GGchem inputs<br/>config templates"]
  node_pt_seed["PT seed<br/>seed profile<br/>[pt_helios.in]"]
end

subgraph group_analysis["Post-processing"]
  node_analyze_notebooks["Notebooks"]
  node_analyze_modules["Analysis utils<br/>python package"]
end

subgraph group_persistence["Run outputs"]
  node_output_tree[("Output tree<br/>run artifacts")]
end

node_multiple_runs -->|"invokes"| node_run_coupled
node_run_coupled -->|"initializes"| node_create_pt
node_run_coupled -->|"prepares"| node_calc_abundances
node_run_coupled -->|"seeds"| node_pt_seed
node_run_coupled -->|"configures"| node_helios_inputs
node_run_coupled -->|"configures"| node_ggchem_inputs
node_run_coupled -->|"calls"| node_ggchem
node_ggchem -->|"outputs"| node_convert_mixfile
node_convert_mixfile -->|"feeds"| node_helios
node_helios -->|"outputs"| node_convert_tp
node_convert_tp -->|"feeds"| node_ggchem
node_run_coupled -->|"writes"| node_output_tree
node_mark_bad_last_iters -->|"edits"| node_output_tree
node_calc_escape -->|"reads"| node_output_tree
node_analyze_notebooks -->|"consumes"| node_output_tree
node_analyze_notebooks -->|"uses"| node_analyze_modules
node_analyze_modules -->|"loads"| node_output_tree

click node_run_coupled "https://github.com/daviddahlbudding/chelio/blob/main/run_coupled.bash"
click node_multiple_runs "https://github.com/daviddahlbudding/chelio/blob/main/multiple_runs.bash"
click node_create_pt "https://github.com/daviddahlbudding/chelio/blob/main/source/create_pt.py"
click node_calc_abundances "https://github.com/daviddahlbudding/chelio/blob/main/source/calc_abundances.py"
click node_convert_tp "https://github.com/daviddahlbudding/chelio/blob/main/source/convert_tp.py"
click node_convert_mixfile "https://github.com/daviddahlbudding/chelio/blob/main/source/convert_mixfile.py"
click node_calc_escape "https://github.com/daviddahlbudding/chelio/blob/main/source/calc_escape.py"
click node_mark_bad_last_iters "https://github.com/daviddahlbudding/chelio/blob/main/source/mark_bad_last_iters.py"
click node_helios_inputs "https://github.com/daviddahlbudding/chelio/tree/main/helios_inputs"
click node_ggchem_inputs "https://github.com/daviddahlbudding/chelio/tree/main/ggchem_inputs"
click node_pt_seed "https://github.com/daviddahlbudding/chelio/blob/main/pt_helios.in"
click node_analyze_notebooks "https://github.com/daviddahlbudding/chelio/tree/main/analyze"
click node_analyze_modules "https://github.com/daviddahlbudding/chelio/tree/main/analyze/analyze_modules"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_run_coupled,node_multiple_runs,node_create_pt,node_calc_abundances,node_convert_tp,node_convert_mixfile,node_calc_escape,node_mark_bad_last_iters,node_helios,node_ggchem toneBlue
class node_helios_inputs,node_ggchem_inputs,node_pt_seed toneAmber
class node_analyze_notebooks,node_analyze_modules toneMint
class node_output_tree toneRose
```

## Components

### Simulation runtime

Entry points, coupling scripts, converters, and external executables used for one atmosphere run.

- [Coupled run](https://github.com/daviddahlbudding/chelio/blob/main/run_coupled.bash): bash entrypoint · Main single-run driver for the iterative HELIOS ↔ GGchem workflow. · `run_coupled.bash`
- [Batch runs](https://github.com/daviddahlbudding/chelio/blob/main/multiple_runs.bash): bash driver · Expands parameter sweeps into multiple independent coupled simulations. · `multiple_runs.bash`
- [Init PT](https://github.com/daviddahlbudding/chelio/blob/main/source/create_pt.py): python transform · Generates starting pressure-temperature profiles for a coupled run. · `source/create_pt.py`
- [Init abundances](https://github.com/daviddahlbudding/chelio/blob/main/source/calc_abundances.py): python transform · Computes starting elemental abundances for chemistry input. · `source/calc_abundances.py`
- [TP convert](https://github.com/daviddahlbudding/chelio/blob/main/source/convert_tp.py): python transform · Converts HELIOS temperature-pressure output into GGchem-readable form. · `source/convert_tp.py`
- [Mix convert](https://github.com/daviddahlbudding/chelio/blob/main/source/convert_mixfile.py): python transform · Converts GGchem mixing ratios into HELIOS mixfile format. · `source/convert_mixfile.py`
- [Escape calc](https://github.com/daviddahlbudding/chelio/blob/main/source/calc_escape.py): python analysis · Post-run escape or stability calculation on produced atmosphere states. · `source/calc_escape.py`
- [Flag bad iters](https://github.com/daviddahlbudding/chelio/blob/main/source/mark_bad_last_iters.py): python utility · Marks problematic iterations in the run history. · `source/mark_bad_last_iters.py`
- **HELIOS**: external solver · External radiative-transfer and temperature-pressure solver.
- **GGchem**: external solver · External equilibrium chemistry solver.

### Static inputs

Templates and seed files that configure the coupled solvers.

- [HELIOS inputs](https://github.com/daviddahlbudding/chelio/tree/main/helios_inputs): config templates · Static configuration and species definitions for HELIOS. · `helios_inputs`
- [GGchem inputs](https://github.com/daviddahlbudding/chelio/tree/main/ggchem_inputs): config templates · Static parameter file and chemistry inputs for GGchem. · `ggchem_inputs`
- [PT seed](https://github.com/daviddahlbudding/chelio/blob/main/pt_helios.in): seed profile · Initial pressure-temperature profile used to bootstrap coupling. · `pt_helios.in`

### Post-processing

Notebook-driven analysis layer and shared plotting/data-loading helpers.

- [Notebooks](https://github.com/daviddahlbudding/chelio/tree/main/analyze): analysis notebooks · Interactive post-processing notebooks for single runs, comparisons, matrices, and escape statistics. · `analyze`
- [Analysis utils](https://github.com/daviddahlbudding/chelio/tree/main/analyze/analyze_modules): python package · Shared data-loading and plotting helpers used by the notebooks. · `analyze/analyze_modules`

### Run outputs

Per-run output tree used as the handoff boundary for simulation artifacts.

- **Output tree**: run artifacts · Per-run directories containing raw solver results and derived coupling products.

## Connections

- Batch runs → Coupled run: invokes · Launches repeated coupled simulations over parameter grids.
- Coupled run → Init PT: initializes · Builds or updates the starting pressure-temperature profile.
- Coupled run → Init abundances: prepares · Derives starting abundances for the chemistry solver.
- Coupled run → PT seed: seeds · Uses the seed profile as a starting template.
- Coupled run → HELIOS inputs: configures · Reads static HELIOS configuration templates.
- Coupled run → GGchem inputs: configures · Reads static GGchem configuration templates.
- Coupled run → GGchem: calls · Runs chemistry after assembling chemistry inputs.
- GGchem → Mix convert: outputs · Chemistry output is transformed into HELIOS mixing-ratio format.
- Mix convert → HELIOS: feeds · Produces mixfiles consumed by HELIOS.
- HELIOS → TP convert: outputs · HELIOS temperature-pressure output is normalized for the next chemistry step.
- TP convert → GGchem: feeds · Converted profiles become input for the next GGchem iteration.
- Coupled run → Output tree: writes · Stores iteration artifacts and final run results.
- Flag bad iters → Output tree: edits · Flags problematic iterations in existing run outputs.
- Escape calc → Output tree: reads · Consumes run artifacts for escape/stability calculations.
- Notebooks → Output tree: consumes · Notebook analyses load results from the run output tree.
- Notebooks → Analysis utils: uses · Notebooks share reusable loading and plotting helpers.
- Analysis utils → Output tree: loads · Data loader abstracts the output layout for analysis.
