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

前端 未结 2 1406
无人共我
无人共我 2021-01-15 19:57

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

相关标签:
2条回答
  • 2021-01-15 20:28

    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.

    0 讨论(0)
  • 2021-01-15 20:28

    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!!

    0 讨论(0)
提交回复
热议问题