tabinv

sofia_redux.toolkit.interpolate.interpolate.tabinv(array, xvals, missing=None, fast=True)[source]

Find the effective index of a function value in an ordered vector with NaN handling.

Parameters:
arrayarray_like

The array to be searched. Should be monotonic increasing or decreasing.

xvalsthe function value(s) whose effective index is sought
missingfloat or int, optional

Value to return if outside the limits. Default uses constant value of the first or last value in the array. Only pertinent if fast is True.

fastbool, optional

If False, uses findidx to check if x in monotonic and does not allow extrapolation beyond the limits of array. NaNs will break monotonic check if not limited to padding on the edges of array. If fast is True, np.interp is used without any form of error checking.

Returns:
numpy.ndarray

The effective index or indices of array

Examples

>>> from sofia_redux.toolkit.interpolate.interpolate import tabinv
>>> import numpy as np
>>> import pytest
>>> x = [np.nan, np.nan, 1, 2, np.nan, 3, np.nan, np.nan]
>>> tabinv(x, 1.5)
2.5
>>> with pytest.raises(ValueError):
...     tabinv(x, 1.5, fast=False)
...
>>> x = [np.nan, np.nan, 1, 2, 3, np.nan, np.nan]
>>> tabinv(x, 1.5, fast=False)
2.5