Plot ========================================== .. py:class:: petpal.visualizations.graphical_plots.Plot(input_tac_path: str, roi_tac_path: str, threshold_in_mins: float, method_name: str, output_directory: str, output_filename_prefix: str = '') A class used to generate and save graphical analysis plots of PET Time-Activity Curves (TACs). This class provides a simple and convenient interface to generate plots from TACs for the 'patlak', 'logan', or 'alt-logan' methods and save them in the specified output directory. The plots are saved in both PNG and PDF formats. It is initialized with paths to the input TACs, the method name, the output directory, and an optional filename prefix. During initialization, it checks the validity of the file paths and directory, loads the TACs, and selects the appropriate figure class based on the given method. Later on, the `save_figure` method can be called to generate and save the plots. :ivar input_tac_path: Path to the input TAC file. :vartype input_tac_path: str :ivar roi_tac_path: Path to the Region of Interest (ROI) TAC file. :vartype roi_tac_path: str :ivar output_directory: Path to the directory where the plot output will be saved. :vartype output_directory: str :ivar method_name: Name of the method for generating the plot ('patlak', 'logan', 'alt-logan'). :vartype method_name: str :ivar thresh_in_mins: A threshold in minutes below which data points will be discarded from the plot. :vartype thresh_in_mins: float :ivar output_filename_prefix: An optional prefix for the output filenames. :vartype output_filename_prefix: str .. rubric:: Example An example of how to use this class to save a Patlak graphical analysis plot: .. code-block:: python import petpal.graphical_plots as pet_plt # ptac_path points to a plasma TAC (or input TAC) # ttac_path points to a ROI TAC. grph_plot = pet_plt.Plot(input_tac_path=ptac_path, roi_tac_path=ttac_path, threshold_in_mins=30.0, method_name='patlak', output_directory='./', output_filename_prefix="plot") grph_plot.save_figure() Initializes the :class:`Plot` object given the paths and the method. During the initialization, it validates the given file paths and directory, and selects the appropriate figure class based on the provided method name. :param input_tac_path: Path to the input Time Activity Curve (TAC) file. :type input_tac_path: str :param roi_tac_path: Path to the Region of Interest (ROI) TAC file. :type roi_tac_path: str :param threshold_in_mins: Threshold in minutes below which data points will be discarded. :type threshold_in_mins: float :param method_name: Name of the method to be used ('patlak', 'logan', or 'alt-logan'). :type method_name: str :param output_directory: Path to the directory where output files will be stored. :type output_directory: str :param output_filename_prefix: Prefix to be appended to the output files. Defaults to an empty string. :type output_filename_prefix: str, optional :raises ValueError: If any of the file paths or the directory path does not exist, or if the method name is invalid. .. note:: This method does not return a value. It's an initializer of this class. Calls: * :meth:`_validate_filepath` * :meth:`_validate_directory` * :func:`safe_load_tac` * :meth:`_select_fig_class_based_on_method` .. py:method:: save_figure() Creates and saves the figure in both PNG and PDF formats. We first safely load the TACS. Then, this method generates the figure using the method selected during the initialization of the class. The figure is then saved inside the specified output directory with a filename based on parameters provided at initialization. The saved files are in both PNG (with a resolution of 150 dpi) and PDF formats (with the PDF file being saved with transparency). .. note:: This method does not return any value. It is responsible for saving the generated figure to the specified output directory in PNG and PDF formats. :raises Exception: An error occurred while loading the TACs from the input or ROI files. .. py:method:: _validate_filepath(filename: str) -> None :staticmethod: Checks if the provided filename is a valid file. This is a private static method and should be called internally by the class while processing files. If the file is not valid, it raises a ValueError. :param filename: The path to the file. :type filename: str :raises ValueError: if the file at provided path does not exist. No return value. .. py:method:: _validate_directory(directory: str) -> None :staticmethod: Validates if the provided directory path is an existing directory. This is a private static method and should be called internally by the class while processing directories. If the directory does not exist, it raises a ValueError. :param directory: Path to the directory. :type directory: str :raises ValueError: if the provided directory path does not exist. No return value. .. py:method:: _select_fig_class_based_on_method(method_name: str) -> Union[Type[PatlakPlot], Type[LoganPlot], Type[AltLoganPlot]] :staticmethod: Selects and returns the appropriate class based on the provided method name. This private static method returns the corresponding class object (`PatlakPlot`, `LoganPlot`, or `AltLoganPlot`) according to the provided method name ('patlak', 'logan', or 'alt-logan'). :param method_name: Name of the method. :type method_name: str :returns: :class:`PatlakPlot` | :class:`LoganPlot` | :class:`AltLoganPlot` -- Corresponding class. :raises ValueError: The method name is invalid. .. seealso:: * :class:`PatlakPlot` * :class:`LoganPlot` * :class:`AltLoganPlot`