The Utilities Module

sfrmaker.utils.arbolate_sum(segment, lengths, routing, starting_asums=None)[source]

Compute the total length of all tributaries upstream from segment, including that segment, using the supplied lengths and routing connections.

Parameters:
segmentint or list of ints

Segment or node number that is also a key in the lengths and routing dictionaries.

lengthsdict

Dictionary of lengths keyed by segment (node) numbers, including those in segment.

routingdict

Dictionary describing routing connections between segments (nodes); values represent downstream connections.

starting_asumsdict

Option to supply starting arbolate sum values for any of the segments. By default, None.

Returns:
asumfloat or dict

Arbolate sums for each segment.

sfrmaker.utils.assign_layers(reach_data, botm_array, strtop_col='strtop', strthick_col='strthick', idomain=None, pad=1.0, inplace=False)[source]
Assigns the appropriate layer for each SFR reach,

based on cell bottoms at location of reach.

Parameters:
reach_dataDataFrame

Table of reach information, similar to SFRData.reach_data

botm_arrayndarary

3D numpy array of layer bottom elevations

strtop_colstr

Column name of streambed top elevations in reach_data. by default, ‘strtop’.

strthick_colstr

Column name of streambed bottom thickness in reach_data. by default, ‘strthick’

idomainndarray (optional)

3D integer array of MODFLOW ibound or idomain values. Values > 0 are considered active. Reaches in cells with values < 1 will be moved to the highest active cell if possible. by default, None (all cells are assumed to be active)

padscalar

Minimum distance that streambed bottom must be above layer bottom. When determining the layer or whether the streambed bottom is below the model bottom, streambed bottom - pad is used. Similarly, when lowering the model bottom to accomodate the streambed bottom, a value of streambed bottom - pad is used.

inplacebool

If True, operate on reach_data and botm_array, otherwise, return 1D array of layer numbers and 2D array of new model botm elevations

Returns:
(if inplace=True)
layers1D array of layer numbers
new_model_botmsndarray or None

New model bottom elevations. If no cell bottoms require adjustment, None is returned. If one or more cells require adjustment and idomain=None (not supplied), a 2D array is returned, for backward compatibility with previous versions of SFRmaker. Otherwise, a 3D array of new bottom elevations is returned. In the future, a 3D array will always be returned.

Notes

Streambed bottom = strtop - strthick When multiple reaches occur in a cell, the lowest streambed bottom is used in determining the layer and any corrections to the model bottom.

sfrmaker.utils.exe_exists(exe_name)[source]
sfrmaker.utils.get_input_arguments(kwargs, function, warn=False)[source]

Return subset of keyword arguments in kwargs dict that are valid parameters to a function or method.

Parameters:
kwargsdict (parameter names, values)
functionfunction of class method
Returns:
input_kwargsdict
sfrmaker.utils.get_layer(botm_array, i, j, elev)[source]

Return the layers for elevations at i, j locations.

Parameters:
botm_array3D numpy array of layer bottom elevations
iscaler or sequence

row index (zero-based)

jscaler or sequence

column index

elevscaler or sequence

elevation (in same units as model)

Returns:
knp.ndarray (1-D) or scalar

zero-based layer index

sfrmaker.utils.get_method_args_values(method, exclude=None)[source]

Get arguments for a function or method and their default values.

Parameters:
methodfunction or method
Returns:
argsdict
sfrmaker.utils.get_sfr_package_format(sfr_package_file)[source]
sfrmaker.utils.make_config_summary()[source]
sfrmaker.utils.print_item(k, v)[source]
sfrmaker.utils.update(d, u)[source]

Recursively update a dictionary of varying depth d with items from u. from: https://stackoverflow.com/questions/3232943/update-value-of-a-nested-dictionary-of-varying-depth

sfrmaker.utils.which(program)[source]

Check for existance of executable. https://stackoverflow.com/questions/377017/test-if-executable-exists-in-python

sfrmaker.utils.width_from_arbolate_sum(asum, a=0.1193, b=0.5032, minimum_width=1.0, input_units='meters', output_units='meters')[source]

Estimate stream width from arbolate sum, using a power law regression comparing measured channel widths to arbolate sum. (after Leaf, 2020 and Feinstein et al. 2010, Appendix 2, p 266.)

\[width = unit\_conversion * a * {asum_{(meters)}}^b\]
Parameters:
asum: float or 1D array

Arbolate sum in the input units.

afloat

Multiplier parameter. Literature values: Feinstein et al (2010; Lake MI Basin): 0.1193 Leaf (2020; Mississippi Embayment): 0.0592

bfloat

Exponent in power law relationship. Literature values: Feinstein et al (2010; Lake MI Basin): 0.5032 Leaf (2020; Mississippi Embayment): 0.5127

minimum_widthfloat

Minimum width to be returned. By default, 1.

input_unitsstr, any length unit; e.g. {‘m’, ‘meters’, ‘km’, etc.}

Length unit of asum

output_unitsstr, any length unit; e.g. {‘m’, ‘meters’, ‘ft’, etc.}

Length unit of output width

Returns:
width: float

Estimated width in feet

Notes

The original relationship described by Feinstein et al (2010) was for arbolate sum in meters and output widths in feet. The \(u\) values above reflect this unit conversion. Therefore, the \(unit\_conversion\) parameter above includes conversion of the input to meters, and output from feet to the specified output units.

NaN arbolate sums are filled with the specified minimum_width.

References

see References Cited

Examples

Original equation from Feinstein et al (2010), for arbolate sum of 1,000 km: >>> width = width_from_arbolate_sum(1000, 0.1193, 0.5032, input_units=’kilometers’, output_units=’feet’) >>> float(round(width, 2)) 124.69