Dataset Metadata¶
The dataset browser in zephyr-frontend does not read the data directories
itself. It reads JSON metadata files that
iac-metadata generates from the
dataset definitions in its
src/datasets.yaml
and publishes at https://data.iac.ethz.ch/zephyr/file_index/.
The C2SM landing page reads the same files: a weekly workflow in C2SM/c2sm.github.io copies the variables, size and number of files of each dataset into its dataset pages.
Published files¶
file_tree_<key>*.json, written byfile_tree.pyinfile_index.yml: the directory tree of a dataset, i.e. the available labels such as variables, models and scenarios, with their date ranges.meta_<key>.json, written byfile_size_number.pyinfile_size_number.yml: the total size and number of files of a dataset.datasets.json, maintained by hand and copied bypublish_datasets.yml: the buttons of the dataset picker, see Keys in datasets.json.
How a run works¶
GitHub-hosted runners cannot reach the IAC servers directly, so each
workflow connects through a bastion host, uploads src/ with rsync and
runs the pipeline on a target host that mounts both the data and the file
index:
flowchart LR
A[GitHub Actions runner] -->|ssh| B[Bastion host]
B -->|ssh| C[Target host]
C -->|reads| D[(/net/atmos/data)]
C -->|writes JSON| E[(/net/co2/c2sm-services/zephyr/file_index)]
E -->|served at data.iac.ethz.ch| F[zephyr-frontend]
E -->|served at data.iac.ethz.ch| G[c2sm.github.io]
The datasets are processed one after the other in a single ssh session. Each job has a timeout of 5 hours; a full nightly run usually takes 1 to 2 hours, but can take much longer while the file system is busy during working hours.
If a dataset yields no data at all, the scripts save nothing for it and the
run fails. This usually points to a wrong path, label or pattern in
datasets.yaml. The file index then keeps the last valid version of that
dataset.
Workflows¶
Workflow |
Trigger |
|---|---|
|
Daily at 02:00 UTC, push to |
|
Daily at 03:00 UTC, push to |
|
Push to |
|
Pull requests that change |
|
Pull requests, push to |
On a push to main that changes datasets.yaml or datasets.json,
file_index.yml and file_size_number.yml run only the added or modified
datasets. Other pipeline changes are published by the next nightly run.
Runs of the same workflow wait for each other, so a push-triggered run and
a nightly run never write the same files at the same time.
To run a workflow by hand, optionally for a single dataset (a top-level key
in datasets.yaml):
gh workflow run file_index.yml --repo C2SM/iac-metadata -f dataset=cmip7
gh workflow run file_size_number.yml --repo C2SM/iac-metadata -f dataset=cmip7
Warning
A manual run writes to the production file index, even when it is started on a feature branch. Use a dry run to test changes.
Adding or changing a dataset¶
Add an entry to
src/datasets.yaml. Required keys aredirectory_paths,labels,patternandblacklist; optional keys arefreq(MorYE),historical_beforeandmap_root. Copy an existing entry with a similar directory layout as a starting point.If the dataset should appear in the dataset picker, add an entry to
src/datasets.json(see below).Add the dataset to zephyr itself (
builder_classesinpath_constructor.py) and to Supported Datasets.To show it on the C2SM landing page, add the key and the heading of its section to
datasets.yamlin C2SM/c2sm.github.io.Open a pull request. The checks validate the configuration and the dry run scans the new or modified datasets on the target host without publishing anything.
After the merge, the push-triggered runs publish the new metadata.
A new option in datasets.yaml also has to be added to the known keys in
tests/test_datasets_config.py.
Keys in datasets.json¶
datasets.json is a curated subset of datasets.yaml, with one
{key, name, description} entry per picker button. Some entries in
datasets.yaml, such as cmip6_ssp126, exist only to scan scenarios
separately and have no button.
The frontend uses each key for two purposes, so it must match in both
places:
It is sent as
files_query_options.datasetin the request, so it must match a key in zephyr’sbuilder_classes(for exampleera5-land_cds).It is used to fetch
file_tree_<key>_noindent.json, so it must match the top-level key indatasets.yaml.
When renaming a key, rename it in both files and in the datasets.yaml of
C2SM/c2sm.github.io, and make sure file_index.yml has run under the new
name before datasets.json points to it. Otherwise the frontend cannot
load that dataset until the next run, and the landing page silently stops
updating it.
Testing changes¶
Checks (
checks.yml, about a minute): validatedatasets.yamlanddatasets.json, run the unit tests on small temporary directory trees and lint the shell scripts withshellcheck. To run them locally:pip install -r src/requirements.txt pytest pytest
Dry run (
dry_run.yml): runs both pipelines with--dry-runon the target host for every pull request that changessrc/. Only the added or modified datasets are run if the pull request changes nothing but the dataset configuration; otherwise all datasets, which takes up to about 2 hours. Pull requests from forks are skipped, since they have no access to the ssh secrets.Manual dry run on a host that mounts
/net/atmos/data. The JSON files are written to the current directory only:cd src bash run_file_index.sh --dry-run cmip7 bash run_file_size_number.sh --dry-run cmip7
Pull requests can only be merged once checks and Dry run have passed.
Dry run also passes when it is skipped.
Setup¶
The workflows need these repository secrets and variables (Settings -> Secrets and variables -> Actions):
Name |
Type |
Purpose |
|---|---|---|
|
Secret |
Private key for the bastion user |
|
Secret |
Private key for the target host user |
|
Variable |
Bastion host, user |
|
Variable |
Target host, user |
|
Variable |
|
The target host account needs uv in
~/.local/bin/uv. Each run creates a fresh virtual environment with it and
installs src/requirements.txt. zephyr-request uses the same account and
uv installation.