Skip to main content

PyOpenChannel

A comprehensive Python library for open channel flow analysis and design. PyOpenChannel provides tools for hydraulic engineers, water resources professionals, and students to analyze and design open channel systems with ease and accuracy.

Features

🏗️ Channel Geometries

  • Rectangular channels: Standard rectangular cross-sections
  • Trapezoidal channels: Most common natural and constructed channels
  • Triangular channels: V-shaped channels and ditches
  • Circular channels: Pipes and culverts with free surface flow
  • Parabolic channels: Efficient hydraulic sections

💧 Hydraulic Calculations

  • Manning's equation: Uniform flow calculations
  • Critical depth: Critical flow conditions and Froude number analysis
  • Normal depth: Uniform flow depth calculations
  • Energy equation: Specific energy and alternate depths
  • Momentum equation: Hydraulic jump analysis

📐 Flow Analysis

  • Uniform flow: Complete flow state analysis
  • Critical flow: Critical conditions and flow regime classification
  • Flow classification: Subcritical, critical, and supercritical flow identification

🌊 Water Surface Profiles (Gradually Varied Flow)

  • Profile solver: Adaptive Runge-Kutta integration of the GVF equation
  • Profile classification: M, S, C, H and A profile types
  • Dam backwater: Backwater curve and its upstream extent
  • Bridges: Backwater through a bridge opening by the energy method, including choking
  • Transitions and chutes: Profiles at changes in section or slope

⚡ Rapidly Varied Flow

  • Hydraulic jumps: Jump type, sequent depths and energy loss
  • Weirs and gates: Flow over weirs and under sluice gates
  • Finite volume solver: Shock-capturing solution of flows with jumps

🎯 Channel Design

  • Optimal sections: Hydraulically efficient channel design
  • Economic sections: Cost-optimized channel design
  • Channel sizing: Capacity-based channel dimensioning
  • Design recommendations: Freeboard, velocity limits, and side slopes

Installation

From Source (Development)

git clone https://github.com/alexiusacademia/pyopenchannel.git
cd pyopenchannel
pip install -e .

Requirements

  • Python 3.9+
  • matplotlib (for plots)

Quick Start

import pyopenchannel as poc

# Create a rectangular channel
channel = poc.RectangularChannel(width=3.0)

# Calculate normal depth for given flow conditions
discharge = 5.0  # m³/s
slope = 0.001    # dimensionless
manning_n = 0.025

normal_depth = poc.NormalDepth.calculate(channel, discharge, slope, manning_n)
print(f"Normal depth: {normal_depth:.3f} m")

# Calculate critical depth
critical_depth = poc.CriticalDepth.calculate(channel, discharge)
print(f"Critical depth: {critical_depth:.3f} m")

# Analyze flow regime
if normal_depth > critical_depth:
    print("Flow regime: Subcritical (mild slope)")
else:
    print("Flow regime: Supercritical (steep slope)")

Examples

Backwater Profile

Profiles are computed from their control. x increases in the flow direction. Subcritical flow, such as backwater behind a dam, is controlled from downstream, so give the depth at the downstream end (DOWNSTREAM_DEPTH) and the profile is computed upstream. Supercritical flow is controlled from upstream (UPSTREAM_DEPTH).

import pyopenchannel as poc

channel = poc.RectangularChannel(width=10.0)
discharge, slope, manning_n = 30.0, 0.0008, 0.025

# 4.0 m deep at the dam (x = 0); compute 5 km upstream
result = poc.GVFSolver().solve_profile(
    channel=channel,
    discharge=discharge,
    slope=slope,
    manning_n=manning_n,
    x_start=-5000.0,
    x_end=0.0,
    boundary_depth=4.0,
    boundary_type=poc.BoundaryType.DOWNSTREAM_DEPTH
)

