Groundwater - 2023 - Hughes - FloPy Workflows For Creating Structured and Unstructured MODFLOW Models
Groundwater - 2023 - Hughes - FloPy Workflows For Creating Structured and Unstructured MODFLOW Models
Abstract
FloPy is a Python package for creating, running, and post-processing MODFLOW-based groundwater flow and transport models.
FloPy functionality has expanded to support the latest version of MODFLOW (MODFLOW 6) including support for unstructured
grids. FloPy can simplify the process required to download MODFLOW-based and other executables for Linux, MacOS, and Windows
operating systems. Expanded FloPy capabilities include (1) full support for structured and unstructured spatial discretizations; (2)
geoprocessing of spatial features and raster data to develop model input for supported discretization types; (3) the addition of
functionality to provide direct access to simulated output data; (4) extension of plotting capabilities to unstructured MODFLOW 6
discretization types; and (5) the ability to export model data to shapefiles, NetCDF, and VTK formats for processing, analysis, and
visualization by other software products. Examples of using expanded FloPy capabilities are presented for a hypothetical watershed.
An unstructured groundwater flow and transport model, with several advanced stress packages, is presented to demonstrate
how FloPy can be used to develop complicated unstructured model datasets from original source data (shapefiles and rasters),
post-process model results, and plot simulated results.
Introduction
FloPy is a Python package for constructing, running, used by others. This workflow has been recommended
and post-processing MODFLOW-based groundwater flow as one way to facilitate repeatable research and sharing
(GWF) and transport (GWT) models (Bakker et al. 2016). of ideas (Fienen and Bakker 2016). Bakker et al. (2016)
It is open-source and developed by a growing community describe the general approach for working with models
of contributors. The combination of open-source program- within the Python environment and emphasize the repro-
ming languages (such as Python) with version control soft- ducible nature of developing models through scripting.
ware (such as Git) allows the model construction process FloPy has been used to pioneer new methods and
to be documented, reproducible, and easily inspected and analysis tools, such as deep learning approaches for
improving groundwater model calibration (Sun 2018;
1 Zhou and Tartakovsky 2021), regionalizing residence
Corresponding author: U.S. Geological Survey, Integrated
Modeling and Prediction Division, 927 W Belle Plaine Avenue, times using metamodeling (Starn and Belitz 2018),
Chicago, IL; [email protected] applying iterative ensemble approaches for calibration and
2 U.S. Geological Survey, Integrated Modeling and Prediction
uncertainty quantification (White 2018), and exploring
Division, 2280 Woodale Drive, Mounds View, MN alternative parameterization schemes for risk analysis
3 U.S. Geological Survey, California Water Science Center, 3130
(Knowling et al. 2019). There are numerous examples
Skyway Drive, Suite 602, Santa Maria, CA
4 U.S. Geological Survey, California Water Science Center, 6000 of constructing MODFLOW models with FloPy to
J Street, Placer Hall, Sacramento, CA solve applied groundwater problems (Befus et al. 2017;
5 Artesia Water, Korte Weistraat 12, Schoonhoven, The
van Engelen et al. 2018; Ebeling et al. 2019; Zipper
Netherlands et al. 2019; Befus et al. 2020). FloPy is also being used in
Article impact statement: FloPy is a Python package for
creating, running, and post-processing structured and unstructured
other software and workflows to improve repeatability and
MODFLOW-based groundwater flow and transport models. robustness through automated model construction (White
Received November 2022, accepted May 2023. et al. 2020; Larsen et al. 2022; Leaf and Fienen 2022;
© 2023 The Authors. Groundwater published by Wiley Peri- Fienen et al. 2022a). FloPy is also used in GIS-based
odicals LLC on behalf of National Ground Water Association. This tools, such as FREEWAT (Rossetto et al. 2018) and other
article has been contributed to by U.S. Government employees and cyberinfrastructures (Essawy et al. 2018) to export models
their work is in the public domain in the USA. into MODFLOW datasets. FloPy can also be used as the
This is an open access article under the terms of the Creative
Commons Attribution-NonCommercial License, which permits use, “glue” to help couple MODFLOW to other hydrological
distribution and reproduction in any medium, provided the original models (Burek et al. 2020) or, for example, to agent-based
work is properly cited and is not used for commercial purposes. models designed to quantify the effects of decision makers
doi: 10.1111/gwat.13327 on environmental behavior (Jaxa-Rozen et al. 2019).
Plotting
FloPy plotting capabilities have been refined and Exporting Grid Data to Other Formats
updated to support plotting both structured and unstruc- Model input and output can be exported in a vari-
tured models in map and cross-section view using
the. PlotMapView() and. PlotCrossSection() ety of standard formats using the .export() method, which
classes, respectively. The plotting methods are wrappers is available for FloPy model objects, package objects,
around the Matplotlib plotting methods (Hunter 2007) binary dependent-variable files (head, concentration, etc.),
and allow fine-grained control using Matplotlib keyword and cell-by-cell output files. Standard output formats that
arguments (kwargs). The following Python code demon- are currently supported include shapefiles (Esri 1998),
strates the steps for plotting a map of simulated heads,
the model grid, the location of drain (DRN) package NetCDF files (Rew and Davis 1990; Rew et al. 2006),
cells, specific-discharge vectors, and head contours for and Visualization Tool Kit (VTK) files (Schroeder
the gwf model. et al. 2006). Entire models, packages, individual pack-
age arrays, binary dependent-variables (e.g., heads), or
mm = flopy.plot.PlotMapView(model=gwf)
three-dimensional representations of binary cell-by-cell
mm.plot_array(head, edgecolor=’’0.5’’)
mm.plot_bc(’’DRN’’)
data can be exported. Shapefile and VTK output can
mm.plot_grid() be exported for all grid types, but currently, NetCDF
cs = mm.contour_array(head) output can only be exported for structured grids. The
mm.ax.clabel(cs) NetCDF output capability has been used to convert entire
mm.plot_vector(qx, qy, normalize=True) models and associated output so that it can be ren-
plt.show()
dered in the GWWebFlow viewer (U.S. Geological Survey
Figure 3A shows the outcome of the Python code 2018).
The following Python code demonstrates the steps for
demonstrated above with additional geographic features exporting the gwf model as a VTK dataset with flat cell
and fine-grained control of grid lines, text, annotations, tops and bottoms (staircase representation).
tick locations, and axis labels. Results shown in Figure 3
are for a steady-state model discretized into three gwf.export(’’temp_vtk/vtk_staircase’’,
convertible layers, with isotropic hydraulic properties, a fmt=’vtk’, smooth=False, vertical_
hydraulic conductivity of 1 m/d, with rivers represented exageration=500.0, pvd=True)
as drain cells in model in layer 1, and an areal
recharge rate of 0.000001 m/d. Figure 3B shows use of VTK models can also be exported with smooth cell
the .plot_array() method to create a map of the tops and bottoms using elevations interpolated to the
layer containing the water table, drain cells where the cell vertices (smooth=True). Other supported export
groundwater is discharging to a river, and cells where formats can be created by specifying the file extension
groundwater is discharging to the surface. to be .shp for shapefiles, .nc for NetCDF files, or if
The following Python code demonstrates the steps the fmt keyword is vtk (as shown above) for VTK files.
for plotting a cross section of simulated heads and
the model grid for the gwf model along an arbi- Figure 4 shows staircase and smooth VTK exports of the
trary line defined using a list of x, y coordinate pairs model described in the Plotting section and rendered with
(tuples) defining the vertices of the line. For structured ParaView (Ahrens et al. 2005).
Scripting MODFLOW 6 Model Development spacing, three model layers, and 1000 active cells per
Using Python and FloPy layer. The upper two layers represent an unconfined
aquifer, and the third layer represents a lower aquifer unit
In this section, FloPy is used to construct, run, and
that is separated from the overlying aquifer by a confining
post process a MODFLOW 6 model. All pre- and post-
unit in the northern part of the model domain (Figure 5A).
processing was done using FloPy grid, geospatial process-
The confining unit was not explicitly represented by Hill
ing, MODFLOW 6 processing, and plotting functionality
et al. (1998); instead a quasi-3D approach (low vertical
discussed previously. Figures 5 through 8 were created conductance) between layers 2 and 3 was used to represent
using a combination of FloPy plotting functionality and the confining unit.
Matplotlib plotting methods (Hunter 2007). Jupyter note-
books (Kluyver et al. 2016) showing the commands for MODFLOW 6 Model Setup
creating the model data sets, processing model results, and To demonstrate the capabilities of FloPy and MOD-
plotting these figures are available at the Synthetic Valley FLOW 6, the 6096 m x 3810 m model domain is dis-
internet address indicated in the Summary and Conclu- cretized using a Voronoi grid, with 6343 active cells per
sions section. layer, and the discretization by vertices (DISV) package
Hill et al. (1998) present a synthetic test case (Figure 5A). The model grid was developed using the
(Synthetic Valley) of an undeveloped alluvial valley Triangle() and VoronoiGrid() utility classes. The
surrounded by low permeability bedrock. The model model grid was refined within Blue Lake, around Straight
includes the Blue Lake and Straight River surface water River using a 750 m buffer, and around pumping wells
features (Figure 5A). The model in Hill et al. (1998) was P1, P2, and P3 using a 100 m buffer.
calibrated and simulated using MODFLOWP (Hill 1992) In this example, both GWF (Langevin et al. 2017)
using a structured grid with a constant 152.4 m grid and solute transport (Langevin et al. 2022) are simulated.
Figure 5. Synthetic Valley model used to demonstrate the MODFLOW 6 capabilities of FloPy. (A) Map showing the Voronoi
grid used to discretize the model domain and the location of Blue Lake, Straight River, and the areal extent of the confining
unit separating the upper and lower aquifer units. (B) Map showing model cells intersecting the northern end of Straight
River. (C) Map showing model cells intersecting the southern end of Straight River. The cell centroid and cell numbers in
the inset areas at the northern and southern end of Straight River are also shown on (B) and (C).
Figure 6. Map showing Synthetic Valley model (A) topography and (B) simulated steady-state heads and specific discharge
rates in model layer 1. Cross-section lines A–A and B–B shown in Figure 7 are also shown on (A).
with a total of 360 time steps with a constant length of Simulated concentrations at the end of 30-years in
30.4375 days. all six model layers are shown in Figure 8. Simulated
Simulated heads and vectors of specific discharge in concentrations are highest beneath Blue Lake in model
model layer 1 are shown in Figure 6B. Specific discharge layer 1 and do not vary much in model layers 1 and 2.
is greatest on the east side of Blue Lake and in the vicinity Simulated concentrations in model layer 3 are limited to
of the three pumping wells and Straight River. Simulated the extent of the confining unit because the remaining cells
heads along cross sections A–A and B–B are shown in the layer are defined to be vertical pass through cells
in Figure 7. The cross sections show that water table (IDOMAIN=-1). The lateral extent of the solute plume
conditions occur in most of the model domain except in does not vary much south of Blue Lake because of the
the vicinity of Blue Lake. lack of confinement in these areas.