Repository navigation
feat(deck.gl-zarr): render arrays whose spatial dims aren't last, such as [y, x, band] - #788
Conversation
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]>
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]>
|
Note This comment was written by Claude (Claude Code), not by @kylebarron. Brought this up to date with
Verified: the deck.gl-zarr and geozarr tests, 🤖 Written by Claude Code |
| 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.`, | ||
| ); | ||
| } |
There was a problem hiding this comment.
is it ok for us to be removing this check?
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
A couple questions but lgtm
| const tileWidth = arr.chunks[xIndex]!; | ||
| const tileHeight = arr.chunks[yIndex]!; | ||
| const arrayWidth = arr.shape[xIndex]!; | ||
| const arrayHeight = arr.shape[yIndex]!; |
There was a problem hiding this comment.
should we have a safety valve here or just assume that the array has this index?
There was a problem hiding this comment.
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
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]>
… its signature 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]>
| `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.`, |
> [!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]>
Note
This PR was written by Claude (Claude Code), not by @kylebarron.
ZarrSourceandZarrLayerrequired an array's two spatial dims to be the last entries of itsdimension_names, in[y, x]order, and read tile and array sizes from the two trailing dims. A channel-last store, such asdimension_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 indimension_names." Y must still come before x, and other dims may sit anywhere.Changes
validateSpatialDimOrderbecomesfindSpatialDimIndices. It finds the y and x dims (the first and second entries ofspatial:dimensions, fix(geozarr): read Y and X fromspatial:dimensionsby position #785) indimension_namesand returns their positions. Other dims may sit anywhere, such as[band, y, x]or channel-last[y, x, band].[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.opensizes each level's tiles from the chunk sizes at those positions, instead of the last two chunk dims. It also rejects levels whosedimension_namesdiffer from the first level's, naming the level and both lists, sinceZarrSource.dimensionNamesholds 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,widthandheight. The slice spec was already built by dim name, so tile slices land at the spatial positions and theselectionfills the rest.getTileDataandrenderTileare required props, so the caller already handles each chunk's layout. ThegetTileDatadocs now say y comes before x, andzarr.getreturns the chunk in the array's own dim order. The public API is unchanged.Tests
findSpatialDimIndicesreturns the positions for trailing, channel-last and split ([y, band, x]) layouts, and throws for x before y and for a missing spatial dim.lat,lonand an optionalbanddim in any order. The rows and columns differ, so a swap of y and x shows.ZarrSource.opengives 512 by 256 tiles for[lat, lon],[band, lat, lon]and[lat, lon, band]arrays. It still rejects arrays with x before y, as onmain, and rejects a pyramid whoser20mlevel has atimedim that itsr10mlevel lacks.ZarrLayerreads the last (edge) tile of each of those three arrays, with the expectedsliceSpecand a 464 by 232 size. That pins both the chunk and the shape lookups.srcreverted tomain, 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 thefindSpatialDimIndicestests. The[lat, lon]and[band, lat, lon]cases, and the source test that rejects x before y, pass onmainand pin the unchanged behavior.Closes #604
🤖 Written by Claude Code