flopy.mf6.mfpackage module

class MFBlock(simulation_data, dimensions, structure, path, model_or_sim, container_package)[source]

Bases: object

Represents a block in a MF6 input file. This class is used internally by FloPy and use by users of the FloPy library is not recommended.

Parameters:
  • simulation_data (MFSimulationData) – Data specific to this simulation

  • dimensions (MFDimensions) – Describes model dimensions including model grid and simulation time

  • structure (MFVariableStructure) – Structure describing block

  • path (tuple) – Unique path to block

block_headers

Block header text (BEGIN/END), header variables, comments in the header

Type:

MFBlockHeader

structure

Structure describing block

Type:

MFBlockStructure

path

Unique path to block

Type:

tuple

datasets

Dictionary of dataset objects with keys that are the name of the dataset

Type:

OrderDict

datasets_keyword

Dictionary of dataset objects with keys that are key words to identify start of dataset

Type:

dict

enabled

If block is being used in the simulation

Type:

bool

add_dataset(dataset_struct, data, var_path)[source]

Add data to this block.

data_factory(sim_data, model_or_sim, structure, enable, path, dimensions, data=None, package=None)[source]

Creates the appropriate data child object derived from MFData.

header_exists(key, data_path=None)[source]
is_allowed()[source]

Determine if block is valid based on the values of dependent MODFLOW variables.

is_empty()[source]

Returns true if this block is empty.

is_valid()[source]

Returns true if the block is valid.

load(block_header, fd, strict=True)[source]

Loads block from file object. file object must be advanced to beginning of block before calling.

Parameters:
  • block_header (MFBlockHeader) – Block header for block block being loaded.

  • fd (file) – File descriptor of file being loaded

  • strict (bool) – Enforce strict MODFLOW 6 file format.

set_all_data_external(base_name, check_data=True, external_data_folder=None, binary=False, replace_existing=False)[source]

Sets the block’s list and array data to be stored externally, base_name is external file name’s prefix, check_data determines if data error checking is enabled during this process.

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:
  • base_name (str) – Base file name of external files where data will be written to.

  • check_data (bool) – Whether to do data error checking.

  • external_data_folder – Folder where external data will be stored

  • 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 block’s list and array data to be stored internally, check_data determines if data error checking is enabled during this process.

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:

check_data (bool) – Whether to do data error checking.

set_model_relative_path(model_ws)[source]

Sets model_ws as the model path relative to the simulation’s path.

Parameters:

model_ws (str) – Model path relative to the simulation’s path.

write(fd, ext_file_action=ExtFileAction.copy_relative_paths)[source]

Writes block to a file object.

Parameters:

fd (file object) – File object to write to.

class MFBlockHeader(name, variable_strings, comment, simulation_data=None, path=None, block=None)[source]

Bases: object

Represents the header of a block in a MF6 input file. This class is used internally by FloPy and its direct use by a user of this library is not recommend.

Parameters:
  • name (str) – Block name

  • variable_strings (list) – List of strings that appear after the block name

  • comment (MFComment) – Comment text in the block header

name

Block name

Type:

str

variable_strings

List of strings that appear after the block name

Type:

list

comment

Comment text in the block header

Type:

MFComment

data_items

List of MFVariable of the variables contained in this block

Type:

list

add_data_item(new_data, data)[source]

Adds data to the block.

build_header_variables(simulation_data, block_header_structure, block_path, data, dimensions)[source]

Builds data objects to hold header variables.

connect_to_dict(simulation_data, path, comment=None)[source]

Add comment to the simulation dictionary

get_comment()[source]

Get block header comment

get_transient_key(data_path=None)[source]

Get transient key associated with this block header.

is_same_header(block_header)[source]

Checks if block_header is the same header as this header.

Writes block footer to file object fd.

Parameters:

fd (file object) – File object to write block footer to.

write_header(fd)[source]

Writes block header to file object fd.

Parameters:

fd (file object) – File object to write block header to.

class MFChildPackages(model_or_sim, parent, pkg_type, filerecord, package=None, package_class=None)[source]

Bases: object

Behind the scenes code for creating an interface to access child packages from a parent package. This class is automatically constructed by the FloPy library and is for internal library use only.

init_package(package, fname, remove_packages=True)[source]
next_default_file_path()[source]
class MFPackage(parent, package_type, filename=None, pname=None, loading_package=False, **kwargs)[source]

Bases: PackageInterface

Provides an interface for the user to specify data to build a package.

