Swiftpack.co - Package - modflowpy/flopy

Version 3.2.8 develop — build 39

Build Status PyPI Version Coverage Status


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

FloPy now includes beta support for MODFLOW 6. Click here for more information.

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.

If you think you have found a bug in FloPy, or if you would like to suggest an improvement or enhancement, please submit a new issue through the Github Issue tracker. Pull requests will only be accepted on the develop branch of the repository.


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

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.8 — develop: U.S. Geological Survey Software Release, 12 January 2018, http://dx.doi.org/10.5066/F7BK19FH


jupyter Notebook Examples

Python Script Examples



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.

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 |

For base Python distributions:

To install FloPy type:

pip install flopy

To update FloPy type:

pip install flopy --upgrade

To uninstall FloPy type:

pip 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

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.

MODFLOW Resources


Stars: 101
Help us keep the lights on


Used By

Total: 0


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.

3.2.4 - Feb 6, 2016

Version 3.2.4

  • Added basic model checking functionality (.check()).
  • Added support for reading SWR Process observation, stage, budget, flow, reach-aquifer exchanges, and structure flows.
  • flopy.utils.HydmodObs returns a numpy recarray. Previously numpy arrays were returned except when the slurp() method was used. The slurp method has been deprecated but the same functionality is available using the get_data() method. The recarray returned from the get_data() method includes the totim value and one or all of the observations (HYDLBL).
  • Added support for MODFLOW-USG DISU package for unstructured grids.
  • Added class (Gridgen) for creating layered quadtree grids using GRIDGEN (flopy.utils.gridgen). See the flopy3_gridgen notebook for an example of how to use the Gridgen class.
  • Added user-specified control on use of OPEN/CLOSE array options (see flopy3_external_file_handling notebook).
  • Added user-specified control for array output formats (see flopy3_array_outputformat_options IPython notebook).
  • Added shapefile as optional output format to .export() method and deprecated .to_shapefile() method.
  • Bug fixes:
    1. Fixed issue with right justified format statement for array control record for MT3DMS.
    2. Fixed bug writing PHIRAMP for MODFLOW-NWT well files.
    3. Fixed bugs in NETCDF export methods.
    4. Fixed bugs in LMT and BTN classes.