flopy.utils.zonbud module

class ZBNetOutput(zones, time, arrays, zone_array, flux=True)[source]

Bases: object

Class that holds zonebudget netcdf output and allows export utilities to recognize the output data type.

Parameters:
  • zones (np.ndarray) – array of zone numbers
  • time (np.ndarray) – array of totim
  • arrays (dict) – dictionary of budget term arrays. axis 0 is totim, axis 1 is zones
  • flux (bool) – boolean flag to indicate if budget data is a flux “L^3/T”(True, default) or if the data have been processed to volumetric values “L^3” (False)
class ZoneBudget(cbc_file, z, kstpkper=None, totim=None, aliases=None, verbose=False, **kwargs)[source]

Bases: object

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

Return type:

None

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

Return a deepcopy of the object.

get_budget(names=None, zones=None, net=False)[source]

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 – A list of the zonebudget record arrays.

Return type:

list of record arrays

Examples

>>> names = ['FROM_CONSTANT_HEAD', '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)[source]

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 with the budget information.

Return type:

Pandas DataFrame

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

Get model shape

Returns:
  • nlay (int) – Number of layers
  • nrow (int) – Number of rows
  • ncol (int) – Number of columns
get_record_names(stripped=False)[source]

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

Returns:out – List of unique text names in the binary file.
Return type:list of strings

Examples

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

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:
Return type:None
class ZoneBudgetOutput(f, dis, zones)[source]

Bases: object

Class method to process zonebudget output into volumetric budgets

Parameters:
  • f (str) – zonebudget output file path
  • dis (flopy.modflow.ModflowDis object) –
  • zones (np.ndarray) – numpy array of zones
dataframe

Returns a net flux dataframe of the zonebudget output

dataframe_to_netcdf_fmt(df, flux=True)[source]

Method to transform a volumetric zonebudget dataframe into array format for netcdf.

time is on axis 0 zone is on axis 1

Parameters:
  • df (pd.DataFrame) –
  • flux (bool) – boolean flag to indicate if budget data is a flux “L^3/T” (True, default) or if the data have been processed to volumetric values “L^3” (False)
  • zone_array (np.ndarray) – zonebudget zones array
Returns:

Return type:

ZBNetOutput object

export(f, ml, **kwargs)[source]

Method to export a netcdf file, or add zonebudget output to an open netcdf file instance

Parameters:
  • f (str or flopy.export.netcdf.NetCdf object) –
  • ml (flopy.modflow.Modflow or flopy.mf6.ModflowGwf object) –
  • **kwargs

    logger : flopy.export.netcdf.Logger instance masked_vals : list

    list of values to mask
Returns:

Return type:

flopy.export.netcdf.NetCdf object

volumetric_flux(extrapolate_kper=False)[source]

Method to generate a volumetric budget table based on flux information

Parameters:extrapolate_kper (bool) –

flag to determine if we fill in data gaps with other timestep information from the same stress period. if True, we assume that flux is constant throughout a stress period and the pandas dataframe returned contains a volumetric budget per stress period

if False, calculates volumes from available flux data

Returns:
Return type:pd.DataFrame
zone_array

Property method to get the zone array

zones

Get a unique list of zones

get_totim_modflow6(tdis)[source]

Create a totim array from the tdis file in modflow 6

Parameters:tdis (ModflowTdis object) – MODDFLOW 6 TDIS object
Returns:totim – total time vector for simulation
Return type:np.ndarray
read_zbarray(fname)[source]

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 – An integer array of the zones.
Return type:numpy ndarray
sort_tuple(tup, n=2)[source]

Sort a tuple by the first n values

tup: tuple
input tuple
n : int
values to sort tuple by (default is 2)
Returns:tup – tuple sorted by the first n values
Return type:tuple
sum_flux_tuples(fromzones, tozones, fluxes)[source]
write_zbarray(fname, X, fmtin=None, iprn=None)[source]

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.