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.

Other Parameters:
 **kwargs (dict, optional) – Keywords arguments.
Returns:
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)

Wrapper for given function.

colour.utilities.common.raise_numpy_errors(function)

Wrapper for given function.

colour.utilities.common.print_numpy_errors(function)

Wrapper for given function.

colour.utilities.common.warn_numpy_errors(function)

Wrapper for given function.

colour.utilities.common.ignore_python_warnings(function)[source]

Decorator for ignoring Python warnings.

Parameters:function (object) – Function to decorate.
Returns:
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_iterable(a)[source]

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

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

Examples

>>> is_iterable([1, 2, 3])
True
>>> is_iterable(1)
False
colour.utilities.common.is_string(a)[source]

Returns if given \(a\) variable is a string like variable.

Parameters:a (object) – Data to test.
Returns:Is \(a\) variable a 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(a)[source]

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

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

See also

is_integer()

Examples

>>> is_numeric(1)
True
>>> is_numeric((1,))
False
colour.utilities.common.is_integer(a)[source]

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

Parameters:a (object) – Variable to check.
Returns:Is \(a\) 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
colour.utilities.common.filter_kwargs(function, **kwargs)[source]

Filters keyword arguments incompatible with the given function signature.

Parameters:function (callable) – Callable to filter the incompatible keyword arguments.
Other Parameters:
 **kwargs (dict, optional) – Keywords arguments.
Returns:Filtered keyword arguments.
Return type:dict

Examples

>>> def fn_a(a):
...     return a
>>> def fn_b(a, b=0):
...     return a, b
>>> def fn_c(a, b=0, c=0):
...     return a, b, c
>>> fn_a(1, **filter_kwargs(fn_a, b=2, c=3))
1
>>> fn_b(1, **filter_kwargs(fn_b, b=2, c=3))
(1, 2)
>>> fn_c(1, **filter_kwargs(fn_c, b=2, c=3))
(1, 2, 3)