modflow.infoHomeResourcesToolsExamplesSearchAbout

MODFLOW Compare

Compares two MODFLOW simulations on the same grid, or a chain of model versions, and writes an HTML summary with maps, tables, shapefiles and a change log. Version 1.0.0, November 2026.

1. Overview

MODFLOW Compare answers the question a reviewer asks every time a model is updated: what changed, and what did it do? It reads two simulations — model versions, calibration runs, or management scenarios — matches their cells, and reports every difference in the input (properties, boundaries, stress periods, solver settings, package options, calibration targets, PEST parameters) and in the results (heads, water budgets, concentrations, drawdown, calibration statistics, MODFLOW Review findings).

4 MODFLOW families
MODFLOW-2005, MODFLOW-NWT, MODFLOW-USG (including USG-Transport) and MODFLOW 6 — DIS, DISV and DISU grids.
Cells matched by location
Models with different node numbering (pinch-outs, changed IBOUND/IDOMAIN) are compared cell by cell; a layer map handles split or merged layers.
One report
A self-contained HTML summary, CSV tables, PNG and interactive maps, shapefiles and a change log (CSV and Word) for the model documentation.
Read-only
The model files are never changed; output goes to a new folder.

MODFLOW Compare is built on the model loaders of the MODFLOW Review app. It carries its own copy of them, so it runs without the MODFLOW Review folder.

2. Installation

