0% found this document useful (0 votes)
88 views16 pages

Groundwater - 2023 - Hughes - FloPy Workflows For Creating Structured and Unstructured MODFLOW Models

Uploaded by

chemirikcamelia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
88 views16 pages

Groundwater - 2023 - Hughes - FloPy Workflows For Creating Structured and Unstructured MODFLOW Models

Uploaded by

chemirikcamelia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

FloPy Workflows for Creating Structured and

Unstructured MODFLOW Models


by Joseph D. Hughes1 , Christian D. Langevin2 , Scott R. Paulinski4 , Joshua D. Larsen4 , and
David Brakenhoff5

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).

124 Vol. 62, No. 1–Groundwater–January-February 2024 (pages 124–139) NGWA.org


17456584, 2024, 1, Downloaded from https://ngwa.onlinelibrary.wiley.com/doi/10.1111/gwat.13327 by Algeria Hinari NPL, Wiley Online Library on [04/01/2025]. See the Terms and Conditions (https://onlinelibrary.wiley.com/terms-and-conditions) on Wiley Online Library for rules of use; OA articles are governed by the applicable Creative Commons License
The U.S. Geological Survey uses FloPy to teach boundaries, mass sources and sinks, and mass sorption
MODFLOW and groundwater modeling to early- and and reactions. GWF and GWT models can be developed
mid-career engineers and scientists. Other organizations using structured model grids consisting of layers, rows,
also use FloPy to teach MODFLOW (e.g., Australian and columns or they can be developed using more
Water School 2023; Hatari Labs 2023). We routinely rely general unstructured grids using many of the concepts
on FloPy to load and help identify problems in user and numerical approaches available in MODFLOW-
model applications, and with the initial release of the USG (Panday et al. 2013). MODFLOW 6 also includes
MODFLOW 6 GWF model (Langevin et al. 2017), we advanced formulations to simulate three-dimensional
started to rely on FloPy to help with the development anisotropy and dispersion (Provost et al. 2017), coupled
of the MODFLOW program. We write tests that rely on variable-density GWF and GWT (Langevin et al. 2020),
FloPy to construct and run models, and then read output. and a water mover package to represent natural and
We then verify that the output is as expected, by using managed hydrologic connections (Morway et al. 2021).
analytical solutions, other models, or results that have Development and testing of the MODFLOW 6 pro-
been confirmed to be correct. gram rely heavily on tight integration with FloPy. A
The purpose of this paper is to highlight FloPy new key component of this tight integration is the capa-
functionality for creating and constructing structured and bility to quickly support new MODFLOW 6 models
unstructured MODFLOW models. We provide examples and packages with FloPy. Unlike the FloPy support for
that demonstrate these new capabilities, and reinforce previous MODFLOW versions (e.g., MODFLOW-2005,
the advantages of the modern scripting workflow for MODFLOW-NWT, MODFLOW-USG, and SEAWAT),
developing reproducible structured and unstructured the FloPy Python classes for MODFLOW 6 are dynam-
MODFLOW GWF and GWT models that can be updated ically generated from simple text files, called “definition
as new data become available. The examples also files,” that describe the input file structure. All MOD-
demonstrate workflows that develop different model grids FLOW 6 model input files are described using these defi-
for the same model domain. The important advances nition files. This allows MODFLOW 6 developers to write
described here include (1) complete support for all tests for new models, packages, and functionality as they
models, packages, and options implemented in the core are developed. These definition files are used to program-
version of MODFLOW supported by the U.S. Geological matically generate the user input and output guide for
Survey (Hughes et al. 2017; Langevin et al. 2017; Provost MODFLOW 6. These same definition files are also used to
et al. 2017; Langevin et al. 2020; Morway et al. 2021; generate FloPy classes, with documentation correspond-
Hughes et al. 2022; Langevin et al. 2022; Mancewicz ing to input variable descriptions in the input and output
et al. 2022); (2) generalized support for models based on guide. New functionality can be added by users to existing
a structured grid consisting of layers, rows, and columns, packages by modifying existing definition files. The exist-
and also for models based on unstructured grids; (3) ing definition files can also be used as a template for cre-
implementation of new geoprocessing capabilities to ating classes for new MODFLOW 6 models or packages.
rapidly populate models with data from a variety of
input sources; (4) simplified access to model results; (5)
plotting capabilities for map and cross-section views of
Common Modeling Tasks
model data; and (6) export capabilities for writing model The code snippets presented in this section that
data to a variety of output formats. demonstrate how to create model grids, geoprocess data,
process output, plot model data, and export model data
are available as Jupyter notebooks (Kluyver et al. 2016)
FloPy Support for MODFLOW 6 at the internet addresses indicated in the Summary and
The most recent version of MODFLOW (MOD- Conclusions section.
FLOW 6) is an object-oriented program and framework
Getting MODFLOW and Other Related Executables
developed to provide a platform for supporting multiple FloPy for MODFLOW 6 relies on a number of
models and multiple types of models within the same helper classes, which wrap functionality available in
simulation (Hughes et al. 2017). These models can be pre-compiled external utility programs, to generate
independent of one another with no interaction, they can unstructured models and calculate water budgets on
exchange coefficients and dependent variables (e.g., head), user-defined zones. These external utility programs (e.g.,
GRIDGEN, Triangle, ZONEBUDGET, etc.), MOD-
or they can be tightly coupled at the matrix level by FLOW 6, and other MODFLOW-related programs (e.g.,
adding them to the same numerical solution. The transfer MODPATH, MT3DMS, MT3D-USGS, SEAWAT, etc.)
of information between models is isolated to exchange can be installed using
objects, which allow models to be developed and used get-modflow:flopy
independently. Within this new framework, a regional-
scale groundwater model may be coupled with multiple in a terminal or at the command line after installing
local-scale groundwater models. FloPy. The get-modflow command detects the operat-
MODFLOW 6 currently includes the GWF model ing system (Linux, MacOS, or Windows) and down-
and the GWT model each with packages to represent loads the latest operating-system-specific release of MOD-
surface water processes, groundwater extraction, external FLOW and related programs from an Executables GitHub

NGWA.org J.D. Hughes et al. Groundwater 62, no. 1: 124–139 125


