interpolate

interpolate(
    x,
    y,
    xout,
    method='linear',
    order=None,
    x_transform='none',
    y_transform='none',
    sort_order='ascending',
    extrapolate=False,
)

Interpolate a paired series.

Mirrors the C# Linear, CubicSpline, and Polynomial interpolaters of the Numerics library. x_transform, y_transform, and extrapolate are Linear-only in C# (neither CubicSpline nor Polynomial has a transform surface or an Extrapolate() method), so they must be left at their defaults for method="cubic_spline" or "polynomial".

Parameters

Name Type Description Default
x array_like Equal-length knots. required
y array_like Equal-length knots. required
xout array_like Positions to interpolate at. required
method ('linear', 'cubic_spline', 'polynomial') "linear"
order int The polynomial order – there are order + 1 terms for each polynomial function. Required when method="polynomial"; must be None otherwise. None
x_transform ('none', 'logarithmic', 'log', 'normal_z') Linear-only. "logarithmic" and "log" are equivalent aliases for the same Transform.Logarithmic value everywhere a transform argument appears in this module (:func:interpolate, :func:interpolate_2d, :func:curve_interpolate, :func:tabular_function); "logarithmic" (matching the C# enum member name) is the spelling used in this package’s own examples and documentation. "none"
y_transform ('none', 'logarithmic', 'log', 'normal_z') Linear-only. "logarithmic" and "log" are equivalent aliases for the same Transform.Logarithmic value everywhere a transform argument appears in this module (:func:interpolate, :func:interpolate_2d, :func:curve_interpolate, :func:tabular_function); "logarithmic" (matching the C# enum member name) is the spelling used in this package’s own examples and documentation. "none"
sort_order ('ascending', 'descending') Describes x. "ascending"
extrapolate bool Whether to extend the end segments beyond the knots. False (the default) clamps to the end knot, matching the C# Interpolate() default; True calls the C# Extrapolate() method instead. Linear-only. False

Returns

Name Type Description
numpy.ndarray Same length as xout.

Examples

>>> from corehydropy import interpolate
>>> interpolate([1, 2, 3, 4], [10, 20, 30, 40], [1.5, 2.5])
array([15., 25.])
>>> interpolate([1, 2, 3, 4], [10, 20, 30, 40], [1.5, 2.5], method="cubic_spline")
array([15., 25.])
>>> interpolate([1, 2, 3, 4], [10, 20, 30, 40], [1.5, 2.5], method="polynomial", order=3)
array([15., 25.])