colour.algebra.common Module

Algebra Common Utilities

Defines algebra common utilities objects that don’t belong to any algebra specific category.

colour.algebra.common.INTEGER_THRESHOLD = 0.001

Integer threshold value.

INTEGER_THRESHOLD : numeric

colour.algebra.common.steps(distribution)[source]

Returns the steps of given distribution.

Parameters:distribution (array_like) – Distribution to retrieve the steps.
Returns:Distribution steps.
Return type:tuple

Examples

Uniformly spaced variable:

>>> y = np.array([1, 2, 3, 4, 5])
>>> steps(y)
(1,)

Non-uniformly spaced variable:

>>> y = np.array([1, 2, 3, 4, 8])
>>> steps(y)
(1, 4)
colour.algebra.common.closest(y, x)[source]

Returns closest \(y\) variable element to reference \(x\) variable.

Parameters:
  • y (array_like) – Variable to search for the closest element.
  • x (numeric) – Reference variable.
Returns:

Closest \(y\) variable element.

Return type:

numeric

Examples

>>> y = np.array([24.31357115, 63.62396289, 55.71528816, 62.70988028, 46.84480573, 25.40026416])  
>>> closest(y, 63)
62.70988028
colour.algebra.common.as_array(x, shape=None, data_type=<type 'numpy.float64'>)[source]

Converts given \(x\) variable to ndarray.

Parameters:
  • x (object) – Variable to convert.
  • shape (tuple, optional) – ndarray shape.
  • data_type (dtype, optional) – ndarray data type.
Returns:

\(x\) variable converted to ndarray.

Return type:

ndarray

Examples

>>> as_array(1)
array([ 1.])
colour.algebra.common.is_uniform(distribution)[source]

Returns if given distribution is uniform.

Parameters:distribution (array_like) – Distribution to check for uniformity.
Returns:Is distribution uniform.
Return type:bool

Examples

Uniformly spaced variable:

>>> y = np.array([1, 2, 3, 4, 5])
>>> is_uniform(y)
True

Non-uniformly spaced variable:

>>> y = np.array([1, 2, 3.1415, 4, 5])
>>> is_uniform(y)
False
colour.algebra.common.is_iterable(x)[source]

Returns if given \(x\) variable is iterable.

Parameters:x (object) – Variable to check the iterability.
Returns:\(x\) variable iterability.
Return type:bool

Examples

>>> is_iterable([1, 2, 3])
True
>>> is_iterable(1)
False
colour.algebra.common.is_numeric(x)[source]

Returns if given \(x\) variable is a number.

Parameters:x (object) – Variable to check.
Returns:Is \(x\) variable a number.
Return type:bool

See also

is_integer()

Examples

>>> is_numeric(1)
True
>>> is_numeric((1,))
False
colour.algebra.common.is_integer(x)[source]

Returns if given \(x\) variable is an integer under given threshold.

Parameters:x (object) – Variable to check.
Returns:Is \(x\) variable an integer.
Return type:bool

Notes

See also

is_numeric()

Examples

>>> is_integer(1)
True
>>> is_integer(1.01)
False
colour.algebra.common.normalise(x, factor=1, clip=True)[source]

Normalises given array_like \(x\) variable values and optionally clip them between.

Parameters:
  • x (array_like) – \(x\) variable to normalise.
  • factor (numeric, optional) – Normalization factor
  • clip (bool, optional) – Clip values between in domain [0, ‘factor’].
Returns:

Normalised \(x\) variable.

Return type:

ndarray

Examples

>>> x = np.array([0.48224885, 0.31651974, 0.22070513])
>>> normalise(x)  
array([ 1.        ,  0.6563411...,  0.4576581...])