Swiftpack.co - Package - modflowpy/flopy

Version 3.2.9 develop — build 216

Build Status PyPI Version Coverage Status


FloPy includes support for MODFLOW 6, MODFLOW-2005, MODFLOW-NWT, MODFLOW-USG, and MODFLOW-2000. Other supported MODFLOW-based models include MODPATH (version 6 and ***7 (beta)***), MT3DMS, MT3D-USGS, and SEAWAT.

For general modeling issues, please consult a modeling forum, such as the MODFLOW Users Group. Other MODFLOW resources are listed in the MODFLOW Resources section.


Bug reports, code contributions, or improvements to the documentation are welcome from the community. Prior to contributing, please read up on our guidelines for contributing and then check out one of our issues in the hotlist: community-help.


FloPy code documentation is available at http://modflowpy.github.io/flopydoc/

Getting Started

Frequently asked questions


Additional jupyter Notebook Examples

Python Script Examples

If You Get Stuck

FloPy usage has been growing rapidly, and as the number of users has increased, so has the number of questions about how to use FloPy. We ask our users to carefully consider the nature of their problem and seek help in the appropriate manner.


For questions related to how to do something with FloPy, we ask our users to submit the question to Stack Overflow and assign the flopy tag. Many of our recent questions have been related to MODFLOW or Python, and the Flopy developers cannot always respond to these inquiries.


If you think you have discovered a bug in FloPy in which you feel that the program does not work as intended, then we ask you to submit a Github issue.

FloPy Supported Packages

A list of supported packages in FloPy is available in docs/supported_packages.md on the github repo.

FloPy Model Checks

A table of the supported and proposed model checks implemented in FloPy is available in docs/model_checks.md on the github repo.

FloPy Changes

A summary of changes in each FloPy version is available in docs/version_changes.md on the github repo.


Python versions:

FloPy requires Python 2.7 or Python 3.3 (or higher)


FloPy requires NumPy 1.9 (or higher) and enum34 for Python 2.7 or Python 3.3.

For base and Anaconda Python distributions:

To install FloPy type:

pip install flopy


conda install -c conda-forge flopy

To update FloPy type:

pip install flopy --upgrade


conda update flopy

To uninstall FloPy type:

pip uninstall flopy


conda uninstall flopy

Installing from the git repository:

Current Version of FloPy:

To install the current version of FloPy from the git repository type:

pip install https://github.com/modflowpy/flopy/zipball/master

To update your version of FloPy with the current version from the git repository type:

pip install https://github.com/modflowpy/flopy/zipball/master --upgrade

Development version of FloPy:

To install the bleeding edge version of FloPy from the git repository type:

pip install https://github.com/modflowpy/flopy/zipball/develop

To update your version of FloPy with the bleeding edge code from the git repository type:

pip install https://github.com/modflowpy/flopy/zipball/develop --upgrade

Optional Method Dependencies:

Additional dependencies to use optional FloPy helper methods are listed below.

| Method | Python Package | | ------------------------------------------------------------------------------------ | -------------------------------------------------- | | .plot() | matplotlib >= 1.4 | | .plot_shapefile() | matplotlib >= 1.4 and Pyshp >= 1.2 | | .to_shapefile() | Pyshp >= 1.2 | | .export(*.shp) | Pyshp >= 1.2 | | .export(*.nc) | netcdf4 >= 1.1 and python-dateutil >= 2.4 | | .export(*.tif) | rasterio | | .export(*.asc) in flopy.utils.reference SpatialReference class | scipy.ndimage | | .interpolate() in flopy.utils.reference SpatialReference class | scipy.interpolate | | .interpolate() in flopy.mf6.utils.reference StructuredSpatialReference class | scipy.interpolate | | .get_dataframes() in flopy.utils.mflistfile ListBudget class | pandas >= 0.15 | | .get_dataframes() in flopy.utils.observationfile ObsFiles class | pandas >= 0.15 | | .get_dataframes() in flopy.utils.sfroutputfile ModflowSfr2 class | pandas >= 0.15 | | .get_dataframes() in flopy.utils.util_list MfList class | pandas >= 0.15 | | .get_dataframes() in flopy.utils.zonebud ZoneBudget class | pandas >= 0.15 | | .pivot_keyarray() in flopy.mf6.utils.arrayutils AdvancedPackageUtil class | pandas >= 0.15 | | ._get_vertices() in flopy.mf6.utils.binaryfile_utils MFOutputRequester class | pandas >= 0.15 | | .get_dataframe() in flopy.mf6.utils.mfobservation Observations class | pandas >= 0.15 | | .df() in flopy.modflow.mfsfr2 SfrFile class | pandas >= 0.15 | | .time_coverage() in flopy.export.metadata acc class - used if available | pandas >= 0.15 | | .loadtxt() in flopy.utils.flopyio - used if available | pandas >= 0.15 |

