ImagePairToArrayStep =================================================== .. py: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: :py:obj:`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 :class:`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. :ivar input_image_path: Path to the first input image file. :vartype input_image_path: str :ivar second_image_path: Path to the second input image file. :vartype second_image_path: str :ivar output_array_path: Path to the output array file. :vartype output_array_path: str Initializes an ImagePairToArrayStep with specified parameters. :param name: The name of the step. :type name: str :param function: The function that uses the two input images and outputs an array. :type function: Callable :param input_image_path: Path to the first input image file. :type input_image_path: str :param second_image_path: Path to the second input image file. :type second_image_path: str :param output_array_path: Path to the output array file. :type output_array_path: str :param \*args: Additional positional arguments for the processing function. :param \*\*kwargs: Additional keyword arguments for the processing function. .. rubric:: 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. .. py:method:: 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. .. py:method:: 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. :param sending_steps: Two pipeline steps whose outputs will be used as the input image path and second image input path. :type sending_steps: tuple[FunctionBasedStep] :raises AssertionError: If the number of provided sending steps is not exactly two. .. py:method:: 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. :param out_dir: Directory where the output array will be saved. :type out_dir: str :param der_type: Type of derivative. Will set the sub-directory in `out_dir`. Defaults to 'tacs'. :type der_type: str, optional :param suffix: Suffix for the output filename. Defaults to 'tac'. :type suffix: str, optional :param ext: File extension for the output file. Defaults to '.tsv'. :type ext: str, optional :param \*\*extra_desc: Additional descriptive parameters for the output filename. .. py:method:: 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. .. py:method:: 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. .. py:method:: 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. .. py:method:: 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. .. py:method:: __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. .. py:method:: __repr__() Returns an unambiguous string representation of the FunctionBasedStep instance. :returns: *str* -- A string representation showing how the FunctionBasedStep can be recreated. .. py:method:: 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. .. py:method:: 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. .. py:method:: 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. .. py:method:: __call__(*args, **kwargs)