Utils

Submodules

mischbares.utils.orchestrator_utils module

A collection of functions for working with hdf5 files and generally with orchestrator data.

mischbares.utils.orchestrator_utils.dict_address(address, dict_keys)[source]

For a string of dict keys seperated by ‘/’, get the value of d under that series

Parameters
  • address (str) – address of value

  • dict_keys – dictionary to search

Returns

value at address

Return type

dict

mischbares.utils.orchestrator_utils.dict_address_set(address, dict_keys, val)[source]

For a string of dict keys seperated by ‘/’, set the value of dictionary d at that address to val

Parameters
  • address (str) – address of value

  • dict_keys (dict) – dictionary to search

  • val (int) – value to set

mischbares.utils.orchestrator_utils.hdf5_group_to_dict(h5file, path)[source]

Take a group from somewhere within an hdf5 file, convert it to a dict, and return it.

Parameters
  • h5file (str) – hdf5 file to read from

  • path (str) – path to group

Raises

ValueError – if the group is not a dictionary

Returns

dictionary of group

Return type

dict

mischbares.utils.orchestrator_utils.highest_name(names: list)[source]

Tke in a list of strings which differ only by an integer, and return the one for which that integer is highest

Parameters

names (list) – list of strings

Returns

highest name

Return type

str

mischbares.utils.orchestrator_utils.increment_name(name: str)[source]

Increment the number at the end of a string.

Parameters

name (str) – name of file

Returns

Incremented name of file

Return type

str

mischbares.utils.orchestrator_utils.paths_in_hdf5(h5path, paths)[source]

Check if the input path or list of paths are valid for the input hdf5 file.

Parameters
  • h5path (str) – path to hdf5 file

  • paths (str or list) – path or list of paths to check

Returns

True if path is in hdf5, False if not.

Return type

bool

mischbares.utils.orchestrator_utils.recursively_save_dict_contents_to_group(h5file, path, dict_keys)[source]

Save a dictionary to an hdf5 file.

Parameters
  • h5file (h5py._hl.files.File) – hdf5 file to save to

  • path (str) – path to save to

  • dict_keys (dict) – dictionary to save

mischbares.utils.orchestrator_utils.save_dict_to_hdf5(dict_keys, filename, path='/', mode='w')[source]

Save a dictionary to an hdf5 file.

Parameters
  • dict (dict) – dictionary to save

  • filename (str) – name of file

  • path (str, optional) – path where the hdf5 is saved. Defaults to ‘/’.

  • mode (str, optional) – mode to open the file. Defaults to ‘w’.

mischbares.utils.utils module

This module defines some utility functions for the MISCHBARES project.

mischbares.utils.utils.assemble_file_name(*args)[source]

Assemble a file name from the given arguments :returns: The assembled file name :rtype: str

mischbares.utils.utils.create_dir(directory)[source]

Checks if a directory is present, if not creates one at the given location :param directory: Location where the directory should be created :type directory: str

mischbares.utils.utils.get_nested_value(config, keys)[source]

Recursively get the value from a nested dictionary using a list of keys.

Parameters

config (dict) – The dictionary to search in. keys (list): A list of keys to search for.

Returns

The value corresponding to the given keys.

Raises

KeyError – If the key is not found in the dictionary.

mischbares.utils.utils.load_data_as_json(directory, name)[source]

Load the given data as json :param directory: The directory where the data should be saved :type directory: str :param name: The name of the file :type name: str

mischbares.utils.utils.save_data_as_json(directory, data, name)[source]

Save the given data as json :param directory: The directory where the data should be saved :type directory: str :param data: The data that should be saved :type data: dict :param name: The name of the file :type name: str

mischbares.utils.utils.send_to_telegram(message, message_type)[source]

Sends a message to a Telegram bot.

Parameters
  • message (str) – The message to be sent.

  • message_type (str) – The type of the message (“error” or “info”).

Module contents