Module: safe.common.interpolation1d
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 interpolation2d.py for documentation of the mathematical derivation used.
-
safe.common.interpolation1d.check_inputs(x, z, points, mode, bounds_error)[source]
Check inputs for interpolate1d function
-
safe.common.interpolation1d.interpolate1d(x, z, points, mode='linear', bounds_error=False)[source]
Fundamental 2D interpolation routine
- Args:
x: 1D array of x-coordinates on which to interpolate
z: 1D array of values for each x
points: 1D array of coordinates where interpolated values are sought
- mode: Determines the interpolation order. Options are:
- ‘constant’ - piecewise constant nearest neighbour interpolation
- ‘linear’ - bilinear interpolation using the two nearest neighbours (default)
- bounds_error: Boolean flag. If True (default) 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
- Returns:
- 1D array with same length as points with interpolated values
- Note:
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).
This module forms part of the InaSAFE tool.