rsatoolbox.util.descriptor_utils module

Descriptor handling. Note: descriptor is assumed to be a list, to accommodate objects that don’t fit well into strings, such as arrays of varying sizes. Some of these methods may convert numpy-array descriptors to list-types.

@author: adkipnis

rsatoolbox.util.descriptor_utils.append_descriptor(descriptor, desc_new)[source]

appends a descriptor to an existing one

Parameters:
  • descriptor (dict) – the descriptor dictionary, with list-like values

  • desc_new (dict) – the descriptor dictionary to append

Returns:

the longer descriptor

Return type:

descriptor(dict)

rsatoolbox.util.descriptor_utils.bool_index(descriptor, value)[source]

creates a boolean index vector where a descriptor has a value

Parameters:
  • descriptor (list-like) – descriptor vector

  • value – value or list of values to mark

Returns:

bool_index: boolean index vector where descriptor == value

Return type:

numpy.ndarray

rsatoolbox.util.descriptor_utils.check_descriptor_length(descriptor, n_element)[source]

Checks whether the entries of a descriptor dictionary have the right length. Converts single-strings to a list of 1 element.

Parameters:
  • descriptor (dict) – the descriptor dictionary

  • n_element – the correct length of the descriptors

Returns:

bool

rsatoolbox.util.descriptor_utils.check_descriptor_length_error(descriptor, name, n_element)[source]

Raises an error if the given descriptor does not have the right length

Parameters:
  • descriptor (dict/None) – the descriptor dictionary

  • name (String) – Descriptor name used for error message

  • n_element – the desired descriptor length

Returns:

rsatoolbox.util.descriptor_utils.desc_eq(a: DescriptorDict, b: DescriptorDict) bool[source]

Whether the two descriptor-style dictionaries are equal

Parameters:
  • a (dict) – Dictionary with list or array values

  • b (dict) – Dictionary with list or array values

Returns:

True if the two dictionaries have the same keys and values

Return type:

bool

rsatoolbox.util.descriptor_utils.dict_to_list(d_dict)[source]

converts a dictionary from a hdf5 file to a list

rsatoolbox.util.descriptor_utils.format_descriptor(descriptors)[source]

formats a descriptor dictionary

Parameters:

descriptors (dict) – the descriptor dictionary

Returns:

formatted string to show dict

Return type:

String

rsatoolbox.util.descriptor_utils.num_index(descriptor, value)[source]

creates a boolean index vector where a descriptor has a value

Parameters:
  • descriptor (list-like) – descriptor vector

  • value – value or list of values to mark

Returns:

bool_index: boolean index vector where descriptor == value

Return type:

numpy.ndarray

rsatoolbox.util.descriptor_utils.parse_input_descriptor(descriptors)[source]

parse input descriptor checks whether an input descriptors dictionary is a dictionary. If it is None instead it is replaced by an empty dict. Otherwise an error is raised.

Parameters:

descriptors (dict/None) – the descriptor dictionary

Returns:

descriptor dictionary

Return type:

dict

rsatoolbox.util.descriptor_utils.subset_descriptor(descriptor, indices)[source]

Retrieves a subset of a descriptor given by indices.

Parameters:
  • descriptor (dict) – the descriptor dictionary

  • indices – the indices to be extracted

Returns:

the selected subset of the descriptor

Return type:

extracted_descriptor(dict)