flopy.mf6.data.mfdataplist module

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

Bases: MFMultiDimVar, DataListInterface

Provides an interface for the user to access and update MODFLOW list data using Pandas. MFPandasList objects are not designed to be directly constructed by the end user. When a flopy for MODFLOW 6 package object is constructed, the appropriate MFList objects are automatically built.

Parameters:
  • sim_data (MFSimulationData) – data contained in the simulation

  • model_or_sim (MFSimulation or MFModel) – parent model, or if not part of a model, parent simulation

  • structure (MFDataStructure) – describes the structure of the data

  • data (list or ndarray or None) – actual data

  • enable (bool) – enable/disable the array

  • path (tuple) – path in the data dictionary to this MFArray

  • dimensions (MFDataDimensions) – dimension information related to the model, package, and array

  • package (MFPackage) – parent package

  • block (MFBlock) – parnet block

append_data(data)[source]

Appends “data” to the end of this list. Assumes data is in a format that can be appended directly to a pandas dataframe.

Parameters:

data (list(tuple)) – Data to append.

append_list_as_record(record)[source]

Appends the list record as a single record in this list’s dataframe. Assumes “data” has the correct dimensions.

Parameters:

record (list) – List to be appended as a single record to the data’s existing recarray.

binary_ext_data()[source]

check for binary data

property data_type

Type of data (DataType) stored in the list

property dtype

Type of data (numpy.dtype) stored in the list

external_file_name()[source]

Returns external file name, or None if this is not external data.

get_data(apply_mult=False, **kwargs)[source]

Returns the list’s data as a recarray.

Parameters:

apply_mult (bool) – Whether to apply a multiplier.

Returns:

data

Return type:

recarray

get_dataframe()[source]

Returns the list’s data as a dataframe.

Returns:

data

Return type:

DataFrame

get_file_entry(ext_file_action=ExtFileAction.copy_relative_paths)[source]

Returns a string containing the data formatted for a MODFLOW 6 file.

Parameters:

ext_file_action (ExtFileAction) – How to handle external paths.

Returns:

file entry

Return type:

str

get_record(data_frame=False)[source]

Returns the list’s data and metadata in a dictionary. Data is in key “data” and metadata in keys “filename” and “binary”.

Returns:

data_record

Return type:

dict

has_data(key=None)[source]

Returns whether this MFList has any data associated with it.

has_modified_ext_data()[source]

check to see if external data has been modified since last read

load(first_line, file_handle, block_header, pre_data_comments=None, external_file_info=None)[source]

Loads data from first_line (the first line of data) and open file file_handle which is pointing to the second line of data. Returns a tuple with the first item indicating whether all data was read and the second item being the last line of text read from the file. This method was only designed for internal FloPy use and is not recommended for end users.

Parameters:
  • first_line (str) – A string containing the first line of data in this list.

  • file_handle (file descriptor) – A file handle for the data file which points to the second line of data for this list

  • block_header (MFBlockHeader) – Block header object that contains block header information for the block containing this data

  • pre_data_comments (MFComment) – Comments immediately prior to the data

  • external_file_info (list) – Contains information about storing files externally

Returns:

  • more data (bool,)

  • next data line (str)

property package

Package object that this data belongs to.

plot(key=None, names=None, filename_base=None, file_extension=None, mflay=None, **kwargs)[source]

Plot boundary condition (MfList) data

Parameters:
  • key (str) – MfList dictionary key. (default is None)

  • names (list) – List of names for figure titles. (default is None)

  • 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_extension (str) – Valid matplotlib.pyplot file extension for savefig(). Only used if filename_base is not None. (default is ‘png’)

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

  • **kwargs (dict) –

    axeslist of matplotlib.pyplot.axis

    List of matplotlib.pyplot.axis that will be used to plot data for each layer. If axes=None axes will be generated. (default is None)

    pcolorbool

    Boolean used to determine if matplotlib.pyplot.pcolormesh plot will be plotted. (default is True)

    colorbarbool

    Boolean used to determine if a color bar will be added to the matplotlib.pyplot.pcolormesh. Only used if pcolor=True. (default is False)

    inactivebool

    Boolean used to determine if a black overlay in inactive cells in a layer will be displayed. (default is True)

    contourbool

    Boolean used to determine if matplotlib.pyplot.contour plot will be plotted. (default is False)

    clabelbool

    Boolean used to determine if matplotlib.pyplot.clabel will be plotted. Only used if contour=True. (default is False)

    gridbool

    Boolean used to determine if the model grid will be plotted on the figure. (default is False)

    masked_valueslist

    List of unique values to be excluded from the plot.

