flopy.utils.util_list module

util_list module. Contains the mflist class.

This classes encapsulates modflow-style list inputs away from the individual packages. The end-user should not need to instantiate this class directly.

some more info
class MfList(package, data=None, dtype=None, model=None, list_free_format=None, binary=False)[source]

Bases: flopy.datbase.DataInterface, flopy.datbase.DataListInterface

a generic object for handling transient boundary condition lists

Parameters:
  • package (package object) – The package object (of type flopy.pakbase.Package) to which this MfList will be added.
  • data (varies) – the data of the transient list (optional). (the default is None)
mxact

the max number of active bc for any stress period

Type:int
add_record(kper,index,value) : None

add a record to stress period kper at index location

write_transient(f) : None

write the transient sequence to the model input file f

check_kij() : None

checks for boundaries outside of model domain - issues warnings only

Notes

Examples

add_record(kper, index, values)[source]
append(other)[source]

append the recarrays from one MfList to another :param other: that corresponds with self :type other: variable: an item that can be cast in to an MfList

Returns:dict of {kper
Return type:recarray}
array
attribute_by_kper(attr, function=<function mean>, idx_val=None)[source]
binary
check_kij()[source]
data
data_type
df
drop(fields)[source]

drop fields from an MfList

Parameters:fields (list or set of field names to drop) –
Returns:dropped
Return type:MfList without the dropped fields
dtype
export(f, **kwargs)[source]
fmt_string

Returns a C-style fmt string for numpy savetxt that corresponds to the dtype

classmethod from_4d(model, pak_name, m4ds)[source]

construct an MfList instance from a dict of (attribute_name,masked 4D ndarray :param model: :type model: mbase derived type :param pak_name: :type pak_name: str package name (e.g GHB) :param m4ds: :type m4ds: {attribute name:4d masked numpy.ndarray}

Returns:
Return type:MfList instance
get_dataframe(squeeze=True)[source]

Cast recarrays for stress periods into single dataframe containing all stress periods.

Parameters:squeeze (bool) – Reduce number of columns in dataframe to only include stress periods where a variable changes.
Returns:df – Dataframe of shape nrow = ncells, ncol = nvar x nper. If the squeeze option is chosen, nper is the number of stress periods where at least one cells is different, otherwise it is equal to the number of keys in MfList.data.
Return type:dataframe

Notes

Requires pandas.

get_empty(ncell=0)[source]
get_filename(kper)[source]
get_filenames()[source]
get_indices()[source]

a helper function for plotting - get all unique indices

get_itmp(kper)[source]
static masked4D_arrays_to_stress_period_data(dtype, m4ds)[source]
convert a dictionary of 4-dim masked arrays to
a stress_period_data style dict of recarray
Parameters:
  • dtype (numpy dtype) –
  • m4ds (dict {name:masked numpy 4-dim ndarray}) –
Returns:

dict {kper

Return type:

recarray}

masked_4D_arrays
masked_4D_arrays_itr()[source]
mg
model
mxact
name
package
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) –
    axes : list 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)
    pcolor : bool
    Boolean used to determine if matplotlib.pyplot.pcolormesh plot will be plotted. (default is True)
    colorbar : bool
    Boolean used to determine if a color bar will be added to the matplotlib.pyplot.pcolormesh. Only used if pcolor=True. (default is False)
    inactive : bool
    Boolean used to determine if a black overlay in inactive cells in a layer will be displayed. (default is True)
    contour : bool
    Boolean used to determine if matplotlib.pyplot.contour plot will be plotted. (default is False)
    clabel : bool
    Boolean used to determine if matplotlib.pyplot.clabel will be plotted. Only used if contour=True. (default is False)
    grid : bool
    Boolean used to determine if the model grid will be plotted on the figure. (default is False)
    masked_values : list
    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

Notes

Examples

>>> import flopy
>>> ml = flopy.modflow.Modflow.load('test.nam')
>>> ml.wel.stress_period_data.plot(ml.wel, kper=1)
plotable
sr
to_array(kper=0, mask=False)[source]

Convert stress period boundary condition (MfList) 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 (boolean) – 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 MfList dtype names for the stress period data (‘cond’, ‘flux’, ‘bhead’, etc.).

Return type:

dict of numpy.ndarrays

Notes

Examples

>>> import flopy
>>> ml = flopy.modflow.Modflow.load('test.nam')
>>> v = ml.wel.stress_period_data.to_array(kper=1)
to_shapefile(filename, kper=None)[source]

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

Parameters:
  • filename (str) – Shapefile name to write
  • kper (int) – MODFLOW zero-based stress period number to return. (default is None)
Returns:

Return type:

None

Notes

Examples

>>> import flopy
>>> ml = flopy.modflow.Modflow.load('test.nam')
>>> ml.wel.to_shapefile('test_hk.shp', kper=1)
vtype
write_transient(f, single_per=None, forceInternal=False)[source]