colour.continuous.MultiSignals

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

Bases: colour.continuous.abstract.AbstractContinuousFunction

Defines the base class for multi-continuous signals, a container for multiple colour.continuous.Signal sub-class instances.

Parameters
Other Parameters
  • name (unicode, optional) – multi-continuous signals 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 for the colour.continuous.Signal sub-class instances.

  • interpolator_kwargs (dict_like, optional) – Arguments to use when instantiating the interpolating function of the colour.continuous.Signal sub-class instances.

  • extrapolator (object, optional) – Extrapolator class type to use as extrapolating function for the colour.continuous.Signal sub-class instances.

  • extrapolator_kwargs (dict_like, optional) – Arguments to use when instantiating the extrapolating function of the colour.continuous.Signal sub-class instances.

  • signal_type (type, optional) – The colour.continuous.Signal sub-class type used for instances.

dtype
domain
range
interpolator
interpolator_kwargs
extrapolator
extrapolator_kwargs
function
signals
labels
signal_type
__str__()[source]
__repr__()[source]
__hash__()[source]
__getitem__()[source]
__setitem__()[source]
__contains__()[source]
__eq__()[source]
__ne__()[source]
arithmetical_operation()[source]
multi_signals_unpack_data()[source]
fill_nan()[source]
to_dataframe()[source]

Examples

Instantiation with implicit domain and a single signal:

