Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

V1 — Scales of Evaluation

A single aggregate RMSE often hides the shape of model error. This notebook ties the three V1 operators together on two real Copernicus Marine products over the Gulf Stream:

RoleProductVariableNative resolution
Reference (truth)GLORYS12V1 ocean reanalysis (GLOBAL_MULTIYEAR_PHY_001_030)zos (sea surface height)1/12° (~9 km)
ModelDUACS L4 reprocessed altimetry (SEALEVEL_GLO_PHY_L4_MY_008_047)adt (absolute dynamic topography)1/8° (~14 km)

The two products use different references (DUACS ADT = SLA + MDT; GLORYS zos = SSH above geoid), so we subtract the per-timestep spatial mean from each to compare anomaly fields rather than absolute values. We also regrid the higher-resolution GLORYS onto the DUACS grid (rather than the other way around) — coarsening the truth to the observation grid avoids fabricating fine scales the lower-resolution DUACS doesn’t actually resolve.

Each preprocessing path is expressed as an xrtoolz Sequential pipeline so the operator config is introspectable end to end. The V1 metrics then run on the two outputs:

  1. EvaluateByRegion — split skill by Gulf Stream core / shelf / offshore.

  2. SkillByLeadTime — skill across the 15 days of the window.

  3. FrequencyBandSkill — mesoscale (50–500 km) vs submesoscale (10–50 km).

1 — Load the two products

Cached netCDFs cover 2023-06-01 → 2023-06-15 over [-70, -50] × [30, 45]. Section 8 has the copernicusmarine snippets for rebuilding the cache (requires CMEMS credentials in .env).

DUACS: {'time': 15, 'latitude': 120, 'longitude': 160} vars: ['adt']
GLORYS: {'time': 15, 'latitude': 181, 'longitude': 241} vars: ['zos']

2 — Preprocessing pipelines

Both pipelines compose entirely from operators shipped in xrtoolz:

OperatorRole
SelectVariablesdrop unused vars
ValidateCoordsrename latitude/longitude → lat/lon, attach CF units
RenameVariablesgive the variable a common name (ssh) so both pipelines speak the same vocabulary
RegridLikebilinear regrid onto another Dataset’s (lat, lon) grid
RemoveMeansubtract per-timestep spatial mean (cheap anomaly without climatology)
DUACS model pipeline (structure + shapes):
Sequential (4 ops)
├── SelectVariables(variables=['adt'])
├── ValidateCoords()
├── RenameVariables(mapping={'adt': 'ssh'})
└── RemoveMean(dims=['lat', 'lon'])

Sequential (4 ops)
Step  Operator                                 Input Signature                                        Output Signature                                     
----  ---------------------------------------  -----------------------------------------------------  -----------------------------------------------------
0     SelectVariables(variables=['adt'])       (time=15, latitude=120, longitude=160); dtype=float64  (time=15, latitude=120, longitude=160); dtype=float64
1     ValidateCoords()                         (time=15, latitude=120, longitude=160); dtype=float64  (time=15, lat=120, lon=160); dtype=float64           
2     RenameVariables(mapping={'adt': 'ssh'})  (time=15, lat=120, lon=160); dtype=float64             (time=15, lat=120, lon=160); dtype=float64           
3     RemoveMean(dims=['lat', 'lon'])          (time=15, lat=120, lon=160); dtype=float64             (time=15, lat=120, lon=160); dtype=float64           

GLORYS truth pipeline (structure + shapes):
Sequential (5 ops)
├── SelectVariables(variables=['zos'])
├── ValidateCoords()
├── RenameVariables(mapping={'zos': 'ssh'})
├── RegridLike(target_shape={'lat': 120, 'lon': 160},
│              dims=['lat', 'lon'],
│              method='linear')
└── RemoveMean(dims=['lat', 'lon'])

Sequential (5 ops)
Step  Operator                                                                                 Input Signature                                        Output Signature                                     
----  ---------------------------------------------------------------------------------------  -----------------------------------------------------  -----------------------------------------------------
0     SelectVariables(variables=['zos'])                                                       (time=15, latitude=181, longitude=241); dtype=float64  (time=15, latitude=181, longitude=241); dtype=float64
1     ValidateCoords()                                                                         (time=15, latitude=181, longitude=241); dtype=float64  (time=15, lat=181, lon=241); dtype=float64           
2     RenameVariables(mapping={'zos': 'ssh'})                                                  (time=15, lat=181, lon=241); dtype=float64             (time=15, lat=181, lon=241); dtype=float64           
3     RegridLike(target_shape={'lat': 120, 'lon': 160}, dims=['lat', 'lon'], method='linear')  (time=15, lat=181, lon=241); dtype=float64             (time=15, lat=120, lon=160); dtype=float64           
4     RemoveMean(dims=['lat', 'lon'])                                                          (time=15, lat=120, lon=160); dtype=float64             (time=15, lat=120, lon=160); dtype=float64           

