Streamflow-LSTM

Model Introduction

Streamflow-LSTM is an engineering reproduction of the gauge-specific LSTM river-flow forecasting method proposed by Hunt et al. It uses the preceding seven days of six-hourly meteorological and hydrological sequences to forecast 40 six-hourly leads, or ten days, for ten western US gauges.

Paper: Using a long short-term memory (LSTM) neural network to boost river streamflow forecasts over the western United States
https://doi.org/10.5194/hess-26-5449-2022

Model Description

The model was proposed by researchers from the University of Reading, the European Centre for Medium-Range Weather Forecasts, Loughborough University, and the UK Centre for Ecology and Hydrology. It was trained with streamflow observations from ten western US gauges together with catchment-averaged meteorological forecasts and hydrological histories. The model is suitable for improving gauge-specific river-flow forecasts over the following ten days and for comparison with persistence and GloFAS baselines. Its key feature is independent temporal learning for each gauge, combined with member selection and ensemble averaging to improve forecast robustness.

Use Cases

Use Case Description
Gauge-specific forecasting Generate 40 six-hourly streamflow leads for ten specified gauges.
Hydrological ensemble experiments Select random-initialization members by validation NSE and average their forecasts.
Local engineering validation Test the complete workflow with structured synthetic data retaining the 10x28x23x40 protocol.
ModelScope/OneCode execution Validate data generation, training, inference, evaluation, and visualization entry points.
Multi-GPU training Distribute gauge-member tasks with torchrun and consolidate one checkpoint.

Usage Instructions

1.OneCode

Try intelligent, one-click AI4S programming

2. Download and Installation

hf download OneScience-Group/Streamflow-LSTM --local-dir ./Streamflow-LSTM
cd Streamflow-LSTM

Environment Dependencies

Hardware Requirements

  • A GPU or DCU is recommended for the paper-scale ensemble.
  • 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 paper dataset combines sources including ERA5, IFS, GloFAS, and USGS for ten gauges, arranging the previous seven days as 28 six-hourly steps with 23 variables per step. The repository's deterministic synthetic data retain ten gauges, [B,28,23] inputs, and 40 six-hourly leads while reducing the numbers of training, validation, and forecast samples. These data validate engineering only and do not represent official distributions, paper-scale training, or paper performance; observed flow is frozen after issue time in forecast inputs to prevent future-observation leakage.

python scripts/fake_data.py

Training

For single-GPU 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 uses MSE, Adam at 0.001, and 0.1 dropout for every gauge member, with member tasks divided among processes. Pass --paper to restore 50 hidden units, 100 members per gauge, and selection of the best five members. All gauges and members are consolidated into one checkpoint, and the artifacts are:

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

Trained Weights

The paper does not provide directly loadable official weights, and weight/ contains only a status note. Local training stores every ensemble member for all ten gauges, normalization statistics, and validation NSE values in one result/checkpoints/streamflow_lstm.pt; it must not be represented as an official pretrained checkpoint.

Inference

python scripts/inference.py

Inference restores every gauge member from the single checkpoint and validates its format version and ten-gauge order. It selects the best two members by validation NSE in default mode or the best five in paper mode, evaluates each [C,40,28,23] input, and averages the ensemble. Outputs are clipped to non-negative streamflow and retain 40 six-hourly leads in m3 s-1. Inference results are saved to:

result/output/predictions.npz

Evaluation and Visualization

python scripts/result.py

Evaluation computes gauge-level KGE, NSE, and RMSE at two-, five-, and eight-day leads, including the correlation, variability, and bias components of KGE. Forecasts are compared with issue-time persistence and a synthetic GloFAS proxy. The figure presents mean RMSE over all leads and five-day KGE for each gauge; synthetic-data results validate engineering only. Evaluation artifacts are saved to:

result/evaluation/metrics.json
result/evaluation/comparison.png

Official OneScience Information

Citation and License

This repository is an independent engineering reproduction of the public Streamflow-LSTM specifications, with code licensed under the Apache License 2.0.

The original paper is licensed under CC BY 4.0; the paper, model weights, and ERA5, IFS, GloFAS, and USGS data remain subject to the licenses and terms of their respective projects.


中文说明

模型简介

Streamflow-LSTM 是对 Hunt 等人提出的逐站 LSTM 河川流量预报方法的工程复现。它使用过去七天每六小时一次的气象和水文序列,为美国西部十个测站预报 40 个六小时时效,即十天。

论文《使用长短期记忆(LSTM)神经网络改进美国西部河川流量预报》
https://doi.org/10.5194/hess-26-5449-2022

模型描述

该模型由雷丁大学、欧洲中期天气预报中心、拉夫堡大学及英国生态与水文中心的研究人员提出。模型使用美国西部十个测站的流量观测数据,以及流域平均气象预报和历史水文数据进行训练。该模型适用于改进各测站未来十天的河川流量预报,并可与持续性和 GloFAS 基线进行对比。其主要特点是针对每个测站独立开展时间序列学习,并结合成员筛选与集合平均以提高预报稳健性。

使用场景

使用场景 说明
逐站预报 为十个指定测站生成 40 个六小时时效的流量预报。
水文集合实验 按验证 NSE 筛选随机初始化的成员,并对其预报取平均。
本地工程验证 使用保留 10x28x23x40 协议的结构化合成数据测试完整流程。
ModelScope/OneCode 运行 验证数据生成、训练、推理(inference)、评估和可视化入口。
多 GPU 训练 通过 torchrun 分配测站与成员任务,并合并为一个模型权重(检查点)(checkpoint)。

使用说明

1.OneCode

体验智能一键 AI4S 编程

2. 下载与安装

hf download OneScience-Group/Streamflow-LSTM --local-dir ./Streamflow-LSTM
cd Streamflow-LSTM

环境依赖

硬件要求

  • 论文规模的集合建议使用 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

训练数据

论文的数据集结合 ERA5、IFS、GloFAS 和 USGS 等来源,为十个测站将过去七天整理为 28 个六小时时间步,每个时间步包含 23 个变量。仓库的确定性合成数据保留十个测站、[B,28,23] 输入和 40 个六小时时效,同时减少训练、验证和预报样本数。这些数据仅用于工程验证,不代表官方分布、论文规模的训练或论文性能。预报输入中的观测流量在起报时刻之后保持不变,以防未来观测泄漏。

python scripts/fake_data.py

训练

单 GPU 训练使用以下命令。

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

训练对每个测站成员使用 MSE、学习率为 0.001 的 Adam 和 0.1 的 Dropout,并将成员任务分配给各进程。传入 --paper 可恢复 50 个隐藏单元、每站 100 个成员及选取最优五个成员的设置。所有测站和成员合并为一个模型权重(检查点),产物如下。

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

训练权重

论文未提供可直接加载的官方权重,weight/ 只包含状态说明。本地训练将全部十个测站的每个集合成员、归一化统计量及验证 NSE 值存放在同一个 result/checkpoints/streamflow_lstm.pt 文件中,不得将其作为官方预训练模型权重(检查点)。

推理

python scripts/inference.py

推理从单个模型权重(检查点)恢复每个测站的成员,并验证其格式版本及十个测站的顺序。它在默认模式下按验证 NSE 选出最优的两个成员,在论文模式下选出最优的五个成员,对每个 [C,40,28,23] 输入进行计算并取集合平均值。输出经裁剪以保证流量非负,保留以 m3 s-1 为单位的 40 个六小时时效。推理结果保存至以下路径。

result/output/predictions.npz

评估与可视化

python scripts/result.py

评估计算两天、五天和八天时效的站点级 KGE、NSE 和 RMSE,包括 KGE 的相关性、变异性和偏差分量。预报与起报时刻的持续性基线和合成 GloFAS 代理值对比。图中展示所有时效的平均 RMSE 及各测站的五天 KGE。合成数据结果仅用于工程验证。评估产物保存至以下路径。

result/evaluation/metrics.json
result/evaluation/comparison.png

OneScience 官方信息

引用与许可证

本仓库是对公开 Streamflow-LSTM 规范的独立工程复现,代码采用 Apache License 2.0。

原始论文采用 CC BY 4.0 许可证。论文、模型权重及 ERA5、IFS、GloFAS 和 USGS 数据仍受各自项目的许可证与条款约束。

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