GraphicalAnalysis ============================================================ .. py: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) :class:`GraphicalAnalysis` to handle Graphical Analysis for time activity curve (TAC) data. The :class:`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 :func:`run_analysis` method. The results of the analysis are stored within the instance's 'analysis_props' dictionary. Key methods include: - :func:`init_analysis_props`: Initializes a dictionary with keys for analysis properties and default values. - :func:`run_analysis`: Runs the graphical analysis on the data using a specific method. - :func:`calculate_fit`: Calculates the best fit values for a given graphical analysis method. - :func:`calculate_fit_properties`: Calculates and stores the properties related to the fitting process. - :func:`save_analysis`: Stores the 'analysis_props' dictionary into a JSON file. :raises RuntimeError: If the :func:`run_analysis` method has not been run before :func:`save_analysis` method. :ivar input_tac_path: The path to input TAC data file. :vartype input_tac_path: str :ivar roi_tac_path: The path to ROI TAC data file. :vartype roi_tac_path: str :ivar output_directory: Directory where the output should be saved. :vartype output_directory: str :ivar output_filename_prefix: Output filename prefix for saving the analysis. :vartype output_filename_prefix: str :ivar analysis_props: Property dictionary used to store results of the analysis. :vartype analysis_props: dict :ivar method: The name of the graphical analysis method to be utilised. :vartype method: str :ivar fit_thresh_in_mins: The fitting threshold time in minutes for the analysis method. :vartype fit_thresh_in_mins: float :ivar self.analysis_func: The function used for performing the fitting. :vartype self.analysis_func: Callable Initializes GraphicalAnalysis with provided paths and output details. :param input_tac_path: The path to the file containing input Time Activity Curve (TAC) data. :type input_tac_path: str :param roi_tac_path: The path to the file containing Region of Interest (ROI) TAC data. :type roi_tac_path: str :param output_directory: The directory where the output of the analysis should be saved. :type output_directory: str :param output_filename_prefix: The prefix for the name of output file(s). :type output_filename_prefix: str :param method: The name of the graphical analysis method to be utilised. :type method: str :param fit_thresh_in_mins: The fitting threshold time in minutes for the analysis method. :type fit_thresh_in_mins: float :returns: None .. py:method:: 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). .. py:method:: 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. :param run_kwargs: Additional keyword arguments used in the analysis. These are passed on to :meth:`calculate_fit` and :meth:`calculate_fit_properties`. :returns: None Side Effects: Computes and updates the analysis-related properties in the object based on the provided method and threshold. .. py:method:: 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. :param 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. .. py:method:: 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. :param 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 :func:`safe_load_tac` function to load time-activity curve (TAC) data from the file at ``input_tac_path``, and the :func:`get_index ` function to get the index from the threshold time. .. seealso:: * :func:`safe_load_tac`: Function to safely load TAC data from a file. * :func:`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. .. py:method:: 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 .. py:method:: __call__(**run_kwargs) Runs :meth:`run_analysis` and :meth:`save_analysis` to run the analysis and save the analysis properties. :param run_kwargs: Additional keyword arguments used in the analysis. These are passed on to :meth:`run_analysis`.