colour.utilities.common Module

Common Utilities

Defines common utilities objects that don’t fall in any specific category.

colour.utilities.common.handle_numpy_errors(**kwargs)[source]

Decorator for handling Numpy errors.

Parameters:**kwargs (**) – Keywords arguments.
Return type:object

References

[1]Kienzle, P., Patel, N., & Krycka, J. (2011). refl1d.numpyerrors - Refl1D v0.6.19 documentation. Retrieved January 30, 2015, from http://www.reflectometry.org/danse/docs/refl1d/_modules/refl1d/numpyerrors.html

Examples

>>> import numpy
>>> @handle_numpy_errors(all='ignore')
... def f():
...     1 / numpy.zeros(3)
>>> f()
colour.utilities.common.ignore_numpy_errors(function)
colour.utilities.common.raise_numpy_errors(function)
colour.utilities.common.print_numpy_errors(function)
colour.utilities.common.warn_numpy_errors(function)
colour.utilities.common.ignore_python_warnings(function)[source]

Decorator for ignoring Python warnings.

Parameters:function (object) – Object to decorate.
Return type:object

Examples

>>> @ignore_python_warnings
... def f():
...     warnings.warn('This is an ignored warning!')
>>> f()
colour.utilities.common.batch(iterable, k=3)[source]

Returns a batch generator from given iterable.

Parameters:
  • iterable (iterable) – Iterable to create batches from.
  • k (integer) – Batches size.
Returns:

Is string_like variable.

Return type:

bool

Examples

>>> batch(tuple(range(10)))  
<generator object batch at 0x...>
colour.utilities.common.is_openimageio_installed(raise_exception=False)[source]

Returns if OpenImageIO is installed and available.

Parameters:raise_exception (bool) – Raise exception if OpenImageIO is unavailable.
Returns:Is OpenImageIO installed.
Return type:bool
Raises:ImportError – If OpenImageIO is not installed.
colour.utilities.common.is_scipy_installed(raise_exception=False)[source]

Returns if scipy is installed and available.

Parameters:raise_exception (bool) – Raise exception if scipy is unavailable.
Returns:Is scipy installed.
Return type:bool
Raises:ImportError – If scipy is not installed.
colour.utilities.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.utilities.common.is_string(data)[source]

Returns if given data is a string_like variable.

Parameters:data (object) – Data to test.
Returns:Is string_like variable.
Return type:bool

Examples

>>> is_string('I`m a string!')
True
>>> is_string(['I`m a string!'])
False
colour.utilities.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.utilities.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

  • The determination threshold is defined by the colour.algebra.common.INTEGER_THRESHOLD attribute.

See also

is_numeric()

Examples

>>> is_integer(1)
True
>>> is_integer(1.01)
False