17456584, 2024, 1, Downloaded from https://ngwa.onlinelibrary.wiley.com/doi/10.1111/gwat.13327 by Algeria Hinari NPL, Wiley Online Library on [04/01/2025]. See the Terms and Conditions (https://onlinelibrary.wiley.com/terms-and-conditions) on Wiley Online Library for rules of use; OA articles are governed by the applicable Creative Commons License
repository. get-modflow can also download previous ver- idomain_parent[0, 8:12, 13:18] = 0
sions of MODFLOW 6 and the latest development version ncpp, ncppl = 3, [1]
lgr = Lgr(nlay_parent, nrow_parent,
of MODFLOW 6 using instructions available on the FloPy ncol_parent,
GitHub repository. delr_parent, delc_parent, topparent, botmpar-
ent,
Managing and Creating Model Grids idomain_parent, ncpp=ncpp,
FloPy was originally developed to support models ncppl=ncppl,
that are based on a structured grid consisting of layers, xllp=0.0, yllp=0.0)
delr, delc = lgr.get_delr_delc()
rows, and columns. Recent support for unstructured xoff, yoff = lgr.get_lower_left()
grids in MODFLOW (Panday et al. 2013; Langevin structured_gridchild = Structured-
et al. 2017) required revisions to the underlying approach Grid(delr=delr, delc=delc, xoff=xoff,
for managing spatial discretization information in FloPy. yoff=yoff)
Grid information is containerized into a single location The child grid is created in the inactive area of
and used throughout FloPy modeling tasks for geospatial the parent grid (idomain_parent) and the returned
processing, plotting, and exporting. Spatial discretization lgr object contains all of the information required to
is now handled in FloPy through dedicated model grid create a child StructuredGrid object. The connection
classes. There is a Grid class, which serves as the properties needed to create the MODFLOW 6 Exchange
base class for the StructuredGrid, VertexGrid,
input file for the parent and child grids can be retrieved
and UnstructuredGrid classes. Grid objects can
using lgr.get_exchange_data().
be created by the user for preprocessing, and they are
FloPy supports the management and generation of
automatically generated and attached to a FloPy model
unstructured grids. Unstructured grids are represented
object.
as layered or fully unstructured. A layered grid is one
Structured MODFLOW grids can have constant row
in which the same grid applies to all model layers.
and column spacings, as shown in Figure 1A, or they can
An unstructured grid is more general and allows the
have variable row and column spacings to focus resolution
model grid to change with depth. Layered grids and
around an area of interest, as shown in Figure 1B. The
unstructured grids are stored in FloPy as VertexGrid
following Python code shows how to create a Struc-
and UnstructuredGrid objects, respectively.
turedGrid object in FloPy. A StructuredGrid Layered quadtree grids can be created using the
object can also be created from discretization data required Gridgen() utility class, which is a wrapper around
when instantiating a MODFLOW 6 DIS object using the GRIDGEN program (Lien et al. 2014). GRIDGEN
flopy.mf6.ModflowGwfdis(). starts with a structured MODFLOW grid with constant
and equal row and column spacing defined by the user.
> structured_grid = The program then recursively subdivides individual cells
flopy.discretization.StructuredGrid that intersect with refinement features into quarters until
(nlay=nlay, . . . delr=delr, delc=delc, a maximum level of refinement is met. Refinement
xoff=0.0, yoff=0.0, angrot=0.0, features may be points, lines, or polygons. Smoothing
top=top, botm=botm) is automatically handled so that a cell is connected
MODFLOW 6 was developed to support multi-model to no more than two cells in any primary horizontal
simulations (Hughes et al. 2017). One form of multi- direction and four cells in the vertical direction. Figure 1D
model simulation is a nested grid application in which shows an example of a quadtree grid created with
a more finely discretized child model is embedded within GRIDGEN in which a base grid is refined two levels
a more coarsely discretized parent model (Mehl and along streams and in the grid refinement area shown
Hill 2006; Vilhelmsen et al. 2012; Mehl and Hill 2013; in Figure 1. The following Python code shows the
Fienen et al. 2022b). The use of a locally refined steps for creating the quadtree grid with GRIDGEN.
grid (LGR) within an encompassing parent grid offers sim = flopy.mf6.MFSimulation()
computational benefits in that the additional refinement gwf = flopy.mf6.ModflowGwf(sim)
is targeted to an area of interest. FloPy provides a dis6 = flopy.mf6.ModflowGwfdis(gwf,
Lgr() utility class for constructing the data required nrow=nrow, ncol=ncol, delr=dy,
to tightly couple parent and child models within a delc=dx)
single MODFLOW 6 simulation. Figure 1C shows two g = Gridgen(dis6, model_ws=temp_path)
StructuredGrid objects—one object represents the g.add_refinement_features([[lgr_
parent model grid and the other represents the nested polygon_xy]], ‘‘polygon’’, 2, range(1))
child grid. The Lgr() utility class defines the connection g.add_refinement_features
properties between cells in the parent model and cells (stream_points, ‘‘line’’, 2, range(1))
in the child model. Connection properties consist of g.build(verbose=False)
distances, areas, and other geometric information needed gridprops_vg = g.get_gridprops_
to calculate flow between cells in different models. vertexgrid()
The Lgr() utility class is general in that the child quadtree_grid = flopy.discretization.
model can have more layers than the parent model. The VertexGrid(**gridprops_vg)
following Python code shows the steps for creating a child
StructuredGrid object using data for the parent grid FloPy also provides a wrapper utility for the Triangle
with the Lgr() utility class. mesh generation program (Shewchuk 1996). The Trian-
gle() utility class writes the Triangle program input file,
idomain_parent = np.ones((nlay_parent, runs the Triangle program, and then loads the triangular
nrow_parent, ncol_parent), dtype=int) mesh. Users provide the maximum area for individual

126 J.D. Hughes et al. Groundwater 62, no. 1: 124–139 NGWA.org


17456584, 2024, 1, Downloaded from https://ngwa.onlinelibrary.wiley.com/doi/10.1111/gwat.13327 by Algeria Hinari NPL, Wiley Online Library on [04/01/2025]. See the Terms and Conditions (https://onlinelibrary.wiley.com/terms-and-conditions) on Wiley Online Library for rules of use; OA articles are governed by the applicable Creative Commons License
Figure 1. Examples of grids that can be generated and processed using FloPy for a hypothetical watershed, including (A)
a structured MODFLOW grid with constant and equal row and column spacings, (B) a structured MODFLOW grid with
variable row and column spacings, (C) a structured MODFLOW child grid nested within a structured MODFLOW parent
grid, (D) a quadtree grid generated with the GRIDGEN program (Lien et al. 2014) through the FloPy wrapper, (E) a
triangular grid generated with the Triangle program (Shewchuk 1996) through the FloPy wrapper, and (F) a Voronoi grid
created from the triangular mesh. All of the grids have refinement in the location of the child grid in (C).

triangles, angle constraints, a polygon describing the idomain=idomain, nlay=nlay,


