colour.KernelInterpolator#
- class colour.KernelInterpolator(x: ArrayLike, y: ArrayLike, window: float = 3, kernel: Callable = kernel_lanczos, kernel_kwargs: dict | None = None, padding_kwargs: dict | None = None, dtype: Type[DTypeReal] | None = None, *args: Any, **kwargs: Any)[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 (float) – Width of the window in samples on each side.
kernel (Callable) – Kernel to use for interpolation.
kernel_kwargs (dict | None) – Arguments to use when calling the kernel.
padding_kwargs (dict | None) – Arguments to use when padding \(y\) variable values with the
np.pad()
definition.dtype (Type[DTypeReal] | None) – Data type used for internal conversions.
args (Any)
kwargs (Any)
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: dict | None = None, padding_kwargs: dict | None = None, dtype: Type[DTypeReal] | None = None, *args: Any, **kwargs: Any) None [source]#
- property x: NDArrayFloat#
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:
- property y: NDArrayFloat#
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:
- property window: float#
Getter and setter property for the window.
- Parameters:
value – Value to set the window with.
- Returns:
Window.
- Return type:
- 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:
- 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:
- __call__(x: ArrayLike) NDArrayFloat [source]#
Evaluate the interpolator at given point(s).
- Parameters:
x (ArrayLike) – Point(s) to evaluate the interpolant at.
- Returns:
Interpolated value(s).
- Return type:
- __weakref__#
list of weak references to the object