Skip to content

feat(deck.gl-zarr)!: open GeoZarr data with ZarrSource - #812

Merged
kylebarron merged 6 commits into
mainfrom
kyle/zarr-source
Oct 28, 2026
Merged

kylebarron merged 6 commits into
mainfrom
kyle/zarr-source

Conversation

@kylebarron

@kylebarron kylebarron commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Note

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

Stage 4b of the Sources design, part 2 of 2 (dev-docs/specs/2026-10-22-sources-design.md, decisions 21 to 23). It builds on #811, which moved the projection helpers into @developmentseed/proj.

ZarrSource.open opens GeoZarr data once, and ZarrLayer draws it:

import { ZarrLayer, ZarrSource } from "@developmentseed/deck.gl-zarr";

const source = await ZarrSource.open(group, { variable: "temperature" });
const { west, south, east, north } = source.geographicBounds;

new ZarrLayer({
  id: "temperature",
  source,
  selection: { time: 0 },
  getTileData,
  renderTile,
});
  • ZarrSource.open(node, options) takes a zarrita group or array. It does four things:

    • reads the GeoZarr metadata from the node's attributes, or from geoZarrMetadata;
    • opens the array of each level;
    • resolves the CRS;
    • builds the tile grid and the WGS84 bounds of the finest level.

    Its options are variable, geoZarrMetadata, epsgResolver and signal.

  • The source holds:

    • arrays, one per level, finest first;
    • dimensionNames and spatialDims;
    • projection;
    • tilesetDescriptor and geographicBounds. Bounds are new for Zarr.

    It doesn't keep the parsed GeoZarr metadata, since nothing outside open needs it (question 9).

  • ZarrLayer's source takes a ZarrSource, or a group or array for the layer to open with the defaults. onSourceLoad gets the source the layer opened. As in COGLayer, RasterTileLayer handles the rest.

  • selection stays on the layer (decision 22). The layer checks it against the source whenever either differs from the pair it last checked. That includes a source opened from input arriving, and a selection that changed while no source was drawn.

    • A selection that doesn't fit goes to onError as "Can't draw the selection in ZarrLayer: ...", and the layer draws nothing until the selection is fixed. Before, an invalid selection failed the whole load, as "Metadata loading failed in ZarrLayer: ...".
    • Changing the selection never opens the source again.
    • Selections are compared by value, so an inline literal isn't checked again on every render.
    • Tiles already loaded still keep the data of the selection they were fetched with, until stage 4c. The selection docs now say so; the old docs recommended updateTriggers, which doesn't fetch again.
  • Edge tiles are clipped to each array's own shape, rather than to the GeoZarr metadata's.

  • Cleanup: the window.* debug lines are gone.

  • Readonly: arrays and dimensionNames are readonly, since layers share a source.

Migration

node, variable, metadata and epsgResolver are removed from ZarrLayer. metadata becomes the geoZarrMetadata option of ZarrSource.open.

// Before
new ZarrLayer({
  node: group,
  variable: "temperature",
  metadata: attrs,
  selection,
  getTileData,
  renderTile,
});

// After: a group or array as the source...
new ZarrLayer({ source: group, selection, getTileData, renderTile });

// ...or, to use the options, an opened source
const source = await ZarrSource.open(group, {
  variable: "temperature",
  geoZarrMetadata: attrs,
});
new ZarrLayer({ source, selection, getTileData, renderTile });

TypeScript rejects the removed props. JavaScript ignores them, and without a source the layer draws nothing.

The type parameters are reordered:

  • ZarrLayer: ZarrLayer<Store, Dtype, DataT> becomes ZarrLayer<DataT, Dtype, Store>, and ZarrLayerProps changes the same way. The tile data type comes first, as in deck.gl's TileLayer<DataT> and COGLayer<DataT>, and then zarrita's order, as in zarr.Array<Dtype, Store>.
  • ZarrSource: it follows zarrita: ZarrSource<Dtype, Store>.
// Before
new ZarrLayer<zarr.Readable, "int8", TileData>({ ... });

// After
new ZarrLayer<TileData, "int8">({ ... });

Examples and docs

  • Three examples open a ZarrSource: aef-mosaic, dynamical-zarr-ecmwf and nldas-icechunk pass geoZarrMetadata, in the effect that already opens their array. In nldas-icechunk, the store module returns the source.
  • zarr-sentinel2-tci passes its group as source.
  • README: deck.gl-zarr's README shows both forms.
  • Spec: it records the answer to question 9, and stage 4b as built.

