{ "cells": [ { "cell_type": "markdown", "id": "0", "metadata": {}, "source": [ "# A1 – Preparing Reference Data for Verification\n", "\n", "This annex shows how to download the two reference datasets used to benchmark AIFS forecasts in the user-guide notebooks:\n", "\n", "1. **MeteoSwiss automatic-station observations** — hourly 2 m temperature and 10 m wind speed, downloaded via [meteora](https://github.com/martibosch/meteora) and stored in the [stationbench](https://github.com/martibosch/stationbench) format.\n", "2. **ERA5 reanalysis** — 2 m temperature and 10 m wind speed from the [Copernicus CDS API](https://cds.climate.copernicus.eu), also stored in stationbench format.\n", "\n", "Both outputs are saved as NetCDF files and loaded lazily with xarray in the main notebooks.\n", "\n", "> **Prerequisites**: a valid `~/.cdsapirc` file for ERA5 downloads (see the [CDS API documentation](https://cds.climate.copernicus.eu/how-to-api))." ] }, { "cell_type": "code", "execution_count": null, "id": "1", "metadata": {}, "outputs": [], "source": [ "import datetime as dt\n", "import pathlib\n", "import tempfile\n", "\n", "import cdsapi\n", "import numpy as np\n", "import xarray as xr\n", "from meteora import clients, units, utils\n", "from shapely import geometry" ] }, { "cell_type": "markdown", "id": "2", "metadata": {}, "source": [ "## Configuration\n", "\n", "Adjust the parameters below to match your experiment." ] }, { "cell_type": "code", "execution_count": null, "id": "3", "metadata": {}, "outputs": [], "source": [ "# forecast window\n", "start_date = dt.datetime(2025, 6, 20, 0, tzinfo=dt.UTC)\n", "lead_time = 240 # hours\n", "end_date = start_date + dt.timedelta(hours=lead_time)\n", "\n", "# spatial bounding box (lat/lon)\n", "lat_slice = (44.5, 48.5)\n", "lon_slice = (4.5, 11.5)\n", "\n", "# output directory\n", "data_dir = pathlib.Path(\"../data/stationbench\")\n", "data_dir.mkdir(parents=True, exist_ok=True)\n", "\n", "# output file paths\n", "experiment = \"heatwave-2025-jun-ens\"\n", "stations_filepath = data_dir / f\"{experiment}-stations.nc\"\n", "era5_filepath = data_dir / f\"{experiment}-era5.nc\"" ] }, { "cell_type": "markdown", "id": "4", "metadata": {}, "source": [ "## 1. MeteoSwiss station observations\n", "\n", "We use [meteora](https://github.com/martibosch/meteora) to download hourly 2 m temperature and 10 m wind speed from MeteoSwiss automatic stations within the bounding box defined above.\n", "The observations are then converted from SI units (K, m/s) and written to a stationbench-ready NetCDF file with dimensions `(time, station_id)`." ] }, { "cell_type": "code", "execution_count": null, "id": "5", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "c62d9124a50d4c6090e651431011763f", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Stations: 0%| | 0/158 [00:00, ?station/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "Saved ../data/stationbench/heatwave-2025-jun-ens-stations.nc\n" ] }, { "data": { "text/html": [ "
<xarray.Dataset> Size: 4MB\n",
"Dimensions: (time: 1441, station_id: 157)\n",
"Coordinates:\n",
" * time (time) datetime64[ns] 12kB 2025-06-20 ... 2025-06-30\n",
" * station_id (station_id) <U3 2kB 'ABO' 'AEG' 'AIG' ... 'WFJ' 'WYN' 'ZER'\n",
" longitude (station_id) float64 1kB ...\n",
" latitude (station_id) float64 1kB ...\n",
"Data variables:\n",
" 2m_temperature (time, station_id) float64 2MB ...\n",
" 10m_wind_speed (time, station_id) float64 2MB ...<xarray.Dataset> Size: 332MB\n",
"Dimensions: (time: 1, prediction_timedelta: 40, latitude: 721,\n",
" longitude: 1440)\n",
"Coordinates:\n",
" * time (time) datetime64[ns] 8B 2025-06-20\n",
" * prediction_timedelta (prediction_timedelta) timedelta64[ns] 320B 06:00:0...\n",
" * latitude (latitude) float64 6kB 90.0 89.75 ... -89.75 -90.0\n",
" * longitude (longitude) float64 12kB 0.0 0.25 0.5 ... 359.5 359.8\n",
"Data variables:\n",
" 2t (time, prediction_timedelta, latitude, longitude) float32 166MB ...\n",
" 10si (time, prediction_timedelta, latitude, longitude) float32 166MB ..."
],
"text/plain": [
"