GraphicalAnalysis#

class petpal.kinetic_modeling.graphical_analysis.GraphicalAnalysis(input_tac_path: str, roi_tac_path: str, output_directory: str, output_filename_prefix: str, method: str, fit_thresh_in_mins: float)#

GraphicalAnalysis to handle Graphical Analysis for time activity curve (TAC) data.

The GraphicalAnalysis class provides methods for managing TAC data analysis. The class is initialized with paths to input TAC data, region of interest (ROI) TAC data files, an output directory, and output filename prefix.

Analysis is performed by specifying a method name and threshold time in the run_analysis() method. The results of the analysis are stored within the instance’s ‘analysis_props’ dictionary.

Key methods include: - init_analysis_props(): Initializes a dictionary with keys for analysis properties and default values. - run_analysis(): Runs the graphical analysis on the data using a specific method. - calculate_fit(): Calculates the best fit values for a given graphical analysis method. - calculate_fit_properties(): Calculates and stores the properties related to the fitting process. - save_analysis(): Stores the ‘analysis_props’ dictionary into a JSON file.

Raises:

RuntimeError – If the run_analysis() method has not been run before save_analysis() method.

Variables:
  • input_tac_path (str) – The path to input TAC data file.

  • roi_tac_path (str) – The path to ROI TAC data file.

  • output_directory (str) – Directory where the output should be saved.

  • output_filename_prefix (str) – Output filename prefix for saving the analysis.

  • analysis_props (dict) – Property dictionary used to store results of the analysis.

  • method (str) – The name of the graphical analysis method to be utilised.

  • fit_thresh_in_mins (float) – The fitting threshold time in minutes for the analysis method.

  • self.analysis_func (Callable) – The function used for performing the fitting.

Initializes GraphicalAnalysis with provided paths and output details.

Parameters:
  • input_tac_path (str) – The path to the file containing input Time Activity Curve (TAC) data.

  • roi_tac_path (str) – The path to the file containing Region of Interest (ROI) TAC data.

  • output_directory (str) – The directory where the output of the analysis should be saved.

  • output_filename_prefix (str) – The prefix for the name of output file(s).

  • method (str) – The name of the graphical analysis method to be utilised.

  • fit_thresh_in_mins (float) – The fitting threshold time in minutes for the analysis method.

Returns:

None

init_analysis_props() dict#

Initializes analysis properties dictionary.

This method initializes a dictionary with keys for all the analysis properties and default values set to None. The paths to the input TAC and ROI TAC files are set from the object’s properties.

Returns:

dict

A dictionary with keys for each analysis property and default values. The keys

include ‘FilePathPTAC’ (the file path to the input TAC file), ‘FilePathTTAC’ (the file path to the ROI TAC file), ‘MethodName’ (the name of the method used in the analysis), ‘ThresholdTime’ (the threshold time for the analysis), ‘StartFrameTime’ and ‘EndFrameTime’ (the start and end times for the frame), ‘NumberOfPointsFit’ (The number of points used in the fit), ‘Slope’, ‘Intercept’ and ‘RSquared’ (the slope, intercept and R-squared of the fit).

run_analysis(**run_kwargs)#

Runs the graphical analysis on the data using the specified method.

This method is the main entry point to carry out the analysis. It executes the steps in order, first calculating the fit, then calculating the properties of the fit.

Parameters:

run_kwargs – Additional keyword arguments used in the analysis. These are passed on to calculate_fit() and calculate_fit_properties().

Returns:

None

Side Effects:
Computes and updates the analysis-related properties in the object based on the

provided method and threshold.

calculate_fit(**run_kwargs)#

Calculates the best fit parameters for a graphical analysis method.

This method applies the specified graphical analysis method to the Time Activity Curve (TAC) data and stores the slope, intercept, and r-squared values of the fit in the analysis properties.

Parameters:

run_kwargs – Additional keyword arguments used in the analysis. These are passed on to analysis_func.

Returns:

None

Side Effect:
Updates ‘Slope’, ‘Intercept’, and ‘RSquared’ in self.analysis_props dictionary with

calculated fit parameters.

calculate_fit_properties(**run_kwargs)#

Calculates and stores the properties related to the fitting process.

This method calculates several properties related to the fitting process, including the threshold time, the name of the method used, the start and end frame time, and the number of points used in the fit. These values are stored in the instance’s analysis_props variable.

Parameters:

run_kwargs – Additional keyword arguments used in the analysis. These are saved to the analysis properties as individual properties.

Note

This method relies on the safe_load_tac() function to load time-activity curve (TAC) data from the file at input_tac_path, and the get_index function to get the index from the threshold time.

See also

  • safe_load_tac(): Function to safely load TAC data from a file.

  • get_index_from_threshold(): Function to get the index from the threshold time.

Returns:

None. The results are stored within the instance’s analysis_props variable.

save_analysis()#

Saves the analysis properties to a JSON file.

This method saves the ‘analysis_props’ dictionary to a JSON file. The file is saved in the specified output directory under a filename constructed from the ‘output_filename_prefix’ and the method name used in analysis. Before executing, the method checks if analysis has been run by verifying if ‘RSquared’ in ‘analysis_props’ is not None.

Raises:

RuntimeError – If the ‘run_analysis’ method was not called before ‘save_analysis’ is invoked.

Returns:

None

__call__(**run_kwargs)#

Runs run_analysis() and save_analysis() to run the analysis and save the analysis properties.

Parameters:

run_kwargs – Additional keyword arguments used in the analysis. These are passed on to run_analysis().