Skip to content

hydrodataset

PyPI version conda-forge License: MIT Documentation Status Python 3.10+

A Python package for accessing hydrological datasets with a unified API, optimized for deep learning workflows.

  • 🌊 Unified Interface: Consistent API across 27 hydrological datasets
  • Fast Access: NetCDF caching locally / Zarr caching on cloud for instant data loading
  • 🎯 Standardized Variables: Common naming across all datasets
  • 🔗 Built on AquaFetch: Powered by the comprehensive AquaFetch backend
  • 📊 ML-Ready: Optimized for integration with torchhydro

Table of Contents

Core Philosophy

This library has been redesigned to serve as a powerful data-adapting layer on top of the AquaFetch package.

While AquaFetch handles the complexities of downloading and reading numerous public hydrological datasets, hydrodataset takes the next step: it standardizes this data into a clean, consistent format — NetCDF (.nc) locally, Zarr on cloud object storage — optimized for seamless integration with hydrological modeling libraries like torchhydro.

One unified way to reach any dataset. Every dataset is addressed by a logical id ("camels_us", "bull", …) resolved through a single chain:

1
~/hydro_setting.yml (storage config) → resolve_data_path / open_dataset → absolute path or s3:// URI

You never construct a data path by hand. open_dataset(dataset_id, source="local"|"cloud") resolves the id, picks the right reader class, and returns an instantiated dataset — source is chosen per call, or defaults to storage.default_source. When you need the raw path or a specific class directly, resolve_data_path(dataset_id) + the class constructor remain available (see Quick Start).

The core workflow is: 1. Resolve: resolve_data_path / open_dataset turns a dataset id into an absolute local path or an s3:// URI, using the config in ~/hydro_setting.yml. 2. Standardize: The hydrodataset reader (backed by AquaFetch) fetches raw data and exposes it through a consistent, unified interface across all datasets. 3. Cache: On the first run, the data is processed into an xarray.Dataset and saved as .nc files (timeseries + attributes) in the local cache directory — or as Zarr stores on cloud storage for source="cloud". 4. Access: All subsequent requests read from the fast cache (NetCDF locally / Zarr on cloud), giving you analysis-ready data instantly.

Installation

We strongly recommend using a virtual environment to manage dependencies.

We recommend using uv for fast, reliable package and environment management:

1
2
3
4
5
# Install uv if you haven't already
pip install uv

# Install hydrodataset with uv
uv pip install hydrodataset

For more advanced usage or to work on the project locally:

1
2
3
4
5
6
# Clone the repository
git clone https://github.com/OuyangWenyu/hydrodataset.git
cd hydrodataset

# Create virtual environment and install all dependencies
uv sync --all-extras

The --all-extras flag installs base dependencies plus all optional dependencies for development and documentation.

Using pip (Alternative)

If you prefer traditional pip:

1
2
3
4
5
6
# Create and activate a virtual environment
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install the package
pip install hydrodataset

Quick Start

The primary goal of hydrodataset is to provide a simple, unified API for accessing various hydrological datasets. Here's a complete example showing the core workflow:

⚠️ Important Note on First-Time Data Download

If you haven't pre-downloaded the datasets, the first access will trigger automatic downloads via AquaFetch, which can take considerable time depending on dataset size:

  • Small datasets (< 1GB, e.g., CAMELS-CL, CAMELS-COL): ~10-30 minutes
  • Medium datasets (1-5GB, e.g., CAMELS-AUS, CAMELS-BR): ~30 minutes to 1 hour
  • Large datasets (10-20GB, e.g., CAMELS-US, LamaH-CE): ~1-3 hours
  • Very large datasets (> 30GB, e.g., HYSETS): ~3-6 hours or more

Download times vary based on your internet connection speed and server availability.

We strongly recommend downloading datasets manually during off-peak hours if possible.

After the initial download, all subsequent access will be fast thanks to NetCDF caching (locally) or Zarr caching (on cloud).

Basic Example

 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
28
29
30
31
32
33
34
35
36
37
38
39
40
from hydrodataset import open_dataset

