Python Utilities

Miscellaneous utility functions used throughout the dragonfly package.

Miscellaneous utility functions called by one or more python modules

class dragonfly.utils.py_src.py_utils.MyTimer[source]

Bases: object

Class to report elapsed time for logging.

reset(msg=None, report=False)[source]

Update time and log difference since last reset if requested.

Parameters:
  • msg (str) – Message to log.

  • report (bool) – Whether to log the time difference.

reset_global()[source]

Update global start time.

report_time_since_beginning()[source]

Log time difference since start.

dragonfly.utils.py_src.py_utils.write_density(in_den_file, in_den, binary=True)[source]

Write density volume to file.

Parameters:
  • in_den_file (str) – Output file path.

  • in_den (numpy.ndarray) – 3D density array.

  • binary (bool) – Write binary if True, text if False.

dragonfly.utils.py_src.py_utils.read_density(in_den_file)[source]

Read density volume from binary file.

Parameters:

in_den_file (str) – Input file path.

Returns:

3D density array.

Return type:

numpy.ndarray

dragonfly.utils.py_src.py_utils.check_to_overwrite(fname)[source]

Check if file exists and prompt before overwriting.

By default, the file is overwritten.

Parameters:

fname (str) – File path to check.

Returns:

True to overwrite, False to cancel.

Return type:

bool

dragonfly.utils.py_src.py_utils.confirm_oversampling(ratio)[source]

Print message if oversampling ratio is too high and prompt for continuation.

Parameters:

ratio (float) – Oversampling ratio to check.

Returns:

True to proceed, False to cancel.

Return type:

bool

dragonfly.utils.py_src.py_utils.gen_det_and_emc(gui, classifier=False, mask=False)[source]

Create EMCReader and Detector instances for GUIs.

Parameters:
  • gui – GUI object with det_list and photons_list attributes.

  • classifier (bool) – Whether this is for the classifier GUI.

  • mask (bool) – Whether to use mask.

Returns:

Sets gui.geom and gui.emc_reader attributes.