I have a global data at 0.25 degree resolution that I'd like to mask so that it only contains data values over land.
The data covers full 360 degrees in the lon dimension and from -60 to 60 degrees in the lat dimension.
The file header, as well as summary lat and lon coordinate values, are listed below:
netcdf cmorph_global_daily {
dimensions:
lat = UNLIMITED ; // (480 currently)
lon = 1440 ;
time = 7305 ;
variables:
float lat(lat) ;
lat:units = "degrees_north" ;
lat:long_name = "Latitude" ;
float lon(lon) ;
lon:units = "degrees_east" ;
lon:long_name = "Longitude" ;
float prcp(lat, lon, time) ;
prcp:_FillValue = NaNf ;
prcp:units = "mm" ;
prcp:standard_name = "precipitation" ;
prcp:long_name = "Precipitation" ;
prcp:description = "CMORPH Version 1.0BETA Version, daily precip from 00Z-24Z" ;
int time(time) ;
time:units = "days since 1900-01-01" ;
time:long_name = "Time" ;
time:calendar = "gregorian" ;
// global attributes:
:history = "Mon Mar 26 10:44:42 2018: ncpdq -a lat,lon,time cmorph_adjusted_daily.nc latlontime/cmorph_adjusted_daily.nc\nThu Mar 15 10:21:10 2018: ncks -4 cmorph_adjusted_daily.nc cmorph_adjusted_daily.nc" ;
:nco_openmp_thread_number = 1 ;
:title = "CMORPH Version 1.0BETA Version, daily precip from 00Z-24Z" ;
:NCO = "4.7.2" ;
data:
lat = -59.875, -59.625, -59.375, -59.125, ..., 59.125, 59.375, 59.625, 59.875 ;
lon = 0.125, 0.375, 0.625, 0.875, 1.125, ..., 359.125, 359.375, 359.625, 359.875 ;
I would prefer to do this using Python/numpy and/or NCO since that's my typical toolset. Thanks in advance for any suggestions.
A solution with CDO
hope that works...
Once you have a variable on the same grid to mask with, you can use ncap2 where, e.g.,
If your mask is on a different grid than your data, you can use (on Linux/Mac) the masking features of ncremap, e.g., to remap your data to your mask (or visa versa) with something like