# open_dataset reads storage config from ~/hydro_setting.yml.
# Example hydro_setting.yml:
#
#   storage:
#     local:
#       root: D:/data/hydrodatasets
#
# source defaults to storage.default_source ("local" unless configured otherwise).
ds = open_dataset("camels_us")

# 1. Check which features are available
print("Available static features:")
print(ds.available_static_features)

print("Available dynamic features:")
print(ds.available_dynamic_features)

# 2. Get a list of all basin IDs
basin_ids = ds.read_object_ids()

# 3. Read static (attribute) data for a subset of basins
# Note: We use standardized names like 'area' and 'p_mean'
attr_data = ds.read_attr_xrdataset(
    gage_id_lst=basin_ids[:2],
    var_lst=["area", "p_mean"]
)
print("Static attribute data:")
print(attr_data)

# 4. Read dynamic (time-series) data for the same basins
# Note: We use standardized names like 'streamflow' and 'precipitation'
ts_data = ds.read_ts_xrdataset(
    gage_id_lst=basin_ids[:2],
    t_range=["1990-01-01", "1995-12-31"],
    var_lst=["streamflow", "precipitation"]
)
print("Time-series data:")
print(ts_data)

Explicit construction (advanced)

open_dataset is the recommended entry point. If you need the resolved path directly (e.g. to pass it somewhere) or want to instantiate a specific reader class, use resolve_data_path + the class constructor — this is equivalent and still fully supported:

1
2
3
4
5
from hydrodataset import resolve_data_path
from hydrodataset.camels_us import CamelsUs

data_path = resolve_data_path("camels_us")   # absolute local path (or s3:// URI)
ds = CamelsUs(data_path)                     # same object as open_dataset("camels_us")

Standardized Variable Names

A key feature of the new architecture is the use of standardized variable names. This allows you to use the same variable name to fetch the same type of data across different datasets, without needing to know the specific, internal naming scheme of each one.

For example, you can get streamflow from both CAMELS-US and CAMELS-AUS using the same variable name:

1
2
3
4
5
# Get streamflow from CAMELS-US
us_ds.read_ts_xrdataset(gage_id_lst=["01013500"], var_lst=["streamflow"], t_range=["1990-01-01", "1995-12-31"])

# Get streamflow from CAMELS-AUS
aus_ds.read_ts_xrdataset(gage_id_lst=["A4260522"], var_lst=["streamflow"], t_range=["1990-01-01", "1995-12-31"])

Similarly, you can use precipitation, temperature_max, etc., across datasets. See Standard Variables for the comprehensive list of standardized names and their coverage across datasets.

Local vs Cloud Data Access

hydrodataset can read the same datasets from either a local disk or cloud object storage (S3-compatible, e.g. Alibaba Cloud OSS). The backend is chosen per call with source="local" | "cloud"; when omitted, storage.default_source from ~/hydro_setting.yml is used (default: local).

Both backends share one configuration file, ~/hydro_setting.yml:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
storage:
  default_source: local         # local | cloud — used when `source` is omitted
  local:
    root: D:/data/hydrodatasets # absolute local path; must exist
  cache: data/cache             # optional; relative paths resolve against local.root
  s3:
    bucket: hydrodataset        # required for cloud access
    prefix: ""                  # optional prefix inside the bucket
    endpoint_url: https://oss-cn-beijing.aliyuncs.com
    access_key_id: <your-access-key>
    secret_access_key: <your-secret-key>

Local

  • resolve_data_path("camels_us", source="local") returns an absolute local path under storage.local.root.
  • Readers cache analysis-ready data as NetCDF files ({dataset}_timeseries.nc, {dataset}_attributes.nc) in the cache directory (storage.cache, default ~/.cache/hydrodataset). Missing caches are generated automatically on first read.

Cloud

  • resolve_data_path("camels_us", source="cloud") returns an S3 URI such as s3://hydrodataset/.
  • Readers access the raw dataset directly on OSS via s3fs and cache analysis-ready data as Zarr stores at s3://<bucket>/zarr/{dataset}_timeseries.zarr and ..._attributes.zarr (with consolidated metadata). Missing Zarr stores are generated automatically on first read — typically on a cloud VM (ECS) using the internal OSS endpoint for bandwidth.