Returns:

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

Return type:

list

set_data(data, autofill=False, check_data=True, append=False)[source]

Sets the contents of the data to “data”. Data can have the following formats:

  1. recarray - recarray containing the datalist

  2. [(line_one), (line_two), …] - list where each line of the datalist is a tuple within the list

If the data is transient, a dictionary can be used to specify each stress period where the dictionary key is <stress period> - 1 and the dictionary value is the datalist data defined above: {0:ndarray, 1:[(line_one), (line_two), …], 2:{‘filename’:filename})

Parameters:
  • data (ndarray/list/dict) – Data to set

  • autofill (bool) – Automatically correct data

  • check_data (bool) – Whether to verify the data

  • append (bool) – Append to existing data

set_record(record, autofill=False, check_data=True)[source]

Sets the contents of the data and metadata to “data_record”. Data_record is a dictionary with has the following format:

{‘filename’:filename, ‘binary’:True/False, ‘data’=data}

To store to file include ‘filename’ in the dictionary.

Parameters:
  • record (ndarray/list/dict) – Data and metadata to set

  • autofill (bool) – Automatically correct data

  • check_data (bool) – Whether to verify the data

store_as_external_file(external_file_path, binary=False, replace_existing_external=True, check_data=True)[source]

Store all data externally in file external_file_path. the binary allows storage in a binary file. If replace_existing_external is set to False, this method will not do anything if the data is already in an external file.

Parameters:
  • external_file_path (str) – Path to external file

  • binary (bool) – Store data in a binary file

  • replace_existing_external (bool) – Whether to replace an existing external file.

  • check_data (bool) – Verify data prior to storing

store_internal(check_data=True)[source]

Store all data internally.

Parameters:

check_data (bool) – Verify data prior to storing

to_array(kper=0, mask=False)[source]

Convert stress period boundary condition (MFDataList) data for a specified stress period to a 3-D numpy array.

Parameters:
  • kper (int) – MODFLOW zero-based stress period number to return (default is zero)

  • mask (bool) – return array with np.nan instead of zero

Returns:

out – Dictionary of 3-D numpy arrays containing the stress period data for a selected stress period. The dictionary keys are the MFDataList dtype names for the stress period data.

Return type:

dict of numpy.ndarrays

update_record(record, key_index)[source]

Updates a record at index “key_index” with the contents of “record”. If the index does not exist update_record appends the contents of “record” to this list’s recarray.

Parameters:
  • record (list) – New record to update data with

  • key_index (int) – Stress period key of record to update. Only used in transient data types.

write_file_entry(fd_data_file, ext_file_action=ExtFileAction.copy_relative_paths, fd_main=None)[source]

Writes file entry to file, or if fd_data_file is None returns file entry as string.

Parameters:
  • fd_data_file (file descriptor) – where data is written

  • ext_file_action (ExtFileAction) – What action to perform on external files

  • fd_main – file descriptor where open/close string should be written (for external file data)

Returns:

file entry

Return type:

str

class MFPandasTransientList(sim_data, model_or_sim, structure, enable=True, path=None, dimensions=None, package=None, block=None)[source]

Bases: MFPandasList, MFTransient, DataListInterface

Provides an interface for the user to access and update MODFLOW transient pandas list data.

Parameters:
  • sim_data (MFSimulationData) – data contained in the simulation

  • structure (MFDataStructure) – describes the structure of the data

  • enable (bool) – enable/disable the array

  • path (tuple) – path in the data dictionary to this MFArray

  • dimensions (MFDataDimensions) – dimension information related to the model, package, and array

