findidx

sofia_redux.toolkit.interpolate.interpolate.findidx(ix, ox, left=0, right=None)[source]

Finds the effective index of a function value in an ordered array.

Formerly tabinv. findidx will abort if xi is not monotonic. Equality of neighboring values in xi is allowed but results may not be unique. This requirement may mean that xi padded with zeroes could cause findidx to abort.

A binary search is used to find the values xi[i] and xi[i+1] where xi[i] < xo < xi[i+1]. Output (ieff) is then computed using linear interpolation between i and i+1:

ieff = i + (xo - xi[i]) / (xi[i+1] - xi[i])
Let n = number of elements in xi::

if (x < xi[0]) or (x > xi[n-1]) then xo = NaN

Parameters:
ixarray_like of float

(N,) The array to be searched, must be monotonic increasing or decreasing.

ox(array_like of float) or float

(M,) The function value(s) whose effective index is sought.

leftfloat, optional

Value to return for ox < min(ix). default is 0

rightfloat, optional

Value to return for ox > max(ix). default is len(ix) - 1

Returns:
float or numpy.ndarray

(M,) The effective index or indices of xo in xi. Note that output type will be float and will need to changed to integer in order to be used for indexing another array.