TCMFittingAnalysisStep#

class petpal.pipelines.kinetic_modeling_steps.TCMFittingAnalysisStep(input_tac_path: str, roi_tacs_dir: str, output_directory: str, output_prefix: str, compartment_model='2tcm-k4zer0', **kwargs)#

Bases: petpal.pipelines.steps_base.ObjectBasedStep, TACAnalysisStepMixin

A step for fitting compartment models to TAC data using MultiTACTCMAnalysis.

This class sets up the compartment model fitting, initializes required paths and parameters, and provides class methods for creating default steps with common compartment models like 1TCM, Serial 2TCM, and Irreversible 2TCM.

Variables:
  • input_tac_path (str) – Path to the input TAC file.

  • roi_tacs_dir (str) – Directory containing the ROI TAC files.

  • output_directory (str) – Directory where output files will be saved.

  • output_prefix (str) – Prefix for the output files.

  • compartment_model (str) – Compartment model to be used for fitting.

Initializes the TCMFittingAnalysisStep with specified parameters.

Parameters:
  • input_tac_path (str) – Path to the input TAC file.

  • roi_tacs_dir (str) – Directory containing the ROI TAC files.

  • output_directory (str) – Directory where output files will be saved.

  • output_prefix (str) – Prefix for the output files.

  • compartment_model (str, optional) – Compartment model to be used for fitting. Defaults to ‘2tcm-k4zer0’.

  • **kwargs – Additional keyword arguments to be included in initialization for MultiTACTCMAnalysis.

__repr__()#

Provides an unambiguous string representation of the ResampleBloodTACStep instance.

Returns:

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

classmethod default_1tcm(**kwargs)#

Creates a default instance for 1TCM compartment model fitting using MultiTACTCMAnalysis. All paths are set to empty-strings.

Parameters:

**kwargs – Additional keyword arguments to be included in the initialization.

Returns:

TCMFittingAnalysisStep – A new instance for 1TCM compartment model fitting.

classmethod default_serial2tcm(**kwargs)#

Creates a default instance for serial-2TCM compartment model fitting using MultiTACTCMAnalysis. All paths are set to empty-strings.

Parameters:

**kwargs – Additional keyword arguments to be included in the initialization.

Returns:

TCMFittingAnalysisStep – A new instance for serial-2TCM compartment model fitting.

classmethod default_irreversible_2tcm(**kwargs)#

Creates a default instance for irreversible-2TCM compartment model fitting using MultiTACTCMAnalysis. All paths are set to empty-strings.

Parameters:

**kwargs – Additional keyword arguments to be included in the initialization.

Returns:

TCMFittingAnalysisStep – A new instance for irreversible-2TCM compartment model fitting.

validate_kwargs()#

Validates that all mandatory initialization and call arguments have been provided.

Raises:

RuntimeError – If any mandatory arguments are missing.

static get_args_not_set_in_kwargs(sig: inspect.Signature, kwargs: dict) dict#

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

Parameters:
  • sig (inspect.Signature) – The signature of the function or method.

  • kwargs (dict) – The keyword arguments provided.

Returns:

dict – A dictionary of arguments that are not set in the keyword arguments.

get_empty_default_kwargs(sig: inspect.Signature, set_kwargs: dict) list#

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

Parameters:
  • sig (inspect.Signature) – The signature of the function or method.

  • set_kwargs (dict) – The keyword arguments provided.

Returns:

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

execute() None#

Instantiates the class and invokes it with the provided arguments.

Raises:

The function may raise any exceptions that its implementation can throw.

__str__()#

Returns a detailed string representation of the ObjectBasedStep instance.

Returns:

str – A string describing the step, including its name, class, initialization, and call arguments.

all_init_kwargs_non_empty_strings()#

Checks if all initialization keyword arguments are non-empty strings.

Returns:

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

all_call_kwargs_non_empty_strings()#

Checks if all call keyword arguments are non-empty strings.

Returns:

bool – True if all call 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 __init__ and __call__ keyword arguments for the object are non-empty strings.

Returns:

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

abstractmethod set_input_as_output_from(*sending_steps)#

Sets the input of the current step as the output from a list of steps.

Parameters:

*sending_steps – The previous steps from which the output will be used as input for the current step.

Raises:

NotImplementedError – This method should be implemented by subclasses.

Notes

For a concrete example, take a look at: TACsFromSegmentationStep

Important

If a step takes multiple input steps. the implementation will have a defined order for steps.

abstractmethod infer_outputs_from_inputs(out_dir: str, der_type: str, suffix: str = None, ext: str = None, **extra_desc)#

Infers output files from input data based on the specified output directory, derivative type, optional suffix and extension, plus any extra descriptions.

Parameters:
  • out_dir (str) – The directory where the output files will be saved.

  • der_type (str) – The type of derivative being produced.

  • suffix (str, optional) – An optional suffix for the output files.

  • ext (str, optional) – An optional extension for the output files.

  • **extra_desc – Additional keyword arguments for extra descriptions to be included.

Raises:

NotImplementedError – This method should be implemented by subclasses.

Notes

For a concrete example, take a look at: TACsFromSegmentationStep

__call__(*args, **kwargs)#
property input_tac_path: str#

Gets the path to the input TAC file.

Returns:

str – Path to the input TAC file.

property reference_tac_path: str#

Gets the path to the reference TAC file.

Returns:

str – Path to the reference TAC file.

property tacs_dir: str#

Gets the directory containing the TAC files to be analyzed.

Returns:

str – Directory containing the TAC files to be analyzed.

property roi_tacs_dir: str#

Gets the directory containing the ROI TAC files to be analyzed.

Returns:

str – Directory containing the ROI TAC files to be analyzed.

property output_directory: str#

Gets the directory where output files will be saved.

Returns:

str – Directory where output files will be saved.

property output_prefix: str#

Gets the prefix for the output files. Usually something like sub-XXXX_ses-XX if BIDS compliant output.

Returns:

str – Prefix for the output files.

property out_path_and_prefix#

Gets the tuple of output directory and prefix.

Returns:

tuple – A tuple containing output directory and prefix.

infer_prefix_from_input_tac_path()#

Infers the output prefix based on the input/reference TAC file path. Gets the subject and session from the path if possible.

infer_output_directory_from_input_tac_path(out_dir: str, der_type: str = 'km')#

Infers the output directory based on the input/reference TAC file path. Gets the subject and session from the path is possible.

Parameters:
  • out_dir (str) – Root output directory.

  • der_type (str) – Type of derivatives. Defaults to ‘km’.