Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overwriting specific cells in netcdf

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!

like image 708
user308827 Avatar asked Mar 26 '14 17:03

user308827


2 Answers

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

like image 165
Charlie Zender Avatar answered Sep 18 '22 21:09

Charlie Zender


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.

like image 37
Spencer Hill Avatar answered Sep 20 '22 21:09

Spencer Hill