Skip to content
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

A self-contained set of training notebooks for the [Climate Rapid Evaluation Framework (REF)](https://climate-ref.org).

The notebooks take you from *what the REF is* through to *querying the public
REF API* and *building a publication-ready figure*.
They are written for climate scientists, analysts, and newcomers with no prior REF knowledge is assumed.
The notebooks take you from *what the REF is* through to *querying public
CMIP7 results* and *building a publication-ready figure*.
They are written for climate scientists, analysts, and newcomers; no prior REF knowledge is assumed.

## Run in your browser (no installation)

Expand Down Expand Up @@ -37,7 +37,6 @@ git clone https://github.com/Climate-REF/climate-ref-tutorials.git
cd climate-ref-tutorials
uv sync # create the environment
uv run bash scripts/generate_client.sh # generate the REF API client
uv run python -c "from ref_tutorials import fetch_sample_data; fetch_sample_data()" # pre-fetch sample data (notebook 04)
uv run jupyter lab notebooks # open the notebooks
```

Expand All @@ -49,23 +48,26 @@ introduced earlier.
| # | Notebook | What you will learn | Prerequisites |
| --- | ----------------------------------------------------------------------- | ---------------------------------------------------------------------------------- | ------------- |
| 01 | [REF concepts](notebooks/01-ref-concepts.ipynb) | The core vocabulary: diagnostics, providers, executions, metrics, datasets | None |
| 02 | [Querying the REF API](notebooks/02-querying-the-api.ipynb) | Set up the API client, list diagnostics, fetch metric values, inspect an execution | 01 |
| 03 | [Figure generation](notebooks/03-publication-figure.ipynb) | Build a polished multi-model metric comparison figure and save it | 01, 02 |
| 04 | [Running a diagnostic locally](notebooks/04-local-diagnostic-run.ipynb) | Define a custom diagnostic provider and run it locally on small sample data | 01 |
| 05 | [Multi-diagnostic example](notebooks/05-ecs-temperature-figure.ipynb) | Build an IPCC-style figure joining ECS scalars to historical `tas` timeseries | 01, 02, 03 |
| 02 | [Querying the REF API](notebooks/02-querying-the-api.ipynb) | Fetch metric values, compare ACCESS-ESM1-6 members with HadCRUT5 observations, and inspect maps and Taylor diagrams | 01 |
| 03 | [Time-series workshop](notebooks/03-publication-figure.ipynb) | Build a three-model CMIP7 chart, then compare ACCESS-ESM1-6 members and HadCRUT5 observations | 01, 02 |
| 04 | [Running a diagnostic locally](notebooks/04-local-diagnostic-run.ipynb) | Run a custom CMIP7 diagnostic on tiny synthetic data generated locally | 01 |
| 05 | [Multi-diagnostic example](notebooks/05-ecs-temperature-figure.ipynb) | Join CMIP7 ECS values to historical `tas` series in three figures | 01, 02, 03 |
| 06 | [Guided Python API tour](notebooks/06-guided-api-tour.ipynb) | Follow the dashboard journey in code: select ACCESS-ESM1-6, open plots, compare scores | 01, 02 |

More notebooks will be added over time — see [CONTRIBUTING.md](CONTRIBUTING.md).

## How it works

- Notebooks 01–03 query the **live** public REF API at <https://api.climate-ref.org>.
- Notebooks 01–03, 05 and 06 query the **live** public REF API at <https://api.climate-ref.org>.
- Notebooks 02 and 03 also read the annual HadCRUT5 global temperature series from the [Met Office](https://www.metoffice.gov.uk/hadobs/hadcrut5/data/HadCRUT.5.2.0.0/download.html).
An internet connection is required; the notebooks fail clearly if the API is unreachable.
- The REF API client (`climate_ref_client`) is **generated** from the API's
[OpenAPI schema](https://api.climate-ref.org/api/v1/openapi.json) by `scripts/generate_client.sh`,
so it always matches the current API.
It is not committed to this repository.
- Notebook 04 fetches a small CMIP6 sample dataset via the REF CLI and runs a
**custom diagnostic provider**, defined in `src/ref_tutorials/provider.py` locally.
- Notebook 04 generates two small synthetic CMIP7-style NetCDF files locally and runs a
**custom diagnostic provider**, defined in `src/ref_tutorials/provider.py`.
The synthetic files demonstrate the REF workflow; they are not real model output.
- Shared logic lives in the `ref_tutorials` helper package (`src/ref_tutorials`),
keeping the notebooks short and readable.
- Notebook **outputs are committed** so the notebooks render fully on GitHub without being run.
Expand Down
126 changes: 56 additions & 70 deletions notebooks/01-ref-concepts.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,13 @@
"source": [
"## What is the REF?\n",
"\n",
"The REF performs evaluation of climate datasets, much like a CI/CD pipeline runs tests against code. \n",
"As new climate model output is published, the REF evaluates it against reference data \n",
"and produces figures and metrics — in near-real time.\n",
"The REF evaluates climate datasets as new model output becomes available and produces\n",
"figures and metrics. The public deployment now includes CMIP7 Assessment Fast Track\n",
"results alongside CMIP6 results. These notebooks use CMIP7 examples.\n",
"\n",
"The public deployment currently evaluates CMIP6 dataset, but will include CMIP7 Assessment Fast Track data\n",
"as they become available.\n",
"\n",
"The REF has a dashboard (<https://dashboard.climate-ref.org>) which offers a curated view of the results from the REF. \n",
"This dashboard uses an API (<https://api.climate-ref.org>) to provide access to the results in a structured way.\n",
"\n",
"We can use this same API to make our own view of the data. As part of the API we also publish a [schema](https://api.climate-ref.org/docs) that describes the different endpoints that can be queried and the shape of the response"
"The [REF dashboard](https://dashboard.climate-ref.org) offers a curated view of the results.\n",
"The [public API](https://api.climate-ref.org) provides the same results in a structured form,\n",
"and its [schema](https://api.climate-ref.org/docs) describes what can be queried."
]
},
{
Expand Down Expand Up @@ -136,7 +132,8 @@
"metadata": {},
"source": [
"Every diagnostic has a human-readable `name`, a short machine-friendly `slug`, and a\n",
"`description`. Let's look at one in full:"
"`description`. We will use the global-mean temperature timeseries diagnostic, which has\n",
"CMIP7 results:"
]
},
{
Expand All @@ -149,14 +146,16 @@
"name": "stdout",
"output_type": "stream",
"text": [
"name: Climate at Global Warming Levels\n",
"slug: climate-at-global-warming-levels\n",
"description: Calculate climate variables at global warming levels (e.g. 1.5C, 2C, 3C, 4C above pre-industrial).\n"
"name: Global Mean Timeseries\n",
"slug: global-mean-timeseries\n",
"description: Plot the global mean time series of near-surface air temperature (tas). Example diagnostic with no observational datasets.\n"
]
}
],
"source": [
"example = diagnostics[0]\n",
"example = next(\n",
" d for d in diagnostics if d.provider.slug == \"esmvaltool\" and d.slug == \"global-mean-timeseries\"\n",
")\n",
"print(\"name: \", example.name)\n",
"print(\"slug: \", example.slug)\n",
"print(\"description:\", example.description.strip())"
Expand Down Expand Up @@ -211,19 +210,17 @@
"id": "be0528dc",
"metadata": {},
"source": [
"## Execution groups and Executions\n",
"## Execution groups and executions\n",
"\n",
"An **execution** is one run of a diagnostic against one specific group of datasets.\n",
"This execution has information about the datasets that were used to run it, the diagnostic and the outputs.\n",
"An **execution** is one run of a diagnostic against a particular set of datasets.\n",
"It records which data were used and what the run produced.\n",
"\n",
"A single diagnostic is typically executed many times on different sets of data.\n",
"This generally depends what is being calculated, but this is often once per model variant.\n",
"Each of these subsets is an *execution group*.\n",
"A diagnostic can run for many models and experiments. Each distinct selection is an\n",
"*execution group*. Its key describes the selection. If its inputs change, REF can run\n",
"it again, so one group may contain several executions.\n",
"\n",
"Each execution group has a unique key that describes it.\n",
"If any datasets in an execution group change, then a new execution is performed.\n",
"\n",
"We can list the execution groups available for the Global Warming Level diagnostic:"
"We list the CMIP7 execution groups for the global-mean timeseries diagnostic,\n",
"then select an ACCESS-ESM1-6 historical run:"
]
},
{
Expand All @@ -236,34 +233,49 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Diagnostic: Climate at Global Warming Levels\n",
"Execution groups: 4\n",
"Execution group keys: ['cmip6_ssp126', 'cmip6_ssp245', 'cmip6_ssp370', 'cmip6_ssp585']\n"
"Diagnostic: Global Mean Timeseries\n",
"CMIP7 execution groups: 496\n",
"ACCESS-ESM1-6 group: cmip7_historical_g115_ACCESS-ESM1-6_tas_r10i1p1f1\n"
]
}
],
"source": [
"from climate_ref_client.api.diagnostics import diagnostics_list_execution_groups\n",
"\n",
"from ref_tutorials import latest_successful_execution\n",
"\n",
"execution_groups = diagnostics_list_execution_groups.sync(\n",
" client=client, provider_slug=example.provider.slug, diagnostic_slug=example.slug\n",
" client=client,\n",
" provider_slug=example.provider.slug,\n",
" diagnostic_slug=example.slug,\n",
" mip_era=\"CMIP7\",\n",
").data\n",
"\n",
"first_execution_group = execution_groups[0]\n",
"access_group = next(\n",
" (\n",
" group\n",
" for group in execution_groups\n",
" if \"ACCESS-ESM1-6\" in group.key\n",
" and \"_historical_\" in group.key\n",
" and latest_successful_execution(group) is not None\n",
" ),\n",
" None,\n",
")\n",
"if access_group is None:\n",
" raise ValueError(\"No successful CMIP7 ACCESS-ESM1-6 historical run is available\")\n",
"\n",
"print(f\"Diagnostic: {example.name}\")\n",
"print(f\"Execution groups: {len(execution_groups)}\")\n",
"print(f\"Execution group keys: {[eg.key for eg in execution_groups]}\")"
"print(f\"CMIP7 execution groups: {len(execution_groups)}\")\n",
"print(f\"ACCESS-ESM1-6 group: {access_group.key}\")"
]
},
{
"cell_type": "markdown",
"id": "dce894b0",
"metadata": {},
"source": [
"Within each execution group, there may be multiple executions.\n",
"We pick the most recent successful one.\n",
"For this execution we can access the outputs that were generated as well as a URL for downloading them."
"Within each execution group, there may be multiple executions. We pick the most recent\n",
"successful one and inspect the files it produced. Each output has a URL for downloading it."
]
},
{
Expand All @@ -276,44 +288,18 @@
"name": "stdout",
"output_type": "stream",
"text": [
" executions/recipe_20261026_015959/plots/gwl_mean_plots_pr/plot_gwl_stats/CMIP6_mm_mean_1.5.png https://api.climate-ref.org/api/v1/results/2284307\n",
" executions/recipe_20261026_015959/plots/gwl_mean_plots_pr/plot_gwl_stats/CMIP6_mm_mean_2.0.png https://api.climate-ref.org/api/v1/results/2284308\n",
" executions/recipe_20261026_015959/plots/gwl_mean_plots_pr/plot_gwl_stats/CMIP6_mm_mean_3.0.png https://api.climate-ref.org/api/v1/results/2284309\n",
" executions/recipe_20261026_015959/plots/gwl_mean_plots_pr/plot_gwl_stats/CMIP6_mm_stdev_1.5.png https://api.climate-ref.org/api/v1/results/2284310\n",
" executions/recipe_20261026_015959/plots/gwl_mean_plots_pr/plot_gwl_stats/CMIP6_mm_stdev_2.0.png https://api.climate-ref.org/api/v1/results/2284311\n",
" executions/recipe_20261026_015959/plots/gwl_mean_plots_pr/plot_gwl_stats/CMIP6_mm_stdev_3.0.png https://api.climate-ref.org/api/v1/results/2284312\n",
" executions/recipe_20261026_015959/plots/gwl_mean_plots_tas/plot_gwl_stats/CMIP6_mm_mean_1.5.png https://api.climate-ref.org/api/v1/results/2284313\n",
" executions/recipe_20261026_015959/plots/gwl_mean_plots_tas/plot_gwl_stats/CMIP6_mm_mean_2.0.png https://api.climate-ref.org/api/v1/results/2284314\n",
" executions/recipe_20261026_015959/plots/gwl_mean_plots_tas/plot_gwl_stats/CMIP6_mm_mean_3.0.png https://api.climate-ref.org/api/v1/results/2284315\n",
" executions/recipe_20261026_015959/plots/gwl_mean_plots_tas/plot_gwl_stats/CMIP6_mm_stdev_1.5.png https://api.climate-ref.org/api/v1/results/2284316\n",
" executions/recipe_20261026_015959/plots/gwl_mean_plots_tas/plot_gwl_stats/CMIP6_mm_stdev_2.0.png https://api.climate-ref.org/api/v1/results/2284317\n",
" executions/recipe_20261026_015959/plots/gwl_mean_plots_tas/plot_gwl_stats/CMIP6_mm_stdev_3.0.png https://api.climate-ref.org/api/v1/results/2284318\n",
" executions/recipe_20261026_015959/work/calculate_gwl_exceedance_years/gwl_exceedance_calculation/GWL_exceedance_years.csv https://api.climate-ref.org/api/v1/results/2284319\n",
" executions/recipe_20261026_015959/work/gwl_mean_plots_pr/plot_gwl_stats/CMIP6_mm_mean_1.5.nc https://api.climate-ref.org/api/v1/results/2284320\n",
" executions/recipe_20261026_015959/work/gwl_mean_plots_pr/plot_gwl_stats/CMIP6_mm_mean_2.0.nc https://api.climate-ref.org/api/v1/results/2284321\n",
" executions/recipe_20261026_015959/work/gwl_mean_plots_pr/plot_gwl_stats/CMIP6_mm_mean_3.0.nc https://api.climate-ref.org/api/v1/results/2284322\n",
" executions/recipe_20261026_015959/work/gwl_mean_plots_pr/plot_gwl_stats/CMIP6_mm_stdev_1.5.nc https://api.climate-ref.org/api/v1/results/2284323\n",
" executions/recipe_20261026_015959/work/gwl_mean_plots_pr/plot_gwl_stats/CMIP6_mm_stdev_2.0.nc https://api.climate-ref.org/api/v1/results/2284324\n",
" executions/recipe_20261026_015959/work/gwl_mean_plots_pr/plot_gwl_stats/CMIP6_mm_stdev_3.0.nc https://api.climate-ref.org/api/v1/results/2284325\n",
" executions/recipe_20261026_015959/work/gwl_mean_plots_tas/plot_gwl_stats/CMIP6_mm_mean_1.5.nc https://api.climate-ref.org/api/v1/results/2284326\n",
" executions/recipe_20261026_015959/work/gwl_mean_plots_tas/plot_gwl_stats/CMIP6_mm_mean_2.0.nc https://api.climate-ref.org/api/v1/results/2284327\n",
" executions/recipe_20261026_015959/work/gwl_mean_plots_tas/plot_gwl_stats/CMIP6_mm_mean_3.0.nc https://api.climate-ref.org/api/v1/results/2284328\n",
" executions/recipe_20261026_015959/work/gwl_mean_plots_tas/plot_gwl_stats/CMIP6_mm_stdev_1.5.nc https://api.climate-ref.org/api/v1/results/2284329\n",
" executions/recipe_20261026_015959/work/gwl_mean_plots_tas/plot_gwl_stats/CMIP6_mm_stdev_2.0.nc https://api.climate-ref.org/api/v1/results/2284330\n",
" executions/recipe_20261026_015959/work/gwl_mean_plots_tas/plot_gwl_stats/CMIP6_mm_stdev_3.0.nc https://api.climate-ref.org/api/v1/results/2284331\n",
" executions/recipe_20261026_015959/index.html https://api.climate-ref.org/api/v1/results/2284332\n"
"Execution group: cmip7_historical_g115_ACCESS-ESM1-6_tas_r10i1p1f1\n",
" executions/recipe_20261026_025620/plots/timeseries/script1/png/tas_tavg-h2m-hxy-u_mon_glb_g115_ACCESS-ESM1-6_historical_r10i1p1f1_18500116T120000-20221216T120000.png https://api.climate-ref.org/api/v1/results/2293024\n",
" executions/recipe_20261026_025620/work/timeseries/script1/tas_tavg-h2m-hxy-u_mon_glb_g115_ACCESS-ESM1-6_historical_r10i1p1f1_18500116T120000-20221216T120000.nc https://api.climate-ref.org/api/v1/results/2293025\n",
" executions/recipe_20261026_025620/index.html https://api.climate-ref.org/api/v1/results/2293026\n"
]
}
],
"source": [
"from ref_tutorials import latest_successful_execution\n",
"\n",
"execution = latest_successful_execution(first_execution_group)\n",
"if execution is None:\n",
" print(\"This execution group has no successful execution yet, so there are no outputs to show.\")\n",
"else:\n",
" for o in execution.outputs:\n",
" print(f\" {o.filename:20s} {o.url}\")"
"execution = latest_successful_execution(access_group)\n",
"print(f\"Execution group: {access_group.key}\")\n",
"for output in execution.outputs:\n",
" print(f\" {output.filename:20s} {output.url}\")"
]
},
{
Expand Down Expand Up @@ -378,7 +364,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.14.4"
"version": "3.13.14"
}
},
"nbformat": 4,
Expand Down
Loading