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.

V4 — Process-Evaluation Metrics

Pointwise scores compare amplitudes — a model that smooths fields can keep RMSE small while quietly violating the underlying physics. V4 metrics test physical consistency directly: geostrophic balance, mass conservation, density stratification, heat budget closure. The numbers are properties of a single dataset, not a pred-vs-ref comparison, so each candidate model is scored on its own.

This notebook exercises V4 on a real Gulf Stream slice with three datasets:

  • GLORYS12 (glorys12_3d_gulfstream_2023-06.nc) — 5 days, 22 depths, 1/12° — treated as the truth. Carries zos, uo, vo, thetao, so.

  • DUACS L4 (duacs_gulfstream_2023-06.nc) — same window, 1/8°, SSH only (adt). The real observational “model”.

  • Smoothed twin — synthetic baseline, gaussian-smoothed GLORYS. Same fields as GLORYS but spatially blurred.

Different metrics see different subsets of the three because each metric needs different inputs:

MetricGLORYSDUACSSmoothed
RMSE on SSH0 (sanity)✓✓
GeostrophicBalanceError✓✓ (derive u, v from SSH)✓
DivergenceError✓— (no uo/vo)✓
DensityInversionFraction✓—✓
HeatBudgetResidual✓—✓

1 — Load the three datasets

Both cached netCDFs cover 2023-06-01 → 2023-06-05 over [-70, -50] × [30, 45]. Section 11 has the copernicusmarine snippets for rebuilding the cache.

GLORYS: {'time': 5, 'depth': 22, 'lat': 181, 'lon': 241} ['uo', 'vo', 'thetao', 'so', 'zos']
DUACS: {'time': 5, 'lat': 181, 'lon': 241} ['adt']

Build the smoothed twin

A 2-D gaussian filter (σ = 2 grid cells ≈ 18 km) is applied per (time, depth) slice. NaN-aware: land mask is preserved, fill-with-mean during the filter then re-mask. The twin retains GLORYS’s structure but drops sub-mesoscale gradients — the kind of quiet damage RMSE alone can miss.

Snapshot at the surface, day 0

<Figure size 1300x350 with 4 Axes>

2 — Pointwise SSH skill (the V1 lens)

RMSE on SSH against GLORYS, after removing each field’s basin-mean to put DUACS and GLORYS on the same reference. Both candidates look acceptable; smoothing barely registers.

Loading...

3 — GeostrophicBalanceError

How well does each dataset’s velocity match the geostrophic balance implied by its SSH? The metric returns a single residual norm per (time) snapshot; we average over time.

  • GLORYS carries its own uo/vo so we score it directly.

  • DUACS has no velocities; we derive geostrophic u/v from adt via xrtoolz.ocn.geostrophic_velocities and score the resulting Dataset (this is a self-consistency check by construction, but useful as a sanity floor).

  • Smoothed twin uses its own (smoothed) uo/vo.

Loading...

DUACS scores ≈ 0 because its velocities are geostrophic by construction — the ideal “self-consistent” floor. GLORYS, run with its prognostic velocities, has a small but non-zero residual (real ageostrophic flow). The smoothed twin lands at essentially the same value as GLORYS: smoothing both SSH and (u, v) consistently preserves the geostrophic balance — gradients of η and velocities damp together, so the residual norm is unchanged. This metric is robust to symmetric smoothing but would catch unbalanced edits.

4 — DivergenceError

Horizontal divergence of (u, v) should be small in a near-incompressible flow at scales where vertical velocity is negligible. The metric returns a basin-mean residual per timestep; we time-average.

Loading...

Smoothing damps the high-frequency divergence signal, so the residual is roughly 3× smaller on the smoothed twin. By the metric’s own scale, the smoothed twin “looks better” — but only because it has less velocity structure to be divergent about. This is a useful warning: a single physical-consistency score, taken in isolation, can reward over-smoothing. Pair it with a metric that penalises lost signal (RMSE, GradientDifference) for an honest reading.

5 — DensityInversionFraction

Fraction of grid cells where ∂ρ/∂z < 0 — a stratification-stability check. We use a simple linear EOS for the demo (gsw is optional); the metric is robust to the choice.

Loading...

Both fractions are low (the Gulf Stream is well-stratified in summer), with the smoothed twin slightly different from truth because horizontal smoothing of θ and S independently can break local equation-of-state coherence.

6 — HeatBudgetResidual

The heat-budget residual: ∂θ/∂t + ∇·(uθ) — a closure check on the temperature equation given (θ, u, v). Without surface heat flux or vertical velocity, the budget cannot close exactly even on truth, but the relative magnitude across candidates is informative. We integrate the squared residual over a control volume (full domain, top 100 m) and report the RMS.

