PyWMP: Professional Watershed Modeling Framework

A comprehensive, network-based hydrologic modeling ecosystem that bridges the gap between intuitive GIS workflows and powerful Python automation for researchers, engineers, and water resource professionals.

🐍 Python 3.8+
πŸ—ΊοΈ PyWMP-Pro Ready
πŸ“– Open Source
⚑ Fast Setup

Get Started in Minutes

Python Developers

Install the core library and start modeling programmatically:

pip install pywmp
# or for development
git clone https://github.com/mandalanil/pywmp.git
cd pywmp && pip install -e .

PyWMP-Pro Users

Download the toolbox and start modeling with familiar GIS tools:

1 Download PyWMP-Pro.pyt
2 Add toolbox to ArcGIS Pro
3 Run your first simulation

About PyWMP

🐍 pywmp (Python Library)

Open-source Python framework for programmatic watershed modeling, research automation, and custom analysis workflows.

pip install NetworkX Pandas

πŸ—ΊοΈ PyWMP-Pro (ArcGIS Toolbox)

Professional GIS toolbox for PyWMP-Pro users, providing point-and-click watershed modeling with enterprise-grade visualization.

PyWMP-Pro GUI Tools Visual Output

Network-Based Watershed Modeling

PyWMP is an innovative, open-source framework designed for watershed modeling and hydrologic planning. It provides a flexible and extensible toolset for simulating runoff generation and flow routing through complex hydrologic systems using a network-based approach.

Key Innovation: Directed Acyclic Graph (DAG) Approach

PyWMP represents watersheds as directed graphs, enabling more intuitive and flexible modeling compared to traditional grid-based approaches.

A key feature of PyWMP is its fully automated workflow for generating high-precision inundation depth raster maps by leveraging high-resolution LiDAR Digital Elevation Models (DEM). To achieve this, PyWMP conceptualizes the watershed as a directed acyclic graph (DAG), a network-based approach that offers significant advantages over traditional grid-based or lumped-parameter models. In this framework:

  • Nodes represent hydrologically significant features such as catchment outlets, hydraulic structures (pumps, weirs), and depressions.
  • Edges represent the conveyance pathways (e.g., streams, canals) that connect these nodes.

By leveraging the NetworkX library, PyWMP captures the complex, non-linear relationships within a watershed, providing an intuitive and adaptable method for representing hydrologic systems. The framework calculates runoff at each node and routes these flows through the network, dynamically updating the hydraulic conditions at each simulation interval. This makes PyWMP an effective tool for researchers, water resource managers, and urban planners engaged in flood modeling, water resource management, and environmental conservation.

Key Features

Integrated GIS Workflow

A dedicated ArcGIS Pro toolbox (`PyWMP-Pro`) for seamless data preparation, simulation, and visualization.

Multi-Scenario Analysis

Efficiently compare the hydrologic impacts of different storm events (e.g., 10-year, 100-year) in a single, automated run.

Extensible Python Core

A modular, object-oriented Python engine (`pywmp`) for custom scripting, research, and automation.

Network-Based Routing

Represents the watershed as a directed graph, enabling efficient and intuitive modeling of complex flow interactions.

Automated Hydrograph Generation

Automatically generates and saves detailed hydrograph plots and data tables for each simulated node.

High-Resolution Mapping

Designed to produce high-precision inundation maps from LiDAR-derived Digital Elevation Models.

🐍 Open Source Python Library (pywmp)

Free, Open, and Extensible

The pywmp library is the core engine that powers watershed modeling through Python. Perfect for researchers, developers, and anyone who needs programmatic control over hydrologic simulations.

Python 3.8+ MIT License Active Development
Terminal
$ pip install pywmp # Ready to model watersheds! πŸš€

Why Choose the Open Source Library?

Lightning Fast

NetworkX-based graph operations and NumPy array processing for high-performance simulations.

Research Ready

Built for reproducible science with comprehensive documentation and validation against established methods.

Fully Customizable

Extend, modify, and integrate with your existing Python workflows. No vendor lock-in.

Well Documented

Complete API documentation, tutorials, and examples to get you started quickly.

Community Driven

Open source means community contributions, peer review, and continuous improvement.

Integration Ready

Works seamlessly with Jupyter, pandas, matplotlib, and the entire scientific Python ecosystem.

5-Minute Example

Get started with a simple watershed simulation in just a few lines of code:

import pandas as pd
from pywmp.models import Cascade2001Model
from pywmp.simulate import HydrologicSimulator

# Load your watershed data
df = pd.read_csv('my_watershed.csv')

# Create the network model
model = Cascade2001Model(df=df, from_col='Basin_ID', to_col='Receives_From')