model domain, and so forth. Figure 1E shows an example ncpl=tri.ncpl, top=top, botm=botm)
of a triangular grid created with the Triangle program.
The Python code for creating the triangular grid is shown refinement_verts in the triangular grid code
below. shown above contains the user-specified stream vertices
tri = flopy.utils.triangle.Triangle and the horizontal cell vertices for the grid refinement
(maximum_area=maximum_area, angle=30, area shown in Figure 1.
nodes=refinement_verts, model_ws= A triangular grid can be converted by FloPy into
temp_path) a Voronoi grid using the VoronoiGrid() utility
tri.add_polygon(boundary_points) class. The VoronoiGrid() utility class uses SciPy
tri.build(verbose=False) routines (Virtanen et al. 2020) to construct Voronoi
cell2d = tri.get_cell2d() polygons around each vertex in the triangular mesh.
vertices = tri.get_vertices() Figure 1F shows an example of a Voronoi grid cre-
triangular_grid = VertexGrid ated from the triangular mesh shown in Figure 1E.
(vertices=vertices, cell2d=cell2d, The steps for creating the Voronoi grid from the

NGWA.org J.D. Hughes et al. Groundwater 62, no. 1: 124–139 127


17456584, 2024, 1, Downloaded from https://ngwa.onlinelibrary.wiley.com/doi/10.1111/gwat.13327 by Algeria Hinari NPL, Wiley Online Library on [04/01/2025]. See the Terms and Conditions (https://onlinelibrary.wiley.com/terms-and-conditions) on Wiley Online Library for rules of use; OA articles are governed by the applicable Creative Commons License
previously created Triangle() object (tri) are shown grids so that it is straightforward to build and construct
below. vor = flopy.utils.voronoi. models with different grid resolutions or grid types. The
VoronoiGrid(tri) geospatial processing routines work with all three of the
gridprops = vor.get_gridprops_ model grid types (StructuredGrid, VertexGrid,
vertexgrid() and UnstructuredGrid).
voronoi_grid = VertexGrid(**gridprops, A common geospatial processing task is resampling
nlay=nlay, idomain=idomain) of raster data onto a model grid. For example, it is often
necessary as part of model construction to resample a
The StructuredGrid, VertexGrid, and raster data set of land surface elevation onto a model grid.
UnstructuredGrid classes have useful properties FloPy includes a new raster sampling utility based on the
and methods for accessing or mapping locations on the Rasterio Python package (Gillies 2023). The following
model grid including: (1) converting x, y pairs from local Python code demonstrates the steps for resampling an
to global coordinates (.get_coords()) and from Esri ASCII raster format grid onto a Voronoi grid.
global to local coordinates (.get_local_coords()); fine_topo = flopy.utils.Raster.load
(2) getting x, y, and z coordinates for cell centers (’’./grid_data/fine_topo.asc’’)
top_vg = fine_topo.resample_to_grid
(.xcellcenters, .ycellcenters, .zcell-
(voronoi_grid, band=fine_topo.bands[0],
centers, and .xyzcellcenters) and vertices method=‘‘linear’’, extrapolate_edges=
(.xvertices, .yvertices, .zvertices, and True)
.xyzvertices); and (3) intersecting a list of x, y
pairs with the grid and returning the appropriate cellid The result of raster resampling is a NumPy array,
(.intersect()). Local coordinates are model-based equal in size to the number of cells in one layer of the
coordinates and global coordinates are coordinates Voronoi grid. The NumPy array contains an interpolated
generated after transforming local model coordinates land surface elevation for each model cell. In this Python
using user-specified x-offset, y-offset, and rotation angle code example, the land surface grid was interpolated
values; global coordinates are equal to local coordinates to the Voronoi grid using a “linear” method, however,
if the x-offset, y-offset, and rotation angle are all zero. the method also supports “nearest,” “cubic,” and other
Other useful grid class properties and methods include options (“mean,” “median,” “mode,” “min,” and “max”)
generating a grid object from a MODFLOW 6 binary available in the rasterstats Python package (Perry 2013)
grid file (.from_binary_grid_file()), retrieving for geostatistical resampling. Elevation ranges in Figure 1
cell thicknesses (.cell_thickness), and calculating show the results of linear raster resampling for land
the saturated thickness for each cell by passing a head surface onto a variety of structured and unstructured
array with dimensions consistent with the grid object model grids.
(.saturated_thickness(head)). Performing intersections of hydrologic features with
The new FloPy capabilities for generating and testing the model grid is another common modeling task. FloPy
different types of model grids allow for innovation is now equipped with robust and efficient capabilities for
in the way a study area is discretized. For example, intersecting a model grid with points, lines, and polygons.
Guira (2018) used a Voronoi grid to add additional The underlying intersection routines rely on the Shapely
resolution in the vicinity of irrigation wells in the Python package (Gillies 2022) to determine intersection
Frenchman Creek Basin in Nebraska, USA to quantify properties. When a point or collection of points is
the effects of land-use change and irrigation on streamflow intersected with a model grid, the grid intersection
depletion. Furthermore, the ability to develop multi-model routine returns the cells that intersect with the points.
simulations using FloPy allows higher-resolution inset When a line or collection of lines is intersected with
models to be added in focused areas. Fienen et al. (2022b) a model grid, the grid intersection routine returns the
used local grid refinement models tightly coupled to cells that intersect with the lines and the lengths of
inset models that were in turn loosely coupled to a lines within each intersected cell. The line and grid
coarse regional model, to better represent lakes and intersection routine also creates and returns individual
quantify the effects of distant pumping on lake and line segments of the line features within each intersected
groundwater interactions in the Central Sands region in cell. When a polygon or collection of polygons is
Wisconsin, USA. The inset GWF models with lakes intersected with a model grid, the grid intersection routine
(Fienen et al. 2022b) were developed using modflow- returns the cells that intersect with the polygons and
setup (Leaf and Fienen 2022), which relies on FloPy to the polygon area within the cell. The polygon and grid
generate MODFLOW 6 datasets. intersection routine also creates and returns individual
polygons of the original polygon features within each
Geospatial Processing intersected cell.
The following Python code demonstrates the steps for
Geospatial processing is often a fundamental part identifying the grid cells that intersect with a collection
of creating a groundwater model. New geospatial pro- of line segments. ixs = flopy.utils.GridIntersect
cessing functionality has been added to FloPy to help
(voronoi_grid)
users construct models using data from common input results = []
sources. The geospatial processing functionality has been for points in segments:
implemented to work with the different types of model segment = ixs.intersect

128 J.D. Hughes et al. Groundwater 62, no. 1: 124–139 NGWA.org


17456584, 2024, 1, Downloaded from https://ngwa.onlinelibrary.wiley.com/doi/10.1111/gwat.13327 by Algeria Hinari NPL, Wiley Online Library on [04/01/2025]. See the Terms and Conditions (https://onlinelibrary.wiley.com/terms-and-conditions) on Wiley Online Library for rules of use; OA articles are governed by the applicable Creative Commons License
Figure 2. Examples of the intersection of a linear stream network with the model grids are shown in Figure 1. Intersections
were performed using FloPy for (A) a structured MODFLOW grid, (B) a structured MODFLOW grid with variable row and
column spacing, (C) a structured MODFLOW child grid nested within a structured MODFLOW parent grid, (D) a quadtree
grid, (E) a triangular grid, and (F) a Voronoi grid. Shaded cells represent those cells that intersect with the linear stream
network.

(LineString(points)) network and the six different model grids is shown in


results.extend(segment[’’cellids’’]. Figure 2.
tolist())

Processing MODFLOW 6 Output


The result of this code snippet (results) is a list MODFLOW 6 has many different types of output that
of Voronoi grid cell numbers that intersect with the line can be created during a simulation. A GWF model, for
segments. The ixs.intersect() method also returns example, can write simulated heads and detailed budget
the ‘‘lengths’’ of the shapelike collection intersect- information to binary files. Global model budgets are
ing each cell, the ‘‘vertices’’ corresponding to each written to standard MODFLOW listing (*.lst) files
cell that intersects a collection of shapelike objects, and a and can be written to comma-separated value text files.
shapely object (‘‘ixshape’’) for each portion of the Some individual GWF and GWT model advanced stress
original shape (LineString(points)) that intersects packages can also write simulated output. Advanced
a cell. Results of the grid intersection for a linear stream packages solve their own continuity equation and include

NGWA.org J.D. Hughes et al. Groundwater 62, no. 1: 124–139 129


17456584, 2024, 1, Downloaded from https://ngwa.onlinelibrary.wiley.com/doi/10.1111/gwat.13327 by Algeria Hinari NPL, Wiley Online Library on [04/01/2025]. See the Terms and Conditions (https://onlinelibrary.wiley.com/terms-and-conditions) on Wiley Online Library for rules of use; OA articles are governed by the applicable Creative Commons License
the Lake (LAK), Streamflow Routing (SFR), Multi- simulated head output, for example, a call can be made
Aquifer Well (MAW), Unsaturated Zone Flow (UZF), and to the head file reader to retrieve data for a specified
Mover (MVR) packages. For example, the LAK Package simulation time using the .get_data() method as
follows. head = gwf.output.head().get_data
can write simulated lake stages and detailed lake budget
information to binary files. Likewise, the MAW Package (totim=1.0)
can write simulated well head and well budgets to binary In this case, the head variable is retrieved for a user-
files. Recent improvements have been made to FloPy specified simulation time (totim= and is a NumPy array
to allow users easier access to simulation results using equal in size to the size of the model grid. Head data can
.output routines available for MODFLOW 6 models and also be accessed for a zero-based time step–stress period
tuple.
advanced stress packages. Prior to these improvements, head = gwf.output.head().get_data
users were required to instantiate head, concentration, and (kstpkper=(0,0))
budget file readers using file paths and names in order to
or a zero-based index.
access simulation results. With the .output routines, the
file readers are automatically generated when called by head = gwf.output.
the user. head().get_data(idx=0)
The following .methods() syntax shows how
a user can discover the type of output informa- Processing Simulated Cell-by-Cell Budgets
tion that is available for the specified gwf model.
Similar to head output, cell-by-cell budget informa-
> gwf.output.methods() tion can be accessed using FloPy. Unlike the simulated
[’list()’, ’zonebudget()’, ’budget()’, head file, the cell-by-cell budget file can have data for
’budgetcsv()’, ’head()’] more than one item and these items may be stored in the
file as arrays or lists of data. The data in the cell-by-cell
The .list() method can be used to get the incre- budget file can be determined using.
mental (incremental=True) or cumulative budget
> gwf.output.budget().list_unique_
information from the MODFLOW listing file for the gwf records()
model for a user-specified simulation time, zero-based
time step and stress period tuple, or zero-based index. RECORD IMETH
The .zonebudget() method allows the user to build — — — — — — — — — — — — — — — — — — — --
FLOW-JA-FACE 1
water and mass budgets for individual zones for MOD- DATA-SPDIS 6
FLOW 6 models, run the ZONEBUDGET program, and DATA-SAT 6
access ZONEBUDGET output. The .budget() method WEL 6
provides access to data in binary MODFLOW 6 cell- DRN 6
by-cell budget files. The .budgetcsv() method pro- RCHA 6
EVTA 6
vides access to cumulative and incremental global budgets SFR 6
written by MODFLOW 6 to comma-separated value files. LAK 6
The .head() method gives user access to data in the
The IMETH code indicates if the data is stored in
binary MODFLOW 6 head file. the file as an array (IMETH=1) or if it is list based
Similarly, the following .methods() syntax shows (IMETH=6). Cell-by-cell specific-discharge data can be
how a user can discover the type of output information extracted using.
that is available for an advanced stress package, such as spdis = gwf.output.budget().get_data
the LAK package.
(totim=1.0, text=’’DATA-SPDIS’’)[0]
> gwf.lak.output.methods()
[’zonebudget()’, ’budget()’, ’bud- Simulated values for specific discharge for each cell
getcsv()’, ’package_convergence()’, are returned as a list containing a NumPy record array
’obs()’, ’stage()’] for the user-specified simulation time (totim=). Like
MODFLOW head data, all of the data in the cell-
The .package_convergence() method can be by-cell data file for a user-specified simulation time
used to get the convergence information for an advanced (totim=), zero-based time step and stress period tuple
(kstpkper=), or zero-based index (idx=) can also be
stress package. The .obs() method can be used extracted. Simulated specific discharge information can
to get observation data saved for a model or stress be processed into a form that can be plotted with FloPy
package as a NumPy record array or pandas data using.
frame. The .stage() method provides access to the qx, qy, qz = flopy.utils.
dependent variable calculated by the LAK package and postprocessing.get_specific_discharge
behaves similarly to the .head() method for the gwf (spdis, gwf, head=head)
model.
The optional argument head= above sets the specific
Processing Simulated Dependent Variables discharge in inactive or dry cells to a value that will not
Simulated output for dependent variables is written be plotted.
by MODFLOW 6 to binary files. Simulated heads and
concentrations written by the GWF and GWT models, Performing Zone Budget Analyses
respectively, can be accessed using the .output method zonebudget() output methods are available for
on the FloPy gwf or gwt objects. To access the both the gwf model and the gwf.lak advanced stress

130 J.D. Hughes et al. Groundwater 62, no. 1: 124–139 NGWA.org


17456584, 2024, 1, Downloaded from https://ngwa.onlinelibrary.wiley.com/doi/10.1111/gwat.13327 by Algeria Hinari NPL, Wiley Online Library on [04/01/2025]. See the Terms and Conditions (https://onlinelibrary.wiley.com/terms-and-conditions) on Wiley Online Library for rules of use; OA articles are governed by the applicable Creative Commons License
package examples shown above because they both solve grids, cross sections can also be specified along a row or
a continuity equation. Other flow and transport advanced column.
stress packages (e.g., SFR, Streamflow Transport (SFT),
Unsaturated Zone Flow (UZF), Unsaturated Zone Trans- fx = flopy.plot.PlotCrossSection
port (UZT), MAW, and Multi-Aquifer Well Transport (model=gwf, line=’’line’’: [(0, 42500),
(MWT)) also solve continuity equations and can be used (186801, 42500)])
with this zone budget functionality. The zonebud- fx.plot_array(head, head=head)
get() output method can be used to perform a zone fx.plot_grid()
budget analysis on the LAK advanced stress package plt.show()
using
> zonbud = gwf.lak.output. The head= keyword option for the plot_array()
zonebudget(zarr) method above causes the plotting routine to draw and
> zonbud.write_input() fill only the saturated part of the model cell (determined
> zonbud.run_model(silent=True) using the simulated head and cell information). Without
(True, [])
the head= keyword option, the entire cell from top to
zarr in the gwf.lak.output.zonebudget() bottom would be color filled based on the head value.
is a NumPy array that defines an integer zone for Figure 3C and 3D shows the outcome of the Python code
each lake or group of lakes in the LAK advanced demonstrated along cross-section lines A–A and B–B
stress package. Zone budget output can be returned (shown in Figure 3A) with additional fine-grained control
as a NumPy record array (.get_budget() or of grid lines, text, annotations, tick locations, and axis
.get_volumetric_budget()) or a pandas labels. Note that the color flood of head in Figure 3C
dataframe (.get_dataframes()). and 3D shows that unconfined conditions occur in higher
elevation cells or cells adjacent to river cells.

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).

NGWA.org J.D. Hughes et al. Groundwater 62, no. 1: 124–139 131


17456584, 2024, 1, Downloaded from https://ngwa.onlinelibrary.wiley.com/doi/10.1111/gwat.13327 by Algeria Hinari NPL, Wiley Online Library on [04/01/2025]. See the Terms and Conditions (https://onlinelibrary.wiley.com/terms-and-conditions) on Wiley Online Library for rules of use; OA articles are governed by the applicable Creative Commons License
Figure 3. Examples of FloPy map and cross-section plotting capabilities for a model discretized using a Voronoi grid
(Figure 1F). (A) Map showing simulated heads and specific-discharge vectors in the upper-most saturated cells. (B) Map
showing the layer containing the water table, the location of cells where the aquifer is discharged to rivers represented as
drain cells, and the location of cells where groundwater is discharging to the land surface (seepage). (C) East–West cross-
section along line A–A , shown in (A), showing the model grid, simulated heads, and cells where water-table conditions exist.
(D) North–South cross-section along line B–B , shown in (A), showing the model grid, simulated heads, and cells where
water-table conditions exist.

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.

132 J.D. Hughes et al. Groundwater 62, no. 1: 124–139 NGWA.org


17456584, 2024, 1, Downloaded from https://ngwa.onlinelibrary.wiley.com/doi/10.1111/gwat.13327 by Algeria Hinari NPL, Wiley Online Library on [04/01/2025]. See the Terms and Conditions (https://onlinelibrary.wiley.com/terms-and-conditions) on Wiley Online Library for rules of use; OA articles are governed by the applicable Creative Commons License
Figure 4. Two different graphical renderings of the Voronoi model grid: (A) staircase representation in which cell have flat
tops and bottoms and (B) smooth representation in which elevations for cell vertices are interpolated using cell top and bottom
elevations. Renderings were created using ParaView (Ahrens et al. 2005) and Visualization Tool Kit (Schroeder et al. 2006)
files exported from FloPy.

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).

