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

北战南征 提交于 2020-01-30 03:14:54

问题


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 only contains the continental data, can anyone help me with this?


回答1:


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.




回答2:


Since you already have the non-continental values masked out, the process is actually fairly simple. There is a command called "sdfwrite" which can write and variable defined in grads to file. The code would go something like this:

define data = <insert expression for masked out data here>
set sdfwrite out.nc
sdfwrite data

*Make sure you remove the angle brackets; those were just for show

Entering these into grads will 1) allocate memory to save the displayed data in the variable "data" 2) set the name of the output file to "out.nc" (you can of course change this to whatever you like), and 3) writes the information in the variable "data" to the out.nc file.

Now as far as I know, there is no way to simply not have the masked out values not be written to file, but with this, they will all be written in as zero/undefined values.

sdfwrite documentation

Hope this Helps!!



来源:https://stackoverflow.com/questions/39058260/create-a-netcdf-file-with-data-masked-to-retain-land-points-only

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!