DGMR

Model Introduction

DGMR (Deep Generative Model of Radar) was proposed by DeepMind in 2021. It is a short-term precipitation nowcasting model based on a conditional generative adversarial network (cGAN). The generator consists of a latent conditioning stack, a context conditioning stack, and an autoregressive sampler based on multiple ConvGRU layers. The discriminator evaluates both spatial and temporal dimensions, and the training objective combines hinge GAN loss with a grid-cell regularizer.

Paper:Skillful Precipitation Nowcasting using Deep Generative Models of Radar

https://arxiv.org/abs/2104.00954

Model Description

DGMR is a probabilistic short-term precipitation nowcasting model: it takes four consecutive radar echo frames and generates 18 future frames at once (5-minute steps, 90 minutes in total, in the paper). Its output is a sample rather than a deterministic estimate. This repository is organized from the official Open Climate Fix PyTorch implementation (openclimatefix/dgmr, MIT License) and integrated with the OneScience data loading and training workflow.

Use Cases

Scenario Description
Short-term precipitation nowcasting research Train a cGAN on radar echo sequences to generate future radar echo frames.
Probabilistic forecast output Obtain multiple generated samples of future fields through latent-variable sampling.
Local quick validation Use synthetic data to check data loading, training, inference, and result scripts.
ModelScope/OneCode execution Download the model package, install dependencies, and run the scripts directly.
Multi-card training Launch multi-process training with torchrun.

Usage

1. OneCode Usage

Use the OneCode online environment for intelligent one-click AI4S programming:

Try intelligent one-click AI4S programming

2. Manual Installation and Usage

Hardware Requirements

  • GPU or DCU is recommended.
  • CPU can be used for imports and small-configuration connectivity validation, but full training and inference are slower.
  • DCU users must install DTK beforehand. DTK 25.04.2 or later, or the OneScience-recommended version matching the current cluster, is recommended.

Download the Model Package

hf download OneScience-Group/DGMR --local-dir ./DGMR
cd DGMR

Install the Runtime Environment

DCU Environment

# Activate DTK and CONDA first
conda create -n onescience311 python=3.11 -y
conda activate onescience311
# uv installation is supported
pip install onescience[earth-dcu] -i http://mirrors.onescience.ai:3141/pypi/simple/  --trusted-host mirrors.onescience.ai

GPU Environment

# Activate CONDA first
conda create -n onescience311 python=3.11 -y libstdcxx-ng=12 libgcc-ng=12 gcc_linux-64=12 gxx_linux-64=12
conda activate onescience311
# uv installation is supported
pip install onescience[earth-gpu] -i http://mirrors.onescience.ai:3141/pypi/simple/  --trusted-host mirrors.onescience.ai

Training Data

The OneScience community provides ERA5 data for training (the current repository contains complete data slices subject to data-file size limits). Download it with the command below and confirm that the data path in conf/config.yaml is correct:

hf download --repo-type dataset OneScience-Group/ERA5 --local-dir ./data

For a quick workflow validation, run the synthetic data script first:

python scripts/fake_data.py

Note: scripts/fake_data.py generates a single-channel radar sequence from num_context, forecast_steps, batch size, and radar grid size. The current small configuration uses 4 input frames, 6 output frames, and a 128×128 grid.

Training

Single card:

python scripts/train.py

Multiple cards:

torchrun --nproc_per_node=8 --nnodes=1 --rdzv_id=1000 --rdzv_backend=c10d --max_restarts=0 --master_addr="localhost" --master_port=29500 scripts/train.py

Training outputs:

data/checkpoints/model_bak.pth
data/checkpoints/trloss.npy
data/checkpoints/valoss.npy

Training Weights

The weight/ folder is reserved for model weights. Pretrained weights are not provided by default; users may train the model using the paper configuration. Official DeepMind pretrained weights require access approval and differ from the current configuration in channel count and grid size, so they must be aligned before loading.

Inference

