A collection of commonly used util functions in hydrological modeling
Project description
hydroutils
A comprehensive collection of utility functions for hydrological modeling and analysis
Hydroutils is a Python package designed for hydrological modeling workflows, providing statistical analysis, data visualization, file handling, time period operations and unit conversion, specifically tailored for hydrological research and applications.
This package is still under development, and the API is subject to change.
- Free software: MIT license
- Documentation: https://OuyangWenyu.github.io/hydroutils
- Source Code: https://github.com/OuyangWenyu/hydroutils
- PyPI Package: https://pypi.org/project/hydroutils/
โจ Features
๐ Statistical Analysis (hydro_stat)
- Dynamic Metric Functions: Automatically generated statistical functions (NSE, RMSE, MAE, etc.)
- Multi-dimensional Analysis: Support for 2D/3D arrays for basin-scale analysis
- HydroErr Integration: Standardized hydrological metrics through HydroErr package
- NaN Handling: Flexible strategies ('no', 'sum', 'mean') for missing data
- Runtime Metric Addition: Add custom metrics dynamically with
add_metric()
๐ Visualization (hydro_plot)
- Geospatial Plotting: Cartopy integration for map-based visualizations
- Chinese Font Support: Automatic font configuration for Chinese text rendering
- Statistical Plots: ECDF, box plots, heatmaps, correlation matrices
- Hydrological Specializations: Flow duration curves, unit hydrographs, precipitation plots
- Customizable Styling: Extensive configuration options for colors, styles, and formats
๐ File Operations (hydro_file)
- JSON Serialization: NumPy array support with
NumpyArrayEncoder - Cloud Storage: S3 and MinIO integration for remote data access
- ZIP Handling: Nested ZIP file extraction and management
- Cache Management: Automatic cache directory creation and management
- Async Operations: Asynchronous data retrieval capabilities
โฐ Time Period (hydro_time)
- UTC Calculations: Timezone offset computation from coordinates
- Date Parsing: Flexible date string parsing and manipulation
- Time Range Operations: Intersection, generation, and validation
- Interval Detection: Automatic time interval identification
๐ท๏ธ Unit Conversion (hydro_units)
- Streamflow Units: Comprehensive unit conversion for hydrological variables
- Time Interval Detection: Automatic detection and validation of time intervals
- Unit Compatibility: Validation functions for unit consistency
- Pint Integration: Physical units handling with pint and pint-xarray
๐ Event Analysis (hydro_event)
- Hydrological Event Detection: Flood event identification
- Event Characterization: Duration, magnitude, and timing analysis
โ๏ธ Cloud Integration (hydro_s3)
- AWS S3 Support: Direct integration with Amazon S3 services
- MinIO Compatibility: Local and private cloud storage solutions
- Credential Management: Secure credential handling and configuration
๐ Logging (hydro_log)
- Rich Console Output: Colored and formatted console logging
- Progress Tracking: Advanced progress bars and status indicators
- Debug Support: Comprehensive debugging and error reporting
๐ Quick Start
Installation
# Install from PyPI
pip install hydroutils
# Install with development dependencies using uv (recommended)
pip install uv
uv add hydroutils
# For development setup
git clone https://github.com/OuyangWenyu/hydroutils.git
cd hydroutils
uv sync --all-extras --dev
Basic Usage
import hydroutils
import numpy as np
# Statistical Analysis
obs = np.array([1.0, 2.0, 3.0, 4.0, 5.0])
sim = np.array([1.1, 2.1, 2.9, 3.9, 5.1])
# Calculate Nash-Sutcliffe Efficiency
nse_value = hydroutils.nse(obs, sim)
print(f"NSE: {nse_value:.3f}")
# Multiple metrics at once
metrics = hydroutils.stat_error(obs, sim)
print(f"RMSE: {metrics['rmse']:.3f}")
print(f"MAE: {metrics['mae']:.3f}")
# Visualization
import matplotlib.pyplot as plt
fig, ax = hydroutils.plot_ecdf([obs, sim],
labels=['Observed', 'Simulated'],
colors=['blue', 'red'])
plt.show()
๐ ๏ธ Development
Setting Up Development Environment
# Clone the repository
git clone https://github.com/OuyangWenyu/hydroutils.git
cd hydroutils
# Install UV (modern Python package manager)
pip install uv
# Setup development environment
uv sync --all-extras --dev
Development Commands
# Run tests
uv run pytest # Basic test run
uv run pytest --cov=hydroutils # With coverage
make test-cov # With HTML coverage report
# Code formatting and linting
uv run black . # Format code
uv run ruff check . # Lint code
uv run ruff check --fix . # Fix linting issues
make format # Format and lint together
# Type checking
uv run mypy hydroutils
make type-check
# Documentation
uv run mkdocs serve # Serve docs locally
make docs-serve
# Build and release
uv run python -m build # Build package
make build
Project Structure
hydroutils/
โโโ hydroutils/
โ โโโ __init__.py # Package initialization and exports
โ โโโ hydro_event.py # Hydrological event analysis
โ โโโ hydro_file.py # File I/O and cloud storage
โ โโโ hydro_log.py # Logging and console output
โ โโโ hydro_plot.py # Visualization functions
โ โโโ hydro_s3.py # AWS S3 and MinIO integration
โ โโโ hydro_stat.py # Statistical analysis engine
โ โโโ hydro_time.py # Time series utilities
โ โโโ hydro_units.py # Unit conversion and validation
โโโ tests/ # Comprehensive test suite
โโโ docs/ # MkDocs documentation
โโโ pyproject.toml # Modern Python project config
โโโ Makefile # Development convenience commands
โโโ uv.lock # UV package manager lock file
๐ค Contributing
We welcome contributions! Please see our Contributing Guide for details.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run tests and linting (
make check-all) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
๐ Documentation
Comprehensive documentation is available at https://OuyangWenyu.github.io/hydroutils, including:
- API Reference: Complete function and class documentation
- User Guide: Step-by-step tutorials and examples
- Contributing Guide: Development setup and contribution guidelines
- FAQ: Frequently asked questions and troubleshooting
๐๏ธ Requirements
- Python: >=3.10
- Core Dependencies: numpy, pandas, matplotlib, seaborn
- Scientific Computing: scipy, HydroErr, numba
- Visualization: cartopy (for geospatial plots)
- Cloud Storage: boto3, minio, s3fs
- Utilities: tqdm, rich, xarray, pint
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- HydroErr: For standardized hydrological error metrics
- Cookiecutter: Project template from giswqs/pypackage
- Scientific Python Ecosystem: NumPy, SciPy, Matplotlib, Pandas
๐ Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: wenyuouyang@outlook.com
Made with โค๏ธ for the hydrology community
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 hydroutils-0.1.0.tar.gz.
File metadata
- Download URL: hydroutils-0.1.0.tar.gz
- Upload date:
- Size: 94.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17272415c5b6020846f0cf526a56eb26f74a8ac2d501cc97543f3832aeccefa5
|
|
| MD5 |
ae6df7b8cd48e3ab2e291b191512c09f
|
|
| BLAKE2b-256 |
cece4ef3af2f2bd5afcd4ba35bccd761f7aa8a8f44e7acf6f173849955ac544e
|
Provenance
The following attestation bundles were made for hydroutils-0.1.0.tar.gz:
Publisher:
pypi.yml on OuyangWenyu/hydroutils
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hydroutils-0.1.0.tar.gz -
Subject digest:
17272415c5b6020846f0cf526a56eb26f74a8ac2d501cc97543f3832aeccefa5 - Sigstore transparency entry: 647231115
- Sigstore integration time:
-
Permalink:
OuyangWenyu/hydroutils@9a8f254fab72c5ec99a2693ceef4d95e544d031d -
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@9a8f254fab72c5ec99a2693ceef4d95e544d031d -
Trigger Event:
release
-
Statement type:
File details
Details for the file hydroutils-0.1.0-py3-none-any.whl.
File metadata
- Download URL: hydroutils-0.1.0-py3-none-any.whl
- Upload date:
- Size: 65.3 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 |
be160af5a85d96d9dea85ce0ccf7a019ad269c109228779e9aec0aa4295cf722
|
|
| MD5 |
a231aa3a2c89db4c211ff5bacf76bce0
|
|
| BLAKE2b-256 |
c6c7b4ac0c61e452c263e10b495c8f7dfa812a878622bc58b15a7dc2606942b1
|
Provenance
The following attestation bundles were made for hydroutils-0.1.0-py3-none-any.whl:
Publisher:
pypi.yml on OuyangWenyu/hydroutils
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hydroutils-0.1.0-py3-none-any.whl -
Subject digest:
be160af5a85d96d9dea85ce0ccf7a019ad269c109228779e9aec0aa4295cf722 - Sigstore transparency entry: 647231116
- Sigstore integration time:
-
Permalink:
OuyangWenyu/hydroutils@9a8f254fab72c5ec99a2693ceef4d95e544d031d -
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@9a8f254fab72c5ec99a2693ceef4d95e544d031d -
Trigger Event:
release
-
Statement type: