colour.continuous.Signal

class colour.continuous.Signal(data=None, domain=None, **kwargs)[source]

Defines the base class for continuous signal.

The class implements the Signal.function() method so that evaluating the function for any independent domain \(x \in \mathbb{R}\) variable returns a corresponding range \(y \in \mathbb{R}\) variable. It adopts an interpolating function encapsulated inside an extrapolating function. The resulting function independent domain, stored as discrete values in the colour.continuous.Signal.domain attribute corresponds with the function dependent and already known range stored in the colour.continuous.Signal.range attribute.

Parameters:
  • data (Series or Signal or array_like or dict_like, optional) – Data to be stored in the continuous signal.
  • domain (array_like, optional) – Values to initialise the colour.continuous.Signal.domain attribute with. If both data and domain arguments are defined, the latter with be used to initialise the colour.continuous.Signal.domain attribute.
Other Parameters:
 
  • name (unicode, optional) – Continuous signal name.
  • dtype (type, optional) – {np.float16, np.float32, np.float64, np.float128}, Floating point data type.
  • interpolator (object, optional) – Interpolator class type to use as interpolating function.
  • interpolator_args (dict_like, optional) – Arguments to use when instantiating the interpolating function.
  • extrapolator (object, optional) – Extrapolator class type to use as extrapolating function.
  • extrapolator_args (dict_like, optional) – Arguments to use when instantiating the extrapolating function.
dtype
domain
range
interpolator
interpolator_args
extrapolator
extrapolator_args
function
__str__()[source]
__repr__()[source]
__getitem__()[source]
__setitem__()[source]
__contains__()[source]
__eq__()[source]
__ne__()[source]
arithmetical_operation()[source]
signal_unpack_data()[source]
fill_nan()[source]
to_series()[source]

Examples

Instantiation with implicit domain:

>>> range_ = np.linspace(10, 100, 10)
>>> print(Signal(range_))
[[   0.   10.]
 [   1.   20.]
 [   2.   30.]
 [   3.   40.]
 [   4.   50.]
 [   5.   60.]
 [   6.   70.]
 [   7.   80.]
 [   8.   90.]
 [   9.  100.]]

Instantiation with explicit domain:

>>> domain = np.arange(100, 1100, 100)
>>> print(Signal(range_, domain))
[[  100.    10.]
 [  200.    20.]
 [  300.    30.]
 [  400.    40.]
 [  500.    50.]
 [  600.    60.]
 [  700.    70.]
 [  800.    80.]
 [  900.    90.]
 [ 1000.   100.]]

Instantiation with a dict:

>>> print(Signal(dict(zip(domain, range_))))
[[  100.    10.]
 [  200.    20.]
 [  300.    30.]
 [  400.    40.]
 [  500.    50.]
 [  600.    60.]
 [  700.    70.]
 [  800.    80.]
 [  900.    90.]
 [ 1000.   100.]]

Instantiation with a Pandas Series:

>>> if is_pandas_installed():
...     from pandas import Series
...     print(Signal(  
...         Series(dict(zip(domain, range_)))))
[[  100.    10.]
 [  200.    20.]
 [  300.    30.]
 [  400.    40.]
 [  500.    50.]
 [  600.    60.]
 [  700.    70.]
 [  800.    80.]
 [  900.    90.]
 [ 1000.   100.]]

Retrieving domain y variable for arbitrary range x variable:

>>> x = 150
>>> range_ = np.sin(np.linspace(0, 1, 10))
>>> Signal(range_, domain)[x]  
0.0359701...
>>> x = np.linspace(100, 1000, 3)
>>> Signal(range_, domain)[x]  
array([  ...,   4.7669395...e-01,   8.4147098...e-01])

Using an alternative interpolating function:

>>> x = 150
>>> from colour.algebra import CubicSplineInterpolator
>>> Signal(
...     range_,
...     domain,
...     interpolator=CubicSplineInterpolator)[x]  
0.0555274...
>>> x = np.linspace(100, 1000, 3)
>>> Signal(
...     range_,
...     domain,
...     interpolator=CubicSplineInterpolator)[x]  
array([ 0.        ,  0.4794253...,  0.8414709...])
__init__(data=None, domain=None, **kwargs)[source]

Methods

__init__([data, domain])
arithmetical_operation(a, operation[, in_place]) Performs given arithmetical operation with \(a\) operand, the operation can be either performed on a copy or in-place.
copy() Returns a copy of the sub-class instance, must be reimplemented by sub-classes.
domain_distance(a) Returns the euclidean distance between given array and independent domain \(x\) closest element.
fill_nan([method, default]) Fill NaNs in independent domain \(x\) variable and corresponding range \(y\) variable using given method.
is_uniform() Returns if independent domain \(x\) variable is uniform.
signal_unpack_data([data, domain, dtype]) Unpack given data for continuous signal instantiation.
to_series() Converts the continuous signal to a Pandas Series class instance.