pygmt.grdlandmask
- pygmt.grdlandmask(outgrid=None, resolution=None, **kwargs)[source]
Create a “wet-dry” mask grid from shoreline database.
Read the selected shoreline database and use that information to decide which nodes in the specified grid are over land or over water. The nodes defined by the selected region and lattice spacing will be set according to one of two criteria: (1) land vs water, or (2) the more detailed (hierarchical) ocean vs land vs lake vs island vs pond. A mask grid is created with the specified grid spacing.
Full GMT docs at https://docs.generic-mapping-tools.org/6.5/grdlandmask.html.
Aliases:
A = area_thresh
E = bordervalues
I = spacing
N = maskvalues
R = region
V = verbose
r = registration
x = cores
- Parameters:
outgrid (
str
|PathLike
|None
, default:None
) – Name of the output netCDF grid file. If not specified, will return anxarray.DataArray
object. For writing a specific grid file format or applying basic data operations to the output grid, see https://docs.generic-mapping-tools.org/6.5/gmt.html#grd-inout-full for the available modifiers.spacing (float, str, or list) –
x_inc[+e|n][/y_inc[+e|n]]. x_inc [and optionally y_inc] is the grid spacing.
Geographical (degrees) coordinates: Optionally, append an increment unit. Choose among m to indicate arc-minutes or s to indicate arc-seconds. If one of the units e, f, k, M, n or u is appended instead, the increment is assumed to be given in meter, foot, km, mile, nautical mile or US survey foot, respectively, and will be converted to the equivalent degrees longitude at the middle latitude of the region (the conversion depends on PROJ_ELLIPSOID). If y_inc is given but set to 0 it will be reset equal to x_inc; otherwise it will be converted to degrees latitude.
All coordinates: If +e is appended then the corresponding max x (east) or y (north) may be slightly adjusted to fit exactly the given increment [by default the increment may be adjusted slightly to fit the given domain]. Finally, instead of giving an increment you may specify the number of nodes desired by appending +n to the supplied integer argument; the increment is then recalculated from the number of nodes, the
registration
, and the domain. The resulting increment value depends on whether you have selected a gridline-registered or pixel-registered grid; see GMT File Formats for details.
Note: If
region=grdfile
is used then the grid spacing and the registration have already been initialized; usespacing
andregistration
to override these values.region (str or list) – xmin/xmax/ymin/ymax[+r][+uunit]. Specify the region of interest.
area_thresh (float or str) – min_area[/min_level/max_level][+a[g|i][s|S]][+l|r][+ppercent]. Features with an area smaller than min_area in km2 or of hierarchical level that is lower than min_level or higher than max_level will not be plotted [Default is
"0/0/4"
(all features)].resolution (
Literal
['auto'
,'full'
,'high'
,'intermediate'
,'low'
,'crude'
,None
], default:None
) – Select the resolution of the coastline dataset to use. The available resolutions from highest to lowest are:"full"
,"high"
,"intermediate"
,"low"
, and"crude"
, which drops by 80% between levels. Alternatively, choose"auto"
to automatically select the most suitable resolution given the chosen region. Note that because the coastlines differ in details, a node in a mask file using one resolution is not guaranteed to remain inside [or outside] when a different resolution is selected. IfNone
, the low resolution is used by default.maskvalues (list) –
Set the values that will be assigned to nodes, in the form of [wet, dry], or [ocean, land, lake, island, pond]. Default is
[0, 1, 0, 1, 0]
(i.e.,[0, 1]
), meaning that all “wet” nodes will be assigned a value of 0 and all “dry” nodes will be assigned a value of 1. Values can be any number, or one ofNone
,"NaN"
, andnp.nan
for setting nodes to NaN.Use
bordervalues
to control how nodes on feature boundaries are handled.bordervalues (bool, float, or list) –
Sets the behavior for nodes that fall exactly on a polygon boundary. Valid values are:
False
: Treat boundary nodes as inside [Default]True
: Treat boundary nodes as outsideA single value: Set all boundary nodes to the same value
A sequence of four values in the form of [cborder, lborder, iborder, pborder] to treat different kinds of boundary nodes as the specified values. cborder is for coastline, lborder for lake outline, iborder for islands-in-lakes outlines, and pborder for ponds-in-islands-in-lakes outlines.
Values can be any number, or one of
None
,"NaN"
, andnp.nan
for setting nodes to NaN.verbose (bool or str) – Select verbosity level [Full usage].
registration (str) – g|p. Force gridline (g) or pixel (p) node registration [Default is g(ridline)].
cores (bool or int) – Specify the number of active cores to be used in any OpenMP-enabled multi-threaded algorithms. By default, all available cores are used. Set a positive number n to use n cores (if too large it will be truncated to the maximum cores available); or set a negative number -n to select (all - n) cores (or at least 1 if n equals or exceeds all).
- Return type:
- Returns:
ret – Return type depends on whether the
outgrid
parameter is set:xarray.DataArray
ifoutgrid
is not setNone
ifoutgrid
is set (grid output will be stored in the file set byoutgrid
)
Example
>>> import pygmt >>> # Create a landmask grid with a longitude range of 125° E to 130° E, a >>> # latitude range of 30° N to 35° N, and a grid spacing of 1 arc-degree >>> landmask = pygmt.grdlandmask(spacing=1, region=[125, 130, 30, 35])