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).
MODFLOW-2005, MODFLOW-NWT, MODFLOW-USG (including USG-Transport) and MODFLOW 6 — DIS, DISV and DISU grids.
Models with different node numbering (pinch-outs, changed IBOUND/IDOMAIN) are compared cell by cell; a layer map handles split or merged layers.
A self-contained HTML summary, CSV tables, PNG and interactive maps, shapefiles and a change log (CSV and Word) for the model documentation.
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
| Option | Effect |
|---|---|
-o DIR, --out DIR | Output folder. Default: FOLDER\model_compare; compare_<A>_vs_<B> beside two folders; FOLDER\model_compare_chain for a chain. |
--layer-map MAP | Layer 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-review | Do not run MODFLOW Review on the models (much faster; no side-by-side findings). |
--no-maps | No PNG or interactive maps. |
--no-shapefiles | No shapefiles. |
--no-word | No Word change log (the CSV change log is still written). |
--debug | Show 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:
- a path does not exist, or more than two paths are given without
--chain; - a folder holds none, one or more than two simulations; a subfolder holds two; a folder holds simulations both in itself and in subfolders; both paths are the same simulation;
- a name file's package files are missing;
- the models have different numbers of layers and no layer map is given (the message shows the option), or the layer map is invalid (a layer missing, named twice, or out of order);
- the two grids do not share their cell positions (less than half of each model's plan positions are found in the other), or two cells of a layer share one position;
- cell coordinates are missing and the grids are not identical node for node (the message points to
--gsf); - a
--gsfor--zonesfile does not belong to the model.
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
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.
.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
| Quantity | Virtual cell | Why |
|---|---|---|
| top, bottom | top of the upper cell, bottom of the lower cell | same total thickness |
| Kh | thickness-weighted mean, Σ K·b / Σ b | transmissivity is kept |
| Kv | thickness-weighted harmonic mean, Σ b / Σ (b/Kv) | vertical leakance is kept |
| Ss, starting head | thickness-weighted means | |
| Sy, layer type | those of the upper cell | the water table is in the upper cell |
| active | any cell active | |
| boundaries, recharge, ET | moved to the virtual cell | |
| heads, concentrations, drawdown | thickness-weighted means of the valid values | |
| layer budgets, target layers | summed / converted by group | read 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
- unchanged or changed — in the matched cell of both models; conductance, head/stage/elevation, river bottom and rate compared;
- moved layer — not in the matched cell of the other model, but at the same plan position in another layer (for example a drain moved down from a pinched-out layer);
- removed or added — no such boundary at that plan position in the other model.
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
- Stress periods: number, length, time steps, multiplier, steady/transient, and the periods that differ; the number of saved head and budget times.
- Solver: every setting of PCG/PCGN/GMG/SIP/DE4/NWT/SMS/IMS, Newton formulation and HDRY.
- Packages: packages present in one model only.
- Options: the option and header lines of each package in both models — the whole file up to 60 KB; otherwise the MODFLOW 6 OPTIONS/DIMENSIONS/solver blocks or the lines before the first array or list data. Output and data files are skipped, and file names containing the model name are masked, so renaming a model does not show as a difference.
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
- Heads: B − A at every saved time both models have (up to 50 evenly spread times), by layer at the last common time, through time, maps, an interactive map and a per-cell CSV; dry cells and heads above land surface.
- Global budget: every term of the listing-file budget at the last common printed budget, percent discrepancies, and every term at every common printed budget (plot of the largest terms).
- Layer budgets: the net flow of every budget record in every layer, from the cell-by-cell budget files.
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.
10. Output
| File | Content |
|---|---|
modflow_compare.html | Summary report with embedded maps and interactive maps (at most 40,000 points each, so the file stays small) |
change_log.csv, change_log.docx | Every input change (category, item, layer, detail, A, B), ready for the model documentation |
tables\*.csv | Cells 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\*.png | Cell 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.shp | Cells with a property change, removed or added, with old and new values and heads |
shapefiles\head_difference_layer_NN.shp | Every matched cell with head A, head B and B − A |
shapefiles\boundary_changes.shp, targets_<type>.shp | Boundary 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:
| Comparison | Size | Time |
|---|---|---|
| Small test models | 360 cells, 2 stress periods | 1–2 s |
| Steady-state regional model, without reviews | 900,000 cells, 15 layers, 1 period | 2 min |
| Same, with both reviews | 3.4 min |
12. Testing
python tests\run_tests.py
| Script | Checks | What it tests |
|---|---|---|
test_discover.py | 15 | Every command-line form and every graceful-error case, with placeholder name files |
test_compare_synthetic.py | 29 | A 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.py | 34 | Layer 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
- The grids must share their cell positions; models on different grids (refined or regridded) are not interpolated.
- Packages that the loaders do not read as boundary lists (for example CLN, MAW, LAK, UZF details) are compared only through their option lines and the budgets.
- Concentrations, drawdown, subsidence, layer budgets and zone budgets are compared at the last saved time; heads at up to 50 saved times.
- Hydrographs use the simulated values in the residual files, not the full simulated line of the
_sim_dates.csvfiles. - Layer groups must follow the layer order of both models.
- PEST: control files, parameter value files and pilot-point files only (no ensembles or PEST++-specific output).
- Very large transient models need a lot of memory (see Run time and memory).
- The Word change log needs Microsoft Word.
14. Architecture and file layout
Module (mfcompare\) | Role |
|---|---|
discover.py | Find the two simulations (or a chain) and raise the errors |
compare.py | Run a comparison: load, layer map, match, compare, write; the summary |
match.py | Cell matching by layer and position (or by node number) |
layers.py | Layer map parsing and collapsing of models and outputs |
inputs.py | Properties, cells by layer, stress periods, solver, packages, option lines |
bcs.py | Boundary conditions, recharge and ET |
calib.py | Calibration residual files |
results.py | Heads, dry and flooded cells, global and layer budgets, saved times |
transient.py | Budgets and heads through time, hydrographs |
zones.py | Zone files and zone budgets |
otherout.py | Concentration, drawdown, subsidence |
pest.py | PEST control, parameter and pilot-point files |
reviews.py | MODFLOW Review findings side by side |
chain.py | Version chains and the history page |
maps.py, export.py, changelog.py, report.py | Maps, 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.