Common¶
-
mesmerize.common.
get_proj_config
(proj_path: Optional[str] = None) → configparser.RawConfigParser[source]¶ - Parameters
proj_path – Full project path
Utils¶
Some frequently used utility functions
-
mesmerize.common.utils.
make_workdir
(prefix: str = '') → str[source]¶ Make a workdir within the mesmerize_tmp directory of the workdir specified in the configuration The name of the created workdir is the date & time of its creation. You can add a prefix to this name.
- Parameters
prefix – Prefix for the workdir namec
- Returns
full workdir path
- Return type
-
mesmerize.common.utils.
make_runfile
(module_path: str, savedir: str, args_str: Optional[str] = None, filename: Optional[str] = None, pre_run: Optional[str] = None, post_run: Optional[str] = None) → str[source]¶ Make an executable bash script. Used for running python scripts in external processes.
- Parameters
module_path (str) – absolute module path
args_str (str) – str of args that is directly passed with the python command in the bash script
savedir (Optional[str]) – working directory
filename (Optional[str]) – optional, specific filename for the script
pre_run (Optional[str]) – optional, str to run before module is ran
post_run (Optional[str]) – optional, str to run after module has run
- Returns
path to the shell script that can be run
- Return type
-
class
mesmerize.common.utils.
HdfTools
[source]¶ Functions for saving and loading HDF5 data
-
static
save_dataframe
(path: str, dataframe: pandas.core.frame.DataFrame, metadata: Optional[dict] = None, metadata_method: str = 'json', raise_meta_fail: bool = True)[source]¶ Save DataFrame to hdf5 file along with a meta data dict.
Meta data dict can either be serialized with json and stored as a str in the hdf5 file, or recursively saved into hdf5 groups if the dict contains types that hdf5 can deal with. Experiment with both methods and see what works best
Currently the hdf5 method can work with these types: [str, bytes, int, float, np.int, np.int8, np.int16, np.int32, np.int64, np.float, np.float16, np.float32, np.float64, np.float128, np.complex].
If it encounters an object that is not of these types it will store whatever that object’s __str__() method returns if on_meta_fail is False, else it will raise an exception.
- Parameters
path (str) – path to save the file to
dataframe (pd.DataFrame) – DataFrame to save in the hdf5 file
metadata (Optional[dict]) – Any associated meta data to store along with the DataFrame in the hdf5 file
metadata_method (str) – method for storing the metadata dict, either ‘json’ or ‘recursive’
raise_meta_fail (bool) – raise an exception if recursive metadata saving encounters an unsupported object If false, it will save the unsupported object’s __str__() return value
-
static
load_dataframe
(filepath: str) → Tuple[pandas.core.frame.DataFrame, Optional[dict]][source]¶ Load a DataFrame along with meta data that were saved using
HdfTools.save_dataframe
-
static
QDialogs¶
Decorators for Qt Dialog GUIs used throughout Mesmerize
-
mesmerize.common.qdialogs.
present_exceptions
(title: str = 'error', msg: str = 'The following error occurred.', help_func: Optional[callable] = None)[source]¶ Use to catch exceptions and present them to the user in a QMessageBox warning dialog. The traceback from the exception is also shown.
This decorator can be stacked on top of other decorators.
Example:
- Parameters
title – Title of the dialog box
msg – Message to display above the traceback in the dialog box
help_func – A helper function which is called if the user clicked the “Help” button
-
mesmerize.common.qdialogs.
exceptions_label
(label: str, exception_holder: Optional[str] = None, title: str = 'error', msg: str = 'The following error occured')[source]¶ Use a label to display an exception instead of a QMessageBox
- Parameters
label – name of a QLabel instance
exception_holder – name of an exception_holder attribute where the exception message is stored. This can be used to view the whole exception when the label is clicked on for example.
title – title supplied for the QMessageBox (if used later)
msg – message supplied for the QMessageBox (if used later)
-
mesmerize.common.qdialogs.
use_open_file_dialog
(title: str = 'Choose file', start_dir: Optional[str] = None, exts: Optional[List[str]] = None)[source]¶ Use to pass a file path, for opening, into the decorated function using QFileDialog.getOpenFileName
- Parameters
title – Title of the dialog box
start_dir – Directory that is first shown in the dialog box.
exts – List of file extensions to set the filter in the dialog box
-
mesmerize.common.qdialogs.
use_save_file_dialog
(title: str = 'Save file', start_dir: Optional[str] = None, ext: Optional[str] = None)[source]¶ Use to pass a file path, for saving, into the decorated function using QFileDialog.getSaveFileName
- Parameters
title – Title of the dialog box
start_dir – Directory that is first shown in the dialog box.
exts – List of file extensions to set the filter in the dialog box
-
mesmerize.common.qdialogs.
use_open_dir_dialog
(title: str = 'Open directory', start_dir: Optional[str] = None)[source]¶ Use to pass a dir path, to open, into the decorated function using QFileDialog.getExistingDirectory
- Parameters
title – Title of the dialog box
start_dir – Directory that is first shown in the dialog box.
Example:
@use_open_dir_dialog('Select Project Directory', '') def load_data(self, path, *args, **kwargs): my_func_to_do_stuff_and_load_data(path)