Bakker Et Al 2016 Groundwater
Bakker Et Al 2016 Groundwater
Bakker Et Al 2016 Groundwater
Abstract
Graphical user interfaces (GUIs) are commonly used to construct and postprocess numerical groundwater flow
and transport models. Scripting model development with the programming language Python is presented here as
an alternative approach. One advantage of Python is that there are many packages available to facilitate the model
development process, including packages for plotting, array manipulation, optimization, and data analysis. For
MODFLOW-based models, the FloPy package was developed by the authors to construct model input files, run
the model, and read and plot simulation results. Use of Python with the available scientific packages and FloPy
facilitates data exploration, alternative model evaluations, and model analyses that can be difficult to perform with
GUIs. Furthermore, Python scripts are a complete, transparent, and repeatable record of the modeling process.
The approach is introduced with a simple FloPy example to create and postprocess a MODFLOW model. A more
complicated capture-fraction analysis with a real-world model is presented to demonstrate the types of analyses
that can be performed using Python and FloPy.
Introduction
The construction of a groundwater model can be a
complex task depending on the size and geometry of
the domain and temporal variability of the processes
simulated. Models are commonly constructed with a
graphical user interface (GUI). Various GUIs have
been developed, with different levels of complexity and
sophistication. GUIs generally consist of an interactive
1 Corresponding
author: Water Resources Section, Delft University of Technology, Delft, Netherlands; [email protected]
2 Flinders University, Adelaide, South Australia.
3 Currently at Federal Institute for Geosciences and Natural
Resources, BGR, Hannover, Germany.
4 U.S. Geological Survey, Reston, VA.
5 U.S. Geological Survey, Texas Water Science Center,
Austin, TX.
6 U.S. Geological Survey, East Hartford, CT.
7 U.S. Geological Survey Wisconsin Water Science Center,
Middleton, WI.
Article Impact Statement: Python/FloPy scripts are a powerful
approach to build and analyze MODFLOW-based models and are a
full record of the entire modeling process.
Received October 2015, accepted January 2016.
2016, National Ground Water Association.
doi: 10.1111/gwat.12413
NGWA.org
2. Create a MODFLOW model object. Here, the MODFLOW model object is stored in a Python variable
called model, but this can be an arbitrary name.
This object name is important as it will be used as
a reference to the model in the remainder of the
FloPy script. In addition, a modelname is specified
when the MODFLOW model object is created. This
modelname is used for all the files that are created
by FloPy for this model.
model = fpm.Modflow(modelname = gwexample)
1
Computer-specific setup, such as specification of the
directory that contains the MODFLOW executable, is omitted here.
NGWA.org
fpm.ModflowDis(model, nlay=1,
nrow=1, ncol=201, delr=10,
delc=1, top=50, botm=0)
Active cells and the like are defined with the Basic
package (BAS), which is required for every MODFLOW model. It contains the ibound array, which
is used to specify which cells are active (value is
positive), inactive (value is 0), or fixed head (value
is negative). The numpy package (aliased as np) can
be used to quickly initialize the ibound array with
values of 1, and then set the ibound value for the
first and last columns to 1. The numpy package
(and Python, in general) uses zero-based indexing and
supports negative indexing so that row 1 and column
1, and row 1 and column 201, can be referenced as [0,
0], and [0, 1], respectively. Although this simulation
is for steady flow, starting heads still need to be
specified. They are used as the head for fixed-head
cells (where ibound is negative), and as a starting
point to compute the saturated thickness for cases of
unconfined flow.
ibound = np.ones((1, 201))
ibound[0, 0] = ibound[0, -1] = -1
fpm.ModflowBas(model, ibound=ibound, strt=20)
Figure 2. FloPy generated map showing inactive parts of the model, stream boundary conditions, and simulated head and
groundwater-flow directions in model layers 4 and 5 of the Upper San Pedro Basin model of Pool and Dickinson (2007).
Groundwater-flow directions are shown for every fourth model cell.
NGWA.org
Conclusion
Figure 5. FloPy generated map showing the computed capture fraction of water from head-dependent boundaries as a
function of well location in the Upper San Pedro Basin model
layer corresponding to the lower basin fill after 10 years of
pumpage. The maximum areal extent of the active model
domain and the location of stream boundary conditions in
all model layers are also shown.
Use of Python and FloPy allows programmatic creation and postprocessing of MODFLOW-based models. A
programmatic modeling approach facilitates analyses that
can be difficult or impossible to complete using currently
available GUIs, especially when many model runs with
slightly different input are required, such as for parameter estimation, uncertainty analysis, drawdown analysis,
and capture-fraction analysis. (Any of these analyses can
be built into a GUI by the GUI developers, of course.)
Use of a high-level programming language such as Python
allows relatively complicated tasks to be achieved with a
few lines of readable code.
The first FloPy example presented in this paper shows
how to create and postprocesses a simple MODFLOW
model. The capture-fraction analysis using the Upper San
Pedro Basin model presented in this paper demonstrates
the utility of advanced model development using Python
scripts. More than 1500 model runs were automatically
executed and postprocessed using the Python script
developed for the analysis. The final script serves as
a record of the steps performed and can be distributed
along with the original data and reproduced by other
hydrogeologists.
FloPy is a community based open source project
hosted on https://github.com/modflowpy/flopy. The scripts
discussed in this paper and the supporting files are
available on the FloPy website. Installation instructions,
documentation, as well as examples demonstrating how
to use FloPy to create and postprocess MODFLOW-based
models can also be found on the FloPy website.
Acknowledgments
The authors welcome additions, suggestions, and
assistance from the groundwater community, and thank all
past contributors for their work. Any use of trade, product,
or firm names is for descriptive purposes only and does
not imply endorsement by the U.S. Government.
References
Bakker, M. 2014. Python scripting: The return to programming.
Ground Water 52, no. 6: 821822.
Bakker, M., and V.A. Kelson. 2009. Writing analytic element
programs in python. Ground Water 47, no. 6: 828834.
Fienen, M.N., and R.J. Hunt. 2015. High-throughput computing
versus high-performance computing for groundwater applications. Ground Water 53, no. 2: 180184.
NGWA.org
NGWA.org