class xbitinfo.save_compressed.ToCompressed_Netcdf(xarray_obj)[source]#

Save to compressed netcdf wrapping xarray.Dataset.to_netcdf() with xbitinfo.save_compressed.get_compress_encoding_nc().

  • path (str, path-like or file-like) – Path to which to save this dataset

  • compression (str) – Compression library used for encoding. Defaults to "zlib".

  • shuffle (bool) – Netcdf shuffle used for encoding. Defaults to True.

  • complevel (int) – Compression level used for encoding. Ranges from 2 (little compression, fast) to 9 (strong compression, slow). Defaults to 7.

  • for_cdo (bool) – If you want to continue working with cdo. If True, sets time chunksize to 1, context https://code.mpimet.mpg.de/boards/2/topics/12598. Defaults to False.

  • time_dim (str) – Name of the time dimension. Defaults to "time".

  • chunks (str, dict) – How should the data be chunked on disk. None keeps defaults. "auto" uses dask.chunk("auto"), dict individual chunking. Defaults to None.

  • kwargs (dict) – Kwargs to be passed to xarray.Dataset.to_netcdf()


>>> ds = xr.tutorial.load_dataset("rasm")
>>> path = "compressed_rasm.nc"
>>> ds.to_compressed_netcdf(path)
>>> ds.to_compressed_netcdf(path, complevel=4)
>>> ds.to_compressed_netcdf(path, for_cdo=True)