Inference reads data/checkpoints/model_bak.pth:

python scripts/inference.py

Prediction results are written frame by frame to:

result/output/

Evaluation and Visualization

python scripts/result.py

Outputs include:

  • result/rmse.npy
  • result/acc.npy
  • result/loss.png
  • Forecast comparison plots for the specified date and variables

Official Source and Reproduction Notes

  • The model implementation comes from the official Open Climate Fix PyTorch package openclimatefix/dgmr (MIT License). The related network modules (common/layers/generators/discriminators/losses) are embedded unchanged in model/dgmr_official/ (with the HuggingFace hub mixin and pytorch_lightning training loop removed); model/dgmr.py is only a YAML-driven thin wrapper.
  • conf/config.yaml uses a small configuration (forecast_steps=6, output_shape=128, latent_channels=384, context_channels=192) for connectivity validation by default; paper-level reproduction requires 4→18 frames, a 256×256 grid, latent_channels=768, and context_channels=384.
  • The paper-level configuration (num_context=4, forecast_steps=18) requires at least T >= num_context + forecast_steps + 1 = 23 frames per year; the current synthetic data uses T=10 (time_step=6h), so the default configuration uses 4→6 frames.
  • The discriminator contains BatchNorm1d, so the training batch must be >= 2 (with synthetic data, the training set uses two samples from two years, exactly one batch).
  • The following details are not disclosed in the paper and are assumptions in this reproduction:data normalization statistics (identity normalization is currently used; real statistics will be supplied with the data), and the number of randomly sampled time frames in the discriminator.

Official OneScience Information

Citation and License

  • This repository is an independent organization and adaptation of DGMR. The model source is based on the Open Climate Fix openclimatefix/dgmr implementation and follows the MIT License.
  • Please cite:Ravuri et al. Skilful Precipitation Nowcasting using Deep Generative Models of Radar. Nature 597, 672-677, 2021.

中文说明

模型简介

DGMR(Deep Generative Model of Radar)由 DeepMind 于 2021 年提出,是一种基于条件生成对抗网络(cGAN)的短时降水临近预报(nowcasting)模型。生成器由潜变量条件堆栈、上下文条件堆栈,以及基于多层 ConvGRU 的自回归采样器组成。判别器同时评估空间和时间维度,训练目标结合合页 GAN 损失与网格单元正则项。

论文《使用雷达深度生成模型的高技巧降水临近预报》

https://arxiv.org/abs/2104.00954

模型描述

DGMR 是一种概率性短时降水临近预报模型,输入连续四帧雷达回波图像,一次生成未来 18 帧(论文中每步 5 分钟,共 90 分钟)。模型输出的是样本,而非确定性估计。本仓库基于 Open Climate Fix 官方 PyTorch 实现(openclimatefix/dgmr,MIT License)整理,并集成了 OneScience 的数据加载和训练工作流。

使用场景

场景 说明
短时降水临近预报研究 使用雷达回波序列训练 cGAN,生成未来的雷达回波帧。
概率预报输出 通过潜变量采样获得多个未来场的生成样本。
本地快速验证 使用合成数据检查数据加载、训练、推理(inference)和结果处理脚本。
在 ModelScope/OneCode 中运行 下载模型包,安装依赖后直接运行脚本。
多卡训练 使用 torchrun 启动多进程训练。

使用方法

1. 使用 OneCode

通过 OneCode 在线环境体验智能一键 AI4S 编程。

体验智能一键 AI4S 编程

2. 手动安装与使用

硬件要求

  • 建议使用 GPU 或 DCU。
  • 可使用 CPU 进行导入和小规模配置连通性验证,完整训练和推理速度较慢。
  • DCU 用户须提前安装 DTK。建议使用 DTK 25.04.2 或更高版本,或使用 OneScience 推荐且与当前集群匹配的版本。

下载模型包

hf download OneScience-Group/DGMR --local-dir ./DGMR
cd DGMR

安装运行环境

