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.

Patterns from coordax for DimArray, GeoArray and CField

Design · pipekit-ops, pipekit-array, geotoolz-array and gridax, and seven ideas taken from coordax without depending on it

4 Dec 2026 · proposed, nothing decided

1TL;DR

2Motivation

The stack has three carriers of its own (carrier arrays): DimArray says which axis is which, GeoArray where on Earth each pixel is, and CField where in the cell each value sits. Each is a pytree whose array is a leaf and whose metadata is static, and each plugs into pipekit-ops’s adapter registry, so one pa.reduce or pa.isel works on all three.

They grew separately, and it shows in four ways.

coordax (neuralgcm/coordax, Apache-2.0) solved each of these in its own Field. Its Coordinate classes slice themselves (_isel) and write and read their own xarray variables (to_xarray, a from_xarray class method that returns NoCoordinateMatch(reason) when the DataArray is not its kind). Its cmap takes the vmap to use as an argument. Its axes may be positional (None) until tag names them. Its coordinates expose derived values through fields, and a Field exposes them through coord_fields. It renders through treescope and builds abstract fields with shape_struct_field.

The first version of this page asked whether to rebuild the carriers on coordax, and the prototype answered no. This version asks the better question: which of coordax’s patterns do the carriers want, and what does each cost to take?

3User stories

  1. A pipekit maintainer fixes a bug in how labels follow a list indexer, and wants to fix it once rather than in three adapters.

  2. A gridax maintainer adds a fifth C-grid point, and wants isel and demotion to follow from the new coordinate instead of from edits to _located and rewrap.

  3. An ocean analyst opens a NetCDF file whose DataArray might be a C-grid field, a georeferenced raster or neither. They call one from_xarray and expect either the right carrier or an error that says why none fit.

  4. A geotoolz user writes jax.vmap over patches whose own dims include one called "batch", and expects the names to survive.

  5. An ensemble user computes a spatial mean for every member and every time step, under vmap on a GPU and in a plain loop on a laptop, with one call.

  6. A retrieval developer needs the map coordinates of every pixel centre inside a jitted model, for every scene, without recompiling per scene.

  7. A notebook user looks at a carrier in Jupyter and wants its dims, sizes, labels, position and georeference at a glance.

  8. A pipeline author plans the output of a patch-wise run with jax.eval_shape before any data exists.

4Scope

In scope

Out of scope

5Background

Notation

A carrier cc is a pair of an array and its coordinates:

c=(x,K)c = \left( \mathbf{x}, \mathcal{K} \right)
K={κd:d∈Dc}\mathcal{K} = \{ \kappa_{d} : d \in D_{c} \}

where x\mathbf{x} is the data of shape (n1,…,nk)(n_{1}, \ldots, n_{k}), DcD_{c} the tuple of its kk dims, and κd\kappa_{d} the coordinate of dim dd, if it has one. A coordinate holds static metadata about one dim: its labels, its position on the cell, its wavelengths. A leaf that varies per scene, such as GeoArray’s transform τ∈R6\boldsymbol{\tau} \in \mathbb{R}^{6}, is not a coordinate; it sits beside x\mathbf{x} in the leaves.

What a carrier is to jit

jit compiles once for each distinct pair of static data and leaf shapes, so the number of compiles over a set of carriers C\mathcal{C} is

Ncompile=∣{(s(c),shape(ℓ(c))):c∈C}∣N_{\mathrm{compile}} = \left| \{ (s(c), \mathrm{shape}(\ell(c))) : c \in \mathcal{C} \} \right|

where ℓ(c)\ell(c) are the leaves of carrier cc and s(c)s(c) its static data. The coordinates K\mathcal{K} are in ss, so a pattern that only changes how coordinates are written changes no compile count, as long as it puts nothing new into ss. Every pattern below keeps to that.

The three carriers on origin/main, read from their source.

DimArrayGeoArrayCField
Package, versionpipekit-array 0.3.3geotoolz-array 0.6.1 (geoarray)gridax 0.4.4
Leavesdatadata, transform (*batch, 6) float64data
Staticdims, labelscrs, fill_value, attrs, dims, coordsdims, labels, stagger
Coordinates todaya dict of label tuplesnine Coordinate types, one per dimlabel tuples and a stagger tuple
Imports JAXnonono, and a test checks it
Notebook displayone-line reprone-line reprone-line repr

