utils.py

A collection of utility functions used in the package.

If you find these codes or methods helpful for your project, please cite our related work.

class utils.DictAsMembers(d_dict)

Takes a dictionary with string keys and makes an object that has these as variables (deprecated). This allows for using dot notation to de-reference dictionary items in the syntax.

Example:

>>> d = MakeDictMembers(d_dict);
>>> d_dict['a'] = 1.0; # gets replaced with
>>> d.a = 1.0;

Should use this class sparingly and manage name spaces with care. Using python ‘map’ is preferred method to dereference large number of dictionary items.

__dict__ = mappingproxy({'__module__': 'utils', '__doc__': "\n  Takes a dictionary with string keys and makes an object \n  that has these as variables (deprecated).  This allows for using \n  dot notation to de-reference dictionary items in the syntax.\n\n  *Example:*\n\n  >>> d = MakeDictMembers(d_dict);\n  >>> d_dict['a'] = 1.0; # gets replaced with\n  >>> d.a = 1.0;\n  \n  Should use this class sparingly and manage name spaces with care. \n  Using python 'map' is preferred method to dereference large number \n  of dictionary items. \n\n  ", '__init__': <function DictAsMembers.__init__>, '__dict__': <attribute '__dict__' of 'DictAsMembers' objects>, '__weakref__': <attribute '__weakref__' of 'DictAsMembers' objects>, '__annotations__': {}})
__init__(d_dict)

Initilizes class to include dictionary items as members.

Parameters:

d_dict (dict) – dictionary to convert to object members

__module__ = 'utils'
__weakref__

list of weak references to the object (if defined)

utils.create_dir(dir_name)

Creates a directory on disk.

utils.rm_dir(dir_name)

Removes recursively a directory on disk.

utils.save_fig(base_filename, extra_label='', flag_verbose=True, dpi_set=200, flag_pdf=False, fig=None)

Saves figure to disk as image or pdf file.