Copy the modflow_compare folder. It needs Python 3.10 or later with numpy, pandas, scipy, matplotlib and plotly; pywin32 and Microsoft Word are needed only for the Word change log. FloPy is bundled in vendor\flopy (Rodrigo Herrera's fork, which reads the MODFLOW-USG Transport packages) and is put first on the Python path at start-up; an installed FloPy is not used or changed.

modflow_compare
  modflow_compare.py      command-line entry point
  mfcompare\              the comparison
  mfreview\               standalone copy of the MODFLOW Review loaders
  vendor\flopy\           bundled FloPy fork
  tests\                  test scripts

3. Usage

python modflow_compare.py FOLDER                 one folder with two simulations, or two subfolders with one each
python modflow_compare.py PATH_A PATH_B          two folders (or name files), one simulation each
python modflow_compare.py --chain FOLDER         a chain of versions: every simulation in FOLDER or its subfolders, in name order
python modflow_compare.py --chain P1 P2 P3 ...   a chain of versions in the order given

A is the first simulation (alphabetical in a folder, or the first path) and B the second; every difference is B − A. The program prints its progress and ends with the path of the report; the exit code is 0 on success and 1 on an error.

Command-line options

OptionEffect
-o DIR, --out DIROutput folder. Default: FOLDER\model_compare; compare_<A>_vs_<B> beside two folders; FOLDER\model_compare_chain for a chain.
--layer-map MAPLayer correspondence when the layer counts differ, e.g. "1-8:1-8,9:9+10,10-15:11-16". With --chain give STEP=MAP (repeat for several steps). See Layer map.
--zones FILE [FILE_B]Zone array file(s) for zone budgets. Default: zones_<root>*.dat beside the name files. One file is transferred to the other model by location.
--gsf FILE [FILE_B]MODFLOW-USG grid specification file for a model whose folder has none (checked: same node count and the same layer for every node).
--no-reviewDo not run MODFLOW Review on the models (much faster; no side-by-side findings).
--no-mapsNo PNG or interactive maps.
--no-shapefilesNo shapefiles.
--no-wordNo Word change log (the CSV change log is still written).
--debugShow the full Python traceback when something goes wrong.

Examples:

python modflow_compare.py examples\usg_pair --gsf model.gsf
python modflow_compare.py v1 v2 --no-review
python modflow_compare.py --chain versions --layer-map "2=1-8:1-8,9:9+10,10-15:11-16" --zones zones.dat

Errors that stop a comparison

The program stops with a one-line message (no traceback unless --debug) when:

Problems in one part of the comparison (a package FloPy cannot read, an unreadable output file, a failed review) do not stop it: the part is left out and the report says why.

4. How it works

Findthe two simulations
→
Load(and review) each model
→
Layer mapcollapse when needed
→
Matchcells by layer and position
→
Compareinputs and results
→
Writetables, maps, shapefiles, change log
→
ReportHTML summary

Each model is loaded with the MODFLOW Review loaders into one version-independent model object (grid, properties, boundary lists by stress period, recharge and ET, solver settings, packages, output file names). When the reviews are run, the model objects and the head and budget data they read are reused for the comparison, so the large files are read once. Boundary, recharge and ET tables are stored compactly (32-bit numbers, categorical names) as soon as a model is loaded.

5. Finding the simulations

A simulation is a MODFLOW 6 mfsim.nam or a MODFLOW-2005/NWT/USG name file with a DIS or DISU entry (MODFLOW 6 model name files belong to their mfsim.nam). Name files that list the same package files — Groundwater Vistas' batch name files mfusgs.nam, mf2005.nam, mfnwt.nam, or a copy with absolute paths to another folder — count as one simulation; the one with relative paths is used. Subfolders named model_review*, model_compare* or compare_* are skipped, so earlier output never counts as a model.

6. Matching cells

Two models "share a grid" when their cells occupy the same plan positions, even if one has fewer cells. Cells are matched by layer and cell centre, rounded to 0.1 % of the smallest cell size; matched cells must have the same plan area. Cells only in A are reported as removed and cells only in B as added. At least half of each model's plan positions must be found in the other model.

For MODFLOW-USG the cell centres come from the .gsf file (or nodes_xyz.csv). When a model folder has no .gsf, give it with --gsf. If neither model has coordinates but the grids are identical node for node, cells are matched by node number; maps, shapefiles, zone transfers and "moved layer" boundaries are then left out.

7. Layer map

When a layer was split, merged or the layers were re-numbered, --layer-map says which layers correspond. Each item is A layers:B layers; two ranges of equal length pair the layers one to one (1-8:1-8 is eight groups), and 9:9+10 or 3+4:3 makes one group of several layers on one side. Every layer of each model must appear exactly once and in order.

Both models are then collapsed onto the groups: the cells of one group at one plan position become one virtual cell with

QuantityVirtual cellWhy
top, bottomtop of the upper cell, bottom of the lower cellsame total thickness
Khthickness-weighted mean, Σ K·b / Σ btransmissivity is kept
Kvthickness-weighted harmonic mean, Σ b / Σ (b/Kv)vertical leakance is kept
Ss, starting headthickness-weighted means
Sy, layer typethose of the upper cellthe water table is in the upper cell
activeany cell active
boundaries, recharge, ETmoved to the virtual cell
heads, concentrations, drawdownthickness-weighted means of the valid values
layer budgets, target layerssummed / converted by groupread with the original model

Layer numbers in a report written with a layer map are group numbers; the map is shown at the top of the grid section and written to tables\layer_groups.csv. A layer split with unchanged K therefore shows no property difference, and the comparison isolates what really changed.

8. What is compared

Grid and cells

Cells in each model, matched, removed and added, by layer; active cells and active area; the share of convertible cells; matched cells with a different plan area; whether the node numbering is identical. A map shows, per layer, cells that are the same, cells whose K, Ss, Sy or layer type changed, cells where only the geometry or starting head changed, and removed and added cells.

Aquifer properties and geometry

Kh, Kv, Ss, Sy, starting head, top, bottom, thickness, active cell (IBOUND/IDOMAIN) and layer type, for every matched cell (relative tolerance 10−5): changed cells overall and by layer, the ratio B/A for K, Ss and Sy (median and range) or the difference B − A for elevations and heads, maps of the change and a CSV of every changed cell. Sy is the effective value (0 in confined layers), so changing a layer type also changes Sy.

Boundary conditions and areal stresses

Every boundary package the loaders read (CHD, GHB, RIV, DRN, WEL, STR, …) is compared at every stress period in which either model defines new data; a period without new data uses the latest earlier one (MODFLOW's reuse rule) and is counted with it. Each boundary cell is

Recharge and ET (rate, surface, extinction depth) are compared by plan position. The report gives an overview per package (cell-periods of each kind, cells with differences), the counts for each period with new data, a map, an interactive map and a per-cell table with one row per cell and kind of difference (number of periods, first and last period, mean values). A per-period table is written as well, up to one million rows.

Stress periods, output control, solver and package options

Calibration targets

Every <root>_<type>target_resids.csv file (head, drawdown, head difference, flux, concentration) beside both name files. Targets are matched by name and time (and order of occurrence for names listed twice). Reported: targets added, removed, moved (more than 1 length unit) or in another layer; changed observed values or weights; residual statistics of each model and of the common observations, overall and by layer; the targets whose absolute residual changed most; a map of the change; and, for transient targets with two or more observations, hydrographs of the observed values and both simulations (PDF, 9 per page).

Heads and water budgets

Concentration, drawdown and subsidence

The last saved concentration of MODFLOW-USG Transport (species 1) or of the first GWT model of a MODFLOW 6 simulation; the last drawdown record of an output-control drawdown file; the last subsidence of a SUB/SWT output file. Each is compared as B − A by layer, with maps and a per-cell CSV.

Zone budgets

For each zone, the inflow and outflow of every budget record and the flow exchanged with every other zone, at the last saved budget, using the sign convention of each MODFLOW version (JA face flows are positive into node n; structured face flows are positive when leaving the cell). Zone files hold one integer per node (an optional leading count and INTERNAL/CONSTANT control records are accepted); a file of the wrong size is refused. A zone file for one model is transferred to the other by layer and plan position.

PEST

The newest .pst in each model folder (or a folder directly below): parameters added or removed; changes of transform, group, tie, initial value or bounds (with the ratio B/A); final values from the newest .par; observation groups (counts, weighted observations, weight sums); and pilot points (*.pts, pp*.dat: name x y zone value) that moved or changed value.

MODFLOW Review findings

Unless --no-review is given, both models are reviewed with MODFLOW Review (full reports in review_A\ and review_B\) and the findings that appear, disappear, become more or less severe, or change their numbers are listed side by side.

9. Version chains

--chain compares every consecutive pair of versions — v1 → v2, v2 → v3, … — each in its own folder, and writes index.html and history.csv with the key numbers of every step: cells removed and added, cells with changed properties, boundary differences, stress periods and solver settings changed, the RMS error of each target type in every version, the mean head change, the largest budget change and the review findings. Each model is loaded and reviewed only once; a layer map can be given per step; zones from a zone file are carried from step to step by location; a failed step is reported and the chain continues.

History page of a three-version chain (synthetic test models).
History page of a three-version chain (synthetic test models).

10. Output

FileContent
modflow_compare.htmlSummary report with embedded maps and interactive maps (at most 40,000 points each, so the file stays small)
change_log.csv, change_log.docxEvery input change (category, item, layer, detail, A, B), ready for the model documentation
tables\*.csvCells by layer, changed cells per property, cells only in A or B, boundary cells (per cell and per period), stress periods, solver, packages, option differences, targets, head and other output differences per cell, budgets, layer and zone budgets, PEST, review findings
maps\*.pngCell status by layer, property changes, boundary changes, head and other output differences by layer, target residual changes, budgets and heads through time, hydrograph figure and PDF
shapefiles\changes_layer_NN.shpCells with a property change, removed or added, with old and new values and heads
shapefiles\head_difference_layer_NN.shpEvery matched cell with head A, head B and B − A
shapefiles\boundary_changes.shp, targets_<type>.shpBoundary cells that differ (periods, mean values); calibration targets with their status
review_A\, review_B\MODFLOW Review reports of the two models

The report starts with a summary of the main differences and has sections for the models, grid and cells, properties, boundaries, stress periods, solver, packages and options, calibration, heads, water budget, other outputs, zone budgets, parameters, review findings and the list of output files. Shapefile coordinates are converted to the units of the model's .prj when they differ.

11. Run time and memory

Most of the time goes into reading the output files and running the two reviews. Typical times on a 64-GB workstation:

ComparisonSizeTime
Small test models360 cells, 2 stress periods1–2 s
Steady-state regional model, without reviews900,000 cells, 15 layers, 1 period2 min
Same, with both reviews3.4 min

12. Testing

python tests\run_tests.py
ScriptChecksWhat it tests
test_discover.py15Every command-line form and every graceful-error case, with placeholder name files
test_compare_synthetic.py29A MODFLOW-2005 pair and a MODFLOW 6 pair built with FloPy, with known differences (Kh, inactive cells, layer type, well rate, drains, stress-period length, solver tolerance, targets added/moved/re-layered); when MF2005 and MF6 are installed the models are run and heads and budgets are checked
test_enhancements.py34Layer map (a split layer with unchanged K shows no difference; bad maps refused), budgets and heads through time, hydrographs, zone budgets (the pumping change appears in the right zone; every zone balances; wrong-size files refused), drawdown, MODFLOW 6 GWT concentrations, PEST parameters and pilot points, a three-version chain

All 78 checks pass. Test output goes to new timestamped folders under test_output\; nothing is deleted. The comparison has also been run on large real models, including several versions of a 900,000-cell regional MODFLOW-USG model, including a version chain with a split layer.

13. Limitations

14. Architecture and file layout

Module (mfcompare\)Role
discover.pyFind the two simulations (or a chain) and raise the errors
compare.pyRun a comparison: load, layer map, match, compare, write; the summary
match.pyCell matching by layer and position (or by node number)
layers.pyLayer map parsing and collapsing of models and outputs
inputs.pyProperties, cells by layer, stress periods, solver, packages, option lines
bcs.pyBoundary conditions, recharge and ET
calib.pyCalibration residual files
results.pyHeads, dry and flooded cells, global and layer budgets, saved times
transient.pyBudgets and heads through time, hydrographs
zones.pyZone files and zone budgets
otherout.pyConcentration, drawdown, subsidence
pest.pyPEST control, parameter and pilot-point files
reviews.pyMODFLOW Review findings side by side
chain.pyVersion chains and the history page
maps.py, export.py, changelog.py, report.pyMaps, CSV and shapefiles, change log, HTML report

The copy of mfreview differs from MODFLOW Review in one line: review() keeps the outputs it read in rv.extra["_outputs"], so the comparison can reuse them.