Utils module

class em_workflows.utils.utils.Header(x, y, z)
x

Alias for field number 0

y

Alias for field number 1

z

Alias for field number 2

class em_workflows.utils.utils.BrtOutput(ali_file, rec_file)
ali_file

Alias for field number 0

rec_file

Alias for field number 1

em_workflows.utils.utils.log(msg)

Convenience function to print an INFO message to both the “input_dir” context log and the “root” prefect log.

Parameters:

msg – string to output

Returns:

None

em_workflows.utils.utils.lookup_dims(fp: Path) Header
Parameters:

fp – pathlib.Path to an image

Returns:

a tuple containing x,y,z dims of file

calls IMOD header with -s (size) flag; parses stdout to get result

em_workflows.utils.utils.collect_exception_task_hook(task: Task, task_run: TaskRun, state: State)

This task hook should be used with tasks where you intend to know which step of the flow run broke. Since most of our tasks are mapped by default using filepaths, it takes map index into account as well So that we can notify the user, ‘this step of this file broke’. The message is written to a file using prefect’s local storage. In order to retrieve it, the flow needs to have a logic at the end,

to lookup for this file with exception message if the task run has failed.

em_workflows.utils.utils.update_adoc(adoc_fp: Path, tg_fp: Path, montage: int, gold: int, focus: int, fiducialless: int, trackingMethod: int, TwoSurfaces: int, TargetNumberOfBeads: int, LocalAlignments: int, THICKNESS: int) Path
Uses jinja templating to update the adoc file with input params.
dual_p is calculated by inputs_paired() and is used to define dual
Some of these parameters are derived programatically.
Todo:

Remove references to dual_p in comments?

em_workflows.utils.utils.copy_tg_to_working_dir(fname: Path, working_dir: Path) Path

copies files (tomograms/mrc files) into working_dir returns Path of copied file :todo: Determine if the ‘a’ & ‘b’ files still exist and if these files need to be copied. (See comment in run_brt before this call is made)

em_workflows.utils.utils.copy_template(working_dir: Path, template_name: str) Path
Parameters:
  • working_dir – libpath.Path of temporary working directory

  • template_name – base str name of the ADOC template

Returns:

libpath.Path of the copied file

copies the template adoc file to the working_dir

em_workflows.utils.utils.notify_api_completion(flow: Flow, flow_run: FlowRun, state: State)

https://docs.prefect.io/core/concepts/states.html#overview. https://docs.prefect.io/core/concepts/notifications.html#state-handlers

em_workflows.utils.utils.get_environment() str

The workflows can operate in one of several environments, named HEDWIG_ENV for historical reasons, eg prod, qa or dev. This function looks up that environment. Raises exception if no environment found.

em_workflows.utils.utils.copy_workdirs_and_cleanup_hook(flow, flow_run, state)
em_workflows.utils.utils.callback_with_cleanup(fps: List[FilePath], callback_result: List, x_no_api: bool = False, callback_url: str | None = None, token: str | None = None, x_keep_workdir: bool = False)
em_workflows.utils.utils.generate_flow_run_name()