How anledinhminh/c4dl-lightningdl works
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 results/ · training.py Training script · models.py Models · batch.py Batching
Components 21
External data
Scientific source data boundary
- NetCDF data · Downloaded lightning nowcasting source data
- data/ · Local mount or workspace for dataset access
data
Pipeline
Feature preparation and experiment orchestration
- Regions · Spatial domains and region definitions
c4dllightning/features/regions.py - Transform · Normalization, masking, and coordinate transforms
c4dllightning/features/transform.py - Batching · Builds model-ready training and validation batches
c4dllightning/features/batch.py - Feature utils · Shared feature-processing utilities
c4dllightning/features/utils.py - Training script · Wires data loading, model construction, training, and saving
scripts/training.py
Modeling
TensorFlow sequence model stack
- Layers · Reusable neural network layers
c4dllightning/ml/models/layers.py - Blocks · Composable model blocks and feature extractors
c4dllightning/ml/models/blocks.py - RNN · Recurrent temporal forecasting components
c4dllightning/ml/models/rnn.py - Models · Complete TensorFlow model definitions
c4dllightning/ml/models/models.py - Optimizers · Optimization and training-time choices
c4dllightning/ml/models/optimizers.py
Analysis
Evaluation and ensemble postprocessing
- Evaluation · Forecast metrics and confusion matrices
c4dllightning/analysis/evaluation.py - Calibration · Calibration curves and reliability analysis
c4dllightning/analysis/calibration.py - Ensemble · Combines multiple prediction outputs
c4dllightning/analysis/ensemble.py - Lagrangian · Lead-time or trajectory-oriented evaluation
c4dllightning/analysis/lagrangian.py
Visualization
Plot generation
- Plot script · Loads results and produces figures
scripts/plots_lightning.py - Plots · Figure construction and styling
c4dllightning/visualization/plots.py
Connections 20
- 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