Overview of the Program Structure
Overview of the Program Structure
The Diversion Runoff Calculator is geospatial hydrologic modeling program written in Python that estimates crop water demand and canal irrigation diversions based on two primary methods:
Published theoretical crop water consumption tables
Remote sensing-based OpenET evapotranspiration (ET) data
It adjusts for irrigation inefficiencies, runoff returning to fields or canals, and seepage losses, producing water budget estimates that can be further processed by RiverWare© for basin-wide water accounting.
The script imports a wide array of Python libraries, including:
Numerical Processing: numpy, pandas, statistics
Geospatial Data Processing: geopandas, fiona, shapely, osgeo
Data Visualization: matplotlib
Configuration and System Utilities: configparser, subprocess, os, sys, datetime, re
Geopandas Installation Check: Ensures geopandas is installed using either Conda or pip.
Function: read_config(config_file)
Purpose: Reads input file paths, connection files, flags, and year settings from a configuration (.ini) file.
This function organizes user inputs into categories:
File Paths: Paths for GIS layers, tables, and observational data.
Connection Files: Define relationships between fields, canals, and rivers.
Flags: Boolean settings controlling optional computations.
Year Settings: Defines the simulation period.
If run as a standalone script, the program:
Loads the configuration file (sys.argv[1])
Processes input GIS data
Estimates irrigation demands
Calculates canal diversions and losses
Generates outputs for RiverWare© and visualization
Allows scenario testing for change cases
Field and Canal Data Handling
Functions:
Set_Geodataframe_CRS(): Ensures consistent coordinate reference systems (CRS) across spatial datasets.
calculate_area_in_acres(): Converts polygon areas from square meters to acres.
Shapefiles Processed:
Water-Related Land Use (WRLU)
Canal Flowlines
OpenET Crop Water Demand Data
Observed Flow Data for Calibration
Water Rights Information
The program estimates crop water demand for individual fields based on:
Net Irrigation Water Requirement (Hill, 1994) is the theoretical crop water demand under well watered conditions.
OpenET Remote Sensing Data (eeMETRIC)
Core Functions
CropIndex(): Matches crop labels with predefined crop demand values.
CropLabel_to_EA_EI_NIWR(): Determines irrigation efficiency (EI) and evapotranspiration application efficiency (EA) based on the irrigation method.
Crop_CU_From_ETDemands(): Extracts and processes OpenET evapotranspiration values.
calculate_adjustment_factor(): Computes a correction factor for NIWR.
Adjustment for Irrigation Efficiency
Different irrigation methods have efficiency factors that affect how much water is actually applied to crops:
Drip Irrigation: ~85% based on the average expected efficiency for microirrigation systems (pg. 74 in Hoffman et al., 2007)
Sprinkler Irrigation: ~80% based on near-average efficiency of a center-pivot or linear-move sprinkler irrigation system. This is on the lower end of the average to account for traveling gun or side-roll methods. (pg. 71 in Hoffman et al., 2007)
Flood Irrigation: ~70% based on low-efficiency border strip irrigation and average-efficiency furrow irrigation (pg. 68 in Hoffman et al., 2007)
Sub-irrigation (groundwater): ~200% (acts as 50% of water source rather than a demand)
To determine total water diversions, the program aggregates field-scale crop water use at the canal service area level.
Key Functions:
Determine_Lengths_and_Loss_Of_Canals(): Computes canal length, lined/unlined portions, and seepage losses.
Calculate_CanalSeepage_Gained_by_Field_Updated(): Estimates how much canal seepage benefits nearby fields.
Calculate_CanalSeepage_Gained_by_CanalRiver_Updated(): Determines how much seepage returns to rivers.
Runoff Considerations
Field-to-Field Runoff: Excess irrigation from one field can supplement adjacent fields.
Field-to-Canal Runoff: Some of this excess water returns to canals.
Canal-to-River Seepage: Unlined canals contribute seepage back to rivers.
The script processes water rights data using find_water_right(), matching parcels with allocated water rights.
This ensures that calculated diversions respect legal allocations.
The model produces results that RiverWare can process for water accounting:
Diversion Flows
Canal Losses
Return Flows
Water Rights Aggregation
CSV and Graphical Outputs
CSV Exports: Summarized flow and crop demand statistics.
Matplotlib Graphs: Time series plots of diversions, losses, and water demands.
Visualization Functions:
Figure_NIWR_Qc(): Compares simulated vs. observed canal diversions.
Figures_Field_Level_OpenET_Data(): Plots evapotranspiration trends for specific crops.
The tool allows users to compare:
Base Case: Existing irrigation and water management.
Change Case: Effects of drought mitigation strategies (e.g., fallowing, crop switching, etc.)
Key scenarios evaluated changes in:
crop type
irrigation methods
irrigation start/end dates
canal lining
canal lengths
If a programmer wants to add a feature, they should consider:
Adding New Data Inputs: Modify read_config() to load new files.
Modifying Water Demand Calculations: Update CropLabel_to_EA_EI_NIWR() or NIWR_Data_From_ETDemands().
Improving Canal Seepage Calculations: Enhance Determine_Lengths_and_Loss_Of_Canals().
Adjusting Water Rights Processing: Modify find_water_right().
Enhancing Outputs: Expand Figure_NIWR_Qc() to include new visualizations.
Hoffman, G. J., Evans, R. G., Jensen, M. E., Martin, D. L., & Elliott, R. L. (Eds.). (2007). Design and operation of farm irrigation systems (pp. 863p-863p). St. Joseph, MI: American Society of Agricultural and Biological Engineers.