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 dependant MODFLOW variables.

is_empty()[source]

Returns true if this block is empty.

is_valid()[source]

Returns true of 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)[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.

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

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.

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, 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.

class MFPackage(model_or_sim, package_type, filename=None, pname=None, loading_package=False, parent_file=None)[source]

Bases: flopy.mf6.mfbase.PackageContainer, flopy.pakbase.PackageInterface

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

Parameters
  • model_or_sim (MFModel of MFSimulation) – The parent model or simulation containing this package

  • package_type (str) – String defining the package type

  • filename (str) – Filename 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) – Package name

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

  • parent_file (MFPackage) – Parent package that contains this package

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

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.

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

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_type

String describing type of package

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)[source]

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

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

  • external_data_folder – Folder where external data will be stored

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.

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.