gsflow.modflow.mf Module

class gsflow.modflow.mf.Modflow(modelname='modflowtest', namefile_ext='nam', version='mfnwt', version2='gsflow', exe_name='mfnwt.exe', structured=True, listunit=2, model_ws='.', external_path=None, verbose=False, **kwargs)[source]

GSFLOW overridden MODFLOW Model Class. This class is a child of the FloPy flopy.modflow.Modflow class

Parameters
modelnamestring, optional

Name of model. This string will be used to name the MODFLOW input that are created with write_model. (the default is ‘modflowtest’)

namefile_extstring, optional

Extension for the namefile (the default is ‘nam’)

versionstring, optional

Version of MODFLOW to use (the default is ‘mfnwt’)

version2str, optional

Secondary MODFLOW version to use (the default is ‘gsflow’)

exe_namestring, optional

The name of the executable to use (the default is ‘mfnwt’).

listunitinteger, optional

Unit number for the list file (the default is 2).

model_wsstring, optional

model workspace. Directory name to create model data sets. (default is the present working directory).

external_pathstring

Location for external files (default is None).

verboseboolean, optional

Print additional information to the screen (default is False).

loadboolean, optional

(default is True).

silentinteger

(default is 0)

Examples

>>> import flopy
>>> m = flopy.modflow.Modflow()
Attributes
exename
hdry
hnoflo
laycbd
laytyp
model_ws

Modflow model’s base directory path

modelgrid
modeltime
name

Get model name

namefile
ncol

Returns the number of columns in the model

ncpl

Returns the number of cells per layer in the model

nlay
nper

Returns the number of stress periods in the model

nrow

Returns the number of model rows

nrow_ncol_nlay_nper
packagelist
solver_tols
verbose
version
version2

Secondary version information about modflow

Methods

add_existing_package(self, filename[, …])

Add an existing package to a model instance.

add_external(self, fname, unit[, binflag, …])

Assign an external array so that it will be listed as a DATA or DATA(BINARY) entry in the name file.

add_output(self, fname, unit[, binflag, package])

Assign an external array so that it will be listed as a DATA or DATA(BINARY) entry in the name file.

add_output_file(self, unit[, fname, …])

Add an ascii or binary output file for a package

add_package(self, p)

Add a package.

add_pop_key_list(self, key)

Add a external file unit number to a list that will be used to remove model output (typically binary) files from ext_unit_dict.

change_model_ws(self[, new_pth, reset_external])

Change the model work space.

check(self[, f, verbose, level])

Check model data for common errors.

export(self, f, \*\*kwargs)

Method to export a model to netcdf or shapefile based on the extension of the file name (.shp for shapefile, .nc for netcdf)

get_name_file_entries(self)

Get a string representation of the name file.

get_output(self[, fname, unit])

Get an output file from the model by specifying either the file name or the unit number.

get_output_attribute(self[, fname, unit, attr])

Get a attribute for an output file from the model by specifying either the file name or the unit number.

get_package(self, name)

Get a package.

get_package_list(self[, ftype])

Get a list of all the package names.

has_package(self, name)

Check if package name is in package list.

load(f[, version, exe_name, verbose, …])

Load an existing MODFLOW model.

next_ext_unit(self)

Function to encapsulate next_ext_unit attribute

plot(self[, SelPackList])

Plot 2-D, 3-D, transient 2-D, and stress period list (MfList) model input data

remove_external(self[, fname, unit])

Remove an external file from the model by specifying either the file name or the unit number.

remove_output(self[, fname, unit])

Remove an output file from the model by specifying either the file name or the unit number.

remove_package(self, pname)

Remove a package from this model

run_model(self[, silent, pause, report, …])

This method will run the model using subprocess.Popen.

set_model_units(self[, iunit0])

Write the model name file.

set_output_attribute(self[, fname, unit, attr])

Set a variable in an output file from the model by specifying either the file name or the unit number and a dictionary with attributes to change.

to_shapefile(self, filename[, package_names])

Wrapper function for writing a shapefile for the model grid.

write_input(self[, SellPackList, check])

Write the input.

write_name_file(self)

Write the model name file

get_ext_dict_attr

get_ifrefm

get_nrow_ncol_nlay_nper

load_results

next_unit

set_ifrefm

set_version

update_modelgrid

