Interpolator of specified order on a rectilinear grid in N ≥ 1 dimensions.
The data must be defined on a rectilinear grid; that is, a rectangular
grid with even or uneven spacing. Linear, nearest-neighbor, spline
interpolations are supported. After setting up the interpolator object,
the interpolation method may be chosen at each evaluation.
Parameters:
pointstuple of ndarray of float, with shapes (m1, ), ..., (mn, )
The points defining the regular grid in n dimensions. The points in
each dimension (i.e. every elements of the points tuple) must be
strictly ascending or descending.
valuesarray_like, shape (m1, ..., mn, ...)
The data on the regular grid in n dimensions. Complex data is
accepted.
methodstr, optional
The method of interpolation to perform. Supported are "linear",
"nearest", "slinear", "cubic", "quintic" and "pchip". This
parameter will become the default for the object’s __call__
method. Default is "linear".
bounds_errorbool, optional
If True, when interpolated values are requested outside of the
domain of the input data, a ValueError is raised.
If False, then fill_value is used.
Default is True.
fill_valuefloat or None, optional
The value to use for points outside of the interpolation domain.
If None, values outside the domain are extrapolated.
Default is np.nan.
solvercallable, optional
Only used for methods "slinear", "cubic" and "quintic".
Sparse linear algebra solver for construction of the NdBSpline instance.
Default is the iterative solver scipy.sparse.linalg.gcrotmk.
Added in version 1.13.
solver_args: dict, optional
Additional arguments to pass to solver, if any.
Added in version 1.13.
Attributes:
gridtuple of ndarrays
The points defining the regular grid in n dimensions.
This tuple defines the full grid via
np.meshgrid(*grid,indexing='ij')
valuesndarray
Data values at the grid.
methodstr
Interpolation method.
fill_valuefloat or None
Use this value for out-of-bounds arguments to __call__.
bounds_errorbool
If True, out-of-bounds argument raise a ValueError.
interpolation on grids with equal spacing (suitable for e.g., N-D image resampling)
Notes
Contrary to LinearNDInterpolator and NearestNDInterpolator, this class
avoids expensive triangulation of the input data by taking advantage of the
regular grid structure.
In other words, this class assumes that the data is defined on a
rectilinear grid.
Added in version 0.14.
The ‘slinear’(k=1), ‘cubic’(k=3), and ‘quintic’(k=5) methods are
tensor-product spline interpolators, where k is the spline degree,
If any dimension has fewer points than k + 1, an error will be raised.
Added in version 1.9.
If the input data is such that dimensions have incommensurate
units and differ by many orders of magnitude, the interpolant may have
numerical artifacts. Consider rescaling the data before interpolating.
Choosing a solver for spline methods
Spline methods, "slinear", "cubic" and "quintic" involve solving a
large sparse linear system at instantiation time. Depending on data,
the default solver may or may not be adequate. When it is not, you may
need to experiment with an optional solver argument, where you may
choose between the direct solver (scipy.sparse.linalg.spsolve) or
iterative solvers from scipy.sparse.linalg. You may need to supply
additional parameters via the optional solver_args parameter (for instance,
you may supply the starting value or target tolerance). See the
scipy.sparse.linalg documentation for the full list of available options.
Alternatively, you may instead use the legacy methods, "slinear_legacy",
"cubic_legacy" and "quintic_legacy". These methods allow faster construction
but evaluations will be much slower.
Rounding rule at half points with `nearest` method
The rounding rule with the nearest method at half points is rounding down.