enstools.io.write

enstools.io.write(ds: Union[Dataset, DataArray], file_path: Union[str, Path], file_format: Optional[str] = None, compression: Optional[Union[str, dict]] = None, compute: bool = True, engine: str = 'h5netcdf', format: str = 'NETCDF4')

write a xarray dataset to a file

Parameters:
dsxarray.Dataset

the dataset to store

file_pathstring or Path

the file to create

file_format{‘NC’}

string indicating the format to use. if not specified, the file extension if used.

compressionstring

Used to specify the compression mode and optionally additional arguments. The parameter follows the rules defined in enstools-encoding. (https://gitlab.physik.uni-muenchen.de/w2w/enstools-encoding.git)

To apply lossless compression we can just use:

“lossless”

Or we can select the backend and the compression level using the following syntax:

“lossless,backend,compression_level”

The backend can be one of:

‘blosclz’ ‘lz4’ (default) ‘lz4hc’ ‘snappy’ ‘zlib’ ‘zstd’

and the compression level must be an integer from 1 to 9 (default is 9). Few examples:

“lossless,zstd,4” “lossless,lz4,9” “lossless,snappy,1”

Using “lossless” without additional arguments would be equivalent to “lossless,lz4,9”

For lossy compression, we might be able to pass more arguments:

“lossy”

The lossy compressors available will be:

‘zfp’ ‘sz’

For ZFP we have different compression methods available:

‘rate’ ‘accuracy’ ‘precision’

For SZ we have also different compression methods available:

‘abs’ ‘rel’ ‘pw_rel’

Each one of this methods require an additional parameter: the rate, the precision or the accuracy. The examples would look like:

‘lossy,zfp,accuracy,0.2’ ‘lossy,zfp,rate,4’

There are also few features that target datasets with multiple variables. One can write a different specification for different variables by using a list of space separated specifications:

‘var1:lossy,zfp,rate,4.0 var2:lossy,sz,abs,0.1’

For more details see the corresponding documentation.

Another option would be to pass the path to a YAML configuration file as argument.

computebool

Dask delayed feature. Set to true to delay the file writing.