xarray.DataTree.to_netcdf#
- DataTree.to_netcdf(filepath=None, mode='w', encoding=None, unlimited_dims=None, format=None, engine=None, group=None, write_inherited_coords=False, compute=True, **kwargs)[source]#
Write datatree contents to a netCDF file.
- Parameters:
filepath (
strorPathLikeorfile-like objectorNone) – Path to which to save this datatree, or a file-like object to write it to (which must support read and write and be seekable) or None to return in-memory bytes as a memoryview.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}, ...}, ...}. Seexarray.Dataset.to_netcdffor 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 viadataset.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, by default preferring “h5netcdf” over “netcdf4” (customizable vianetcdf_engine_orderinxarray.set_options()).group (
str, optional) – Path to the netCDF4 group in the given file to open as the root group of theDataTree. Currently, specifying a group is not supported.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.kwargs – Additional keyword arguments to be passed to
xarray.Dataset.to_netcdf
- Returns:
* ``memoryview`if path is None`* ``dask.delayed.Delayed`if compute is False`* ``None`otherwise`
Note
Due to file format specifications the on-disk root group name is always
"/"overriding any givenDataTreeroot node name.