pack#

geobricks.pack(data, nbits=16, to_file=False)[source]#

Applies a lossy compression to a netCDF dataset, by packing the values to a data type with smaller number of bits. Under the hood, this function automatically defines the corresponding add_offset and scale_factor.

Parameters#

datapath (str or pathlib.Path), or variable (xarray.Dataset, xarray.DataArray)

Dataset (netCDF or xarray variable) that will be gzipped (non-lossy).

Note that data will be loaded into a xarray.Dataset or xarray.DataArray.

nbits{8, 16}, default 16

Number of bits for the data type of the output values.

to_filebool or path (str or pathlib.Path), default False

If True and if data is a path (str or pathlib.Path), the resulting dataset will be exported to a file with the same pathname and the suffix ‘_pack’. If to_file is a path, the resulting dataset will be exported to this specified filepath.

Returns#

data_dsxarray.Dataset

Standard GEOP4TH variable (xarray.Dataset) with lossy compression.

If to_file argument is used, the resulting dataset can also be exported to a file.