Tutorials#

Step-by-step tutorials for common pyiwfm workflows.

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 package and pyiwfm run CLI 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.out files, 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)