# anledinhminh/c4dl-lightningdl architecture

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

- Interactive diagram: https://gitdiagram.com/anledinhminh/c4dl-lightningdl
- Repository: https://github.com/anledinhminh/c4dl-lightningdl

## Overview

1. **Repository purpose**
   This is a research codebase for **lightning nowcasting with recurrent deep learning**. The core flow is: load multi-source geospatial data from a NetCDF dataset, convert it into model-ready feature batches, train TensorFlow-based sequence models, then evaluate and visualize forecast quality.

2. **Top-level package layout**
   The main implementation lives under `c4dllightning/`, split into four functional areas:
   - `features/` for data preparation
   - `ml/models/` for neural network building blocks and architectures
   - `analysis/` for evaluation, calibration, and ensembling
   - `visualization/` for plotting results

3. **Data boundary**
   The input dataset is external and downloaded from Zenodo as a **NetCDF file**. The repo does not appear to embed raw training data; instead, `data/` is a local mount point or working location. This creates a clear boundary between stored scientific data and the code that transforms it.

4. **Feature engineering subsystem**
   `c4dllightning/features/` contains the data interface layer:
   - `regions.py` likely defines geographic domains or spatial slicing
   - `batch.py` likely assembles training/validation batches
   - `transform.py` and `utils.py` handle preprocessing, normalization, masking, or coordinate transforms  
   This layer is the bridge from raw meteorological fields to model inputs.

5. **Modeling subsystem**
   `c4dllightning/ml/models/` is the prediction engine. It includes:
   - `layers.py` and `blocks.py` for reusable neural components
   - `rnn.py` for recurrent sequence modeling
   - `models.py` for complete model definitions
   - `optimizers.py` for training-time optimization choices  
   The architecture is centered on **TensorFlow** and recurrent deep learning, with model variants likely differing in loss, regularization, or ensemble strategy.

6. **Training entry point**
   `scripts/training.py` is the operational entry point for experiments. It likely wires together feature loading, model construction, training, and saving outputs into `models/` and `results/`. The repository is packaged via `setup.py`, so the package can be installed in editable or standard mode before running experiments.

7. **Analysis and metric subsystem**
   `c4dllightning/analysis/` handles post-training scientific evaluation:
   - `evaluation.py` computes forecast metrics and confusion matrices
   - `calibration.py` measures probabilistic calibration
   - `ensemble.py` combines multiple model outputs
   - `lagrangian.py` likely supports lead-time or trajectory-oriented evaluation  
   This is the layer that turns raw predictions into paper-ready quantitative results.

8. **Visualization boundary**
   `c4dllightning/visualization/plots.py` plus `scripts/plots_lightning.py` form the plotting pipeline. These scripts read precomputed artifacts from `results/` and generate figures into `figures/`. Plotting is downstream from training and evaluation, not tightly coupled to model execution.

9. **Persisted artifacts**
   The repo includes separate artifact directories:
   - `models/` for saved trained models
   - `results/valid/` and `results/test/` for `.npy` outputs such as calibration curves and confusion matrices
   - `figures/` for generated plots  
   This shows a clear separation between code, trained assets, evaluation outputs, and publication graphics.

10. **Experiment workflow**
   The end-to-end data flow is: **NetCDF dataset → feature extraction/batching → recurrent model training → saved predictions/results → evaluation/calibration/ensemble analysis → plots**. The architecture is intentionally modular so that feature handling, model definitions, and postprocessing can evolve independently while sharing a common experiment pipeline.

11. **Technical dependencies that shape the design**
   The repository depends on **NumPy, SciPy, Matplotlib, TensorFlow, Numba, Dask, and NetCDF4**. Those dependencies imply a workload that mixes scientific array processing, distributed or chunked data handling, compiled acceleration, deep learning, and offline visualization rather than a runtime service.

12. **What to show in an architecture diagram**
   A good diagram would center on three major boxes: **Data/feature preparation**, **TensorFlow model training**, and **analysis/visualization**. Surround those with the external NetCDF dataset on the input side and saved model/results/figure artifacts on the output side, with `scripts/` acting as the orchestration entry points that connect the stages.