NGWA.org J.D. Hughes et al. Groundwater 62, no. 1: 124–139 133


17456584, 2024, 1, Downloaded from https://ngwa.onlinelibrary.wiley.com/doi/10.1111/gwat.13327 by Algeria Hinari NPL, Wiley Online Library on [04/01/2025]. See the Terms and Conditions (https://onlinelibrary.wiley.com/terms-and-conditions) on Wiley Online Library for rules of use; OA articles are governed by the applicable Creative Commons License
To better represent solute transport, the lower aquifer communication,); the top of the model is shown in
has been discretized into three layers (instead of one). Figure 6A. The top of the model and the bottom of layer
Confining units have to be explicitly simulated in 6 were resampled from the data used in the structured
MODFLOW 6, therefore, a total of six layers are grid model using the .resample_to_grid() method
simulated. The bottom of layers 1, 2, 3, and 4 were set to available on the VertexGrid and linear interpolation.
constant values of −1.53, −15.24, −15.55, and −30.48 m, Figure 7 shows the vertical discretization along cross-
respectively. Model layer 3 represents the confining unit section lines A–A and B–B , which are shown in
and is relatively thin (0.3 m). The IDOMAIN concept Figure 6A.
(Langevin et al. 2017) was used to eliminate cells in model Hydraulic properties for the model were resampled
layer 3 (by setting IDOMAIN=-1) where the confining from the data used in the structured grid model that
unit does not exist. In these areas, the thickness of layer 3 was used as the starting point for Hill et al. (1998)
was set to zero and IDOMAIN was set to −1, which marks (D.W.Pollock, personal communication,). The horizontal
these cells in layer 3 as “vertical pass through cells” and hydraulic conductivity was discretized into five zones with
results in cells in layer 2 being directly connected to cells values of 45.72, 50.29, 60.96, 83.82, and 121.92 m/d; the
in layer 4. lowest hydraulic conductivity zone was located south of
The bottom of the model (layer 6) is based on Hill Blue Lake and the highest hydraulic conductivity zone
et al. (1998) and the bottom of layer 5 was specified to was located beneath Blue Lake. The vertical hydraulic
be half the distance between the bottom of layers 4 and 6. conductivity in the upper and lower aquifer was specified
The top of the model was constructed from topographic to be one quarter of the horizontal hydraulic conductivity.
contours developed for the model that was used as the The horizontal and vertical hydraulic conductivity in
starting point for Hill et al. (1998) (D.W.Pollock, personal the confining unit was set equal to 9.14 × 10−4 m/d.

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).

