enstools.compression.api.emulate_compression_on_dataset
- enstools.compression.api.emulate_compression_on_dataset(dataset: Dataset, compression: str | dict, in_place: bool = True)
Emulate the compression on an xarray dataset using the specified compression settings. This function applies the given compression settings to each variable in the dataset that is not a coordinate. The compression is either applied in-place or to a deep copy of the dataset, depending on the value of the in_place parameter.
- Parameters:
dataset – An xarray dataset containing the data to be compressed.
compression – A string or dictionary defining the compression settings to be applied to the dataset. If a string is provided, it should be a predefined compression setting. If a dictionary is provided, it should have the variable names as keys and the corresponding compression settings as values.
in_place – A boolean value indicating whether to apply the compression in-place or to a deep copy of the dataset. If True, the function returns the same dataset with compression applied. If False, the function returns a compressed deep copy of the dataset.
- Returns:
A tuple containing the compressed dataset and a dictionary with compression metrics for each variable.