# Set up and run simulation
simulator = HydrologicSimulator(
    graph=model.graph,
    scenarios={"100yr": "Rainfall_100yr_in"},
    column_mapping={
        'name_col': 'Basin_ID',
        'area_col': 'Area_ac', 
        'tc_col': 'Time_Concentration_hr'
    }
)

# Run the simulation - results saved automatically
simulator.run()

print("βœ… Simulation complete! Check the 'simulation_results' directory.")

Installation & Requirements

πŸ“¦ Installation Options

Stable Release (Recommended)

pip install pywmp

Development Version

git clone https://github.com/mandalanil/pywmp.git cd pywmp && pip install -e .

βš™οΈ System Requirements

  • βœ… Python 3.8 or later
  • βœ… NumPy >= 1.19.0
  • βœ… pandas >= 1.2.0
  • βœ… NetworkX >= 2.5
  • βœ… matplotlib >= 3.3.0
  • πŸ’Ύ ~50MB disk space
  • 🧠 2GB+ RAM recommended

PyWMP-Pro (ArcGIS) Tutorial

This section provides a hands-on tutorial for users of the ArcGIS Pro toolbox. This guide is designed to get you productive with the software quickly through a practical, real-world example.

Video Tutorial: Complete Workflow

This video provides a complete visual guide to using PyWMP-Pro, from project setup to result interpretation. It's the perfect starting point for new users.

PyWMP-Pro Video Tutorial

Workshop: Flood Inundation Mapping

This workshop guides you through a complete modeling workflow to produce a flood inundation map for a 100-year storm event. For a complete walkthrough, a sample data package can be made available.

Step 1: Create the Hydrologic Model

First, add the PyWMP-Pro.pyt toolbox to your ArcGIS Pro project. Open the Create Hydrological Model tool. This tool processes your raw GIS and tabular data (e.g., a CSV or shapefile defining your basins and structures) into a structured JSON file that defines the watershed network. The most important step is to carefully map your data columns to the model's required fields in the tool's interface.

Create Model Tool Screenshot

Step 2: Run the Simulation and Analyze Results

Open the Simulate Multi-Scenario Model tool. Use the .json file generated in the previous step as the primary input and select the desired storm scenarios to run. The tool automatically runs the simulation and adds a `simulation_results` point layer to your map. Use its attribute table and symbology to visualize peak water stages and identify areas of potential flooding. The output directory will also contain detailed hydrograph plots and CSV files for each simulated node.

pywmp (Python) Tutorial

For developers and researchers who prefer a programmatic approach, this tutorial provides an interactive, code-first introduction to the `pywmp` library.

Video Tutorial: Introduction to the `pywmp` API

This video introduces the core concepts and objects in the `pywmp` Python library, showing you how to set up your environment and run a basic simulation script.

pywmp API Video Tutorial

Example: Scripting a Multi-Scenario Simulation

This example demonstrates the core workflow: loading data, creating a model network, configuring the simulator, and running a multi-scenario analysis programmatically.

import pandas as pd
import networkx as nx
from pywmp.models import Cascade2001Model
from pywmp.simulate import HydrologicSimulator

# 1. Load data and create the network model
# The model requires a dataframe with columns defining the basins,
# their connectivity, and their physical and hydrologic parameters.
df = pd.read_csv('path/to/your/basin_data.csv')
model = Cascade2001Model(df=df, from_col='Basin_ID', to_col='Receives_From')
graph = model.graph

# 2. Define scenarios and instantiate the simulator
# The keys are the scenario names, and the values are the corresponding
# rainfall column names in your input dataframe.
scenarios_to_run = {
    "1d_100y": "Rainfall_1d_100y_in",
    "1d_25y": "Rainfall_1d_25y_in"
}

# The column_mapping dictionary tells the simulator which columns to use
# for essential parameters.
column_map = {
    'name_col': 'Basin_ID', 
    'area_col': 'Area_ac',
    'tc_col': 'Time_of_Concentration_hr',
    'soil_storage_col': 'Soil_Storage_in',
    'initial_stage_col': 'Initial_Stage_ft',
    'high_elev_col': 'High_Elevation_ft'
}

simulator = HydrologicSimulator(
    graph=graph,
    outdir="simulation_results",
    scenarios=scenarios_to_run,
    column_mapping=column_map,
    start_hour=0.0,
    end_hour=72.0,
    time_interval=1.0
)

# 3. Run the simulation
# This will execute all defined scenarios and save results to the output directory.
simulator.run()

# 4. Access summary results
# A consolidated summary of all scenarios is saved to the output directory.
summary_df = pd.read_csv('simulation_results/all_scenarios_summary.csv')
print(summary_df.head())

PyWMP-Pro Tool Guide

This guide provides conceptual explanations of the PyWMP-Pro toolbox for ArcGIS, helping you understand its components and how they work together.

Tool Reference