add_existing_package(self, filename, ptype=None, copy_to_model_ws=True)

Add an existing package to a model instance.

Parameters
filenamestr

the name of the file to add as a package

ptypeoptional

the model package type (e.g. “lpf”, “wel”, etc). If None, then the file extension of the filename arg is used

copy_to_model_wsbool

flag to copy the package file into the model_ws directory.

Returns
None
add_external(self, fname, unit, binflag=False, output=False)

Assign an external array so that it will be listed as a DATA or DATA(BINARY) entry in the name file. This will allow an outside file package to refer to it.

Parameters
fnamestr

filename of external array

unitint

unit number of external array

binflagboolean

binary or not. (default is False)

add_output(self, fname, unit, binflag=False, package=None)

Assign an external array so that it will be listed as a DATA or DATA(BINARY) entry in the name file. This will allow an outside file package to refer to it.

Parameters
fnamestr

filename of external array

unitint

unit number of external array

binflagboolean

binary or not. (default is False)

add_output_file(self, unit, fname=None, extension='cbc', binflag=True, package=None)

Add an ascii or binary output file for a package

Parameters
unitint

unit number of external array

fnamestr

filename of external array. (default is None)

extensionstr

extension to use for the cell-by-cell file. Only used if fname is None. (default is cbc)

binflagbool

boolean flag indicating if the output file is a binary file. Default is True

packagestr

string that defines the package the output file is attached to. Default is None

add_package(self, p)

Add a package.

Parameters
pPackage object
add_pop_key_list(self, key)

Add a external file unit number to a list that will be used to remove model output (typically binary) files from ext_unit_dict.

Parameters
keyint

file unit number

change_model_ws(self, new_pth=None, reset_external=False)[source]

Change the model work space.

Parameters
new_pthstr

Location of new model workspace. If this path does not exist, it will be created. (default is None, which will be assigned to the present working directory).

Returns
None
check(self, f=None, verbose=True, level=1)

Check model data for common errors.

Parameters
fstr or file handle

String defining file name or file handle for summary file of check method output. If a string is passed a file handle is created. If f is None, check method does not write results to a summary file. (default is None)

verbosebool

Boolean flag used to determine if check method results are written to the screen

levelint

Check method analysis level. If level=0, summary checks are performed. If level=1, full checks are performed.

Returns
None

Examples

>>> import flopy
>>> m = flopy.modflow.Modflow.load('model.nam')
>>> m.check()
export(self, f, **kwargs)

Method to export a model to netcdf or shapefile based on the extension of the file name (.shp for shapefile, .nc for netcdf)

Parameters
fstr

filename

kwargskeyword arguments
modelgridflopy.discretization.Grid instance

user supplied modelgrid which can be used for exporting in lieu of the modelgrid associated with the model object

Returns
None or Netcdf object
get_name_file_entries(self)

Get a string representation of the name file.

get_output(self, fname=None, unit=None)

Get an output file from the model by specifying either the file name or the unit number.

Parameters
fnamestr

filename of output array

unitint

unit number of output array

get_output_attribute(self, fname=None, unit=None, attr=None)

Get a attribute for an output file from the model by specifying either the file name or the unit number.

Parameters
fnamestr

filename of output array

unitint

unit number of output array

get_package(self, name)

Get a package.

Parameters
namestr

Name of the package, ‘RIV’, ‘LPF’, etc. (case-insensitive).

Returns
ppPackage object

Package object of type flopy.pakbase.Package

get_package_list(self, ftype=None)

Get a list of all the package names.

Parameters
ftypestr

Type of package, ‘RIV’, ‘LPF’, etc.

Returns
vallist of strings

Can be used to see what packages are in the model, and can then be used with get_package to pull out individual packages.

has_package(self, name)

Check if package name is in package list.

Parameters
namestr

Name of the package, ‘DIS’, ‘BAS6’, etc. (case-insensitive).

Returns
bool

True if package name exists, otherwise False if not found.

static load(f, version='mfnwt', exe_name='mfnwt.exe', verbose=False, model_ws='.', load_only=None, forgive=False, check=True, control_file=None)[source]

Load an existing MODFLOW model.

Parameters
fstr

Path to MODFLOW name file to load.

versionstr, optional

MODFLOW version. Default ‘mfnwt’, although can be modified on loading packages unique to different MODFLOW versions.

exe_namestr, optional

