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.ProcessingResultIoBase#
Base class for processing result importers and exporters.
- export_frame_to_file(index: int, frame_result_dict: dict[int, Dataset], **kwargs: Any) None#
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[int, Dataset]) – The result dictionary with nodeID keys and result values.
**kwargs – Any kwargs which should be passed to the underlying exporter.
- export_full_data_to_file(full_data: dict[int, Dataset], squeeze: bool = False) None#
Export all specified datasets to disk.
- Raises:
NotImplementedError – This method needs to be implemented by each concrete subclass.
- Parameters:
- get_filenames(node_information: dict[int, PluginResultInfo]) dict[int, str]#
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:
node_information (dict[int, PluginResultInfo]) – A dictionary with nodeID keys and PluginResultInfo values.
- Returns:
names – The dictionary of filenames for all nodes to export.
- Return type:
dict[int, str]
- static import_results_from_file(filename: Path | str) tuple[Dataset, dict[str, Any], Scan, DiffractionExperiment, ProcessingTree]#
Import results from a file and store them as a Dataset.
- Parameters:
filename (Path or 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[str, Any]) – A dictionary with node_label, data_label, plugin_name keys and the respective values.
scan (Scan) – The imported scan configuration.
diffraction_exp (DiffractionExperiment) – The imported diffraction experiment configuration.
tree (ProcessingTree) – The imported processing tree.
- prepare_files_and_directories(save_dir: Path | str, node_information: dict[int, PluginResultInfo], **kwargs: Any) None#
Prepare the required files and directories to write the data to disk.
- Parameters:
save_dir (Path or str) – The full path for the data to be saved.
node_information (dict[int, PluginResultInfo]) – A dictionary with nodeID keys and PluginResultInfo values.
**kwargs –
Supported kwargs are:
- scanScan or 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_expDiffractionExp or 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.
- processing_treeProcessingTree or None, optional
The ProcessingTree. If None, the generic WorkflowTree will be used. Only specify this, if you explicitly require a different context. The default is None.
- class pydidas.workflow.result_io.ProcessingResultIoMeta(clsname: str, bases: tuple[type], attrs: dict[str, Any])#
Metaclass for ProcessingResult exporters and importers which holds the registry with all associated file extensions for exporting ProcessingResults.
- static get_savers(formats: str | list[str] | None = None) dict[str, ProcessingResultIoBase]#
Get the savers based on the selected formats.
- Parameters:
formats (str or list[str] or None) – A single string with the name of the format or a list of names of the formats. None is a valid format to get an empty dictionary. Multiple formats can also be given as a single string if they are separated by a semicolon ;.
- Returns:
The dictionary with the active savers. Keys are the file extensions and values are the respective saver instances.
- Return type:
dict[str, ProcessingResultIoBase]
- static import_data_from_directory(dir_name: 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 ProcessingResults to update it
- Parameters:
dir_name (Path or String) – 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 (ProcessingTree) – A pydidas ProcessingTree instance (i.e. possibly also the WorkflowTree) with the workflow configuration.
- classmethod register_class(new_class: type[ProcessingResultIoBase], update_registry: bool = False) None#
Register a class as object for its native extensions.
- Parameters:
new_class (type[ProcessingResultIoBase]) – The class to be registered.
update_registry (bool) – Keyword to allow updating / overwriting of registered extensions. The default is False.
- Raises:
KeyError – If an extension associated with new_class has already been registered and update_registry is False.