The toolbox contains primary tools that guide the user through the modeling process. Refer to each tool's help documentation within ArcGIS Pro for detailed parameter descriptions.

  • Create Hydrological Model: This tool is the first step in the workflow. It processes your raw GIS and tabular data into a structured JSON file that defines the watershed network, its connectivity, and all associated parameters. This file serves as the master input for the simulation engine.
  • Simulate Multi-Scenario Model: This tool is the computational core of the workflow. It takes the JSON model file as input, runs the `pywmp` engine for all user-selected scenarios, and generates a comprehensive set of outputs, including GIS layers with summary results, and detailed hydrograph data tables and plots for each node.

pywmp Library Guide

This guide is for developers and researchers using the core Python library. It explains the library's architecture and data structures.

Installation

Since the project is under active development, it is recommended to clone the repository for testing and contributing to improvements:

git clone https://github.com/mandalanil/pywmp.git
cd pywmp
pip install -e .

Module Breakdown

The `pywmp` library is organized into several key modules, each responsible for a specific part of the hydrologic modeling process:

  • simulate: Contains the main HydrologicSimulator class that orchestrates the entire simulation, managing time steps, scenarios, and data flow.
  • models: Includes the Cascade2001Model class, which uses NetworkX to construct the watershed graph from input data.
  • hyetograph: Provides functions like generate_rainfall_table to create rainfall distributions and calculate rainfall excess using the SCS-CN method.
  • hydrograph: Contains functions like generate_runoff_hydrograph to perform convolution and generate direct runoff hydrographs from rainfall excess.
  • stage_storage: Implements functions to relate a basin's storage volume to its water surface elevation (stage).
  • structure_flows: Provides functions to calculate discharge through hydraulic structures like pumps and gated spillways based on hydraulic conditions.

Methodological Foundations

This section provides a citable, academic-quality reference on the theoretical underpinnings of the models implemented in `pywmp`. Understanding these methods is crucial for conducting and publishing rigorous scientific research.

Rainfall-Runoff Modeling

1. Rainfall Excess Generation (SCS-CN)

PyWMP estimates direct runoff from storm rainfall using the widely-accepted SCS Curve Number (CN) method. This empirical model calculates rainfall excess based on total rainfall, soil type, land use, and antecedent moisture conditions. The framework first determines the initial abstraction ($I_a$), the amount of rainfall captured by interception and surface storage before runoff begins, as a function of the potential maximum soil moisture retention ($S$):

Iₐ = 0.2 * S

As the storm continues, the cumulative runoff depth ($Q$) is calculated at each time step based on the cumulative rainfall ($P$):

Q = (P - Iₐ)Β² / (P - Iₐ + S)     for P > Iₐ

The retention parameter $S$ is derived from the user-provided Curve Number: S = (1000 / CN) - 10. The model then calculates the incremental rainfall excess for each time step, which becomes the input for hydrograph generation.

2. Runoff Hydrograph Generation (Unit Hydrograph & Convolution)

The incremental rainfall excess is transformed into a direct runoff hydrograph using the synthetic unit hydrograph method. The framework generates a unit hydrograph (UH), representing the response of the watershed to one inch of excess rainfall over a specific duration. This UH is then convoluted with the rainfall excess time series to produce the final runoff hydrograph.

The shape of the unit hydrograph is determined by the basin's time of concentration ($t_c$) and area. The time to peak ($t_p$) and peak discharge ($q_p$) of the unit hydrograph are calculated using specific empirical relationships implemented in the code. The resulting runoff hydrograph represents the inflow to a specific node in the watershed network.

Hydrologic Routing and Hydraulic Structures

Level-Pool Routing (Storage Routing)

For outlet nodes that represent storage features like ponds or reservoirs, PyWMP employs a Level-Pool Routing (also known as Modified Puls or storage routing) method. This is a hydrologic (lumped) routing technique that solves the continuity equation:

Inflow - Outflow = Ξ”Storage / Ξ”t

At each time step ($\Delta t$), the model performs the following calculations for a given node:

  1. The inflow volume is determined from the node's own runoff hydrograph plus the routed outflows from any upstream nodes.
  2. The outflow is calculated as the sum of discharges from all immediately downstream structures (e.g., pumps, weirs), based on the current water stage at the node.
  3. The change in storage is calculated, and the total storage volume is updated.
  4. A new water surface elevation (stage) is calculated from the updated storage volume using a predefined stage-storage relationship. In the current implementation, this is handled by the simple_average function, which assumes a linear relationship between stage and storage.

This iterative process provides a time-series of stage and discharge for each storage node in the network.

Hydraulic Control Structures

The outflow from a storage node is controlled by the hydraulic characteristics of its downstream structures. PyWMP models two primary types of control structures:

  • Pumps: Modeled as simple on/off devices. When the headwater elevation at the storage node exceeds a defined "on" elevation, the pump operates at its full rated capacity. Below this elevation, its discharge is zero.
  • Gated Spillways and Weirs: Modeled using standard hydraulic equations that account for different flow regimes. The model can simulate free-orifice flow, submerged-orifice flow, and weir flow based on the relative headwater and tailwater elevations compared to the structure's crest and gate opening. Submergence corrections are applied to accurately reduce discharge when tailwater effects become significant.

API Reference

The API Reference is the definitive, code-level guide for developers. It is auto-generated from the docstrings in the `pywmp` source code to ensure it is always accurate and up-to-date with the latest version of the software. Each function and class entry includes detailed parameter descriptions, return values, and practical, executable examples. This section provides a reference for the most critical components of the library.

CLASS
pywmp.simulate.HydrologicSimulator

Encapsulates the data and methods for a watershed hydrologic simulation across multiple scenarios. This is the main class that orchestrates the simulation.

Parameters
graphnx.DiGraphA NetworkX directed graph representing the watershed, with node attributes containing all necessary parameters.
outdirstrThe root output directory where all result files will be saved.
scenariosdictA dictionary mapping user-friendly scenario names to the corresponding rainfall column names in the input data.
column_mappingdictA dictionary to map standard parameter names (e.g., 'area_col') to the actual column names in the input data.
start_hourfloatThe simulation start time in hours. Default is 0.0.
end_hourfloatThe simulation end time in hours. Default is 72.0.
time_intervalfloatThe time step for the simulation in hours. Default is 1.0.
FUNCTION
pywmp.hyetograph.generate_rainfall_table(...)

Generates a rainfall table including cumulative and incremental rainfall, and calculates rainfall excess using the SCS-CN methodology.

Parameters
total_rainfallfloatTotal rainfall depth for the storm event, in inches.
soil_storage_constantfloatThe soil storage parameter 'S' from the SCS-CN method.
start_time, end_time, time_intervalfloatParameters defining the simulation time window and step, in hours.
Returns

pandas.DataFrame with columns: "Time (hrs)", "Cumulative Rainfall (in)", "Incremental Rainfall (in)", and "Rainfall Excess (in)".

FUNCTION
pywmp.hydrograph.generate_runoff_hydrograph(...)

Generates a direct runoff hydrograph by convoluting a rainfall excess time-series with a synthetic unit hydrograph.

Parameters
rainfall_excessnp.ndarrayA NumPy array of incremental rainfall excess values, in inches.
tcfloatThe time of concentration for the watershed, in hours.
drainage_area_acresfloatThe watershed area in acres.
start_time, end_time, time_intervalfloatParameters defining the simulation time window and step, in hours.
Returns

pandas.DataFrame with columns: "Time (hrs)" and "Runoff (cfs)".

FUNCTION
pywmp.structure_flows.pump_discharge(...)

Calculates pump discharge based on a simple on/off stage elevation.

Parameters
stagefloatCurrent water surface elevation at the pump intake.
on_elevfloatThe elevation at which the pump turns on.
capacityfloatThe rated discharge capacity of the pump in cfs.
Returns

float representing the pump discharge in cfs.

FUNCTION
pywmp.structure_flows.gated_spillway_discharge(...)

Estimates flow through a gated spillway or uncontrolled weir, accounting for multiple flow regimes and submergence.

Parameters
headwater_elevfloatUpstream water surface elevation.
tailwater_elevfloatDownstream water surface elevation.
crest_elevfloatElevation of the spillway crest.
gate_opening_heightfloatVertical opening of the gate.
spillway_widthfloatWidth of the spillway.
Returns

float representing the estimated discharge in cfs.

Use Limitations

Both PyWMP-Pro and the `pywmp` library are intended for planning-level analysis, not for detailed engineering design where high-precision hydraulics are required. The primary limitation stems from the use of hydrologic routing methods.

No Backwater Analysis

The Level-Pool routing method assumes a horizontal water surface within each storage node. Therefore, the model **cannot simulate backwater effects** caused by downstream obstructions, tides, or complex channel confluences. This makes the software unsuitable for low-gradient systems, tidally influenced areas, or channel networks where downstream controls significantly affect upstream water levels.

How to Cite

If you use PyWMP or PyWMP-Pro in your research, please cite it as follows:

[Author, A. A.]. (2025). PyWMP: An Open-Source Framework for Network-Based Watershed Modeling (Version X.X). [Link to software/paper - dummy]

References

The methods implemented in `pywmp` are based on foundational and widely accepted literature in the field of hydrology.

  1. Chow, V. T., Maidment, D. R., & Mays, L. W. (1988). *Applied Hydrology*. McGraw-Hill.
  2. U.S. Department of Agriculture, Natural Resources Conservation Service. (1986). *National Engineering Handbook, Part 630: Hydrology*. Washington, D.C.