Skip to main content

Pre-delineated MERIT-Hydro watershed boundaries for ~60,000 gauging stations across 16 countries

Project description

watershed-retrieve

PyPI version License: MIT Python 3.13+

Instant access to ~60,000 pre-delineated MERIT-Hydro watershed boundaries and river networks across 16 countries, served as GeoParquet. No data download required — basins are fetched on demand from a public CDN and cached locally.

Background

This library is a community contribution to the RivRetrieve ecosystem. Where RivRetrieve provides observed streamflow time series for gauging stations worldwide, watershed-retrieve adds the corresponding watershed boundaries and river networks, delineated on the MERIT-Hydro digital elevation model.

See the original proposal: kratzert/RivRetrieve-Python#87.

Installation

pip install watershed-retrieve

Quick Start

import watershed_retrieve as wr

# Zero-config — data is fetched from R2 CDN and cached locally
watershed = wr.get_watershed("portugal", "04K/04A")

# With river network
watershed, rivers = wr.get_watershed_with_rivers("portugal", "04K/04A")

# Bulk retrieval — all watersheds for a country
all_watersheds = wr.get_watersheds("portugal")

To use a local data directory instead of the CDN:

# Option 1: Environment variable
# export WATERSHED_RETRIEVE_DATA_DIR=/path/to/parquet/files

# Option 2: Programmatic
wr.configure("/path/to/parquet/files")

# Option 3: Explicit backend selection
from watershed_retrieve import Backend
wr.configure(backend=Backend.R2, cache_dir=Path("~/.my-cache"))

API Reference

Discovery

# List all supported countries
wr.available_countries()
# -> ['australia', 'brazil', 'canada', ..., 'usa']

# List gauge IDs for a country
wr.available_gauges("portugal")
# -> ['02G-02H', '02O-01H', ..., '16J-01H']  (73 gauges)

Single Watershed

# Watershed boundary (GeoDataFrame, 1 row)
gdf = wr.get_watershed("portugal", "04K/04A")

# Watershed + river network (WatershedResult — unpackable NamedTuple)
result = wr.get_watershed_with_rivers("portugal", "04K/04A")
watershed, rivers = result

Bulk Retrieval

# All watersheds for a country
gdf = wr.get_watersheds("portugal")  # -> GeoDataFrame (73 rows)

# Subset by gauge IDs
gdf = wr.get_watersheds("portugal", ["04K/04A", "05G/01A"])

# With rivers
result = wr.get_watersheds_with_rivers("portugal")
result.watershed  # GeoDataFrame
result.rivers     # GeoDataFrame

Gauge ID Normalization

Slashes are automatically normalized to dashes:

wr.get_watershed("portugal", "04K/04A")   # slash
wr.get_watershed("portugal", "04K-04A")   # dash — equivalent

Errors

from watershed_retrieve import (
    WatershedRetrieveError,     # base class
    CountryNotFoundError,       # invalid country name
    GaugeNotFoundError,         # gauge ID not in dataset
    DataNotFoundError,          # parquet file missing
    DataUnavailableError,       # region exists but data not yet extracted
    R2ConnectionError,          # CDN fetch failed
)

DataUnavailableError is raised for regions where gauging stations are registered in RivRetrieve but MERIT-Hydro basin delineation is pending (e.g., UK regions — the British Isles fall outside MERIT-Hydro coverage).

Supported Countries

Country Gauges Status
Australia ~5,200 Available
Brazil ~4,300 Available
Canada ~5,800 Available
Chile ~500 Available
Czech Republic ~400 Available
France ~5,400 Available
Germany ~500 Available
Japan ~1,200 Available
Lithuania ~70 Available
Norway ~600 Available
Poland ~600 Available
Portugal 73 Available
Slovenia ~200 Available
South Africa ~900 Available
Spain ~600 Available
UK (EA) ~1,500 Pending — MERIT-Hydro coverage gap
UK (NRFA) ~1,500 Pending — MERIT-Hydro coverage gap
USA ~32,000 Available

Development

# Install
git clone https://github.com/CooperBigFoot/watershed-retrieve.git
cd watershed-retrieve
uv sync

# Unit tests (no data or network needed)
uv run pytest tests/ -v -m "not integration and not network"

# Integration tests (requires local parquet data)
WATERSHED_RETRIEVE_DATA_DIR=/path/to/data uv run pytest tests/ -v -m integration

# Lint & format
uv run ruff check --fix src/ tests/
uv run ruff format src/ tests/

See CONTRIBUTING.md for full development guidelines.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

watershed_retrieve-1.0.0.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

watershed_retrieve-1.0.0-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file watershed_retrieve-1.0.0.tar.gz.

File metadata

  • Download URL: watershed_retrieve-1.0.0.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.0

File hashes

Hashes for watershed_retrieve-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d73157d02f5a9b7a3e312651ca95c4e41f37c476daaf5f7585ddc487075713ed
MD5 65b690d145042b91b9dcf2b39ce01b1a
BLAKE2b-256 359883ba3402bfe115cb01081a529880d43e32aa07a2ede360cb8f7018c813b1

See more details on using hashes here.

File details

Details for the file watershed_retrieve-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for watershed_retrieve-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f9bd888286bdbff4c1153acbab089c73317a99f177e0af6c6306eea1f0f6988a
MD5 6e1014119e7239f88ed9d5d55022646e
BLAKE2b-256 93f0b291a1ecb031d9a5df66a88c8a93818d80e84d483e5e6a917f3d737b04d6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page