Open root zarr with multiple groups using xarray

Viewed 59

Suppose I had a zarr file that has n groups each of which have only one zarr array and share at least 3 dimensions but may have others as well, how would I load an xarray Dataset from said zarr root file while aligning their common dimensions and preserving attributes?

Currently I am experimenting with a hack where I list the individual zarr groups using glob and feeding them as a list to xr.open_mfdataset(list_of_zarr_groups,engine=‘zarr’, but surely there must be a better way.

1 Answers

Using xarray-datatree you can open all groups in a Zarr store at once as a single DataTree object. You can then extract the different groups as individual xarray.Dataset objects. Just call datatree.open_datatree(zarr_store, engine="zarr").

(As @michael-delgado said, this is being actively developed as part of the xarray roadmap.)

Related