normal_depth = poc.NormalDepth.calculate(channel, discharge, slope, manning_n)
upstream_end = result.profile_points[-1]
print(f"Normal depth: {normal_depth:.3f} m")                                       # 2.061 m
print(f"Depth 5 km upstream: {upstream_end.depth:.3f} m")                          # 2.097 m
profile = poc.ProfileClassifier().classify_profile(result, channel, discharge, slope, manning_n)
print(f"Profile type: {profile.profile_type.value}")                               # M1

For a dam or a bridge, poc.DamAnalysis and poc.BridgeAnalysis do this for you and report the backwater rise and its extent.

Basic Flow Analysis

import pyopenchannel as poc

# Create a trapezoidal channel
channel = poc.TrapezoidalChannel(bottom_width=2.0, side_slope=1.5)

# Flow conditions
discharge = 10.0  # m³/s
slope = 0.002     # 0.2%
manning_n = 0.030 # earth channel

# Create uniform flow analyzer
uniform_flow = poc.UniformFlow(channel, slope, manning_n)
flow_state = uniform_flow.calculate_flow_state(discharge)

print(f"Flow depth: {flow_state.depth:.3f} m")
print(f"Flow velocity: {flow_state.velocity:.3f} m/s")
print(f"Froude number: {flow_state.froude_number:.3f}")
print(f"Flow type: {'Subcritical' if flow_state.is_subcritical else 'Supercritical'}")

Channel Design

import pyopenchannel as poc

# Design optimal rectangular channel
discharge = 15.0  # m³/s
slope = 0.001     # 0.1%
manning_n = 0.025 # concrete lining

result = poc.OptimalSections.rectangular(discharge, slope, manning_n)

print(f"Optimal width: {result.channel.width:.3f} m")
print(f"Flow depth: {result.depth:.3f} m")
print(f"Flow velocity: {result.velocity:.3f} m/s")
print(f"Recommended freeboard: {result.freeboard:.3f} m")
print(f"Total channel depth: {result.total_depth:.3f} m")

Economic Design

import pyopenchannel as poc

# Economic channel design considering costs
economic_designer = poc.EconomicSections(
    excavation_cost_per_m3=25.0,  # $/m³
    lining_cost_per_m2=50.0,      # $/m²
    land_cost_per_m2=100.0        # $/m²
)

result = economic_designer.design_rectangular(
    discharge=20.0, slope=0.001, manning_n=0.015
)

print(f"Economic width: {result.channel.width:.3f} m")
print(f"Flow depth: {result.depth:.3f} m")
print(f"Cost per meter: ${result.cost_per_meter:.2f}/m")

API Reference

Channel Geometries

RectangularChannel(width)

Rectangular channel cross-section.

Parameters:

  • width (float): Channel bottom width in meters

Methods:

  • area(depth): Cross-sectional area
  • wetted_perimeter(depth): Wetted perimeter
  • top_width(depth): Top width (constant for rectangular)
  • hydraulic_radius(depth): Hydraulic radius (A/P)

TrapezoidalChannel(bottom_width, side_slope)

Trapezoidal channel cross-section.

Parameters:

  • bottom_width (float): Channel bottom width in meters
  • side_slope (float): Side slope ratio (horizontal:vertical)

TriangularChannel(side_slope)

Triangular channel cross-section.

Parameters:

  • side_slope (float): Side slope ratio (horizontal:vertical)

CircularChannel(diameter)

Circular channel cross-section (pipe with free surface).

Parameters:

  • diameter (float): Pipe diameter in meters

ParabolicChannel(shape_parameter)

Parabolic channel cross-section.

Parameters:

  • shape_parameter (float): Shape parameter 'a' in y = ax²

Hydraulic Calculations

ManningEquation

Static methods for Manning's equation calculations.

Methods:

  • discharge(area, hydraulic_radius, slope, manning_n): Calculate discharge
  • velocity(hydraulic_radius, slope, manning_n): Calculate velocity
  • required_slope(discharge, area, hydraulic_radius, manning_n): Calculate required slope

