colour.KernelInterpolator¶
-
class
colour.KernelInterpolator(x, y, window=3, kernel=<function kernel_lanczos>, kernel_args=None, padding_args=None, dtype=<class 'numpy.float64'>)[source]¶ Kernel based interpolation of a 1-D function.
The reconstruction of a continuous signal can be described as a linear convolution operation. Interpolation can be expressed as a convolution of the given discrete function \(g(x)\) with some continuous interpolation kernel \(k(w)\):
\(\hat{g}(w_0) = [k * g](w_0) = \sum_{x=-\infty}^{\infty}k(w_0 - x)\cdot g(x)\)
Parameters: - x (array_like) – Independent \(x\) variable values corresponding with \(y\) variable.
- y (array_like) – Dependent and already known \(y\) variable values to interpolate.
- window (int, optional) – Width of the window in samples on each side.
- kernel (callable, optional) – Kernel to use for interpolation.
- kernel_args (dict, optional) – Arguments to use when calling the kernel.
- padding_args (dict, optional) – Arguments to use when padding \(y\) variable values with the
np.pad()definition. - dtype (type) – Data type used for internal conversions.
-
x¶
-
y¶
-
window¶
-
kernel¶
-
kernel_args¶
-
padding_args¶
References
Examples
Interpolating a single numeric variable:
>>> y = np.array([5.9200, 9.3700, 10.8135, 4.5100, ... 69.5900, 27.8007, 86.0500]) >>> x = np.arange(len(y)) >>> f = KernelInterpolator(x, y) >>> f(0.5) # doctest: +ELLIPSIS 6.9411400...
Interpolating an array_like variable:
>>> f([0.25, 0.75]) # doctest: +ELLIPSIS array([ 6.1806208..., 8.0823848...])
Using a different lanczos kernel:
>>> f = KernelInterpolator(x, y, kernel=kernel_sinc) >>> f([0.25, 0.75]) # doctest: +ELLIPSIS array([ 6.5147317..., 8.3965466...])
Using a different window size:
>>> f = KernelInterpolator( ... x, ... y, ... window=16, ... kernel=kernel_lanczos, ... kernel_args={'a': 16}) >>> f([0.25, 0.75]) # doctest: +ELLIPSIS array([ 5.3961792..., 5.6521093...])
-
__init__(x, y, window=3, kernel=<function kernel_lanczos>, kernel_args=None, padding_args=None, dtype=<class 'numpy.float64'>)[source]¶ Initialize self. See help(type(self)) for accurate signature.
Methods
__init__(x, y[, window, kernel, …])Initialize self. Attributes
kernelGetter and setter property for the kernel callable. kernel_argsGetter and setter property for the kernel call time arguments. padding_argsGetter and setter property for the kernel call time arguments. windowGetter and setter property for the window. xGetter and setter property for the independent \(x\) variable. yGetter and setter property for the dependent and already known \(y\) variable.