I have a netCDF file where I want to replace some data based on another variable in the netCDF file. The file is available here: https://umd.box.com/s/lrb12vl7bxbqpv2lt0c27t8m0ps0nm0e and has the following structure:
dimensions:
lat = 720;
time = 3;
lon = 1440;
variables:
float cntry_codes(lat=720, lon=1440);
:_FillValue = 0.0f; // float
float data(time=3, lat=720, lon=1440);
:_FillValue = NaNf; // float
:units = "%";
int time(time=3);
float longitude(lon=1440);
float latitude(lat=720);
I want to replace the 'data' values in the grid cells (where the cntry_codes value is 840) to a new value of 0.8. I am trying to subset like this:
import netCDF4
lat_inds = numpy.where(cntry_codes = 840.0)
lon_inds = numpy.where(cntry_codes = 840.0)
However, this just does not work. Any better solution?
data = netCDF4.Dataset(...), then access the variables you need,cntry_codes = data.variables['cntry_codes'][:], then play with them,mask = cntry_codes[cntry_codes = 840.0]and, finally, modify the data you want for thedatavar in the nc file.