1

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.

Curious
  • 383
  • 3
  • 13
  • 1
    The ability to work with multiple groups and other tree-like/hierarchical structures is part of the [xarray development roadmap](https://xarray.pydata.org/en/v2022.06.0/roadmap.html#flexible-data-structures). But for now, your approach sounds fine! – Michael Delgado Jul 29 '22 at 05:46

1 Answers1

2

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

ThomasNicholas
  • 1,273
  • 11
  • 21