Search code examples
pythonnetcdfchunkschunkingnetcdf4

How to set chunk size of netCDF4 in python?


I can see the default chunking setting in netCDF4 library, but I have no idea how to change the chunk size.

from netCDF4 import Dataset    
volcgrp = Dataset('datasets/volcano.nc', 'r')
data = volcgrp.variables['abso4']
print data.shape
print data.chunking()
>(8, 96, 192)
>[1, 96, 192]

Is there anyone who can help with the setting?


Solution

  • You can use xarray to read the netcdf file and set chunks, e.g.

    import xarray as xr
    
    ds = xr.open_dataset('/datasets/volcano.nc', chunks={'time': 10})