>>> range_ = np.linspace(10, 100, 10)
>>> print(MultiSignals(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 and a single signal:

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

Instantiation with multiple signals:

>>> range_ = tstack([np.linspace(10, 100, 10)] * 3)
>>> range_ += np.array([0, 10, 20])
>>> print(MultiSignals(range_, domain))
[[  100.    10.    20.    30.]
 [  200.    20.    30.    40.]
 [  300.    30.    40.    50.]
 [  400.    40.    50.    60.]
 [  500.    50.    60.    70.]
 [  600.    60.    70.    80.]
 [  700.    70.    80.    90.]
 [  800.    80.    90.   100.]
 [  900.    90.   100.   110.]
 [ 1000.   100.   110.   120.]]

Instantiation with a dict:

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

Instantiation using a Signal sub-class:

>>> class NotSignal(Signal):
...     pass
>>> multi_signals = MultiSignals(range_, domain, signal_type=NotSignal)
>>> print(multi_signals)
[[  100.    10.    20.    30.]
 [  200.    20.    30.    40.]
 [  300.    30.    40.    50.]
 [  400.    40.    50.    60.]
 [  500.    50.    60.    70.]
 [  600.    60.    70.    80.]
 [  700.    70.    80.    90.]
 [  800.    80.    90.   100.]
 [  900.    90.   100.   110.]
 [ 1000.   100.   110.   120.]]
 >>> type(multi_signals.signals[0])  
 <class 'multi_signals.NotSignal'>

Instantiation with a Pandas Series:

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

Instantiation with a Pandas Dataframe:

>>> if is_pandas_installed():
...     from pandas import DataFrame
...     data = dict(zip(['a', 'b', 'c'], tsplit(range_)))
...     print(MultiSignals(  
...         DataFrame(data, domain)))
[[  100.    10.    20.    30.]
 [  200.    20.    30.    40.]
 [  300.    30.    40.    50.]
 [  400.    40.    50.    60.]
 [  500.    50.    60.    70.]
 [  600.    60.    70.    80.]
 [  700.    70.    80.    90.]
 [  800.    80.    90.   100.]
 [  900.    90.   100.   110.]
 [ 1000.   100.   110.   120.]]

Retrieving domain y variable for arbitrary range x variable:

>>> x = 150
>>> range_ = tstack([np.sin(np.linspace(0, 1, 10))] * 3)
>>> range_ += np.array([0.0, 0.25, 0.5])
>>> MultiSignals(range_, domain)[x]  
array([ 0.0359701...,  0.2845447...,  0.5331193...])
>>> x = np.linspace(100, 1000, 3)
>>> MultiSignals(range_, domain)[x]  
array([[  4.4085384...e-20,   2.5000000...e-01,   5.0000000...e-01],
       [  4.7669395...e-01,   7.2526859...e-01,   9.7384323...e-01],
       [  8.4147098...e-01,   1.0914709...e+00,   1.3414709...e+00]])

Using an alternative interpolating function:

>>> x = 150
>>> from colour.algebra import CubicSplineInterpolator
>>> MultiSignals(
...     range_,
...     domain,
...     interpolator=CubicSplineInterpolator)[x]  
array([ 0.0555274...,  0.3055274...,  0.5555274...])
>>> x = np.linspace(100, 1000, 3)
>>> MultiSignals(
...     range_,
...     domain,
...     interpolator=CubicSplineInterpolator)[x]  
array([[ 0.       ...,  0.25     ...,  0.5      ...],
       [ 0.4794253...,  0.7294253...,  0.9794253...],
       [ 0.8414709...,  1.0914709...,  1.3414709...]])
arithmetical_operation(a, operation, in_place=False)[source]

Performs given arithmetical operation with \(a\) operand, the operation can be either performed on a copy or in-place.

Parameters
  • a (numeric or ndarray or Signal) – Operand.

  • operation (object) – Operation to perform.

  • in_place (bool, optional) – Operation happens in place.

Returns

multi-continuous signals.

Return type

MultiSignals

Examples

Adding a single numeric variable:

>>> domain = np.arange(0, 10, 1)
>>> range_ = tstack([np.linspace(10, 100, 10)] * 3)
>>> range_ += np.array([0, 10, 20])
>>> multi_signals_1 = MultiSignals(range_)
>>> print(multi_signals_1)
[[   0.   10.   20.   30.]
 [   1.   20.   30.   40.]
 [   2.   30.   40.   50.]
 [   3.   40.   50.   60.]
 [   4.   50.   60.   70.]
 [   5.   60.   70.   80.]
 [   6.   70.   80.   90.]
 [   7.   80.   90.  100.]
 [   8.   90.  100.  110.]
 [   9.  100.  110.  120.]]
>>> print(multi_signals_1.arithmetical_operation(10, '+', True))
[[   0.   20.   30.   40.]
 [   1.   30.   40.   50.]
 [   2.   40.   50.   60.]
 [   3.   50.   60.   70.]
 [   4.   60.   70.   80.]
 [   5.   70.   80.   90.]
 [   6.   80.   90.  100.]
 [   7.   90.  100.  110.]
 [   8.  100.  110.  120.]
 [   9.  110.  120.  130.]]

Adding an array_like variable:

>>> a = np.linspace(10, 100, 10)
>>> print(multi_signals_1.arithmetical_operation(a, '+', True))
[[   0.   30.   40.   50.]
 [   1.   50.   60.   70.]
 [   2.   70.   80.   90.]
 [   3.   90.  100.  110.]
 [   4.  110.  120.  130.]
 [   5.  130.  140.  150.]
 [   6.  150.  160.  170.]
 [   7.  170.  180.  190.]
 [   8.  190.  200.  210.]
 [   9.  210.  220.  230.]]
>>> a = np.array([[10, 20, 30]])
>>> print(multi_signals_1.arithmetical_operation(a, '+', True))
[[   0.   40.   60.   80.]
 [   1.   60.   80.  100.]
 [   2.   80.  100.  120.]
 [   3.  100.  120.  140.]
 [   4.  120.  140.  160.]
 [   5.  140.  160.  180.]
 [   6.  160.  180.  200.]
 [   7.  180.  200.  220.]
 [   8.  200.  220.  240.]
 [   9.  220.  240.  260.]]
>>> a = np.arange(0, 30, 1).reshape([10, 3])
>>> print(multi_signals_1.arithmetical_operation(a, '+', True))
[[   0.   40.   61.   82.]
 [   1.   63.   84.  105.]
 [   2.   86.  107.  128.]
 [   3.  109.  130.  151.]
 [   4.  132.  153.  174.]
 [   5.  155.  176.  197.]
 [   6.  178.  199.  220.]
 [   7.  201.  222.  243.]
 [   8.  224.  245.  266.]
 [   9.  247.  268.  289.]]

Adding a colour.continuous.Signal sub-class:

>>> multi_signals_2 = MultiSignals(range_)
>>> print(multi_signals_1.arithmetical_operation(
...     multi_signals_2, '+', True))
[[   0.   50.   81.  112.]
 [   1.   83.  114.  145.]
 [   2.  116.  147.  178.]
 [   3.  149.  180.  211.]
 [   4.  182.  213.  244.]
 [   5.  215.  246.  277.]
 [   6.  248.  279.  310.]
 [   7.  281.  312.  343.]
 [   8.  314.  345.  376.]
 [   9.  347.  378.  409.]]
property domain

Getter and setter property for the colour.continuous.Signal sub-class instances independent domain \(x\) variable.

Parameters

value (array_like) – Value to set the colour.continuous.Signal sub-class instances independent domain \(x\) variable with.

Returns

colour.continuous.Signal sub-class instances independent domain \(x\) variable.

Return type

ndarray

property dtype

Getter and setter property for the continuous signal dtype.

Parameters

value (type) – Value to set the continuous signal dtype with.

Returns

Continuous signal dtype.

Return type

type

property extrapolator

Getter and setter property for the colour.continuous.Signal sub-class instances extrapolator type.

Parameters

value (type) – Value to set the colour.continuous.Signal sub-class instances extrapolator type with.

Returns

colour.continuous.Signal sub-class instances extrapolator type.

Return type

type

property extrapolator_kwargs

Getter and setter property for the colour.continuous.Signal sub-class instances extrapolator instantiation time arguments.

Parameters

value (dict) – Value to set the colour.continuous.Signal sub-class instances extrapolator instantiation time arguments to.

Returns

colour.continuous.Signal sub-class instances extrapolator instantiation time arguments.

Return type

dict

fill_nan(method='Interpolation', default=0)[source]

Fill NaNs in independent domain \(x\) variable and corresponding range \(y\) variable using given method.

Parameters
  • method (unicode, optional) – {‘Interpolation’, ‘Constant’}, Interpolation method linearly interpolates through the NaNs, Constant method replaces NaNs with default.

  • default (numeric, optional) – Value to use with the Constant method.

Returns

  • Signal – NaNs filled multi-continuous signals.

  • >>> domain = np.arange(0, 10, 1)

  • >>> range_ = tstack([np.linspace(10, 100, 10)] * 3)

  • >>> range_ += np.array([0, 10, 20])

  • >>> multi_signals = MultiSignals(range_)

  • >>> multi_signals[3 (7] = np.nan)

  • >>> print(multi_signals)

  • [[ 0. 10. 20. 30.] – [ 1. 20. 30. 40.] [ 2. 30. 40. 50.] [ 3. nan nan nan] [ 4. nan nan nan] [ 5. nan nan nan] [ 6. nan nan nan] [ 7. 80. 90. 100.] [ 8. 90. 100. 110.] [ 9. 100. 110. 120.]]

  • >>> print(multi_signals.fill_nan())

  • [[ 0. 10. 20. 30.] – [ 1. 20. 30. 40.] [ 2. 30. 40. 50.] [ 3. 40. 50. 60.] [ 4. 50. 60. 70.] [ 5. 60. 70. 80.] [ 6. 70. 80. 90.] [ 7. 80. 90. 100.] [ 8. 90. 100. 110.] [ 9. 100. 110. 120.]]

  • >>> multi_signals[3 (7] = np.nan)

  • >>> print(multi_signals.fill_nan(method=’Constant’))

  • [[ 0. 10. 20. 30.] – [ 1. 20. 30. 40.] [ 2. 30. 40. 50.] [ 3. 0. 0. 0.] [ 4. 0. 0. 0.] [ 5. 0. 0. 0.] [ 6. 0. 0. 0.] [ 7. 80. 90. 100.] [ 8. 90. 100. 110.] [ 9. 100. 110. 120.]]

property function

Getter and setter property for the colour.continuous.Signal sub-class instances callable.

Parameters

value (object) – Attribute value.

Returns

colour.continuous.Signal sub-class instances callable.

Return type

callable

Notes

  • This property is read only.

property interpolator

Getter and setter property for the colour.continuous.Signal sub-class instances interpolator type.

Parameters

value (type) – Value to set the colour.continuous.Signal sub-class instances interpolator type with.

Returns

colour.continuous.Signal sub-class instances interpolator type.

Return type

type

property interpolator_kwargs

Getter and setter property for the colour.continuous.Signal sub-class instances interpolator instantiation time arguments.

Parameters

value (dict) – Value to set the colour.continuous.Signal sub-class instances interpolator instantiation time arguments to.

Returns

colour.continuous.Signal sub-class instances interpolator instantiation time arguments.

Return type

dict

property labels

Getter and setter property for the colour.continuous.Signal sub-class instances name.

Parameters

value (array_like) – Value to set the colour.continuous.Signal sub-class instances name.

Returns

colour.continuous.Signal sub-class instance name.

Return type

dict

static multi_signals_unpack_data(data=None, domain=None, labels=None, dtype=<class 'numpy.float64'>, signal_type=<class 'colour.continuous.signal.Signal'>, **kwargs)[source]

Unpack given data for multi-continuous signals instantiation.

Parameters
Other Parameters
  • name (unicode, optional) – multi-continuous signals name.

  • interpolator (object, optional) – Interpolator class type to use as interpolating function for the colour.continuous.Signal sub-class instances.

  • interpolator_kwargs (dict_like, optional) – Arguments to use when instantiating the interpolating function of the colour.continuous.Signal sub-class instances.

  • extrapolator (object, optional) – Extrapolator class type to use as extrapolating function for the colour.continuous.Signal sub-class instances.

  • extrapolator_kwargs (dict_like, optional) – Arguments to use when instantiating the extrapolating function of the colour.continuous.Signal sub-class instances.

Returns

Mapping of labeled colour.continuous.Signal sub-class instances.

Return type

dict

Examples

Unpacking using implicit domain and a single signal:

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

Unpacking using explicit domain and a single signal:

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

Unpacking using multiple signals:

>>> range_ = tstack([np.linspace(10, 100, 10)] * 3)
>>> range_ += np.array([0, 10, 20])
>>> signals = MultiSignals.multi_signals_unpack_data(range_, domain)
>>> list(signals.keys())
[0, 1, 2]
>>> print(signals[2])
[[  100.    30.]
 [  200.    40.]
 [  300.    50.]
 [  400.    60.]
 [  500.    70.]
 [  600.    80.]
 [  700.    90.]
 [  800.   100.]
 [  900.   110.]
 [ 1000.   120.]]

Unpacking using a dict:

>>> signals = MultiSignals.multi_signals_unpack_data(
...     dict(zip(domain, range_)))
>>> list(signals.keys())
[0, 1, 2]
>>> print(signals[2])
[[  100.    30.]
 [  200.    40.]
 [  300.    50.]
 [  400.    60.]
 [  500.    70.]
 [  600.    80.]
 [  700.    90.]
 [  800.   100.]
 [  900.   110.]
 [ 1000.   120.]]

Unpacking using MultiSignals.multi_signals_unpack_data method output:

>>> signals = MultiSignals.multi_signals_unpack_data(
...     dict(zip(domain, range_)))
>>> signals = MultiSignals.multi_signals_unpack_data(signals)
>>> list(signals.keys())
[0, 1, 2]
>>> print(signals[2])
[[  100.    30.]
 [  200.    40.]
 [  300.    50.]
 [  400.    60.]
 [  500.    70.]
 [  600.    80.]
 [  700.    90.]
 [  800.   100.]
 [  900.   110.]
 [ 1000.   120.]]

Unpacking using a Pandas Series:

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

Unpacking using a Pandas Dataframe:

>>> if is_pandas_installed():
...     from pandas import DataFrame
...     data = dict(zip(['a', 'b', 'c'], tsplit(range_)))
...     signals = MultiSignals.multi_signals_unpack_data(
...         DataFrame(data, domain))
...     print(signals['c'])  
[[  100.    30.]
 [  200.    40.]
 [  300.    50.]
 [  400.    60.]
 [  500.    70.]
 [  600.    80.]
 [  700.    90.]
 [  800.   100.]
 [  900.   110.]
 [ 1000.   120.]]
property range

Getter and setter property for the colour.continuous.Signal sub-class instances corresponding range \(y\) variable.

Parameters

value (array_like) – Value to set the colour.continuous.Signal sub-class instances corresponding range \(y\) variable with.

Returns

colour.continuous.Signal sub-class instances corresponding range \(y\) variable.

Return type

ndarray

property signal_type

Getter and setter property for the colour.continuous.Signal sub-class instances type.

Returns

colour.continuous.Signal sub-class instances type.

Return type

type

Notes

  • This property is read only.

property signals

Getter and setter property for the colour.continuous.Signal sub-class instances.

Parameters

value (Series or Dataframe or Signal or MultiSignals or array_like or dict_like) – Attribute value.

Returns

colour.continuous.Signal sub-class instances.

Return type

OrderedDict

to_dataframe()[source]

Converts the continuous signal to a Pandas DataFrame class instance.

Returns

Continuous signal as a Pandas DataFrame class instance.

Return type

DataFrame

Examples

>>> if is_pandas_installed():
...     domain = np.arange(0, 10, 1)
...     range_ = tstack([np.linspace(10, 100, 10)] * 3)
...     range_ += np.array([0, 10, 20])
...     multi_signals = MultiSignals(range_)
...     print(multi_signals.to_dataframe())  
         0      1      2
0.0   10.0   20.0   30.0
1.0   20.0   30.0   40.0
2.0   30.0   40.0   50.0
3.0   40.0   50.0   60.0
4.0   50.0   60.0   70.0
5.0   60.0   70.0   80.0
6.0   70.0   80.0   90.0
7.0   80.0   90.0  100.0
8.0   90.0  100.0  110.0
9.0  100.0  110.0  120.0