CriticalDepth

Critical depth and critical flow calculations.

Methods:

  • calculate(channel, discharge): Calculate critical depth
  • froude_number(velocity, hydraulic_depth): Calculate Froude number

NormalDepth

Normal depth calculations for uniform flow.

Methods:

  • calculate(channel, discharge, slope, manning_n): Calculate normal depth

Flow Analysis

UniformFlow(channel, slope, manning_n)

Uniform flow analysis.

Methods:

  • calculate_flow_state(discharge): Get complete flow state
  • calculate_discharge(depth): Calculate discharge for given depth

EnergyEquation

Energy equation applications.

Methods:

  • specific_energy(depth, velocity): Calculate specific energy
  • minimum_specific_energy(channel, discharge): Minimum specific energy
  • alternate_depths(channel, discharge, specific_energy): Calculate alternate depths

Design Tools

OptimalSections

Hydraulically optimal channel design.

Methods:

  • rectangular(discharge, slope, manning_n): Optimal rectangular section
  • trapezoidal(discharge, slope, manning_n, side_slope): Optimal trapezoidal section
  • triangular(discharge, slope, manning_n): Optimal triangular section

EconomicSections(excavation_cost, lining_cost, land_cost)

Economic channel design.

Methods:

  • design_rectangular(discharge, slope, manning_n): Economic rectangular design
  • design_trapezoidal(discharge, slope, manning_n, side_slope): Economic trapezoidal design

ChannelDesigner

General design utilities.

Methods:

  • calculate_freeboard(discharge, depth, velocity): Recommended freeboard
  • check_velocity_limits(velocity, channel_material): Velocity limit checks
  • recommend_side_slope(soil_type): Side slope recommendations
  • size_channel_for_capacity(discharge, slope, manning_n, channel_type): Size channel for capacity

Constants and Utilities

Physical Constants

  • GRAVITY: 9.81 m/s²
  • WATER_DENSITY: 1000 kg/m³
  • KINEMATIC_VISCOSITY: 1.004×10⁻⁶ m²/s

Manning's Roughness Coefficients

Pre-defined roughness coefficients for common channel materials:

  • Concrete (smooth): 0.012
  • Concrete (rough): 0.017
  • Earth channels: 0.025-0.040
  • Natural channels: 0.030-0.040

Side Slope Recommendations

Recommended side slopes for different soil types:

  • Rock: 0.25:1 to 0.5:1
  • Firm earth: 1:1
  • Ordinary earth: 1.5:1
  • Sandy earth: 2:1
  • Loose earth: 3:1

Error Handling

PyOpenChannel includes comprehensive error handling with custom exceptions:

  • PyOpenChannelError: Base exception class
  • InvalidGeometryError: Invalid channel geometry parameters
  • ConvergenceError: Iterative calculations failed to converge
  • InvalidFlowConditionError: Physically impossible flow conditions
  • InvalidRoughnessError: Invalid Manning's roughness coefficient
  • InvalidSlopeError: Invalid channel slope

Testing

Run the test suite:

# Run all tests
pytest

# Run with coverage
pytest --cov=pyopenchannel

# Run specific test categories
pytest -m unit          # Unit tests only
pytest -m integration   # Integration tests only
pytest -m "not slow"    # Skip slow tests

Examples Directory

The examples/ directory contains comprehensive examples:

  • basic_calculations.py: Fundamental hydraulic calculations
  • channel_design.py: Channel design and optimization examples
  • gvf_simple_example.py, gvf_basic_usage.py: Water surface profiles (M1, M2, S1)
  • backwater_analysis_demo.py, gvf_dam_backwater_analysis.py: Dam backwater
  • gvf_applications_demo.py, gvf_channel_transitions.py: Bridges, chutes and transitions
  • rvf_hydraulic_jump_analysis.py: Hydraulic jumps
  • complete_gate_flow_analysis.py, rigorous_spillway_demo.py: Gates and spillways

