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.

diagnostix: diagnostics of geophysical fields

diagnostix computes what a geophysical field says, physically and statistically: kinematics (velocity gradients, advection, frontogenesis, the geostrophic residual), column quantities (N², mixed-layer depth, boundary-layer height, column integrals), budgets, climatologies and anomalies, spectra, area-weighted EOFs and skill scores. It sits at GeoNumerics tier 2, above gridax, whose differences and named diagnostics it builds on, and holds the maths that xrops wraps for xarray. It absorbs what was planned as skillax. Status: scaffold built; the public modules are planned.

At a glance

Layer, tierGeoNumerics, tier 2
Importsgridax, geophysix, pipekit-array, NumPy; JAX and xarray optional
Imported byxrops; sesmax-ocean (planned)
Takes overthe maths of xrops ocn, atm (vertical and wind), budgets, anomaly, the spectra in transforms and wavelets, and the scores in metrics; somax’s eval/metrics.py
Does not ownthe DataArray API (xrops); differences, metrics and the diagnostics gridax already names (gridax); facts at a point (geophysix); bases and generic signal processing (functax); benchmark contracts and leaderboards (pipekit-evaluate); extremes modelling (xtremax)
Statusthe scaffold, the test harness and the shared reductions are built in diagnostix; the public modules are planned
Tracked ingeostack#309; the layer map; the companion gridax and functax designs
where diagnostix sits · GeoNumerics tier 2

Where diagnostix sits · geonumerics tier 2.

diagnostix sits one tier above gridax, whose differences and metrics every diagnostic is built from. This page is the design; core types, algorithms and the code survey are in diagnostix: design details.

The problem

A plume’s emission rate is checked with diagnostics before anyone trusts it, and every one of them lives in xrops, on xarray, in NumPy and SciPy (as read on 5 Nov 2026):

StepThe diagnosticWhere it is coded today
How deep the plume mixesboundary-layer height from the bulk Richardson numberxrops pbl_height_bulk_richardson
The enhancement over backgrounda climatology and the anomaly from itxrops calculate_climatology, calculate_anomaly and their smoothed forms
The rate by mass balancethe flux through the faces of a box around the sourcexrops boundary_flux (which sums over every face of the field, not a chosen box), control_volume_integral, budget_residual
Which scales a reconstruction resolvespower spectra and the PSD scorexrops power_spectrum, isotropic_power_spectrum, psd_score, resolved_scale
How good the transport model isRMSE, bias, correlation, spread–skillxrops metrics (rmse, bias, correlation, spread_skill_ratio, rank_histogram)
The ocean side, for sesmaxvorticity, strain, Okubo–Weiss, geostrophy, kinetic energyxrops ocn/kinematics.py; somax eval/metrics.py; gridax operators/diagnostics.py

Because they sit on xarray, none of them traces under JAX or differentiates, so a model that wants a diagnostic inside its loop or as a loss writes it again: kinetic energy, enstrophy and geostrophic imbalance each exist in xrops, in somax and in gridax. And xrops’ diagnostics run on geoops’ difference kernels, so the xarray toolkit depends on the GeoArray toolkit for maths that belongs to neither.

What a field says

A diagnostic is a function of one or more fields on a grid that returns a smaller or more telling field: a derivative combination, an integral, a residual, a spectrum, a decomposition or a score. Each is built from gridax’s differences and metrics and geophysix’s constants. Vorticity, the strains, Okubo–Weiss and the geostrophic velocity below are gridax’s functions, on every grid it supports (decision 4); they are written here because what diagnostix owns is built from them.

Kinematics. With u, v the horizontal velocity and f the Coriolis parameter, vorticity and the two strains are

ζ=∂xv−∂yu\zeta = \partial_x v - \partial_y u
σn=∂xu−∂yv\sigma_n = \partial_x u - \partial_y v
σs=∂xv+∂yu\sigma_s = \partial_x v + \partial_y u

