3

How do you determine the compression level of a netCDF4 variable (preferably in Python)?

sfinkens
  • 1,210
  • 12
  • 15

1 Answers1

8

Python option using netCDF4 directly:

import netCDF4 as nc4
ds = nc4.Dataset('foo.nc')
var = ds.variables['bar']
print('complevel: %s', var.filters().get('complevel', False))

Note that the filters method returns a dictionary of all the HDF5 filter parameters

Python option using Xarray and netCDF4 under the hood:

import xarray as xr
ds = xr.open_dataset('foo.nc')
print('complevel: %s', ds['bar'].encoding.get('complevel', False))

Note that the encoding attribute is a dictionary with all the variable encoding attributes for each variable

The command line options is easy too:

ncdump -h -s foo.nc
jhamman
  • 5,867
  • 19
  • 39