How to Cite

Citation for FloPy:

Bakker, M., Post, V., Langevin, C. D., Hughes, J. D., White, J. T., Starn, J. J. and Fienen, M. N., 2016, Scripting MODFLOW Model Development Using Python and FloPy: Groundwater, v. 54, p. 733–739, doi:10.1111/gwat.12413.

Software/Code citation for FloPy:

Bakker, M., Post, V., Langevin, C.D., Hughes, J.D., White, J.T., Starn, J.J., and Fienen, M.N., 2018, FloPy v3.2.9 — develop: U.S. Geological Survey Software Release, 17 October 2018, http://dx.doi.org/10.5066/F7BK19FH

MODFLOW Resources


This software is preliminary or provisional and is subject to revision. It is being provided to meet the need for timely best science. The software has not received final approval by the U.S. Geological Survey (USGS). No warranty, expressed or implied, is made by the USGS or the U.S. Government as to the functionality of the software and related material nor shall the fact of release constitute any such warranty. The software is provided on the condition that neither the USGS nor the U.S. Government shall be held liable for any damages resulting from the authorized or unauthorized use of the software.


Stars: 125
Help us keep the lights on


Used By

Total: 0


3.2.9 - Feb 19, 2018

  • Modified MODFLOW 5 OC stress_period_data=None default behaviour. If MODFLOW 5 OC stress_period_data is not provided then binary head output is saved for the last time step of each stress period.

  • added multiple component support to mt3dusgs SFT module

  • Optimized loading and saving of MODFLOW 6 files

  • MODFLOW 6 identifiers are now zero based

  • Added remove_package method in MFSimulation and MFModel that removes MODFLOW 6 packages from the existing simulation/model

  • Changed some of the input argument names for MODFLOW 6 classes. Note that this will break some existing user scripts. For example, the stress period information was passed to the boundary package classes using the periodrecarray argument. The argument is now called stress_period_data in order to be consistent with other Flopy functionality.

  • Flopy code for MODFLOW 6 generalized to support different model types

  • Flopy code for some MODFLOW 6 arguments now have default values in order to be consistent with other Flopy functionality

  • Added ModflowSfr2.export_transient_variable method to export shapefiles of segment data variables, with stress period data as attributes

  • Added support for UZF package gages

  • Bug fixes:

    • Fixed issue with default settings for MODFLOW 5 SUB package dp dataset.
    • Fixed issue if an external BC list file has only one entry
    • Some patching for recarray issues with latest numpy release (there are more of these lurking...)
    • Fixed setting model relative path for MODFLOW 6 simulations
    • Python 2.7 compatibility issues fixed for MODFLOW 6 simulations
    • IMS file name conflicts now automatically resolved
    • Fixed issue with passing in numpy ndarrays arrays as layered data
    • Doc string formatting for MODFLOW 6 packages fixed to make doc strings easier to read
    • UZF package: fixed issues with handling of finf, pet, extdp and extwc arrays.
    • SFR package: fixed issue with reading stress period data where not all segments are listed for periods > 0.
    • SpatialReference.write_gridSpec was not converting the model origin coordinates to model length units.
    • shorted integer field lengths written to shapefiles to 18 characters; some readers may misinterpret longer field lengths as float dtypes.

3.2.8 - Dec 18, 2017

  • Added has_package(name) method to see if a package exists. This feature goes nicely with get_package(name) method.
  • Added set_model_units() method to change model units for all files created by a model. This method can be useful when creating MODFLOW-LGR models from scratch.
  • Bug fixes:
    • Installation: Added dfn files required by MODFLOW 6 functionality to MANIFEST.in so that they are included in the distribution.
    • SFR2 package: Fixed issue reading transient data when ISFOPT is 4 or 5 for the first stress period.

