flopy.mf6.mfmodel module
- class MFModel(simulation, model_type='gwf6', modelname='model', model_nam_file=None, version='mf6', exe_name='mf6', add_to_simulation=True, structure=None, model_rel_path='.', verbose=False, **kwargs)[source]
Bases:
ModelInterfaceMODFLOW-6 model base class. Represents a single model in a simulation.
- Parameters:
simulation (MFSimulation) – Simulation object that this model is a part of.
model_type (str, default "gwf6") – Model type.
modelname (str, default "model") – Name of the model.
model_nam_file (str, optional) – Relative path to the model name file from model working folder.
version (str, default "mf6") – Version of modflow.
exe_name (str, default "mf6") – Model executable name.
add_to_simulation (bool, default True) – Adds model to simulation.
structure (MFModelStructure) – Structure of this type of model.
model_rel_path (str or PathLike, default "." (curdir)) – Relative path of model folder to simulation folder.
verbose (bool, default False) – Verbose setting for model operations.
**kwargs – Extra keyword options to support spatial referencing, including
xll,yll,xul,yul,rotation, andcrs.
- check(f=None, verbose=True, level=1)[source]
Check model data for common errors.
Warning
The MF6 check mechanism is deprecated pending reimplementation in a future release. While the checks API will remain in place through 3.x, it may be unstable, and will likely change in 4.x.
- Parameters:
f (str 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)
verbose (bool) – Boolean flag used to determine if check method results are written to the screen
level (int) – Check method analysis level. If level=0, summary checks are performed. If level=1, full checks are performed.
- Returns:
success
- Return type:
Examples
>>> import flopy >>> m = flopy.modflow.Modflow.load('model.nam') >>> m.check()
- property exename
MODFLOW executable name
- export(f, **kwargs)[source]
Method to export a model to a shapefile or netcdf file
- Parameters:
f (str) – File name (“.nc” for netcdf or “.shp” for shapefile) or dictionary of ….
**kwargs (keyword arguments) –
- modelgrid: flopy.discretization.Grid
User supplied modelgrid object which will supersede the built in modelgrid object
if fmt is set to ‘vtk’, parameters of Vtk initializer
- get_grid_type()[source]
Return the type of grid used by model ‘model_name’ in simulation containing simulation data ‘simulation_data’.
- Returns:
grid type
- Return type:
- get_ims_package()[source]
Get the IMS package associated with this model.
- Returns:
IMS package
- Return type:
- get_package(name=None, type_only=False, name_only=False)[source]
Finds a package by package name, package key, package type, or partial package name. returns either a single package, a list of packages, or None.
- get_steadystate_list()[source]
Returns a list of stress periods that are steady state.
- Returns:
steady state list
- Return type:
- property hdry
Dry cell value
- property hnoflo
No-flow cell value
- inspect_cells(cell_list, stress_period=None, output_file_path=None, inspect_budget=True, inspect_dependent_var=True)[source]
Inspect model cells. Returns model data associated with cells.
- Parameters:
cell_list (list of tuples) – List of model cells. Each model cell is a tuple of integers. ex: [(1,1,1), (2,4,3)]
stress_period (int) – For transient data qnly return data from this stress period. If not specified or None, all stress period data will be returned.
output_file_path (str) – Path to output file that will contain the inspection results
inspect_budget (bool) – Inspect budget file
inspect_dependent_var (bool) – Inspect head file
- Returns:
output – Dictionary containing inspection results
- Return type:
Examples
>>> import flopy >>> sim = flopy.mf6.MFSimulationBase.load("name", "mf6", "mf6", ".") >>> model = sim.get_model() >>> inspect_list = [(2, 3, 2), (0, 4, 2), (0, 2, 4)] >>> out_file = os.path.join("temp", "inspect_AdvGW_tidal.csv") >>> model.inspect_cells(inspect_list, output_file_path=out_file)
- is_valid()[source]
Checks the validity of the model and all of its packages
- Returns:
valid
- Return type:
- property laycbd
Quasi-3D confining bed. Not supported in MODFLOW-6.
- Returns:
None
- Return type:
None
- property laytyp
Layering type
- static load_base(cls_child, simulation, structure, modelname='NewModel', model_nam_file='modflowtest.nam', mtype='gwf', version='mf6', exe_name: str | PathLike = 'mf6', strict=True, model_rel_path='.', load_only=None)[source]
Class method that loads an existing model.
- Parameters:
simulation (MFSimulation) – Simulation object that this model is a part of.
structure (MFModelStructure) – Structure of this type of model.
modelname (str, default "NewModel") – Name of the model.
model_nam_file (str, default "modflowtest.nam") – Relative path to the model name file from model working folder.
mtype (str, default "gwf") – Not used.
version (str, default "mf6") – Version of modflow.
exe_name (str or PathLike, default "mf6") – Model executable name or path.
strict (bool, default True) – Strict mode when loading files.
model_rel_path (str, default "." (curdir)) – relative path of model folder to simulation folder.
load_only (list) – List of package abbreviations or package names corresponding to packages that flopy will load. default is None, which loads all packages. The discretization packages will load regardless of this setting. Subpackages, like time series and observations, will also load regardless of this setting. Example list:
['ic', 'maw', 'npf', 'oc', 'my_well_package_1']
- Returns:
model
- Return type:
Examples
- load_package(ftype, fname, pname, strict, ref_path, dict_package_name=None, parent_package: MFPackage | None = None)[source]
Loads a package from a file. This method is used internally by FloPy and is not intended for the end user.
- Parameters:
ftype (str) – the file type
fname (str) – the name of the file containing the package input
pname (str) – the user-defined name for the package
strict (bool) – strict mode when loading the file
ref_path (str) – path to the file. uses local path if set to None
dict_package_name (str) – package name for dictionary lookup
parent_package (MFPackage) – parent package
Examples
- property model_ws
Model file path.
- property modeldiscrit
Basic model spatial discretization information. This is used internally prior to model spatial discretization information being fully loaded.
- Returns:
model grid – FloPy object containing basic spatial discretization information for the model.
- Return type:
Grid subclass
- property modelgrid
Model spatial discretization information.
- Returns:
model grid – FloPy object containing spatial discretization information for the model.
- Return type:
Grid subclass
- property modeltime
Model time discretization information.
- Returns:
modeltime – FloPy object containing time discretization information for the simulation.
- Return type:
- property namefile
Model namefile object.
- property nper
Number of stress periods.
- Returns:
nper – Number of stress periods in the simulation.
- Return type:
- property output
- property package_dict
Returns a copy of the package name dictionary.
Deprecated since version 3.9: This method is for internal use only and will be deprecated.
- property package_filename_dict
Deprecated since version 3.9.
This method is for internal use only and will be deprecated.
- property package_key_dict
Deprecated since version 3.9.
This method is for internal use only and will be deprecated.
- property package_name_dict
Deprecated since version 3.9.
This method is for internal use only and will be deprecated.
- property package_names
Returns a list of package names.
Deprecated since version 3.9: This method is for internal use only and will be deprecated.
- property package_type_dict
Deprecated since version 3.9.
This method is for internal use only and will be deprecated.
- property packagelist
List of model packages.
- plot(SelPackList=None, **kwargs)[source]
Plot 2-D, 3-D, transient 2-D, and stress period list (MfList) model input data from a model instance
- Parameters:
model – Flopy model instance
SelPackList – (list) list of package names to plot, if none all packages will be plotted
**kwargs –
dict filename_base : str
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:
- list
Empty list is returned if filename_base is not None. Otherwise a list of matplotlib.pyplot.axis are returned.
- Return type:
axes
- register_package(package, add_to_package_list=True, set_package_name=True, set_package_filename=True)[source]
Registers a package with the model. This method is used internally by FloPy and is not intended for use by the end user.
- Parameters:
- Returns:
path, package structure
- Return type:
tuple, MFPackageStructure
- remove_package(package_name)[source]
Removes package and all child packages from the model. package_name can be the package’s name, type, or package object to be removed from the model.
- Parameters:
package_name (str) – Package name, package type, or package object to be removed from the model.
- rename_all_packages(name)[source]
Renames all package files in the model.
- Parameters:
name (str) – Prefix of package names. Packages files will be named <name>.<package ext>.
- set_all_data_external(check_data=True, external_data_folder=None, base_name=None, binary=False, replace_existing=False)[source]
Sets the model’s list and array data to be stored externally.
Warning
The MF6 check mechanism is deprecated pending reimplementation in a future release. While the checks API will remain in place through 3.x, it may be unstable, and will likely change in 4.x.
Note
External files are written immediately when this method is called, using the current value of max_columns_of_data and other formatting settings. If you need to change these settings, do so BEFORE calling this method. Changing settings afterward will not affect already-written external files unless you call this method again with replace_existing=True.
- Parameters:
check_data (bool) – Determines if data error checking is enabled during this process.
external_data_folder – Folder, relative to the simulation path or model relative path (see use_model_relative_path parameter), where external data will be stored
base_name (str) – Base file name prefix for all files
binary (bool) – Whether file will be stored as binary
replace_existing (bool) – Whether to replace existing external files. If True, existing external files will be rewritten with current settings (e.g., max_columns_of_data). If False, existing external files will not be rewritten. Default is False.
- set_all_data_internal(check_data=True)[source]
Sets the model’s list and array data to be stored externally.
- Parameters:
check_data (bool) – Determines if data error checking is enabled during this process.
- set_model_relative_path(model_ws)[source]
Sets the file path to the model folder relative to the simulation folder and updates all model file paths, placing them in the model folder.
- Parameters:
model_ws (str) – Model working folder relative to simulation working folder
- property solver_tols
Returns the solver inner hclose and rclose values.
- to_geodataframe(gdf=None, kper=0, package_names=None, shorten_attr=False)[source]
Method to build a Geodataframe from model inputs. Note: transient data will only be exported for a single stress period.
- Parameters:
gdf (GeoDataFrame) – optional geopandas geodataframe object to add data to. Default is None
kper (int) – stress period to get transient data from
package_names (list) – optional list of package names
shorten_attr (bool) – method to truncate attribute names for shapefile attribute name length restrictions
- Returns:
gdf
- Return type:
GeoDataFrame
- update_package_filename(package, new_name)[source]
Updates the filename for a package. For internal flopy use only.
- property verbose
Verbose setting for model operations (True/False)
- property version
Version of MODFLOW
- write(ext_file_action=ExtFileAction.copy_relative_paths)[source]
Writes out model’s package files.
- Parameters:
ext_file_action (ExtFileAction) – Defines what to do with external files when the simulation path has changed. defaults to copy_relative_paths which copies only files with relative paths, leaving files defined by absolute paths fixed.