Skip to main content

TorchRiver

TorchRiver is a Python library for river low-flow and drought early warning. It provides a notebook-friendly workflow for loading river data, training forecasting models, predicting low-flow risk, saving .triver models, and launching an Arabic RTL Gradio interface.

The default architecture is river_cnn_lstm:

Conv1D -> ReLU -> MaxPool1D -> LSTM -> Dense -> probability/logit

Available architectures:

Name Description
river_cnn_lstm Conv1D + LSTM hybrid (default, recommended)
cnn_lstm Alias for river_cnn_lstm
lstm Pure LSTM recurrent model
gru GRU recurrent model
cnn Pure convolutional model
mlp Multi-layer perceptron (fully connected)
transformer Transformer encoder model
custom Bring your own nn.Module

Repository: https://github.com/torchriver/torchriver

Installation

pip install torchriver

In Google Colab:

%pip install -q torchriver

TorchRiver Quick Start

Open the main full notebook:

A smaller compact notebook is also included:

Quick start in Python

from torchriver import RiverProject

project = RiverProject(title="TorchRiver", lang="ar", direction="rtl")

project.make_synthetic(
    days=240,
    station_codes=["R001", "R002", "R003"],
    station_names={"R001": "River One", "R002": "River Two", "R003": "River Three"},
)

project.clean()
project.use_model(
    "river_cnn_lstm",
    horizons=[7, 14, 30],
    lookback=30,
    device="auto",
    window_mode="per_station",
    balance_classes=True,
)
project.train(epochs=2, batch_size=512, lr=0.001, seed=42)
print(project.predict_all(horizon=14))
project.save_model("river_warning_model.triver", include_recent_data=True)

Kaggle example

import os, getpass
from torchriver import RiverProject

KAGGLE_URL = "https://www.kaggle.com/datasets/assemelqirsh/elbe-river-data-lake"
os.environ["KAGGLE_USERNAME"] = "YOUR_KAGGLE_USERNAME"
os.environ["KAGGLE_KEY"] = getpass.getpass("Paste Kaggle API key/token hidden: ")

project = RiverProject(title="TorchRiver", lang="ar", direction="rtl")
project.load_kaggle(KAGGLE_URL, nrows=200_000, fallback_synthetic=False)
project.clean()
project.use_model("river_cnn_lstm", horizons=[7, 14, 30], lookback=30, window_mode="per_station", balance_classes=True)
project.train(epochs=2, batch_size=512, lr=0.001)
print(project.predict_all(horizon=14))

TorchRiver never stores Kaggle API keys. Use KAGGLE_USERNAME and KAGGLE_KEY, Kaggle's standard ~/.kaggle/kaggle.json, or a hidden prompt.

Notebooks

All notebooks install TorchRiver from PyPI with %pip install -q torchriver.

Notebook Purpose GitHub Colab
notebooks/TorchRiver_Quick_Start.ipynb Main full quick-start runner https://github.com/torchriver/torchriver/blob/main/notebooks/TorchRiver_Quick_Start.ipynb https://colab.research.google.com/github/torchriver/torchriver/blob/main/notebooks/TorchRiver_Quick_Start.ipynb
notebooks/TorchRiver_Quick_Start_small.ipynb Small compact quick start https://github.com/torchriver/torchriver/blob/main/notebooks/TorchRiver_Quick_Start_small.ipynb https://colab.research.google.com/github/torchriver/torchriver/blob/main/notebooks/TorchRiver_Quick_Start_small.ipynb
notebooks/02_quick_start_synthetic_train_predict.ipynb Synthetic training and prediction https://github.com/torchriver/torchriver/blob/main/notebooks/02_quick_start_synthetic_train_predict.ipynb https://colab.research.google.com/github/torchriver/torchriver/blob/main/notebooks/02_quick_start_synthetic_train_predict.ipynb
notebooks/03_kaggle_url_train_river.ipynb Kaggle URL training https://github.com/torchriver/torchriver/blob/main/notebooks/03_kaggle_url_train_river.ipynb https://colab.research.google.com/github/torchriver/torchriver/blob/main/notebooks/03_kaggle_url_train_river.ipynb
notebooks/08_save_load_triver.ipynb Save/load .triver models https://github.com/torchriver/torchriver/blob/main/notebooks/08_save_load_triver.ipynb https://colab.research.google.com/github/torchriver/torchriver/blob/main/notebooks/08_save_load_triver.ipynb
notebooks/09_gradio_rtl_arabic.ipynb Arabic RTL Gradio UI https://github.com/torchriver/torchriver/blob/main/notebooks/09_gradio_rtl_arabic.ipynb https://colab.research.google.com/github/torchriver/torchriver/blob/main/notebooks/09_gradio_rtl_arabic.ipynb