134 J.D. Hughes et al. Groundwater 62, no. 1: 124–139 NGWA.org


17456584, 2024, 1, Downloaded from https://ngwa.onlinelibrary.wiley.com/doi/10.1111/gwat.13327 by Algeria Hinari NPL, Wiley Online Library on [04/01/2025]. See the Terms and Conditions (https://onlinelibrary.wiley.com/terms-and-conditions) on Wiley Online Library for rules of use; OA articles are governed by the applicable Creative Commons License
Straight River are shown in Figure 5B and 5C. The bed
thickness and width of each SFR reach were specified
to be 0.3048 and 3.048 m, respectively. The leakance for
each SFR reach was calculated using the bed thickness,
reach width, and reach length in each cell and based
on a total Straight River conductance of 50,971.72 m2 /d.
A specified rainfall rate of 0.0025 m/d and a potential
evaporation rate of 0.0019 m/d was defined for each
Straight River reach.
Blue Lake was simulated as a lake on top of the model
grid and only had vertical connections to 1406 cells in the
underlying upper aquifer (model layer 1). A bed leakance
of 0.0013 1/d was specified for each cell connected to
Blue Lake. A specified rainfall rate of 0.0025 m/d and a
potential evaporation rate of 0.0019 m/d were defined for
Blue Lake.
Drain (DRN) cells were specified in each cell in
model layer 1 that was not connected to Blue Lake to
prevent water levels from exceeding the top of the model.
The conductance of each DRN cell was based on the
horizontal cell area, a thickness of 0.3048 m, and a vertical
hydraulic conductivity of 0.03048 m/d. Linear scaling of
the drainage conductance was applied to improve model
convergence and ranged from 0 m2 /d when groundwater
levels were greater than or equal to 1 m below the top of
the model to the specified conductance when groundwater
water levels were greater than or equal to the top of the
model.
Uniform recharge and potential evapotranspiration
Figure 7. Cross-section of Synthetic Valley model grid and
simulated steady-state heads along cross-section line (A) rates were specified using the recharge (RCH) and
A–A and (B) B–B . The simulated Blue Lake steady-state evapotranspiration (EVT) packages, respectively, and
stage (3.46 m) and pumping well P-2 are also shown on (A). were equal to the rates specified in the SFR and LAK
packages (0.0025 and 0.0019 m/d). The EVT surface was
specified to be the top of the model and the EVT extinction
The horizontal and vertical hydraulic conductivity were depth was specified to be 1 m.
resampled from the data used in the structured grid The location of pumping wells P1, P2, and P3 was
model using the .resample_to_grid() method on determined using GridIntersect().intersect()
the VertexGrid modelgrid and the nearest neighbor FloPy functionality (Figure 5A). Pumping rates of −7600,
algorithm. −7600, and −1900 m3 /d were specified for pumping wells
For the GWT model, the porosity was set to 0.2 P1, P2, and P3, respectively.
in the upper and lower aquifer and 0.4 for cells in Transport was not simulated in the LAK and SFR
the confining unit. For the transport model, the Total packages. Instead, a specified concentration condition
Variation Diminishing scheme available in the GWT with a concentration of 1.0 mg/L was specified for Blue
model (Langevin et al. 2022) was used to simulate Lake. All other stress packages were assumed to have a
advection. Dispersion was simulated using a longitudinal concentration of 0 mg/L.
dispersivity of 75 m and a transverse dispersivity of 7.5 m. An initial head of 11 m was specified for every cell.
Molecular diffusion was not represented. An initial stage of 3.44 m was specified for Blue Lake.
In the Hill et al. (1998) representation of Syn- An initial concentration of 0 mg/L was specified for every
thetic Valley, the Straight River was simulated as head- cell in the transport model.
dependent river (RIV) package cells, and Blue Lake
was simulated as a high-hydraulic conductivity feature Simulated Results
in model layer 1. In this recreation, Straight River is The GWF model used the Newton–Raphson For-
simulated using the streamflow routing (SFR) package, mulation with Newton under-relaxation to improve
and Blue Lake is simulated using the LAK package. convergence. The GWF and GWT models used the
The SFR and LAK package cells were determined using Bi-conjugate Stabilized (bicgstab) linear accelerator
GridIntersect().intersect() FloPy function- and complexity=‘‘simple’’ settings.
ality (Figure 5A). The GWF and GWT models were run for a total of
Straight River was discretized into 108 SFR reaches. 30 years. The GWF model used a single steady-state time
Cells that intersect the northern and southern end of step and GWF results were used to run the transport model

