SFRmaker is a python package for automating construction of stream flow routing networks from hydrography data. Hydrography are input from a polyline shapefile and intersected with a structured grid defined using a Flopy SpatialReference
instance. Attribute data are supplied via .dbf
files (NHDPlus input option) or via specified fields in the hydrography shapefile. Line fragments representing intersections between the flowlines and model grid cells are converted to SFR reaches using the supplied attribute data. MODFLOW-NWT/2005 or MODFLOW-6 SFR package input can then be written, along with shapefiles for visualizing the SFR package dataset.
import flopy
import sfrmaker
- alternatively,
lines
can also be created from a shapefile or dataframe containing LineString features representing streams - see input data requirements below for more details
lns = sfrmaker.lines.from_NHDPlus_v2(NHDFlowlines='NHDFlowlines.shp',
PlusFlowlineVAA='PlusFlowlineVAA.dbf',
PlusFlow='PlusFlow.dbf',
elevslope='elevslope.dbf',
filter='data/grid.shp')
- when creating
lines
from a shapefile or dataframe, attribute field or column names can be supplied in lieu of the NHDPlus attribute tables (.dbf files).
lns = lines.from_shapefile(flowlines_file,
id_column='COMID',
routing_column='tocomid',
width1_column='width1',
width2_column='width2',
up_elevation_column='elevupsmo',
dn_elevation_column='elevdnsmo',
name_column='GNIS_NAME',
attr_length_units='feet',
attr_height_units='feet')
sr = flopy.utils.SpatialReference(delr=np.ones(160)*250,
delc=np.ones(112)*250,
lenuni=1,
xll=682688, yll=5139052, rotation=0,
proj_str='epsg:26715')
- can be created from a shapefile or
SpatialReference
. - an
active_area
polygon defines the area within the grid where SFR will be populated - See example scripts in
Examples/
for more details.
grd = StructuredGrid.from_shapefile(shapefile='Examples/data/badriver/grid.shp',
icol='i',
jcol='j',
active_area='Examples/data/badriver/active_area.shp'.format(data_dir)
)
- results in an
sfrdata
class instance
sfr = lns.to_sfr(sr=sr)
or
sfr = lns.to_sfr(grid=grd)
sfr.write_package('model.sfr')
sfr.write_package('model.sfr6', version='mf6')
sfr.export_cells('sfr_cells.shp')
sfr.export_outlets('sfr_outlets.shp')
sfr.export_transient_variable('flow', 'sfr_inlets.shp') # inflows to SFR network
sfr.export_lines('sfr_lines.shp')
sfr.export_routing('sfr_routing.shp')
Python versions:
SFRmaker requires Python 3.6 (or higher)
Dependencies:
pyyaml
numpy
pandas
fiona
rasterio
rasterstats
shapely
pyproj
rtree
flopy
Download and install the Anaconda python distribution.
Open an Anaconda Command Prompt on Windows or a terminal window on OSX.
From the root folder for the package (that contains requirements.yml
), install the above packages from requirements.yml
.
conda env create -f requirements.yml
activate the environment:
conda activate sfrmaker
from the root folder for the package (that contains setup.py
):
python setup.py install
Instead of copying the source code to the python site_packages
folder, this option creates a link so that python uses the source code in-situ.
from the root folder for the package (that contains setup.py
):
pip install -e .
-
Available at http://www.horizon-systems.com/NHDPlus/NHDPlusV2_data.php
-
Archives needed/relevant files:
-
NHDPlusV21_XX_YY_NHDSnapshot_.7z**
- NHDFcode.dbf
- NHDFlowline.dbf, .prj, .shp, .shx
-
NHDPlusV21_XX_YY_NHDPlusAttributes_.7z**
- elevslope.dbf
- PlusFlow.dbf
- PlusFlowlineVAA.dbf
-
If your model domain encompasses multiple drainage areas, each type of NHDPlus file (e.g. NHDFlowline.shp, PlusFlow.dbf, etc.) can be supplied as a list. e.g.
NHDFlowlines=['<path to drainage area 1>/NHDFlowlines.shp', '<path to drainage area 2>/NHDFlowlines.shp'... ]
Notes:
- XX is Drainage Area ID (e.g., GL for Great Lakes) and YY is the Vector Processing Unit (VPU; e.g. 04) in the above (see NHDPlus website for details).
-
Any Polyline shapefile can be supplied in lieu of NHDPlus, but it must have the following columns, as shown in the second example:
flowlines_file: path to shapefile
id_column: unique identifier for each polyline
routing_column: downstream connection (ID), 0 if none
width1_column: channel width at start of line, in attr\_length\_units
(optional)
width2_column: channel width at end of line, in attr_length_units
(optional)
up_elevation_column: streambed elevation at start of line, in attr_height_units
dn_elevation_column: streambed elevation at end of line, in attr_height_units
name_column: stream name (optional)
attr_length_units: channel width units
attr_height_units: streambed elevation units
is supplied by creating a flopy.utils.SpatialReference
instance or via a shapefile, as shown in the examples.
from the Examples folder:
python make_sfr.py
This creates an sfr package and adds it to the model in Examples/data/badriver/tylerforks
.
Shapefiles for visualization of the sfr package are written to Examples/temp
.