RegionalTacFigure ================================================= .. py:class:: petpal.visualizations.tac_plots.RegionalTacFigure(tacs_dir: str, figsize: tuple = (8, 4), xlabel: str = '$t$ [minutes]', ylabel: str = 'TAC [$\\mathrm{kBq/ml}$]', plot_type='both') Bases: :py:obj:`TacFigure`, :py:obj:`petpal.utils.time_activity_curve.MultiTACAnalysisMixin` Handle plotting regional TACs generated with PETPAL. Used when visualizing activity in several brain regions in the same participant, especially after running PETPAL's :py:func:`~petpal.preproc.regional_tac_extraction.write_tacs` or :py:class:`~petpal.preproc.symmetric_geometric_transfer_matrix.Sgtm` methods. Example: .. code-block:: python from petpal.visualizations.tac_plots import RegionalTacFigure from petpal.utils.time_activity_curve import TimeActivityCurve ## Load up an individual TAC file my_tac = TimeActivityCurve.from_tsv("/path/to/tac.tsv") ## Select a list of regions to plot and the folder containing TAC files for those regions my_regions = ['Putamen', 'Cerebellum', 'CorticalGrayMatter'] my_fig = tac_plots.RegionalTacFigure(tacs_dir="/path/to/tacs/folder/") ## Add the individual TAC and the regional TACs to the figure my_fig.add_errorbar(*my_tac.tac_werr, label='Whole Brain') my_fig.plot_tacs_in_regions_list(regions=my_regions) ## Write the figure to file my_fig.write_fig(out_fig_path="/path/to/plot.png") plt.show() # Comment this out if you don't want to see the figure # plt.close() # Uncomment this if you don't want to see the figure Initialize the TacFigure with two subplots, one with a linear scale and the other with a semi-logarithmic scale. :param figsize: The total size of the figure. Defaults to an 8x4 inches figure. :type figsize: tuple :param xlabel: The label for the x-axis. Defaults to '$t$ [minutes]'. :type xlabel: str :param ylabel: The label for the y-axis. Defaults to 'TAC [$\mathrm{kBq/ml}$]'. :type ylabel: str :param plot_type: Type of plot, with options 'linear', 'log', or 'both'. :type plot_type: str .. py:property:: tacs_objects_dict A dictionary containing region name/TAC object pairs for all TAC files found in tacs_dir. .. py:method:: plot_tacs_in_regions_list(regions: list[str], show_legend: bool = True, colormap: str = 'Dark2', **kwargs) Plot TACs for a list of provided regions without errorbars. Region names correspond to abbreviated segment names in the dseg file used to generate the regions. :param regions: A list of region names whose TACs are plotted. :type regions: list[str] :param show_legend: Show the legend with region names in the resulting figure. Default True. :type show_legend: bool :param colormap: A matplotlib color map used to select colors of different TAC plots. Default 'Dark2'. :type colormap: str :param kwargs: Additional keyword arguments for the plt.plot() function. :type kwargs: dict .. py:method:: plot_tacs_in_regions_list_with_errorbar(regions: list[str], show_legend: bool = True, colormap: str = 'Dark2', **kwargs) Plot TACs for a list of provided regions with errorbars. Region names correspond to abbreviated segment names in the dseg file used to generate the regions. :param regions: A list of region names whose TACs are plotted. :type regions: list[str] :param show_legend: Show the legend with region names in the resulting figure. Default True. :type show_legend: bool :param colormap: A matplotlib color map used to select colors of different TAC plots. Default 'Dark2'. :type colormap: str :param kwargs: Additional keyword arguments for the plt.errorbar() function. :type kwargs: dict .. py:method:: plot_all_regional_tacs(show_legend: bool = True, colormap='Dark2', **kwargs) Plot TACs for all TACs found in a folder without errorbars. Region names correspond to abbreviated segment names in the dseg file used to generate the regions. :param show_legend: Show the legend with region names in the resulting figure. Default True. :type show_legend: bool :param colormap: A matplotlib color map used to select colors of different TAC plots. Default 'Dark2'. :type colormap: str :param kwargs: Additional keyword arguments for the plt.plot() function. :type kwargs: dict .. py:method:: plot_all_regional_tacs_with_errorbar(show_legend: bool = True, colormap='Dark2', **kwargs) Plot TACs for all TACs found in a folder with errorbars. Region names correspond to abbreviated segment names in the dseg file used to generate the regions. :param show_legend: Show the legend with region names in the resulting figure. Default True. :type show_legend: bool :param colormap: A matplotlib color map used to select colors of different TAC plots. Default 'Dark2'. :type colormap: str :param kwargs: Additional keyword arguments for the plt.errorbar() function. :type kwargs: dict .. py:method:: setup_linear_subplot(xlabel: str, ylabel: str, figsize: tuple) Get the figure and axes objects for a 1x1 MatPlotLib subplot. :param xlabel: The label for the x-axis. :type xlabel: str :param ylabel: The label for the y-axis. :type ylabel: str :param figsize: Size of the figure. :type figsize: tuple .. py:method:: setup_log_subplot(xlabel: str, ylabel: str, figsize: tuple) Get the figure and axes objects for a 1x1 MatPlotLib subplot. :param xlabel: The label for the x-axis. :type xlabel: str :param ylabel: The label for the y-axis. :type ylabel: str :param figsize: Size of the figure. :type figsize: tuple .. py:method:: setup_linear_and_log_subplot(xlabel: str, ylabel: str, figsize: tuple) Get the figure and axes objects for a 1x2 MatPlotLib subplot. :param xlabel: The label for the x-axis. :type xlabel: str :param ylabel: The label for the y-axis. :type ylabel: str :param figsize: Size of the figure. :type figsize: tuple .. py:method:: add_tac(tac_times: numpy.ndarray, tac_vals: numpy.ndarray, **kwargs) Add a TAC to both subplots. :param tac_times: The time points for the TAC. :type tac_times: np.ndarray :param tac_vals: The corresponding values for the TAC. :type tac_vals: np.ndarray :param kwargs: Additional keyword arguments for the plot() function. :type kwargs: dict .. py:method:: add_errorbar(tac_times: numpy.ndarray, tac_vals: numpy.ndarray, uncertainty: numpy.ndarray, **kwargs) Add a lineplot with errorbars to the figure. :param tac_times: Array containing times at which TAC is sampled. :type tac_times: np.ndarray :param tac_vals: Array containing TAC activity concentration. :type tac_vals: np.ndarray :param uncertainty: Array containing uncertainties in TAC measurements. :type uncertainty: np.ndarray :param kwargs: Additional keyword arguments for the plt.errorbar() function. :type kwargs: dict .. py:method:: set_ylim_min_to_zero(**kwargs) Set the y-axis lower limit to zero. :param kwargs: Additional keyword arguments for the set_ylim() function. :type kwargs: dict .. py:method:: gen_legend() Generate a legend using the labels provided in the add_tac() method. .. note:: It is recommended to add all TACs before generating the legend. Any TACs added after the legend is generated will not be included in the legend. .. py:method:: write_fig(out_fig_path: str, **kwargs) Write the figure to a common image file type, such as .png or .jpg. Applies :meth:`plt.savefig` to figure object. :param out_fig_path: Path to the file the figure will be written to. :type out_fig_path: str :param kwargs: Additional key word arguments passed to plt.savefig() :type kwargs: dict .. py:property:: input_tac_path Gets the input TAC file path. .. py:property:: tacs_dir Gets the TAC directory path. .. py:property:: reference_tac_path Gets the reference TAC file path. .. py:method:: is_valid_tacs_dir(tacs_dir: str) Validates the TAC directory by checking for TAC files. :param tacs_dir: Directory to validate. :type tacs_dir: str :returns: *bool* -- True if valid, otherwise False. .. py:method:: get_tacs_list_from_dir(tacs_dir: str) -> list[str] :staticmethod: Retrieves a sorted list of TAC file paths from a directory. :param tacs_dir: Directory from which to retrieve TAC files. :type tacs_dir: str :returns: *list[str]* -- Sorted list of TAC file paths. .. py:method:: get_tacs_objects_dict_from_files_list(tacs_files_list: list[str]) :staticmethod: Creates a dict of TAC objects from a list of file paths. :param tacs_files_list: List of TAC file paths. :type tacs_files_list: list[str] :returns: *dict* -- Dictionary of region name-TAC object pairs. .. py:method:: get_tacs_objects_dict_from_dir(tacs_dir: str) -> dict :staticmethod: Creates a dict of TAC objects from a directory of TAC files. :param tacs_dir: A directory of TAC files. :type tacs_dir: str :returns: *dict* -- Dictionary of region name-TAC object pairs. .. py:method:: get_tacs_objects_list_from_files_list(tacs_files_list: list[str]) :staticmethod: Creates a list of TAC objects from a list of file paths. :param tacs_files_list: List of TAC file paths. :type tacs_files_list: list[str] :returns: *list[TimeActivityCurve]* -- List of TAC objects. .. py:method:: get_tacs_vals_from_objs_list(tacs_objects_list: list[TimeActivityCurve]) :staticmethod: Extracts TAC values from a list of TAC objects. :param tacs_objects_list: List of TAC objects. :type tacs_objects_list: list[TimeActivityCurve] :returns: *list* -- List of TAC values. .. py:method:: get_tacs_vals_from_dir(tacs_dir: str) Retrieves TAC values from files in a specified directory. :param tacs_dir: Directory containing TAC files. :type tacs_dir: str :returns: *list* -- List of TAC values. .. py:method:: capitalize_first_char_of_str(input_str: str) :staticmethod: Capitalize only the first character of a string, leaving the remainder unchanged. :param input_str: The string to capitalize the first character of. :type input_str: str :returns: *output_str (str)* -- The string with only the first character capitalized. .. py:method:: infer_segmentation_label_from_tac_path(tac_path: str, tac_id: int) :staticmethod: Infers a segmentation label from a TAC file path by analyzing the filename. This method extracts a segment label from the filename of a TAC file. It checks the presence of a `seg-` marker in the filename, which is followed by the segment name. This segment name is then formatted with each part capitalized. If no segment label is found, a default unknown label is generated using the TAC's ID. :param tac_path: Path of the TAC file. :type tac_path: str :param tac_id: ID of the TAC. :type tac_id: int :returns: *str* -- Inferred segmentation label. .. py:method:: infer_segmentation_labels_for_tacs() Infers segmentation labels for TACs. :returns: *list[str]* -- List of inferred segmentation labels. .. seealso:: :meth:`infer_segmentation_label_from_tac_path`