# pygmt.grdtrack¶

pygmt.grdtrack(points, grid, newcolname=None, outfile=None, **kwargs)[source]

Sample grids at specified (x,y) locations.

Grdtrack reads one or more grid files and a table with (x,y) [or (lon,lat)] positions in the first two columns (more columns may be present). It interpolates the grid(s) at the positions in the table and writes out the table with the interpolated values added as (one or more) new columns. A bicubic [Default], bilinear, B-spline or nearest-neighbor interpolation is used, requiring boundary conditions at the limits of the region (see interpolation; Default uses “natural” conditions (second partial derivative normal to edge is zero) unless the grid is automatically recognized as periodic.)

Full option list at https://docs.generic-mapping-tools.org/latest/grdtrack.html

Aliases:

• n = interpolation

Parameters
• points (pandas.DataFrame or str) – Either a table with (x, y) or (lon, lat) values in the first two columns, or a filename (e.g. csv, txt format). More columns may be present.

• grid (xarray.DataArray or str) – Gridded array from which to sample values from, or a filename (netcdf format).

• newcolname (str) – Required if ‘points’ is a pandas.DataFrame. The name for the new column in the track pandas.DataFrame table where the sampled values will be placed.

• outfile (str) – Required if ‘points’ is a file. The file name for the output ASCII file.

• interpolation (str) –

[b|c|l|n][+a][+bBC][+c][+tthreshold] Select interpolation mode for grids. You can select the type of spline used:

• ’b’ for B-spline

• ’c’ for bicubic [Default]

• ’l’ for bilinear

• ’n’ for nearest-neighbor

Returns

track (pandas.DataFrame or None) – Return type depends on whether the outfile parameter is set:

• pandas.DataFrame table with (x, y, …, newcolname) if outfile is not set

• None if outfile is set (track output will be stored in outfile)