safe.gis.interpolation1d module

Module for 1D interpolation

This module:

  • provides piecewise constant (nearest neighbour) and bilinear interpolation
  • is fast (based on numpy vector operations)
  • depends only on numpy
  • guarantees that interpolated values never exceed the two nearest neighbours
  • handles missing values in domain sensibly using NaN
  • is unit tested with a range of common and corner cases

See for documentation of the mathematical derivation used.

safe.gis.interpolation1d.interpolate1d(x, z, points, mode='linear', bounds_error=False)[source]

Fundamental 1D interpolation routine.

  • x (numpy.ndarray) – 1D array of x-coordinates on which to interpolate
  • z (numpy.ndarray) – 1D array of values for each x
  • points (numpy.ndarray) – 1D array of coordinates where interpolated values are sought
  • mode (str) –

    Determines the interpolation order. Options are:

    • ‘constant’ - piecewise constant nearest neighbour interpolation
    • ‘linear’ - bilinear interpolation using the two nearest neighbours (default)
  • bounds_error (bool) – Flag to indicate whether an exception will be raised when interpolated values are requested outside the domain of the input data. If False, nan is returned for those values.

1D array with same length as points with interpolated values

Return type:





Input coordinates x are assumed to be monotonically increasing, but need not be equidistantly spaced.

z is assumed to have dimension M where M = len(x).