I have masked a NetCDF file using basemap.gs
script in grads. Here is what I got using the mask:
So, I would like to obtain a NetCDF file which
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:
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
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:
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.