TorchHydro¶
A PyTorch-based deep learning framework for hydrological modeling. Supports Normal, Transfer Learning, Multi-Task Learning, and Federated Learning modes.
Documentation: https://OuyangWenyu.github.io/torchhydro
Installation¶
Python 3.10+ required.
1 | |
or with uv (faster):
1 | |
See the Installation Guide for developer setup.
Quick Start¶
1. Configure data path¶
Create hydro_setting.yml in your home directory (~/ or %USERPROFILE%):
1 2 3 4 5 | |
Standard dataset paths (e.g., CAMELS-US) are resolved automatically from this root by the unified data resolver.
2. Run a model¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | |
See examples/ for runnable scripts:
- examples/lstm_camels_example.py — Standard LSTM on CAMELS-US
- examples/dpl_xaj_example.py — Differentiable Xinanjiang (XAJ) model
Features¶
Models¶
| Category | Models |
|---|---|
| LSTM variants | SimpleLSTM, CudaLSTM, CNNLSTM, MCLSTM, SPPLSTM, BALSTM, MTSLSTM |
| Seq2Seq / Encoder-Decoder | GeneralSeq2Seq, Transformer, DataFusionModel, SeqForecast |
| Differentiable physical models | DPL-XAJ, DPL-HBV, DPL-GR4J, DPL-MC-Reservoir |
| Graph neural networks | GCN, ResGCN, GCNII, ResGAT, GCGRU, GCLSTM, STGCN |
| Mixture of Experts | DenseMoE, SparseMoE, SwitchMoE, HydrologyTopKMoE, GlobalTopKMoE |
| Generative / spectral | Diffusion, FNO (Fourier Neural Operator) |
| Specialized | WDNE (3D flood), CoupledLSTM, RegulLSTM |
Datasets¶
Standard datasets resolved via hydrodataset and hydrodatasource:
dataset_id |
Description |
|---|---|
camels_us |
CAMELS-US (671 US basins) |
camelsh |
CAMELS-Hourly |
caravan / grdc_caravan |
Caravan / GRDC-Caravan collections |
camels_aus / camels_br / camels_cl / camels_gb / camels_col |
CAMELS regional datasets |
Custom data sources: selfmadehydrodataset, selfmadeforecastdataset, longtermdataset, floodeventdatasource, stationhydrodataset, tghydrodatasource.
Training modes¶
- Standard supervised learning — single basin or regional training
- Transfer learning — cross-basin model adaptation
- Multi-task learning — shared backbone, task-specific heads
- Federated learning — decentralized basin-level training
Key capabilities¶
- Unified data resolver — all dataset paths from one
hydro_setting.ymlconfig - Monthly and sub-daily (hourly) time units
- Cloud-Zarr lazy loading for joint training on remote data
- Lightning Fabric integration for debugging and distributed training
- SHAP-based model interpretability and loss landscape visualization
- Advanced dropout strategies and data augmentation
Guides & Documentation¶
Examples & Results¶
- LSTM on CAMELS-US — baseline benchmark and basin-level performance
- Songliao Flood Models — LSTM, MCLSTM, GNN, WDNE flood forecasting
- Sanxia Multi-Site — reservoir and multi-site experiments
- MoE / Diffusion / FNO — advanced model experiments
- Seq2Seq / BALSTM / MTSLSTM — encoder-decoder and spatial-temporal models
Advanced Topics¶
- Cloud-Zarr Joint Training — lazy loading for large-scale remote data
- Lightning Fabric — debugging and distributed training
- ERA5-Land & GPM — gridded meteorological data experiments
- Model Interpretability — SHAP and loss landscape analysis
API Reference¶
Models · Datasets · Trainers · Configs · Explainers
Architecture¶
1 2 3 4 5 6 7 | |
Why TorchHydro?¶
- Decoupled data layer — a unified resolver supports 10+ datasets, custom sources, and cloud storage; data tooling is usable even without a deep-learning model
- Flexible learning paradigms — transfer, multi-task, and federated learning are first-class, not afterthoughts
- Deep configuration — fine-grained control over data traversal, normalization, batch sampling, and advanced dropout
- Extensible — configuration is externalized so new data sources and models plug in without modifying core code
Contributing¶
See the Contributing Guide for development setup, code standards, and pull request workflow.
License¶
BSD License. See LICENSE.