The Okubo–Weiss parameter Okubo, 1970Weiss, 1991 W = σₙ² + σₛ² − ζ² separates strain-dominated from rotation-dominated flow, and the geostrophic velocity from sea-surface height η is u_g = −(g / f) ∂ᵧη, v_g = (g / f) ∂ₓη.

Columns. The buoyancy frequency is N² = −(g / ρ₀) ∂ρ/∂z with ρ from geophysix’s equation of state. The boundary-layer height is the lowest z where the bulk Richardson number reaches a critical value Ri_c, with θ_v the virtual potential temperature:

Rib(z)=gθv,0(θv(z)−θv,0)zu(z)2+v(z)2\mathrm{Ri}_b(z) = \frac{g}{\theta_{v,0}} \frac{(\theta_v(z) - \theta_{v,0}) z}{u(z)^2 + v(z)^2}

Budgets. For a quantity q carried by the velocity u, with source S, over a control volume V with surface ∂V and outward normal n,

ddt∫VqdV+∮∂Vqu⋅ndS=∫VSdV\frac{d}{dt} \int_V q dV + \oint_{\partial V} q \mathbf{u} \cdot \mathbf{n} dS = \int_V S dV

and the residual of that balance is the diagnostic. For a plume in steady state, the flux through the faces of a box around the source is the emission rate, Q = ∮ Ω’ (u · n) dl, with Ω’ the column enhancement.

Climate. With q̄(d) the climatology at calendar day d (on a leap-year calendar, so each date keeps one slot in every year), the anomaly is q’(t) = q(t) − q̄(d(t)); trends, detrending and temporal filters act on q’.

Spectra. With q̂(k) the Fourier transform of q, the power spectrum is P(k) = |q̂(k)|², the isotropic spectrum averages it over rings of |k|, and the spectral flux Π(k) sums the nonlinear transfer below k. Cross, coherence and rotary spectra and wavelets follow the same pattern.

EOFs. With X the anomaly matrix (time × space) and W the diagonal of cell areas from gridax, the area-weighted EOFs come from the SVD of the weighted anomalies:

W1/2X⊤=UΣV⊤W^{1/2} X^\top = U \Sigma V^\top

The EOFs are W^(−1/2) U, the principal components VΣ, and the i-th explains a fraction σᵢ² / ∑ⱼ σⱼ² of the variance.

Skill. With ŷ a prediction and y the truth over valid cells with weights w, RMSE = (∑ w (ŷ − y)² / ∑ w)^½, the bias, the correlation, and for ensembles the spread–skill ratio and the rank histogram.

Modules and boundaries

Seven modules, each created by its first feature issue. Functions over a grid or an axis take plain arrays, and a DataArray there raises an error; elementwise functions keep a DataArray’s labels. xrops keeps the names, attributes and units.

ModuleOwnsComes from
diagnostix.kinematicsthe velocity gradient, shear and curvature vorticity, advection, frontogenesis, the ageostrophic velocity, the geostrophic residualxrops ocn/kinematics.py, metrics/_src/physical.py
diagnostix.columnsN², lapse rate, first crossings, mixed-layer depth, boundary-layer height, column integralsxrops ocn/kinematics.py (N², mixed layer), atm/_src/vertical.py
diagnostix.budgetscontrol volumes, boundary fluxes, budgets and their residualsxrops budgets/; the flux through a region’s own boundary is new
diagnostix.climateclimatologies, anomalies, trends, running meansxrops anomaly/; trends are new
diagnostix.spectrapower, isotropic, cross, coherence, rotary and wavelet spectra, spectral fluxes, slopesxrops transforms/_src/fourier.py, wavelets/_src/
diagnostix.eofsarea-weighted EOFs and their reading: explained variance, principal components, truncationxrops transforms/_src/decompose.py (eof), which is unweighted scikit-learn PCA; the area weighting is new
diagnostix.skillpointwise, ensemble, spectral and physical scores: RMSE, bias, correlation, CRPS, spread–skill, rank histogram, PSD score, resolved scale, geostrophic imbalancexrops metrics/; somax eval/metrics.py

What diagnostix owns, and what it hands off

