MassConservingCNN

Model Introduction

MassConservingCNN corrects mass-conservation violations introduced by localization in ensemble Kalman filter data assimilation. Given an unconstrained analysis and radar-observation locations, it generates an analysis field with nonnegative rain and improved mass conservation for research on physically constrained data assimilation and analysis postprocessing.

Paper: Training a convolutional neural network to conserve mass in data assimilation
https://doi.org/10.5194/npg-28-111-2021

Model Description

MassConservingCNN was proposed by researchers from the Meteorological Institute of Ludwig-Maximilians-Universität München and ClimateAi. The paper trains and validates the model with EnKF unconstrained analyses, QPEns constrained analyses, and radar-observation locations generated by twin experiments with a one-dimensional modified shallow-water model. The model is suitable for mass-conserving data-assimilation correction, rain non-negativity constraints, and physically consistent analysis generation.

Use Cases

Use Case Description
Data-assimilation correction Predict a QPEns-style analysis from X^a and a radar-location indicator.
Mass-aware training Train with the paper Equation 6 error and Equation 7 mass penalty.
ModelScope/OneCode execution Validate training, inference, evaluation, visualization, and checkpoint workflows in ModelScope or OneCode.
Multi-GPU training Launch distributed data-parallel training with torchrun.

Usage Instructions

1.OneCode

Experience intelligent, one-click AI4S programming through the OneCode online environment:

Try intelligent, one-click AI4S programming

2.Download and Installation

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

Environment Dependencies

Hardware Requirements

  • A GPU or DCU is recommended.
  • A CPU can be used for connectivity validation with the default small-sample configuration.
  • DCU users must install DTK in advance. DTK 25.04.2 or later, or the OneScience-recommended version matching the current cluster, is recommended.

DCU Environment

# Activate DTK and Conda first
conda create -n onescience311 python=3.11 -y
conda activate onescience311
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
pip install onescience[earth-gpu] -i http://mirrors.onescience.ai:3141/pypi/simple/ --trusted-host mirrors.onescience.ai

Training Data

The default generator creates 24 training samples and 12 validation samples while preserving [B,4,250] inputs and [B,3,250] targets. The data combine periodic waves, smooth convective cells, nonnegative rain related to velocity convergence, rainy-region radar masks, and smooth EnKF-style errors. They validate the engineering workflow only and are not equivalent to the paper's 48,000-sample QPEns datasets.

python scripts/fake_data.py --force

Training

For single-device training, use:

python scripts/train.py

For multi-GPU training, use:

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 checks the data version, shapes, dtypes, finite values, binary radar masks, and rain non-negativity. The checkpoint stores model parameters, optimizer state, model configuration, normalization statistics, variable order, data version, eta, epoch, and seed. Outputs are written to:

result/checkpoints/massconservingcnn.pt
result/training/metrics.json

Trained Weights

This repository does not include weights under weight/. The paper does not provide a confirmed official checkpoint, and the current engineering checkpoint is not claimed to be compatible with external weights.

Inference

python scripts/inference.py

Inference restores the model parameters produced by training and generates mass-corrected analysis fields from unconstrained analyses and radar-location indicators. Results include input analyses, target analyses, model predictions, radar-observation locations, and the corresponding physical and normalization information, and are saved to:

result/output/predictions.npz

Evaluation and Visualization

python scripts/result.py

Evaluation results include core prediction-error, mass-conservation-error, and relative-improvement results, together with an input, target, and prediction comparison figure. Structured metrics and the auxiliary figure are saved to the paths below; synthetic-data results validate the engineering workflow only and do not represent paper performance.

result/evaluation/metrics.json
result/evaluation/input_target_prediction.png

Official OneScience Information

Citation and License

This repository is an independent engineering reproduction of the public MassConservingCNN specifications.

Use of this repository's code, official model weights, and data remains subject to the licenses and terms of their respective projects.


中文说明

模型简介