See notebooks/00_INDEX.ipynb for the full notebook list:

https://github.com/torchriver/torchriver/blob/main/notebooks/00_INDEX.ipynb

Examples

pip install torchriver
python examples/01_train_synthetic.py
python examples/02_train_kaggle_url.py

See examples/README.md for all script examples:

https://github.com/torchriver/torchriver/blob/main/examples/README.md

Compatible data format

Default columns:

date
station_code
station
discharge_m3s
low_flow_q10_threshold_m3s
sdi_30
precipitation_mm
temperature_c
ndwi
target_lowflow

Custom schemas are supported through mapping:

project.load_file(
    "my_river_data.csv",
    mapping={
        "date": "day",
        "station": "gauge_id",
        "station_name": "gauge_name",
        "discharge": "Q_m3s",
        "low_flow_threshold": "Q10",
        "target": "low_flow_flag",
    },
)

If a threshold is missing, TorchRiver computes Q10 per station. If the target is missing, it creates:

target_lowflow = discharge_m3s < low_flow_q10_threshold_m3s

Prediction

project.predict(station="501060", horizon=14)
project.predict_all(horizon=14)
project.diagnose_predictions(horizon=14)

Prediction uses the last lookback days for the selected station. TorchRiver does not reuse the same last rows for every station.

Gradio API

project.launch_river_style(share=True, api=True, direction="rtl")

Client usage:

from gradio_client import Client

client = Client("GRADIO_URL")
client.predict("501060 - DRESDEN", "+14 days", api_name="/predict")

Save/load

project.save_model("river_warning_model.triver", include_recent_data=True)

from torchriver import load_river_model
loaded = load_river_model("river_warning_model.triver")
loaded.predict(station="501060", horizon=14)

Tests

pytest

Repository folders

docs/       Documentation
examples/   Runnable Python examples
notebooks/  Colab and Jupyter notebooks
data/       Small sample datasets
tests/      Pytest tests

License

MIT

Metadata

Release files for torchriver 2.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for torchriver 2.0.1
File Size Uploaded
torchriver-2.0.1.tar.gz 26.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for torchriver 2.0.1
File Interpreter ABI Platform
torchriver-2.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 54.3 kB

Release files / torchriver-2.0.1.tar.gz

Download URL torchriver-2.0.1.tar.gz
Size 26.5 kB
Tags Source
SHA-256 checksum
How to use checksums
7d9e72f0a859b9f08320b039db98819cbd189cce5e946ea65bfb1ec914aa7f1f
BLAKE2b-256 checksum
How to use checksums
7bfce3b4fc9f23f2da8a8efa019b9c2cea2bd3ae162b0bd2cbdde281116aa0e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 9, 2026.

Transparency log

Release files / torchriver-2.0.1-py3-none-any.whl

Download URL torchriver-2.0.1-py3-none-any.whl
Size 27.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
754a0a63f8b2c8ca544cd62037976d1757378aaabafa91fa203b87fc9a999019
BLAKE2b-256 checksum
How to use checksums
53738d033ea3aefde311b3fc672efb4d4a53a1a84405abed36f9b7bd66f2fd2e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 9, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

2.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page