Tests

  • ZarrSource: 12 tests against an in-memory GeoZarr store. They cover:
  • ZarrLayer:
    • An opened source draws without opening anything.
    • The load signal reaches ZarrSource.open.
    • The newer source wins a race.
    • A selection that doesn't fit:
      • is reported, and draws nothing;
      • draws again once fixed, without opening the source again;
      • isn't reported again for an equal selection;
      • is checked, at its newest value, once a source opened from input arrives;
      • is checked when it changed while there was no source and the old source comes back.
    • The tile callback reads the finest level's edge tile at the selection. The test checks the array, the clipped 176-pixel width and height, and the slice spec.
    • The 4 isLoaded tests and the error-routing test now use source.
  • Type tests:
    • state.source is exactly ZarrSource, and ZarrSource<"int8"> for an int8 layer.
    • onSourceLoad gets a ZarrSource.
    • The removed props are rejected, and so is a string as source.
  • Mutation checks: each of these makes a test fail:
  • In Chrome:
    • dynamical-zarr-ecmwf draws as before. Its animation changes the selection at every step.
    • aef-mosaic draws as before. Switching the year reads no zarr.json.
    • nldas-icechunk draws as before.
    • zarr-sentinel2-tci reads from a local data server, which I didn't run, so I only typechecked it.

🤖 Written by Claude Code

Base automatically changed from kyle/proj-projection-helpers to main October 28, 2026 00:27
kylebarron and others added 4 commits October 27, 2026 20:27
`ZarrSource.open(node, options)` opens GeoZarr data from a zarrita group
or array. It reads the GeoZarr metadata from the node's attributes, or
from `geoZarrMetadata`, opens the array of each level, and resolves the
CRS. It then builds the tile grid and the WGS84 bounds of the finest
level.

The source holds `arrays` (finest first), `dimensionNames`,
`spatialDims` and `projection`, plus the tile grid and bounds from
`RasterSource`. It doesn't keep the parsed GeoZarr metadata. It checks
what ZarrLayer's load checks today, except `selection`, which stays on
the layer.

The tests' GeoZarr store moves to `tests/helpers.ts`, with groups for
the failure cases.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ayer's source

ZarrLayer's `source` is an opened `ZarrSource`, or a zarrita group or
array that the layer opens with `ZarrSource.open`'s defaults. Like
COGLayer, it lets RasterTileLayer handle the source and only says how
to open input. `onSourceLoad` gets the source it opened.

`node`, `variable`, `metadata` and `epsgResolver` are removed. The last
three are `ZarrSource.open` options, with `metadata` renamed
`geoZarrMetadata`.

`selection` stays on the layer. It's checked against the source whenever
either changes, including when a source opened from input arrives. A
selection that doesn't fit goes to `onError`, and the layer draws
nothing until the selection is fixed. Changing the selection never opens
the source again. Selections are compared by value, so an inline literal
isn't checked or reported again on every render.

Edge tiles are clipped with each array's shape, so the layer no longer
needs the parsed GeoZarr metadata. The `window.*` debug lines are gone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- **Examples:**
  - aef-mosaic, dynamical-zarr-ecmwf and nldas-icechunk open a
    `ZarrSource` with `geoZarrMetadata` in the effect that already opens
    their array.
  - nldas-icechunk's store module returns the source, as `SurfaceTemp`.
  - zarr-sentinel2-tci passes its group as `source`.
- **README:** deck.gl-zarr's Quick Start passes a group as `source`, and
  shows `ZarrSource.open` for the options.
- **Spec:**
  - Question 9 is decided: the option is `geoZarrMetadata`, and the source
    doesn't keep the parsed metadata.
  - Decisions 21 and 23 and the stage 4b entry describe what was built.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…source

ZarrLayer compared `selection` with the old props to decide whether to
check it again. A selection that changed while no source was drawn, such
as while new input opened, was never checked. If the old source came
back, the layer drew the old selection. It now compares the source and
the selection with the pair it last checked, kept in state with whether
the selection fits.

Also from the final review:

- **Tests:**
  - A test calls the tile callback. It checks the level, the clipping of
    an edge tile, and the selection in the slice spec, using a test group
    with a `time` dimension.
  - Another test checks that a global grid centered on the poles keeps its
    bounds within -90° to 90°.
  - The node registration test now says the bounds move, which is what it
    shows, and checks `east` too.