See examples/README_GVF_Examples.md for a guide to the profile examples.

Run examples:

python examples/basic_calculations.py
python examples/channel_design.py

Applications

PyOpenChannel is suitable for:

Water Resources Engineering

  • River and stream analysis
  • Flood control channel design
  • Irrigation and drainage systems
  • Culvert and bridge hydraulics

Civil Engineering

  • Storm water management
  • Highway drainage design
  • Urban channel systems
  • Infrastructure hydraulics

Environmental Engineering

  • Constructed wetlands
  • Stream restoration
  • Ecological channel design
  • Natural channel analysis

Education and Research

  • Hydraulic engineering coursework
  • Research applications
  • Design verification
  • Parametric studies

Theory and Background

PyOpenChannel implements fundamental open channel flow theory:

Manning's Equation

Q = (1/n) × A × R^(2/3) × S^(1/2)

Where:

  • Q = discharge (m³/s)
  • n = Manning's roughness coefficient
  • A = cross-sectional area (m²)
  • R = hydraulic radius (m)
  • S = channel slope (dimensionless)

Critical Flow Condition

Q² = g × A³ / T

Where:

  • g = gravitational acceleration (m/s²)
  • T = top width (m)

Froude Number

Fr = V / √(g × D)

Where:

  • V = average velocity (m/s)
  • D = hydraulic depth (m)

Flow classification:

  • Fr < 1: Subcritical flow
  • Fr = 1: Critical flow
  • Fr > 1: Supercritical flow

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

Development Setup

git clone https://github.com/alexiusacademia/pyopenchannel.git
cd pyopenchannel
pip install -e ".[dev]"

Running Tests

pytest

If using uv

uv run --with pytest pytest

Code Style

This project uses:

  • Black for code formatting
  • isort for import sorting
  • flake8 for linting
  • mypy for type checking

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Based on established open channel flow theory from hydraulic engineering literature
  • Inspired by classic texts: "Open Channel Hydraulics" by Ven Te Chow
  • Developed for educational and professional use in hydraulic engineering

Support

For questions, issues, or contributions:

  1. Check the documentation and examples
  2. Search existing issues on GitHub
  3. Create a new issue with detailed information
  4. Consider contributing improvements

Roadmap

Future enhancements planned:

  • Compound channel analysis
  • Sediment transport basics
  • Unsteady flow analysis
  • Advanced optimization algorithms
  • Integration with GIS data
  • Visualization tools
  • Additional channel shapes
  • Performance optimizations

PyOpenChannel - Making open channel flow analysis accessible, accurate, and efficient.

Metadata

Release files for pyopenchannel 0.5.0

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

Source distribution (sdist)

Source distribution for pyopenchannel 0.5.0
File Size Uploaded Provenance
pyopenchannel-0.5.0.tar.gz 312.1 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 451.4 kB

Release files / pyopenchannel-0.5.0.tar.gz

Download URL pyopenchannel-0.5.0.tar.gz
Size 312.1 kB
Tags Source
SHA-256 checksum
How to use checksums
309abac6d39adbfc85f651a9eae3009f148cecc6ec430df93a49564642436562
BLAKE2b-256 checksum
How to use checksums
c50beb8bd3b964c659dfd645c41cbf4d6076c2f8f72c0127fdd99751111e4a7b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.20 {"installer":{"name":"uv","version":"0.11.20","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / pyopenchannel-0.5.0-py3-none-any.whl

Download URL pyopenchannel-0.5.0-py3-none-any.whl
Size 139.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d2e179703f8474e29bf6ed8d4aaa9d9fdce482ad60203d14b9c87d1b95b9561c
BLAKE2b-256 checksum
How to use checksums
f1b74f021d39027fe34f5c4603136bb482ff8c9a92233157f29307c0f22bf67d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.20 {"installer":{"name":"uv","version":"0.11.20","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for pyopenchannel 0.5.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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