Post · 2 min read· pp. 864–866

aerosandbox.numpy.interpolate

Functions

interp(x, xp, fp[, left, right, period])One-dimensional linear interpolation, analogous to numpy.interp().
is_data_structured(x_data_coordinates, y_data_structured)Determines if the shapes of a given dataset are consistent with "structured" (i.e. gridded) data.
interpn(points, values, xi[, method, bounds_error, ...])Performs multidimensional interpolation on regular grids. Analogue to scipy.interpolate.interpn().

Module Contents

aerosandbox.numpy.interpolate.interp(x, xp, fp, left=None, right=None, period=None) : One-dimensional linear interpolation, analogous to numpy.interp().

code
Returns the one-dimensional piecewise linear interpolant to a function with given discrete data points (xp, fp),
evaluated at x.

See syntax here: <https://numpy.org/doc/stable/reference/generated/numpy.interp.html>

Specific notes: xp is assumed to be sorted.

aerosandbox.numpy.interpolate.is_data_structured(x_data_coordinates, y_data_structured) : Determines if the shapes of a given dataset are consistent with “structured” (i.e. gridded) data.

code
For this to evaluate True, the inputs should be:

> x\_data\_coordinates: A tuple or list of 1D ndarrays that represent coordinates along each axis of a N-dimensional hypercube.
>
> y\_data\_structured: The values of some scalar defined on that N-dimensional hypercube, expressed as an
> N-dimesional array. In other words, y\_data\_structured is evaluated at np.meshgrid(\*x\_data\_coordinates,
> indexing=”ij”).

Returns: Boolean of whether the above description is true.

Parameters:
:   - **x\_data\_coordinates** (*Tuple**[**numpy.ndarray**]*) –
    - **y\_data\_structured** (*numpy.ndarray*) –

Return type:
:   bool

aerosandbox.numpy.interpolate.interpn(points, values, xi, method='linear', bounds_error=True, fill_value=_onp.nan) : Performs multidimensional interpolation on regular grids. Analogue to scipy.interpolate.interpn().

code
See syntax here: <https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.interpn.html>

Parameters:
:   - **points** (*Tuple**[**numpy.ndarray**]*) – The points defining the regular grid in n dimensions. Tuple of coordinates of each axis. Shapes (m1,
    - **)** (*mn**,*) –
    - **...** (*mn**,*) –
    - **values** (*numpy.ndarray*) –
    - **xi** (*numpy.ndarray*) –
    - **method** (*str*) –

Return type:
:   numpy.ndarray

:param :
:type : mn,
:param values: The data on the regular grid in n dimensions. Shape (m1, …, mn)
:param xi: The coordinates to sample the gridded data at. (…, ndim)
:param method: The method of interpolation to perform. one of:

> - “bspline” (Note: differentiable and suitable for optimization - made of piecewise-cubics. For other
>
> applications, other interpolators may be faster. Not monotonicity-preserving - may overshoot.)
>
> - “linear” (Note: differentiable, but not suitable for use in optimization w/o subgradient treatment due
>
> to C1-discontinuity)
>
> - “nearest” (Note: NOT differentiable, don’t use in optimization. Fast.)

Parameters:
:   - **bounds\_error** – If True, when interpolated values are requested outside of the domain of the input data,
    - **False** (*a ValueError is raised. If*) –
    - **used.** (*then fill\_value is*) –
    - **fill\_value** – If provided, the value to use for points outside of the interpolation domain. If None,
    - **extrapolated.** (*values outside the domain are*) –
    - **points** (*Tuple**[**numpy.ndarray**]*) –
    - **values** (*numpy.ndarray*) –
    - **xi** (*numpy.ndarray*) –
    - **method** (*str*) –

Return type:
:   numpy.ndarray

Returns: Interpolated values at input coordinates.