Skip to content

feat(deck.gl-zarr): render arrays whose spatial dims aren't last, such as [y, x, band] - #788

Merged
kylebarron merged 5 commits into
mainfrom
kyle/zarr-spatial-dim-positions
Nov 4, 2026
Merged

kylebarron merged 5 commits into
mainfrom
kyle/zarr-spatial-dim-positions

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.

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 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, fix(geozarr): read Y and X from spatial:dimensions by position #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

ZarrLayer required an array's two spatial dims to be the last entries of
its dimension_names, in [y, x] order, and read tile sizes from the two
trailing chunk dims. A channel-last store, such as dimension_names
[lat, lon, band] with chunks [512, 512, 4], failed validation, and without
the check it would have been tiled 4 px wide.

The layer now finds each array's spatial dims by name and reads the tile
width and height from the chunk sizes at those positions.
validateSpatialDimOrder becomes findSpatialDimIndices, which only requires
the declared spatial dims to exist and returns their positions, so x before
y is accepted too. 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 the chunk comes
in the array's own dim order.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the feat label Oct 23, 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

Copy link
Copy Markdown
Member Author

Note

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

Brought this up to date with main in fecb98a, a merge of main (no force-push). The change is now re-applied on top of ZarrSource:

  • Source: ZarrSource.open (feat(deck.gl-zarr)!: open GeoZarr data with ZarrSource #812) finds the y and x dims in the arrays' dimension_names with findSpatialDimIndices. The dims come from spatial:dimensions by position (fix(geozarr): read Y and X from spatial:dimensions by position #785). It sizes each level's tiles from the chunk sizes at those positions. Before, it rejected any layout other than [..., y, x].
  • Layer: ZarrLayer's tile callback reads the tile size, and the array's width and height, at the same positions. On main it had started taking the width and height from the last two shape entries, so that lookup is fixed too.
  • Tests: ZarrSource's "rejects arrays with x before y" test and its transposed fixture group are gone. The old zarr-layer-spatial-dims.test.ts is folded into zarr-source.test.ts and zarr-layer.test.ts, which now share an in-memory array helper in tests/helpers.ts. The layer test reads an edge tile, so it also pins the shape lookup.
  • Description: updated to match.

Verified: the deck.gl-zarr and geozarr tests, pnpm -r test, pnpm -r --filter='!docs' typecheck (including the four Zarr examples) and biome ci. With src reverted to main, 8 tests fail. Reverting only the layer's chunk lookup, only its shape lookup, or only the source's chunk sizes fails 2 tests each.

🤖 Written by Claude Code

Comment on lines -94 to -107
if (yPos !== y || xPos !== x) {
if (yPos === x && xPos === y) {
throw new Error(
`Spatial dim order is swapped: expected ["${y}", "${x}"] at the ` +
`last two positions, got ["${yPos}", "${xPos}"]. Transpose is ` +
`not implemented yet.`,
);
}
throw new Error(
`Spatial dims must be the last two entries in dimension_names: ` +
`expected ["${y}", "${x}"] at positions [${n - 2}, ${n - 1}], got ` +
`["${yPos}", "${xPos}"]. Transpose is not implemented yet.`,
);
}

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 it ok for us to be removing this check?

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.

Not entirely, so I narrowed the check instead of removing it, in 711c65f5. The removed check also stopped arrays with x before y, and nothing transposes a chunk: getTileData gets zarr.get's chunk in the array's own order, so an [x, y] array would draw transposed, with no error, in an app that builds a row-major texture.

findSpatialDimIndices still finds the spatial dims anywhere, so [band, y, x] and #604's channel-last [y, x, band] work. It now throws when x comes before y, saying that needs a transpose, which isn't implemented. The ZarrSource test that rejects x before y is back as on main, and the docs say y comes before x.

🤖 Written by Claude Code

@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.

A couple questions but lgtm

Comment thread packages/deck.gl-zarr/src/validation.ts Resolved
Comment on lines +241 to +244
const tileWidth = arr.chunks[xIndex]!;
const tileHeight = arr.chunks[yIndex]!;
const arrayWidth = arr.shape[xIndex]!;
const arrayHeight = arr.shape[yIndex]!;

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.

should we have a safety valve here or just assume that the array has this index?

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.

A safety valve, but once, at open, in 4f04ca13. These positions come from source.dimensionNames, which are the first level's, and nothing checked that the other levels match.

ZarrSource.open now rejects levels whose dimension_names differ from the first level's, naming the level's path and both lists, with a test. The per-tile lookups here rely on that and stay unchecked, since they run on the tile hot path. A one-line comment above them says so.

🤖 Written by Claude Code

kylebarron and others added 3 commits November 4, 2026 17:18
findSpatialDimIndices found the spatial dims at any position and in
either order. Nothing transposes a chunk, and getTileData gets zarr.get's
chunk in the array's own dim order, so an [x, y] array would draw
transposed, with no error, in an app that builds a row-major texture.

It now throws when x comes before y, saying that needs a transpose, which
is not implemented. Y before x still works with other dims anywhere, such
as [band, y, x] or channel-last [y, x, band]. The ZarrSource test that
rejects x before y and its fixture group are back as on main.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ZarrSource takes its dimensionNames, and so the y and x positions, from
the first level's array, and ZarrLayer reads every level's chunks and
shape at those positions. Nothing checked that the other levels match.

ZarrSource.open now rejects levels whose dimension_names differ from the
first level's, naming the level and both lists. The per-tile lookups stay
unchecked, since they run on the tile hot path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kylebarron kylebarron changed the title feat(deck.gl-zarr): render arrays with spatial dims in any position feat(deck.gl-zarr): render arrays whose spatial dims aren't last, such as [y, x, band] Nov 4, 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.

✅

Comment on lines +97 to +99
`Spatial dim order is swapped: x dim "${x}" comes before y dim "${y}" ` +
`in zarr array dims [${dimensionNames.join(", ")}]. Arrays with x ` +
`before y need a transpose, which is not implemented.`,

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 4e162ee into main Nov 4, 2026
4 checks passed
@kylebarron
kylebarron deleted the kyle/zarr-spatial-dim-positions branch November 4, 2026 22:55
kylebarron added a commit that referenced this pull request Nov 9, 2026
> [!NOTE]
> This PR was written by Claude (Claude Code), not by @kylebarron.

A docs pass for 0.10, so that the site deployed with the release
describes the 0.10 API.

## Changes

- **Intro guide** (`docs/guides/intro.md`):
- The first sentence names Zarr. The features list adds merged range
requests and shared sources, and nodata masks leave the "Soon" list,
since the default pipeline applies a COG's mask.
  - The packages table gets a `range-reader` row.
- The "How It Works" diagram drops `GeoTIFFLayer`, which no longer
exists, and adds the other layers, the sources, `RasterTileLayer`, the
range reader and zarrita.
- A new "Sources" paragraph, and "Tile Streaming" says how the range
reader merges and caches reads.
- **deck.gl-geotiff README:** a "Layers and sources" section, with the
source each layer takes, opening a source yourself, and a `MosaicLayer`
over `parseVRT` items.
- **deck.gl-raster README:** points Zarr users to `ZarrLayer`. Both
layer links are now URLs. A `{@link}` to another package's symbol
renders as plain text on the docs site, and literally on GitHub and npm.
- **deck.gl-zarr README:** arrays may have other dimensions in any
position, as long as y comes before x (#788).
- **range-reader README:** "Status" points to #855 for Zarr, instead of
saying that sharded Zarr is next.
- **Relative links:** the geotiff and deck.gl-geotiff READMEs linked
`../range-reader/README.md`, which TypeDoc turns into a copy of the raw
file (`_media/README.md`). They now link the range-reader API page.
- **API docs:** TypeDoc links a type from another package only through
`crossPackageLinks`, which had no entries for the 0.10 types. It now
maps `RasterSource`, `DEFAULT_RANGE_READER`, `COGSource`,
`MultiCOGSource`, `ZarrSource`, the `range-reader` types and the `proj`
types they use. `COGSource`'s page, for example, now links "Extends
`RasterSource`".
- **`GetTileDataOptions` JSDoc** linked `ZarrLayerProps.getTileData`,
which TypeDoc can't resolve. That was the only TypeDoc warning.

## Checked

- `docusaurus generate-typedoc` reports no warnings, down from one, and
every page that `crossPackageLinks` maps to exists in its output.
- `docusaurus build` succeeds and reports no broken links. Its two
warnings are on main too: `onBrokenMarkdownLinks` is deprecated, and
`docs/docs` doesn't exist.
- The deck.gl-geotiff README's snippets typecheck against the package,
except for `noUnusedParameters` on `renderSource`'s `item`, which
`MosaicLayer`'s own docs also leave unused.
- Biome is clean.

Closes #853

🤖 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.

ZarrLayer: support band/channel-last arrays ([y, x, band]) — multiscale GeoZarr RGB(A) pyramids fail validateSpatialDimOrder

1 participant