Skip to main content

A collection of commonly used util functions in hydrological modeling

Project description

hydroutils

image image image Python Version License: MIT

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.

โœจ 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.

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Run tests and linting (make check-all)
  5. Commit your changes (git commit -m 'Add amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. 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


Made with โค๏ธ for the hydrology community

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

hydroutils-0.1.0.tar.gz (94.1 kB view details)

Uploaded Source

Built Distribution

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

hydroutils-0.1.0-py3-none-any.whl (65.3 kB view details)

Uploaded Python 3

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

Hashes for hydroutils-0.1.0.tar.gz
Algorithm Hash digest
SHA256 17272415c5b6020846f0cf526a56eb26f74a8ac2d501cc97543f3832aeccefa5
MD5 ae6df7b8cd48e3ab2e291b191512c09f
BLAKE2b-256 cece4ef3af2f2bd5afcd4ba35bccd761f7aa8a8f44e7acf6f173849955ac544e

See more details on using hashes here.

Provenance

The following attestation bundles were made for hydroutils-0.1.0.tar.gz:

Publisher: pypi.yml on OuyangWenyu/hydroutils

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for hydroutils-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 be160af5a85d96d9dea85ce0ccf7a019ad269c109228779e9aec0aa4295cf722
MD5 a231aa3a2c89db4c211ff5bacf76bce0
BLAKE2b-256 c6c7b4ac0c61e452c263e10b495c8f7dfa812a878622bc58b15a7dc2606942b1

See more details on using hashes here.

Provenance

The following attestation bundles were made for hydroutils-0.1.0-py3-none-any.whl:

Publisher: pypi.yml on OuyangWenyu/hydroutils

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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