Loading...

Same trap as DivergenceError: smoothing damps both the tendency ∂θ/∂t and the advection ∇·(uθ) together, so the residual gets smaller on the smoothed twin — the budget looks better-closed by ≈ 3×. The lesson is the same: closure metrics reward smoother fields whether or not the underlying physics is preserved. Use closure as one signal among many.

7 — Side-by-side summary

Pointwise vs process-consistency for the two candidates we can score on every metric.

Loading...

Reading the row. SSH RMSE prefers the smoothed twin (it’s GLORYS, just blurred), while the closure-style consistency metrics — Divergence, Heat-budget — also score the smoothed twin “better” for the wrong reason: smoothing damps both sides of each equation. Geostrophic err is the only metric here that’s invariant to symmetric smoothing — it correctly reports the smoothed twin and GLORYS as physically equivalent. The takeaway is to read process metrics as a vector, never any single score in isolation, and to pair them with signal-preservation metrics (RMSE, GradientDifference) that punish smoothing for what it is.

8 — Bonus: a Sequential preprocessing pipeline

Every V4 metric expects a Dataset with a specific set of variable names and a uniform grid. A Sequential of preprocessing operators standardises that contract once and applies it identically to every candidate before scoring.

Sequential (3 ops)
├── ValidateCoords()
├── RenameVariables(mapping={'zos': 'ssh', 'uo': 'u', 'vo': 'v'})
└── RemoveMean(dims=['lat', 'lon'])

Sequential (3 ops)
Step  Operator                                                       Input Signature                                      Output Signature                                   
----  -------------------------------------------------------------  ---------------------------------------------------  ---------------------------------------------------
0     ValidateCoords()                                               (time=5, depth=22, lat=181, lon=241); dtype=float64  (time=5, depth=22, lat=181, lon=241); dtype=float64
1     RenameVariables(mapping={'zos': 'ssh', 'uo': 'u', 'vo': 'v'})  (time=5, depth=22, lat=181, lon=241); dtype=float64  (time=5, depth=22, lat=181, lon=241); dtype=float64
2     RemoveMean(dims=['lat', 'lon'])                                (time=5, depth=22, lat=181, lon=241); dtype=float64  (time=5, depth=22, lat=181, lon=241); dtype=float64

Applied to GLORYS surface and the smoothed twin’s surface:

Loading...

9 — Bonus: full Graph — preprocessing and the V4 scorecard in one DAG

The same preprocessing wired onto an Input(name='dataset'), then a terminal Node per V4 metric. One scorecard(dataset=...) call returns every score for any candidate.

Graph (1 input, 2 outputs)
Step  Operator                                                                                       Input Signature                                      Output Signature                                   
----  ---------------------------------------------------------------------------------------------  ---------------------------------------------------  ---------------------------------------------------
1     Sequential([ValidateCoords(), RenameVariables(mapping={'zos': 'ssh', 'uo': 'u', 'vo': 'v'})])  (time=5, depth=22, lat=181, lon=241); dtype=float64  (time=5, depth=22, lat=181, lon=241); dtype=float64
2     DivergenceError(u_var='u', v_var='v', lat='lat', lon='lon')                                    (time=5, depth=22, lat=181, lon=241); dtype=float64  (time=5, depth=22, lat=181, lon=241); dtype=float64
3     GeostrophicBalanceError(ssh_var='ssh', u_var='u', v_var='v', lat='lat', lon='lon', g=9.80665)  (time=5, depth=22, lat=181, lon=241); dtype=float64  (time=5, depth=22, lat=181, lon=241); dtype=float64
Loading...

Same numbers as the per-cell tables, but produced by a single graph that V6 can later attach panel operators to.

10 — Takeaway

Process-evaluation metrics measure physical consistency, but they are not free. Closure-style metrics (DivergenceError, HeatBudgetResidual) damp together with their inputs and so reward over-smoothing; balance-style metrics (GeostrophicBalanceError) are robust to symmetric smoothing but only catch unbalanced edits. The honest validation pipeline reads them as a vector alongside V1 amplitude metrics — a model is good when all of them agree, and any disagreement is a diagnostic about what kind of error is present. With Sequential and Graph, the preprocessing-then-scoring path is one reusable object you can point at any new model run.

11 — Rebuilding the cache

import copernicusmarine as cm
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-05")

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_3d = cm.open_dataset(
    dataset_id="cmems_mod_glo_phy_my_0.083deg_P1D-m",
    variables=["uo", "vo", "thetao", "so", "zos"],
    minimum_depth=0.0, maximum_depth=100.0,
    **bbox, **window,
).load()
glorys_3d.to_netcdf(".cache/glorys12_3d_gulfstream_2023-06.nc")