workflow.result_io#

The pydidas.workflow.result_saver package includes exporters for workflow results in different formats as well as a registry metaclass to handle actual exports.

class pydidas.workflow.result_io.WorkflowResultIoBase#

Base class for WorkflowTree exporters.

classmethod export_frame_to_file(index: int, frame_result_dict: dict[int, Dataset], **kwargs: dict)#

Export the results of one frame and store them on disk.

Raises:

NotImplementedError – This method needs to be implemented by each concrete subclass.

Parameters:
  • index (int) – The frame index.

  • frame_result_dict (dict) – The result dictionary with nodeID keys and result values.

  • **kwargs (dict) – Any kwargs which should be passed to the udnerlying exporter.

classmethod export_full_data_to_file(full_data: dict[int, Dataset], scan_context: Scan | None = None)#

Export all specified datasets to disk.

Raises:

NotImplementedError – This method needs to be implemented by each concrete subclass.

Parameters:
  • full_data (dict) – The result dictionary with nodeID keys and result values.

  • scan_context (Union[Scan, None], optional) – The scan context. If None, the generic context will be used. Only specify this, if you explicitly require a different context. The default is None.

classmethod get_attribute_dict(name: str) dict#

Get a dictionary for a single attribute from the combined node informatinon.

Parameters:

name (str) – The name of the attribute to extract.

Returns:

The dictionary with the node IDs and the single attribute values.

Return type:

dict

classmethod get_filenames_from_labels(labels: dict | None = None)#

Get the directory names from labels.

This method will assemble directory names which include the node ID, the Plugin label and the format name. Any spaces or escape characters will be converted to underscores.

Parameters:

labels (Union[dict, None], optional) – The labels to be used. If labels are not supplied, they will be taken from the internally stored node information. The default is None.

Returns:

names – The dictionary of possible directory names.

Return type:

dict

classmethod get_node_attribute(node_id: int, name: str) object#

Get a single node attribute from the stored node information.

Parameters:
  • node_id (int) – The node number.

  • name (str) – The required attribute name.

Returns:

The value of the required attribute

Return type:

type

classmethod import_results_from_file(filename: Path | str)#

Import results from a file and store them as a Dataset.

Parameters:

filename (Union[Path, str]) – The full filename of the file to be imported.

Raises:

NotImplementedError – This method needs to be implemented by each concrete subclass.

Returns:

  • data (pydidas.core.Dataset) – The dataset with the imported data.

  • node_info (dict) – A dictionary with node_label, data_label, plugin_name keys and the respective values.

  • scan (dict) – The dictionary with meta information about the scan.

classmethod prepare_files_and_directories(save_dir: Path | str, node_information: dict, **kwargs)#

Prepare the required files and directories to write the data to disk.

Parameters:
  • save_dir (Union[Path, str]) – The full path for the data to be saved.

  • node_information (dict) – A dictionary with nodeID keys and dictionary values. Each value dictionary must have the following keys: shape, node_label, data_label, plugin_name and the respecive values. The shape (tuple) detemines the shape of the Dataset, the node_label is the user’s name for the processing node. The data_label gives the description of what the data shows (e.g. intensity) and the plugin_name is simply the name of the plugin.

  • **kwargs

    Supported kwargs are:

    scan_contextUnion[Scan, None], optional

    The scan context. If None, the generic context will be used. Only specify this, if you explicitly require a different context. The default is None.

    diffraction_exp_contextUnion[DiffractionExp, None], optional

    The diffraction experiment context. If None, the generic context will be used. Only specify this, if you explicitly require a different context. The default is None.

    workflow_treeUnion[WorkflowTree, None], optional

    The WorkflowTree. If None, the generic WorkflowTree will be used. Only specify this, if you explicitly require a different context. The default is None.

classmethod update_frame_metadata(metadata: dict, scan: Scan | None = None)#

Update the metadata of the individual frame.

Raises:

NotImplementedError – This method needs to be implemented by each concrete subclass.

Parameters:
  • metadata (dict) – The metadata dictionary with results of one frame for each node.

  • scan (Union[pydidas.contexts.scan.Scan, None], optional) – The Scan instance. If None, this will default to the generic ScanContext. The default is None.

class pydidas.workflow.result_io.WorkflowResultIoMeta(clsname, bases, attrs)#

Metaclass for WorkflowTree exporters and importers which holds the registry with all associated file extensions for exporting WorkflowTrees.

classmethod export_frame_to_active_savers(index: int, frame_result_dict: dict, **kwargs: dict)#

Export the results of a frame to all active savers.