The test for every name: does it take a field and say something about it, physically or statistically, and does no library below already name it? Then diagnostix owns it. A one-line combination of functions the stack has (absolute vorticity, eddy kinetic energy) is written by the caller.

Neighbourdiagnostix ownsThe neighbour ownsThe line
xropsthe mathsthe DataArray API: names, attributes, units, dask chunkingxrops calls diagnostix kernels
gridaxthe diagnostics gridax does not namegrids, masks, derivatives, area means, and the diagnostics it names: curl, divergence, kinetic energy, strain, Okubo–Weiss, geostrophic velocity, shallow-water potential vorticitydiagnostix builds on them and defines no second name (decision 4)
geophysixwhatever differentiates, integrates or averages a fieldfacts at a point: density, θ, wind speed, Coriolis, constantsa fact at a point is geophysix’s
functaxthe EOFs, their area weights and their readingbases and generic signal processingfunctax’s eof_basis is the oracle (decision 6)
traceraxEulerian diagnostics of fieldsLagrangian analysis and trajectory skillvorticity is Eulerian, FTLE is tracerax’s
pipekit-evaluatethe scoresbenchmark contracts, evaluation protocols, leaderboardsa score is a function here; a benchmark that runs it is pipekit’s
xtremaxanomalies and climatologiesextremes modelling: GEV, GPD, return levelsxtremax fits extremes to what diagnostix extracts

What moves in

FromWhatIts users then import
xropsthe maths of ocn, atm/_src/vertical.py, budgets, anomaly, the spectra in transforms and wavelets, and metricsdiagnostix and gridax underneath; xrops keeps every DataArray function and Operator, and metrics/leaderboard.py goes to pipekit-evaluate
somaxeval/metrics.py: kinetic energy, enstrophy, RMS divergence, geostrophic imbalance, QG balance residualgridax, diagnostix.kinematics, diagnostix.skill; sesmax-core inherits nothing to move
the skillax planskill scoresdiagnostix.skill (decision 2)

In use

Checking a plume’s emission rate: how deep it mixes, its enhancement over background, its rate by mass balance, and how well the transport model reproduces it. Every diagnostix name is proposed, by the issues of Waves 1, 2 and 4; jitting is the caller’s.

# Shapes: Z levels; T times; Ny × Nx lon/lat cells

import gridax
from diagnostix import budgets, climate, columns, skill

# today (gridax)
grid = gridax.SphericalAGrid2D.from_coords(lat=lat, lon=lon)
cell_area = gridax.area_weights(grid)  # → (Ny, Nx)

# --- how deep the plume mixes ---
# proposed (diagnostix#22)
# lowest z where Ri_b(z) = g (θ_v − θ_vs) (z − z_s) / (θ_vs |u − u_s|²) reaches Ri_c
mixing_height = columns.boundary_layer_height(  # (Z, Ny, Nx) → (Ny, Nx)
    virtual_potential_temperature, eastward_wind, northward_wind, height, axis=0
)

# --- enhancement over background ---
# proposed (diagnostix#25)
# d, the calendar day on a leap-year calendar, 1 … 366
day = climate.calendar_day(month, day_of_month)  # → (T,)
# Ω̄(d), the mean of each calendar day
daily = climate.climatology(column, day, axis=0)  # (T, Ny, Nx) → (366, Ny, Nx)
# proposed (diagnostix#26)
# Ω' = Ω − Ω̄(d(t))
enhancement = climate.anomaly(column, daily, day, axis=0)  # → (T, Ny, Nx)

# --- the rate by mass balance ---
# proposed (diagnostix#23)
# a boolean region, made into signed boundary faces once, on the host
box = budgets.ControlVolume.from_region(source_region, grid)  # (Ny, Nx) → volume
# Q = ∮ Ω' (u · n) dl over the faces of the box
rate = budgets.boundary_flux(  # (T, Ny, Nx) → (T,)
    enhancement, eastward_wind_pbl, northward_wind_pbl, grid, box
)

