MODFLOW Document
Writes a Microsoft Word report, with an HTML copy, that documents one or more MODFLOW simulations: packages, grid and layers, stress periods, aquifer properties, boundary conditions, heads, water budget and calibration. Version 1.0.0, November 2026.
1. Overview
Model documentation repeats the same work for every model: tables of layers and properties, maps of each layer,
boundary-condition summaries, budget tables, calibration statistics and a hydrograph for every target. MODFLOW
Document does that part. It reads the simulations in a folder, takes the project, simulation and
hydrostratigraphic names from ConceptualModel.csv, and writes a report with one chapter per simulation.
The text states facts taken from the model files and outputs. Where a statement needs the modeler's knowledge, such as the purpose, data sources, interpretation or the calibration verdict, it writes a highlighted placeholder [Modeler: …] instead of guessing.
MODFLOW Document builds on MODFLOW Review, which reads the models and checks their quality, and is a companion to MODFLOW Compare. It carries its own copy of the reviewer code and of the bundled FloPy fork, so it runs on its own. It never changes the model files.
2. Installation
Copy the modflow_document folder. It runs in the esi_py26 conda environment, which has
numpy, pandas, matplotlib, scipy, geopandas, pyproj and plotly, plus python-docx, which writes the Word file:
conda activate esi_py26 python -m pip install python-docx
Microsoft Word is not needed to write the report, only to read it. The FloPy fork in vendor\ is used
automatically. MODFLOW itself is only needed by the tests, which run MF2005 from GWV9.
3. Usage
python modflow_document.py FOLDER [-o OUT] [--no-maps] [--no-hydrographs] [--debug]
FOLDER holds the simulations, directly or in subfolders at any depth, and optionally
ConceptualModel.csv. The report goes to FOLDER\model_document and is named after the model,
for example DWRM4_Model_Documentation.docx and .html.
Command-line options
| Option | Effect |
|---|---|
-o, --out DIR | Output folder instead of FOLDER\model_document. |
--no-maps | No plan-view maps, which is faster. Tables, budget and calibration figures are still drawn. |
--no-hydrographs | No hydrograph for each target. Calibration statistics and the review figures stay. |
--debug | Print the full Python traceback when something goes wrong. |
Errors that stop a run
The app ends with a one-line ERROR: message and exit code 1, never a traceback, when:
- the folder does not exist, or neither it nor its subfolders hold a MODFLOW simulation;
- none of the simulations listed in
ConceptualModel.csvis found (the message lists those that were found); - two simulations share a root name and the list does not say which to document;
- no simulation could be read;
- the Word file is open in Word and cannot be overwritten.
Problems that affect only part of the report do not stop it. A simulation that cannot be read gets a short chapter saying why. A missing shapefile, an unreadable package or a figure that cannot be drawn is written to the report's notes.
4. ConceptualModel.csv
A CSV file divided into sections. Each section starts with a line whose first cell begins with #. The
example below is the file supplied with DWRM4:
#Project, Company,"Environmental Simulations, Inc." Client,Southwest Florida Water Management District Model,DWRM4 , #Simulations, dwrm4_tr15h,Transient Calibration , #Stratigraphy, Surficial Aquifer System,1 Intermediate Confining Unit,2 Upper Arcadia Aquifer,3 ... Lower Floridan Aquifer VIII,15 , #Shapefiles, Counties_within_the_District.shp,County Boundaries
| Section | Each line | Used for |
|---|---|---|
#Project | Company, Client or Model, and a value; other keys are kept | Title page, report file name, introduction |
#Simulations | Name-file root (without .nam) and a description | Which simulations are documented, their order and their chapter titles |
#Stratigraphy | Unit name and its layer(s): 3, 3-4, 3 to 4 or 3;5 | Layer labels on tables, maps and hydrographs; tables and budget by unit; hydrograph selection |
#Shapefiles | Shapefile (relative to the folder) and what it shows | Outlines drawn on every plan-view map, with a legend entry |
Section names are not case sensitive and the file name is matched in any case. A stratigraphy line without a layer
takes the next layer, and layer,name is also accepted. The following are listed under "Notes on the input
to this report" in the report:
- unknown sections;
- shapefiles that are not found;
- a layer given to two units;
- layers with no unit;
- units naming layers the model does not have.
Without the file the report still works: it uses the file names, refers to layers by number and has no map annotation.
5. How it works
For each simulation the bundled MODFLOW Review loads the model and reads the heads, the cell-by-cell budget, the
listing file and the calibration residual files. It writes its complete review to review\<simulation>.
MODFLOW Document reuses everything the review read: each large output file is opened once for the review and only the
last budget step is read again for the budget by unit. It then derives its own tables and figures and composes the
report as a document model, numbering the figures and tables. Two writers turn that model into Word (python-docx)
and HTML.
6. Finding the simulations
- A simulation is a MODFLOW-2005/NWT/USG name file or a MODFLOW 6
mfsim.nam. The whole folder tree is searched. - Name files that point to the same package files count once. These include Groundwater Vistas' batch copies
(
mfusgs.nam,mf2005.nam,mfnwt.nam,mfusg.nam) and copies with absolute paths. - A name file whose package files are missing is skipped with a note.
- Output folders of the MODFLOW apps (
model_review,model_document,model_compare, …) are not searched. - When
#Simulationslists simulations, only those are documented, in the order listed. Simulations found but not listed, and listed ones that are not found, are reported.
7. What the report contains
The report starts with a title page (client, company, month) and an introduction:
- the simulations table;
- the hydrostratigraphic framework;
- the shapefiles used on the maps;
- notes on the input.
Then each simulation gets a chapter with the sections below. Several simulations add a comparison chapter, with layers, cells, stress periods, RMS of each target type, budget discrepancy and review findings side by side. The appendices list the MODFLOW Review findings and the model and report files.
Model code and packages
A sentence on the simulation, for example "a transient MODFLOW-USG - DISU simulation with 15 layers and 899,955
cells … 240 stress periods covering 7,305 days, from 01 January 1996 to 01 January 2016". It is followed by every
name-file package with a description of what it is, the solver settings, and the flow package. When the length unit is
undefined (LENUNI 0) it is taken from the model's .prj or the target coordinates, and a note says so.
Grid and layers
The grid type, rows and columns or nodes per layer, cell sizes and extent. A table gives, for each layer, its unit, cells, active cells, top and bottom elevation ranges and thickness. It is followed by a map of the top of layer 1 and a multi-panel map of layer thickness.
Time discretization
The number of stress periods and time steps, period lengths, and calendar dates. The start date comes from a
Groundwater Vistas start_datetime comment, MODFLOW 6 START_DATE_TIME, or the calibration date
files. More than 30 periods with few distinct settings are grouped in a short table, and every period is in
stress_periods.csv. Adaptive time stepping is recognised: the text then says that MODFLOW chose the steps and
how many budgets the listing file has.
Aquifer properties
Kx, Kz, Kz/Kx, Ss and Sy of the active cells:
- by hydrostratigraphic unit (geometric means and ranges);
- by layer, in a conductivity table and a storage table;
- a multi-panel map of each property (logarithmic colour scale for K and Ss).
Specific yield is summarised and mapped only over convertible cells, the only cells where it is used. Storage is left out for steady-state simulations.
Boundary conditions
For every package (WEL, RIV, DRN, GHB, CHD, RCH, EVT, …), a summary table and a paragraph give:
- the cells and layers;
- the stress periods with new data;
- the ranges of conductance, stage or elevation, bottom, recharge flux, ET rate, extinction depth and ET surface;
- for flux boundaries, the minimum, maximum and time-weighted mean of the total rate.
Each paragraph ends with a placeholder for its data sources. Figures show the cells of each package coloured by layer, the time-weighted recharge flux and ET rate, and the total specified rates through time.
Initial conditions and simulated heads
Where the starting heads come from (for example a head file listed as DATA), a table of starting and final heads and dry convertible cells by layer, and maps of the final heads with contours.
Water budget
- The number of printed budgets, the largest rate discrepancy and the final cumulative discrepancy.
- The budget at the last printed time step and a graph of every budget term at every printed step.
- The net flow of each term into each hydrostratigraphic unit, with the net exchange with the units above and below, computed from the cell-by-cell budget file.
Calibration
For every Groundwater Vistas residual file (<root>_<type>target_resids.csv) the report gives:
- the targets, observations, layers and times;
- residual statistics overall and for the change from each target's first observation;
- statistics by layer with the unit names;
- for flux targets, the percent-discrepancy bands;
- the MODFLOW Review figures: observed against simulated, residual distribution, residual map, residuals through time, and normality and bias tests;
- a table of the RMS of the targets in each unit and the hydrograph figures (see Hydrographs).
Residual maps of single layers stay in the review folder.
Model quality and appendices
The quality section counts the MODFLOW Review errors and warnings, lists the most important, and links the full review report. Appendix A lists every finding with its summary. Appendix B lists the model files with their sizes and explains the report folder.
8. Modeler placeholders
The app writes facts. Interpretation and judgement are left to the modeler, marked yellow in both Word and HTML so they are easy to find, fill in or delete:
- [Modeler: state the purpose of the model, the questions it is meant to answer, and the study area.]
- [Modeler: describe the data used to define the layer elevations …]
- [Modeler: describe the data sources and assumptions for the wells.] (one per boundary package)
- [Modeler: evaluate the fit to the head targets against the calibration criteria and discuss areas of bias.]
In Word, Find with Format › Highlight jumps from one placeholder to the next.
9. Maps and shapefiles
Every grid type (DIS, DISV, DISU including quadtree) is drawn the same way. The plan view is rasterised once per layer: each pixel takes the nearest cell centre of the layer and is blank outside that cell's bounding box. Every map then reuses that lookup, so the 15-layer maps of the 900,000-cell DWRM4 model take seconds each.
The report has a multi-panel figure, one panel per layer, whose columns are chosen so the figure suits a portrait
page. A full-size PNG of every layer goes to maps\<simulation>\<map>\.
Shapefiles from #Shapefiles are drawn on every map:
- When both the shapefile and the model (a
.prjin the name-file folder) have a coordinate system, the shapes are reprojected with pyproj. - When only the units differ, the coordinates are scaled between metres and feet.
- A shapefile that does not overlap the grid, for example because the grid is not georeferenced, is left off with a note.
10. Hydrographs
When a residual file has targets observed at two or more times, there is one hydrograph per target:
- The simulated line comes from the Groundwater Vistas
_sim_dates.csvfile, and measurements from_obs_dates.csv, against calendar dates. - Without those files the hydrographs are drawn against model time from the residual file.
- Every graph has the same Y-axis span where practical, so the graphs can be compared at a glance. Targets with a larger range use their own scale, and the title says so.
- Each graph shows the number of observations, the mean residual and RMS, and the same statistics for the change from the first observation.
Output for each target type:
- a folder for each layer, named after the layer and its unit (
layer_09_Avon_Park_Aquifer), holding a PNG of each target in that layer and<layer>_hydrographs.pdfwith all of them, three to a page; all_<type>_hydrographs.pdfwith every target, layer by layer;index.html, a table of every target with its layer, unit, observations, dates, mean residual, RMS and a link to its graph, plus links to the PDFs;- in the report: a table of the RMS in each unit, and figures of the best, median and worst target of each unit, ranked by RMS.
11. Output folder and PDFs
Path in model_document\ | Content |
|---|---|
<Model>_Model_Documentation.docx | The report in Word (title page, page numbers, numbered figures and tables, highlighted placeholders) |
<Model>_Model_Documentation.html | The same report in HTML with a table of contents. Figures are linked, not embedded, so keep the folder together |
figures\<sim>\*.png, all_figures.pdf | The report figures, and all of them in one PDF |
maps\<sim>\<map>\layer_NN.png | Full-size map of every layer for thickness, kh, kv, ss, sy and heads |
maps\<sim>\<map>\<map>_all_layers.pdf | Every layer of that map in one PDF |
maps\<sim>\all_maps.pdf | Every layer map of every folder in one PDF |
tables\<sim>\*.csv | Every table in full: stress periods, layers, conductivity, storage, boundaries, heads, budgets, budget through time |
hydrographs\<sim>\<type>\<layer>\ | A PNG for each target and <layer>_hydrographs.pdf |
hydrographs\<sim>\<type>\ | all_<type>_hydrographs.pdf, index.html, targets.csv |
review\<sim>\ | The complete MODFLOW Review report, maps, calibration figures and shapefiles |
The PDFs keep the PNGs: the PNG files stay where they are, for pasting into other documents. Hydrograph PDFs are vector graphics, three graphs to a portrait letter page. Map PDFs put one map on each page.
12. Example: DWRM4 transient calibration
The District-Wide Regulation Model 4 (DWRM4) of the Southwest Florida Water Management District is a public model.
Its 1996–2015 transient calibration (examples\dwrm4_transient) is the largest test of the app.
| Item | DWRM4 transient calibration |
|---|---|
| Code and grid | MODFLOW-USG, DISU with a .gsf, Newton (SMS), LENUNI 0 (taken as feet from the .prj) |
| Size | 15 layers, 899,955 cells (30,065–79,076 per layer), cells about 2,500 ft across |
| Time | 240 monthly stress periods (1996–2015) with adaptive time stepping: 2,652 printed budgets |
| Boundaries | RIV 20,779 cells, DRN 7,260, GHB 1,432, CHD 15,797, WEL 35,087 (layers 1–11), RCH 64,410, EVT 78,944 |
| Calibration | 1,214 head targets (191,529 observations; RMS 6.45 ft, scaled RMS 3.3%) and 3 spring-flow targets |
| Outputs | budget file 38.5 GB, heads 2.6 GB, listing 2.4 GB |
| Report | 38 pages in Word with 26 figures and 22 tables; 1,214 hydrographs in 7 layer folders, each with its PDF, and a 407-page PDF of all of them; 76 layer maps in 6 map folders with PDFs (all_maps.pdf: 76 pages) |
13. Run time and memory
DWRM4 took 19 minutes on a workstation:
- MODFLOW Review: about 12 minutes, most of it reading the 38.5 GB budget file and the 2.4 GB listing file;
- tables, maps, 1,214 hydrograph PNGs and all the PDFs: about 7 minutes (the PDFs added about 3);
- writing the report: seconds.
Memory is set by the boundary tables held by the reviewer, about 8 GB for DWRM4. --no-maps and
--no-hydrographs shorten a run when only the tables are needed.
14. Testing
python tests\run_tests.py runs two scripts with 94 checks, all passing:
- test_inputs.py (25 checks) covers the parts of
ConceptualModel.csvparsing that are easy to get wrong:- commas in quoted values;
.namsuffixes;- layer ranges, a unit without a layer, and
layer,nameorder; - missing shapefiles and unknown sections;
- a missing file.
- test_document.py (69 checks) builds two synthetic transient MODFLOW-2005 models with head and flux targets, date files, a
shapefile and a conceptual model, and runs MF2005. It checks the following.
- The Word chapters, sections, highlighted placeholders, figures and unit names.
- That the HTML links resolve.
- The CSV files, hydrographs, maps and PDF page counts.
- Values against hand calculations: the time-weighted well rate, the geometric mean of Kx, Sy only in convertible cells, and that the unit budget exchanges balance.
- A run without
ConceptualModel.csv. - The command-line errors.
The DWRM4 example is run by hand because it is large.
15. Limitations
- Heads, the budget by unit and the head maps are at the last saved time. The budget through time comes from the listing file.
- Packages such as SFR, LAK, UZF, MAW and CLN are listed and appear in the budget, but they have no dedicated summary table.
- Maps need cell coordinates: MODFLOW-USG without a .gsf gets tables but no maps.
- When LENUNI is 0 and nothing tells the unit, lengths are labelled "model length units".
- The HTML links to its figures, so the report folder must be copied whole.
- Word styling uses the default Word template; a company template, table of contents and caching of large outputs are possible next steps.
16. Architecture and file layout
modflow_document\
modflow_document.py command line; graceful errors
mfdocument\
conceptual.py ConceptualModel.csv
discover.py simulations in the folder tree
gather.py review, tables, maps, budgets; SimData
canvas.py plan-view raster maps, multi-panel figures, PNG -> PDF
overlays.py shapefiles: read, reproject, draw
hydro.py hydrograph PNGs, layer PDFs, index.html, best/median/worst figures
build.py composes the report (chapters, captions, placeholders)
doc.py document model, numbering, number formatting
write_docx.py Word writer (python-docx)
write_html.py HTML writer
run.py orchestration
mfreview\ standalone copy of the MODFLOW Review code
vendor\flopy\ bundled FloPy fork (MODFLOW-USG Transport)
tests\ synthetic models and the test scripts
examples\dwrm4_transient\ DWRM4 transient calibration (public)