simuran.analysis.analysis_handler module

This module provides functionality for performing large batch analysis.

class simuran.analysis.analysis_handler.AnalysisHandler(fns_to_run: list = <factory>, fn_params_list: list = <factory>, verbose: bool = False, handle_errors: bool = False, pickle_path: Union[str, Path, None] = 'simuran_analysis.pkl', _was_error: bool = False)

Bases: object

Hold functions to run and the parameters to use for them.

fns_to_run

The functions to run

Type:list of functions
fn_param_list

The arguments to pass to these functions. The arguments are passed in order, so these are positional.

Type:list of tuples
fn_kwargs_list

Keyword arguments to pass to the functions to run.

Type:list of dicts
results

The results of the function calls

Type:indexed.IndexedOrderedDict
verbose

Whether to print more information while running the functions.

Type:bool
handle_errors

Whether to handle errors during runtime of underlying functions, or to crash on error.

Type:bool
Parameters:
  • verbose (bool, optional) – Sets the value of the verbose attribute, defaults to False.
  • handle_errors (bool, optional) – Sets the value of the handle_errors attribute, defaults to False.
add_analysis(fn, args)

Add the function fn to the list with the given args and kwargs.

Parameters:
Returns:

Return type:

None

handle_errors = False
load_results_from_pickle()
pickle_path = 'simuran_analysis.pkl'
reset()

Reset this object, clearing results and function list.

run(pbar: bool = False, n_jobs: int = 1, save_every: int = 0, force_mp: bool = False)

Run all of the established functions.

Parameters:
  • pbar (string or bool, optional) – Whether to have a progress bar. Options are False (default) no progress bar. True a tdqm progress bat “notebook” a progress for notebooks
  • n_jobs (int, optional) – The number of jobs to run in parallel, by default 1 Uses mpire.WorkerPool along with a mapping. For more complex multiprocessing, directly use mpire.WorkerPool.
  • save_every (int, optional) – Save the results to a pickle file every n jobs, by default 0 If 0, then no saving occurs.
  • force_mp (bool, optional) – Force multiprocessing, by default False
Returns:

Return type:

None

save_results_to_pickle()
save_results_to_table(filename=None, columns=None, from_dict=True)

Dump analysis results to csv file.

Parameters:filename (str or Path) – The output path.
Returns:The resulting dataframe
Return type:Dataframe
verbose = False