flopy.modflow.mfsfr2 module

class ModflowSfr2(model, nstrm=-2, nss=1, nsfrpar=0, nparseg=0, const=None, dleak=0.0001, ipakcb=None, istcb2=None, isfropt=0, nstrail=10, isuzn=1, nsfrsets=30, irtflg=0, numtim=2, weight=0.75, flwtol=0.0001, reach_data=None, segment_data=None, channel_geometry_data=None, channel_flow_data=None, dataset_5=None, irdflag=0, iptflag=0, reachinput=False, transroute=False, tabfiles=False, tabfiles_dict=None, extension='sfr', unit_number=None, filenames=None, options=None)[source]

Bases: flopy.pakbase.Package

Streamflow-Routing (SFR2) Package Class

Parameters:
  • model (model object) – The model object (of type :class:’flopy.modflow.mf.Modflow’) to which this package will be added.
  • nstrm (integer) – An integer value that can be specified to be positive or negative. The absolute value of NSTRM is equal to the number of stream reaches (finite-difference cells) that are active during the simulation and the number of lines of data to be included in Item 2, described below. When NSTRM is specified to be a negative integer, it is also used as a flag for changing the format of the data input, for simulating unsaturated flow beneath streams, and (or) for simulating transient streamflow routing (for MODFLOW-2005 simulations only), depending on the values specified for variables ISFROPT and IRTFLG, as described below. When NSTRM is negative, NSFRPAR must be set to zero, which means that parameters cannot be specified. By default, nstrm is set to negative.
  • nss (integer) – An integer value equal to the number of stream segments (consisting of one or more reaches) that are used to define the complete stream network. The value of NSS represents the number of segments that must be defined through a combination of parameters and variables in Item 4 or variables in Item 6.
  • nparseg (integer) – An integer value equal to (or exceeding) the number of stream-segment definitions associated with all parameters. This number can be more than the total number of segments (NSS) in the stream network because the same segment can be defined in multiple parameters, and because parameters can be time-varying. NPARSEG must equal or exceed the sum of NLST x N for all parameters, where N is the greater of 1 and NUMINST; that is, NPARSEG must equal or exceed the total number of repetitions of item 4b. This variable must be zero when NSTRM is negative.
  • const (float) – A real value (or conversion factor) used in calculating stream depth for stream reach. If stream depth is not calculated using Manning’s equation for any stream segment (that is, ICALC does not equal 1 or 2), then a value of zero can be entered. If Manning’s equation is used, a constant of 1.486 is used for flow units of cubic feet per second, and a constant of 1.0 is used for units of cubic meters per second. The constant must be multiplied by 86,400 when using time units of days in the simulation. An explanation of time units used in MODFLOW is given by Harbaugh and others (2000, p. 10).
  • dleak (float) – A real value equal to the tolerance level of stream depth used in computing leakage between each stream reach and active model cell. Value is in units of length. Usually a value of 0.0001 is sufficient when units of feet or meters are used in model.
  • ipakcb (integer) – An integer value used as a flag for writing stream-aquifer leakage values. If ipakcb > 0, unformatted leakage between each stream reach and corresponding model cell will be saved to the main cell-by-cell budget file whenever when a cell-by-cell budget has been specified in Output Control (see Harbaugh and others, 2000, pages 52-55). If ipakcb = 0, leakage values will not be printed or saved. Printing to the listing file (ipakcb < 0) is not supported.
  • istcb2 (integer) – An integer value used as a flag for writing to a separate formatted file all information on inflows and outflows from each reach; on stream depth, width, and streambed conductance; and on head difference and gradient across the streambed. If ISTCB2 > 0, then ISTCB2 also represents the unit number to which all information for each stream reach will be saved to a separate file when a cell-by-cell budget has been specified in Output Control. If ISTCB2 < 0, it is the unit number to which unformatted streamflow out of each reach will be saved to a file whenever the cell-by-cell budget has been specified in Output Control. Unformatted output will be saved to <model name>.sfq.
  • isfropt (integer) –

    An integer value that defines the format of the input data and whether or not unsaturated flow is simulated beneath streams. Values of ISFROPT are defined as follows

    0 No vertical unsaturated flow beneath streams. Streambed elevations,
    stream slope, streambed thickness, and streambed hydraulic conductivity are read for each stress period using variables defined in Items 6b and 6c; the optional variables in Item 2 are not used.
    1 No vertical unsaturated flow beneath streams. Streambed elevation,
    stream slope, streambed thickness, and streambed hydraulic conductivity are read for each reach only once at the beginning of the simulation using optional variables defined in Item 2; Items 6b and 6c are used to define stream width and depth for ICALC = 0 and stream width for ICALC = 1.
    2 Streambed and unsaturated-zone properties are read for each reach
    only once at the beginning of the simulation using optional variables defined in Item 2; Items 6b and 6c are used to define stream width and depth for ICALC = 0 and stream width for ICALC = 1. When using the LPF Package, saturated vertical hydraulic conductivity for the unsaturated zone is the same as the vertical hydraulic conductivity of the corresponding layer in LPF and input variable UHC is not read.
    3 Same as 2 except saturated vertical hydraulic conductivity for the
    unsaturated zone (input variable UHC) is read for each reach.
    4 Streambed and unsaturated-zone properties are read for the
    beginning and end of each stream segment using variables defined in Items 6b and 6c; the optional variables in Item 2 are not used. Streambed properties can vary each stress period. When using the LPF Package, saturated vertical hydraulic conductivity for the unsaturated zone is the same as the vertical hydraulic conductivity of the corresponding layer in LPF and input variable UHC1 is not read.
    5 Same as 4 except saturated vertical hydraulic conductivity for the
    unsaturated zone (input variable UHC1) is read for each segment at the beginning of the first stress period only.
  • nstrail (integer) – An integer value that is the number of trailing wave increments used to represent a trailing wave. Trailing waves are used to represent a decrease in the surface infiltration rate. The value can be increased to improve mass balance in the unsaturated zone. Values between 10 and 20 work well and result in unsaturated-zone mass balance errors beneath streams ranging between 0.001 and 0.01 percent. Please see Smith (1983) for further details. (default is 10; for MODFLOW-2005 simulations only when isfropt > 1)
  • isuzn (integer) – An integer value that is the maximum number of vertical cells used to define the unsaturated zone beneath a stream reach. If ICALC is 1 for all segments then ISUZN should be set to 1. (default is 1; for MODFLOW-2005 simulations only when isfropt > 1)
  • nsfrsets (integer) – An integer value that is the maximum number of different sets of trailing waves used to allocate arrays. Arrays are allocated by multiplying NSTRAIL by NSFRSETS. A value of 30 is sufficient for problems where the stream depth varies often. NSFRSETS does not affect model run time. (default is 30; for MODFLOW-2005 simulations only when isfropt > 1)
  • irtflg (integer) – An integer value that indicates whether transient streamflow routing is active. IRTFLG must be specified if NSTRM < 0. If IRTFLG > 0, streamflow will be routed using the kinematic-wave equation (see USGS Techniques and Methods 6-D1, p. 68-69); otherwise, IRTFLG should be specified as 0. Transient streamflow routing is only available for MODFLOW-2005; IRTFLG can be left blank for MODFLOW-2000 simulations. (default is 1)
  • numtim (integer) – An integer value equal to the number of sub time steps used to route streamflow. The time step that will be used to route streamflow will be equal to the MODFLOW time step divided by NUMTIM. (default is 2; for MODFLOW-2005 simulations only when irtflg > 0)
  • weight (float) – A real number equal to the time weighting factor used to calculate the change in channel storage. WEIGHT has a value between 0.5 and 1. Please refer to equation 83 in USGS Techniques and Methods 6-D1 for further details. (default is 0.75; for MODFLOW-2005 simulations only when irtflg > 0)
  • flwtol (float) – A real number equal to the streamflow tolerance for convergence of the kinematic wave equation used for transient streamflow routing. A value of 0.00003 cubic meters per second has been used successfully in test simulations (and would need to be converted to whatever units are being used in the particular simulation). (default is 0.0001; for MODFLOW-2005 simulations only when irtflg > 0)
  • reach_data (recarray) – Numpy record array of length equal to nstrm, with columns for each variable entered in item 2 (see SFR package input instructions). In following flopy convention, layer, row, column and node number (for unstructured grids) are zero-based; segment and reach are one-based.
  • segment_data (recarray) – Numpy record array of length equal to nss, with columns for each variable entered in items 6a, 6b and 6c (see SFR package input instructions). Segment numbers are one-based.
  • dataset_5 (dict of lists) – Optional; will be built automatically from segment_data unless specified. Dict of lists, with key for each stress period. Each list contains the variables [itmp, irdflag, iptflag]. (see SFR documentation for more details):
  • itmp (list of integers (len = NPER)) – For each stress period, an integer value for reusing or reading stream segment data that can change each stress period. If ITMP = 0 then all stream segment data are defined by Item 4 (NSFRPAR > 0; number of stream parameters is greater than 0). If ITMP > 0, then stream segment data are not defined in Item 4 and must be defined in Item 6 below for a number of segments equal to the value of ITMP. If ITMP < 0, then stream segment data not defined in Item 4 will be reused from the last stress period (Item 6 is not read for the current stress period). ITMP must be defined >= 0 for the first stress period of a simulation.
  • irdflag (int or list of integers (len = NPER)) – For each stress period, an integer value for printing input data specified for this stress period. If IRDFLG = 0, input data for this stress period will be printed. If IRDFLG > 0, then input data for this stress period will not be printed.
  • iptflag (int or list of integers (len = NPER)) – For each stress period, an integer value for printing streamflow- routing results during this stress period. If IPTFLG = 0, or whenever the variable ICBCFL or “Save Budget” is specified in Output Control, the results for specified time steps during this stress period will be printed. If IPTFLG > 0, then the results during this stress period will not be printed.
  • extension (string) – Filename extension (default is ‘sfr’)
  • unit_number (int) – File unit number (default is None).
  • filenames (str or list of str) – Filenames to use for the package and the output files. If filenames=None the package name will be created using the model name and package extension and the cbc output and sfr output name will be created using the model name and .cbc the .sfr.bin/.sfr.out extensions (for example, modflowtest.cbc, and modflowtest.sfr.bin), if ipakcbc and istcb2 are numbers greater than zero. If a single string is passed the package name will be set to the string and other uzf output files will be set to the model name with the appropriate output file extensions. To define the names for all package files (input and output) the length of the list of strings should be 3. Default is None.