Parameters:
  • index (int) – The frame index.

  • frame_result_dict (dict) – The result dictionary with nodeID keys and result values.

  • kwargs (dict) – Any kwargs which should be passed to the udnerlying exporter.

classmethod export_frame_to_file(index: int, extension: str, frame_result_dict: dict[int, Dataset], **kwargs: dict)#

Call the concrete export_to_file method in the subclass registered to the extension of the filename.

Parameters:
  • index (int) – The frame index.

  • extension (str) – The file extension for the saver.

  • frame_result_dict (dict) – The result dictionary with nodeID keys and result values.

  • kwargs (dict) – Any kwargs which should be passed to the udnerlying exporter.

classmethod export_full_data_to_active_savers(data: dict[int, Dataset], scan_context: Scan | None = None)#

Export the full data to all active savers.

Parameters:
  • data (dict) – The result dictionary with nodeID keys and result values.

  • scan_context (Union[Scan, None], optional) – The scan context. If None, the generic context will be used. Only specify this, if you explicitly require a different context. The default is None.

classmethod export_full_data_to_file(extension: str, data: dict[int, Dataset], scan_context: Scan | None = None)#

Export the full data to all active savers.

Parameters:
  • extension (str) – The file extension for the saver.

  • data (dict) – The result dictionary with nodeID keys and result values.

  • scan_context (Union[Scan, None], optional) – The scan context. If None, the generic context will be used. Only specify this, if you explicitly require a different context. The default is None.

classmethod get_filenames_from_active_savers(labels: dict) list[dict]#

Get the filenames from all active savers based on the supplied labels.

Parameters:

labels (dict) – The labels of the results in form of a dictionary with nodeID keys and label values.

Returns:

A list will all filenames for all selected nodes and exporters.

Return type:

list

classmethod import_data_from_directory(dirname: Path | str) tuple[dict[int, Dataset], dict, Scan, DiffractionExperiment, ProcessingTree]#

Import data from files in a directory.

This method imports data, reads the metadata and passes it in a format for the WorkflowResults to update itself.

Parameters:

dirname (Union[Path, str]) – The name of the directory from which data shall be imported.

Returns:

  • data_dict (dict) – The dictionary with the data. Keys are the respective node IDs and dict values is the imported data.

  • node_info_dict (dict) – The dictionary with information for all imported nodes.

  • scan (Scan) – A pydidas Scan instance with the scan’s context

  • exp (DiffractionExperiment) – A pydidas DiffractionExperiment instance with the experiment’s context

  • tree (WorkflowTree) – A pydidas WorkflowTree instance with the workflow’s context

classmethod prepare_active_savers(save_dir: Path | str, node_information: dict, scan_context: Scan | None = None, diffraction_exp: DiffractionExperiment | None = None, workflow_tree: ProcessingTree | None = None)#

Prepare the active savers for storing data.

This method creates the required files and directories.

Parameters:
  • save_dir (Union[Path, str]) – The full path for the data to be saved.

  • node_information (dict) – A dictionary with nodeID keys and dictionary values. Each value dictionary must have the following keys: shape, node_label, data_label, plugin_name and the respecive values. The shape (tuple) detemines the shape of the Dataset, the node_label is the user’s name for the processing node. The data_label gives the description of what the data shows (e.g. intensity) and the plugin_name is simply the name of the plugin.

  • scan_context (Union[Scan, None], optional) – The scan context. If None, the generic context will be used. Only specify this, if you explicitly require a different context. The default is None.

  • diffraction_exp (Union[DiffractionExp, None], optional) – The diffraction experiment context. If None, the generic context will be used. Only specify this, if you explicitly require a different context. The default is None.

  • workflow_tree (Union[WorkflowTree, None], optional) – The WorkflowTree. If None, the generic WorkflowTree will be used. Only specify this, if you explicitly require a different context. The default is None.

classmethod push_frame_metadata_to_active_savers(metadata: dict, scan: Scan | None = None)#

Push the frame metadata to all active savers.

This method is required if the ExecuteWorkflowApp is used with the AppRunner because the metadata cannot be transferred through the shared numpy.buffers and needs to be forwarded independently of the frame data.

Parameters:
  • metadata (dict) – The dictionary with the metadata.

  • scan (Union[Scan, None], optional) – The Scan instance. If None, this will default to the generic ScanContext. The default is None.

classmethod reset()#

Reset the Meta registry and clear all entries.

classmethod set_active_savers_and_title(savers: list[str], title: str = 'unknown')#

Set the active savers so they do not need to be specified individually later on.

Parameters:
  • savers (list) – A list of the names of the savers. “None” is a valid Saver to clear the list.

  • title (str, optional) – The title of the scan. If not provided, the title will default to “unknown”.