Recommended usage: open_dataset(dataset_id, source=...) — one call to resolve and construct, source picks the backend per call. resolve_data_path(dataset_id, source=...) is for when you need the raw path or URI explicitly (e.g. to inspect or pass it on). Both share the same source semantics:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
from hydrodataset import resolve_data_path, open_dataset

# Local
local_uri = resolve_data_path("camels_us", source="local")
ds = open_dataset("camels_us", source="local")
ts = ds.read_ts_xrdataset(
    gage_id_lst=["01013500"],
    t_range=["1990-01-01", "1995-12-31"],
    var_lst=["streamflow", "precipitation"],
)

# Cloud
cloud_uri = resolve_data_path("camels_us", source="cloud")
print(cloud_uri)  # e.g. s3://hydrodataset/
ds_cloud = open_dataset("camels_us", source="cloud")
ts_cloud = ds_cloud.read_ts_xrdataset(
    gage_id_lst=["01013500"],
    t_range=["1990-01-01", "1995-12-31"],
    var_lst=["streamflow"],
)

The CLI exposes the same --source switch:

1
2
3
4
5
hydrodataset config                                    # show effective config (secrets masked)
hydrodataset resolve camels_us --source local
hydrodataset resolve camels_us --source cloud
hydrodataset info camels_us --source cloud
hydrodataset read-ts bull --source cloud --gages BULL_10004 --vars precipitation -o ts.nc

Notes:

  • The config file lives in your home directory (~/hydro_setting.yml). A project-level .hydro_setting.yml in the project root is also supported and overrides user-level settings.
  • storage.s3.* contains credentials — never commit it to a repository.
  • Readers constructed with an s3:// URI skip local path validation and are treated as cloud readers (_is_cloud()).

Supported Datasets

hydrodataset currently provides unified access to 27 hydrological datasets across the globe. Below is a summary of all supported datasets:

Dataset Name Paper Temporal Resolution Data Version Region Basins Time Span Release Date Size
BULL Paper / Code Daily Version 3 (code) / Version 2 (data) Spain 484 1951-01-02 to 2021-12-31 2024-03-10 2.2G
CAMELS-AUS Paper (V1) / Paper (V2) Daily Version 1 / Version 2 Australia 561 1950-01-01 to 2022-03-31 2024-12 2.1G
CAMELS-BR Paper Daily Version 1.2 / Version 1.1 Brazil 897 1980-01-01 to 2024-10-22 2025-03-21 1.4G
CAMELS-CH Paper Daily Version 0.9 / Version 0.6 Switzerland 331 1981-01-01 to 2020-12-31 2025-03-14 793.1M
CAMELS-CL Paper Daily Dataset Chile 516 1913-02-15 to 2018-03-09 2018-09-28 208M
CAMELS-COL Paper Daily Version 2 Colombia 347 1981-05 to 2022-12 2025-05 80.9M
CAMELS-DE Paper Daily Version 1.1 / Version 0.1 Germany 1582 1951-01-01 to 2020-12-31 2025-08-07 2.2G
CAMELS-DK Paper Daily Version 6.0 Denmark 304 1989-01-02 to 2023-12-31 2025-02-14 1.41G
CAMELS-FI Meeting Yearly/Daily Version 1.0.1 Finland 320 1961-01-01 to 2023-12-31 2025-07 382M
CAMELS-FR Paper Daily/Monthly/Yearly Version 3.2 / Version 3 France 654 1970-01-01 to 2021-12-31 2025-08-12 364M
CAMELS-GB Paper Daily Dataset United Kingdom 671 1970-10-01 to 2015-09-30 2025-05 (new data link) 244M
CAMELS-IND Paper Daily Version 2.2 India 472 (242 sufficient flow) 1980-01-01 to 2020-12-31 2025-03-13 529.4M
CAMELS-LUX Paper Hourly/Daily Version 1.1 Luxembourg 56 2004-11-01 to 2021-10-31 2024-09-27 1.4G
CAMELS-PE Paper Daily Version 1.0.1 Peru 136 1981-01-01 to 2025-12-31 2026-07-04 121.4M
CAMELS-NZ Paper Hourly/Daily Version 2 / Version 1 New Zealand 369 1972-01-01 to 2024-08-02 2025-08-05 4.81G
CAMELS-SE Paper Daily Version 1 Sweden 50 1961-2020 2024-02 16.19M
CAMELS-US Paper Daily Version 1.2 United States 671 1980-2014 2022-06-24 14.6G
CAMELSH-KR - Hourly Version 1 South Korea 178 2000-2019 2025-03-23 3.1G
CAMELSH Paper Hourly Version 6 + 3 + 2 United States 9008 1980-2024 2025-08-14 4.2G+3.57G+2.18G
Caravan-DK Paper Daily Version 7 / Version 5 Denmark 308 1981-01-02 to 2020-12-31 2025-04-11 521.6M
Caravan Paper / Code Daily Version 0.3 Global 16299 1950-2023 2023-05 24.8G
EStream Paper / Code Daily (weekly, monthly, yearly available) Version 1.3 / Version 1.1 Europe 17130 1950-01-01 to 2023-06-30 2025-06-30 12.3G
GRDC-Caravan Paper Daily Version 0.6 / Version 0.2 Global 5357 1950-2023 2025-05-06 16.4G
HYSETS Paper / Code Daily Dataset (dynamic attributes) North America 14425 1950-01-01 to 2023-12-31 2024-09 41.9G
LamaH-CE Paper Daily/Hourly Version 1.0 Central Europe 859 1981-01-01 to 2019-12-31 2021-08-02 16.3G
LamaH-Ice Paper Daily/Hourly Version 1.5 / old version Iceland 111 1950-01-01 to 2021-12-31 2025-08-12 9.6G
Simbi Paper Daily/Monthly Version 6.0 Haiti 24 1920-01-01 to 2005-12-31 2024-07-02 125M
>

