Plot#
- 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.
- Variables:
input_tac_path (str) – Path to the input TAC file.
roi_tac_path (str) – Path to the Region of Interest (ROI) TAC file.
output_directory (str) – Path to the directory where the plot output will be saved.
method_name (str) – Name of the method for generating the plot (‘patlak’, ‘logan’, ‘alt-logan’).
thresh_in_mins (float) – A threshold in minutes below which data points will be discarded from the plot.
output_filename_prefix (str) – An optional prefix for the output filenames.
Example
An example of how to use this class to save a Patlak graphical analysis plot:
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
Plotobject 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.
- Parameters:
input_tac_path (str) – Path to the input Time Activity Curve (TAC) file.
roi_tac_path (str) – Path to the Region of Interest (ROI) TAC file.
threshold_in_mins (float) – Threshold in minutes below which data points will be discarded.
method_name (str) – Name of the method to be used (‘patlak’, ‘logan’, or ‘alt-logan’).
output_directory (str) – Path to the directory where output files will be stored.
output_filename_prefix (str, optional) – Prefix to be appended to the output files. Defaults to an empty string.
- 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:
- 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.
- static _validate_filepath(filename: str) None#
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.
- Parameters:
filename (str) – The path to the file.
- Raises:
ValueError – if the file at provided path does not exist.
No return value.
- static _validate_directory(directory: str) None#
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.
- Parameters:
directory (str) – Path to the directory.
- Raises:
ValueError – if the provided directory path does not exist.
No return value.
- static _select_fig_class_based_on_method(method_name: str) Type[PatlakPlot] | Type[LoganPlot] | Type[AltLoganPlot]#
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’).
- Parameters:
method_name (str) – Name of the method.
- Returns:
PatlakPlot|LoganPlot|AltLoganPlot– Corresponding class.- Raises:
ValueError – The method name is invalid.
See also
PatlakPlotLoganPlotAltLoganPlot