# wang-fujin/battnn architecture

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

- Interactive diagram: https://gitdiagram.com/wang-fujin/battnn
- Repository: https://github.com/wang-fujin/battnn

## Overview

##### Project Type and Purpose
- This is a Python‐based research pipeline for battery modeling and prognosis. It ingests three kinds of data (Lab, NASA, simulated), trains three model variants (physics‐informed BattNN, CNN, RNN), and outputs serialized results for analysis. It is not a deployed service but a batch experiment framework.

a. Data Sources (left‐most layer)
- LabData (./data/LabData/*.npy)
- NASAData (./data/NASA11/*.mat)
- SimData (./data/SimData/{train,test}/*.npy)
- External: full XJTU dataset (hyperlink)
b. DataLoader Module
- load_Lab_data.py
- load_NASA_data.py
- load_sim_data.py
- __init__.py
c. Preprocessing & Utilities
- functions.py (common transforms, metrics, batching)
d. Model Definitions
- BattNN.py (physics‐informed NN)
- CNN.py
- RNN.py
e. Orchestrators (entry points)
- main_LabData.py
- main_NASAData.py
- main_SimData.py
f. Results Storage
- ./results/*.pkl (trained model checkpoints)
- ./results/test record/*.txt (evaluation logs)
- ./results/batch size and seq len/*.txt (config sweeps)

##### Interactions and Data Flow
- DataLoader → Preprocessing/Utilities (functions.py) → Batch generator
- Batch generator → Model Definitions → Training loop
- Training loop → Results Storage (pickle model, write logs)
- Orchestrator scripts coordinate the above steps per data type

##### Architectural Patterns & Principles
- Modular separation: Data loading, preprocessing, modeling, orchestration
- Single responsibility: each module focuses on one task
- Reusability: functions.py and DataLoader are shared across experiments

##### Technologies & Frameworks
- Python 3
- NumPy (.npy files), SciPy or h5py (for .mat)
- Likely PyTorch or TensorFlow inside model scripts (implicit)
- Pickle for model serialization

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Orchestrators (entry points)
    mainLab["main_LabData.py"]:::orchestrator
    mainNASA["main_NASAData.py"]:::orchestrator
    mainSim["main_SimData.py"]:::orchestrator

    %% External Dataset
    external["External: XJTU dataset"]:::external

    %% Data Sources
    LabData["LabData (.npy)"]:::data
    NASAData["NASAData (.mat)"]:::data
    SimData["SimData (.npy)"]:::data

    %% Core Modules
    DataLoader["DataLoader Module"]:::core
    Functions["Preprocessing & Utilities (functions.py)"]:::core

    %% Model Variants
    subgraph "Model Variants"
        BattNN["BattNN.py"]:::model
        CNN["CNN.py"]:::model
        RNN["RNN.py"]:::model
    end

    %% Training and Results
    Train["Training/Eval Loop"]:::core
    Results["Results Storage (.pkl, .txt)"]:::data
    Analysis["Analysis: test record"]:::data

    %% Connections
    mainLab -->|runs pipeline| DataLoader
    mainNASA -->|runs pipeline| DataLoader
    mainSim -->|runs pipeline| DataLoader

    external -->|"download .mat/.npy"| LabData
    external -->|"download .mat/.npy"| NASAData
    external -->|"download .npy"| SimData

    LabData -->|".npy arrays"| DataLoader
    NASAData -->|".mat arrays"| DataLoader
    SimData -->|".npy arrays"| DataLoader

    DataLoader -->|"raw arrays"| Functions
    Functions -->|"batches"| BattNN
    Functions -->|"batches"| CNN
    Functions -->|"batches"| RNN

    BattNN -->|"model outputs"| Train
    CNN -->|"model outputs"| Train
    RNN -->|"model outputs"| Train

    Train -->|".pkl model"| Results
    Train -->|".txt logs"| Results

    Results -->|"for analysis"| Analysis

    %% Click Events
    click mainLab "https://github.com/wang-fujin/battnn/blob/main/main_LabData.py"
    click mainNASA "https://github.com/wang-fujin/battnn/blob/main/main_NASAData.py"
    click mainSim "https://github.com/wang-fujin/battnn/blob/main/main_SimData.py"
    click LabData "https://github.com/wang-fujin/battnn/tree/main/data/LabData/"
    click NASAData "https://github.com/wang-fujin/battnn/tree/main/data/NASA11/"
    click SimData "https://github.com/wang-fujin/battnn/tree/main/data/SimData/"
    click DataLoader "https://github.com/wang-fujin/battnn/tree/main/dataloader/"
    click Functions "https://github.com/wang-fujin/battnn/blob/main/functions.py"
    click BattNN "https://github.com/wang-fujin/battnn/blob/main/BattNN.py"
    click CNN "https://github.com/wang-fujin/battnn/blob/main/CNN.py"
    click RNN "https://github.com/wang-fujin/battnn/blob/main/RNN.py"
    click Results "https://github.com/wang-fujin/battnn/tree/main/results/"

    %% Styles
    classDef data fill:#BBE1FA,stroke:#1E90FF,color:#000
    classDef core fill:#FFD580,stroke:#FFA500,color:#000
    classDef model fill:#C8E6C9,stroke:#388E3C,color:#000
    classDef orchestrator fill:#E0E0E0,stroke:#9E9E9E,color:#000
    classDef external fill:#ADE8F4,stroke:#0077B6,color:#000
```