DCU 环境

# Activate DTK and CONDA first
conda create -n onescience311 python=3.11 -y
conda activate onescience311
# uv installation is supported
pip install onescience[earth-dcu] -i http://mirrors.onescience.ai:3141/pypi/simple/  --trusted-host mirrors.onescience.ai

GPU 环境

# Activate CONDA first
conda create -n onescience311 python=3.11 -y libstdcxx-ng=12 libgcc-ng=12 gcc_linux-64=12 gxx_linux-64=12
conda activate onescience311
# uv installation is supported
pip install onescience[earth-gpu] -i http://mirrors.onescience.ai:3141/pypi/simple/  --trusted-host mirrors.onescience.ai

训练数据

OneScience 社区提供用于训练的 ERA5 数据(受数据文件大小限制,当前仓库包含完整的数据切片)。使用以下命令下载数据,并确认 conf/config.yaml 中的数据路径正确。

hf download --repo-type dataset OneScience-Group/ERA5 --local-dir ./data

如需快速验证工作流,请先运行合成数据脚本。

python scripts/fake_data.py

注意,scripts/fake_data.py 根据 num_context、forecast_steps、批大小和雷达网格大小生成单通道雷达序列。当前小规模配置使用 4 帧输入、6 帧输出和 128×128 网格。

训练

单卡

python scripts/train.py

多卡

torchrun --nproc_per_node=8 --nnodes=1 --rdzv_id=1000 --rdzv_backend=c10d --max_restarts=0 --master_addr="localhost" --master_port=29500 scripts/train.py

训练输出

data/checkpoints/model_bak.pth
data/checkpoints/trloss.npy
data/checkpoints/valoss.npy

训练权重

weight/ 文件夹预留给模型权重。默认不提供预训练权重,用户可使用论文配置训练模型。DeepMind 官方预训练权重需要申请访问权限,并且在通道数及网格大小上与当前配置有差异,因此必须在加载前进行匹配。

推理

推理读取 data/checkpoints/model_bak.pth。

python scripts/inference.py

预测结果逐帧写入以下位置。

result/output/

评估与可视化

python scripts/result.py

输出内容包括

  • result/rmse.npy
  • result/acc.npy
  • result/loss.png
  • 指定日期和变量的预报对比图

官方来源与复现说明

  • 模型实现来自 Open Climate Fix 官方 PyTorch 软件包 openclimatefix/dgmr(MIT License)。相关网络模块(common/layers/generators/discriminators/losses)原样嵌入 model/dgmr_official/ 中(移除了 HuggingFace hub mixin 和 pytorch_lightning 训练循环)。model/dgmr.py 仅是由 YAML 驱动的轻量封装。
  • conf/config.yaml 默认使用小规模配置(forecast_steps=6、output_shape=128、latent_channels=384、context_channels=192)验证连通性。论文规模复现需要 4→18 帧、256×256 网格、latent_channels=768 和 context_channels=384。
  • 论文规模配置(num_context=4、forecast_steps=18)要求每年最少 T >= num_context + forecast_steps + 1 = 23 帧。当前合成数据为 T=10(time_step=6h),因此默认配置使用 4→6 帧。
  • 判别器包含 BatchNorm1d,因此训练批大小必须 >= 2(使用合成数据时,训练集采用来自两年的两个样本,恰好构成一个批次)。
  • 数据归一化统计量(目前使用恒等归一化,真实统计量将随数据提供)及判别器随机采样的时间帧数均未在论文中披露,属于本次复现的假设。

OneScience 官方信息

引用与许可证

  • 本仓库是对 DGMR 的独立整理和适配。模型源代码基于 Open Climate Fix 的 openclimatefix/dgmr 实现,遵循 MIT License。
  • 请引用 Ravuri et al. Skilful Precipitation Nowcasting using Deep Generative Models of Radar. Nature 597, 672-677, 2021.
Downloads last month
28
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Paper for OneScience-Group/DGMR