Is there a netcdf operator (from nco or any python netcdf library) which can be used to overwrite specific cells in a netcdf file?
I want to change the values of a small region in a netcdf file containing global climate data. thanks!
Or NCO's ncap2 does this in one command with
ncap2 -s 'var[0,0,0]=-999' in.nc out.nc
ncap2 is described here
This is easy with netCDF4-python. For example, suppose nc
is your netCDF file, the variable is named var
, and the index of the cell you want to change is (0,0,0)
. Then:
from netCDF4 import Dataset
new_value = -999
nc.variables['var'][0,0,0] = new_value
netCDF4 represents all netCDF arrays using numpy, which enables their powerful manipulation using numpy's slicing and other capabilities.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With