outlets

Contains the outlet for each SFR segment; format is {per: {segment: outlet}} This attribute is created by the get_outlets() method.

Type:nested dictionary
outsegs

Each array is of shape nss rows x maximum of nss columns. The first column contains the SFR segments, the second column contains the outsegs of those segments; the third column the outsegs of the outsegs, and so on, until all outlets have been encountered, or nss is reached. The latter case indicates circular routing. This attribute is created by the get_outlets() method.

Type:dictionary of arrays

Notes

Parameters are not supported in FloPy.

MODFLOW-OWHM is not supported.

The Ground-Water Transport (GWT) process is not supported.

Limitations on which features are supported…

Examples

>>> import flopy
>>> ml = flopy.modflow.Modflow()
>>> sfr2 = flopy.modflow.ModflowSfr2(ml, ...)
assign_layers(adjust_botms=False, pad=1.0)[source]

Assigns the appropriate layer for each SFR reach, based on cell bottoms at location of reach.

Parameters:
  • adjust_botms (bool) – Streambed bottom elevations below the model bottom will cause an error in MODFLOW. If True, adjust bottom elevations in lowest layer of the model so they are at least pad distance below any co-located streambed elevations.
  • pad (scalar) – Minimum distance below streambed bottom to set any conflicting model bottom elevations.

