colour.KernelInterpolator#

class colour.KernelInterpolator(x: ArrayLike, y: ArrayLike, window: float = 3, kernel: Callable = kernel_lanczos, kernel_kwargs: Optional[Dict] = None, padding_kwargs: Optional[Dict] = None, dtype: Optional[Type[DTypeNumber]] = 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)\):

:math:`\hat{g}(w_0) = [k * g](w_0) = \sum_{x=-\infty}^{\infty}k(w_0 - x)\cdot g(x)`
Parameters:
  • x (ArrayLike) – Independent \(x\) variable values corresponding with \(y\) variable.

  • y (ArrayLike) – Dependent and already known \(y\) variable values to interpolate.

  • window (Floating) – Width of the window in samples on each side.

  • kernel (Callable) – Kernel to use for interpolation.

  • kernel_kwargs (Optional[Dict]) – Arguments to use when calling the kernel.

  • padding_kwargs (Optional[Dict]) – Arguments to use when padding \(y\) variable values with the np.pad() definition.

  • dtype (Optional[Type[DTypeNumber]]) – Data type used for internal conversions.

Attributes

Methods

References

[BB09], [Wikipedia05a]

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 ArrayLike 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: ArrayLike, y: ArrayLike, window: float = 3, kernel: Callable = kernel_lanczos, kernel_kwargs: Optional[Dict] = None, padding_kwargs: Optional[Dict] = None, dtype: Optional[Type[DTypeNumber]] = None) None[source]#
Parameters:
Return type:

None

property x: ndarray#

Getter and setter property for the independent \(x\) variable.

Parameters:

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

Returns:

Independent \(x\) variable.

Return type:

numpy.ndarray

property y: ndarray#

Getter and setter property for the dependent and already known \(y\) variable.

Parameters:

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

Returns:

Dependent and already known \(y\) variable.

Return type:

numpy.ndarray

property window: float#

Getter and setter property for the window.

Parameters:

value – Value to set the window with.

Returns:

Window.

Return type:

numpy.floating

property kernel: Callable#

Getter and setter property for the kernel callable.

Parameters:

value – Value to set the kernel callable.

Returns:

Kernel callable.

Return type:

Callable

property kernel_kwargs: Dict#

Getter and setter property for the kernel call time arguments.

Parameters:

value – Value to call the interpolation kernel with.

Returns:

Kernel call time arguments.

Return type:

dict

property padding_kwargs: Dict#

Getter and setter property for the kernel call time arguments.

Parameters:

value – Value to call the interpolation kernel with.

Returns:

Kernel call time arguments.

Return type:

dict

__call__(x: FloatingOrArrayLike) FloatingOrNDArray[source]#

Evaluate the interpolator at given point(s).

Parameters:

x (FloatingOrArrayLike) – Point(s) to evaluate the interpolant at.

Returns:

Interpolated value(s).

Return type:

numpy.floating or numpy.ndarray

__weakref__#

list of weak references to the object (if defined)