Skip to content

feat: Accept a GeoZarr multiscale DataTree in from_xarray - #1359

Open
kylebarron wants to merge 7 commits into
kyle/raster-from-xarrayfrom
kyle/raster-xarray-datatree
Open

kylebarron wants to merge 7 commits into
kyle/raster-from-xarrayfrom
kyle/raster-xarray-datatree

Conversation

@kylebarron

Copy link
Copy Markdown
Member

Note

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

Third of the stack toward xarray support. Stacked on the from_xarray PR.

What I am changing

RasterLayer.from_xarray also accepts an xarray.DataTree opened from a GeoZarr multiscale group with xr.open_datatree(store, engine="zarr"). Each item of the root's multiscales.layout names a child group; its variable= (or only data variable) becomes one level, with the level's transform from the item's spatial:transform or its coordinates, its tile size from its own chunks, and the levels sorted coarsest first by pixel size. Bounds and min_zoom come from the coarsest level, so a zoomed-out view of a continent-sized pyramid is a handful of small reads.

Checked against carbonplan's public USGS CONUS 10 m DEM pyramid (14 levels, Zarr v3): it opens over HTTP with consolidated metadata, builds in well under a second, min_zoom is 0, and the coarsest tile reads in about 0.2 s.

The array-based layout the convention also allows (bare arrays as levels) cannot be opened by xarray when the levels share dimension names, because a Dataset cannot hold two sizes for one dimension, so it is documented as out of scope and left to a later from_zarr. The spec is updated.

How I did it

build_from_xarray is split into _single_level and _tree_levels branches that each produce the level list; everything after that (tile sizes, bounds, min_zoom, loader, fetch_tile) is the single-array code over a longer list. The GeoZarr CRS finder is split into geozarr_crs_from_attrs so it can read the tree's root attrs.

How you can test it

  • uv run --frozen pytest tests/test_raster_xarray.py tests/test_raster.py (62 + 9 tests; the tree tests build a two-level store in memory with zarr: level order from either layout order, item transforms, levels without coordinates, the variable rule, missing multiscales, mismatched dims, transform= rejected, fetch_tile at each level, a dask-opened tree).
  • PORT=18768 uv run --frozen pytest tests/ui/test_raster.py (browser: a two-level in-memory tree renders).

🤖 Written by Claude Code

🤖 Generated with Claude Code

@kylebarron
kylebarron added this pull request to stack #1361 November 13, 2026 18:55
@github-actions github-actions Bot added the feat label Nov 13, 2026
@kylebarron
kylebarron force-pushed the kyle/raster-xarray-datatree branch from 620a1a0 to 6f319e1 Compare November 16, 2026 20:43
kylebarron and others added 6 commits November 16, 2026 16:07
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@kylebarron
kylebarron force-pushed the kyle/raster-xarray-datatree branch from 6f319e1 to 3e9ab2e Compare November 16, 2026 21:07
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant