Tutorials#
Step-by-step tutorials for common pyiwfm workflows.
- Tutorial: Reading an Existing IWFM Model
- Tutorial: Building the IWFM Sample Model from Scratch
- Learning Objectives
- Overview
- Section 1: Create the Mesh
- Section 2: Define Stratigraphy
- Section 3: Groundwater Component
- Section 4: Stream Component
- Section 5: Lake Component
- Section 6: Root Zone Component
- Section 7: Assemble and Write the Model
- Section 8: Run the Preprocessor
- Section 9: Run the Simulation
- Section 10: Visualize Results
- Interactive Viewing
- Complete Script
- Next Steps
- Tutorial: Mesh Generation
- Learning Objectives
- Step 1: Import Libraries
- Step 2: Define the Model Boundary
- Step 3: Add Stream Constraints
- Step 4: Add Well Locations
- Step 5: Define Refinement Zones
- Step 6: Generate the Mesh
- Step 7: Convert to AppGrid
- Step 8: Visualize the Mesh
- Step 9: Export to GIS
- Step 10: Analyze Mesh Quality
- Complete Script
- Next Steps
- Tutorial: Mixed Triangular-Quadrilateral Mesh
- Tutorial: Visualization
- Tutorial: Model Comparison
- Tutorial: Calibration Workflow
- Learning Objectives
- Step 1: Reading SMP Files
- Step 2: IWFM2OBS – Interpolate to Observation Times
- Step 2b: Model-Discovery Mode (IWFM2OBS from Simulation Main File)
- Step 3: Cluster Observation Wells
- Step 4: Compute Typical Hydrographs (CalcTypHyd)
- Step 5: Calibration Metrics
- Step 6: Calibration Plots
- Step 7: Parse SimulationMessages.out
- CLI Commands
- Summary
- Tutorial: Packaging and Running IWFM Models
- Drawdown Analysis
- Stream Depletion Analysis
- Simulation Diagnostics
- Mesh Quality Analysis
Overview#
These tutorials walk you through complete workflows using pyiwfm:
- Reading an Existing Model (C2VSimCG)
Load C2VSimCG (California Central Valley Simulation – Coarse Grid), inspect its mesh, streams, lakes, stratigraphy, and create visualizations. Start here if you already have an IWFM model and want to work with it in Python.
- Building the Sample Model from Scratch
Build the official IWFM sample model programmatically – mesh, stratigraphy, groundwater, streams, lakes, root zone – then run the preprocessor and simulation and visualize results.
- Mesh Generation
Create a finite element mesh from scratch, including defining boundaries, adding stream constraints, and refining areas of interest.
- Mixed Triangular-Quadrilateral Mesh
Generate meshes with Gmsh that combine triangles and quadrilaterals. Compare pure triangle, pure quad, and mixed element modes side by side, and visualize element type distributions and area statistics.
- Visualization
Export model data for visualization in GIS software, ParaView, and matplotlib. Create publication-quality figures.
- Model Comparison
Compare two model versions, compute performance metrics, and generate comparison reports.
- Calibration Workflow
Cluster observation wells, interpolate simulated heads to observation times (IWFM2OBS), compute typical hydrographs (CalcTypHyd), and create publication-quality calibration figures.
- Packaging and Running Models
Package an IWFM model directory into a distributable ZIP archive, generate platform-appropriate run scripts (.bat, .ps1, .sh), and use the
pyiwfm packageandpyiwfm runCLI commands.- Drawdown Analysis
Compute drawdown relative to a reference timestep, visualize spatially with diverging colormaps, and use the web viewer’s drawdown mode.
- Stream Depletion Analysis
Compare baseline and pumping scenario model runs to quantify stream flow depletion, plot timeseries, and interpret cumulative depletion.
- Simulation Diagnostics
Parse IWFM
SimulationMessages.outfiles, track convergence iterations, identify mass balance errors, and locate problem areas.- Mesh Quality Analysis
Compute element quality metrics (aspect ratio, skewness, angles), identify problematic elements, and visualize quality spatially.
Prerequisites#
Make sure you have pyiwfm installed with the required optional dependencies:
pip install pyiwfm[all]
The tutorials assume basic familiarity with:
Python and NumPy arrays
IWFM model concepts (mesh, stratigraphy, layers)
Basic GIS concepts (coordinate systems, shapefiles)