# ummisco/ecgtizer architecture

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

- Interactive diagram: https://gitdiagram.com/ummisco/ecgtizer
- Repository: https://github.com/ummisco/ecgtizer

## Overview

##### Main Components
- Input Source: The ECG PDF files (for instance, the contents in the “data/PTB-XL/PDF” directory).
- Extraction Module: Represented by the ECGtizer class and related extraction functions (in ecgtizer/extraction_functions.py, ecgtizer/ecgtizer.py, and the other conversion scripts like PDF2XML.py and XML2PDF.py). This module reads the PDF file and extracts ECG leads.
- Plot/Visualization & Save Module: Functions for plotting and saving the extracted leads, as shown in the “plot” and “save_xml” instructions.
- Completion Module: A separate processing step that uses a deep learning model (the file inside the “model” directory) to “complete” ECG leads. This leverages the “completion” functionality in ecgtizer/completion.py.
- User Interface / Access Points: Illustrate both the command-line interface (main script: ECGtizer_main.py) and the interactive usage via Jupyter notebooks (Test_ECGtizer.ipynb).
- Environment and Dependency Management: Note the Conda environment configuration file (ecgtizer_env.yml) to reflect the dependency setup and supporting libraries like PyTorch.

##### Relationships and Data Flow
- Within the Extraction Module, delineate that the process produces “Extracted Leads” (potentially stored in an XML format).
- Then, from both the extraction and (if used) completion modules, show flows leading to the “Visualization/Save Module” where the results can be plotted and saved.
- Finally, indicate that these functionalities are accessible either via command-line (via ECGtizer_main.py) or via a Jupyter Notebook.

##### Architectural Patterns and Design Principles
- The separation of concerns is clearly noticeable: one set of functions for extraction, another set for plotting/saving, and a distinct component for lead completion.
- You might want to indicate the modular design by grouping the related Python modules under an “ECGtizer Engine” component.

##### Relevant Technologies and Libraries
- A node or label indicating “Conda Environment” with reference to ecgtizer_env.yml.
- Use of PyTorch (model/Model_Completion.pth) in the Completion Module.
- If needed, mention any plotting or file handling libraries (implied though not explicitly stated).

## Diagram (Mermaid)

```mermaid
graph TD
    %% Input Source
    pdf_input["PDF Input (ECG PDF Files)"]:::source
    click pdf_input "https://github.com/ummisco/ecgtizer/tree/main/data/PTB-XL/PDF"

    %% Conda Environment node
    COND["Conda Environment (ecgtizer_env.yml)"]:::env
    click COND "https://github.com/ummisco/ecgtizer/blob/main/ecgtizer_env.yml"
    
    %% Extraction Module Subgraph
    subgraph "Extraction Module"
        direction TB
        E1["ECGtizer (ecgtizer.py)"]:::process
        click E1 "https://github.com/ummisco/ecgtizer/blob/main/ecgtizer/ecgtizer.py"
        E2["Extraction Functions (extraction_functions.py)"]:::process
        click E2 "https://github.com/ummisco/ecgtizer/blob/main/ecgtizer/extraction_functions.py"
        E3["PDF2XML Conversion (PDF2XML.py)"]:::process
        click E3 "https://github.com/ummisco/ecgtizer/blob/main/ecgtizer/PDF2XML.py"
        E4["XML2PDF Conversion (XML2PDF.py)"]:::process
        click E4 "https://github.com/ummisco/ecgtizer/blob/main/ecgtizer/XML2PDF.py"
    end

    %% Extraction Output Node
    Extracted_Leads["Extracted Leads (XML/CSV)"]:::data

    %% Completion Module Subgraph
    subgraph "Completion Module"
        direction TB
        C1["Completion Processing (completion.py)"]:::process
        click C1 "https://github.com/ummisco/ecgtizer/blob/main/ecgtizer/completion.py"
        C2["Model Inference (Deep Learning)"]:::process
        click C2 "https://github.com/ummisco/ecgtizer/blob/main/model/Model_Completion.pth"
    end

    %% Completion Output Node
    Completed_Leads["Completed ECG Leads"]:::data

    %% Plot & Save Module
    PS["Plot & Save Module"]:::output

    %% User Interface Nodes
    CLI["CLI Interface (ECGtizer_main.py)"]:::ui
    click CLI "https://github.com/ummisco/ecgtizer/blob/main/ECGtizer_main.py"
    Notebook["Notebook Interface (Test_ECGtizer.ipynb)"]:::ui
    click Notebook "https://github.com/ummisco/ecgtizer/blob/main/Test_ECGtizer.ipynb"

    %% Data Flow
    pdf_input --> E1
    E1 --> E2
    E2 --> E3
    E3 --> E4
    E4 --> Extracted_Leads

    %% Optional flow: Completion Module
    Extracted_Leads -->|"optional"| C1
    C1 --> C2
    C2 --> Completed_Leads

    %% Merging paths to Plot & Save Module
    Extracted_Leads --> PS
    Completed_Leads --> PS

    %% User Interface
    PS --> CLI
    PS --> Notebook

    %% Dependency arrows from Conda Environment
    COND -.-> E1
    COND -.-> C1

    %% Styles
    classDef source fill:#ffdead,stroke:#333,stroke-width:2px;
    classDef process fill:#add8e6,stroke:#333,stroke-width:2px;
    classDef data fill:#98fb98,stroke:#333,stroke-width:2px;
    classDef output fill:#dda0dd,stroke:#333,stroke-width:2px;
    classDef ui fill:#f4a460,stroke:#333,stroke-width:2px;
    classDef env fill:#ffb6c1,stroke:#333,stroke-width:2px;
```