add_transient_key(transient_key)[source]

Adds a new transient time allowing data for that time to be stored and retrieved using the key transient_key. Method is used internally by FloPy and is not intended to the end user.

Parameters:

transient_key (int) – Zero-based stress period to add

append_list_as_record(record, key=0)[source]

Appends the list data as a single record in this list’s recarray at time key. Assumes data has the correct dimensions.

Parameters:
  • record (list) – Data to append

  • key (int) – Zero based stress period to append data too.

binary_ext_data(key=None)[source]

check for binary data

property data

Returns list data. Calls get_data with default parameters.

property data_type

Type of data (DataType) stored in the list

property dataframe

Returns list data. Calls get_data with default parameters.

property dtype

Type of data (numpy.dtype) stored in the list

external_file_name(key=0)[source]

Returns external file name, or None if this is not external data.

Parameters:

key (int) – Zero based stress period to return data from.

get_data(key=None, apply_mult=False, dataframe=False, **kwargs)[source]

Returns the data for stress period key.

Parameters:
  • key (int) – Zero-based stress period to return data from.

  • apply_mult (bool) – Apply multiplier

  • dataframe (bool) – Get as pandas dataframe

Returns:

data

Return type:

recarray

get_dataframe(key=None, apply_mult=False)[source]

Returns the list’s data as a dataframe.

Returns:

data

Return type:

DataFrame

get_file_entry(key=0, ext_file_action=ExtFileAction.copy_relative_paths)[source]

Returns a string containing the data at time key formatted for a MODFLOW 6 file.

Parameters:
  • key (int) – Zero based stress period to return data from.

  • ext_file_action (ExtFileAction) – How to handle external paths.

Returns:

file entry

Return type:

str

get_record(key=None, data_frame=False)[source]

Returns the data for stress period key. If no key is specified returns all records in a dictionary with zero-based stress period numbers as keys. See MFList’s get_record documentation for more information on the format of each record returned.

Parameters:
  • key (int) – Zero-based stress period to return data from.

  • data_frame (bool) – whether to return a Pandas DataFrame object instead of a recarray

Returns:

data_record

Return type:

dict

has_data(key=None)[source]

Returns whether this MFList has any data associated with it in key “key”.

has_modified_ext_data(key=None)[source]

check to see if external data has been modified since last read

load(first_line, file_handle, block_header, pre_data_comments=None, external_file_info=None)[source]

Loads data from first_line (the first line of data) and open file file_handle which is pointing to the second line of data. Returns a tuple with the first item indicating whether all data was read and the second item being the last line of text read from the file.

Parameters:
  • first_line (str) – A string containing the first line of data in this list.

  • file_handle (file descriptor) – A file handle for the data file which points to the second line of data for this array

  • block_header (MFBlockHeader) – Block header object that contains block header information for the block containing this data

  • pre_data_comments (MFComment) – Comments immediately prior to the data

  • external_file_info (list) – Contains information about storing files externally

masked_4D_arrays_itr()[source]

Returns list data as an iterator of a masked 4D array.

plot(key=None, names=None, kper=0, filename_base=None, file_extension=None, mflay=None, **kwargs)[source]

Plot stress period boundary condition (MfList) data for a specified stress period

Parameters:
  • key (str) – MfList dictionary key. (default is None)

  • names (list) – List of names for figure titles. (default is None)

  • kper (int) – MODFLOW zero-based stress period number to return. (default is zero)

  • 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_extension (str) – Valid matplotlib.pyplot file extension for savefig(). Only used if filename_base is not None. (default is ‘png’)

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

  • **kwargs (dict) –

    axeslist of matplotlib.pyplot.axis

    List of matplotlib.pyplot.axis that will be used to plot data for each layer. If axes=None axes will be generated. (default is None)

    pcolorbool

    Boolean used to determine if matplotlib.pyplot.pcolormesh plot will be plotted. (default is True)

    colorbarbool

    Boolean used to determine if a color bar will be added to the matplotlib.pyplot.pcolormesh. Only used if pcolor=True. (default is False)

    inactivebool

    Boolean used to determine if a black overlay in inactive cells in a layer will be displayed. (default is True)

    contourbool

    Boolean used to determine if matplotlib.pyplot.contour plot will be plotted. (default is False)

    clabelbool

    Boolean used to determine if matplotlib.pyplot.clabel will be plotted. Only used if contour=True. (default is False)

    gridbool

    Boolean used to determine if the model grid will be plotted on the figure. (default is False)

    masked_valueslist

    List of unique values to be excluded from the plot.

