colour.algebra.interpolation Module¶
Interpolation¶
Defines classes for interpolating variables.
LinearInterpolator
: 1-D function linear interpolation.SpragueInterpolator
: 1-D function fifth-order polynomial interpolation.CubicSplineInterpolator
: 1-D function cubic spline interpolation.PchipInterpolator
: 1-D function piecewise cube Hermite interpolation.lagrange_coefficients()
: Computation of Lagrange Coefficients.
-
class
colour.algebra.interpolation.
LinearInterpolator
(x=None, y=None)[source]¶ Bases:
object
Linearly interpolates a 1-D function.
Parameters: - x (ndarray) – Independent \(x\) variable values corresponding with \(y\) variable.
- y (ndarray) – Dependent and already known \(y\) variable values to interpolate.
Notes
This class is a wrapper around numpy.interp definition.
See also
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 = LinearInterpolator(x, y) >>> # Doctests ellipsis for Python 2.x compatibility. >>> f(0.5) 7.64...
Interpolating an array_like variable:
>>> f([0.25, 0.75]) array([ 6.7825, 8.5075])
-
__call__
(x)[source] Evaluates the interpolating polynomial 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
-
x
¶ Property for self.__x private attribute.
Returns: self.__x Return type: array_like
-
y
¶ Property for self.__y private attribute.
Returns: self.__y Return type: array_like
-
class
colour.algebra.interpolation.
SpragueInterpolator
(x=None, y=None)[source]¶ Bases:
object
Constructs a fifth-order polynomial that passes through \(y\) dependent variable.
Sprague (1880) method is recommended by the CIE for interpolating functions having a uniformly spaced independent variable.
Parameters: - x (array_like) – Independent \(x\) variable values corresponding with \(y\) variable.
- y (array_like) – Dependent and already known \(y\) variable values to interpolate.
See also
Notes
The minimum number \(k\) of data points required along the interpolation axis is \(k=6\).
References
[1] CIE TC 1-38. (2005). 9.2.4 Method of interpolation for uniformly spaced independent variable. In CIE 167:2005 Recommended Practice for Tabulating Spectral Data for Use in Colour Computations (pp. 1–27). ISBN:978-3-901-90641-1 [2] Westland, S., Ripamonti, C., & Cheung, V. (2012). Interpolation Methods. In Computational Colour Science Using MATLAB (2nd ed., pp. 29–37). ISBN:978-0-470-66569-5 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 = SpragueInterpolator(x, y) >>> f(0.5) 7.2185025...
Interpolating an array_like variable:
>>> f([0.25, 0.75]) array([ 6.7295161..., 7.8140625...])
-
SPRAGUE_C_COEFFICIENTS
= array([[ 884, -1960, 3033, -2648, 1080, -180], [ 508, -540, 488, -367, 144, -24], [ -24, 144, -367, 488, -540, 508], [ -180, 1080, -2648, 3033, -1960, 884]])¶ Defines the coefficients used to generate extra points for boundaries interpolation.
SPRAGUE_C_COEFFICIENTS : array_like, (4, 6)
References
[3] CIE TC 1-38. (2005). Table V. Values of the c-coefficients of Equ.s 6 and 7. In CIE 167:2005 Recommended Practice for Tabulating Spectral Data for Use in Colour Computations (p. 19). ISBN:978-3-901-90641-1
-
__call__
(x)[source] Evaluates the interpolating polynomial at given point(s).
Parameters: x (numeric or array_like) – Point(s) to evaluate the interpolant at. Returns: Interpolated value(s). Return type: numeric or ndarray
-
x
¶ Property for self.__x private attribute.
Returns: self.__x Return type: array_like
-
y
¶ Property for self.__y private attribute.
Returns: self.__y Return type: array_like
-
colour.algebra.interpolation.
lagrange_coefficients
(r, n=4)[source]¶ Computes the Lagrange Coefficients at given point \(r\) for degree \(n\).
Parameters: - r (numeric) – Point to get the Lagrange Coefficients at.
- n (int, optional) – Degree of the Lagrange Coefficients being calculated.
Returns: Return type: ndarray
References
[4] Fairman, H. S. (1985). The calculation of weight factors for tristimulus integration. Color Research & Application, 10(4), 199–203. doi:10.1002/col.5080100407 [5] Wikipedia. (n.d.). Lagrange polynomial - Definition. Retrieved January 20, 2016, from https://en.wikipedia.org/wiki/Lagrange_polynomial#Definition Examples
>>> lagrange_coefficients(0.1) array([ 0.8265, 0.2755, -0.1305, 0.0285])