pygmt.sphdistance
- pygmt.sphdistance(data=None, x=None, y=None, outgrid=None, **kwargs)[source]
Create Voronoi distance, node, or natural nearest-neighbor grid on a sphere.
Reads a table containing lon, lat columns and performs the construction of Voronoi polygons. These polygons are then processed to calculate the nearest distance to each node of the lattice and written to the specified grid.
Full option list at https://docs.generic-mapping-tools.org/6.5/sphdistance.html
Aliases:
C = single_form
D = duplicate
E = quantity
I = spacing
L = unit
N = node_table
Q = voronoi
R = region
V = verbose
- Parameters:
data (str, numpy.ndarray, pandas.DataFrame, xarray.Dataset, or geopandas.GeoDataFrame) – Pass in (x, y) or (longitude, latitude) values by providing a file name to an ASCII data table, a 2-D
numpy.ndarray
, apandas.DataFrame
, anxarray.Dataset
made up of 1-Dxarray.DataArray
data variables, or ageopandas.GeoDataFrame
containing the tabular data.x/y (1-D arrays) – Arrays of x and y coordinates.
outgrid (
str
|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.
Select verbosity level [Default is w], which modulates the messages written to stderr. Choose among 7 levels of verbosity:
q - Quiet, not even fatal error messages are produced
e - Error messages only
w - Warnings [Default]
t - Timings (report runtimes for time-intensive algorithms)
i - Informational messages (same as
verbose=True
)c - Compatibility warnings
d - Debugging messages
single_form (bool) – For large data sets you can save some memory (at the expense of more processing) by only storing one form of location coordinates (geographic or Cartesian 3-D vectors) at any given time, translating from one form to the other when necessary [Default keeps both arrays in memory]. Not applicable with
voronoi
.duplicate (bool) – Used to skip duplicate points since the algorithm cannot handle them. [Default assumes there are no duplicates].
quantity (str) –
d|n|z[dist]. Specify the quantity that should be assigned to the grid nodes [Default is d]:
d - compute distances to the nearest data point
n - assign the ID numbers of the Voronoi polygons that each grid node is inside
z - assign all nodes inside the polygon the z-value of the center node for a natural nearest-neighbor grid.
Optionally, append the resampling interval along Voronoi arcs in spherical degrees.
unit (str) – Specify the unit used for distance calculations. Choose among d (spherical degrees), e (meters), f (feet), k (kilometers), M (miles), n (nautical miles), or u (survey feet).
node_table (str) – Read the information pertaining to each Voronoi polygon (the unique node lon, lat and polygon area) from a separate file [Default acquires this information from the ASCII segment headers of the output file]. Required if binary input via voronoi is used.
voronoi (str) – Append the name of a file with pre-calculated Voronoi polygons [Default performs the Voronoi construction on input data].
- Return type:
- Returns:
ret – Return type depends on whether the
outgrid
parameter is set:xarray.DataArray
ifoutgrid
is not setNone if
outgrid
is set (grid output will be stored in file set byoutgrid
)
Example
>>> import numpy as np >>> import pygmt >>> # Create an array of longitude/latitude coordinates >>> coords_list = [[85.5, 22.3], [82.3, 22.6], [85.8, 22.4], [86.5, 23.3]] >>> coords_array = np.array(coords_list) >>> # Perform a calculation of the distance to >>> # each point from Voronoi polygons >>> grid = pygmt.sphdistance( ... data=coords_array, spacing=[1, 2], region=[82, 87, 22, 24] ... )