MODFLOW executable name. Default ‘mfnwt.exe’.

verbosebool, optional

Show messages that can be useful for debugging. Default False.

model_wsstr

Model workspace path. Default ‘.’ or current directory.

load_onlylist, str or None

List of case insensitive filetypes to load, e.g. [“bas6”, “lpf”]. One package can also be specified, e.g. “rch”. Default is None, which attempts to load all files. An empty list [] will not load any additional packages than is necessary. At a minimum, “dis” or “disu” is always loaded.

forgivebool, optional

Option to raise exceptions on package load failure, which can be useful for debugging. Default False.

checkboolean, optional

Check model input for common errors. Default True.

control_filestr, optional

For using GSFLOW, providing a control file helps to adjust the paths on the fly

Returns
mlModflow object

Examples

>>> import gsflow
>>> ml = gsflow.modflow.Modflow.load('model.nam')
property model_ws

Modflow model’s base directory path

property name

Get model name

Returns
namestr

name of model

property ncol

Returns the number of columns in the model

property ncpl

Returns the number of cells per layer in the model

next_ext_unit(self)

Function to encapsulate next_ext_unit attribute

property nper

Returns the number of stress periods in the model

property nrow

Returns the number of model rows

plot(self, SelPackList=None, **kwargs)[source]

Plot 2-D, 3-D, transient 2-D, and stress period list (MfList) model input data

Parameters
SelPackListbool or list

List of of packages to plot. If SelPackList=None all packages are plotted. (default is None)

**kwargsdict
filename_basestr

Base file name that will be used to automatically generate file names for output image files. Plots will be exported as image files if file_name_base is not None. (default is None)

file_extensionstr

Valid matplotlib.pyplot file extension for savefig(). Only used if filename_base is not None. (default is ‘png’)

mflayint

MODFLOW zero-based layer number to return. If None, then all all layers will be included. (default is None)

kperint

MODFLOW zero-based stress period number to return. (default is zero)

keystr

MfList dictionary key. (default is None)

Returns
axeslist

Empty list is returned if filename_base is not None. Otherwise a list of matplotlib.pyplot.axis are returned.

Examples

>>> import gsflow
>>> ml = gsflow.modflow.Modflow.load('test.nam')
>>> ml.plot()
remove_external(self, fname=None, unit=None)

Remove an external file from the model by specifying either the file name or the unit number.

Parameters
fnamestr

filename of external array

unitint

unit number of external array

remove_output(self, fname=None, unit=None)

Remove an output file from the model by specifying either the file name or the unit number.

Parameters
fnamestr

filename of output array

unitint

unit number of output array

remove_package(self, pname)

Remove a package from this model

Parameters
pnamestring

Name of the package, such as ‘RIV’, ‘BAS6’, etc.

run_model(self, silent=False, pause=False, report=False, normal_msg='normal termination')

This method will run the model using subprocess.Popen.

Parameters
silentboolean

Echo run information to screen (default is True).

pauseboolean, optional

Pause upon completion (default is False).

reportboolean, optional

Save stdout lines to a list (buff) which is returned by the method . (default is False).

normal_msgstr

Normal termination message used to determine if the run terminated normally. (default is ‘normal termination’)

Returns
(success, buff)
successboolean
bufflist of lines of stdout
set_model_units(self, iunit0=None)[source]

Write the model name file.

set_output_attribute(self, fname=None, unit=None, attr=None)

Set a variable in an output file from the model by specifying either the file name or the unit number and a dictionary with attributes to change.

Parameters
fnamestr

filename of output array

unitint

unit number of output array

to_shapefile(self, filename, package_names=None, **kwargs)[source]

Wrapper function for writing a shapefile for the model grid. If package_names is not None, then search through the requested packages looking for arrays that can be added to the shapefile as attributes

Parameters
filenamestring

name of the shapefile to write

package_nameslist of package names (e.g. [“dis”,”lpf”])

Packages to export data arrays to shapefile. (default is None)

Returns
None

Examples

>>> import gsflow
>>> m = gsflow.modflow.Modflow()
>>> m.to_shapefile('model.shp', SelPackList)
property version2

Secondary version information about modflow

write_input(self, SellPackList=False, check=False)[source]

Write the input.

Parameters
SelPackListFalse or list of packages
write_name_file(self)[source]

Write the model name file