NGWA.org J.D. Hughes et al. Groundwater 62, no. 1: 124–139 135


Figure 8. Maps showing Synthetic Valley simulated concentrations at the end of 30 years in model layer (A) 1, (B) 2, (C) 3, 17456584, 2024, 1, Downloaded from https://ngwa.onlinelibrary.wiley.com/doi/10.1111/gwat.13327 by Algeria Hinari NPL, Wiley Online Library on [04/01/2025]. See the Terms and Conditions (https://onlinelibrary.wiley.com/terms-and-conditions) on Wiley Online Library for rules of use; OA articles are governed by the applicable Creative Commons License
(D) 4, (E) 5, and (F) 6. The extent of the confining unit in model layer 3 is also shown on (C).

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.

136 J.D. Hughes et al. Groundwater 62, no. 1: 124–139 NGWA.org


17456584, 2024, 1, Downloaded from https://ngwa.onlinelibrary.wiley.com/doi/10.1111/gwat.13327 by Algeria Hinari NPL, Wiley Online Library on [04/01/2025]. See the Terms and Conditions (https://onlinelibrary.wiley.com/terms-and-conditions) on Wiley Online Library for rules of use; OA articles are governed by the applicable Creative Commons License
Summary and Conclusions The robust new features in FloPy allow users to
FloPy is a Python package for building, running, and quickly try different model grids, different model
post-processing groundwater models. It is open source spatial and temporal resolution, and different model
and developed with input from a growing community configurations.
of contributors. This paper summarizes new FloPy The ability to script groundwater model construc-
capabilities that have been added since the package was tion and post-processing increases robustness, ensures
first described by Bakker et al. (2016). The new and reproducibility, provides a record of the data processing
updated capabilities can be summarized as follows. and model construction steps, and provides a means to
improve the model and extend the simulation period as
• FloPy supports the creation of many different types new data become available. The new geospatial process-
of groundwater models, including models that use ing routines make it possible to change model resolution
MODFLOW 6, MODFLOW-2005, MODFLOW-NWT, as part of the model construction script. This allows one
MODFLOW-USG, MT3D, MT3D-USGS, and SEA- to prototype fast-running models with coarse resolution
WAT. FloPy support for MODFLOW 6 is based on an and use finer resolution as the model starts to behave as
entirely new approach designed to automatically sup- intended. This workflow also allows one to conduct grid
port all MODFLOW 6 models, packages, and options. convergence studies to ensure that the grid is not the cause
The underlying FloPy classes for MODFLOW 6 are of unintended model behavior.
programmatically generated from the same input defi- FloPy is open source and we welcome bug reports,
nition files that are used to construct the MODFLOW 6 code contributions, or improvements to the documentation
user guide. This correspondence ensures that the FloPy from the community. The FloPy Python package can be
classes are consistent and in-sync with MODFLOW 6 installed using the conda or pip package managers. The
input. source code, code documentation, tutorials, and examples
• FloPy has been extended to support unstructured can be found in the FloPy GitHub repository. The
model grids in addition to structured grids defined Synthetic Valley example is available as a MODFLOW 6
by layers, rows, and columns. FloPy has several example and the hypothetical watershed grid examples are
different routines for creating unstructured grids. FloPy available on the FloPy GitHub repository.
includes a wrapper for the GRIDGEN program (Lien
et al. 2014), which can be used to create layered
quadtree grids. FloPy also includes a wrapper for the Acknowledgments
Triangle program (Shewchuk 1996), which can be The authors gratefully acknowledge the efforts of
used to create triangular meshes. A triangular mesh Mark Bakker and Vincent E.A. Post for initially devel-
can be converted by FloPy into a Voronoi grid. Grid oping FloPy and their continued efforts improving FloPy.
information is stored for each FloPy model created by Funding for this research was provided by the Enterprise
the user. This model grid object is used systemically Capacity project of the U.S. Geological Survey Integrated
throughout FloPy for geospatial operations, plotting, Water Prediction program.
and exporting model information to supported formats.
• Geospatial intersections of points, lines, and polygons
with model grids and raster resampling onto model grids Authors’ Note
are common steps in model construction. FloPy fully The authors do not have any conflicts of interest to
supports these geospatial operations through its grid report.
intersection and raster resampling routines.
• Access to model output using FloPy has been simplified
for MODFLOW 6 models. The new output access Disclaimer
routines makes it possible to quickly extract simulated Any use of trade, firm, or product names is for
results from binary and text model output files. descriptive purposes only and does not imply endorsement
• FloPy supports plan-view map and cross-section plot- by the U.S. Government.
ting of model grids, boundary conditions, and simulated
results. These plotting routines work with structured and
unstructured models and can be customized to produce References
high-quality figures. Ahrens, J., B. Geveci, and C. Law. 2005. ParaView: An end-
• user tool for large data visualization. In C.D. Hansen and
FloPy supports the export of model information to
C.R. Johnson (Eds.) Visualization Handbook , Chapter 36,
shapefiles, VTK files, and NetCDF files. These exported Burlington, MA: Elsevier. 717–731. https://doi.org.10.1016
files can then be loaded into other software programs, /B978-012387582/50038-1
such as geographic information systems or advanced Australian Water School. 2023. On-demand: MODFLOW
visualization programs for additional processing. 6 and FloPy. https://awschool.com.au/training/modflow6
-flopy/ (accessed April 13, 2023).
Bakker, M., V. Post, C.D. Langevin, J.D. Hughes, J. White,
FloPy makes it possible to construct, and reproduce J. Starn, and M.N. Fienen. 2016. Scripting MODFLOW
the construction, of a groundwater model from data model development using Python and FloPy. Groundwater
in any format that can be accessed using Python. 54, no. 5: 733–739. https://doi.org/10.1111/gwat.12413

NGWA.org J.D. Hughes et al. Groundwater 62, no. 1: 124–139 137


