jicbioimage.core.util.array

Module containing utility functions for manipulating numpy arrays.

jicbioimage.core.util.array.check_dtype(array, allowed)[source]

Raises TypeError if the array is not of an allowed dtype.

Parameters:
  • array – array whose dtype is to be checked
  • allowed – instance or list of allowed dtypes
Raises:

TypeError

jicbioimage.core.util.array.color_array(array, color_dict)[source]

Return RGB color array.

Assigning a unique RGB color value to each unique element of the input array and return an array of shape (array.shape, 3).

Parameters:
  • array – input numpy.array
  • color_dict – dictionary with keys/values corresponding to identifiers and RGB tuples respectively
jicbioimage.core.util.array.dtype_contract(input_dtype=None, output_dtype=None)[source]

Function decorator for specifying input and/or output array dtypes.

Parameters:
  • input_dtype – dtype of input array
  • output_dtype – dtype of output array
Returns:

function decorator

jicbioimage.core.util.array.map_stack(array3D, z_function)[source]

Return 3D array where each z-slice has had the function applied to it.

Parameters:
  • array3D – 3D numpy.array
  • z_function – function to be mapped to each z-slice
jicbioimage.core.util.array.normalise(array)[source]

Return array normalised such that all values are between 0 and 1.

If all the values in the array are the same the function will return: - np.zeros(array.shape, dtype=np.float) if the value is 0 or less - np.ones(array.shape, dtype=np.float) if the value is greater than 0

Parameters:array – numpy.array
Returns:numpy.array.astype(numpy.float)
jicbioimage.core.util.array.pretty_color_array(array, keep_zero_black=True)[source]

Return a RGB pretty color array.

Assigning a pretty RGB color value to each unique element of the input array and return an array of shape (array.shape, 3).

Parameters:
  • array – input numpy.array
  • keep_zero_black – whether or not the background should be black
Returns:

numpy.array

jicbioimage.core.util.array.reduce_stack(array3D, z_function)[source]

Return 2D array projection of the input 3D array.

The input function is applied to each line of an input x, y value.

Parameters:
  • array3D – 3D numpy.array
  • z_function – function to use for the projection (e.g. max())
jicbioimage.core.util.array.unique_color_array(array)[source]

Return a RGB unique color array.

Assigning a unique RGB color value to each unique element of the input array and return an array of shape (array.shape, 3).

Parameters:array – input numpy.array
Returns:numpy.array