files.save

files.save

Functions

Name Description
clean_attributes Remove attributes that can not be written to netcdf
get_zarr_compressor Return a Blosc compressor for zarr encoding.
to_netcdf Write an xarray Dataset ds using .to_netcdf with several additional features:
to_zarr Write an xarray Dataset ds using .to_zarr with several additional features:

clean_attributes

files.save.clean_attributes(obj)

Remove attributes that can not be written to netcdf

get_zarr_compressor

files.save.get_zarr_compressor(complevel=5)

Return a Blosc compressor for zarr encoding.

Args: complevel (int): Compression level (1-9). Defaults to 5.

Returns: zarr.Blosc compressor instance

to_netcdf

files.save.to_netcdf(
    ds,
    filename,
    *,
    engine='h5netcdf',
    zlib=True,
    complevel=5,
    verbose=True,
    tmpdir=None,
    lock_timeout=0,
    git_comit=True,
    if_exists='error',
    clean_attrs=True,
    **kwargs,
)

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…

Args: 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. other kwargs are passed to ds.to_netcdf

to_zarr

files.save.to_zarr(
    ds,
    filename,
    *,
    zlib=True,
    complevel=5,
    verbose=True,
    tmpdir=None,
    lock_timeout=0,
    git_comit=True,
    if_exists='error',
    clean_attrs=True,
    **kwargs,
)

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

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

Args: ds (xr.Dataset): Input dataset filename (Path): Output zarr store path (directory or .zip file) zlib (bool, optional): activate zlib compression. 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_comit (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 zarr. other kwargs are passed to ds.to_zarr