GRDMASK(1gmt) | GMT | GRDMASK(1gmt) |
grdmask - Create mask grid from polygons or point coverage
grdmask pathfiles -Gmask_grd_file
-Iincrement
-Rregion [ -A[m|p|x|y] ] [
-N[z|Z|p|P]values ] [
-Ssearch_radius[unit] ] [ -V[level] ] [
-bibinary ] [ -dinodata ] [ -eregexp ] [ -fflags
] [ -ggaps ] [ -hheaders ] [ -iflags ] [ -nflags
] [ -r ] [ -x[[-]n] ] [ -:[i|o]
]
Note: No space is allowed between the option flag and the associated arguments.
grdmask can operate in two different modes. 1. It reads one or more pathfiles that each define a closed polygon. The nodes defined by the specified region and lattice spacing will be set equal to one of three possible values depending on whether the node is outside, on the polygon perimeter, or inside the polygon. The resulting mask may be used in subsequent operations involving grdmath to mask out data from polygonal areas. 2. The pathfiles simply represent data point locations and the mask is set to the inside or outside value depending on whether a node is within a maximum distance from the nearest data point. If the distance specified is zero then only the nodes nearest each data point are considered "inside".
For map distance unit, append unit d for arc degree, m for arc minute, and s for arc second, or e for meter [Default], f for foot, k for km, M for statute mile, n for nautical mile, and u for US survey foot. By default we compute such distances using a spherical approximation with great circles. Prepend - to a distance (or the unit is no distance is given) to perform "Flat Earth" calculations (quicker but less accurate) or prepend + to perform exact geodesic calculations (slower but more accurate).
By default GMT writes out grid as single precision floats in a COARDS-complaint netCDF file format. However, GMT is able to produce grid files in many other commonly used grid file formats and also facilitates so called "packing" of grids, writing out floating point data as 1- or 2-byte integers. To specify the precision, scale and offset, the user should add the suffix =ID[+sscale][+ooffset][+ninvalid], where ID is a two-letter identifier of the grid type and precision, and scale and offset are optional scale factor and offset to be applied to all grid values, and invalid is the value used to indicate missing data. See grdconvert and Section grid-file-format of the GMT Technical Reference and Cookbook for more information.
When writing a netCDF file, the grid is stored by default with the variable name "z". To specify another variable name varname, append ?varname to the file name. Note that you may need to escape the special meaning of ? in your shell program by putting a backslash in front of it, or by placing the filename and suffix between quotes or double quotes.
When the output grid type is netCDF, the coordinates will be labeled "longitude", "latitude", or "time" based on the attributes of the input data or grid (if any) or on the -f or -R options. For example, both -f0x -f1t and -R90w/90e/0t/3t will result in a longitude/time grid. When the x, y, or z coordinate is time, it will be stored in the grid as relative time since epoch as specified by TIME_UNIT and TIME_EPOCH in the gmt.conf file or on the command line. In addition, the unit attribute of the time variable will indicate both this unit and epoch.
A grid produced by grdmask is a categorical dataset. As such, one has to be careful not to interpolate it with standard methods, such as splines. However, if you make a map of this grid using a map projection the grid will be reprojected to yield a rectangular matrix in the projected coordinates. This interpolation is done using splines by default and thus may yield artifacts in your map. We recommend you use grdimage -nn to instead use a nearest neighbor interpolation for such cases.
Since most uses of grdmask revolves around creating mask grids that hold just a few integer values (and perhaps NaN), we choose to write them to disk as byte grids by appending the suffix =nb to the desired grid filename. Some situations may store integers that exceed the range available in a byte and for those we specify a short integer grid with =ns. For larger integers you may consider =ni, otherwise use the default float grid format.
To set all nodes inside and on the polygons coastline_*.xy to 0, and outside points to 1, do
gmt grdmask coastline_*.xy -R-60/-40/-40/-30 -I5m -N1/0/0 -Gland_mask.nc=nb -V
To set nodes within 50 km of data points to 1 and other nodes to NaN, do
gmt grdmask data.xyz -R-60/-40/-40/-30 -I5m -NNaN/1/1 -S50k -Gdata_mask.nc=nb -V
To assign polygon IDs to the gridnodes using the insides of the polygons in plates.gmt, based on the attribute POL_ID, do
gmt grdmask plates.gmt -R-40/40/-40/40 -I2m -Nz -Gplate_IDs.nc=ns -aZ=POL_ID -V
Same exercise, but instead compute running polygon IDs starting at 100, do
gmt grdmask plates.gmt -R-40/40/-40/40 -I2m -Np100 -Gplate_IDs.nc=ns -V
gmt, grdlandmask, grdmath, grdclip, psmask, psclip
2019, P. Wessel, W. H. F. Smith, R. Scharroo, J. Luis, and F. Wobbe
May 21, 2019 | 5.4.5 |