per_axis_interpolator¶
-
odl.discr.discr_utils.
per_axis_interpolator
(f, coord_vecs, interp)[source]¶ Return a per axis defined interpolator for discrete values.
With this function, the interpolation scheme can be chosen for each axis separately.
- Parameters
- fnumpy.ndarray
Function values that should be interpolated.
- coord_vecssequence of numpy.ndarray
Coordinate vectors of the rectangular grid on which interpolation should be based. They must be sorted in ascending order. Usually they are obtained as
grid.coord_vectors
from aRectGrid
.- interpstr or sequence of str
Indicates which interpolation scheme to use for which axis. A single string is interpreted as a global scheme for all axes.
Examples
Choose linear interpolation in the first axis and nearest neighbor in the second:
>>> part = odl.uniform_partition([0, 0], [1, 5], shape=(2, 4)) >>> part.coord_vectors (array([ 0.25, 0.75]), array([ 0.625, 1.875, 3.125, 4.375])) >>> f = np.array([[1, 2, 3, 4], ... [5, 6, 7, 8]], ... dtype=float) >>> interpolator = per_axis_interpolator( ... f, part.coord_vectors, ['linear', 'nearest'] ... ) >>> interpolator([1, 1]) # single point 2.5 >>> x = np.array([[0.5, 2.0], ... [0.0, 4.5], ... [0.0, 3.0]]).T # 3 points at once >>> interpolator(x) array([ 4. , 2. , 1.5]) >>> from odl.discr.grid import sparse_meshgrid >>> mesh = sparse_meshgrid([0.0, 0.5, 1.0], [1.5, 3.5]) >>> interpolator(mesh) # 3x2 grid of points array([[ 1. , 1.5], [ 4. , 5. ], [ 3. , 3.5]])