If I have understood the question correctly, the desire is to have a netcdf file with all the values set to missing (i.e. _Fillvalue) over the sea points. If so there are two solutions from the command line:
SOLUTION 1:
One way is to use CDO to create a land-sea mask and then set all the sea points to missing:
cdo -f nc2 setctomiss,0 -gtc,0 -remapcon,your_data_.nc -topo seamask.nc
- where remapcon remaps the topography to the domain and resolution of your data file.
- The gtc,produces 1 when the built in topography is greater then sea level.
- Then the setctomiss sets all the "zero" points to missing.
You can now use this to mask your datafile:
cdo mul datafile.nc seamask.nc masked_datafile.nc
However, in some circumstances I have found that the remapping process leaves traces of "ocean" data around the edges, in this case to be safer you can use the second method:
SOLUTION 2
Download the netcdf data file for "distance to ocean" at 1km resolution from this thredds server: https://pae-paha.pacioos.hawaii.edu/thredds/ncss/dist2coast_1deg_land/dataset.html
Then you can mask out any points within a certain distance of the ocean to play it safe, at the expense of possibly masking out a small amount of land data.
I remapped the distance file to the target resolution first:
cdo remapbil,your_data.nc distance.nc remap_dist.nc
then mask (e.g. in this case all points within 5km of the coast, sea points are already "missing" in this file) and multiply
cdo mul your_data.nc -gtc,5 remap_dist.nc masked_data.nc
As said, this is a little safer, a little more longwinded, but may mask some land data.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…