Pick a single day so the spatial-skill demos run on a 2D field; keep the full multi-day window for the lead-time demo.

Aggregate RMSE (m): 0.1246
<Figure size 1400x360 with 6 Axes>

3 — EvaluateByRegion — Gulf Stream core / shelf / offshore

Three latitude-band masks roughly tracking the GS jet core (35–40 °N), the shelf (north of jet), and the offshore (south of jet).

<xarray.Dataset> Size: 120B
Dimensions:  (region: 3)
Coordinates:
  * region   (region) <U8 96B 'core' 'shelf' 'offshore'
Data variables:
    ssh      (region) float64 24B 0.1701 0.1245 0.04687
<Figure size 500x300 with 1 Axes>

4 — SkillByLeadTime — skill across the 15-day window

The “lead_time” dim here is just calendar time across the window — a stand-in for forecast lead. Each daily slice is scored independently.

<xarray.DataArray 'ssh' (lead_time: 15)> Size: 120B
array([0.11285044, 0.11079514, 0.10976455, 0.11011367, 0.11197797,
       0.11622509, 0.12183196, 0.12464292, 0.12518927, 0.12337096,
       0.1207528 , 0.11749359, 0.11524241, 0.11473888, 0.11446557])
Coordinates:
  * lead_time  (lead_time) datetime64[ns] 120B 2023-06-01 ... 2023-06-15
Attributes:
    comment:        The absolute dynamic topography is the sea surface height...
    grid_mapping:   crs
    long_name:      Absolute dynamic topography
    standard_name:  sea_surface_height_above_geoid
    units:          m
<Figure size 600x300 with 1 Axes>

5 — FrequencyBandSkill — mesoscale vs submesoscale

Bands are {name: (low, high)} in physical units of the dim coords. The lat/lon coords carry units="degrees_north" / "degrees_east", so the operator converts spacing to kilometres internally — bands are therefore in cycles/km. The mesoscale band catches wavelengths 50–500 km; the submesoscale band 10–50 km.

<xarray.Dataset> Size: 144B
Dimensions:    (band: 2)
Coordinates:
  * band       (band) <U12 96B 'mesoscale' 'submesoscale'
    band_low   (band) float64 16B 0.002 0.02
    band_high  (band) float64 16B 0.02 0.1
Data variables:
    ssh        (band) float64 16B 0.1102 0.01037

Absolute band-limited RMSE depends on the variance available in each band. Normalise by the truth’s in-band RMS to see fraction of in-band variance the model fails to reproduce.

<Figure size 1000x320 with 2 Axes>

6 — Stacked summary

Three views, one comparison: a single aggregate RMSE conceals where and at what scale the model deviates from the observation-based reference.

<Figure size 1300x340 with 3 Axes>

7 — Operator configs are JSON-serializable

Both pipelines and every metric operator round-trip through get_config() to JSON — useful when attaching a validation graph to a model artifact.

{
  "variable": "ssh",
  "dims": [
    "lat",
    "lon"
  ],
  "bands": {
    "mesoscale": [
      0.002,
      0.02
    ],
    "submesoscale": [
      0.02,
      0.1
    ]
  },
  "metric": {
    "class": "RMSE",
    "config": {
      "variable": "ssh",
      "dims": [
        "lat",
        "lon"
      ]
    }
  }
}

8 — Rebuilding the cache

The cells below download both slices from CMEMS via copernicusmarine. Skip them if .cache/duacs_gulfstream_2023-06.nc and .cache/glorys12_gulfstream_2023-06.nc already exist. Requires COPERNICUSMARINE_SERVICE_USERNAME and COPERNICUSMARINE_SERVICE_PASSWORD in .env.

from dotenv import load_dotenv
import copernicusmarine as cm
load_dotenv()
bbox = dict(
    minimum_longitude=-70.0, maximum_longitude=-50.0,
    minimum_latitude=30.0,   maximum_latitude=45.0,
)
window = dict(start_datetime="2023-06-01", end_datetime="2023-06-15")

duacs = cm.open_dataset(
    dataset_id="cmems_obs-sl_glo_phy-ssh_my_allsat-l4-duacs-0.125deg_P1D",
    variables=["adt"], **bbox, **window,
).load()
duacs.to_netcdf(".cache/duacs_gulfstream_2023-06.nc")

glorys = cm.open_dataset(
    dataset_id="cmems_mod_glo_phy_my_0.083deg_P1D-m",
    variables=["zos"], **bbox, **window,
).load()
glorys.to_netcdf(".cache/glorys12_gulfstream_2023-06.nc")