datasets, samplers, transforms, and pre-trained models for hydrology and water resources
Project description
Torchhydro
- License: BSD license
- Documentation: https://OuyangWenyu.github.io/torchhydro
torchhydro provides datasets and models for applying deep learning to hydrological modeling.
Installation
For Users
You can install torchhydro using pip or uv (which is faster).
pip install torchhydro
or
uv pip install torchhydro
For Developers
If you want to contribute to the project, we recommend using uv for environment management.
# Clone the repository
git clone https://github.com/OuyangWenyu/torchhydro.git
cd torchhydro
# Create a virtual environment and install all dependencies
uv sync --all-extras
Usage
1. Configure Data Path
Before running any examples, you need to tell torchhydro where your data is located.
Create a file named hydro_setting.yml in your user home directory (C:\Users\YourUsername on Windows or ~/ on Linux/macOS). Then, add the following content, pointing to your data folders:
local_data_path:
root: 'D:/data/waterism' # Update with your root data directory
datasets-origin: 'D:/data/waterism/datasets-origin'
datasets-interim: 'D:/data/waterism/datasets-interim'
cache: 'D:/data/waterism/cache'
The examples use the CAMELS dataset. If you don't have it, torchhydro will automatically call hydrodataset to download it.
2. Run Examples
We provide standalone scripts in the examples/ directory to help you get started.
examples/lstm_camels_example.py: A basic example of training a standard LSTM model on the CAMELS dataset.examples/dpl_xaj_example.py: An advanced example of training a differentiable model based on the Xinanjiang (XAJ) hydrological model.
To run an example:
python examples/lstm_camels_example.py
Feel free to modify these scripts to experiment with different models, datasets, and parameters.
Explore More Features
The examples above cover two primary use cases, but torchhydro is much more flexible. We support a variety of models, datasets, and data sources out of the box. Explore the full public API to see all available components:
- Models API: Discover all available model architectures.
- Datasets API: See all dataset classes, data sources, and samplers.
- Trainers API: Understand the core training and evaluation pipeline.
We are continuously working to expand the documentation with more examples.
Main Modules
The project is organized into several key modules:
- Trainers: Manages the end-to-end training and evaluation pipeline. The core
DeepHydroclass handles data loading, model initialization, training loops, and evaluation. It is designed to be extensible for various learning paradigms like transfer learning or multi-task learning. - Models: Contains all available model architectures, including standard neural networks (e.g., LSTM) and differentiable models. A central dictionary allows for easy configuration and selection of models and loss functions.
- Datasets: Provides data handling capabilities. It interfaces with data source libraries like hydrodataset (for public datasets like CAMELS) and hydrodatasource (for custom data) to create
torch.utils.data.Datasetobjects suitable for training. - Configs: Manages all experiment configurations, including settings for the model, data (time periods, variables), training (epochs, batch size), and evaluation.
Why Torchhydro?
While mature tools like NeuralHydrology exist, torchhydro was developed with a different architectural philosophy:
- Decoupled Data Sources: We believe data handling, especially for complex or private datasets, requires a separate abstraction layer. Our approach uses
hydrodatasetandhydrodatasourceto manage data access first, which then feeds into a PyTorchDataset. This modularity promotes code reuse and allows the data source tools to be used even without a deep learning model. - Flexible Learning Paradigms: The framework is explicitly designed to support not just standard supervised learning, but also more complex modes like transfer learning, multi-task learning, and federated learning from the ground up.
- Deep Configuration: We provide fine-grained control over many aspects of the pipeline, including data traversal, normalization methods, batch sampling strategies, and advanced dropout techniques, allowing for greater flexibility in experimentation.
- Extensibility: The core design principle is to externalize as much configuration as possible, enabling flexible matching and calling of different data sources and models.
Additional Information
This package was inspired by:
This package was created using the Cookiecutter and the giswqs/pypackage project template.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file torchhydro-0.1.0.tar.gz.
File metadata
- Download URL: torchhydro-0.1.0.tar.gz
- Upload date:
- Size: 198.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f32a456d0d29529c28a138917468e7faa72c38d433d2124beb6528c6453a678
|
|
| MD5 |
26695c18cd8d68987b0b090a1506f0b1
|
|
| BLAKE2b-256 |
0c340e9513a99d1932f958c3f685cbbf81e571e1acd52bc8defae260481dc507
|
Provenance
The following attestation bundles were made for torchhydro-0.1.0.tar.gz:
Publisher:
pypi.yml on OuyangWenyu/torchhydro
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torchhydro-0.1.0.tar.gz -
Subject digest:
7f32a456d0d29529c28a138917468e7faa72c38d433d2124beb6528c6453a678 - Sigstore transparency entry: 684868756
- Sigstore integration time:
-
Permalink:
OuyangWenyu/torchhydro@aff0946c84dae3c1eb4fdf164e8efdb0e25fc385 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/OuyangWenyu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@aff0946c84dae3c1eb4fdf164e8efdb0e25fc385 -
Trigger Event:
release
-
Statement type:
File details
Details for the file torchhydro-0.1.0-py3-none-any.whl.
File metadata
- Download URL: torchhydro-0.1.0-py3-none-any.whl
- Upload date:
- Size: 180.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d78f124dcbd09ebf9facd64cffc4ac0a45d71fd65810d1f48bc931e1c9e408e3
|
|
| MD5 |
5046a1565b2562fe97889cf48a77b49c
|
|
| BLAKE2b-256 |
5d204bfde1e13092b38bbedd096f8a43883cbff12b7a9a067682e27635cd673f
|
Provenance
The following attestation bundles were made for torchhydro-0.1.0-py3-none-any.whl:
Publisher:
pypi.yml on OuyangWenyu/torchhydro
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torchhydro-0.1.0-py3-none-any.whl -
Subject digest:
d78f124dcbd09ebf9facd64cffc4ac0a45d71fd65810d1f48bc931e1c9e408e3 - Sigstore transparency entry: 684868759
- Sigstore integration time:
-
Permalink:
OuyangWenyu/torchhydro@aff0946c84dae3c1eb4fdf164e8efdb0e25fc385 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/OuyangWenyu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@aff0946c84dae3c1eb4fdf164e8efdb0e25fc385 -
Trigger Event:
release
-
Statement type: