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.

Example usage:

>>> 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)

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.

Returns:

budget_list : list of reecord arrays

A list of the zonebudget record arrays.

Example usage:

>>> 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')

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.
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()

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.

Example usage:

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

width : int

The number of values to write to each line.