core.files.save

core.files.save.clean_attributes(obj: Dataset | DataArray)[source]

Remove attributes that can not be written to netcdf

core.files.save.to_netcdf(ds: Dataset, filename: Path, *, engine: str = 'h5netcdf', zlib: bool = True, complevel: int = 5, verbose: bool = True, tmpdir: Path | None = None, lock_timeout: int = 0, git_comit: bool = True, if_exists: Literal['skip', 'overwrite', 'backup', 'error'] = 'error', clean_attrs: bool = True, **kwargs)[source]

Write an xarray Dataset ds using .to_netcdf with several additional features:

  • Use file compression

  • Wrapped by filegen: use temporary files, detect existing output files…

Parameters:
  • ds (xr.Dataset) – Input dataset

  • filename (Path) – Output file path

  • engine (str, optional) – Engine driver to use. Defaults to ‘h5netcdf’.

  • zlib (bool, optional) – activate zlib. Defaults to True.

  • complevel (int, optional) – Compression level. Defaults to 5.

  • verbose (bool, optional) – Verbosity. Defaults to True.

  • tmpdir (Path, optional) – use a given temporary directory. Defaults to None.

  • lock_timeout (int, optional) – timeout in case of existing lock file

  • git_commit (bool, optional) – Option to add git commit tag to input dataset attributes

  • if_exists (str, optional) – what to do if output file exists. Defaults to ‘error’.

  • clean_attrs – whether to remove attributes in the xarray object, that cannot be written to netcdf.

  • ds.to_netcdf (other kwargs are passed to)