Project

General

Profile

How to replace values of variables in a nc file for specific points?

Added by Natalia L over 2 years ago

Hi,

I have a netcdf file with multiple 2D variables for multiple points (lat/lon).

I want to change the values of all the 2D variables for specific points (lat,lon). i.e. For 5 points of lat/lon I want to set all the 2D variables to zero. Could I do that with cdo?

The 2D variables are 37 with specific names.


Replies (3)

RE: How to replace values of variables in a nc file for specific points? - Added by Uwe Schulzweida over 2 years ago

Hi Natalia,

This will be possible in the next CDO version 2.0.0 with the new operator setgridcell.
The new version will be ready in about 4 weeks. Here is an example:

cdo setgridcell,value=0.0,cell=1,2,3,4,5 infile outfile
cell=1,2,3,4,5 selects the cells with index 1,2,3,4,5. You have to replace this with the cell index of your cells.

Cheers,
Uwe

RE: How to replace values of variables in a nc file for specific points? - Added by Natalia L over 2 years ago

Thank you Uwe.

However, can I multiply the values of the variables for all the points with a constant? i.e. for the whole grid.

I have a file with several variables e.g. val1, val2, val3 etc. and I want to create a new file including all the variables but multiply them with a different constant
i.e. val1*c1, val2*c2 etc.

RE: How to replace values of variables in a nc file for specific points? - Added by Uwe Schulzweida over 2 years ago

Try the operator expr, here is an example:

cdo expr,"val1=val1*c1;val2=val2*c2;val3=val3*c3;" infile outfile 

    (1-3/3)