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
Status: proposed. Decisions CP-D1 to CP-D9 and questions CP-O1 to CP-O6 are the owner’s. It keeps GA-T4 and LL-G2 (21 Oct 2026, geoarray and labeled lane): coordax stays out of the carriers’ dependencies.
Repositories: pipekit (pipekit-ops, pipekit-array), geotoolz (geotoolz-array), gridax, and geostack for this page.
Surveyed:
origin/mainof pipekit at7568691(pipekit-array 0.3.3), geotoolz atba3bd0c6(geotoolz-array 0.6.1) and gridax at83c8b27(gridax 0.4.4), fetched on 4 Dec 2026, with coordax 0.2.9 from PyPI read in full.Prototype: every number on this page comes from a script in
scratch/geostack/coordax-port/, with each script’s printed output beside it:patterns/q1_coordinates.pytopatterns/q4b_batch_clash.pyfor the seven patterns, andp1_imports_backends.pytop5_field_adapter.pyfor the port that was rejected. They ran on CPU with JAX 0.12.1, NumPy 2.4, xarray 2026.12.0 and Python 3.13, against the three packages installed from the commits above. The scripts are design evidence, not results of this repository’s pipeline, so they are kept in the owner’s scratch space and not committed here. No decision rests on them alone: each step below names an oracle that re-measures the same property in the owning repository’s tests before that step merges.
1TL;DR¶
Depending on coordax was measured and rejected. It would load JAX at import in three packages that promise not to, turn NumPy data into JAX arrays and refuse dask, and, for
GeoArray, compile once per scene because its coordinates are static (20 compiles for 20 origins, and novmapover patches). The numbers are in the background section.Its design is still better than ours in seven places, and each can be taken without the dependency:
Coordinates that slice themselves (CP-D1, CP-D2). One
Coordinateprotocol in pipekit-ops, lifted from the one geoarray already has, so one genericiselreplaces three adapters’ metadata code. The prototype matched today’spa.iselin 40 of 40 cases forCFieldand 10 of 10 forDimArray, and geoarray’sSpectralAxisworked through it unchanged.An xarray reader chain that explains a refusal (CP-D3). Today, of the six calls that give one carrier’s reader another carrier’s DataArray, four drop the other carrier’s metadata without a word, and two of those call the result a C-grid field:
CField.from_xarrayreads a georeferenced cube as aCFieldat T. A chain of readers, each returning a carrier or a reason, picked the right carrier for all three, and its refusal named why each reader declined.Mapping over several dims with a pluggable mapper (CP-D4). One call over
("member", "time")withmapper=jax.vmapor a loop, equal to nestedpa.map_overto the bit.Positional axes in place of an invented name (CP-D5). Today a bare
vmapcalls its new axis"batch", and a carrier built insidevmapwith a dim of its own called"batch"loses that name to the mapped axis. A positional axis (None) cannot clash, andpa.tagnames it.Derived fields from coordinates (CP-D6). A georeference’s map coordinates computed from the leaf transform under
jit: one trace for 20 origins.Rich display (CP-D7). None of the three carriers has a notebook hook today.
Abstract carriers (CP-D8).
DimArrayandCFieldalready accept ajax.ShapeDtypeStructas data;GeoArrayrefuses one at construction.
Nothing here changes what is static and what is a leaf. The transform stays a float64 leaf and the stagger stays static, so every compile count stays what it is today.
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.
Metadata code is written three times. Each adapter slices its own labels, stagger or coordinates in
isel, rebuilds itself inrewrap, and decides what it becomes when a dim goes.DimArrayAdapterspends 65 lines on this,CFieldAdapter26, and geoarray 66 between its adapter andGeoArray.isel. geoarray already has a better shape for it: aCoordinateper dim that slices itself.The xarray boundary guesses. Three readers each assume the DataArray is theirs. Given another carrier’s DataArray, most of them return something wrong without an error.
vmapinvents a name. A barevmapover a carrier gives its new axis the dim"batch", which is a real name a user may already have chosen.Notebook use is bare. None of the carriers renders in Jupyter beyond its one-line
repr, andGeoArraycannot be built from a shape alone.
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¶
A pipekit maintainer fixes a bug in how labels follow a list indexer, and wants to fix it once rather than in three adapters.
A gridax maintainer adds a fifth C-grid point, and wants
iseland demotion to follow from the new coordinate instead of from edits to_locatedandrewrap.An ocean analyst opens a NetCDF file whose DataArray might be a C-grid field, a georeferenced raster or neither. They call one
from_xarrayand expect either the right carrier or an error that says why none fit.A geotoolz user writes
jax.vmapover patches whose own dims include one called"batch", and expects the names to survive.An ensemble user computes a spatial mean for every member and every time step, under
vmapon a GPU and in a plain loop on a laptop, with one call.A retrieval developer needs the map coordinates of every pixel centre inside a jitted model, for every scene, without recompiling per scene.
A notebook user looks at a carrier in Jupyter and wants its dims, sizes, labels, position and georeference at a glance.
A pipeline author plans the output of a patch-wise run with
jax.eval_shapebefore any data exists.
4Scope¶
In scope
Seven patterns, each taken into the carriers by the package that owns the concept: the coordinate protocol and the generic
isel(pipekit-ops), the reader chain, the mapper, positional axes and display (pipekit-ops and pipekit-array), coordinate types and derived fields (geoarray, gridax), and abstract carriers (all three).The coordinate types each carrier keeps:
LabelsforDimArrayandCField,StaggerforCField, and geoarray’s existing nine types.
Out of scope
A dependency on coordax, in any form. The background section on it records why.
Operators on carriers. All three keep
__array_ufunc__ = Noneandcombine; coordax’s operators and its plain-array broadcasting are not taken.Coordinate values inside the trace for
DimArray. pipekit-array’s decision A9 keeps it to “no coordinates beyond static labels”, and nothing here changes that.GeoSwathandGeoPoints. Their geometry is per-pixel leaves; they gain the protocol later if the owner wants it.
5Background¶
Notation¶
A carrier is a pair of an array and its coordinates:
where is the data of shape , the tuple of its dims, and the coordinate of dim , 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 , is not a coordinate; it sits beside 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 is
where are the leaves of carrier and its static data. The coordinates are in , so a pattern that only changes how coordinates are written changes no compile count, as long as it puts nothing new into . Every pattern below keeps to that.
The three carriers on origin/main, read from their source.
DimArray | GeoArray | CField | |
|---|---|---|---|
| Package, version | pipekit-array 0.3.3 | geotoolz-array 0.6.1 (geoarray) | gridax 0.4.4 |
| Leaves | data | data, transform (*batch, 6) float64 | data |
| Static | dims, labels | crs, fill_value, attrs, dims, coords | dims, labels, stagger |
| Coordinates today | a dict of label tuples | nine Coordinate types, one per dim | label tuples and a stagger tuple |
| Imports JAX | no | no | no, and a test checks it |
| Notebook display | one-line repr | one-line repr | one-line repr |
Slicing commutes with coordinates¶
Selection by position on dim with an indexer (an integer, a slice or a list of positions) acts on the data and on that dim’s coordinate, and on nothing else:
where indexes axis and is the coordinate sliced the same way, or dropped when is an integer. Each adapter today writes this rule by hand for its own metadata. coordax writes it once and asks each coordinate for ; 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 on each coordinate that says whether it defines the carrier’s kind,
so demotion is decided by the coordinates that are left, not by code in the adapter.
Mapping over named dims¶
Mapping over dims of applies to every item and stacks the results, mapped dims first:
where runs over . 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 sits at
where is the transform, the row and the column. Both are affine in the leaf , 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 page | coordax | pipekit-array | geoarray | gridax |
|---|---|---|---|---|
| carrier | Field | DimArray | GeoArray | CField |
| coordinate | Coordinate | (labels in the adapter) | Coordinate | (labels and stagger in the adapter) |
_isel | DimArrayAdapter.isel | Coordinate.isel | CFieldAdapter.isel | |
| a reader’s refusal | NoCoordinateMatch(reason) | — | — | — |
cmap(f, vmap=…) | map_over(x, f, dim), one dim | — | — | |
| a positional axis | None in dims, tag, untag | "batch" from vmapped_dims | the same | the same |
| derived values | Coordinate.fields, Field.coord_fields | — | PixelGrid.centres(transform) | grid.coords(dim) |
| abstract carrier | shape_struct_field | accepts ShapeDtypeStruct | refuses it | accepts 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.
| Script | Measurement | Result |
|---|---|---|
| P1 | import 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 |
| P1 | NumPy and dask data | DimArray 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 |
| P2 | jit over 20 scenes with different origins | GeoArray 1 compile; a Field with a static grid coordinate 20; a Field with the transform as a leaf beside it 1 |
| P2 | vmap over 4 patches with different origins | GeoArray works; a static grid coordinate raises ValueError |
| P2 | xarray round trip | with 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,) array | gridax (122, 162); coordax (162, 122, 162) with no error |
| P4 | eager add with JAX data | bare 40 µs, DimArray 45 µs, CField 43 µs, Field 1 181 µs; compiled programs identical |
| P5 | a Field in pipekit’s adapter registry | about 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.
| Script | Pattern | Measurement | Result |
|---|---|---|---|
| Q1 | coordinates | generic isel with Labels and Stagger against pa.isel on CField, points T, U, V, X, ten indexers each | 40 of 40 equal: data, dims, labels, stagger and the demotion to DimArray |
| Q1 | coordinates | the same on DimArray | 10 of 10 equal |
| Q1 | coordinates | geoarray’s SpectralAxis through the generic isel, bands [2, 0] | labels ('B04', 'B02'), wavelengths (665.0, 490.0), with no change to geoarray |
| Q1 | coordinates | jit over CField points T, T, U, U | 2 traces, as today |
| Q1 | coordinates | metadata code in the adapters today | DimArrayAdapter isel + rewrap + relabel 65 lines; CFieldAdapter with check_compatible and _located 26; geoarray’s adapter isel + rewrap 45 and GeoArray.isel 21 |
| Q1 | coordinates | the prototype | generic isel and demotion 13 lines; Labels and Stagger 23 lines |
| Q2 | reader chain | three readers today, each given each carrier’s DataArray | see the table below: each reads its own; of the six cross calls, 2 raise and 4 drop metadata with no error |
| Q2 | reader chain | a chain of the three, each returning a carrier or a reason | 3 of 3 right; a DataArray none of the two geo readers claims raises with both reasons |
| Q3 | mapper | nested pa.map_over against one call over ("member", "time") with jax.vmap, and with a loop | dims ('member', 'time') in all three; vmap equals nested to 0.0, loop equals vmap to 2.2 × 10⁻⁸ |
| Q3 | mapper | eager cost, 20 items | vmap 3.0 ms, loop 10.3 ms per call |
| Q3 | mapper | pa.map_over with np.nanmean on NumPy data | falls back to a loop today and returns NumPy |
| Q4 | positional axes | a bare vmap of each carrier | dims ('batch', 'y', 'x') for all three |
| Q4 | positional axes | vmap of 2 items, each a ('member', 'x') carrier of shape (3, 4) | sizes {batch: 2, member: 3, x: 4} |
| Q4 | positional axes | the 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 |
| Q5 | derived fields | jit(lambda g: g.pixel_grid.centres(g.transform)) over 20 origins | 1 trace, shape (64, 64) |
| Q5 | derived fields | pyproj longitude and latitude under jit | TracerArrayConversionError; on the host, lon 16.1116, lat 36.1395 at pixel (0, 0) |
| Q6 | display | _repr_html_, __treescope_repr__ or _repr_mimebundle_ on each carrier | none on any |
| Q7 | abstract carriers | a 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().
| Reader | GeoArray’s DataArray | CField’s DataArray | DimArray’s DataArray |
|---|---|---|---|
GeoArray.from_xarray | GeoArray, CRS 32633 | AttributeError: 'NoneType' object has no attribute 'to_epsg' | ValueError: no grid |
CField.from_xarray | CField at T, georeference dropped | CField at U | CField at T on (member, time) |
pipekit_array.bridges.xarray.from_xarray | DimArray, georeference dropped | DimArray on (y_c, x_g), position dropped | DimArray |
What follows from it.
The coordinate protocol is a refactor, not a new behaviour. It reproduced today’s slicing and demotion exactly, kept the compile counts, and geoarray’s types needed no change to pass through it. What it buys is one place to fix a slicing bug instead of three, and a new point or coordinate type that needs no adapter edit.
The line counts are indicative, not a saving to promise. The prototype handles labels, stagger and demotion; geoarray’s
iselalso moves the transform’s origin, which stays geoarray’s code. The real saving is the adapters’ metadata branches, not their whole bodies.The reader problem is real. Four of the six cross calls drop metadata without an error. The worst is
CField.from_xarray, which accepts anything and calls it T. pipekit’s reader is right to return aDimArray, but it keeps gridax’sy_candx_gdim names, so the position is lost and a laterCFieldcannot be built from it by name. One of the two errors is anAttributeErrorfrom inside geoarray, which does not say what was wrong.The mapper is a convenience, measured as exact. Nesting
map_overalready works; the gain is one call and a choice of mapper. The loop is about three times slower eagerly here, which is the reason the choice belongs to the caller.The
"batch"clash is a silent renaming. It needs no unusual code: any function that builds a carrier with a dim called"batch"insidevmaptriggers it.Derived fields are free under
jitonly for affine maps. Map coordinates trace once per shape; longitude and latitude need pyproj and stay a host step.
Numerics that are design constraints.
Nothing new goes into the static data per scene. A coordinate that held per-scene numbers would multiply compiles, as P2 measured for coordax’s static grid.
Coordinates compare exactly. They are static and hashed; geoarray’s float tolerance for transforms stays where it is, on the leaf.
A coordinate must slice itself for every indexer kind. An integer drops it, a slice or a list keeps it with the new size. A type that gets this wrong breaks
iselon every carrier that holds it, as coordax’s_iseldoes when missing.
8Prior art¶
Read on 4 Dec 2026.
| Library | What it has | What to take | What to avoid |
|---|---|---|---|
| coordax 0.2.9 | Coordinate 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_field | all seven patterns | static 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 point | the isinstance chain in its xarray writer (_coordinate_vars), which the protocol replaces |
| xarray 2026.12.0 | IndexVariables that slice with the data; an open backend-engine registry for readers | the idea that a reader is registered by the package that owns the format | coordinate values as arrays beside the data |
9What it builds on¶
| Need | Upstream name | State |
|---|---|---|
the adapter registry the generic isel sits behind | pipekit_ops.carriers.register_adapter, NamedArrayAdapter | today (pipekit-ops) |
| the coordinate protocol | geoarray._src.coords.Coordinate | today (geoarray), to be lifted |
| the dim functions | pipekit_array.isel, reduce, map_over, batch | today (pipekit-array 0.3.3) |
| the batch naming to replace | pipekit_array.named._carrier.vmapped_dims, core_dims | today (pipekit-array) |
| the readers to chain | GeoArray.from_xarray, CField.from_xarray, pipekit_array.bridges.xarray.from_xarray | today |
| map coordinates from the transform | PixelGrid.centres(transform) | today (geoarray) |
| a C-grid’s coordinates at centres and faces | grid.coords(dim), and the x_c, x_g variables CField.to_xarray writes | today (gridax) |
Gaps, each sent to the package that owns the concept.
| Gap | Owner | Why there |
|---|---|---|
the Coordinate protocol with to_xarray and from_xarray, NoMatch, and the generic coordinate isel | pipekit-ops, in pipekit_ops.carriers | the adapter registry lives there, and every carrier package already depends on it |
Labels, a coordinate for exact labels | pipekit-array | DimArray is its first user; gridax reuses it |
the reader registry and pa.from_xarray that walks it | pipekit-array, in pipekit_array.bridges.xarray | the xarray bridge is already there, behind the xarray extra |
map_over over several dims with mapper= | pipekit-array | map_over is there |
positional axes, pa.tag, pa.untag | pipekit-array, with the adapters in each package | vmapped_dims is there; each adapter’s dims must accept None |
| the HTML renderer | pipekit-ops | it 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 data | geoarray | it owns the georeference and its CF convention (LL-F1) |
Stagger; the C-grid reader; gridax.coord_fields(field, grid) | gridax | it 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¶
| Pattern | pipekit-ops | pipekit-array | geoarray | gridax |
|---|---|---|---|---|
| 1. coordinates | Coordinate, NoMatch, isel_coords | Labels; DimArray stores its labels as coordinates | its nine types gain to_xarray, from_xarray | Stagger; CField stores labels and stagger as coordinates |
| 2. reader chain | — | register_reader, pa.from_xarray | registers the georeference reader | registers the xgcm reader |
| 3. mapper | — | map_over(x, f, dims, mapper=) | — | — |
| 4. positional axes | None allowed in an adapter’s dims | vmapped_dims gives None; pa.tag, pa.untag | adapter accepts None | adapter accepts None |
| 5. derived fields | — | — | GeoArray.coord_fields() | gridax.coord_fields(field, grid) |
| 6. display | render_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.
| Piece | Rung | Kind | Package | Used by |
|---|---|---|---|---|
Coordinate, NoMatch | ⓪ structure | protocol, record | pipekit-ops | every coordinate type, every reader |
Labels, Stagger, geoarray’s nine types | ⓪ structure | static coordinates | pipekit-array, gridax, geoarray | the carriers |
isel_coords | ① primitive | function | pipekit-ops | every adapter’s isel |
pa.from_xarray, register_reader | ① primitive | function, registry | pipekit-array | users at the xarray boundary |
map_over with mapper= | ① primitive | function | pipekit-array | analyses, ensembles |
pa.tag, pa.untag | ① primitive | function | pipekit-array | code after a bare vmap |
coord_fields | ① primitive | method, function | geoarray, gridax | model code under jit |
render_html, pa.shape_struct | ① primitive | function | pipekit-ops, pipekit-array | notebooks, 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:
defining: bool, defaultFalse. A carrier whose coordinates include a defining one keeps its kind; otherwise it demotes toDimArray.Staggeris defining;Labelsis not.to_xarray() -> dict[str, tuple], the xarray variables this coordinate writes, keyed by name. It replaces geoarray’s isinstance chain and gridax’s hand-writtenx_candx_g.from_xarray(dims, coords) -> Self | NoMatch, a class method that claims the coordinate from a DataArray’s coordinates or says why not.
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_fieldsNo 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 labelsA 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.
| ID | Decision | Main reason |
|---|---|---|
| CP-D1 | pipekit-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 coordinates | the prototype reproduced today’s slicing on DimArray and CField in 50 of 50 cases, and geoarray’s types passed unchanged |
| CP-D2 | DimArray and CField store labels as Labels and the stagger as a Stagger per grid dim; demotion follows from defining | demotion is decided in one place, and a new point or coordinate needs no adapter edit |
| CP-D3 | one 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 attributes | four of the six cross calls today drop metadata with no error, two of them into a CField at T |
| CP-D4 | map_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-D5 | a 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 special | the "batch" name silently moves to the mapped axis when a user has a dim of that name |
| CP-D6 | GeoArray.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 step | affine coordinates trace once per shape; pyproj cannot run under jit |
| CP-D7 | each carrier has a _repr_html_ from one renderer in pipekit-ops that reads the adapter and the coordinates | no carrier has a notebook display today, and one renderer keeps the three consistent |
| CP-D8 | GeoArray accepts ShapeDtypeStruct data, and pa.shape_struct(x) returns any carrier with abstract data | DimArray and CField already do; GeoArray is the one that refuses |
| CP-D9 | no carrier depends on coordax | the port measured in P1 to P4 breaks no-JAX imports, the NumPy and dask backends and, for GeoArray, batched georeferences |
14Open questions¶
| ID | Question | Recommended |
|---|---|---|
| CP-O1 | Are 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-O2 | Is 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-O3 | Do 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-O4 | Does 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-O5 | Does 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-O6 | Is 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.
| Step | Repo | Work | Oracle | Gate |
|---|---|---|---|---|
| S0 | pipekit | Coordinate, NoMatch, isel_coords in pipekit-ops; Labels in pipekit-array; DimArray stores its labels as coordinates | Q1: 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 xarray | CP-D1 |
| S1 | gridax | Stagger; CField stores labels and stagger as coordinates; CFieldAdapter uses isel_coords; demotion from defining | Q1: 40 of 40 against the 0.4.4 behaviour; tests/test_numpy_only.py green; jit traces unchanged | S0 released, CP-D2 |
| S2 | geotoolz | geoarray’s protocol becomes pipekit-ops’s; its nine types gain to_xarray and from_xarray; _coordinate_vars goes | every round-trip test of GeoArray.to_xarray and from_xarray unchanged | S0 released, CP-D1 |
| S3 | pipekit, geotoolz, gridax | register_reader and pa.from_xarray; the georeference and xgcm readers; CField.from_xarray refuses without xgcm attributes | Q2: every carrier’s own DataArray reads back as that carrier, and the six cross cases either pick the right carrier or raise with every reason | S1, S2, CP-D3, CP-O1 |
| S4 | pipekit | map_over over a tuple of dims with mapper= | Q3: equal to nested map_over with jax.vmap; equal to round-off with a loop | CP-D4 |
| S5 | pipekit, geotoolz, gridax | positional 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 name | S0 to S3, CP-D5, CP-O2 |
| S6 | pipekit, geotoolz, gridax | render_html and the three _repr_html_ | a snapshot test per carrier; the renderer imports nothing | CP-D7 |
| S7 | pipekit, geotoolz | pa.shape_struct; GeoArray accepts ShapeDtypeStruct data | Q7: eval_shape of a reduction gives the same dims and shape as running it, for all three | CP-D8, CP-O4 |
| S8 | geotoolz, gridax | GeoArray.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 writes | S1, S2, CP-D6, CP-O5 |
16What it does not do¶
| Not here | Where instead |
|---|---|
| a dependency on coordax | none (CP-D9); a peer adapter later if asked (CP-O6) |
| operators on carriers, or coordax’s plain-array broadcasting | combine in each package, as today |
coordinate values inside the trace for DimArray | pipekit-array’s A9 keeps it to labels |
longitude and latitude under jit | a host step with pyproj, or geoarray’s reprojection |
| lazy, by-value and many-file work | xarray and xrops (labeled lane) |
17References¶
coordax: repository and documentation, read at 0.2.9:
coordinate_systems.py(Coordinate,NoCoordinateMatch,fields),fields.py(cmap,cpmap,coord_fields,tag,untag,shape_struct_field,__treescope_repr__).xgcm’s grid positions: documentation, the convention gridax’s
to_xarraywrites.geoarray, decisions GA-A2, GA-B1 and GA-T4; labeled lane, LL-F1, LL-G1 and LL-G2.
pipekit-array’s decision A9 (
packages/pipekit-array/docs/design/decisions.mdin pipekit), which keepsDimArrayto static labels.gridax’s
docs/fields.md, on whyCFieldhas no operators and no grid.Carrier arrays, which introduces coordax’s
Fieldas a candidate carrier.