Inside the trace or on disk, one grid or many: which container holds the window?
GeoStack · background · carriers · 2 of 2: many arrays
Abstract¶
One array has one carrier. A data-assimilation window has five ingredients in four geometries: an initial condition, a state, parameters, observations and the model read at the observations. Inside the trace they travel as a pytree of CFields; on disk, one grid is an xr.Dataset and the whole window is an xr.DataTree. The same North Atlantic window as the carrier arrays page carries every section.
At a glance¶
Two questions place every container: does it enter the trace, and how many grids does it hold?
in the trace
vector flat, for filterax and vardax57 600 entries without ghostsa view of one State, not a container
pytreeState, Params of CFieldsgrids not stored: the model holds any numberjit, grad, vmap, scan
Teal: device arrays with static layout. Blue: xarray, lazy, labelled, any size. Only one hop crosses the dashed line.
The running example¶
Notation¶
Indices: is the hour (frame), the grid row and column, an observation.
Table 2:The symbols used on this page.
| Symbol | Meaning | Shape | Unit |
|---|---|---|---|
| state at the window start and at hour | 3 fields (y, x) | m, m s⁻¹ | |
| background (GLORYS on the model grid) and its error covariance | (state,), (state, state) | m, m s⁻¹; squared | |
| observations of hour , their error covariance (diagonal) | (obs,), (obs, obs) | m; m² | |
| observation operator: read at hour ’s positions | (state,) → (obs,) | m → m | |
| the model run over one hour, from to | (state,) → (state,) | — | |
| gravity, linear drag, depth | (), (), (y, x) | m s⁻², s⁻¹, m | |
| the state as one flat vector | (state,) | mixed | |
| innovation, | (obs,) | m |
1 · The window as a model¶
The containers follow from what the window computes. Strong-constraint 4D-Var finds the initial state that, run forward, best fits the background and every observation in the window.
Each symbol in the cost (11) lives somewhere else. arrives on GLORYS’s grid, on GEBCO’s, on points and a swath. Only is on the model grid. Two conversions carry everything across:
background GLORYS 1/12°, 360 × 480
depth GEBCO 15″, 7 200 × 9 600
average 3 × 3, stagger ,
average 60 × 60 → depth, mask
the model grid: spherical C-grid, 1/4° (one scan)State: at T, at U, at V · Params: , , at Tthe only place grad flows
frames read at each obs position and hour
conversion 2 · out:
nadir points (obs,)+ hx, innovation
SWOT swath (line, pixel)+ hx, innovation
Everything else stays in the geometry it arrived in. and the innovation are written next to their observation.
2 · Inside the trace: a pytree of CFields¶
Inside jit, a state is an eqx.Module whose fields are CFields (sesmax#138, 23 Nov 2026). The class is the schema: its attribute names are the field names, its annotations say which are fields and which are parameters, and jax.tree sees only the arrays.
etaCField T
uCField U
vCField V
gravityfloat
dragfloat
depthCField T
What the trace seessix leaves; dims and staggers are static, so a run recompiles only when a field’s layout changes.What grad sees has SWState’s shape; has SWParams’ shape, depth included.
# Shapes: N_row × N_col = 120 × 160 interior cells, stored (122, 162)
# Units: η m; u, v m s⁻¹; g m s⁻²; γ s⁻¹; H m
# today (sesmax-core, sesmax#138)
class SWState(sesmax_core.State):
# η, stagger {y: center, x: center}
eta: gridax.CField
# u, stagger {y: center, x: right}
u: gridax.CField
# v, stagger {y: right, x: center}
v: gridax.CField
# today (sesmax-core, sesmax#138)
class SWParams(sesmax_core.Params):
# g
gravity: float
# γ
drag: float
# H(φ, λ) at T points: a parameter that is a field
depth: gridax.CFieldProgram 1:The shallow-water state and parameters as Equinox modules of CFields: the class is the schema, and the depth is a parameter that is a field.
The depth is why Params holds CFields too. It sits on the model grid like the state, grad reaches it as a leaf so it can be estimated, and on disk it goes in a node, not in attrs.
2.1 The DA vector, and the ghost ring inside it¶
Ensemble filters and variational solvers work on one flat vector. ravel_pytree (and sesmax-core’s state_to_vector) concatenate the leaves:
grey: ghost ring
The proposed vector concatenates each field’s interior, written and so on, with stacking a 2-D array into a column:
where , and each have shape = 120 × 160, in m and m s⁻¹.
| Expression | Reading |
|---|---|
| fields · cells = entries → 3 × 122 × 162 = 59 292 | |
| entries → 3 × 120 × 160 = 57 600 | |
| difference | entries → 1 692 |
| ✓ 2.9 % of the vector is overwritten by the next boundary fill |
Watch out: ghosts in the vector. An analysis increment on a ghost cell is overwritten by the next boundary fill, so in an ensemble filter it is wasted rank, and in a variational cost it is a direction the cost does not constrain. The U field’s east ghost column even lies outside the domain. Flatten the interior only.
2.2 Ensembles: name the member axis¶
jax.vmap over 32 members returns CFields whose data gained a leading axis. gridax names it for you: pipekit’s vmap rule (gridax#569) drops the mapped dim inside the trace and brings it back as "batch", so the dims always match the data. What it cannot know is that the axis means members; sesmax-core’s writer skips batch dims when it records a field’s dims. Rename it at rest.
gridax operators take leading batch axes, so either name costs nothing inside the trace; member is for whoever reads the file.
| Carries well | transforms (jit, grad in or , scan over time); mixed content (fields, scalars, nested states); one flat vector for DA |
| Stops at | coordinates (time, member and layer are positions only); alignment by value; describing itself on disk, since its meaning is a Python class (the cfield_loc attr carries the point, nothing else) |
3 · One grid on disk: an xr.Dataset¶
A Dataset holds several variables on shared coordinates, so it is the file form of one state or one trajectory on one grid. Its rule is the one geoarray already enforces in to_dataset: every variable on the same grid, shared coordinates aligned with join="exact", so xarray never unions two layouts and fills the gap with NaN.
3.1 Staggering as dimensions¶
xgcm’s convention gives each position on an axis its own dimension, with an axis attribute and, for a shifted position, c_grid_axis_shift. The model grid then has four 1-D coordinates: y_c and x_c at centres, y_g and x_g half a cell north and east. CField.to_xarray(grid, name) writes exactly these, from the grid’s coordinates, ghost ring included.
x_c at the centrex_g at the east facey_cy_g
variable → dimseta (time, y_c, x_c)u (time, y_c, x_g)v (time, y_g, x_c)attrs on x_gaxis: “X”c_grid_axis_shift: 0.5xgcm.Grid(ds) reads them; CField.to_xarray writes them, one field at a time (today)
3.2 What sesmax-core writes today¶
state_to_dataset and snapshots_to_dataset (at 9a2fc25) take dims from the array’s rank alone: (y, x) for every 2-D field, no spatial coordinates, ghost ring included. Since sesmax#138 each CField variable also carries two attrs, cfield_dims and cfield_loc, so dataset_to_state rebuilds at U. Any other reader (xgcm, xrops, a plot) still sees on the T dims.
| Carries well | files (Zarr, netCDF), lazy dask chunks, labelled analysis, a member dim for 32 members that share every coordinate |
| Stops at | one geometry (GLORYS’s 360 × 480 next to the 120 × 160 state needs renamed dims or a tree); no trace; no pipekit adapter (PK-P5: xrops’s Operator._apply takes a Dataset directly) |
4 · A whole window on disk: an xr.DataTree¶
A DataTree is a tree of Datasets. Each node keeps its own dims and coordinates, and a child inherits its parent’s. So the carriers rule goes up one level: one grid is one node, and anything on another grid, or another geometry, is another node.
Teal: the model grid, held once and inherited. Blue: ingredients in the geometry they arrived in.
and the innovation sit next to the observation they belong to, on its dims, so a reader can map an innovation without knowing the model grid at all.
Table 3:What already builds or reads a DataTree on main.
| Exists on main | What it does |
|---|---|
geoarray to_datatree, from_datatree | one node per grid: to_datatree({"r10m": g10, "r20m": g20}) |
| xrops operators | accept a DataTree wherever they accept a Dataset: _apply mapped over every data-bearing node; mixing a tree and a Dataset in one call raises |
geocatalog load_states | returns a DataTree with one leaf per grid when the matched files hold more than one |
Watch out: members are not nodes. 32 members on one grid share every coordinate. A node per member repeats the coordinates 32 times and loses vectorised reductions over the ensemble; a member dim inside the node keeps both. The same goes for layers and time.
| Stops at | node-wise maps only: anything that couples nodes (an analysis from background and observations, fluxes between ocean and atmosphere) is explicit code, not a tree map; no trace |
5 · Side by side¶
Table 4:The three containers, property by property.
Pytree of CFields | xr.Dataset | xr.DataTree | |
|---|---|---|---|
| Structure | a Python class; attributes are fields | flat: named variables | nested: a path per node, a Dataset in each |
| Schema lives in | the class | the file | the file, one level deeper |
| Grids | any number, not stored; the model holds them | one | one per node |
| Shared coordinates | none | across all variables | within a node, plus what parents pass down |
| Field positions | static stagger per CField | xgcm dims and attrs | the same, per node |
| Parameters | leaves of a Params module | attrs, or 0-d variables | a params node |
jit, grad, vmap | yes | no | no |
| DA vector | ravel_pytree / state_to_vector | via a state | via a state |
| Ensemble | a leading member axis | a member dim | a member dim inside each node |
| Lazy, bigger than memory | no: device arrays | yes | yes, per node |
| Operators | gridax, GridOps, sesmax Terms | xrops Operator._apply | xrops, node by node |
| Built today by | sesmax states of CFields (sesmax#138) | sesmax-core io, geoarray to_dataset | geoarray to_datatree, geocatalog load_states |
6 · Conversions: one hop crosses the trace¶
Every hop is a named call. Only one crosses into the trace, Dataset to State and back; the vector is a view of the state for the DA libraries.
Zarr store open_datatree · to_zarrDataTree (the window)tree[“/background”].to_dataset()Dataset (one grid)geoarray.from_datasetGeoArray (regrid here)ResampleLike(average), flip, embed trace boundaryCField per field
stagger , (lossy, warns)
State (pytree) select interior · embed + fill ghostsvector (a view)state_to_dataset
Above the line: xarray, lazy, labelled, any size. Below it: device arrays with static layout. Dotted hops change values (lossy); solid hops only change the container.
Table 5:Every conversion between the containers, and whether it ships.
| From → to | Call | Status |
|---|---|---|
Zarr ↔ DataTree | xr.open_datatree(store, engine="zarr"), tree.to_zarr(store) | today |
DataTree → Dataset | tree["/model/forecast"].to_dataset() | today |
GeoArrays ↔ Dataset / DataTree | geoarray.to_dataset, from_dataset, to_datatree, from_datatree | today |
background Dataset → State | from_dataset → ResampleLike(…, "average") → CField + gridax.embed; , through gridax.stagger | today |
| bathymetry → depth and mask | the same resample; gridax.Mask2D.from_bathymetry(depth, min_depth) | today |
obs file → GeoPoints / GeoSwath | the constructors; from_xarray when geoarray wrote the file | today |
GeoSwath → GeoPoints | the finite pixels, each with its line’s time | user code |
State trajectory → | frames as a GeoArray (trim, flip), then geoops.geom.interp_at(frames, points, frame=hour) | interp_at today; the frames step has no helper |
Dataset → State | sesmax_core.io.dataset_to_state(ds, SWState) | today: dims by rank, the point from cfield_loc |
State → Dataset | state_to_dataset, snapshots_to_dataset | today with the point as an attr; xgcm dims proposed |
State ↔ vector | ravel_pytree, sesmax_core.da.state_to_vector | today with ghosts; interior proposed |
7 · The window, end to end¶
Five steps take the window from files to one tree on disk. Each card names the container it starts and ends in. Code is a sketch: proposed names don’t exist yet, and user marks code the experiment writes itself.
7.1 Initial condition: GLORYS Dataset → model State¶
In
GLORYS zos, uo, volat–lon A-grid, 1/12°, all at cell centres(latitude, longitude),
↓
↓
Out
SWState at T exact; at U and at V lossy (warns)3 × (122, 162),
is the 3 × 3 block of GLORYS cells inside T cell . Regrid while it is still a GeoArray; a CField never holds a foreign grid.
# Shapes: GLORYS 360 × 480 at 1/12°; model N_row × N_col = 120 × 160 at 1/4°
# Units: η m; u, v m s⁻¹
# today (xarray)
# → Dataset: zos, uo, vo on (latitude, longitude), 360 × 480
glorys = xr.open_zarr(glorys_store).sel(time=window_start)
# today (geoarray)
# → dict of GeoArray (360, 480)
background = geoarray.from_dataset(glorys)
# today* (geoops)
# η̄ⱼᵢ = (1/9) ∑ η over the 3 × 3 cells in T cell (j, i)
# (360, 480) → GeoArray (120, 160), m
to_model = geoops.geom.ResampleLike(like=model_t, resampling="average")
eta_t = to_model(background["zos"])
# user
# rows run south in the GeoArray, north in the model: flip, wrap, add ghosts
# (120, 160) → CField (122, 162), T
def to_t_field(g: GeoArray["y x"]) -> gridax.CField:
# today (gridax)
return gridax.embed(gridax.CField(g.data[::-1], ("y", "x")), grid)
# → CField (122, 162), T, m
eta_initial = to_t_field(eta_t)
# today (gridax.stagger)
# u at U = ½ (u at T west + u at T east); warns LossyConversionWarning
# → CField (122, 162), U, m s⁻¹
u_initial = gridax.stagger(to_t_field(to_model(background["uo"])), agrid, dst="U", bc=walls)Program 2:The initial condition: GLORYS read as a Dataset, regridded as GeoArrays, wrapped as CFields at T and staggered to U.
Watch out: coastal NaN. GLORYS land is NaN, so a coastal T cell averages to NaN. The mask from step 2 decides which cells are wet, and dry inputs are zeroed with jnp.where before any stencil reads them (gridax contract 3); multiplying by a 0/1 mask keeps NaN × 0 = NaN.
7.2 Parameters: GEBCO GeoArray → Params and the mask¶
In
GEBCO elevation15″ grid; negative below sea level(7200, 9600)
↓
↓
Out · for every call of the model
depth in SWParamsa CField at T, positive down(122, 162)
wet mask, Mask2DT; U, V and X follow from it(122, 162)bool
is GEBCO elevation and the 60 × 60 GEBCO cells inside T cell . Depth and coastline come from one field, so they agree by construction. GEBCO nests exactly, so a reshape and a mean does this without a 3 600-tap plan.
7.3 Observations: two files → GeoPoints¶
In
nadir SLA; SWOT SSHpoints with lon, lat, time; a swath with lat, lon per pixel, time per line(obs,), (line, pixel)
↓
Out
GeoPoints ×2SWOT’s finite pixels, each with its line’s time(obs,)
SWOT longitudes run 0–360°; the box is −70 to −30°. Neither file touches the model grid.
7.4 Run and : State → GeoArray frames → GeoPoints¶
Gravity waves set the time step. The fastest wave has speed , and the 2-D C-grid limit uses the narrowest cell.
| Expression | Reading |
|---|---|
| → m s⁻¹ | |
| km → 1/4° of longitude at 55°N = 15.9 km | |
| m / (m s⁻¹) = s → 15 945 / 280 = 57 s 45 s | |
| steps · s = s → 19 200 × 45 = 864 000 s = 10 d | |
| ✓ 240 hourly frames, stable by a margin of 1.27 |
Here is the number of model steps in the window and the narrowest cell width.
In
, SWState , SWParams3 × (122, 162),
GeoPointspositions and hours(obs,)
↓
↓
Out
forecast SWStateleaves gain a time axis(240, 122, 162),
, on the observations’ dims; invalid outside the box and next to land(obs,)
is observation ’s hour. The frames step (trim ghosts, flip rows, attach the transform) is user code today; geoarray.from_cfield is the recommended helper.
7.5 The window on disk: one DataTree¶
# today (xarray)
# one node per ingredient, each in its own geometry
# → DataTree, the layout of section 4
tree = xr.DataTree.from_dict({
"/background": glorys,
"/bathymetry": gebco.to_xarray().to_dataset(name="elevation"),
"/model/params": params_dataset,
"/model/initial": sesmax_core.io.state_to_dataset(x_initial),
"/model/forecast": sesmax_core.io.snapshots_to_dataset(forecast, frame_times),
"/model/analysis": sesmax_core.io.snapshots_to_dataset(analysis, frame_times),
"/obs/nadir": nadir_dataset,
"/obs/swot": swot_dataset,
})
# today (xarray)
tree.to_zarr(window_store)Program 3:The whole window written as one DataTree, one node per ingredient, each in its own geometry.
Three pieces are missing today. The model nodes come out on (y, x) with no coordinates, so their children inherit no grid and a reader cannot place (writing each field through CField.to_xarray would fix it). params_dataset and the obs datasets with hx and innovation are written by hand; a states_to_datatree would build the model half.
The same split holds beyond one window. A coupled run keeps one module per component inside the trace (ocean 120 × 160, atmosphere 60 × 80) and a node per component on disk. An evaluation across resolutions opens the window tree beside an L4 product; xrops runs node by node, and the comparison itself is an explicit regrid that writes a new node.
8 · Numbers for the window¶
Table 6:Sizes in the window, container by container.
| Container | Quantity | Value | Unit |
|---|---|---|---|
| pytree | leaves of SWState + SWParams | 6 | — |
| vector | today, with ghosts | 59 292 | entries |
| vector | interior only | 57 600 | entries |
| vector | 32-member ensemble, float32, interior | 7.37 | MB |
Dataset | forecast, 3 × 240 × 122 × 162 float32 | 56.9 | MB |
DataTree | bathymetry node, int16, as read | 138 | MB |
DataTree | model grid coordinates held once | 4 | 1-D arrays |
| run | stability margin, 57 s / 45 s | 1.27 | — |
9 · Rules and open questions¶
Proposed rules (none decided yet):
Only pytrees enter a trace. A
DatasetorDataTreeis converted at the boundary.One geometry is one
Dataset; a window of several is aDataTreewith one node per ingredient.Each ingredient keeps the geometry it arrived in, on disk. The tree never regrids.
Regrid while it is still a
GeoArray, then wrap as aCFieldon the model grid.and the innovation live in the observation’s node, on its dims.
Members, layers and time are dims, never nodes or separate variables.
A state on disk records its positions as xgcm dims, through
CField.to_xarray, not only as acfield_locattr.A DA vector holds the interior only (
gridax.interiorper field); the way back isgridax.embedand a ghost fill from the BCs.
Open questions, each with a recommendation:
Table 7:The open questions and the recommended answer to each.
| Question | Recommended |
|---|---|
Who turns a T-point CField into a GeoArray for ? | geoarray.from_cfield(f, grid) for regular grids, duck-typed like to_geoswath; the to_geoswath path also needs interp_at to read a GeoSwath |
Where does states_to_datatree live? | sesmax-core io, beside the State ↔ Dataset pair |
| Parameters on disk? | a params node: fields as variables, scalars as attrs |
| How does an ensemble name its axis? | an explicit member dim at rest |
Dataset and DataTree adapters in pipekit? | no: leave PK-P5, xrops owns them |
Sources and status
From the artifact “Carrier trees: pytree, Dataset and DataTree” (updated 1 December 2026), which explains the design doc “Advanced carriers: pytree, Dataset and DataTree” (2026-11-21). Its facts cite sesmax#138 (23 Nov 2026), gridax#522 and gridax#569. The artifact read its names in sesmax-core io at 9a2fc25 and gridax at 92415e7 (_src/fields/, contracts 1 and 3 of AGENTS.md); they were not checked again against the pins for this page. today and proposed follow the design doc’s markers. The carrier arrays page covers each single carrier. The window’s numbers are illustrative but consistent with the roles and carrier-arrays pages; m in the stability check is a representative open-ocean depth. The page has no notebook behind it.