Parameters:
  • parent (MFModel, MFSimulation, or MFPackage) – The parent model, simulation, or package containing this package.

  • package_type (str) – String defining the package type.

  • filename (str or PathLike, optional) – Name or path of file where this package is stored.

  • quoted_filename (str) – Filename with quotes around it when there is a space in the name

  • pname (str, optional) – Package name.

  • loading_package (bool, default False) – Whether or not to add this package to the parent container’s package list during initialization

  • **kwargs – Extra keyword arguments.

blocks

Dictionary of blocks contained in this package by block name

Type:

dict

path

Data dictionary path to this package

Type:

tuple

structure

Describes the blocks and data contain in this package

Type:

PackageStructure

dimensions

Resolves data dimensions for data within this package

Type:

PackageDimension

add_package(package)[source]
build_child_package(pkg_type, data, parameter_name, filerecord)[source]

Builds a child package. This method is only intended for FloPy internal use.

build_child_packages_container(pkg_type, filerecord)[source]

Builds a container object for any child packages. This method is only intended for FloPy internal use.

build_mfdata(var_name, data=None)[source]

Returns the appropriate data type object (mfdatalist, mfdataarray, or mfdatascalar) given that object the appropriate structure (looked up based on var_name) and any data supplied. This method is for internal FloPy library use only.

Parameters:
  • var_name (str) – Variable name

  • data (many supported types) – Data contained in this object

Returns:

data object

Return type:

MFData subclass

check(f=None, verbose=True, level=1, checktype=None)[source]

Data check, returns True on success.

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.

create_package_dimensions()[source]

Creates a package dimensions object. For internal FloPy library use.

Returns:

package dimensions

Return type:

PackageDimensions

property data_list

List of data in this package.

export(f, **kwargs)[source]

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

Parameters:
  • f (str) – Filename

  • kwargs (keyword arguments) –

    modelgridflopy.discretization.Grid instance

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

Return type:

None or Netcdf object

property filename

Package’s file name.

get_file_path()[source]

Returns the package file’s path.

Returns:

file path

Return type:

str

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.

Parameters:
  • name (str) – Name or type of the package, ‘my-riv-1, ‘RIV’, ‘LPF’, etc.

  • type_only (bool) – Search for package by type only

  • name_only (bool) – Search for package by name only

Returns:

pp

Return type:

Package object

inspect_cells(cell_list, stress_period=None)[source]

Inspect model cells. Returns package 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, only return data from this stress period. If not specified or None, all stress period data will be returned.

Returns:

output – Array containing inspection results

Return type:

array

is_valid()[source]

Returns whether or not this package is valid.

Returns:

is valid

Return type:

bool

load(strict=True)[source]

Loads the package from file.

Parameters:

strict (bool) – Enforce strict checking of data.

Returns:

success

Return type:

bool

property name

Name of package

property output

Method to get output associated with a specific package

Return type:

MF6Output object

property package_dict

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

String describing type of package

property package_type_dict

Deprecated since version 3.9.

This method is for internal use only and will be deprecated.

property parent

Parent package

plot(**kwargs)[source]

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

Parameters:

**kwargs (dict) –

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:

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

Return type:

list

property plottable

If package is plottable

property quoted_filename

Package’s file name with quotes if there is a space.

remove()[source]

Removes this package from the simulation/model it is currently a part of.

set_all_data_external(check_data=True, external_data_folder=None, base_name=None, binary=False, replace_existing=False)[source]

Sets the package’s list and array data to be stored externally.

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) – Determine if data error checking is enabled

  • external_data_folder – Folder 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 package’s list and array data to be stored internally.

Parameters:

check_data (bool) – Determine if data error checking is enabled

set_model_relative_path(model_ws)[source]

Sets the model path relative to the simulation’s path.

Parameters:

model_ws (str) – Model path relative to the simulation’s path.

to_geodataframe(gdf=None, kper=0, full_grid=True, shorten_attr=False, **kwargs)[source]

Method to create a GeoDataFrame from a modflow package

Parameters:
  • gdf (GeoDataFrame) – optional geopandas geodataframe object to add data to. Default is None

  • kper (int) – stress period to get transient data from

  • full_grid (bool) – boolean flag for full grid dataframe construction. Default is True. If False, geodataframe will only include active cells

  • shorten_attr (bool) – method to truncate attribute names for shapefile restrictions

Returns:

gdf

Return type:

GeoDataFrame

write(ext_file_action=ExtFileAction.copy_relative_paths)[source]

Writes the package to a file.

Parameters:

ext_file_action (ExtFileAction) – How to handle pathing of external data files.