flopy.utils.zonbud Module

class flopy.utils.zonbud.ZoneBudget(cbc_file, z, kstpkper=None, totim=None, aliases=None, **kwargs)

ZoneBudget class

Parameters:

cbc_file : str or CellBudgetFile object

The file name or CellBudgetFile object for which budgets will be computed.

z : ndarray

The array containing to zones to be used.

kstpkper : tuple of ints

A tuple containing the time step and stress period (kstp, kper). The kstp and kper values are zero based.

totim : float

The simulation time.

aliases : dict

A dictionary with key, value pairs of zones and aliases. Replaces the corresponding record and field names with the aliases provided. NOTE: When using this option in conjunction with a list of zones, the zone(s) passed may either be all strings (aliases), all integers, or mixed.

Examples

>>> from flopy.utils.zonbud import ZoneBudget, read_zbarray
>>> zon = read_zbarray('zone_input_file')
>>> zb = ZoneBudget('zonebudtest.cbc', zon, kstpkper=(0, 0))
>>> zb.to_csv('zonebudtest.csv')
>>> zb_mgd = zb * 7.48052 / 1000000
copy()

Return a deepcopy of the object.

get_budget(names=None, zones=None, net=False)

Get a list of zonebudget record arrays.

Parameters:

names : list of strings

A list of strings containing the names of the records desired.

zones : list of ints or strings

A list of integer zone numbers or zone names desired.

net : boolean

If True, returns net IN-OUT for each record.

Returns:

budget_list : list of reecord arrays

A list of the zonebudget record arrays.

Examples

>>> names = ['CONSTANT_HEAD_IN', 'RIVER_LEAKAGE_OUT']
>>> zones = ['ZONE_1', 'ZONE_2']
>>> zb = ZoneBudget('zonebudtest.cbc', zon, kstpkper=(0, 0))
>>> bud = zb.get_budget(names=names, zones=zones)
get_dataframes(start_datetime=None, timeunit='D', index_key='totim', names=None, zones=None, net=False)

Get pandas dataframes. Parameters ———-

start_datetime : str
Datetime string indicating the time at which the simulation starts.
timeunit : str
String that indicates the time units used in the model.
index_key : str
Indicates the fields to be used (in addition to “record”) in the resulting DataFrame multi-index.
names : list of strings
A list of strings containing the names of the records desired.
zones : list of ints or strings
A list of integer zone numbers or zone names desired.
net : boolean
If True, returns net IN-OUT for each record.
Returns:

df : Pandas DataFrame

Pandas DataFrame with the budget information.

Examples

>>> from flopy.utils.zonbud import ZoneBudget, read_zbarray
>>> zon = read_zbarray('zone_input_file')
>>> zb = ZoneBudget('zonebudtest.cbc', zon, kstpkper=(0, 0))
>>> df = zb.get_dataframes()
get_record_names(stripped=False)

Get a list of water budget record names in the file.

Returns:

out : list of strings

List of unique text names in the binary file.

Examples

>>> zb = ZoneBudget('zonebudtest.cbc', zon, kstpkper=(0, 0))
>>> recnames = zb.get_record_names()
to_csv(fname)

Saves the budget record arrays to a formatted comma-separated values file.

Parameters:

fname : str

The name of the output comma-separated values file.

Returns:

None

flopy.utils.zonbud.read_zbarray(fname)

Reads an ascii array in a format readable by the zonebudget program executable.

Parameters:

fname : str

The path and name of the file to be written.

Returns:

zones : numpy ndarray

An integer array of the zones.

flopy.utils.zonbud.sort_tuple(tup, n=2)

Sort a tuple by the first n values :param tup: :param n: :return:

flopy.utils.zonbud.write_zbarray(fname, X, fmtin=None, iprn=None)

Saves a numpy array in a format readable by the zonebudget program executable.

File format: line 1: nlay, nrow, ncol line 2: INTERNAL (format) line 3: begin data . . .

example from NACP: 19 250 500 INTERNAL (10I8)

199 199 199 199 199 199 199 199 199 199 199 199 199 199 199 199 199 199 199 199 …
INTERNAL (10I8)
199 199 199 199 199 199 199 199 199 199 199 199 199 199 199 199 199 199 199 199 …
Parameters:

X : array

The array of zones to be written.

fname : str

The path and name of the file to be written.

fmtin : int

The number of values to write to each line.

iprn : int

Padding space to add between each value.