colour.Extrapolator#

class colour.Extrapolator(interpolator: ProtocolInterpolator | None = None, method: Literal['Linear', 'Constant'] | str = 'Linear', left: Real | None = None, right: Real | None = None, dtype: Type[DTypeReal] | None = None, *args: Any, **kwargs: Any)[source]#

Bases: object

Extrapolate the 1-D function of given interpolator.

The colour.Extrapolator class acts as a wrapper around a given Colour or scipy interpolator class instance with compatible signature. Two extrapolation methods are available:

  • Linear: Linearly extrapolates given points using the slope defined by the interpolator boundaries (xi[0], xi[1]) if x < xi[0] and (xi[-1], xi[-2]) if x > xi[-1].

  • Constant: Extrapolates given points by assigning the interpolator boundaries values xi[0] if x < xi[0] and xi[-1] if x > xi[-1].

Specifying the left and right arguments takes precedence on the chosen extrapolation method and will assign the respective left and right values to the given points.

Parameters:
  • interpolator (ProtocolInterpolator | None) – Interpolator object.

  • method (Literal['Linear', 'Constant'] | str) – Extrapolation method.

  • left (Real | None) – Value to return for x < xi[0].

  • right (Real | None) – Value to return for x > xi[-1].

  • dtype (Type[DTypeReal] | None) – Data type used for internal conversions.

  • args (Any) –

  • kwargs (Any) –

Methods

Notes

  • The interpolator must define x and y properties.

References

[sastanin], [WRC12b]

Examples

Extrapolating a single numeric variable:

>>> from colour.algebra import LinearInterpolator
>>> x = np.array([3, 4, 5])
>>> y = np.array([1, 2, 3])
>>> interpolator = LinearInterpolator(x, y)
>>> extrapolator = Extrapolator(interpolator)
>>> extrapolator(1)
-1.0

Extrapolating an ArrayLike variable:

>>> extrapolator(np.array([6, 7, 8]))
array([ 4.,  5.,  6.])

Using the Constant extrapolation method:

>>> x = np.array([3, 4, 5])
>>> y = np.array([1, 2, 3])
>>> interpolator = LinearInterpolator(x, y)
>>> extrapolator = Extrapolator(interpolator, method="Constant")
>>> extrapolator(np.array([0.1, 0.2, 8, 9]))
array([ 1.,  1.,  3.,  3.])

Using defined left boundary and Constant extrapolation method:

>>> x = np.array([3, 4, 5])
>>> y = np.array([1, 2, 3])
>>> interpolator = LinearInterpolator(x, y)
>>> extrapolator = Extrapolator(interpolator, method="Constant", left=0)
>>> extrapolator(np.array([0.1, 0.2, 8, 9]))
array([ 0.,  0.,  3.,  3.])
__init__(interpolator: ProtocolInterpolator | None = None, method: Literal['Linear', 'Constant'] | str = 'Linear', left: Real | None = None, right: Real | None = None, dtype: Type[DTypeReal] | None = None, *args: Any, **kwargs: Any) None[source]#
Parameters:
  • interpolator (ProtocolInterpolator | None) –

  • method (Literal['Linear', 'Constant'] | str) –

  • left (Real | None) –

  • right (Real | None) –

  • dtype (Type[DTypeReal] | None) –

  • args (Any) –

  • kwargs (Any) –

Return type:

None

property interpolator: ProtocolInterpolator#

Getter and setter property for the Colour or scipy interpolator class instance.

Parameters:

value – Value to set the Colour or scipy interpolator class instance with.

Returns:

Colour or scipy interpolator class instance.

Return type:

ProtocolInterpolator

__weakref__#

list of weak references to the object (if defined)

property method: Literal['Linear', 'Constant'] | str#

Getter and setter property for the extrapolation method.

Parameters:

value – Value to set the extrapolation method. with.

Returns:

Extrapolation method.

Return type:

str

property left: Real | None#

Getter and setter property for left value to return for x < xi[0].

Parameters:

value – Left value to return for x < xi[0].

Returns:

Left value to return for x < xi[0].

Return type:

None or Real

property right: Real | None#

Getter and setter property for right value to return for x > xi[-1].

Parameters:

value – Right value to return for x > xi[-1].

Returns:

Right value to return for x > xi[-1].

Return type:

None or Real

__call__(x: ArrayLike) NDArrayFloat[source]#

Evaluate the Extrapolator at given point(s).

Parameters:

x (ArrayLike) – Point(s) to evaluate the Extrapolator at.

Returns:

Extrapolated points value(s).

Return type:

numpy.ndarray