3.2.7 - Dec 1, 2017

  • Added beta support for MODFLOW 6 See here for more information.
  • Added support for retrieving time series from binary cell-by-cell files. Cell-by-cell time series are accessed in the same way they are accessed for heads and concentrations but a text string is required.
  • Added support for FORTRAN free format array data using n*value where n is the number of times value is repeated.
  • Added support for comma separators in 1D data in LPF and UPF files
  • Added support for comma separators on non array data lines in DIS, BCF, LPF, UPW, HFB, and RCH Packages.
  • Added .reset_budgetunit() method to OC package to faciltate saving cell-by-cell binary output to a single file for all packages that can save cell-by-cell output.
  • Added a .get_residual() method to the CellBudgetFile class.
  • Added support for binary stress period files (OPEN/CLOSE filename (BINARY)) in wel stress packages on load and instantiation. Will extend to other list-based MODFLOW stress packages.
  • Added a new flopy.utils.HeadUFile Class (located in binaryfile.py) for reading unstructured head files from MODFLOW-USG. The .get_data() method for this class returns a list of one-dimensional head arrays for each layer.
  • Added metadata.acdd class to fetch model metadata from ScienceBase.gov and manage CF/ACDD-complient metadata for NetCDF export
  • Added sparse export option for boundary condition stress period data, where only cells for that B.C. are exported (for example, package.stress_period_data.export('stuff.shp', sparse=True))
  • Added additional SFR2 package functionality:
    • .export_linkages() and .export_outlets() methods to export routing linkages and outlets
    • sparse shapefile export, where only cells with SFR reaches are included
    • .plot_path() method to plot streambed elevation profile along sequence of segments
    • .assign_layers() method
    • additional error checks and bug fixes
  • Added SpatialReference / GIS export functionality:
    • GeoTiff export option to SpatialReference.export_array
    • SpatialReference.export_array_contours: contours an array and then exports contours to shapefile
    • inverse option added to SpatialReference.transform
    • automatic reading of spatial reference info from .nam or usgs.model.reference files
  • Modified node numbers in SFR package and ModflowDis.get_node() from one- to zero-based.
  • Modified HYDMOD package klay variable from one- to zero-based.
  • Added .get_layer() method to DIS package.
  • Added .get_saturated_thickness() and .get_gradients() methods
  • Bug fixes:
    • OC package: Fixed bug when printing and saving data for select stress periods and timesteps. In previous versions, OC data was repeated until respecified.
    • SUB package: Fixed bug if data set 15 is passed to preserved unit numbers (i.e., use unit numbers passed on load).
    • SUB and SUB-WT packages: Fixed bugs .load() to pop original unit number.
    • BTN package: Fixed bug in obs.
    • LPF package: Fixed bug regarding when HANI is read and written.
    • UZF package: added support for MODFLOW NWT options block; fixed issue with loading files with thti/thtr options
    • SFR package: fixed bug with segment renumbering, issues with reading transient text file output,
    • Fixed issues with dynamic setting of SpatialReference parameters
    • NWT package: forgive missing value for MXITERXMD
    • MNW2 package: fix bug where ztop and zbotm were written incorrectly in get_allnode_data(). This was not affecting writing of these variables, only their values in this summary array.
    • PCGN package: fixed bug writing package.
    • Fixed issue in Util2d when non-integer cnstnt passed.

