Skip to content

fix(geozarr): read Y and X from spatial:dimensions by position - #785

Merged
kylebarron merged 4 commits into
mainfrom
kyle/geozarr-positional-dims
Nov 3, 2026
Merged

kylebarron merged 4 commits into
mainfrom
kyle/geozarr-positional-dims

Conversation

@kylebarron

@kylebarron kylebarron commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Note

This PR was written by Claude (Claude Code), not by @kylebarron.

parseGeoZarrMetadata found the Y and X axes only by the labels y/latitude/lat and x/longitude/lon, and threw for any other names, so ZarrLayer couldn't load data such as ["northing", "easting"].

v0.1 of the spatial convention orders spatial:dimensions by axis role: "the first entry names the dimension carrying the logical Y axis; the second entry names the dimension carrying the logical X axis" (README). Its schema allows exactly two entries (maxItems: 2). The array's own axis order is free: a reader finds each name in dimension_names.

Changes

  • parseGeoZarrMetadata takes Y from the first entry and X from the second, whatever their names. The label matching is gone.
  • The schema accepts exactly two entries. It accepted three, for the ["z", "y", "x"] of the pre-v0.1 draft in the vendored packages/geozarr/spatial submodule.
  • ZarrLayer needs no change: it matches the spatial dims against each array's dimension_names by name.

Every spatial:dimensions our examples read lists Y first: ["latitude", "longitude"] (ecmwf), ["lat", "lon"] (nldas) and ["y", "x"] (the AEF store).

Tests

New packages/geozarr/tests/parse.test.ts:

  • ["northing", "easting"] gives Y = northing and X = easting.
  • ["lon", "lat"] gives Y = lon and X = lat, by position.
  • Lists of 1 and 3 entries are rejected.

Closes #451

🤖 Written by Claude Code

The spatial convention leaves the names in `spatial:dimensions` free and
lists them in row-major order (`[y, x]` or `[z, y, x]`), so Y and X are
the last two entries. `parseGeoZarrMetadata` only recognized the labels
"y"/"latitude"/"lat" and "x"/"longitude"/"lon" and threw for any other
names, such as `["northing", "easting"]`, so ZarrLayer could not load
spec-compliant data that used them.

Keep the label match when both a Y and an X label are present, so every
dataset that parses today gets the same axes, including ones that list
the labels in a non-spec order such as `["lon", "lat"]`. Otherwise take Y
and X from the last two entries. The schema already requires at least
two entries, so the positional indices are always valid.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the fix label Oct 23, 2026
@kylebarron kylebarron added this to the 0.10 milestone Oct 30, 2026
Comment thread packages/geozarr/src/parse.ts Outdated
Comment on lines +17 to +19
* "lon"), ignoring case. Otherwise they are the last two entries, following
* the convention's row-major order (`[y, x]` or `[z, y, x]`), whatever their
* names.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this true? Can we link to a specific part of the geozarr spec / convention to back this up?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

This comment was written by Claude (Claude Code), not by @kylebarron.

No. It matched the pre-v0.1 draft vendored in packages/geozarr/spatial ("provide 2 elements in row-major order: ["y", "x"]", "For 3D spatial data, provide 3 elements: ["z", "y", "x"]"), not the released v0.1. v0.1 says spatial:dimensions "is ordered by axis role: the first entry names the dimension carrying the logical Y axis; the second entry names the dimension carrying the logical X axis" (README), with exactly two entries (schema). So the name matching was wrong too: under v0.1, ["lon", "lat"] means Y = lon.

711cd25d makes the code follow v0.1. Y is the first entry and X the second, whatever their names, and the schema allows exactly two entries. The docstring now says that and links to the convention. Every store our examples read lists Y first, so none of them changes. I updated the PR description to match.

🤖 Written by Claude Code

…e convention says

The spatial convention orders spatial:dimensions by axis role: Y first,
then X, whatever their names, with exactly two entries. Drop the label
matching and the last-two fallback, and allow only two entries.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kylebarron kylebarron changed the title fix(geozarr): accept arbitrary spatial:dimensions names fix(geozarr): read Y and X from spatial:dimensions by position Nov 3, 2026

@kylebarron kylebarron left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅

