airbornegeo.sample_grid

Contents

airbornegeo.sample_grid#

sample_grid(grid, x, y, interpolation='cubic')[source]#

Sample a grid’s values at a set of x, y point coordinates. By default this uses bicubic spline interpolation (scipy.interpolate.RectBivariateSpline), matching pygmt.grdtrack’s default behavior (interpolation=”c”) closely on smooth grids (sub-percent differences) and reasonably on rough, high-frequency ones (e.g. real terrain: a few tenths of a percent RMS of the grid’s value range in testing) - scipy’s spline and GMT’s own bicubic convolution algorithm are both legitimate but different interpolants, so they are not bit-identical on rough data. Pass interpolation=”nearest” for fast nearest-grid-cell sampling instead (see _sample_grid_nearest for details on that method, including NaN and tie handling). NaN values in x or y give a NaN sample; for “cubic”, a point whose nearest original grid cell is NaN also samples as NaN, matching GMT’s behavior near data gaps.

Parameters:
  • grid (DataArray) – 2D grid to sample, with coordinates along its two dimensions.

  • x (ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]) – x-coordinates of the points to sample at.

  • y (ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]) – y-coordinates of the points to sample at, same length as x.

  • interpolation (str) – Either “cubic” or “nearest”, by default “cubic”.

Returns:

Sampled grid values, the same length and order as x and y.

Return type:

ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]