lfkit.utils.interpolation module#
Interpolation utilities for 1D tabulated curves.
This module provides small helpers for preparing tabulated (x, y) data for interpolation and constructing simple 1D interpolators with optional extrapolation. These utilities are intended for internal use across LFKit (e.g., correction tables, response curves, and other tabulated mappings).
- lfkit.utils.interpolation.as_1d_finite_grid(z_grid, *, name='z_grid')[source]#
- Parameters:
z_grid (ArrayLike)
name (str)
- Return type:
ndarray
- lfkit.utils.interpolation.build_1d_interpolator(z, y, *, method, extrapolate, extrap_mode='native')[source]#
Builds a 1D interpolator for tabulated data.
- Parameters:
z (ndarray) – Sample locations.
y (ndarray) – Sample values at
z.method (Literal['pchip', 'akima', 'linear']) – Interpolation method. Supported values are
"pchip","akima", and"linear".extrapolate (bool) – Whether to allow evaluation outside the tabulated range.
extrap_mode (Literal['none', 'native', 'linear_tail']) – Extrapolation mode.
- Returns:
A callable interpolator. For
"pchip"and"akima", this is a SciPy interpolator object. For"linear", this is a function implementing linear interpolation (and optional linear extrapolation).- Raises:
ValueError – If
methodis not recognized or the inputs cannot be prepared for interpolation.- Return type:
PchipInterpolator | Akima1DInterpolator | Callable[[ndarray], ndarray]
- lfkit.utils.interpolation.linear_interp_extrap(x, xp, fp)[source]#
Interpolates linearly and extrapolates linearly outside the tabulated range.
This function behaves like
numpy.interpwithin the range spanned byxp, but extends the curve outside that range using straight-line extrapolation from the first/last interval.- Parameters:
x (ndarray) – Query points.
xp (ndarray) – Monotonic sample locations.
fp (ndarray) – Sample values at
xp.
- Returns:
Interpolated values at
xwith linear extrapolation beyond[xp[0], xp[-1]].- Raises:
ValueError – If
xpandfphave different lengths.- Return type:
ndarray
- lfkit.utils.interpolation.prep_strictly_increasing_xy(z, y)[source]#
Prepares tabulated data for 1D interpolation.
- Parameters:
z (ndarray) – Sample locations.
y (ndarray) – Sample values at
z.
- Returns:
A tuple
(z_out, y_out)wherez_outis strictly increasing and aligned withy_out. Non-finite entries are removed.- Raises:
ValueError – If fewer than two valid sample points remain.
- Return type:
tuple[ndarray, ndarray]