3.2.6 - Mar 19, 2017

  • Added functionality to read binary grd file for unstructured grids.

  • Additions to SpatialReference class:

    • xll, yll input option
    • transform method to convert model coordinates to real-world coordinates
    • epsg and length_multiplier arguments
  • Export:

    • Added writing of prj files to shapefile export; prj information can be passed through spatial reference class, or given as an EPSG code or existing prj file path
    • Added NetCDF export to MNW2
  • Added MODFLOW support for:

    • FHB Package - no support for flow or head auxiliary variables (datasets 2, 3, 6, and 8)
    • HOB Package
  • New utilities:

    • flopy.utils.get_transmissivities() Computes transmissivity in each model layer at specified locations and open intervals. A saturated thickness is determined for each row, column or x, y location supplied, based on the well open interval (sctop, scbot), if supplied, otherwise the layer tops and bottoms and the water table are used.
  • Added MODFLOW-LGR support - no support for model name files in different directories than the directory with the lgr control file.

  • Additions to MODPATH:

    • shapefile export of MODPATH Pathline and Endpoint data
    • Modpath.create_mpsim() supports MNW2
    • creation of MODPATH StartingLocations files
    • Easy subsetting of endpoint and pathline results to destination cells of interest
  • New ZoneBudget class provides ZONEBUDGET functionality:

    • reads a CellBudgetFile and accumulates flows by zone
    • pass kstpkper or totim keyword arguments to retrieve a subset of available times in the CellBudgetFile
    • includes a method to write the budget recarrays to a .csv file
    • ZoneBudget objects support numerical operators to facilitate conversion of units
    • utilities are included which read/write ZONEBUDGET-style zone files to and from numpy arrays
    • pass a dictionary of {zone: "alias"} to rename fields to more descriptive names (e.g. {1: 'New York', 2: 'Delmarva'}
  • Added new precision='auto' option to flopy.utils.binaryfile for HeadFile and UcnFile readers. This will automatically try and determine the float precision for head files created by single and double precision versions of MODFLOW. 'auto' is now the default. Not implemented yet for cell by cell flow file.

  • Modified MT3D-related packages to also support MT3D-USGS

    • BTN will support the use of keywords (e.g., 'MODFLOWStyleArrays', etc.) on the first line
    • DSP will support the use of keyword NOCROSS
    • Keyword FREE now added to MT3D name file when the flow-transport link (FTL) file is formatted. Previously defaulted to unformatted only.
  • Added 3 new packages:

    • SFT: Streamflow Transport, companion transport package for use with the SFR2 package in MODFLOW
    • LKT: Lake Transport, companion transport package for use with the LAK3 package in MODFLOW
    • UZT: Unsaturated-zone Transport, companion transport package for use with the UZF1 package in MODFLOW
  • Modified LMT

    • load() functionality will now support optional PACKAGE_FLOWS line (last line of LMT input)
    • write_file() will will now insert PACKAGE_FLOWS line based on user input
  • Bug fixes:

    1. Fixed bug in parsenamefile when file path in namefile is surrounded with quotes.
    2. Fixed bug in check routine when THICKSTRT is specified as an option in the LPF and UPW packages.
    3. Fixed bug in BinaryHeader.set_values method that prevented setting of entries based on passed kwargs.
    4. Fixed bugs in reading and writing SEAWAT Viscosity package.
    5. The DENSE and VISC arrays are now Transient3d objects, so they may change by stress period.
    6. MNW2: fixed bug with k, i, j node input option and issues with loading at model level
    7. Fixed bug in ModflowDis.get_cell_volumes().

3.2.5 - Jun 27, 2016

Version 3.2.5

  • Added support for LAK and GAGE packages - full load and write functionality supported.
  • Added support for MNW2 package. Load and write of .mnw2 package files supported. Support for .mnwi, or the results files (.qsu, .byn) not yet implemented.
  • Improved support for changing the output format of arrays and variables written to MODFLOW input files.
  • Restructued SEAWAT support so that packages can be added directly to the SEAWAT model, in addition to the approach of adding a modflow model and a mt3d model. Can now load a SEAWAT model.
  • Added load support for MT3DMS Reactions package
  • Added multi-species support for MT3DMS Reactions package
  • Added static method to Mt3dms().load_mas that reads an MT3D mass file and returns a recarray
  • Added static method to Mt3dms().load_obs that reads an MT3D mass file and returns a recarray
  • Added method to flopy.modpath.Modpath to create modpath simulation file from modflow model instance boundary conditions. Also added examples of creating modpath files and post-processing modpath pathline and endpoint files to the flopy3_MapExample notebook.
  • Bug fixes:
    1. Fixed issue with VK parameters for LPF and UPW packages.
    2. Fixed issue with MT3D ADV load in cases where empty fields were present in the first line of the file.
    3. Fixed cross-section array plotting issues.
    4. BTN observation locations must now be entered in zero-based indices (a 1 is now added to the index values written to btn file)
    5. Uploaded supporting files for SFR example notebook; fixed issue with segment_data submitted as array (instead of dict) and as 0d array(s).
    6. Fixed CHD Package so that it now supports options, and therefore, auxiliary variables can be specified.
    7. Fixed loading BTN save times when numbers are touching.