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 1-D function values beyond the specified interpolator’s domain boundaries.

The colour.Extrapolator class wraps a specified Colour or scipy interpolator instance with compatible signature to provide controlled extrapolation behaviour. Two extrapolation methods are supported:

  • Linear: Extrapolate values linearly using the slope defined by boundary points (xi[0], xi[1]) for x < xi[0] and (xi[-1], xi[-2]) for x > xi[-1].

  • Constant: Assign boundary values xi[0] for x < xi[0] and xi[-1] for x > xi[-1].

Specifying left and right arguments overrides the chosen extrapolation method, assigning these values to points outside the interpolator’s domain.

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:
Return type:

None

property interpolator: ProtocolInterpolator#

Getter and setter for the interpolator.

The interpolator must implement the interpolator protocol with an x attribute containing the independent variable data.

Parameters:

value – Value to set the interpolator instance implementing the required protocol with an x attribute for wavelength or frequency values with.

Returns:

Interpolator instance implementing the required protocol with an x attribute for wavelength or frequency values.

Return type:

ProtocolInterpolator

__weakref__#

list of weak references to the object

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

Getter and setter for the extrapolation method for the interpolator.

This property controls the behaviour of the interpolator when extrapolating values outside the interpolation domain. The method determines how values are computed beyond the specified boundaries.

Parameters:

value – Value to set the extrapolation method to use, either 'Linear' for linear extrapolation or 'Constant' for constant value extrapolation at the boundaries.

Returns:

Extrapolation method to use.

Return type:

str

property left: TypeAliasForwardRef('Real') | None#

Getter and setter for the left boundary value.

Specifies the value to return when evaluating the interpolant at points beyond the leftmost data point ( x < xi[0]).

Parameters:

value – Value to return for x < xi[0] for extrapolation beyond the leftmost data point.

Returns:

Value to return for x < xi[0] for extrapolation beyond the leftmost data point.

Return type:

Real or None

property right: TypeAliasForwardRef('Real') | None#

Getter and setter for the right boundary value.

Specifies the value to return when evaluating the interpolant at points beyond the rightmost data point (x > xi[-1]).

Parameters:

value – Value to return for x > xi[-1] for extrapolation beyond the rightmost data point.

Returns:

Value to return for x > xi[-1] for extrapolation beyond the rightmost data point.

Return type:

numbers.Real or None

__call__(x: ArrayLike) NDArrayFloat[source]#

Evaluate the extrapolator at specified point(s).

Parameters:

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

Returns:

Extrapolated point value(s).

Return type:

numpy.ndarray