17456584, 2024, 1, Downloaded from https://ngwa.onlinelibrary.wiley.com/doi/10.1111/gwat.13327 by Algeria Hinari NPL, Wiley Online Library on [04/01/2025]. See the Terms and Conditions (https://onlinelibrary.wiley.com/terms-and-conditions) on Wiley Online Library for rules of use; OA articles are governed by the applicable Creative Commons License
Befus, K.M., P.L. Barnard, D.J. Hoover, J.A. Finzi Hart, and and Subsidence (CSUB) Package of MODFLOW 6. U.S.
C.I. Voss. 2020. Increasing threat of coastal groundwa- Geological Survey Techniques and Methods, book 6, chap.
ter hazards from sea-level rise in California. Nature Cli- A62, 57 p. https://doi.org/10.3133/tm6A62.
mate Change 10, no. 10: 946–952. https://doi.org/10.1038 Hughes, J.D., C.D. Langevin, and E.R. Banta. 2017. Documen-
/s41558-020-0874-1 tation for the MODFLOW 6 framework. U.S. Geological
Befus, K.M., K.D. Kroeger, C.G. Smith, and P.W. Swarzenski. Survey Techniques and Methods, book 6, chap. A57, 36 p.
2017. The magnitude and origin of groundwater discharge https://doi.org/10.3133/tm6A57.
to eastern U.S. and Gulf of Mexico coastal waters. Hunter, J.D. 2007. Matplotlib: A 2D graphics environment.
Geophysical Research Letters 44, no. 20: 10396–10406. Computing in Science & Engineering 9, no. 3: 90–95.
https://doi.org/10.1002/2017GL075238 Jaxa-Rozen, M., J.H. Kwakkel, and M. Bloemendal.
Burek, P., Y. Satoh, T. Kahil, T. Tang, P. Greve, M. Smilovic, 2019. A coupled simulation architecture for agent-
L. Guillaumot, F. Zhao, and Y. Wada. 2020. Development based/geohydrological modelling with NetLogo and
of the Community Water Model (CWatM v1.04) – A MODFLOW. Environmental Modelling & Software 115:
high-resolution hydrological model for global and regional 19–37. https://doi.org/10.1016/j.envsoft.2019.01.020
assessment of integrated water resources management. Kluyver, T., B. Ragan-Kelley, F. Pérez, B. Granger, M. Bus-
Geoscientific Model Development 13, no. 7: 3267–3298. sonnier, J. Frederic, K. Kelley, J. Hamrick, J. Grout,
https://doi.org/10.5194/gmd-13-3267-2020 S. Corlay, P. Ivanov, D. Avila, S. Abdalla, and C. Will-
Ebeling, P., F. Handel, and M. Walther. 2019. Potential of mixed ing. 2016. Jupyter notebooks – A publishing format
hydraulic barriers to remediate seawater intrusion. Science for reproducible computational workflows. In Positioning
of the Total Environment 693: 133478. https://doi.org/10 and Power in Academic Publishing: Players, Agents and
.1016/j.scitotenv.2019.07.284 Agendas, ed. F. Loizides, and B. Schmidt, 87–90.
van Engelen, J., G.H. Oude Essink, H. Kooi, and M.F. Bierkens. Amsterdam, Netherlands: IOS Press. https://doi.org/10
2018. On the origins of hypersaline groundwater in the Nile .3233/978-1-61499-649-1-87
Delta aquifer. Journal of Hydrology 560: 301–317. https:/ Knowling, M.J., J.T. White, and C.R. Moore. 2019. Role of
/doi.org/10.1016/j.jhydrol.2018.03.029 model parameterization in risk-based decision support: An
Esri. 1998. Esri Shapefile Technical Description, an ESRI empirical exploration. Advances in Water Resources 128:
white paper. http://www.esri.com/library/whitepapers/pdfs 59–73. https://doi.org/10.1016/j.advwatres.2019.04.010
/shapefile.pdf (accessed August 29, 2022). Langevin, C.D., A.M. Provost, S. Panday, and J.D. Hughes.
Essawy, B.T., J.L. Goodall, W. Zell, D. Voce, M.M. Morsy, 2022. Documentation for the MODFLOW 6 Groundwater
J. Sadler, Z. Yuan, and T. Malik. 2018. Integrating Transport (GWT) Model. U.S. Geological Survey Tech-
scientific cyberinfrastructures to improve reproducibility niques and Methods, book 6, chap. A61, 56 p. https://doi
in computational hydrology: Example for HydroShare .org/10.3133/tm6A55.
and GeoTrust. Environmental Modelling & Software 105:
Langevin, C.D., S. Panday, and A.M. Provost. 2020. Hydraulic-
217–229. https://doi.org/10.1016/j.envsoft.2018.03.025
head formulation for density-dependent flow and transport.
Fienen, M.N., N.T. Corson-Dosch, J.T. White, A.T. Leaf, and
Groundwater 58, no. 3: 349–362.
R.J. Hunt. 2022a. Risk-based wellhead protection decision
Langevin, C.D., J.D. Hughes, A.M. Provost, E.R. Banta, R.G.
support: A repeatable workflow approach. Groundwater 60,
Niswonger, and S. Panday. 2017. Documentation for the
no. 1: 71–86. https://doi.org/10.3389/feart.2022.903965
MODFLOW 6 Groundwater Flow (GWF) Model. U.S.
Fienen, M.N., M.J. Haserodt, A.T. Leaf, and S.M. Westen-
broek. 2022b. Simulation of regional groundwater flow and Geological Survey Techniques and Methods, book 6, chap.
groundwater/lake interactions in the Central Sands, Wiscon- A55, 197 p. https://doi.org/10.3133/tm6A55.
sin. U.S. Geological Survey Scientific Investigations Report Larsen, J.D., A.H. Alzraiee, D. Martin, and R.G. Niswonger.
2022-5046, 111. https://doi.org/10.3133/sir20225046. 2022. Rapid model development for GSFLOW with python
Fienen, M.N., and M. Bakker. 2016. HESS opinions: Repeatable and pyGSFLOW. Frontiers in Earth Science 10: 907533.
research: What hydrologists can learn from the Duke cancer https://doi.org/10.3389/feart.2022.907533
research scandal. Hydrology and Earth System Sciences 20, Leaf, A.T., and M.N. Fienen. 2022. Modflow-setup: Robust
no. 9: 3739–3743. https://doi.org/10.5194/hess-20-3739 automation of groundwater model construction. Frontiers
-2016 in Earth Science 10: 903965. https://doi.org/10.3389/feart
Gillies, S. 2022. The shapely user manual. https://shapely .2022.903965
.readthedocs.io/en/stable/manual.html (accessed August 28, Lien, J.M., G. Liu, and C.D. Langevin. 2014. GRIDGEN Version
2022). 1.0: A computer program for generating unstructured finite-
Gillies, S. 2023. rasterio Documentation. https://github.com volume grids. U.S. Geological Survey Open-File Report
/rasterio/rasterio (accessed June 1, 2023). 2014-1109, 26 p. https://doi.org/10.3133/ofr20141109.
Guira, M. 2018. Numerical modeling of the effects of land Mancewicz, L.K., A. Mayer, C.D. Langevin, and J. Gulley. 2022.
use change and irrigation on streamflow depletion of Improved method for simulating groundwater inundation
Frenchman Creek, Nebraska. Master’s thesis, University of using the MODFLOW 6 Lake transport package. Ground-
Nebraska, Lincoln, NE. water 61: 421–430. https://doi.org/10.1111/gwat.13254
Hatari Labs. 2023. Regional Groundwater Modeling with Mehl, S.W., and M.C. Hill. 2013. MODFLOW-
MODFLOW and Flopy – Tutorial. https://hatarilabs.com LGR—Documentation of ghost node local grid refinement
/ih-en/regional-groundwater-modeling-with-modflow-and (LGR2) for multiple areas and the boundary flow and head
-flopy-tutorial (accessed April 13, 2023). (BFH2) package. U.S. Geological Survey Techniques and
Hill, M.C. 1992. A computer program (MODFLOWP) for Methods, book 6, chap. A44, 43 p. https://doi.org/10.3133
estimating parameters of a transient, three-dimensional, /tm6A44.
ground-water flow model using nonlinear regression. Mehl, S.W., and M.C. Hill. 2006. MODFLOW-2005, the
U.S. Geological Survey Open-File Report 91-484: 358. U.S. Geological Survey modular ground-water model-
Hill, M.C., R.L. Cooley, and D.W. Pollock. 1998. A con- documentation of shared node local grid refinement (LGR)
trolled experiment in ground water flow model calibration. and the boundary flow and head (BFH) package. U.S.
Groundwater 36, no. 3: 520–535. https://doi.org/10.1111/j Geological Survey Techniques and Methods, book 6, chap.
.1745-6584.1998.tb02824.x A12, 78 p. https://doi.org/10.3133/tm6A12.
Hughes, J.D., S.A. Leake, D.L. Galloway, and J.W. White. Morway, E.D., C.D. Langevin, and J.D. Hughes. 2021. Use of
2022. Documentation for the Skeletal Storage, Compaction, the MODFLOW 6 water mover package to represent natural

