# colour.KernelInterpolator¶

class colour.KernelInterpolator(x, y, window=3, kernel=<function kernel_lanczos>, kernel_kwargs=None, padding_kwargs=None, dtype=None)[source]

Bases: object

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_kwargs (dict, optional) – Arguments to use when calling the kernel.

• padding_kwargs (dict, optional) – Arguments to use when padding $$y$$ variable values with the np.pad() definition.

• dtype (type) – Data type used for internal conversions.

Attributes

Methods

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)
6.9411400...


Interpolating an array_like variable:

>>> f([0.25, 0.75])
array([ 6.1806208...,  8.0823848...])


Using a different lanczos kernel:

>>> f = KernelInterpolator(x, y, kernel=kernel_sinc)
>>> f([0.25, 0.75])
array([ 6.5147317...,  8.3965466...])


Using a different window size:

>>> f = KernelInterpolator(
...     x,
...     y,
...     window=16,
...     kernel=kernel_lanczos,
...     kernel_kwargs={'a': 16})
>>> f([0.25, 0.75])
array([ 5.3961792...,  5.6521093...])

__init__(x, y, window=3, kernel=<function kernel_lanczos>, kernel_kwargs=None, padding_kwargs=None, dtype=None)[source]

Initialize self. See help(type(self)) for accurate signature.

property x

Getter and setter property for the independent $$x$$ variable.

Parameters

value (array_like) – Value to set the independent $$x$$ variable with.

Returns

Independent $$x$$ variable.

Return type

array_like

property y

Getter and setter property for the dependent and already known $$y$$ variable.

Parameters

value (array_like) – Value to set the dependent and already known $$y$$ variable with.

Returns

Dependent and already known $$y$$ variable.

Return type

array_like

property window

Getter and setter property for the window.

Parameters

value (int) – Value to set the window with.

Returns

Window.

Return type

int

property kernel

Getter and setter property for the kernel callable.

Parameters

value (callable) – Value to set the kernel callable.

Returns

Kernel callable.

Return type

callable

property kernel_kwargs

Getter and setter property for the kernel call time arguments.

Parameters

value (dict) – Value to call the interpolation kernel with.

Returns

Kernel call time arguments.

Return type

dict

property padding_kwargs

Getter and setter property for the kernel call time arguments.

Parameters

value (dict) – Value to call the interpolation kernel with.

Returns

Kernel call time arguments.

Return type

dict

__call__(x)[source]

Evaluates the interpolator at given point(s).

Parameters

x (numeric or array_like) – Point(s) to evaluate the interpolant at.

Returns

Interpolated value(s).

Return type

float or ndarray

__weakref__

list of weak references to the object (if defined)