pygetm.util.interpolate module

class pygetm.util.interpolate.Linear2DGridInterpolator(x: ArrayLike, y: ArrayLike, xp: ArrayLike, yp: ArrayLike, preslice=(Ellipsis,), ndim_trailing: int = 0, mask: ArrayLike | None = None)[source]

Bases: object

class pygetm.util.interpolate.LinearVectorized1D(x: ArrayLike, xp: ArrayLike, axis: int = 0, fill_value: float = nan, mask: ArrayLike | None = None, edges: EdgeTreatment = EdgeTreatment.MISSING)[source]

Bases: object

One-dimensional linear interpolation along a given axis, for nD source coordinates and 1D target coordinates. For instance, to go from 3D depths to a z grid (1D)

Initialize the interpolator. It can subsequently be called multiple times with different source values but the same coordinates.

Parameters:
  • x – Target coordinate values (1D)

  • xp – Source coordinate values (nD)

  • axis – Axis along which to interpolate

  • fill_value – Value to use for out-of-bounds target coordinates (if edges is MISSING) and for locations where there are no valid source points along the interpolated dimension (if mask is given)

  • mask – Optional boolean array of the same shape as xp indicating masked (invalid) source points. It is currently only used to detect locations where there are no valid source points along the interpolated dimension. There, fill_value will be used independent of the edges setting.

  • edges – How to treat target coordinates that fall outside the range of valid source coordinates. If MISSING, these will be assigned fill_value. If CLAMP, these will be assigned the nearest valid source value.

pygetm.util.interpolate.interp_1d(x: ArrayLike, xp: ArrayLike, fp: ArrayLike, axis: int = 0) ndarray[source]

One-dimensional linear interpolation along a given axis for 1D source coordinates and nD target coordinates. For instance, to interpolate from 3D values defined at z coordinates (1D) to 3D values at depth coordinates that vary in the horizontal.

Source values may contain NaNs or masked values at the beginning or end of the interpolated dimension; these will be skipped during interpolation.

Where target coordinates fall outside the range of valid source coordinates, the corresponding output values will be equal to the nearest valid source value.

Parameters:
  • x – Target coordinate values (nD, matching shape of fp except at axis)

  • xp – Source coordinate values (1D)

  • fp – Source values to interpolate (nD, matching the size of xp at axis)

  • axis – Axis along which to interpolate

Returns:

Interpolated values at target coordinates