Main entry points: [`results`](https://github.com/anledinhminh/c4dl-lightningdl/tree/master/results) (results/), [`scripts/training.py`](https://github.com/anledinhminh/c4dl-lightningdl/blob/master/scripts/training.py) (Training script), [`c4dllightning/ml/models/models.py`](https://github.com/anledinhminh/c4dl-lightningdl/blob/master/c4dllightning/ml/models/models.py) (Models), [`c4dllightning/features/batch.py`](https://github.com/anledinhminh/c4dl-lightningdl/blob/master/c4dllightning/features/batch.py) (Batching)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_external["External data"]
  node_zenodo_netcdf[("NetCDF data<br/>external dataset")]
  node_data_mount[("data/<br/>working data")]
end

subgraph group_pipeline["Pipeline"]
  node_regions["Regions<br/>geo slicing<br/>[regions.py]"]
  node_transform["Transform<br/>preprocessing<br/>[transform.py]"]
  node_batch["Batching<br/>data batches<br/>[batch.py]"]
  node_features_utils["Feature utils<br/>helpers<br/>[utils.py]"]
  node_training_script["Training script<br/>entry point<br/>[training.py]"]
end

subgraph group_modeling["Modeling"]
  node_layers["Layers<br/>nn primitives<br/>[layers.py]"]
  node_blocks["Blocks<br/>[blocks.py]"]
  node_rnn["RNN<br/>sequence model<br/>[rnn.py]"]
  node_models_py["Models<br/>architectures<br/>[models.py]"]
  node_optimizers["Optimizers<br/>training config<br/>[optimizers.py]"]
end

subgraph group_analysis["Analysis"]
  node_evaluation["Evaluation<br/>metrics<br/>[evaluation.py]"]
  node_calibration["Calibration<br/>probability analysis<br/>[calibration.py]"]
  node_ensemble["Ensemble<br/>model aggregation<br/>[ensemble.py]"]
  node_lagrangian["Lagrangian<br/>lead-time analysis<br/>[lagrangian.py]"]
end

subgraph group_viz["Visualization"]
  node_plots_script["Plot script<br/>entry point<br/>[plots_lightning.py]"]
  node_plots["Plots<br/>visualization<br/>[plots.py]"]
end

subgraph group_artifacts["Artifacts"]
  node_models_dir[("models/<br/>saved models")]
  node_results_dir[("results/<br/>experiment outputs")]
  node_figures_dir[("figures/<br/>publication figures")]
end

node_zenodo_netcdf -->|"download"| node_data_mount
node_data_mount -->|"slice"| node_regions
node_regions -->|"shape"| node_transform
node_transform -->|"prepare"| node_batch
node_features_utils -->|"support"| node_batch
node_training_script -->|"load"| node_batch
node_training_script -->|"build"| node_models_py
node_models_py -->|"compose"| node_blocks
node_blocks -->|"reuse"| node_layers
node_models_py -->|"sequence"| node_rnn
node_training_script -->|"configure"| node_optimizers
node_training_script -->|"save"| node_models_dir
node_training_script -->|"export"| node_results_dir
node_results_dir -->|"analyze"| node_evaluation
node_results_dir -->|"analyze"| node_calibration
node_results_dir -->|"combine"| node_ensemble
node_results_dir -->|"assess"| node_lagrangian
node_results_dir -->|"read"| node_plots_script
node_plots_script -->|"render"| node_plots
node_plots -->|"write"| node_figures_dir

click node_data_mount "https://github.com/anledinhminh/c4dl-lightningdl/tree/master/data"
click node_regions "https://github.com/anledinhminh/c4dl-lightningdl/blob/master/c4dllightning/features/regions.py"
click node_transform "https://github.com/anledinhminh/c4dl-lightningdl/blob/master/c4dllightning/features/transform.py"
click node_batch "https://github.com/anledinhminh/c4dl-lightningdl/blob/master/c4dllightning/features/batch.py"
click node_features_utils "https://github.com/anledinhminh/c4dl-lightningdl/blob/master/c4dllightning/features/utils.py"
click node_training_script "https://github.com/anledinhminh/c4dl-lightningdl/blob/master/scripts/training.py"
click node_layers "https://github.com/anledinhminh/c4dl-lightningdl/blob/master/c4dllightning/ml/models/layers.py"
click node_blocks "https://github.com/anledinhminh/c4dl-lightningdl/blob/master/c4dllightning/ml/models/blocks.py"
click node_rnn "https://github.com/anledinhminh/c4dl-lightningdl/blob/master/c4dllightning/ml/models/rnn.py"
click node_models_py "https://github.com/anledinhminh/c4dl-lightningdl/blob/master/c4dllightning/ml/models/models.py"
click node_optimizers "https://github.com/anledinhminh/c4dl-lightningdl/blob/master/c4dllightning/ml/models/optimizers.py"
click node_evaluation "https://github.com/anledinhminh/c4dl-lightningdl/blob/master/c4dllightning/analysis/evaluation.py"
click node_calibration "https://github.com/anledinhminh/c4dl-lightningdl/blob/master/c4dllightning/analysis/calibration.py"
click node_ensemble "https://github.com/anledinhminh/c4dl-lightningdl/blob/master/c4dllightning/analysis/ensemble.py"
click node_lagrangian "https://github.com/anledinhminh/c4dl-lightningdl/blob/master/c4dllightning/analysis/lagrangian.py"
click node_plots_script "https://github.com/anledinhminh/c4dl-lightningdl/blob/master/scripts/plots_lightning.py"
click node_plots "https://github.com/anledinhminh/c4dl-lightningdl/blob/master/c4dllightning/visualization/plots.py"
click node_models_dir "https://github.com/anledinhminh/c4dl-lightningdl/tree/master/models"
click node_results_dir "https://github.com/anledinhminh/c4dl-lightningdl/tree/master/results"
click node_figures_dir "https://github.com/anledinhminh/c4dl-lightningdl/tree/master/figures"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_zenodo_netcdf,node_data_mount toneBlue
class node_regions,node_transform,node_batch,node_features_utils,node_training_script toneAmber
class node_layers,node_blocks,node_rnn,node_models_py,node_optimizers toneMint
class node_evaluation,node_calibration,node_ensemble,node_lagrangian toneRose
class node_plots_script,node_plots toneIndigo
class node_models_dir,node_results_dir,node_figures_dir toneTeal
```

## Components

### External data

Scientific source data boundary

- **NetCDF data**: external dataset · Downloaded lightning nowcasting source data
- [data/](https://github.com/anledinhminh/c4dl-lightningdl/tree/master/data): working data · Local mount or workspace for dataset access · `data`

### Pipeline

Feature preparation and experiment orchestration

- [Regions](https://github.com/anledinhminh/c4dl-lightningdl/blob/master/c4dllightning/features/regions.py): geo slicing · Spatial domains and region definitions · `c4dllightning/features/regions.py`
- [Transform](https://github.com/anledinhminh/c4dl-lightningdl/blob/master/c4dllightning/features/transform.py): preprocessing · Normalization, masking, and coordinate transforms · `c4dllightning/features/transform.py`
- [Batching](https://github.com/anledinhminh/c4dl-lightningdl/blob/master/c4dllightning/features/batch.py): data batches · Builds model-ready training and validation batches · `c4dllightning/features/batch.py`
- [Feature utils](https://github.com/anledinhminh/c4dl-lightningdl/blob/master/c4dllightning/features/utils.py): helpers · Shared feature-processing utilities · `c4dllightning/features/utils.py`
- [Training script](https://github.com/anledinhminh/c4dl-lightningdl/blob/master/scripts/training.py): entry point · Wires data loading, model construction, training, and saving · `scripts/training.py`

### Modeling

TensorFlow sequence model stack

- [Layers](https://github.com/anledinhminh/c4dl-lightningdl/blob/master/c4dllightning/ml/models/layers.py): nn primitives · Reusable neural network layers · `c4dllightning/ml/models/layers.py`
- [Blocks](https://github.com/anledinhminh/c4dl-lightningdl/blob/master/c4dllightning/ml/models/blocks.py): nn blocks · Composable model blocks and feature extractors · `c4dllightning/ml/models/blocks.py`
- [RNN](https://github.com/anledinhminh/c4dl-lightningdl/blob/master/c4dllightning/ml/models/rnn.py): sequence model · Recurrent temporal forecasting components · `c4dllightning/ml/models/rnn.py`
- [Models](https://github.com/anledinhminh/c4dl-lightningdl/blob/master/c4dllightning/ml/models/models.py): architectures · Complete TensorFlow model definitions · `c4dllightning/ml/models/models.py`
- [Optimizers](https://github.com/anledinhminh/c4dl-lightningdl/blob/master/c4dllightning/ml/models/optimizers.py): training config · Optimization and training-time choices · `c4dllightning/ml/models/optimizers.py`

### Analysis

Evaluation and ensemble postprocessing

- [Evaluation](https://github.com/anledinhminh/c4dl-lightningdl/blob/master/c4dllightning/analysis/evaluation.py): metrics · Forecast metrics and confusion matrices · `c4dllightning/analysis/evaluation.py`
- [Calibration](https://github.com/anledinhminh/c4dl-lightningdl/blob/master/c4dllightning/analysis/calibration.py): probability analysis · Calibration curves and reliability analysis · `c4dllightning/analysis/calibration.py`
- [Ensemble](https://github.com/anledinhminh/c4dl-lightningdl/blob/master/c4dllightning/analysis/ensemble.py): model aggregation · Combines multiple prediction outputs · `c4dllightning/analysis/ensemble.py`
- [Lagrangian](https://github.com/anledinhminh/c4dl-lightningdl/blob/master/c4dllightning/analysis/lagrangian.py): lead-time analysis · Lead-time or trajectory-oriented evaluation · `c4dllightning/analysis/lagrangian.py`

### Visualization

Plot generation

- [Plot script](https://github.com/anledinhminh/c4dl-lightningdl/blob/master/scripts/plots_lightning.py): entry point · Loads results and produces figures · `scripts/plots_lightning.py`
- [Plots](https://github.com/anledinhminh/c4dl-lightningdl/blob/master/c4dllightning/visualization/plots.py): visualization · Figure construction and styling · `c4dllightning/visualization/plots.py`

### Artifacts

Persisted experiment outputs

- [models/](https://github.com/anledinhminh/c4dl-lightningdl/tree/master/models): saved models · Persisted trained model artifacts · `models`
- [results/](https://github.com/anledinhminh/c4dl-lightningdl/tree/master/results): experiment outputs · Saved validation and test arrays · `results`
- [figures/](https://github.com/anledinhminh/c4dl-lightningdl/tree/master/figures): publication figures · Generated plots and figures · `figures`

## Connections

- NetCDF data → data/: download · Source dataset is stored or mounted locally
- data/ → Regions: slice · Select geographic domains
- Regions → Transform: shape · Apply spatial and feature transforms
- Transform → Batching: prepare · Convert fields into model-ready batches
- Feature utils → Batching: support · Shared feature helpers used during batching
- Training script → Batching: load · Training entry point requests prepared batches
- Training script → Models: build · Select and instantiate model architecture
- Models → Blocks: compose · Models are assembled from reusable blocks
- Blocks → Layers: reuse · Blocks depend on lower-level layers
- Models → RNN: sequence · Recurrent forecasting core
- Training script → Optimizers: configure · Choose optimization strategy
- Training script → models/: save · Persist trained model artifacts
- Training script → results/: export · Write predictions and evaluation arrays
- results/ → Evaluation: analyze · Compute forecast metrics from saved outputs
- results/ → Calibration: analyze · Measure probabilistic calibration
- results/ → Ensemble: combine · Aggregate multiple model outputs
- results/ → Lagrangian: assess · Evaluate lead-time or trajectory behavior
- results/ → Plot script: read · Plotting script consumes saved results
- Plot script → Plots: render · Build figures from analysis artifacts
- Plots → figures/: write · Store generated plots