@kylebarron
kylebarron merged commit 79a59a6 into main Nov 3, 2026
4 checks passed
@kylebarron
kylebarron deleted the kyle/geozarr-positional-dims branch November 3, 2026 00:17
kylebarron added a commit that referenced this pull request Nov 4, 2026
Re-applies the change on top of ZarrSource (#812). ZarrSource.open finds
the y and x dims (from spatial:dimensions by position, #785) in the arrays'
dimension_names with findSpatialDimIndices, and sizes each level's tiles
from the chunk sizes at those positions. ZarrLayer's tile callback reads
the tile and array sizes at the same positions.

The old layer test file is folded into the ZarrSource and ZarrLayer test
files, with a shared in-memory array helper. The "rejects arrays with x
before y" ZarrSource test and its fixture group are gone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
kylebarron added a commit that referenced this pull request Nov 4, 2026
…h as [y, x, band] (#788)

> [!NOTE]
> This PR was written by Claude (Claude Code), not by @kylebarron.

`ZarrSource` and `ZarrLayer` required an array's two spatial dims to be
the last entries of its `dimension_names`, in `[y, x]` order, and read
tile and array sizes from the two trailing dims. A channel-last store,
such as `dimension_names: ["lat", "lon", "band"]` with chunks `[512,
512, 4]`, failed to open, and without the check it would have been tiled
4 px wide. Now each spatial dim is found by name, as the [spatial
convention](https://github.com/zarr-conventions/spatial/blob/54d81b7ced0376e63ee10f34db31db7d08dcc28d/README.md?plain=1#L94-L98)
says: "A reader locates each spatial axis in the array by looking up its
name in `dimension_names`." Y must still come before x, and other dims
may sit anywhere.

## Changes

- `validateSpatialDimOrder` becomes `findSpatialDimIndices`. It finds
the y and x dims (the first and second entries of `spatial:dimensions`,
#785) in `dimension_names` and returns their positions. Other dims may
sit anywhere, such as `[band, y, x]` or channel-last `[y, x, band]`.
- It still throws when x comes before y, such as `[x, y]`, saying that
needs a transpose, which is not implemented. Nothing transposes a chunk,
so such an array would otherwise draw transposed, with no error, in an
app that builds a row-major texture.
- `ZarrSource.open` sizes each level's tiles from the chunk sizes at
those positions, instead of the last two chunk dims. It also rejects
levels whose `dimension_names` differ from the first level's, naming the
level and both lists, since `ZarrSource.dimensionNames` holds one list
for every level.
- `ZarrLayer`'s tile callback reads the tile size and the array's width
and height at the same positions, for each tile's bounds, `width` and
`height`. The slice spec was already built by dim name, so tile slices
land at the spatial positions and the `selection` fills the rest.
- `getTileData` and `renderTile` are required props, so the caller
already handles each chunk's layout. The `getTileData` docs now say y
comes before x, and `zarr.get` returns the chunk in the array's own dim
order. The public API is unchanged.

## Tests

- `findSpatialDimIndices` returns the positions for trailing,
channel-last and split (`[y, band, x]`) layouts, and throws for x before
y and for a missing spatial dim.
- A new in-memory array helper opens a 1000-row by 2000-column array,
chunked 256 by 512, with `lat`, `lon` and an optional `band` dim in any
order. The rows and columns differ, so a swap of y and x shows.
- `ZarrSource.open` gives 512 by 256 tiles for `[lat, lon]`, `[band,
lat, lon]` and `[lat, lon, band]` arrays. It still rejects arrays with x
before y, as on `main`, and rejects a pyramid whose `r20m` level has a
`time` dim that its `r10m` level lacks.
- `ZarrLayer` reads the last (edge) tile of each of those three arrays,
with the expected `sliceSpec` and a 464 by 232 size. That pins both the
chunk and the shape lookups.
- With `src` reverted to `main`, 8 tests fail: the channel-last source
and layer tests, with the issue's "Spatial dims must be the last two
entries" error, the mixed-levels test, and the `findSpatialDimIndices`
tests. The `[lat, lon]` and `[band, lat, lon]` cases, and the source
test that rejects x before y, pass on `main` and pin the unchanged
behavior.

Closes #604

🤖 Written by [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
kylebarron added a commit that referenced this pull request Nov 5, 2026
> [!NOTE]
> This PR was written by Claude (Claude Code), not by @kylebarron.

Bumps `version` to `0.10.0-beta.3` in the root `package.json` and in
every `packages/*/package.json`. The publish workflow publishes it under
the `beta` dist-tag, so `latest` stays on 0.9.0.

`CHANGELOG.md` gets a `v0.10.0-beta.3` section with GitHub's generated
notes for the 17 PRs merged since v0.10.0-beta.2.

## Breaking change

- #843: `MosaicLayer` no longer takes `maxCacheByteSize`. To bound an
item's memory by bytes, set `maxCacheByteSize` on the layer that
`renderSource` returns.

## Behavior changes

- #839: a `MosaicLayer` item out of view keeps its opened source in the
cache but drops its layers, which frees their textures.
- #785: `parseGeoZarrMetadata` takes Y from the first entry of
`spatial:dimensions` and X from the second, whatever their names, as
v0.1 of the spatial convention says. Lists that aren't two entries long
are rejected.
- #841: `RasterTileset2D.getParentIndex` picks the parent tile that
contains the child's centre.

## New APIs

- #835: `parseVRT` in `@developmentseed/deck.gl-geotiff`, and `fromGDAL`
in `@developmentseed/affine`.
- #789: `renderSource` gets the props that `MosaicLayer` passes to its
sublayers.

## Not included

#838 (`ZarrSource` opens from a store with a `path`) and #837
(`DEFAULT_RANGE_READER` moves to `@developmentseed/deck.gl-raster`) are
still open. Both are breaking.

🤖 Written by [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

geozarr: Double check correct implementation of spatial:dimensions

1 participant