utilities

Module of common utility methods and attributes used by all the modules.

class mloop.utilities.NullQueueListener

Bases: object

Shell class with start and stop functions that do nothing. Queue listener is not implemented in python 2. Current fix is to simply use the multiprocessing class to pipe straight to the cmd line if running on python 2. This is class is just a placeholder.

start()

Does nothing

stop()

Does nothing

mloop.utilities._config_logger(log_filename='M-LOOP_', file_log_level=10, console_log_level=20, **kwargs)

Configure and the root logger.

Keyword Arguments:
 
  • log_filename (Optional [string]) – Filename prefix for log. Default MLOOP run . If None, no file handler is created
  • file_log_level (Optional[int]) – Level of log output for file, default is logging.DEBUG = 10
  • console_log_level (Optional[int]) – Level of log output for console, defalut is logging.INFO = 20
Returns:

Dict with extra keywords not used by the logging configuration.

Return type:

dictionary

mloop.utilities.check_file_type_supported(file_type)

Checks whether the file type is supported

Returns:True if file_type is supported, False otherwise.
Return type:bool
mloop.utilities.config_logger(**kwargs)

Wrapper for _config_logger.

mloop.utilities.datetime_to_string(datetime)

Method for changing a datetime into a standard string format used by all packages.

mloop.utilities.dict_to_txt_file(tdict, filename)

Method for writing a dict to a file with syntax similar to how files are input.

Parameters:
  • tdict (dict) – Dictionary to be written to file.
  • filename (string) – Filename for file.
mloop.utilities.get_dict_from_file(filename, file_type)

Method for getting a dictionary from a file, of a given format.

Parameters:
  • filename – The filename for the file.
  • file_type – The file_type for the file. Can be ‘mat’ for matlab, ‘txt’ for text, or ‘pkl’ for pickle.
Returns:

Dictionary of values in file.

Return type:

dict

mloop.utilities.safe_cast_to_array(in_array)

Attempts to safely cast the input to an array. Takes care of border cases

Parameters:in_array (array or equivalent) – The array (or otherwise) to be converted to a list.
Returns:array that has been squeezed and 0-D cases change to 1-D cases
Return type:array
mloop.utilities.safe_cast_to_list(in_array)

Attempts to safely cast a numpy array to a list, if not a numpy array just casts to list on the object.

Parameters:in_array (array or equivalent) – The array (or otherwise) to be converted to a list.
Returns:List of elements from in_array
Return type:list
mloop.utilities.save_dict_to_file(dictionary, filename, file_type)

Method for saving a dictionary to a file, of a given format.

Parameters:
  • dictionary – The dictionary to be saved in the file.
  • filename – The filename for the saved file
  • file_type – The file_type for the saved file. Can be ‘mat’ for matlab, ‘txt’ for text, or ‘pkl’ for pickle.
mloop.utilities.txt_file_to_dict(filename)

Method for taking a file and changing it to a dict. Every line in file is a new entry for the dictionary and each element should be written as:

[key] = [value]

White space does not matter.

Parameters:filename (string) – Filename of file.
Returns:Dictionary of values in file.
Return type:dict