or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

discretization.mdexport.mdfile-io.mdindex.mdmodflow2005.mdmodflow6.mdparticle-tracking.mdplotting.mdtransport.mdutilities.md
tile.json

tessl/pypi-flopy

FloPy is a Python package to create, run, and post-process MODFLOW-based models

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/flopy@3.9.x

To install, run

npx @tessl/cli install tessl/pypi-flopy@3.9.0

index.mddocs/

FloPy

FloPy is a comprehensive Python library for groundwater modeling that provides support for MODFLOW 6, MODFLOW-2005, MODFLOW-NWT, MODFLOW-USG, and MODFLOW-2000, along with related models like MODPATH, MT3DMS, MT3D-USGS, and SEAWAT. The package enables scientists and engineers to create, run, and post-process MODFLOW-based groundwater models through a Python interface, offering tools for model construction, parameter management, input/output handling, and visualization.

Package Information

  • Package Name: flopy
  • Language: Python
  • Installation: pip install flopy or conda install -c conda-forge flopy
  • Requirements: Python 3.10+, numpy >=1.20.3, matplotlib >=1.4.0, pandas >=2.0.0

Core Imports

import flopy

For specific model types:

# MODFLOW 6
from flopy.mf6 import MFSimulation, ModflowGwf

# MODFLOW 2005
from flopy.modflow import Modflow

# Utilities and plotting
from flopy.utils import HeadFile, CellBudgetFile, ZoneBudget
from flopy.plot import PlotMapView

Basic Usage

import flopy
import numpy as np

# Create a simple MODFLOW 6 groundwater flow model
sim = flopy.mf6.MFSimulation(sim_name='example', version='mf6', exe_name='mf6')

# Add time discretization
tdis = flopy.mf6.ModflowTdis(sim, time_units='DAYS', nper=1, perioddata=[(1.0, 1, 1)])

# Create groundwater flow model
gwf = flopy.mf6.ModflowGwf(sim, modelname='gwf', save_flows=True)

# Add discretization
dis = flopy.mf6.ModflowGwfdis(gwf, nlay=1, nrow=10, ncol=10, delr=100.0, delc=100.0)

# Add initial conditions
ic = flopy.mf6.ModflowGwfic(gwf, strt=100.0)

# Add node property flow
npf = flopy.mf6.ModflowGwfnpf(gwf, k=1.0)

# Add constant head boundary
chd_period_data = {0: [[(0, 0, 0), 100.0], [(0, 9, 9), 90.0]]}
chd = flopy.mf6.ModflowGwfchd(gwf, stress_period_data=chd_period_data)

# Add output control
oc = flopy.mf6.ModflowGwfoc(gwf, head_filerecord='gwf.hds', budget_filerecord='gwf.cbc', saverecord=[('HEAD', 'ALL'), ('BUDGET', 'ALL')])

# Add solver
ims = flopy.mf6.ModflowIms(sim, complexity='SIMPLE')

# Write input files
sim.write_simulation()

# Run the model
success, buff = sim.run_simulation()

Architecture

FloPy follows a modular architecture that mirrors the structure of MODFLOW models:

  • Models: Top-level containers (MFSimulation, Modflow, Mt3dms, etc.) that manage packages and execution
  • Packages: Individual model components (boundary conditions, solvers, discretization)
  • Grids: Spatial discretization classes (StructuredGrid, UnstructuredGrid, VertexGrid)
  • Data Arrays: Utilities for handling model input data (Util2d, Util3d, MfList)
  • File I/O: Readers and writers for model input/output files
  • Visualization: Plotting tools for model grids, results, and cross-sections

This design enables flexible model construction while maintaining compatibility with MODFLOW file formats and conventions.

Capabilities

MODFLOW 6 Models

Complete support for MODFLOW 6 including groundwater flow (GWF), transport (GWT), energy transport (GWE), and particle tracking (PRT) models with all standard packages and advanced features.

class MFSimulation:
    """MODFLOW 6 simulation container"""
    def __init__(self, sim_name: str = 'sim', version: str = 'mf6', exe_name: Union[str, PathLike] = 'mf6', sim_ws: Union[str, PathLike] = '.', verbosity_level: int = 1, write_headers: bool = True, use_pandas: bool = True, lazy_io: bool = False, continue_=None, nocheck=None, memory_print_option=None, profile_option=None, maxerrors=None, print_input=None, hpc_data=None): ...
    def write_simulation(self, silent: bool = False): ...
    def run_simulation(self, silent: bool = False, pause: bool = False, report: bool = False): ...

class ModflowGwf:
    """MODFLOW 6 groundwater flow model"""
    def __init__(self, simulation, modelname: str = 'model', model_nam_file=None, version: str = 'mf6', exe_name: str = 'mf6', model_rel_path: str = '.', list=None, print_input=None, print_flows=None, save_flows=None, newtonoptions=None, nc_mesh2d_filerecord=None, nc_structured_filerecord=None, nc_filerecord=None, **kwargs): ...

