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:
objectPerform kernel-based interpolation of a 1-D function.
Reconstruct a continuous signal from discrete samples using linear convolution. Express interpolation as the convolution of the specified discrete function \(g(x)\) with a 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 (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) np.float64(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 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 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 for the filtering window size for the moving average.
The window determines the number of samples used in the moving average calculation. A larger window produces smoother results with greater lag, while a smaller window yields more responsive but potentially noisier output.
- Parameters:
value – Value to set the window with.
- Returns:
Window size for the moving average filter.
- Return type:
- property kernel: Callable#
Getter and setter for the kernel callable for the interpolator.
- Parameters:
value – Value to set the callable object to use as the interpolation kernel with. Must be a callable that accepts numeric arguments.
- Returns:
Callable object to use as the interpolation kernel.
- Return type:
- Raises:
AssertionError – If the provided value is not callable.
- property kernel_kwargs: dict#
Getter and setter for the kernel keyword arguments for the convolution operation.
- Parameters:
value – Value to set the keyword arguments to pass to the kernel function with.
- Returns:
Keyword arguments to pass to the kernel function.
- Return type:
- Raises:
AssertionError – If the provided value is not a :class:’dict` class instance.
- property padding_kwargs: dict#
Getter and setter for the padding keyword arguments for edge handling.
- Parameters:
value – Value to set the keyword arguments to pass to the padding function when handling edges during interpolation.
- Returns:
Keyword arguments to pass to the padding function when handling edges during interpolation.
- Return type:
- Raises:
AssertionError – If the provided value is not a
dictclass instance.
- __call__(x: ArrayLike) NDArrayFloat[source]#
Evaluate the interpolator at specified 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