Tasks#

The package exposes Ewoks task classes under ewoksscxrd.tasks.

XDS processing#

Create an XDS.INP file from explicit task inputs.

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

Create an XDS.INP file using explicit experiment parameters.

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])

run()[source]#

To be implemented by the derived classes

Conversion and preprocessing#

Convert Eiger or LImA HDF5 files to CBF frames using Fabio.

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

Wrap fabio.app.eiger2cbf as an Ewoks task.

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])

run()[source]#

To be implemented by the derived classes

Convert an HDF5 file to a Esperanto file

class ewoksscxrd.tasks.eiger2crysalis.Eiger2Crysalis(inputs=None, varinfo=None, node_id=None, node_attrs=None, execinfo=None, profile_directory=None)[source]#
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])

run()[source]#

To be implemented by the derived classes

class ewoksscxrd.tasks.lima2thresholding.Lima2Thresholding(inputs=None, varinfo=None, node_id=None, node_attrs=None, execinfo=None, profile_directory=None)[source]#
Reads a 4D HDF5 file (shape: (nframes, 2, H, W)) and processes each frame:
  • For each pixel, if image1 exceeds dectris_masking_value (optional, default: 1e6), the two corresponding pixel values are summed.

  • Otherwise, image1 is scaled by scale_factor and subtracted from image0.

  • Any negative result values after subtraction are set to 0.

The processed result (a 3D image) is then written to output in LImA HDF5 format.

Inputs:

images: list of input HDF5 files. output: destination file path for the processed result. scale_factor: scaling factor applied to image1 for subtraction. dectris_masking_value: threshold for image1

(optional; default: 2**32 - 1).

Outputs:

output_path: final path of the saved file.

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])

run()[source]#

To be implemented by the derived classes

CrysAlis files#

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

Task to copy a .ini file to the specified output location.

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])

run()[source]#

To be implemented by the derived classes

class ewoksscxrd.tasks.createsetccdfiles.CreateSetCcdFiles(inputs=None, varinfo=None, node_id=None, node_attrs=None, execinfo=None, profile_directory=None)[source]#
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])

run()[source]#

To be implemented by the derived classes

class ewoksscxrd.tasks.createparfiles.CreateParFiles(inputs=None, varinfo=None, node_id=None, node_attrs=None, execinfo=None, profile_directory=None)[source]#
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])

run()[source]#

To be implemented by the derived classes

class ewoksscxrd.tasks.createrunfiles.CreateRunFiles(inputs=None, varinfo=None, node_id=None, node_attrs=None, execinfo=None, profile_directory=None)[source]#
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])

run()[source]#

To be implemented by the derived classes

Data export and publication#

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

Reads an HDF5 file with frames, averages them along the frame axis, and saves the averaged image in EDF format using fabio. images is a list of lima HDF5 files.

The HDF5 file is assumed to contain a 3D dataset (n_frames, height, width). By default, it will attempt to use the dataset named “/entry_0000/measurement/data”.

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])

run()[source]#

To be implemented by the derived classes

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

Reads an HDF5 file with frames, extracts each individual frame, and saves them as TIFF images in a folder called ‘xdi’. The TIFF images will have a key called imageDescription, default is eiger, if the detector name is supplied, it will be set accordingly

The HDF5 file is assumed to contain a 2D or 3D dataset (n_frames, height, width) at the dataset path “/entry_0000/measurement/data”. The output folder xdi is created in PROCESSED_DATA/sample/sample_dataset/scan0001.

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])

run()[source]#

To be implemented by the derived classes

ewoksscxrd.tasks.tifffiles.save_tiff_worker(frame, file_path, tiff_info_dict)[source]#

Worker to save a single TIFF frame.

class ewoksscxrd.tasks.dataportal.DataPortal(inputs=None, varinfo=None, node_id=None, node_attrs=None, execinfo=None, profile_directory=None)[source]#
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])

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

Parameters:

processed_data_dir (str)

Return type:

str

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 to 8-bit grayscale using provided bounds when 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. Pixels with values at or above 1e9 are set to 0 to handle saturation.

  • 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

store_to_icat()[source]#

Infer ICAT parameters from processed_data_dir and store them with pyicat_plus.

The processed_data_dir (icat_processed_path) is taken from 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”.

  • icat_metadata: {} (an empty dictionary).

Return type:

None