- **Types:** `ZarrSource`'s `arrays` and `dimensionNames` are readonly,
  since layers share the source.
- **Docs:**
  - `selection` says that loaded tiles keep the data of the selection they
    were fetched with.
  - `open` lists when it rejects, above its parameter.
  - The spec says `node` becomes `open`'s first argument, not an option.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
/** The opened temperature data plus the fill sentinel read from its attrs. */
export interface SurfaceTemp {
/** The near-surface air temperature, for a `ZarrLayer` to draw. */
source: ZarrSource<zarr.Readable, "float32">;

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.

I'm not sure it's a good idea for our ZarrSource to have the exact same type parameters as zarr.Array, but switched. If anything we should explicitly follow the same ordering as zarrita.js, right?

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.

Yes. In 6639a88 it's ZarrSource<Dtype, Store>, in the same order as zarrita's zarr.Array<Dtype, Store>. The common case is now just ZarrSource<"float32">, with the store left at its default.

ZarrLayer and ZarrLayerProps had the same switched order, <Store, Dtype, DataT>, from before this PR. I reordered them too, to ZarrLayer<"int8", zarr.Readable, AefTileData>, because:

  • this PR already breaks ZarrLayer;
  • a layer takes a ZarrSource, so the two types appear together.

That part is easy to undo if you'd rather keep ZarrLayer's order.

🤖 Written by Claude Code

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.

Follow-up, after your note that layers take DataT first like other deck.gl layers. In b279a15:

  • ZarrLayer: ZarrLayer<DataT, Dtype, Store>, and ZarrLayerProps the same way. DataT comes first as in TileLayer<DataT, …> and COGLayer<DataT>, then zarrita's order. The examples shorten to ZarrLayer<AefTileData, "int8">.
  • ZarrSource: stays ZarrSource<Dtype, Store>.

On main, ZarrLayer had DataT last (<Store, Dtype, DataT>), so this changes its order too. The PR description's migration section shows the before and after.

🤖 Written by Claude Code

kylebarron and others added 2 commits October 27, 2026 20:33
zarrita's `zarr.Array<Dtype, Store>` takes the data type first. Our
`ZarrSource`, `ZarrLayer` and `ZarrLayerProps` took the store first, so
they now take `Dtype` first too. That also shortens the common case to
`ZarrSource<"float32">`, with the store left at its default.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Like deck.gl's `TileLayer<DataT, ...>`, `RasterTileLayer<DataT, ...>`
and `COGLayer<DataT>`, ZarrLayer and ZarrLayerProps take `DataT` first,
then zarrita's `Dtype` and `Store`. The examples shorten to
`ZarrLayer<AefTileData, "int8">`, with the store left at its default.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

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

lgtm!

null,
);
const [rootAttrs, setRootAttrs] = useState<unknown>(null);
const [source, setSource] = useState<ZarrSource<"int8"> | null>(null);

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.

👍
I like that the simplest type parameteriziation of source is just ZarrSource<Dtype>

`Expected AEF embeddings to be int8, got ${opened.dtype}`,
);
}
// The GeoZarr metadata is on the root group, not on the array

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.

todo: we should probably somehow manage this ourselves... perhaps ZarrSource should support traversing child nodes? Let's make an issue about this

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 reply was written by Claude (Claude Code), not by @kylebarron.

Filed as #813. It proposes that variable can name an array as well as a group. The conventions apply a group's proj: and spatial: attributes to the arrays directly inside it. So open would read them from the group, and this example could call ZarrSource.open(root, { variable: "embeddings" }).

The issue also lists four open questions. One is how the example would still check that the data is int8.

🤖 Written by Claude Code

Comment on lines 53 to +55
DataT extends MinimalTileData = MinimalTileData,
Dtype extends zarr.DataType = zarr.DataType,
Store extends zarr.Readable = zarr.Readable,

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.

DataT, Dtype, Store ordering matches COGLayer, right?

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 reply was written by Claude (Claude Code), not by @kylebarron.

Yes, for the part they share. COGLayer takes only DataT (COGLayer<DataT = TextureDataT>), so DataT comes first in both, as in RasterTileLayer<DataT, ...> and deck.gl's TileLayer<DataT, ...>. In b279a15, ZarrLayer's Dtype and Store follow it, in zarrita's order. COGLayer has nothing like them.