Key Features

🎯 Unified API Across All Datasets

Access any dataset using the same method calls:

1
2
3
4
# Same API works for all datasets
ds.read_object_ids()                          # Get basin IDs
ds.read_attr_xrdataset(...)                   # Read attributes
ds.read_ts_xrdataset(...)                     # Read timeseries

⚡ Fast Caching (NetCDF locally, Zarr on cloud)

First access processes and caches data; all subsequent reads are instant: - Local: NetCDF files {dataset}_timeseries.nc / {dataset}_attributes.nc - Cloud: Zarr stores {dataset}_timeseries.zarr / {dataset}_attributes.zarr (with consolidated metadata) - Configured via ~/hydro_setting.yml (storage.cache locally, storage.s3 for cloud)

🔄 Standardized Variable Names

Use common names across all datasets: - streamflow - River discharge - precipitation - Rainfall - temperature_max / temperature_min - Temperature extremes - potential_evapotranspiration - PET - And many more...

📊 xarray Integration

All data returned as xarray.Dataset objects: - Labeled dimensions and coordinates - Built-in metadata and units - Easy slicing, selection, and computation - Compatible with Dask for large datasets

🌐 Station Network Connectivity (LamaH-CE)

LamaH-CE dataset supports querying stream network topology between gauging stations:

1
2
3
4
5
6
7
8
9
from hydrodataset import resolve_data_path
from hydrodataset.lamah_ce import LamahCe

ds = LamahCe(resolve_data_path("lamah_ce"))

# Read station connectivity data
stations = ds.read_stations_xrdataset(station_id_lst=["3", "4"])
print(stations)
# Returns: NEXTDOWNID, dist_hdn, elev_diff, strm_slope

See LamaH-CE API documentation for detailed variable descriptions and usage examples.

Project Status

hydrodataset provides unified access to 27 hydrological datasets, all implemented on the HydroDataset base class with the ADR 0001 path-resolution architecture (resolve_data_path → absolute URI → reader). CAMELS-US and CAMELS-AUS serve as the reference implementations; every other supported dataset follows the same pattern.

New datasets and features are added continuously. Please check the Changelog for the latest updates.

Credits

This package was created with Cookiecutter and the giswqs/pypackage project template. The data fetching and reading is now powered by AquaFetch.