Utilities

Common

colour

domain_range_scale(scale)

A context manager and decorator temporarily setting Colour domain-range scale.

get_domain_range_scale()

Returns the current Colour domain-range scale.

set_domain_range_scale([scale])

Sets the current Colour domain-range scale.

colour.utilities

handle_numpy_errors(**kwargs)

Decorator for handling Numpy errors.

ignore_numpy_errors(function)

Wrapper for given function.

raise_numpy_errors(function)

Wrapper for given function.

print_numpy_errors(function)

Wrapper for given function.

warn_numpy_errors(function)

Wrapper for given function.

ignore_python_warnings(function)

Decorator for ignoring Python warnings.

batch(iterable[, k])

Returns a batch generator from given iterable.

disable_multiprocessing

A context manager and decorator temporarily disabling Colour multiprocessing.

multiprocessing_pool(*args, **kwargs)

A context manager providing a multiprocessing pool.

is_openimageio_installed([raise_exception])

Returns if OpenImageIO is installed and available.

is_pandas_installed([raise_exception])

Returns if Pandas is installed and available.

is_iterable(a)

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

is_string(a)

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

is_numeric(a)

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

is_integer(a)

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

is_sibling(element, mapping)

Returns whether given element type is present in given mapping types.

filter_kwargs(function, **kwargs)

Filters keyword arguments incompatible with the given function signature.

filter_mapping(mapping, filterers[, …])

Filters given mapping with given filterers.

first_item(a)

Return the first item of an iterable.

to_domain_1(a[, scale_factor, dtype])

Scales given array \(a\) to domain ‘1’.

to_domain_10(a[, scale_factor, dtype])

Scales given array \(a\) to domain ‘10’, used by Munsell Renotation System.

to_domain_100(a[, scale_factor, dtype])

Scales given array \(a\) to domain ‘100’.

to_domain_degrees(a[, scale_factor, dtype])

Scales given array \(a\) to degrees domain.

to_domain_int(a[, bit_depth, dtype])

Scales given array \(a\) to int domain.

from_range_1(a[, scale_factor])

Scales given array \(a\) from range ‘1’.

from_range_10(a[, scale_factor])

Scales given array \(a\) from range ‘10’, used by Munsell Renotation System.

from_range_100(a[, scale_factor])

Scales given array \(a\) from range ‘100’.

from_range_degrees(a[, scale_factor])

Scales given array \(a\) from degrees range.

from_range_int(a[, bit_depth, dtype])

Scales given array \(a\) from int range.

Array

colour.utilities

as_array(a[, dtype])

Converts given \(a\) variable to ndarray with given type.

as_int_array(a)

Converts given \(a\) variable to ndarray using the type defined by colour.constant.DEFAULT_INT_DTYPE attribute.

as_float_array(a)

Converts given \(a\) variable to ndarray using the type defined by colour.constant.DEFAULT_FLOAT_DTYPE attribute.

as_numeric(a[, dtype])

Converts given \(a\) variable to numeric.

as_int(a)

Converts given \(a\) variable to numeric using the type defined by colour.constant.DEFAULT_INT_DTYPE attribute.

as_float(a)

Converts given \(a\) variable to numeric using the type defined by colour.constant.DEFAULT_FLOAT_DTYPE attribute.

as_namedtuple(a, named_tuple)

Converts given \(a\) variable to given namedtuple class instance.

closest_indexes(a, b)

Returns the \(a\) variable closest element indexes to reference \(b\) variable elements.

closest(a, b)

Returns the \(a\) variable closest elements to reference \(b\) variable elements.

normalise_maximum(a[, axis, factor, clip])

Normalises given array_like \(a\) variable values by \(a\) variable maximum value and optionally clip them between.

interval(distribution[, unique])

Returns the interval size of given distribution.

is_uniform(distribution)

Returns if given distribution is uniform.

in_array(a, b[, tolerance])

Tests whether each element of an array is also present in a second array within given tolerance.

tstack(a[, dtype])

Stacks arrays in sequence along the last axis (tail).

tsplit(a[, dtype])

Splits arrays in sequence along the last axis (tail).

row_as_diagonal(a)

Returns the per row diagonal matrices of the given array.

dot_vector(m, v)

Convenient wrapper around np.einsum() with the following subscripts: ‘…ij,…j->…i’.

dot_matrix(a, b)

Convenient wrapper around np.einsum() with the following subscripts: ‘…ij,…jk->…ik’.

orient(a, orientation)

Orient given array according to given orientation value.

centroid(a)

Computes the centroid indexes of given \(a\) array.

linear_conversion(a, old_range, new_range)

Performs a simple linear conversion of given array between the old and new ranges.

lerp(a, b, c)

Performs a simple linear interpolation between given array \(a\) and array \(b\) using \(c\) value.

fill_nan(a[, method, default])

Fills given array NaNs according to given method.

ndarray_write(a)

A context manager setting given array writeable to perform an operation and then read-only.

Metrics

colour.utilities

metric_mse(a, b)

Computes the mean squared error (MSE) or mean squared deviation (MSD) between given array_like \(a\) and \(b\) variables.

metric_psnr(a, b[, max_a])

Computes the peak signal-to-noise ratio (PSNR) between given array_like \(a\) and \(b\) variables.

Data Structures

colour.utilities

CaseInsensitiveMapping([data])

Implements a case-insensitive mutable mapping / dict object.

Lookup

Extends dict type to provide a lookup by value(s).

Structure(*args, **kwargs)

Defines a dict-like object allowing to access key values using dot syntax.

Verbose

colour.utilities

message_box(message[, width, padding, …])

Prints a message inside a box.

warning(*args, **kwargs)

Issues a warning.

filter_warnings([state, colour_warnings, …])

Filters Colour and also optionally overall Python warnings.

suppress_warnings([colour_warnings, …])

A context manager filtering Colour and also optionally overall Python warnings.

numpy_print_options(*args, **kwargs)

A context manager implementing context changes to Numpy print behaviour.

describe_environment([runtime_packages, …])

Describes Colour running environment, i.e.

Ancillary Objects

colour.utilities

ColourWarning

This is the base class of Colour warnings.

ColourUsageWarning

This is the base class of Colour usage warnings.

ColourRuntimeWarning

This is the base class of Colour runtime warnings.