MassConservingCNN 校正集合 Kalman 滤波资料同化(data assimilation)中的局地化所引入的质量不守恒问题。给定无约束分析场和雷达观测位置,它生成降雨非负且质量守恒性更强的分析场,用于有物理约束的资料同化和分析场后处理研究。

论文《训练卷积神经网络以在资料同化中保持质量守恒》
https://doi.org/10.5194/npg-28-111-2021

模型描述

MassConservingCNN 由慕尼黑路德维希-马克西米利安大学气象研究所和 ClimateAi 的研究人员提出。论文使用一维改进浅水模型的孪生试验生成 EnKF 无约束分析场、QPEns 有约束分析场和雷达观测位置,以训练和验证模型。该模型适用于质量守恒资料同化校正、降雨非负约束和物理一致分析场生成。

使用场景

使用场景 说明
资料同化校正 根据 X^a 和雷达位置指示量预测 QPEns 风格的分析场。
考虑质量的训练 使用论文式 6 的误差和式 7 的质量惩罚进行训练。
ModelScope/OneCode 运行 在 ModelScope 或 OneCode 中验证训练、推理(inference)、评估、可视化及模型权重(检查点)(checkpoint)流程。
多 GPU 训练 使用 torchrun 启动分布式数据并行训练。

使用说明

1.OneCode

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

体验智能一键 AI4S 编程

2.下载与安装

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

环境依赖

硬件要求

  • 建议使用 GPU 或 DCU。
  • 可使用 CPU 在默认小样本配置下验证连通性。
  • DCU 用户必须提前安装 DTK。建议使用 DTK 25.04.2 或更高版本,或使用 OneScience 推荐的与当前集群匹配的版本。

DCU 环境

# Activate DTK and Conda first
conda create -n onescience311 python=3.11 -y
conda activate onescience311
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
pip install onescience[earth-gpu] -i http://mirrors.onescience.ai:3141/pypi/simple/ --trusted-host mirrors.onescience.ai

训练数据

默认生成器创建 24 个训练样本和 12 个验证样本,同时保留 [B,4,250] 输入和 [B,3,250] 目标。数据结合周期波、平滑对流单体、与速度辐合相关的非负降雨、降雨区雷达掩膜和平滑的 EnKF 风格误差。这些数据仅验证工程流程,不等同于论文中含 48,000 个样本的 QPEns 数据集。

python scripts/fake_data.py --force

训练

单设备训练使用以下命令。

python scripts/train.py

多 GPU 训练使用以下命令。

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

训练检查数据版本、形状、数据类型、有限值、二值雷达掩膜以及降雨非负性。模型权重(检查点)保存模型参数、优化器状态、模型配置、归一化统计量、变量顺序、数据版本、eta、训练轮次和随机种子。输出写入以下路径。

result/checkpoints/massconservingcnn.pt
result/training/metrics.json

训练权重

本仓库的 weight/ 中未附带权重。论文未提供经确认的官方模型权重(检查点),当前工程实现的模型权重(检查点)未声明与外部权重兼容。

推理

python scripts/inference.py

推理恢复训练生成的模型参数,根据无约束分析场及雷达位置指示量生成质量经校正的分析场。结果包括输入分析场、目标分析场、模型预测、雷达观测位置以及对应的物理和归一化信息,并保存至以下路径。

result/output/predictions.npz

评估与可视化

python scripts/result.py

评估结果包括核心预测误差、质量守恒误差及相对改善结果,以及输入、目标和预测的对比图。结构化指标和辅助图保存至以下路径。合成数据结果仅验证工程流程,不代表论文性能。

result/evaluation/metrics.json
result/evaluation/input_target_prediction.png

OneScience 官方信息

引用与许可证

本仓库是对公开 MassConservingCNN 规范的独立工程复现。

使用本仓库的代码、官方模型权重和数据仍须遵守各自项目的许可证和条款。

Downloads last month
20
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support