# --- skill of the transport model ---
# proposed (diagnostix#12)
# RMSE = (∑ w (ŷ − y)² / ∑ w)^½, with w the cell areas
error = skill.rmse(  # (T, Ny, Nx) → (T,)
    simulated, enhancement, weights=cell_area, axis=(-2, -1)
)

Each call is a pure function of the array API standard, so it runs on NumPy for xrops, and the same rmse and boundary_flux trace and differentiate under JAX inside a training loss for an emulator of the transport model, where today they cannot.

Integration across the stack

Two libraries would import diagnostix, and one model’s metrics retire into it.

ConsumerUses todayWith diagnostix
xropsevery diagnostic written on xarray in NumPy and SciPy, its differences through geoopsthe same DataArray functions and Operators, each a thin wrapper over a diagnostix or gridax function; differences through gridax, so xrops’ calculus no longer needs geoops
sesmax-ocean (planned)—kinematics, spectra and skill as in-loop diagnostics and losses
somaxeval/metrics.pyretires with somax; sesmax-ocean imports diagnostix instead

For an xrops user nothing changes; inside xrops the kernel moves:

# Today: xrops computes N² on xarray with geoops' difference kernels
# today (xrops)
from xrops.ocn import brunt_vaisala_frequency

# After: the same function, a wrapper over the array function
# proposed (diagnostix#20)
from diagnostix.columns import buoyancy_frequency_squared

Decisions and open questions

Eleven decided, one open. Each entry gives the position first, then the trade-off. The decisions of 24 Nov 2026 and the measurements behind them are in diagnostix#15.

1. Layer: GeoNumerics tier 2

Decided (5 Nov 2026, on the layer map). diagnostix imports gridax (tier 1), geophysix (tier 0) and pipekit-array (Core). xrops and sesmax-ocean sit above it. Dependencies (24 Nov 2026): NumPy, gridax, geophysix and pipekit-array[numpy,compat], all required. functax, integrix and gaussx need JAX for what diagnostix would use, so functax is a test reference and the others are not imported.

2. One library for physical and statistical diagnostics

Decided (5 Nov 2026). The skill scores planned for a separate skillax live here. A PSD score and a resolved scale need the same spectra as an energy-flux diagnostic, and a geostrophic-imbalance score needs the same kinematics; two libraries would import each other.

3. The DataArray API stays in xrops

Decided (5 Nov 2026, on the layer map). diagnostix takes arrays and a gridax grid; its elementwise functions also keep a DataArray’s labels, and the others refuse one, so labels are never lost silently (24 Nov 2026). Names, attributes, units, CF conventions and dask chunking are xrops’, which wraps each kernel.

4. One home per diagnostic, on every grid

