ewoksscxrd.tasks.dataportal.DataPortal#

class ewoksscxrd.tasks.dataportal.DataPortal(inputs=None, varinfo=None, node_id=None, node_attrs=None, execinfo=None, profile_directory=None)[source]#

Bases: Task

Task that builds a gallery by processing an image:
  • Normalizes/clamps the image to 8-bit grayscale.

  • Applies binning with a defined binning factor.

  • Saves the processed image as a PNG (or as specified by gallery_output_format) in a folder called “gallery” within the processed data directory.

  • Infers ICAT parameters from the processed data directory and stores processed data metadata using pyicat_plus.

Inputs:
  • image: A 2D numpy.ndarray (or a 3D array with a singleton first dimension).

  • output: A file path; its directory is used as the processed data directory.

Optional inputs:
  • gallery_output_format: Output image file format (default “png”).

  • gallery_overwrite: Whether to overwrite an existing file (default True).

  • gallery_output_binning: Binning factor (default 1, meaning no binning).

  • bounds: A tuple (lower_bound, upper_bound) used for normalization.

    If not provided, lower_bound defaults to 0 and upper_bound is set to the 99.9th percentile of pixel values below 1e9, with any pixel at or above 1e9 set to 0. This generated image is only for display purposes.

Parameters:
  • inputs (Optional[Mapping])

  • varinfo (Optional[dict])

  • node_id (Union[str, int, tuple, None])

  • node_attrs (Optional[dict])

  • execinfo (Optional[dict])

  • profile_directory (Optional[dict])

MISSING_DATA = <MISSING_DATA>#
assert_ready_to_execute()#
cancel()#

Function called when a task is cancelled. To be implemented by the derived classes

property cancelled: bool#

Return True if the task has been cancelled by the user

classmethod class_nonce()#
classmethod class_nonce_data()#
classmethod class_registry_name()#
Return type:

Optional[str]

cleanup_references()#

Removes all references to the inputs. Side effect: fixes the uhash of the task and outputs

property done: bool#

Completed (with or without exception)

property exception: Exception | None#
execute(force_rerun=False, raise_on_error=True, cleanup_references=False)#
Parameters:
  • force_rerun (Optional[bool])

  • raise_on_error (Optional[bool])

  • cleanup_references (Optional[bool])

property failed: bool#

Completed with exception

fix_uhash()#

Fix the uhash when it is derived from the uhash data.

Returns the path to the gallery folder inside the processed data directory.

Parameters:

processed_data_dir (str)

Return type:

str

get_input_uhashes()#
get_input_value(key, default=<MISSING_DATA>)#
Parameters:

default (Any)

Return type:

Any

get_input_values()#
get_named_input_values()#
get_output_transfer_data()#

The values are either DataUri or Variable

get_output_uhashes()#
get_output_value(key, default=<MISSING_DATA>)#
Parameters:

default (Any)

Return type:

Any

get_output_values()#
get_positional_input_values()#
classmethod get_subclass(registry_name, _second_attempt=False)#

Retrieving a derived class

classmethod get_subclass_names()#
Return type:

List[str]

classmethod get_subclasses()#
get_uhash_init(serialize=False)#
classmethod input_model()#
Return type:

Optional[BaseInputModel]

classmethod input_names()#
Return type:

Set[str]

property input_uhashes#
property input_values#

DEPRECATED

property input_variables: VariableContainer#
property inputs: ReadOnlyVariableContainerNamespace#
instance_nonce()#
classmethod instantiate(registry_name, **kw)#

Factory method for instantiating a derived class.

Parameters:
  • registry_name (str) – for example “tasklib.tasks.MyTask” or “MyTask”

  • **kwTask constructor arguments

  • registry_name

Returns Task:

property is_ready_to_execute#
property job_id: str | None#
property label: str#
property missing_inputs: VariableContainerMissingNamespace#
property missing_outputs: VariableContainerMissingNamespace#
property n_positional_inputs: int#
classmethod n_required_positional_inputs()#
Return type:

int

property named_input_values#

DEPRECATED

property node_id: str | int | tuple#
property npositional_inputs#

DEPRECATED

classmethod optional_input_names()#
Return type:

Set[str]

property output_metadata: dict | None#
classmethod output_names()#
Return type:

Set[str]

property output_transfer_data#

DEPRECATED

property output_uhashes#

DEPRECATED

property output_values#

DEPRECATED

property output_variables: VariableContainer#
property outputs: VariableContainerNamespace#
property positional_input_values#

DEPRECATED

classmethod required_input_names()#
Return type:

Set[str]

reset_state()#
run()[source]#

To be implemented by the derived classes

Processes and saves the image to the gallery folder:
  • If the image is 3D with a singleton first dimension, reshapes it to 2D.

  • Normalizes the image to 8-bit grayscale using the provided bounds if available. If no bounds are provided, lower_bound defaults to 0 and upper_bound is set to the 99.9th percentile of pixels below 1e9. Also, any pixel with a value at or above 1e9 is set to 0. This is designed to handle the case of saturated pixels.

  • Applies binning based on gallery_output_binning.

  • Saves the result as an image in the specified output format.

Parameters:
  • output_file_name (str)

  • image (ndarray)

  • bounds (Optional[Tuple[float, float]])

Return type:

None

set_uhash_init(pre_uhash=None, instance_nonce=None)#
Parameters:
  • pre_uhash (Union[str, bytes, UniversalHash, HasUhash, None])

  • instance_nonce (Optional[Any])

store_to_icat()[source]#

Infers ICAT parameters from the processed data directory and stores processed data information using pyicat_plus.

The processed_data_dir (icat_processed_path) is taken from the directory of the output path. For a processed_data_dir like:

/data/visitor/proposal/beamline/sessions/PROCESSED_DATA/sample/sample_dataset

the parameters are inferred as follows:
  • icat_processed_path: Same as processed_data_dir.

  • icat_proposal: “proposal” (4th element).

  • icat_beamline: “beamline” (5th element).

  • icat_dataset: “sample_dataset” (last element).

  • icat_raw: Replace “PROCESSED_DATA” with “RAW_DATA” in the processed_data_dir.

  • icat_metadata: {} (an empty dictionary).

Return type:

None

property succeeded: bool#

Completed without exception and with output values

property task_identifier: str#
property uhash: UniversalHash | None#
uhash_randomize()#
undo_fix_uhash()#
undo_randomize()#
property workflow_id: str | None#