# b-rbmp/flowcast architecture

> Architecture diagram of the GitHub repository b-rbmp/flowcast, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/b-rbmp/flowcast
- Repository: https://github.com/b-rbmp/flowcast

## Overview

#### Purpose and execution model
FlowCast is a PyTorch-based probabilistic precipitation-nowcasting system. It forecasts SEVIR radar VIL sequences by learning conditional flow matching (CFM) in an autoencoder-compressed latent space. It is a batch/offline training and inference repository, not a serving application.

Primary entry points:
- Autoencoder training: `experiments/sevir/autoencoder/dist_train_autoencoder_kl.py`
- Latent-data generation: `experiments/sevir/autoencoder/generate_static_dataset.py`
- FlowCast distributed training: `experiments/sevir/runner/flowcast/dist_train_flowcast.py`
- Evaluation/inference: `experiments/sevir/runner/flowcast/test_flowcast.py`

#### 1. SEVIR ingestion and dataset preparation
Raw SEVIR VIL data is downloaded from public AWS S3, then converted into train/validation/test HDF5 datasets plus metadata CSVs. The preprocessing split boundaries and downsampling are command-line controlled.
- `datasets/sevir/sevir_preprocessing.py`
- `experiments/sevir/dataset/sevirfulldataset.py`
- `experiments/sevir/dataset/sevirfulldataset_autoencoder.py`

This is the boundary from external radar files to model-ready sequence samples. AWS CLI/S3 is required only for initial SEVIR acquisition.

#### 2. KL autoencoder stage
A KL-regularized autoencoder first compresses high-dimensional radar imagery into latent representations. Its distributed trainer consumes full-resolution SEVIR datasets, applies reconstruction/perceptual objectives, checkpoints the model, and uses early stopping.
- `experiments/sevir/autoencoder/dist_train_autoencoder_kl.py`
- `experiments/sevir/autoencoder/autoencoder_kl_config.yaml`
- `common/autoencoder/losses/lpips.py`

The trained encoder/decoder is a hard dependency for both latent-dataset creation and forecast visualization/evaluation.

#### 3. Static latent dataset boundary
The generation script runs the pretrained encoder over full SEVIR train/validation inputs and persists latents as a separate HDF5-backed dataset. This decouples costly image encoding from CFM training and establishes the interface between the two model stages.
- `experiments/sevir/autoencoder/generate_static_dataset.py`
- `experiments/sevir/dataset/sevirfulldataset_autoencoder.py`

FlowCast training reads these latent files, while partial evaluation can still use the original full-resolution data for decoded forecast assessment.

#### 4. Conditional flow-matching core
The CFM implementation defines the noise-to-data latent trajectory and training objective. The FlowCast runner conditions generation on observed radar-history latents, trains the latent dynamical/generative model under distributed execution, and saves model artifacts.
- `common/cfm/cfm.py`
- `experiments/sevir/runner/flowcast/dist_train_flowcast.py`
- `experiments/sevir/runner/flowcast/flowcast_config.yaml`

At inference, sampled noise is integrated/mapped to future latents conditioned on context; generated future latents are decoded by the autoencoder back to radar fields.

#### 5. FlowCast neural architecture
The learned CFM vector field is implemented using cuboid-transformer and U-Net-style components, with explicit temporal embeddings and transformer attention-pattern definitions.
- `common/models/flowcast/cuboid_transformer_unet.py`
- `common/models/flowcast/cuboid_transformer.py`
- `common/models/flowcast/time_embed.py`

This layer is model-specific infrastructure beneath the trainer: it receives latent spatiotemporal tensors plus conditioning/time information and produces flow predictions.

#### 6. Evaluation, metrics, and outputs
Testing restores autoencoder and FlowCast checkpoints, generates forecasts over the held-out full SEVIR test set, decodes results, and computes deterministic/probabilistic nowcasting quality measures.
- `experiments/sevir/runner/flowcast/test_flowcast.py`
- `common/metrics/metrics_streaming_probabilistic.py`
- `common/metrics/fss.py`

Display utilities support geographic/image presentation but are downstream of inference.
- `experiments/sevir/display/display.py`

#### Runtime and artifact dependencies
Python 3.10 with PyTorch/TorchVision and CUDA is the primary runtime. Training uses `torchrun` multi-process distributed execution; documented workloads target multi-H100 nodes. Persistent artifacts include preprocessed/latent HDF5 and CSV data, autoencoder and FlowCast checkpoints under `saved_models/`, and optional pretrained checkpoints from Hugging Face Hub.