Notes

Streambed bottom = strtop - strthick This routine updates the elevations in the botm array of the flopy.model.ModflowDis instance. To produce a new DIS package file, model.write() or flopy.model.ModflowDis.write() must be run.

check(f=None, verbose=True, level=1, checktype=None)[source]

Check sfr2 package data for common errors.

Parameters:
  • f (str or file handle) – String defining file name or file handle for summary file of check method output. If a string is passed a file handle is created. If f is None, check method does not write results to a summary file. (default is None)
  • verbose (bool) – Boolean flag used to determine if check method results are written to the screen
  • level (int) – Check method analysis level. If level=0, summary checks are performed. If level=1, full checks are performed.
Returns:

Return type:

None

Examples

>>> import flopy
>>> m = flopy.modflow.Modflow.load('model.nam')
>>> m.sfr2.check()
const
dataset_5

auto-update itmp so it is consistent with segment_data.

deactivate_ibound_above()[source]

Sets ibound to 0 for all cells above active SFR cells.

Parameters:none

Notes

This routine updates the ibound array of the flopy.model.ModflowBas6 instance. To produce a new BAS6 package file, model.write() or flopy.model.ModflowBas6.write() must be run.

default_value = 0.0
df
export(f, **kwargs)[source]

Method to export a package to netcdf or shapefile based on the extension of the file name (.shp for shapefile, .nc for netcdf)