Returns:

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

Return type:

list

property plottable

If this list data is plottable

remove_transient_key(transient_key)[source]

Remove transient stress period key. Method is used internally by FloPy and is not intended to the end user.

set_data(data, key=None, autofill=False)[source]

Sets the contents of the data at time key to data.

Parameters:
  • data (dict, recarray, list) – Data being set. Data can be a dictionary with keys as zero-based stress periods and values as the data. If data is a recarray or list of tuples, it will be assigned to the stress period specified in key. If any is set to None, that stress period of data will be removed.

  • key (int) – Zero based stress period to assign data too. Does not apply if data is a dictionary.

  • autofill (bool) – Automatically correct data.

set_record(record, autofill=False, check_data=True)[source]

Sets the contents of the data based on the contents of ‘record`.

Parameters:
  • record (dict) – Record being set. Record must be a dictionary with keys as zero-based stress periods and values as dictionaries containing the data and metadata. See MFList’s set_record documentation for more information on the format of the values.

  • autofill (bool) – Automatically correct data

  • check_data (bool) – Whether to verify the data

store_as_external_file(external_file_path, binary=False, replace_existing_external=True, check_data=True)[source]

Store all data externally in file external_file_path. the binary allows storage in a binary file. If replace_existing_external is set to False, this method will not do anything if the data is already in an external file.

Parameters:
  • external_file_path (str) – Path to external file

  • binary (bool) – Store data in a binary file

  • replace_existing_external (bool) – Whether to replace an existing external file.

  • check_data (bool) – Verify data prior to storing

store_internal(check_data=True)[source]

Store all data internally.

Parameters:

check_data (bool) – Verify data prior to storing

to_array(kper=0, mask=False)[source]

Returns list data as an array.

update_record(record, key_index, key=0)[source]

Updates a record at index key_index and time key with the contents of record. If the index does not exist update_record appends the contents of record to this list’s recarray.

Parameters:
  • record (list) – Record to append

  • key_index (int) – Index to update

  • key (int) – Zero based stress period to append data too

write_file_entry(fd_data_file, key=0, ext_file_action=ExtFileAction.copy_relative_paths, fd_main=None)[source]

Returns a string containing the data at time key formatted for a MODFLOW 6 file.

Parameters:
  • fd_data_file (file) – File to write to

  • key (int) – Zero based stress period to return data from.

  • ext_file_action (ExtFileAction) – How to handle external paths.

Returns:

file entry

Return type:

str

class PandasListStorage[source]

Bases: object

Contains data storage information for a single list.

internal_data

data being stored, if full data is being stored internally in memory

Type:

ndarray or recarray

data_storage_type

method used to store the data

Type:

DataStorageType

fname

file name of external file containing the data

Type:

str

factor

factor to multiply the data by

Type:

int/float

iprn

print code

Type:

int

binary

whether the data is stored in a binary file

Type:

bool

modified

whether data in storage has been modified since last write

Type:

bool

get_record : dict

returns a dictionary with all data storage information

set_record(rec)[source]

sets data storage information based on the the dictionary “rec”

set_internal(internal_data)[source]

make data storage internal, using “internal_data” as the data

set_external(fname, data)[source]

make data storage external, with file “fname” and external data “data”

internal_size : int

size of the internal data

has_data : bool

whether or not data exists

get_data_str(formal)[source]
get_record()[source]
has_data()[source]
property internal_size
set_external(fname, data=None)[source]
set_internal(internal_data)[source]
set_record(rec)[source]