pygmt.src.ClipAccessor.mask
- ClipAccessor.mask(data=None, x=None, y=None, *, spacing=None, invert=None, radius=None, **kwargs)[source]
Clip the data to a mask.
Must be used as a context manager. Any plotting operations within the context manager will be clipped to the mask.
- Parameters:
data (default:
None
) – Either a file name to an ASCII data table, a 2-Dnumpy.ndarray
, apandas.DataFrame
, anxarray.Dataset
made up of 1-Dxarray.DataArray
data variables, or ageopandas.GeoDataFrame
containing the tabular data.x/y – X and Y coordinates of the mask.
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.invert – Invert the sense of what is inside and outside.
Examples
>>> import numpy as np >>> from pygmt import Figure >>> from pygmt.datasets import load_earth_relief >>> >>> grid = load_earth_relief() >>> fig = Figure() >>> fig.basemap(region="g", projection="Q15c", frame=True) >>> with fig.clip.mask( ... x=[180] * 16, y=np.arange(-80, 80, 10), spacing="30m", radius="5d" ... ): ... fig.grdimage(grid, cmap="geo") >>> fig.show()