Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
798 views
in Technique[技术] by (71.8m points)

mask - Create a NetCDF file with data masked to retain land points only

I have masked a NetCDF file using basemap.gs script in grads. Here is what I got using the mask:

Example

So, I would like to obtain a NetCDF file which only contains the continental data, can anyone help me with this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...