ImagePairToArrayStep#

class petpal.pipelines.preproc_steps.ImagePairToArrayStep(name: str, function: petpal.pipelines.steps_base.Callable, input_image_path: str, second_image_path: str, output_array_path: str, *args, **kwargs)#

Bases: petpal.pipelines.steps_base.FunctionBasedStep

A step in a processing pipeline for transforming two input image files into an output array.

This class extends the FunctionBasedStep and is designed for tasks that require combining or processing information from two image inputs and outputing an array e.g. getting the mean activity from a 4D-PET image given a voxel mask image. It handles input image paths, output array paths, and provides methods for setting inputs from connected pipeline steps or for inferring output array paths.

Attention

The passed function must have the following arguments order: func(input_image, second_image, output_array, *args, **kwargs) where input_image and output_image can be named something else. The first argument must be an input image path, the second argument must be the path to the second image, and the third argument must be an output array path.

Variables:
  • input_image_path (str) – Path to the first input image file.

  • second_image_path (str) – Path to the second input image file.

  • output_array_path (str) – Path to the output array file.

Initializes an ImagePairToArrayStep with specified parameters.

Parameters:
  • name (str) – The name of the step.

  • function (Callable) – The function that uses the two input images and outputs an array.

  • input_image_path (str) – Path to the first input image file.

  • second_image_path (str) – Path to the second input image file.

  • output_array_path (str) – Path to the output array file.

  • *args – Additional positional arguments for the processing function.

  • **kwargs – Additional keyword arguments for the processing function.

Notes

The passed function (func) must have the following arguments order: func(input_image, second_image, output_array, *args, **kwargs) where input_image, second_image, and output_array can be named something else. The first argument must be an input image path, the second argument must be the path to the second image, and the third argument must be an output array path.

execute()#

Executes the function to process the two input images into an output array.

The specified function will be called with the paths to the two input images, the output array, any additional arguments, and keyword arguments.

set_input_as_output_from(*sending_steps) None#

Sets the input image paths based on the output paths from other steps in the pipeline. The first sending step will set the input image path, and the second sending step will set the second image path.

Parameters:

sending_steps (tuple[FunctionBasedStep]) – Two pipeline steps whose outputs will be used as the input image path and second image input path.

Raises:

AssertionError – If the number of provided sending steps is not exactly two.

infer_outputs_from_inputs(out_dir: str, der_type: str = 'tacs', suffix: str = 'tac', ext: str = '.tsv', **extra_desc)#

Infers the output array path based on the inputs and specified parameters.

This method generates a BIDS-like derivatives filepath for the output based on the subject and session IDs extracted from the input image path.

Parameters:
  • out_dir (str) – Directory where the output array will be saved.

  • der_type (str, optional) – Type of derivative. Will set the sub-directory in out_dir. Defaults to ‘tacs’.

  • suffix (str, optional) – Suffix for the output filename. Defaults to ‘tac’.

  • ext (str, optional) – File extension for the output file. Defaults to ‘.tsv’.

  • **extra_desc – Additional descriptive parameters for the output filename.

get_function_args_not_set_in_kwargs() ArgsDict#

Retrieves arguments of the function that are not set in the keyword arguments.

Returns:

ArgsDict – A dictionary of function arguments that have not been set in the keyword arguments.

get_empty_default_kwargs() list#

Identifies arguments that have not been provided and lack default values.

Returns:

list – A list of argument names that have no default values and are not provided.

validate_kwargs_for_non_default_have_been_set() None#

Validates that all mandatory arguments have been provided.

Raises:

RuntimeError – If any mandatory arguments are missing.

generate_kwargs_from_args() ArgsDict#

Converts positional arguments into keyword arguments.

Returns:

ArgsDict – A dictionary where positional arguments are mapped to their corresponding parameter names.

__str__()#

Returns a detailed string representation of the FunctionBasedStep instance.

Returns:

str – A string describing the step, including its name, function, arguments, and keyword arguments.

__repr__()#

Returns an unambiguous string representation of the FunctionBasedStep instance.

Returns:

str – A string representation showing how the FunctionBasedStep can be recreated.

all_args_non_empty_strings()#

Checks if all positional arguments are non-empty strings.

Returns:

bool – True if all positional arguments are non-empty strings, False otherwise.

all_kwargs_non_empty_strings()#

Checks if all keyword arguments are non-empty strings.

Returns:

bool – True if all keyword arguments are non-empty strings, False otherwise.

can_potentially_run()#

Determines if the step can potentially be executed based on argument validation. Very simply checks if all arguments and keyword arguments are non-empty strings.

Returns:

bool – True if the step can potentially run, False otherwise.

__call__(*args, **kwargs)#