class ModflowGwt:
    """MODFLOW 6 groundwater transport model"""
    def __init__(self, simulation, modelname: str = 'model', model_nam_file=None, version: str = 'mf6', exe_name: str = 'mf6', model_rel_path: str = '.', list=None, print_input=None, print_flows=None, save_flows=None, nc_mesh2d_filerecord=None, nc_structured_filerecord=None, nc_filerecord=None, **kwargs): ...

MODFLOW 6

MODFLOW 2005 Models

Support for MODFLOW-2005, MODFLOW-NWT, MODFLOW-USG, and MODFLOW-2000 with comprehensive package coverage including flow, boundary conditions, and solvers.

class Modflow:
    """MODFLOW 2005 model"""
    def __init__(self, modelname: str = 'modflowtest', namefile_ext: str = 'nam', version: str = 'mf2005', exe_name: str = 'mf2005', **kwargs): ...
    def write_input(self, SelPackList: list = None, check: bool = True): ...
    def run_model(self, silent: bool = False, pause: bool = False, report: bool = False): ...

MODFLOW 2005

Grid and Discretization

Grid classes for structured, unstructured, and vertex-based discretizations with coordinate transformations, intersection utilities, and export capabilities.

class StructuredGrid:
    """Regular rectangular grid discretization"""
    def __init__(self, delc, delr, top=None, botm=None, idomain=None, **kwargs): ...
    @property
    def xcellcenters(self): ...
    @property
    def ycellcenters(self): ...
    def intersect(self, x, y, z=None): ...

class UnstructuredGrid:
    """Flexible unstructured mesh discretization"""
    def __init__(self, vertices, iverts, **kwargs): ...

class ModelTime:
    """Temporal discretization management"""
    def __init__(self, perioddata, time_units='days', **kwargs): ...

Grid and Discretization

Transport Modeling

MT3DMS and MT3D-USGS transport models with advection, dispersion, reactions, and specialized packages for complex transport scenarios.

class Mt3dms:
    """MT3DMS transport model"""
    def __init__(self, modelname: str = 'mt3dtest', namefile_ext: str = 'nam', ftlfilename: str = 'mt3d_link.ftl', **kwargs): ...

class Mt3dBtn:
    """Basic transport package"""
    def __init__(self, model, nlay=1, nrow=2, ncol=2, **kwargs): ...

Transport Modeling

Particle Tracking

MODPATH 6 and 7 models for particle tracking analysis with flexible particle placement, endpoint analysis, and pathline tracking.

class Modpath7:
    """MODPATH 7 particle tracking model"""
    def __init__(self, modelname: str = 'modpathtest', flowmodel=None, **kwargs): ...

class ParticleData:
    """Base particle data class"""
    def __init__(self, partlocs, **kwargs): ...

class ParticleGroup:
    """Particle group container"""
    def __init__(self, particlegroupname: str, particledata, **kwargs): ...

Particle Tracking

File I/O and Post-processing

Comprehensive file readers for MODFLOW output files, budget analysis, observation processing, and result visualization.

class HeadFile:
    """Head file reader"""
    def __init__(self, filename, text='head', **kwargs): ...
    def get_data(self, kstpkper=None, idx=None, totim=None): ...

class CellBudgetFile:
    """Cell budget file reader"""
    def __init__(self, filename, **kwargs): ...
    def get_data(self, kstpkper=None, idx=None, totim=None, text=None): ...

class ZoneBudget:
    """Zone budget analysis"""
    def __init__(self, cbc_file, z, kstpkper=None, **kwargs): ...

File I/O and Post-processing

Visualization and Plotting

Plotting utilities for map views, cross-sections, and 3D visualization with matplotlib integration and export capabilities.

class PlotMapView:
    """Map view plotting"""
    def __init__(self, model=None, ax=None, layer=0, **kwargs): ...
    def plot_grid(self, **kwargs): ...
    def plot_array(self, a, **kwargs): ...
    def contour_array(self, a, **kwargs): ...

class PlotCrossSection:
    """Cross-section plotting"""
    def __init__(self, model=None, line=None, ax=None, **kwargs): ...

Visualization and Plotting

Data Export

Export model grids, arrays, and results to various formats including NetCDF, VTK, shapefiles, and other GIS-compatible formats.

class NetCdf:
    """NetCDF export functionality"""
    def __init__(self, output_filename, model, **kwargs): ...
    def write(self): ...

class Vtk:
    """VTK format export"""
    def __init__(self, model, **kwargs): ...
    def add_array(self, array, name, **kwargs): ...

Data Export

Utilities and Helpers

General utilities for model checking, parameter estimation, coordinate transformations, and integration with external tools.

def run_model(namefile, exe_name, **kwargs):
    """Execute model runs with subprocess management"""
    ...

def which(program):
    """Find executable paths"""
    ...

def check(model, **kwargs):
    """Model checking function"""
    ...

Utilities and Helpers

Common Types

# Stress period data format
StressPeriodData = dict[int, list[list]]

# Array data types
ArrayData = Union[int, float, np.ndarray, list]

# File path types
FilePath = Union[str, os.PathLike]

# Model coordinate types
Coordinates = tuple[float, float] | list[float]