Decided (24 Nov 2026, geostack#287). gridax owns a diagnostic it names, on every grid it supports, and diagnostix owns everything else. gridax’s functions dispatch on the grid type, so it registers its collocated grids for the strains, Okubo–Weiss, the geostrophic velocity and the shallow-water potential vorticity (gridax#565), and Okubo–Weiss of a reanalysis and of a model’s output is one call. diagnostix holding every collocated kernel would give Okubo–Weiss one name on a C-grid and another on an A-grid.

5. Array-API code, JAX optional

Decided (24 Nov 2026). Every function is written once in the Python array API standard, through pipekit_array.functions, so xrops can compute a diagnostic without JAX and a model can trace the same function. Nothing inside the library calls jax.jit; the caller jits once, at the top. Wavelets port too, because xrops’ Morlet, Paul and derivative-of-Gaussian transforms are FFTs; only their significance test needs SciPy and stays on the host, and the PyWavelets transforms stay in xrops. JAX and Equinox alone would be simpler code, but xrops would need JAX.

6. EOFs without functax

Decided (24 Nov 2026; it replaces the decision of 5 Nov, which took the basis from functax). diagnostix.eofs takes the SVD of the area-weighted anomalies itself. functax’s eof_basis requires JAX and takes no weights, so it is the oracle instead. diagnostix supplies the area weights from gridax, the truncation and the reading of the modes.

7. Scores here, benchmarks in pipekit-evaluate

Decided (1 Dec 2026, diagnostix#85). A score is a function of a prediction and a truth; a benchmark that fixes the data, the splits and the leaderboard is pipekit-evaluate’s. xrops’ rank_methods moves there, as a ranking of an EvaluationReport (pipekit#354), not here. Of the other formulas xrops still holds, the segmented PSD, CSD and coherence move to diagnostix.spectra (diagnostix#87), and gradient_difference and phase_shift_error to diagnostix.skill (diagnostix#88); the energy distance and MMD belong to kernellib, and xrops keeps a NumPy copy of energy_distance because it runs without JAX; ssim, centroid_displacement, instance matching, residual binning and wasserstein_1 stay in xrops.

8. The continuous wavelet transform goes to functax

Decided (1 Dec 2026, geostack#355, diagnostix#95). The 1-D transform, its Morlet, Paul and derivative-of-Gaussian mothers, the scale grid and the cone of influence move from diagnostix.spectra to functax.transform, and the directional 2-D Morlet transform moves there from xrops. A transform is a basis, and functax owns the transforms. diagnostix keeps the statistics on top of it: wavelet power, its significance and the local spectrum. This replaces the part of decision 5 that ported the wavelet transforms here. The cost is that functax’s transforms must run on NumPy as functax.filter does, or diagnostix loses its NumPy path (functax#197, functax#198).

9. One EOF implementation, in functax

Decided (1 Dec 2026, geostack#355, diagnostix#95). functax.basis.eof_basis is the one EOF. It gains weights and a NumPy path (functax#200); diagnostix.eofs keeps the explained variance, the projection and the reconstruction on top of it, and geoops’ fit_pca calls it. This replaces decision 6: the objection there was that eof_basis requires JAX and takes no weights, and both are being removed. diagnostix still supplies the area weights from gridax, the truncation and the reading of the modes.

10. p-values stay with the caller

Decided (1 Dec 2026, geostack#355, diagnostix#95). A test in diagnostix returns a statistic and its degrees of freedom, as diebold_mariano already does, and the caller takes the p-value from scipy.stats.

11. Buoyancy frequency and lapse rate stay in diagnostix

Decided (1 Dec 2026, geostack#355, diagnostix#95). Both need a vertical derivative of a column, which diagnostix#20 placed in diagnostix. The difference along an uneven vertical coordinate itself is gridax’s (gridax#613).

12. Bootstrap resampling, sliced Wasserstein and C2ST stay open

Open (1 Dec 2026, geostack#355, diagnostix#95). No library owns them today, and C2ST exists only as a private helper in rbig’s benchmarks.

Roadmap

Six waves, each a GitHub issue epic in the diagnostix repository.

WaveDeliversEndsNeeds
0. Scaffoldthe repository from the library template, with its rules; the test harness (closed forms, stored xrops values, library oracles); grouped sums and masked reductions——
1. Kinematics and columnsdiagnostix.kinematics, diagnostix.columns; gridax’s collocated registrationsthe maths of xrops ocn and atm/vertical0
2. Budgets and climatediagnostix.budgets, diagnostix.climatethe maths of xrops budgets and anomaly0
3. Spectra and EOFsdiagnostix.spectra, diagnostix.eofsthe maths of xrops transforms/_src/fourier.py, its eof, and wavelets0
4. Skilldiagnostix.skillthe maths of xrops metrics; somax eval/metrics.py1, 3
5. Consumers switchxrops onto diagnostix; sesmax-ocean from the startthe copies1–4

Waves 1, 2 and 3 can run side by side.

Sources

References
  1. Okubo, A. (1970). Horizontal dispersion of floatable particles in the vicinity of velocity singularities such as convergences. Deep-Sea Research, 17, 445–454.
  2. Weiss, J. (1991). The dynamics of enstrophy transfer in two-dimensional hydrodynamics. Physica D, 48, 273–294.
  3. Vogelezang, D. H. P., & Holtslag, A. A. M. (1996). Evaluation and model impacts of alternative boundary-layer height formulations. Boundary-Layer Meteorology, 81, 245–269.