StepsPipeline =============================================== .. py:class:: petpal.pipelines.steps_containers.StepsPipeline(name: str, step_containers: list[StepsContainer]) A pipeline for managing and executing a sequence of steps organized in containers, with support for dependencies. This class allows for the addition, removal, and execution of step containers, as well as managing dependencies between the steps. :ivar name: Name of the steps pipeline. :vartype name: str :ivar step_containers: Dictionary of step containers in the pipeline. :vartype step_containers: dict[str, StepsContainer] :ivar dependency_graph: Directed acyclic graph representing dependencies between steps. :vartype dependency_graph: nx.DiGraph .. seealso:: :class:`StepsContainer` Initializes the StepsPipeline with a name and an optional list of step containers. :param name: Name of the steps pipeline. :type name: str :param step_containers: Optional list of step containers to add to the pipeline. :type step_containers: list[StepsContainer] .. py:method:: __repr__() Provides an unambiguous string representation of the TACsFromSegmentationStep instance. .. important:: This ``repr`` does not include the dependency graph. :returns: *str* -- A string representation showing how the instance can be recreated. .. py:method:: __str__() -> str Returns a detailed string representation of the StepsPipeline instance. :returns: *str* -- A string describing the steps-pipeline, including its name, the steps in each of the steps-containers, and the output dependencies of each step. .. py:method:: add_container(step_container: StepsContainer) Adds a step container to the pipeline. :param step_container: The step container to add. :type step_container: StepsContainer :raises TypeError: If the step container is not an instance of StepsContainer. :raises KeyError: If a container with the same name already exists. .. py:method:: __call__() Executes all steps in the pipeline in topologically sorted order. .. py:method:: add_step(container_name: str, step: StepType) Adds a step to a specified container in the pipeline. :param container_name: The name of the container to add the step to. :type container_name: str :param step: The step to add. :type step: StepType :raises KeyError: If the container or step name does not exist or if the step name already exists. .. py:method:: remove_step(step: str) Removes a step from the pipeline based on its name. :param step: The name of the step to remove. :type step: str :raises KeyError: If the step name does not exist. .. py:method:: print_steps_names(container_name: Union[str, None] = None) Prints the names of all steps in the pipeline or a specific container. :param container_name: The name of the container to print step names from. If None, prints step names from all containers. :type container_name: Union[str, None], optional :raises KeyError: If the container name does not exist. .. py:method:: print_steps_details(container_name: Union[str, None] = None) Prints the details of all steps in the pipeline or a specific container. :param container_name: The name of the container to print step details from. If None, prints step details from all containers. :type container_name: Union[str, None], optional :raises KeyError: If the container name does not exist. .. py:method:: add_dependency(sending: str, receiving: str) Adds a dependency between two steps in the pipeline. :param sending: The name of the sending step. :type sending: str :param receiving: The name of the receiving step. :type receiving: str :raises KeyError: If either step name does not exist. :raises RuntimeError: If adding the dependency creates a cycle in the dependency graph. .. py:method:: get_step_from_node_label(node_label: str) -> StepType Retrieves a step object based on its node label in the dependency graph. :param node_label: The label of the node representing the step. :type node_label: str :returns: *StepType* -- The step object. :raises KeyError: If the step name does not exist in the graph. .. py:method:: update_dependencies_for(step_name: str, verbose=False) Updates the dependencies for a specified step, setting inputs from the outputs of its dependencies. Gets the list of steps that are sending outputs to this step. The order of dependency may matter depending on the implementation of `set_input_as_output_from` for the step. :param step_name: The name of the step to update dependencies for. :type step_name: str :param verbose: If True, prints detailed information during the update process. Defaults to False. :type verbose: bool, optional .. py:method:: update_dependencies(verbose=False) Updates the dependencies for all steps in the pipeline. :param verbose: If True, prints detailed information during the update process. Defaults to False. :type verbose: bool, optional .. py:method:: get_steps_potential_run_state() -> dict Gets a dictionary representing the potential run state of all steps in topologically sorted order. :returns: *dict* -- Dictionary mapping step names to their potential run state (True if the step can potentially run, False otherwise). .. py:method:: can_steps_potentially_run() -> bool Checks if all steps in the pipeline can potentially run. :returns: *bool* -- True if all steps can potentially run, False otherwise. .. py:method:: plot_dependency_graph(figsize: tuple = (12, 12), node_options: Union[dict, None] = None, label_options: Union[dict, None] = None, draw_options: Union[dict, None] = None) -> None Plots the dependency graph of the steps pipeline. :param figsize: Figure size for the plot. Defaults to (12, 12). :type figsize: tuple, optional :param node_options: Additional options for drawing nodes. Defaults to None. :type node_options: dict, optional :param label_options: Additional options for node labels. Defaults to None. :type label_options: dict, optional :param draw_options: Additional options for the draw_networkx function. Defaults to None. :type draw_options: dict, optional .. rubric:: Notes We have the following node options. .. code-block:: python default_node_options = {'node_size': 2000, 'node_color': 'w', 'node_shape': 'o'} default_label_options = {'verticalalignment': 'center', 'clip_on': False, 'font_size': 15, 'bbox' : dict(facecolor='azure', edgecolor='blue', boxstyle='round', alpha=0.25, linewidth=2) } default_draw_options = {'with_labels': True, 'arrows': True, 'arrowsize': 30, 'width': 2} .. py:method:: print_dependency_graph() Prints a textual representation of the dependency graph for the steps pipeline. This method outputs the steps in the pipeline in topologically sorted order, showing their dependencies. For each step, it lists the subsequent steps that depend on it, formatted in a tree-like structure. .. py:method:: default_steps_pipeline(name='PET-MR_analysis') :classmethod: Creates a default steps pipeline with predefined containers and dependencies. Contains the following step-containers: - :meth:`Pre-processing`. - :meth:`Kinetic modeling`. The pipeline has the following steps dependency: .. plot:: :include-source: :caption: The dependency graph of the steps pipeline. From raw PET `.nii` images we crop the images in each dimension based on a threshold, perform motion correction for each frame where the per-frame mean-intensity is larger than the overall time-averaged intensity of the PET series, register the PET series to anatomical space, extract all the TACs corresponding the ROIs defined via segmentation, and resample the blood TAC onto the scanner frame times as part of pre-processing. Then, we perform ROI-based graphical and full tissue compartment model fits, and parametric graphical analysis fits. from petpal.pipelines.steps_containers import StepsPipeline # Instantiate the default PET/MR pipeline my_pipe = StepsPipeline.default_steps_pipeline() # Plot the dependency graph of the steps pipeline my_pipe.plot_dependency_graph() :param name: Name of the steps pipeline. Defaults to 'PET-MR_analysis'. :type name: str, optional :returns: *StepsPipeline* -- A new StepsPipeline instance with default setup.