Parameters:
  • f (str) – filename
  • kwargs (keyword arguments) –
    modelgrid : flopy.discretization.Grid instance
    user supplied modelgrid which can be used for exporting in lieu of the modelgrid associated with the model object
Returns:

Return type:

None or Netcdf object

export_linkages(f, **kwargs)[source]

Export linework shapefile showing all routing connections between SFR reaches. A length field containing the distance between connected reaches can be used to filter for the longest connections in a GIS.

export_outlets(f, **kwargs)[source]

Export point shapefile showing locations where streamflow is leaving the model (outset=0).

export_transient_variable(f, varname, **kwargs)[source]

Export point shapefile showing locations with a given segment_data variable applied. For example, segments where streamflow is entering or leaving the upstream end of a stream segment (FLOW) or where RUNOFF is applied. Cell centroids of the first reach of segments with non-zero terms of varname are exported; values of varname are exported by stress period in the attribute fields (e.g. flow0, flow1, flow2… for FLOW in stress periods 0, 1, 2…

Parameters:
  • f (str, filename) –
  • varname (str) – Variable in SFR Package dataset 6a (see SFR package documentation)
static get_default_reach_dtype(structured=True)[source]
static get_default_segment_dtype()[source]
static get_empty_reach_data(nreaches=0, aux_names=None, structured=True, default_value=0.0)[source]
static get_empty_segment_data(nsegments=0, aux_names=None, default_value=0.0)[source]
get_outlets(level=0, verbose=True)[source]

Traces all routing connections from each headwater to the outlet.

get_slopes(default_slope=0.001, minimum_slope=0.0001, maximum_slope=1.0)[source]

Compute slopes by reach using values in strtop (streambed top) and rchlen (reach length) columns of reach_data. The slope for a reach n is computed as strtop(n+1) - strtop(n) / rchlen(n). Slopes for outlet reaches are set equal to a default value (default_slope). Populates the slope column in reach_data.

Parameters:
  • default_slope (float) – Slope value applied to outlet reaches (where water leaves the model). Default value is 0.001
  • minimum_slope (float) – Assigned to reaches with computed slopes less than this value. This ensures that the Manning’s equation won’t produce unreasonable values of stage (in other words, that stage is consistent with assumption that streamflow is primarily drive by the streambed gradient). Default value is 0.0001.
  • maximum_slope (float) – Assigned to reaches with computed slopes more than this value. Default value is 1.
get_upsegs()[source]

From segment_data, returns nested dict of all upstream segments by segment, by stress period.

Returns:all_upsegs – Nested dictionary of form {stress period: {segment: [list of upsegs]}}
Return type:dict

Notes

This method will not work if there are instances of circular routing.

get_variable_by_stress_period(varname)[source]
graph

Dictionary of routing connections between segments.

heading = '# Streamflow-Routing (SFR2) file for MODFLOW, generated by Flopy'
len_const = {1: 1.486, 2: 1.0, 3: 100.0}
classmethod load(f, model, nper=None, gwt=False, nsol=1, ext_unit_dict=None)[source]

Default load method for standard boundary packages.

nper
nsfrpar = 0
nss
nstrm
paths
plot_path(start_seg=None, end_seg=0, plot_segment_lines=True)[source]

Plot a profile of streambed elevation and model top along a path of segments.

Parameters:
  • start_seg (int) – Number of first segment in path.
  • end_seg (int) – Number of last segment in path (defaults to 0/outlet).
  • plot_segment_lines (bool) – Controls plotting of segment end locations along profile. (default True)
Returns:

ax

Return type:

matplotlib.axes._subplots.AxesSubplot object

renumber_segments()[source]

Renumber segments so that segment numbering is continuous and always increases in the downstream direction. This may speed convergence of the NWT solver in some situations.

Returns:r
Return type:dictionary mapping old segment numbers to new
repair_outsegs()[source]
reset_reaches()[source]
set_outreaches()[source]

Determine the outreach for each SFR reach (requires a reachID column in reach_data). Uses the segment routing specified for the first stress period to route reaches between segments.

time_const = {1: 1.0, 2: 60.0, 3: 3600.0, 4: 86400.0, 5: 31557600.0}
write_file(filename=None)[source]

Write the package file.

Returns:
Return type:None
class check(sfrpackage, verbose=True, level=1)[source]

Bases: object

Check SFR2 package for common errors

Parameters:
  • sfrpackage (object) – Instance of Flopy ModflowSfr2 class.
  • verbose (bool) – Boolean flag used to determine if check method results are written to the screen
  • level (int) – Check method analysis level. If level=0, summary checks are performed. If level=1, full checks are performed.

Notes

Daniel Feinstein’s top 10 SFR problems (7/16/2014): 1) cell gaps btw adjacent reaches in a single segment 2) cell gaps btw routed segments. possibly because of re-entry problems at domain edge 3) adjacent reaches with STOP sloping the wrong way 4) routed segments with end/start sloping the wrong way 5) STOP>TOP1 violations, i.e.,floaters 6) STOP<<TOP1 violations, i.e., exaggerated incisions 7) segments that end within one diagonal cell distance from another segment, inviting linkage 8) circular routing of segments 9) multiple reaches with non-zero conductance in a single cell 10) reaches in inactive cells

Also after running the model they will want to check for backwater effects.

elevations(min_strtop=-10, max_strtop=15000)[source]

Checks streambed elevations for downstream rises and inconsistencies with model grid

for_nans()[source]

Check for nans in reach or segment data

numbering()[source]

Checks for continuity in segment and reach numbering

overlapping_conductance(tol=1e-06)[source]

Checks for multiple SFR reaches in one cell; and whether more than one reach has Cond > 0

routing()[source]

Checks for breaks in routing and does comprehensive check for circular routing

run_all()[source]
slope(minimum_slope=0.0001, maximum_slope=1.0)[source]

Checks that streambed slopes are greater than or equal to a specified minimum value. Low slope values can cause “backup” or unrealistic stream stages with icalc options where stage is computed.

find_path(graph, start, end=0)[source]

Get a path through the routing network, from a segment to an outlet.

Parameters:
  • graph (dict) – Dictionary of seg : outseg numbers
  • start (int) – Starting segment
  • end (int) – Ending segment (default 0)
Returns:

path – List of segment numbers along routing path.

Return type:

list