138 J.D. Hughes et al. Groundwater 62, no. 1: 124–139 NGWA.org


17456584, 2024, 1, Downloaded from https://ngwa.onlinelibrary.wiley.com/doi/10.1111/gwat.13327 by Algeria Hinari NPL, Wiley Online Library on [04/01/2025]. See the Terms and Conditions (https://onlinelibrary.wiley.com/terms-and-conditions) on Wiley Online Library for rules of use; OA articles are governed by the applicable Creative Commons License
and managed hydrologic connections. Groundwater 59, no. Geophysical Research Letters 45, no. 20: 11137–11146.
6: 913–924. https://doi.org/10.1111/gwat.13117 https://doi.org/10.1029/2018GL080404
Panday, S., C.D. Langevin, R.G. Niswonger, M. Ibaraki, and J.D. U.S. Geological Survey. 2018. GWWebFlow–a browser-based
Hughes. 2013. MODFLOW-USG version 1—An unstruc- groundwater model viewer. https://webapps.usgs.gov
tured grid version of MODFLOW for simulating ground- /gwwebflow/.
water flow and tightly coupled processes using a control Vilhelmsen, T.N., S. Christensen, and S.W. Mehl. 2012.
volume finite-difference formulation. U.S. Geological Sur- Evaluation of MODFLOW-LGR in connection with
vey Techniques and Methods, book 6, chap. A45, 66 p. a synthetic regional-scale model. Groundwater 50,
Perry, M. 2013. Rasterstats python library. https://github.com no. 1: 118–132. https://doi.org/10.1111/j.1745-6584.2011
/perrygeo/python-rasterstats (accessed April 13, 2023). .00826.x
Provost, A.M., C.D. Langevin, and J.D. Hughes. 2017. Docu- Virtanen, P., R. Gommers, T.E. Oliphant, M. Haberland,
mentation for the “XT3D” Option in the Node Property T. Reddy, D. Cournapeau, E. Burovski, P. Peterson,
Flow (NPF) Package of MODFLOW 6. U.S. Geological W. Weckesser, J. Bright, S.J. van der Walt, M. Brett,
Survey Techniques and Methods, book 6, chap. A56, 46 p. J. Wilson, K.J. Millman, N. Mayorov, A.R.J. Nelson,
https://doi.org/10.3133/tm6A56. E. Jones, R. Kern, E. Larson, C.J. Carey, İ. Polat, Y. Feng,
Rew, R., E. Hartnett, J. Caron, et al. 2006. NetCDF-4: Soft- E.W. Moore, J. VanderPlas, D. Laxalde, J. Perktold,
ware implementing an enhanced data model for the geo- R. Cimrman, I. Henriksen, E.A. Quintero, C.R. Harris, A.M.
sciences. In 22nd International Conference on Interactive Archibald, A.H. Ribeiro, F. Pedregosa, P. van Mulbregt,
Information Processing Systems for Meteorology, Oceano- and SciPy 1.0 Contributors. 2020. SciPy 1.0: Fundamental
graph, and Hydrology, Volume 6. algorithms for scientific computing in python. Nature
Rew, R., and G. Davis. 1990. NetCDF: An interface for scientific Methods 17: 261–272. https://doi.org/10.1038/s41592-019
data access. IEEE Computer Graphics and Applications 10, -0686-2
no. 4: 76–82. White, J.T. 2018. A model-independent iterative ensemble
Rossetto, R., G. De Filippis, I. Borsi, L. Foglia, M. Cannata, smoother for efficient history-matching and uncertainty
R. Criollo, and E. Vázquez-Suñé. 2018. Integrating free quantification in very high dimensions. Environmental
and open source tools and distributed modelling codes in Modelling & Software 109: 191–201. https://doi.org/10
GIS environment for data-based groundwater management. .1016/j.envsoft.2018.06.009
Environmental Modelling & Software 107: 210–230. https: White, J.T., L.K. Foster, M.N. Fienen, M.J. Knowling, B. Hem-
//doi.org/10.1016/j.envsoft.2018.06.007 mings, and J.R. Winterle. 2020. Toward reproducible
Schroeder, W., K. Martin, and B. Lorensen. 2006. The environmental modeling for decision support: A worked
Visualization Toolkit, 4th ed. Cliftton, NY: Kitware. example. Frontiers in Earth Science 8: 50. https://doi.org
Shewchuk, J.R. 1996. Triangle: Engineering a 2D quality /10.3389/feart.2020.00050
mesh generator and Delaunay triangulator. In Applied Zhou, Z., and D.M. Tartakovsky. 2021. Markov chain Monte
Computational Geometry, Towards Geometric Engineering, Carlo with neural network surrogates: Application to
FCRC’96 Workshop, WACG’96, Philadelphia, PA, USA, contaminant source identification. Stochastic Environmental
May 27–28, 1996, Selected Papers, 203–222. https://doi Research and Risk Assessment 35, no. 10: 639–651. https:
.org/10.1007/BFb0014497. //doi.org/10.1007/s00477-020-01888-9
Starn, J.J., and K. Belitz. 2018. Regionalization of groundwa- Zipper, S.C., T. Gleeson, B. Kerr, J.K. Howard, M.M. Rohde,
ter residence time using metamodeling. Water Resources J. Carah, and J. Zimmerman. 2019. Rapid and accurate
Research 54, no. 9: 6357–6373. https://doi.org/10.1029 estimates of streamflow depletion caused by groundwa-
/2017WR021531 ter pumping using analytical depletion functions. Water
Sun, A.Y. 2018. Discovering state-parameter mappings in Resources Research 55, no. 7: 5807–5829. https://doi.org
subsurface models using generative adversarial networks. /10.1029/2018WR024403

NGWA.org J.D. Hughes et al. Groundwater 62, no. 1: 124–139 139

You might also like