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 by file_tree.py in file_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 by file_size_number.py in file_size_number.yml: the total size and number of files of a dataset.

  • datasets.json, maintained by hand and copied by publish_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

file_index.yml

Daily at 02:00 UTC, push to main, manual

file_size_number.yml

Daily at 03:00 UTC, push to main, manual

publish_datasets.yml

Push to main that changes datasets.json, manual

dry_run.yml

Pull requests that change src/

checks.yml

Pull requests, push to main

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

  1. Add an entry to src/datasets.yaml. Required keys are directory_paths, labels, pattern and blacklist; optional keys are freq (M or YE), historical_before and map_root. Copy an existing entry with a similar directory layout as a starting point.

  2. If the dataset should appear in the dataset picker, add an entry to src/datasets.json (see below).

  3. Add the dataset to zephyr itself (builder_classes in path_constructor.py) and to Supported Datasets.

  4. To show it on the C2SM landing page, add the key and the heading of its section to datasets.yaml in C2SM/c2sm.github.io.

  5. 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.

  6. 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.dataset in the request, so it must match a key in zephyr’s builder_classes (for example era5-land_cds).

  • It is used to fetch file_tree_<key>_noindent.json, so it must match the top-level key in datasets.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): validate datasets.yaml and datasets.json, run the unit tests on small temporary directory trees and lint the shell scripts with shellcheck. To run them locally:

    pip install -r src/requirements.txt pytest
    pytest
    
  • Dry run (dry_run.yml): runs both pipelines with --dry-run on the target host for every pull request that changes src/. 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

FOG_SSH_KEY

Secret

Private key for the bastion user

IACDIPL7_SSH_KEY

Secret

Private key for the target host user

SSH_BASTION_HOST, SSH_BASTION_USER

Variable

Bastion host, user

SSH_TARGET_HOST, SSH_TARGET_USER

Variable

Target host, user

SSH_KNOWN_HOSTS

Variable

known_hosts lines for both hosts

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.