Search code examples
nanetcdfcdo-climatenco

set to all NAs a given region in a lat-lon ncfile


I have the following netcdf file which is a global grid with latitude from -90 to 90 and longitude from 0 to 360 degrees.

Let's suppose I would like to set to NAs (or missing values) all the gridpoints (or region) included within latitude -90 to 90 and longitude 20E to 100E.

How can I achieve this? Is this possible with CDO?


Solution

  • There may be a better way to do this, but one way is the masklonlatbox command. Unfortunately, that does the opposite to what you want as it keeps the box you define, so you would need to mask the bit to the left and the bit to the right, if you see what I mean. Luckily cdo handles wrapped longitudes quite well. I tested this out and it worked for me:

    cdo masklonlatbox,100,20,-90,90 in.nc out.nc