xarray.DataTree.to_netcdf

xarray.DataTree.to_netcdf#

DataTree.to_netcdf(filepath, mode='w', encoding=None, unlimited_dims=None, format=None, engine=None, group=None, compute=True, **kwargs)[source]#

Write datatree contents to a netCDF file.

Parameters
  • filepath (str or Path) – Path to which to save this datatree.

  • mode ({"w", "a"}, default: "w") – Write (‘w’) or append (‘a’) mode. If mode=’w’, any existing file at this location will be overwritten. If mode=’a’, existing variables will be overwritten. Only applies to the root group.

  • 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, "zlib": True}, ...}, ...}. See xarray.Dataset.to_netcdf for available options.

  • unlimited_dims (dict, optional) – Mapping of unlimited dimensions per group that that should be serialized as unlimited dimensions. By default, no dimensions are treated as unlimited dimensions. Note that unlimited_dims may also be set via dataset.encoding["unlimited_dims"].

  • format ({"NETCDF4", }, optional) – File format for the resulting netCDF file:

    • NETCDF4: Data is stored in an HDF5 file, using netCDF4 API features.

  • engine ({"netcdf4", "h5netcdf"}, optional) – Engine to use when writing netCDF files. If not provided, the default engine is chosen based on available dependencies, with a preference for “netcdf4” if writing to a file on disk.

  • group (str, optional) – Path to the netCDF4 group in the given file to open as the root group of the DataTree. Currently, specifying a group is not supported.

  • compute (bool, default: True) – If true compute immediately, otherwise return a dask.delayed.Delayed object that can be computed later. Currently, compute=False is not supported.

  • kwargs – Additional keyword arguments to be passed to xarray.Dataset.to_netcdf

Note

Due to file format specifications the on-disk root group name is always "/" overriding any given DataTree root node name.