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:

  • V = verbose

  • f = coltypes

  • n = interpolation

Parameters
  • points (str or numpy.ndarray or pandas.DataFrame or xarray.Dataset or geopandas.GeoDataFrame) – Pass in either a file name to an ASCII data table, a 2D numpy.ndarray, a pandas.DataFrame, an xarray.Dataset made up of 1D xarray.DataArray data variables, or a geopandas.GeoDataFrame containing the tabular data.

  • 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) – The file name for the output ASCII file.

  • verbose (bool or str) –

    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

  • coltypes (str) – [i|o]colinfo. Specify data types of input and/or output columns (time or geographical data). Full documentation is at https://docs.generic-mapping-tools.org/latest/gmt.html#f-full.

  • 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 file set by outfile)

Examples using pygmt.grdtrack