# mozanunal/sparsect architecture

> Architecture diagram of the GitHub repository mozanunal/sparsect, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mozanunal/sparsect
- Repository: https://github.com/mozanunal/sparsect

## Overview

- Data & Dataset Management:
- Modules under sparse_ct/data (benchmark scripts, benchmark_human, bp_160u_dense, etc.) and sparse_ct/dataset provide the entry points for data handling.
- As the "Data Input" component from which benchmark datasets and experimental data are loaded.
- Model Component:
- That these modules represent different neural network architectures used for reconstruction.
- Loss and Metric Calculation:
- sparse_ct/loss and sparse_ct/metric contain functions to compute various losses (e.g., perceptual loss, TV loss) and performance metrics.
- Reconstruction Algorithms:
- The core reconstruction logic is found in sparse_ct/reconstructor_2d which contains multiple reconstruction methods (analytic, iterative, supervised, self-supervised, noise2self variants, etc.).
- Present this set as the “Reconstruction Engine” highlighting its role as the central abstraction that implements the Reconstructor classes expected for development and extension.
- Experiment & Example Scripts:
- The sparse_ct/example directory includes scripts that demonstrate how to run benchmarks, supervise training, and generate paper figures.
- This should be grouped as “Demonstration & Experimentation” modules that interface with both the data, models, and the reconstruction engine.
- External/Supporting Modules:
- “Tool” (sparse_ct/tool.py) along with external dependencies and utilities (e.g., dependencies mentioned in requirements.txt, usage of noise2self and deep image prior repositories).
- Research Papers & Documentation:
- Even though not part of the runtime code, the papers directory and docs folder contain experiment-specific scripts and documentation.

##### Relationships and interactions
- Data flows from “Data Input” to the “Dataset” module, which then provides preprocessed inputs to the “Model” and “Reconstruction Engine”.
- The “Reconstruction Engine” utilizes models from the “Model” component, employs loss functions from “Loss Functions”, and feeds output to a postprocessing and evaluation phase (“Metrics”).
- “Experiment & Example” scripts orchestrate these interactions by setting up data paths, instantiating specific reconstruction methods, initiating training or inference, and subsequently assessing performance.
- External libraries (e.g., from noise2self and deep image prior) should be depicted as dependencies feeding into the model and reconstruction components.

##### Architectural patterns and design principles
- Modularity and separation of concerns: components for data, models, reconstruction algorithms, losses/metrics, and experimental orchestration are clearly segregated.
- Usage of an abstract “Reconstructor” base class (as mentioned in the README’s contribution guideline), which allows for plug-and-play substitution of reconstruction techniques.
- That the system might follow an MVP (Minimum Viable Prototype) pattern common in research codebases where different experiments (dgr, self_super_ct_reconstruction) share common underlying modules.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Data & Dataset Management"
        DM["Data Management"]:::data
        DS["Dataset"]:::data
    end

    subgraph "Model Layer"
        MC["Model Component"]:::model
    end

    subgraph "Reconstruction"
        RE["Reconstruction Engine"]:::engine
    end

    subgraph "Evaluation"
        LF["Loss Functions"]:::loss
        MT["Metrics"]:::metrics
    end

    subgraph "Experimentation"
        EXP["Experiment & Example Scripts"]:::experiment
    end

    subgraph "Support"
        EXT["External Modules"]:::external
    end

    subgraph "Research & Documentation"
        DC["Docs"]:::research
        PP["Papers"]:::research
    end

    %% Data flows to Model and Reconstruction Engine
    DM -->|"data"| MC
    DS -->|"data"| MC
    DM -->|"raw_data"| RE
    DS -->|"data"| RE

    %% Model feeds into Reconstruction Engine
    MC -->|"model_output"| RE

    %% Reconstruction Engine -> Loss Functions -> Metrics
    RE -->|"reconstruction"| LF
    LF -->|"evaluation"| MT

    %% External dependencies feed into Model and Reconstruction Engine
    EXT -->|"dependency"| MC
    EXT -->|"dependency"| RE

    %% Experiment scripts orchestrate the workflow
    EXP -->|"setup"| DM
    EXP -->|"setup"| DS
    EXP -->|"experiment"| MC
    EXP -->|"experiment"| RE
    EXP -->|"experiment"| LF
    EXP -->|"experiment"| MT

    %% Experimentation links to Research & Documentation for guidance
    EXP -->|"documentation"| DC
    EXP -->|"paper_references"| PP

    %% Click Events
    click DM "https://github.com/mozanunal/sparsect/tree/master/sparse_ct/data"
    click DS "https://github.com/mozanunal/sparsect/tree/master/sparse_ct/dataset"
    click MC "https://github.com/mozanunal/sparsect/tree/master/sparse_ct/model"
    click RE "https://github.com/mozanunal/sparsect/tree/master/sparse_ct/reconstructor_2d"
    click LF "https://github.com/mozanunal/sparsect/tree/master/sparse_ct/loss"
    click MT "https://github.com/mozanunal/sparsect/blob/master/sparse_ct/metric.py"
    click EXP "https://github.com/mozanunal/sparsect/tree/master/sparse_ct/example"
    click EXT "https://github.com/mozanunal/sparsect/blob/master/sparse_ct/tool.py"
    click DC "https://github.com/mozanunal/sparsect/tree/master/docs"
    click PP "https://github.com/mozanunal/sparsect/tree/master/papers"

    %% Styles
    classDef data fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef model fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef engine fill:#F5CBA7,stroke:#C0392B,stroke-width:2px;
    classDef loss fill:#D2B4DE,stroke:#8E44AD,stroke-width:2px;
    classDef metrics fill:#A3E4D7,stroke:#16A085,stroke-width:2px;
    classDef experiment fill:#F7DC6F,stroke:#B7950B,stroke-width:2px;
    classDef external fill:#E6B0AA,stroke:#922B21,stroke-width:2px;
    classDef research fill:#D5F5E3,stroke:#27AE60,stroke-width:2px;
```
