colour.continuous.Signal¶
-
class
colour.continuous.
Signal
(data=None, domain=None, **kwargs)[source]¶ Bases:
colour.continuous.abstract.AbstractContinuousFunction
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 thecolour.continuous.Signal.domain
attribute corresponds with the function dependent and already known range stored in thecolour.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 bothdata
anddomain
arguments are defined, the latter with be used to initialise thecolour.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
¶
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...])
-
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
- Returns
Continuous signal.
- Return type
Examples
Adding a single numeric variable:
>>> range_ = np.linspace(10, 100, 10) >>> signal_1 = Signal(range_) >>> print(signal_1) [[ 0. 10.] [ 1. 20.] [ 2. 30.] [ 3. 40.] [ 4. 50.] [ 5. 60.] [ 6. 70.] [ 7. 80.] [ 8. 90.] [ 9. 100.]] >>> print(signal_1.arithmetical_operation(10, '+', True)) [[ 0. 20.] [ 1. 30.] [ 2. 40.] [ 3. 50.] [ 4. 60.] [ 5. 70.] [ 6. 80.] [ 7. 90.] [ 8. 100.] [ 9. 110.]]
Adding an array_like variable:
>>> a = np.linspace(10, 100, 10) >>> print(signal_1.arithmetical_operation(a, '+', True)) [[ 0. 30.] [ 1. 50.] [ 2. 70.] [ 3. 90.] [ 4. 110.] [ 5. 130.] [ 6. 150.] [ 7. 170.] [ 8. 190.] [ 9. 210.]]
Adding a
colour.continuous.Signal
class:>>> signal_2 = Signal(range_) >>> print(signal_1.arithmetical_operation(signal_2, '+', True)) [[ 0. 40.] [ 1. 70.] [ 2. 100.] [ 3. 130.] [ 4. 160.] [ 5. 190.] [ 6. 220.] [ 7. 250.] [ 8. 280.] [ 9. 310.]]
-
property
domain
Getter and setter property for the continuous signal independent domain \(x\) variable.
- Parameters
value (array_like) – Value to set the continuous signal independent domain \(x\) variable with.
- Returns
Continuous signal independent domain \(x\) variable.
- Return type
ndarray
-
property
dtype
Getter and setter property for the continuous signal dtype.
-
property
extrapolator
Getter and setter property for the continuous signal extrapolator type.
-
property
extrapolator_args
Getter and setter property for the continuous signal extrapolator instantiation time arguments.
-
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
NaNs filled continuous signal.
- Return type
Examples
>>> range_ = np.linspace(10, 100, 10) >>> signal = Signal(range_) >>> signal[3:7] = np.nan >>> print(signal) [[ 0. 10.] [ 1. 20.] [ 2. 30.] [ 3. nan] [ 4. nan] [ 5. nan] [ 6. nan] [ 7. 80.] [ 8. 90.] [ 9. 100.]] >>> print(signal.fill_nan()) [[ 0. 10.] [ 1. 20.] [ 2. 30.] [ 3. 40.] [ 4. 50.] [ 5. 60.] [ 6. 70.] [ 7. 80.] [ 8. 90.] [ 9. 100.]] >>> signal[3:7] = np.nan >>> print(signal.fill_nan(method='Constant')) [[ 0. 10.] [ 1. 20.] [ 2. 30.] [ 3. 0.] [ 4. 0.] [ 5. 0.] [ 6. 0.] [ 7. 80.] [ 8. 90.] [ 9. 100.]]
-
property
function
Getter and setter property for the continuous signal callable.
- Parameters
value (object) – Attribute value.
- Returns
Continuous signal callable.
- Return type
callable
Notes
This property is read only.
-
property
interpolator
Getter and setter property for the continuous signal interpolator type.
-
property
interpolator_args
Getter and setter property for the continuous signal interpolator instantiation time arguments.
-
property
range
Getter and setter property for the continuous signal corresponding range \(y\) variable.
- Parameters
value (array_like) – Value to set the continuous signal corresponding range \(y\) variable with.
- Returns
Continuous signal corresponding range \(y\) variable.
- Return type
ndarray
-
static
signal_unpack_data
(data=None, domain=None, dtype=<class 'numpy.float64'>)[source] Unpack given data for continuous signal instantiation.
- Parameters
data (Series or Signal or array_like or dict_like, optional) – Data to unpack for continuous signal instantiation.
domain (array_like, optional) – Values to initialise the
colour.continuous.Signal.domain
attribute with. If bothdata
anddomain
arguments are defined, the latter will be used to initialise thecolour.continuous.Signal.domain
attribute.dtype (type, optional) – {np.float16, np.float32, np.float64, np.float128}, Floating point data type.
- Returns
Independent domain \(x\) variable and corresponding range \(y\) variable unpacked for continuous signal instantiation.
- Return type
Examples
Unpacking using implicit domain:
>>> range_ = np.linspace(10, 100, 10) >>> domain, range_ = Signal.signal_unpack_data(range_) >>> print(domain) [ 0. 1. 2. 3. 4. 5. 6. 7. 8. 9.] >>> print(range_) [ 10. 20. 30. 40. 50. 60. 70. 80. 90. 100.]
Unpacking using explicit domain:
>>> domain = np.arange(100, 1100, 100) >>> domain, range = Signal.signal_unpack_data(range_, domain) >>> print(domain) [ 100. 200. 300. 400. 500. 600. 700. 800. 900. 1000.] >>> print(range_) [ 10. 20. 30. 40. 50. 60. 70. 80. 90. 100.]
Unpacking using a dict:
>>> domain, range_ = Signal.signal_unpack_data( ... dict(zip(domain, range_))) >>> print(domain) [ 100. 200. 300. 400. 500. 600. 700. 800. 900. 1000.] >>> print(range_) [ 10. 20. 30. 40. 50. 60. 70. 80. 90. 100.]
Unpacking using a Pandas Series:
>>> if is_pandas_installed(): ... from pandas import Series ... domain, range = Signal.signal_unpack_data( ... Series(dict(zip(domain, range_)))) ... >>> print(domain) [ 100. 200. 300. 400. 500. 600. 700. 800. 900. 1000.] >>> print(range_) [ 10. 20. 30. 40. 50. 60. 70. 80. 90. 100.]
Unpacking using a
colour.continuous.Signal
class:>>> domain, range_ = Signal.signal_unpack_data( ... Signal(range_, domain)) >>> print(domain) [ 100. 200. 300. 400. 500. 600. 700. 800. 900. 1000.] >>> print(range_) [ 10. 20. 30. 40. 50. 60. 70. 80. 90. 100.]
-
to_series
()[source] Converts the continuous signal to a Pandas
Series
class instance.- Returns
Continuous signal as a Pandas
Series
class instance.- Return type
Series
Examples
>>> if is_pandas_installed(): ... range_ = np.linspace(10, 100, 10) ... signal = Signal(range_) ... print(signal.to_series()) 0.0 10.0 1.0 20.0 2.0 30.0 3.0 40.0 4.0 50.0 5.0 60.0 6.0 70.0 7.0 80.0 8.0 90.0 9.0 100.0 Name: Signal (...), dtype: float64