pylops.signalprocessing.Interp¶
- pylops.signalprocessing.Interp(dims, iava, axis=-1, kind='linear', dtype='float64', name='I')[source]¶
Interpolation operator.
Apply interpolation along
axisfrom regularly sampled input vector into fractionary positionsiavausing one of the following algorithms:Nearest neighbour interpolation is a thin wrapper around
pylops.Restrictionatnp.round(iava)locations.Linear interpolation extracts values from input vector at locations
np.floor(iava)andnp.floor(iava)+1and linearly combines them in forward mode, places weighted versions of the interpolated values at locationsnp.floor(iava)andnp.floor(iava)+1in an otherwise zero vector in adjoint mode.Sinc interpolation performs sinc interpolation at locations
iava. Note that this is the most accurate method but it has higher computational cost as it involves multiplying the input data by a matrix of size \(N \times M\).Cubic Spline interpolation relies on a cubic spline, i.e., a 2-times continuously differentiable piecewise third order polynomial with equally spaced knots. It is interpolated at the locations
iavaby evaluating the respective polynomial fitted betweennp.floor(iava)andnp.floor(iava) + 1. It offers an excellent tradeoff between accuracy and computational complexity and its results oscillate less than those obtained from sinc interpolation. It can also be accessed directly viapylops.signalprocessing.InterpCubicSpline.
Note
The vector
iavashould contain unique values. If the same index is repeated twice an error will be raised. This also applies when values beyond the last element of the input array for linear interpolation and cubic spline interpolation as those values are forced to be just before this element.- Parameters:
- dims
listorint Number of samples for each dimension
- iava
listornumpy.ndarray Floating indices of locations of available samples for interpolation.
- axis
int, optional Added in version 2.0.0.
Axis along which interpolation is applied.
- kind
str, optional Kind of interpolation. Currently,
"nearest","linear","sinc", and"cubic_spline"are available.Added in version 2.7.0.
The
"cubic_spline"-interpolation was added.- dtype
str, optional Type of elements in input array.
- name
str, optional Added in version 2.0.0.
Name of operator (to be used by
pylops.utils.describe.describe)
- dims
- Returns:
- op
pylops.LinearOperator Linear interpolation operator
- iava
listornumpy.ndarray Corrected indices of locations of available samples (samples at
M-1or beyond are forced to be atM-1-eps)
- op
- Raises:
- ValueError
If the vector
iavacontains repeated values.- NotImplementedError
If
kindis notnearest,linear,sinc, orcubic_spline
See also
pylops.RestrictionRestriction operator
Notes
Linear interpolation of a subset of \(N\) values at locations
iavafrom an input (or model) vector \(\mathbf{x}\) of size \(M\) can be expressed as:\[y_i = (1-w_i) x_{l^{l}_i} + w_i x_{l^{r}_i} \quad \forall i=1,2,\ldots,N\]where \(\mathbf{l^l}=[\lfloor l_1 \rfloor, \lfloor l_2 \rfloor,\ldots, \lfloor l_N \rfloor]\) and \(\mathbf{l^r}=[\lfloor l_1 \rfloor +1, \lfloor l_2 \rfloor +1,\ldots, \lfloor l_N \rfloor +1]\) are vectors containing the indeces of the original array at which samples are taken, and \(\mathbf{w}=[l_1 - \lfloor l_1 \rfloor, l_2 - \lfloor l_2 \rfloor, ..., l_N - \lfloor l_N \rfloor]\) are the linear interpolation weights. This operator can be implemented by simply summing two
pylops.Restrictionoperators which are weighted usingpylops.basicoperators.Diagonaloperators.Sinc interpolation of a subset of \(N\) values at locations
iavafrom an input (or model) vector \(\mathbf{x}\) of size \(M\) can be expressed as:\[\DeclareMathOperator{\sinc}{sinc} y_i = \sum_{j=0}^{M} x_j \sinc(i-j) \quad \forall i=1,2,\ldots,N\]This operator can be implemented using the
pylops.MatrixMultoperator with a matrix containing the values of the sinc function at all \(i,j\) possible combinations.