Main entry points: [`experiments/sevir/runner/flowcast/test_flowcast.py`](https://github.com/b-rbmp/flowcast/blob/main/experiments/sevir/runner/flowcast/test_flowcast.py) (FlowCast inference and test), [`experiments/sevir/runner/flowcast/dist_train_flowcast.py`](https://github.com/b-rbmp/flowcast/blob/main/experiments/sevir/runner/flowcast/dist_train_flowcast.py) (FlowCast trainer), [`experiments/sevir/autoencoder/dist_train_autoencoder_kl.py`](https://github.com/b-rbmp/flowcast/blob/main/experiments/sevir/autoencoder/dist_train_autoencoder_kl.py) (KL autoencoder trainer), [`experiments/sevir/dataset/sevirfulldataset.py`](https://github.com/b-rbmp/flowcast/blob/main/experiments/sevir/dataset/sevirfulldataset.py) (Full SEVIR datasets)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["SEVIR data pipeline"]
  node_s3[("Public SEVIR S3<br/>external data source")]
  node_preprocess["SEVIR preprocessing<br/>data preparation"]
  node_full_dataset[("Full SEVIR datasets<br/>HDF5 dataset loader")]
  node_ae_dataset["Autoencoder dataset loader<br/>HDF5 dataset loader"]
end

subgraph group_ae["Latent autoencoder"]
  node_ae_train["KL autoencoder trainer<br/>distributed training entry point"]
  node_ae_config["Autoencoder config<br/>training configuration"]
  node_lpips["Perceptual loss<br/>training objective<br/>[lpips.py]"]
  node_ae_checkpoint["Autoencoder checkpoint<br/>model artifact"]
  node_latent_generate["Static latent generation<br/>dataset generation entry point"]
end

subgraph group_flow["FlowCast training"]
  node_latent_dataset[("Latent HDF5 dataset<br/>persistent dataset")]
  node_flow_train["FlowCast trainer<br/>distributed training entry point"]
  node_flow_config["FlowCast config<br/>training configuration"]
  node_cfm["Conditional flow matching<br/>latent trajectory objective<br/>[cfm.py]"]
  node_vector_field["Cuboid Transformer U-Net<br/>CFM vector field network"]
  node_transformer["Cuboid transformer<br/>attention backbone"]
  node_time_embed["Time embeddings<br/>model conditioning<br/>[time_embed.py]"]
  node_flow_checkpoint["FlowCast checkpoint<br/>model artifact"]
end

subgraph group_eval["Forecast evaluation"]
  node_test["FlowCast inference and test<br/>evaluation entry point<br/>[test_flowcast.py]"]
  node_metrics["Probabilistic metrics<br/>evaluation metrics"]
  node_fss["Fraction skill score<br/>spatial metric<br/>[fss.py]"]
  node_display["Forecast display<br/>visualization utility<br/>[display.py]"]
end

node_s3 -->|"raw VIL"| node_preprocess
node_preprocess -->|"HDF5 sequences"| node_full_dataset
node_full_dataset -->|"full-resolution samples"| node_ae_dataset
node_ae_dataset -->|"training batches"| node_ae_train
node_ae_config -.->|"configures"| node_ae_train
node_lpips -->|"perceptual objective"| node_ae_train
node_ae_train -->|"saves"| node_ae_checkpoint
node_ae_dataset -->|"train/validation samples"| node_latent_generate
node_ae_checkpoint -->|"pretrained encoder"| node_latent_generate
node_latent_generate -->|"encoded latents"| node_latent_dataset
node_latent_dataset -->|"latent batches"| node_flow_train
node_flow_config -.->|"configures"| node_flow_train
node_cfm -->|"training objective"| node_flow_train
node_vector_field -->|"learned vector field"| node_flow_train
node_transformer -->|"attention layers"| node_vector_field
node_time_embed -->|"time conditioning"| node_vector_field
node_flow_train -->|"saves"| node_flow_checkpoint
node_full_dataset -->|"held-out radar sequences"| node_test
node_ae_checkpoint -->|"decodes forecasts"| node_test
node_flow_checkpoint -->|"samples future latents"| node_test
node_test -->|"forecast scores"| node_metrics
node_test -->|"spatial scores"| node_fss
node_test -->|"decoded forecasts"| node_display

click node_preprocess "https://github.com/b-rbmp/flowcast/blob/main/datasets/sevir/sevir_preprocessing.py"
click node_full_dataset "https://github.com/b-rbmp/flowcast/blob/main/experiments/sevir/dataset/sevirfulldataset.py"
click node_ae_dataset "https://github.com/b-rbmp/flowcast/blob/main/experiments/sevir/dataset/sevirfulldataset_autoencoder.py"
click node_ae_train "https://github.com/b-rbmp/flowcast/blob/main/experiments/sevir/autoencoder/dist_train_autoencoder_kl.py"
click node_ae_config "https://github.com/b-rbmp/flowcast/blob/main/experiments/sevir/autoencoder/autoencoder_kl_config.yaml"
click node_lpips "https://github.com/b-rbmp/flowcast/blob/main/common/autoencoder/losses/lpips.py"
click node_latent_generate "https://github.com/b-rbmp/flowcast/blob/main/experiments/sevir/autoencoder/generate_static_dataset.py"
click node_flow_train "https://github.com/b-rbmp/flowcast/blob/main/experiments/sevir/runner/flowcast/dist_train_flowcast.py"
click node_flow_config "https://github.com/b-rbmp/flowcast/blob/main/experiments/sevir/runner/flowcast/flowcast_config.yaml"
click node_cfm "https://github.com/b-rbmp/flowcast/blob/main/common/cfm/cfm.py"
click node_vector_field "https://github.com/b-rbmp/flowcast/blob/main/common/models/flowcast/cuboid_transformer_unet.py"
click node_transformer "https://github.com/b-rbmp/flowcast/blob/main/common/models/flowcast/cuboid_transformer.py"
click node_time_embed "https://github.com/b-rbmp/flowcast/blob/main/common/models/flowcast/time_embed.py"
click node_test "https://github.com/b-rbmp/flowcast/blob/main/experiments/sevir/runner/flowcast/test_flowcast.py"
click node_metrics "https://github.com/b-rbmp/flowcast/blob/main/common/metrics/metrics_streaming_probabilistic.py"
click node_fss "https://github.com/b-rbmp/flowcast/blob/main/common/metrics/fss.py"
click node_display "https://github.com/b-rbmp/flowcast/blob/main/experiments/sevir/display/display.py"

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_s3,node_preprocess,node_full_dataset,node_ae_dataset toneBlue
class node_ae_train,node_ae_config,node_lpips,node_ae_checkpoint,node_latent_generate toneAmber
class node_latent_dataset,node_flow_train,node_flow_config,node_cfm,node_vector_field,node_transformer,node_time_embed,node_flow_checkpoint toneMint
class node_test,node_metrics,node_fss,node_display toneRose
```

## Components

### SEVIR data pipeline

- **Public SEVIR S3**: external data source · Raw radar VIL files acquired with AWS CLI.
- [SEVIR preprocessing](https://github.com/b-rbmp/flowcast/blob/main/datasets/sevir/sevir_preprocessing.py): data preparation · Splits and downsamples raw SEVIR into HDF5 and metadata. · `datasets/sevir/sevir_preprocessing.py`
- [Full SEVIR datasets](https://github.com/b-rbmp/flowcast/blob/main/experiments/sevir/dataset/sevirfulldataset.py): HDF5 dataset loader · Model-ready full-resolution train, validation, and test sequences. · `experiments/sevir/dataset/sevirfulldataset.py`
- [Autoencoder dataset loader](https://github.com/b-rbmp/flowcast/blob/main/experiments/sevir/dataset/sevirfulldataset_autoencoder.py): HDF5 dataset loader · Loads full SEVIR samples for encoding and autoencoder training. · `experiments/sevir/dataset/sevirfulldataset_autoencoder.py`

### Latent autoencoder

- [KL autoencoder trainer](https://github.com/b-rbmp/flowcast/blob/main/experiments/sevir/autoencoder/dist_train_autoencoder_kl.py): distributed training entry point · Trains and checkpoints the radar latent encoder/decoder. · `experiments/sevir/autoencoder/dist_train_autoencoder_kl.py`
- [Autoencoder config](https://github.com/b-rbmp/flowcast/blob/main/experiments/sevir/autoencoder/autoencoder_kl_config.yaml): training configuration · `experiments/sevir/autoencoder/autoencoder_kl_config.yaml`
- [Perceptual loss](https://github.com/b-rbmp/flowcast/blob/main/common/autoencoder/losses/lpips.py): training objective · `common/autoencoder/losses/lpips.py`
- **Autoencoder checkpoint**: model artifact · Required to encode latent data and decode forecasts.
- [Static latent generation](https://github.com/b-rbmp/flowcast/blob/main/experiments/sevir/autoencoder/generate_static_dataset.py): dataset generation entry point · Encodes train and validation sequences into persistent latents. · `experiments/sevir/autoencoder/generate_static_dataset.py`

### FlowCast training

- **Latent HDF5 dataset**: persistent dataset · Precomputed representation boundary for FlowCast training.
- [FlowCast trainer](https://github.com/b-rbmp/flowcast/blob/main/experiments/sevir/runner/flowcast/dist_train_flowcast.py): distributed training entry point · Trains the conditional latent flow model with torchrun. · `experiments/sevir/runner/flowcast/dist_train_flowcast.py`
- [FlowCast config](https://github.com/b-rbmp/flowcast/blob/main/experiments/sevir/runner/flowcast/flowcast_config.yaml): training configuration · `experiments/sevir/runner/flowcast/flowcast_config.yaml`
- [Conditional flow matching](https://github.com/b-rbmp/flowcast/blob/main/common/cfm/cfm.py): latent trajectory objective · Defines noise-to-data paths and the vector-field objective. · `common/cfm/cfm.py`
- [Cuboid Transformer U-Net](https://github.com/b-rbmp/flowcast/blob/main/common/models/flowcast/cuboid_transformer_unet.py): CFM vector field network · Predicts latent flow from context and time conditioning. · `common/models/flowcast/cuboid_transformer_unet.py`
- [Cuboid transformer](https://github.com/b-rbmp/flowcast/blob/main/common/models/flowcast/cuboid_transformer.py): attention backbone · `common/models/flowcast/cuboid_transformer.py`
- [Time embeddings](https://github.com/b-rbmp/flowcast/blob/main/common/models/flowcast/time_embed.py): model conditioning · `common/models/flowcast/time_embed.py`
- **FlowCast checkpoint**: model artifact · Saved latent forecasting model.

### Forecast evaluation

- [FlowCast inference and test](https://github.com/b-rbmp/flowcast/blob/main/experiments/sevir/runner/flowcast/test_flowcast.py): evaluation entry point · Samples future latents, decodes forecasts, and evaluates held-out SEVIR. · `experiments/sevir/runner/flowcast/test_flowcast.py`
- [Probabilistic metrics](https://github.com/b-rbmp/flowcast/blob/main/common/metrics/metrics_streaming_probabilistic.py): evaluation metrics · `common/metrics/metrics_streaming_probabilistic.py`
- [Fraction skill score](https://github.com/b-rbmp/flowcast/blob/main/common/metrics/fss.py): spatial metric · `common/metrics/fss.py`
- [Forecast display](https://github.com/b-rbmp/flowcast/blob/main/experiments/sevir/display/display.py): visualization utility · `experiments/sevir/display/display.py`

## Connections

- Public SEVIR S3 → SEVIR preprocessing: raw VIL
- SEVIR preprocessing → Full SEVIR datasets: HDF5 sequences
- Full SEVIR datasets → Autoencoder dataset loader: full-resolution samples
- Autoencoder dataset loader → KL autoencoder trainer: training batches
- Autoencoder config → KL autoencoder trainer: configures
- Perceptual loss → KL autoencoder trainer: perceptual objective
- KL autoencoder trainer → Autoencoder checkpoint: saves
- Autoencoder dataset loader → Static latent generation: train/validation samples
- Autoencoder checkpoint → Static latent generation: pretrained encoder
- Static latent generation → Latent HDF5 dataset: encoded latents
- Latent HDF5 dataset → FlowCast trainer: latent batches
- FlowCast config → FlowCast trainer: configures
- Conditional flow matching → FlowCast trainer: training objective
- Cuboid Transformer U-Net → FlowCast trainer: learned vector field
- Cuboid transformer → Cuboid Transformer U-Net: attention layers
- Time embeddings → Cuboid Transformer U-Net: time conditioning
- FlowCast trainer → FlowCast checkpoint: saves
- Full SEVIR datasets → FlowCast inference and test: held-out radar sequences
- Autoencoder checkpoint → FlowCast inference and test: decodes forecasts
- FlowCast checkpoint → FlowCast inference and test: samples future latents
- FlowCast inference and test → Probabilistic metrics: forecast scores
- FlowCast inference and test → Fraction skill score: spatial scores
- FlowCast inference and test → Forecast display: decoded forecasts