Slicing commutes with coordinates

Selection by position on dim dd with an indexer π\pi (an integer, a slice or a list of positions) acts on the data and on that dim’s coordinate, and on nothing else:

iseld(c,π)=(x[π],K∖{κd}∪{κd[π]})\mathrm{isel}_{d}(c, \pi) = \left( \mathbf{x}[\pi], \mathcal{K} \setminus \{ \kappa_{d} \} \cup \{ \kappa_{d}[\pi] \} \right)

where x[π]\mathbf{x}[\pi] indexes axis dd and κd[π]\kappa_{d}[\pi] is the coordinate sliced the same way, or dropped when π\pi is an integer. Each adapter today writes this rule by hand for its own metadata. coordax writes it once and asks each coordinate for κd[π]\kappa_{d}[\pi]; geoarray already does the same for its own coordinates.

What a carrier becomes after a dim goes is a second rule. A CField that loses its last grid dim is a DimArray, because a value with no grid dim has no position on the cell. With a flag δ(κ)∈{0,1}\delta(\kappa) \in \{0, 1\} on each coordinate that says whether it defines the carrier’s kind,

kind(c)={CFieldif ∃κ∈K:δ(κ)=1DimArrayotherwise\mathrm{kind}(c) = \begin{cases} \mathrm{CField} & \text{if } \exists \kappa \in \mathcal{K} : \delta(\kappa) = 1 \\ \mathrm{DimArray} & \text{otherwise} \end{cases}

so demotion is decided by the coordinates that are left, not by code in the adapter.

Mapping over named dims

Mapping ff over dims M=(m1,…,mj)M = (m_{1}, \ldots, m_{j}) of cc applies ff to every item and stacks the results, mapped dims first:

mapM(f,c)[i1,…,ij]=f(iselm1,…,mj(c,i1,…,ij))\mathrm{map}_{M}(f, c)[i_{1}, \ldots, i_{j}] = f\left( \mathrm{isel}_{m_{1}, \ldots, m_{j}}(c, i_{1}, \ldots, i_{j}) \right)

where iri_{r} runs over 0,…,nmr−10, \ldots, n_{m_{r}} - 1. The result does not depend on how the items are visited, so jax.vmap, a Python loop, or a sharded map are interchangeable ways to compute it, and the caller should be able to choose.

Map coordinates from the transform

A GeoArray’s pixel centre (i,j)(i, j) sits at

xij=c+a(j+12)+b(i+12)x_{ij} = c + a \left( j + \frac{1}{2} \right) + b \left( i + \frac{1}{2} \right)
yij=f+d(j+12)+e(i+12)y_{ij} = f + d \left( j + \frac{1}{2} \right) + e \left( i + \frac{1}{2} \right)

where τ=(a,b,c,d,e,f)\boldsymbol{\tau} = (a, b, c, d, e, f) is the transform, ii the row and jj the column. Both are affine in the leaf τ\boldsymbol{\tau}, so they trace once for every scene of the same shape. Longitude and latitude are not: they need the CRS’s projection, which pyproj computes on the host.

Notation crosswalk

The same ideas under each library’s names.

This pagecoordaxpipekit-arraygeoarraygridax
carrierFieldDimArrayGeoArrayCField
coordinate κd\kappa_{d}Coordinate(labels in the adapter)Coordinate(labels and stagger in the adapter)
κd[π]\kappa_{d}[\pi]_iselDimArrayAdapter.iselCoordinate.iselCFieldAdapter.isel
a reader’s refusalNoCoordinateMatch(reason)———
mapM\mathrm{map}_{M}cmap(f, vmap=…)map_over(x, f, dim), one dim——
a positional axisNone in dims, tag, untag"batch" from vmapped_dimsthe samethe same
derived valuesCoordinate.fields, Field.coord_fields—PixelGrid.centres(transform)grid.coords(dim)
abstract carriershape_struct_fieldaccepts ShapeDtypeStructrefuses itaccepts it

6Background: why not depend on coordax

The first version of this page measured three depths of dependency: carriers as Field subclasses (A), carriers that store a Field (B), and coordax as a peer carrier behind an extra (C). The prototype measured each against what the packages promise today, on a 122 × 162 float32 grid.

ScriptMeasurementResult
P1import time; is JAX loaded?pipekit_array 0.12 s, geoarray 0.34 s, gridax 0.49 s, none loads JAX; coordax 0.84 s and loads JAX
P1NumPy and dask dataDimArray and CField keep NumPy as NumPy and dask lazy; a Field turns NumPy into JAX on the first operator and refuses dask; cmap(np.nanmean) raises TracerArrayConversionError
P2jit over 20 scenes with different originsGeoArray 1 compile; a Field with a static grid coordinate 20; a Field with the transform as a leaf beside it 1
P2vmap over 4 patches with different originsGeoArray works; a static grid coordinate raises ValueError
P2xarray round tripwith a grid coordinate the transform and CRS are exact; fill value, attrs and name are lost in every form, as a Field has none
P3(y, x) field plus a plain (x,) arraygridax (122, 162); coordax (162, 122, 162) with no error
P4eager add with JAX databare 40 µs, DimArray 45 µs, CField 43 µs, Field 1 181 µs; compiled programs identical
P5a Field in pipekit’s adapter registryabout 25 lines; pa.reduce, isel, combine and window work on it

Options A and B break the no-JAX import, the NumPy and dask backends, and for A the batched georeference. Option C works but keeps three named-array cores beside coordax’s, which is the cost this page now attacks from the other side: take coordax’s patterns into the one core the stack has. Whether to also ship the peer adapter of P5 is question CP-O6.

7Background numerics

What the pattern prototype measured. Small arrays, because nothing here is a cost per element: a (member, y, x) = (3, 6, 8) cube for slicing, a (member, time, y, x) = (4, 5, 32, 32) ensemble for mapping, and a 64 × 64 scene for derived fields. Timings are the mean of five calls after a warm-up on a shared CPU VM, so they are good to about ±20 %.

The pattern prototype’s measurements.

ScriptPatternMeasurementResult
Q1coordinatesgeneric isel with Labels and Stagger against pa.isel on CField, points T, U, V, X, ten indexers each40 of 40 equal: data, dims, labels, stagger and the demotion to DimArray
Q1coordinatesthe same on DimArray10 of 10 equal
Q1coordinatesgeoarray’s SpectralAxis through the generic isel, bands [2, 0]labels ('B04', 'B02'), wavelengths (665.0, 490.0), with no change to geoarray
Q1coordinatesjit over CField points T, T, U, U2 traces, as today
Q1coordinatesmetadata code in the adapters todayDimArrayAdapter isel + rewrap + relabel 65 lines; CFieldAdapter with check_compatible and _located 26; geoarray’s adapter isel + rewrap 45 and GeoArray.isel 21
Q1coordinatesthe prototypegeneric isel and demotion 13 lines; Labels and Stagger 23 lines
Q2reader chainthree readers today, each given each carrier’s DataArraysee the table below: each reads its own; of the six cross calls, 2 raise and 4 drop metadata with no error
Q2reader chaina chain of the three, each returning a carrier or a reason3 of 3 right; a DataArray none of the two geo readers claims raises with both reasons
Q3mappernested pa.map_over against one call over ("member", "time") with jax.vmap, and with a loopdims ('member', 'time') in all three; vmap equals nested to 0.0, loop equals vmap to 2.2 × 10⁻⁸
Q3mappereager cost, 20 itemsvmap 3.0 ms, loop 10.3 ms per call
Q3mapperpa.map_over with np.nanmean on NumPy datafalls back to a loop today and returns NumPy
Q4positional axesa bare vmap of each carrierdims ('batch', 'y', 'x') for all three
Q4positional axesvmap of 2 items, each a ('member', 'x') carrier of shape (3, 4)sizes {batch: 2, member: 3, x: 4}
Q4positional axesthe same with the item’s dim called "batch"sizes {batch: 2, batch_1: 3, x: 4}: the user’s dim is renamed batch_1 and its name goes to the mapped axis
Q5derived fieldsjit(lambda g: g.pixel_grid.centres(g.transform)) over 20 origins1 trace, shape (64, 64)
Q5derived fieldspyproj longitude and latitude under jitTracerArrayConversionError; on the host, lon 16.1116, lat 36.1395 at pixel (0, 0)
Q6display_repr_html_, __treescope_repr__ or _repr_mimebundle_ on each carriernone on any
Q7abstract carriersa carrier built on a ShapeDtypeStruct((3, 64, 64), float32)DimArray and CField build, and eval_shape of a mean over time gives dims ('y', 'x'); GeoArray raises TypeError at construction

What each reader does with each carrier’s DataArray today (Q2). Each DataArray is that carrier’s own to_xarray().

ReaderGeoArray’s DataArrayCField’s DataArrayDimArray’s DataArray
GeoArray.from_xarrayGeoArray, CRS 32633AttributeError: 'NoneType' object has no attribute 'to_epsg'ValueError: no grid
CField.from_xarrayCField at T, georeference droppedCField at UCField at T on (member, time)
pipekit_array.bridges.xarray.from_xarrayDimArray, georeference droppedDimArray on (y_c, x_g), position droppedDimArray

What follows from it.

Numerics that are design constraints.

8Prior art

Read on 4 Dec 2026.

LibraryWhat it hasWhat to takeWhat to avoid
coordax 0.2.9Coordinate with _isel, to_xarray, from_xarray and fields; NoCoordinateMatch; cmap(fun, out_axes, *, vmap=jax.vmap) and cpmap; positional axes with tag and untag; __treescope_repr__; shape_struct_fieldall seven patternsstatic data for per-scene numbers; its operators’ plain-array broadcasting; JAX at import
geoarray’s coordinates (geotoolz-array 0.6.1)a Coordinate protocol (dim, size, labels, isel) and nine types; GeoArray.coord(dim) and labels(dim)the protocol itself, as the stack’s starting pointthe isinstance chain in its xarray writer (_coordinate_vars), which the protocol replaces
xarray 2026.12.0IndexVariables that slice with the data; an open backend-engine registry for readersthe idea that a reader is registered by the package that owns the formatcoordinate values as arrays beside the data

9What it builds on

NeedUpstream nameState
the adapter registry the generic isel sits behindpipekit_ops.carriers.register_adapter, NamedArrayAdaptertoday (pipekit-ops)
the coordinate protocolgeoarray._src.coords.Coordinatetoday (geoarray), to be lifted
the dim functionspipekit_array.isel, reduce, map_over, batchtoday (pipekit-array 0.3.3)
the batch naming to replacepipekit_array.named._carrier.vmapped_dims, core_dimstoday (pipekit-array)
the readers to chainGeoArray.from_xarray, CField.from_xarray, pipekit_array.bridges.xarray.from_xarraytoday
map coordinates from the transformPixelGrid.centres(transform)today (geoarray)
a C-grid’s coordinates at centres and facesgrid.coords(dim), and the x_c, x_g variables CField.to_xarray writestoday (gridax)

Gaps, each sent to the package that owns the concept.

GapOwnerWhy there
the Coordinate protocol with to_xarray and from_xarray, NoMatch, and the generic coordinate iselpipekit-ops, in pipekit_ops.carriersthe adapter registry lives there, and every carrier package already depends on it
Labels, a coordinate for exact labelspipekit-arrayDimArray is its first user; gridax reuses it
the reader registry and pa.from_xarray that walks itpipekit-array, in pipekit_array.bridges.xarraythe xarray bridge is already there, behind the xarray extra
map_over over several dims with mapper=pipekit-arraymap_over is there
positional axes, pa.tag, pa.untagpipekit-array, with the adapters in each packagevmapped_dims is there; each adapter’s dims must accept None
the HTML rendererpipekit-opsit reads only the adapter and the coordinates, so one renderer serves every carrier
to_xarray and from_xarray on geoarray’s nine types; the georeference reader; coord_fields; ShapeDtypeStruct datageoarrayit owns the georeference and its CF convention (LL-F1)
Stagger; the C-grid reader; gridax.coord_fields(field, grid)gridaxit owns the stagger and its xgcm convention

What stays where it is: every carrier’s leaves, its static data, its pytree registration, its combine, and the float64 transform.

10Architecture

The patterns by package

Patternpipekit-opspipekit-arraygeoarraygridax
1. coordinatesCoordinate, NoMatch, isel_coordsLabels; DimArray stores its labels as coordinatesits nine types gain to_xarray, from_xarrayStagger; CField stores labels and stagger as coordinates
2. reader chain—register_reader, pa.from_xarrayregisters the georeference readerregisters the xgcm reader
3. mapper—map_over(x, f, dims, mapper=)——
4. positional axesNone allowed in an adapter’s dimsvmapped_dims gives None; pa.tag, pa.untagadapter accepts Noneadapter accepts None
5. derived fields——GeoArray.coord_fields()gridax.coord_fields(field, grid)
6. displayrender_html(x)DimArray._repr_html_GeoArray._repr_html_CField._repr_html_
7. abstract carriers—pa.shape_struct(x)accepts ShapeDtypeStruct data—

The pieces, by rung.

PieceRungKindPackageUsed by
Coordinate, NoMatch⓪ structureprotocol, recordpipekit-opsevery coordinate type, every reader
Labels, Stagger, geoarray’s nine types⓪ structurestatic coordinatespipekit-array, gridax, geoarraythe carriers
isel_coords① primitivefunctionpipekit-opsevery adapter’s isel
pa.from_xarray, register_reader① primitivefunction, registrypipekit-arrayusers at the xarray boundary
map_over with mapper=① primitivefunctionpipekit-arrayanalyses, ensembles
pa.tag, pa.untag① primitivefunctionpipekit-arraycode after a bare vmap
coord_fields① primitivemethod, functiongeoarray, gridaxmodel code under jit
render_html, pa.shape_struct① primitivefunctionpipekit-ops, pipekit-arraynotebooks, planners

Protocols

Coordinate (pipekit-ops) is a Protocol with the four members geoarray’s has today, dim, size, labels and isel(index), plus three optional ones:

Every implementation is a frozen dataclass, hashable, holding static values only. isel(index) with an integer is never called: the carrier drops the coordinate.

isel_coords(coords, indexers) -> dict[str, Coordinate] (pipekit-ops) is the coordinate half of the commuting rule. Each adapter’s isel slices its data as it does today and calls this for the coordinates. Leaves beside the data, such as the transform, stay the adapter’s job.

NoMatch(reason: str) (pipekit-ops) is what a coordinate type or a reader returns when the input is not its kind. It is a value, not an exception, so a chain can collect every reason.

A reader (pipekit-array) is a callable reader(da) -> carrier | NoMatch, registered with a name and a priority by the package that owns the carrier. pa.from_xarray(da) tries them in priority order and returns the first carrier; when every reader declines it raises ValueError listing each name and reason. DimArray’s reader is last and never declines. A reader that raises is recorded as declining, with the exception as its reason.

Layout

pipekit/packages/pipekit-ops/src/pipekit_ops/carriers/_coords.py      # Coordinate, NoMatch, isel_coords
pipekit/packages/pipekit-ops/src/pipekit_ops/carriers/_display.py     # render_html
pipekit/packages/pipekit-array/src/pipekit_array/named/_coords.py     # Labels, tag, untag, shape_struct
pipekit/packages/pipekit-array/src/pipekit_array/bridges/xarray.py    # register_reader, from_xarray
geotoolz/packages/geotoolz-array/src/geoarray/_src/coords.py          # the nine types gain to_xarray, from_xarray
gridax/packages/gridax/src/gridax/_src/fields/coords.py               # Stagger, coord_fields

No module imports JAX or xarray at its top. The display module writes HTML as a string and imports nothing.

11API proposal

Each sketch shows today’s call and the proposed one, in the order of the patterns.

1. Coordinates that slice themselves

# Shapes: (member, y, x) = (3, 122, 162); an ocean ensemble with the ghost ring
# Units:  u m s⁻¹

# today (gridax)
# CFieldAdapter.isel slices labels, keeps the stagger of dims left, and _located demotes
# (member, y, x) at U → (y, x) at U
u0 = pa.isel(u, member=0)

# proposed (CP-D1, CP-D2)
# the same call; each coordinate slices itself and the defining Stagger decides the kind
# coords: member → Labels, y → Stagger("y", 122, "center"), x → Stagger("x", 162, "right")
# (member, y, x) at U → (y, x) at U
u0 = pa.isel(u, member=0)

# proposed (CP-D2)
# both Staggers dropped; only Labels is left, which is not defining
# (member, y, x) at U → (member,) DimArray
corner = pa.isel(u, y=0, x=0)
# proposed (CP-D1)
# a new coordinate type written once; every carrier that holds it slices it
@dataclass(frozen=True)
class Stagger:
    dim: str
    size: int
    position: str = "center"      # xgcm: center, left, right, outer, inner
    defining: ClassVar[bool] = True
    labels: ClassVar[None] = None

    def isel(self, index) -> Stagger: ...   # the new size, the same position
    def to_xarray(self) -> dict: ...         # axis, c_grid_axis_shift
    @classmethod
    def from_xarray(cls, dims, coords) -> Stagger | NoMatch: ...

2. One reader chain

# Shapes: (y, x) = (16, 16) interior of a C-grid
# Units:  u m s⁻¹

# today (gridax)
# any DataArray becomes a CField; one with no xgcm attributes is called T
# DataArray (band, y, x) → CField (band, y, x) at T
f = gridax.CField.from_xarray(geo_da)

# proposed (CP-D3)
# readers tried in priority order: georeference, C-grid, then DimArray
# DataArray (band, y, x) with spatial_ref → GeoArray (band, y, x)
# DataArray (y_c, x_g) with axis, c_grid_axis_shift → CField (y, x) at U
# DataArray (member, time) → DimArray (member, time)
carrier = pa.from_xarray(da)

# proposed (CP-D3)
# readers=("geoarray", "gridax") narrows the chain; a refusal names every reason
# ValueError: no carrier reads this DataArray:
#   geoarray: no spatial_ref coordinate
#   gridax: no dim coordinate with an xgcm axis attribute
carrier = pa.from_xarray(da, readers=("geoarray", "gridax"))

3. A mapper over several dims

# Shapes: (member, time, y, x) = (4, 5, 32, 32)
# Units:  η m

# today (pipekit-array)
# η̄[m, t] = mean over y, x of η[m, t]
# (member, time, y, x) → (member, time)
eta_bar = pa.map_over(eta, lambda m: pa.map_over(m, spatial_mean, "time"), "member")

# proposed (CP-D4)
# the same, one call; mapper is jax.vmap by default, or "loop", or any vmap-like callable
# (member, time, y, x) → (member, time)
eta_bar = pa.map_over(eta, spatial_mean, ("member", "time"), mapper=jax.vmap)

4. Positional axes

# Shapes: (patch, y, x) = (2, 3, 4)

# today (pipekit-array)
# the mapped axis is named "batch"; an item's own "batch" dim is renamed "batch_1"
# (y, x) per item → (batch, y, x); ("batch", x) per item → (batch, batch_1, x)
out = jax.vmap(build)(patches)

# proposed (CP-D5)
# the mapped axis is positional until named; dim functions refuse it by name
# ("batch", x) per item → (None, batch, x)
out = jax.vmap(build)(patches)

# proposed (CP-D5)
# (None, batch, x) → (patch, batch, x)
out = pa.tag(out, "patch")

5. Derived fields

# Shapes: (y, x) = (64, 64); a scene at 20 m in UTM 33N
# Units:  x, y m (projected)

# today (geoarray)
# x_ij, y_ij from τ, traced once for every origin
xs, ys = g.pixel_grid.centres(g.transform)

# proposed (CP-D6)
# the same values as carriers on the scene's own dims, from the coordinates that hold them
# GeoArray (band, y, x) → {"x": DimArray (y, x), "y": DimArray (y, x)}
fields = g.coord_fields()

# proposed (CP-D6)
# a C-grid field's coordinates at its own position: faces along x for a U field
# CField (y, x) at U → {"x": DimArray (x,), "y": DimArray (y,)}
fields = gridax.coord_fields(u, grid)

6 and 7. Display and abstract carriers

# Shapes: (time, y, x) = (3, 64, 64)

# proposed (CP-D7)
# Jupyter shows a table: dims with sizes, dtype, backend, then one row per coordinate
g   # GeoArray._repr_html_ → pipekit_ops.carriers.render_html(g)

# proposed (CP-D8)
# the same carrier with ShapeDtypeStruct data, for eval_shape and planning
# GeoArray (time, y, x) → GeoArray (time, y, x) of ShapeDtypeStruct
spec = pa.shape_struct(g)

# today (pipekit-array)
# DimArray (time, y, x) → DimArray (y, x)
out = jax.eval_shape(lambda f: pa.reduce(f, jnp.mean, "time"), spec)

12Usage examples

An ensemble diagnostic end to end. A NetCDF file of an ensemble of C-grid runs is read without knowing what it holds, reduced per member and time, and inspected.

# Shapes: (member, time, y, x) = (4, 5, 122, 162) with the ghost ring
# Units:  u m s⁻¹

# proposed (CP-D3)
# the xgcm reader claims it: x_g has axis "X" and c_grid_axis_shift 0.5
# DataArray (member, time, y_c, x_g) → CField (member, time, y, x) at U
u = pa.from_xarray(xr.open_dataarray("runs.nc"))

# proposed (CP-D4)
# ū[m, t] = mean over the interior of u[m, t]
# (member, time, y, x) → (member, time) DimArray, the Staggers gone with y and x
u_bar = pa.map_over(u, interior_mean, ("member", "time"))

# proposed (CP-D7)
u_bar   # a table: member 4, time 5; float32; jax; member labels

A batched retrieval with map coordinates. Patches of one scene, each with its own origin, go through one compiled model that needs every pixel’s map coordinates.

# Shapes: (patch, band, y, x) = (16, 4, 64, 64); transforms (patch, 6) float64
# Units:  x, y m (projected)

# today (geopatcher)
# GeoArray (band, H, W) → GeoArray (patch, band, y, x), one compile for every origin
patches = patcher(scene)

# proposed (CP-D6)
# x_ij, y_ij per patch, traced once
# GeoArray (band, y, x) → {"x": DimArray (y, x), "y": DimArray (y, x)}
@jax.jit
def retrieve(g):
    xy = g.coord_fields()
    return model(g, xy["x"], xy["y"])

# proposed (CP-D5)
# the mapped axis comes back positional and is named once
# (None, y, x) → (patch, y, x)
out = pa.tag(jax.vmap(retrieve)(patches), "patch")

13Decisions

All proposed on 4 Dec 2026; none is decided.

IDDecisionMain reason
CP-D1pipekit-ops owns a Coordinate protocol, lifted from geoarray’s and extended with defining, to_xarray and from_xarray, and an isel_coords that every adapter uses for its coordinatesthe prototype reproduced today’s slicing on DimArray and CField in 50 of 50 cases, and geoarray’s types passed unchanged
CP-D2DimArray and CField store labels as Labels and the stagger as a Stagger per grid dim; demotion follows from definingdemotion is decided in one place, and a new point or coordinate needs no adapter edit
CP-D3one pa.from_xarray walks readers registered by each carrier’s package, each returning a carrier or NoMatch(reason); CField.from_xarray refuses a DataArray with no xgcm attributesfour of the six cross calls today drop metadata with no error, two of them into a CField at T
CP-D4map_over takes a tuple of dims and a mapper= (jax.vmap by default, "loop", or any vmap-like callable)one call for the common nested case, equal to nesting to the bit, and the mapper is the caller’s choice
CP-D5a bare vmap gives its new axis a positional dim (None); dim functions refuse a positional dim with an error naming pa.tag; vmapped_dims and core_dims stop treating "batch" as specialthe "batch" name silently moves to the mapped axis when a user has a dim of that name
CP-D6GeoArray.coord_fields() gives the map coordinates of the pixel centres as DimArrays from the leaf transform; gridax.coord_fields(field, grid) gives a field’s coordinates at its own position; longitude and latitude stay a host stepaffine coordinates trace once per shape; pyproj cannot run under jit
CP-D7each carrier has a _repr_html_ from one renderer in pipekit-ops that reads the adapter and the coordinatesno carrier has a notebook display today, and one renderer keeps the three consistent
CP-D8GeoArray accepts ShapeDtypeStruct data, and pa.shape_struct(x) returns any carrier with abstract dataDimArray and CField already do; GeoArray is the one that refuses
CP-D9no carrier depends on coordaxthe port measured in P1 to P4 breaks no-JAX imports, the NumPy and dask backends and, for GeoArray, batched georeferences

14Open questions

IDQuestionRecommended
CP-O1Are readers registered when their package is imported, or through entry points, so that pa.from_xarray finds gridax’s reader without import gridax?Entry points (pipekit.readers), loaded on the first call. A reader that needs its package imported first is the same trap as the adapters’ lazy registration, and the chain is only useful if it knows every reader.
CP-O2Is a positional axis None, as in coordax, or a sentinel object that cannot be a user’s name?None. It is what coordax and jax’s own named-axis work use, and it cannot be typed by accident. to_xarray refuses a carrier with a positional dim, naming pa.tag.
CP-O3Do the carriers also get __treescope_repr__, as coordax’s Field has?Not now. treescope would be a new optional dependency for one viewer; _repr_html_ covers Jupyter, VS Code and MyST.
CP-O4Does GeoArray’s abstract form also allow an abstract transform?Yes. Under eval_shape the transform is a leaf like the data, and a planner may not know the origins yet.
CP-O5Does coord_fields on a GeoArray with a batched transform give batched fields?Yes, (*batch, y, x), since centres is affine in a (*batch, 6) transform; check it against a loop over the batch.
CP-O6Is coordax’s Field still registered as a fifth carrier behind an extra (P5’s adapter)?Only when a user brings Fields. The patterns above make the stack’s carriers do what a Field would have added, and the adapter stays a small step for later.

15Steps

Each step is one issue, with its oracle and its gate. S1 to S3 follow S0 and can run in parallel; S4, S6 and S7 are independent of the others; S5 changes every adapter and goes last.

StepRepoWorkOracleGate
S0pipekitCoordinate, NoMatch, isel_coords in pipekit-ops; Labels in pipekit-array; DimArray stores its labels as coordinatesQ1: pa.isel on DimArray equal before and after for every indexer kind; pipekit_array.testing adapter tests green; import pipekit_array loads neither JAX nor xarrayCP-D1
S1gridaxStagger; CField stores labels and stagger as coordinates; CFieldAdapter uses isel_coords; demotion from definingQ1: 40 of 40 against the 0.4.4 behaviour; tests/test_numpy_only.py green; jit traces unchangedS0 released, CP-D2
S2geotoolzgeoarray’s protocol becomes pipekit-ops’s; its nine types gain to_xarray and from_xarray; _coordinate_vars goesevery round-trip test of GeoArray.to_xarray and from_xarray unchangedS0 released, CP-D1
S3pipekit, geotoolz, gridaxregister_reader and pa.from_xarray; the georeference and xgcm readers; CField.from_xarray refuses without xgcm attributesQ2: every carrier’s own DataArray reads back as that carrier, and the six cross cases either pick the right carrier or raise with every reasonS1, S2, CP-D3, CP-O1
S4pipekitmap_over over a tuple of dims with mapper=Q3: equal to nested map_over with jax.vmap; equal to round-off with a loopCP-D4
S5pipekit, geotoolz, gridaxpositional axes, pa.tag, pa.untag; every adapter’s dims accepts None; vmapped_dims and core_dims without "batch"Q4b: a ("batch", "x") item under vmap keeps its name; grep of every consumer for a dim named "batch" that relied on the old nameS0 to S3, CP-D5, CP-O2
S6pipekit, geotoolz, gridaxrender_html and the three _repr_html_a snapshot test per carrier; the renderer imports nothingCP-D7
S7pipekit, geotoolzpa.shape_struct; GeoArray accepts ShapeDtypeStruct dataQ7: eval_shape of a reduction gives the same dims and shape as running it, for all threeCP-D8, CP-O4
S8geotoolz, gridaxGeoArray.coord_fields(), gridax.coord_fields(field, grid)Q5: one trace over 20 origins; values equal to PixelGrid.centres; gridax’s equal to the x_c and x_g that to_xarray writesS1, S2, CP-D6, CP-O5

16What it does not do

Not hereWhere instead
a dependency on coordaxnone (CP-D9); a peer adapter later if asked (CP-O6)
operators on carriers, or coordax’s plain-array broadcastingcombine in each package, as today
coordinate values inside the trace for DimArraypipekit-array’s A9 keeps it to labels
longitude and latitude under jita host step with pyproj, or geoarray’s reprojection
lazy, by-value and many-file workxarray and xrops (labeled lane)

17References