🤖 Written by Claude Code

@kylebarron
kylebarron merged commit 0714b55 into main Oct 28, 2026
4 checks passed
@kylebarron
kylebarron deleted the kyle/zarr-source branch October 28, 2026 00:41
kylebarron added a commit that referenced this pull request Oct 30, 2026
> [!NOTE]
> This PR was written by Claude (Claude Code), not by @kylebarron.

Bumps `version` to `0.10.0-beta.1` in the root `package.json` and in
every `packages/*/package.json`, ready for the first 0.10 beta. The
publish workflow sees `beta` in the version and publishes to npm under
the `beta` dist-tag, so `latest` stays on 0.9.0.

`CHANGELOG.md` gets a `v0.10.0-beta.1` section listing the 19 PRs merged
since v0.9.0.

## Publish `@developmentseed/range-reader` by hand before tagging

`@developmentseed/range-reader` (#806) isn't on npm yet, and
`@developmentseed/geotiff` and `@developmentseed/deck.gl-geotiff` depend
on it. The publish workflow can't create it: it publishes only through
trusted publishing (OIDC), and npm can add a trusted publisher only to a
package that [already
exists](https://docs.npmjs.com/cli/v11/commands/npm-trust). Pushing the
tag first would fail at `range-reader`. `pnpm publish --recursive` stops
at the first failure, so packages published before it in the run would
be out, and the rest, including `geotiff` and `deck.gl-geotiff`, would
not.

Once this is merged, from an up-to-date `main`:

1. Publish it once, as a public package under the `beta` tag. Its
`prepublishOnly` script builds it first.
   ```sh
   cd packages/range-reader
   pnpm publish --tag beta --access public --no-git-checks
   ```
2. Give it the same trusted publisher as the other packages (workflow
`release.yml`, environment `release`), in its settings on npmjs.com or
with:
   ```sh
npm trust github @developmentseed/range-reader --file release.yml --repo
developmentseed/deck.gl-raster --env release --allow-publish
   ```
3. Tag the merge commit `v0.10.0-beta.1` and push the tag. The workflow
skips `range-reader`, since that version is already on npm, and
publishes the other ten packages.

## Breaking changes

- #799: `COGLayer` takes a single `source`: an opened `COGSource`, or
any input of `COGSource.open`. `geotiff` becomes `source`,
`onGeoTIFFLoad` becomes `onSourceLoad`, and `epsgResolver` and
`concurrencyLimiter` move to `COGSource.open`.
- #801: `MultiCOGLayer` does the same with `MultiCOGSource`. `sources: {
red: { url } }` becomes `source: { red: url }`, `MultiCOGSourceConfig`
is removed, and files that don't share a CRS and an extent are rejected.
- #804: `MosaicLayer`'s `sources` becomes deck.gl's `data`, and
`MosaicSource` becomes `MosaicItem`. The callbacks get the item's opened
source as `source`, and `onViewportLoad`'s entries are `{ item, source
}`.
- #821: `renderSource` gets only `{ source }`, without `signal`.
- #812: `ZarrLayer` takes a `ZarrSource`, or a zarrita group or array,
as `source`. `node`, `variable`, `metadata` and `epsgResolver` are
removed (`metadata` becomes `ZarrSource.open`'s `geoZarrMetadata`), and
the type parameters are now `ZarrLayer<DataT, Dtype, Store>`.
- #807: `GeoTIFF.fromUrl` no longer takes `chunkSize` or `cacheSize`.
They're `RangeReader` options now (`minMetadataReadBytes`,
`cache.metadataBytes`).

Two behavior changes aren't marked breaking:

- #809: COG tile reads are coalesced by default, and `COGLayer` and
`MultiCOGLayer` default to `maxRequests: 256` and `debounceTime: 50`.
- #818: changing `updateTriggers.getTileData`, or ZarrLayer's
`selection`, fetches tiles again, and the old tiles are removed at once.

🤖 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 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
Port zarr-globe to the ZarrLayer API from #812, as dynamical-zarr-ecmwf
was ported there: open the array with `ZarrSource.open` and the GeoZarr
attrs, pass the source as `source`, and use the
`ZarrLayer<DataT, Dtype>` type parameter order.

Drop `initTimeIdx` from the layer id, since changing `selection` now
fetches tiles again (#818).

Match dynamical-zarr-ecmwf's dependency versions.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant