xarray.DataTree.to_zarr#
- DataTree.to_zarr(store, mode='w-', encoding=None, consolidated=True, group=None, write_inherited_coords=False, compute=True, **kwargs)[source]#
Write datatree contents to a Zarr store.
- Parameters:
store (
zarr.storage.StoreLike) – Store or path to directory in file systemmode (
{{"w", "w-", "a", "r+", None}, default:"w-") – Persistence mode:“w” means create (remove old if exists and write new);
“w-” means create (fail if exists);
“a” means override all existing variables including dimension coordinates (create if does not exist);
“r+” means modify existing array values only (raise an error if any metadata or shapes would change).
The default mode is “w-”.
Note
When modifying an existing Zarr array that is lazily opened, the “w” behavior can be surprising since the underlying file that is being lazily read from might get deleted before the data is computed.
encoding (
dict, optional) – Nested dictionary with variable names as keys and dictionaries of variable specific encodings as values, e.g.,{"root/set1": {"my_variable": {"dtype": "int16", "scale_factor": 0.1}, ...}, ...}. Seexarray.Dataset.to_zarrfor available options.consolidated (
bool) – If True, apply zarr’s consolidate_metadata function to the store after writing metadata for all groups.group (
str, optional) – Group path. (a.k.a. path in zarr terminology.)write_inherited_coords (
bool, default:False) – If true, replicate inherited coordinates on all descendant nodes. Otherwise, only write coordinates at the level at which they are originally defined. This saves disk space, but requires opening the full tree to load inherited coordinates.compute (
bool, default:True) – If true compute immediately, otherwise return adask.delayed.Delayedobject that can be computed later. Metadata is always updated eagerly.kwargs – Additional keyword arguments to be passed to
xarray.Dataset.to_zarr
Notes
Due to file format specifications the on-disk root group name is always
"/"overriding any givenDataTreeroot node name.