# germanfid/fieldaveraging architecture

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

- Interactive diagram: https://gitdiagram.com/germanfid/fieldaveraging
- Repository: https://github.com/germanfid/fieldaveraging

## Overview

##### Main Components
- User Interfaces
- CLI Interface (main.py + averager.py)
- GUI Interface (mainUI.py + ui.py + useful_graphics.py)
- Core Processing Library
- CPU Averaging (averager.py)
- GPU/CUDA Averaging (averager_cuda.py)
- Data Model & I/O
- structures.py (data classes, file parsing)
- Visualization Helpers
- useful_graphics.py (plots, charts used by GUI)
- Entry Points & Scripts
- main.py (shell mode)
- mainUI.py (GUI)
- External Dependencies
- Python packages (numpy, pandas, matplotlib, pycuda, etc.)

##### Relationships & Data Flow
- User → CLI (shell commands) or User → GUI (window events)
- CLI/GUI → Data Model (structures.py reads CSV or other sources)
- Data Model → Core Processing (calls averager or averager_cuda)
- Core Processing → returns averaged result arrays
- GUI → Visualization Helpers → renders charts/tables
- Optionally, write output back to disk via structures.py

##### Architectural Patterns
- Layered Architecture: UI layer, Processing layer, Data layer
- Strategy Pattern: two processing strategies (CPU vs CUDA) behind a common interface
- Modular Design: each Python module encapsulates a distinct responsibility

##### Detailed Component Breakdown
a. UI Layer:
- Component: CLI Frontend
- File: main.py
- Invokes: averager.py functions
- Component: GUI Frontend
- Files: mainUI.py + ui.py
- Uses: useful_graphics.py for charts
b. Core Processing:
- Module: CPU Averager
- File: averager.py
- Exposes: average_2d(), average_3d()
- Module: GPU Averager
- File: averager_cuda.py
- Exposes: cuda_average()
c. Data Model & I/O:
- Module: structures.py
- Classes: StreamData, FieldData
- Responsibilities: parse CSV, hold numerical arrays
d. Visualization:
- Module: useful_graphics.py
- Functions: plot_contour(), plot_surface()
- Module: ui.py
- Helper widgets for GUI layout

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User
    User((User)):::user

    %% User Interfaces
    subgraph "User Interfaces"
        direction TB
        CLI["CLI Frontend"]:::ui
        GUI["GUI Frontend"]:::ui
    end

    %% Data Model & I/O
    Data["Data Model & I/O<br/>(structures.py)"]:::data

    %% Core Processing
    subgraph "Core Processing"
        direction TB
        CPU["CPU Averager<br/>(averager.py)"]:::process
        GPU["GPU Averager<br/>(averager_cuda.py)"]:::process
    end

    %% Visualization Layer
    subgraph "Visualization"
        direction TB
        Viz["Visualization Helpers<br/>(useful_graphics.py)"]:::viz
        GUILayout["GUI Layout Helpers<br/>(ui.py)"]:::viz
    end

    %% Storage & External
    FS[(File System)]:::storage
    ExtDeps[/"External Dependencies"/]:::storage

    %% Connections
    User -->|"shell commands"| CLI
    User -->|"GUI events"| GUI

    CLI -->|"read/write data"| Data
    GUI -->|"read/write data"| Data

    Data -->|"StreamData input"| CPU
    Data -->|"StreamData input"| GPU

    CPU -->|"ndarray results"| Data
    GPU -->|"ndarray results"| Data

    GUI -->|"call plots"| Viz
    Viz -->|"render charts"| GUI

    GUI -->|"use widgets"| GUILayout

    Data -->|"reads/writes CSV"| FS
    FS -->|"stores data"| Data

    ExtDeps -.-> CLI
    ExtDeps -.-> GUI
    ExtDeps -.-> CPU
    ExtDeps -.-> GPU

    %% Click Events
    click CLI "https://github.com/germanfid/fieldaveraging/blob/main/main.py"
    click GUI "https://github.com/germanfid/fieldaveraging/blob/main/mainUI.py"
    click CPU "https://github.com/germanfid/fieldaveraging/blob/main/averager.py"
    click GPU "https://github.com/germanfid/fieldaveraging/blob/main/averager_cuda.py"
    click Data "https://github.com/germanfid/fieldaveraging/blob/main/structures.py"
    click Viz "https://github.com/germanfid/fieldaveraging/blob/main/useful_graphics.py"
    click GUILayout "https://github.com/germanfid/fieldaveraging/blob/main/ui.py"

    %% Styles
    classDef user fill:#dddddd,stroke:#333,stroke-width:1px;
    classDef ui fill:#cce5ff,stroke:#339,stroke-width:1px;
    classDef data fill:#fff2cc,stroke:#996600,stroke-width:1px;
    classDef process fill:#d4edda,stroke:#2d6a4f,stroke-width:1px;
    classDef viz fill:#ffe5d9,stroke:#d35400,stroke-width:1px;
    classDef storage fill:#eeeeee,stroke:#666666,stroke-width:1px,stroke-dasharray: 5 5;
```
