Skip to content
Alan D. Snow edited this page Jun 1, 2016 · 1 revision

Function definition:

#How to import
from AutoRoutePy.prepare import prepare_autoroute_single_folder
#Function
prepare_autoroute_single_folder(sub_folder,
                                autoroute_executable_location,
                                stream_network_shapefile,
                                land_use_raster="",
                                manning_n_table="",
                                dem_extension='img',
                                river_id='COMID',
                                slope_id='SLOPE',
                                streamflow_id="",
                                default_manning_n=0.035,
                                return_period="",
                                return_period_file="",
                                rapid_output_file="",
                                date_peak_search_start=None,
                                date_peak_search_end=None)
Variable Data Type Description Default
watershed_folder String Main directory where the sub folders with elevation DEM files are stored.
autoroute_executable_location String Path to AutoRoute executable.
stream_network_shapefile String Path to stream network shapefile with unique id and slope for each stream segment.
land_use_raster String (Optional) Land use raster covering the entire watershed domain whereby Manning's n rasters can be generated for the individual tiles.
manning_n_table String (Optional) Table of values to convert land use raster values to Manning's n values. NOTE: These are available in the AutoRoute repository.
dem_extension String (Optional) This is the extension of the DEM raster you are using (e.g. tif, asc, img ...). "img"
river_id String (Optional) This is the unique identifier field in the stream network shapefile. "COMID"
slope_id String (Optional) This is the slope field in the stream network shapefile. "SLOPE"
streamflow_id String (Optional) This is the streamflow peak field in the stream network shapefile.
default_manning_n Float (Optional) This is the value of Mannning's n used in the simulation when there are missing values or no Manning's n raster. 0.035
return_period String (Optional) This is the value of the field in the return period file generated by RAPIDpy. Valid values include: 'max_flow','return_period_20','return_period_10', and 'return_period_2'.
return_period_file String (Optional) This is the path to the return period file generated by RAPIDpy.
rapid_output_file String (Optional) This is the path to a CF compliant RAPID Qout output file.
date_peak_search_start datetime (Optional) This constrains the start of the search for the peak in the RAPID Qout file.
date_peak_search_end datetime (Optional) This constrains the end of the search for the peak in the RAPID Qout file.

Usage Examples:

Here are examples of using the workflow to prepare input for AutoRoute. This requires each elevation DEM file to be inside of its own folder within the main watershed folder.

WARNING: The land use raster must be in the same projection as your elevation raster! If it is not in the same projection, either reproject using a GIS tool or use the reproject_lu_raster function (from RAPIDpy.prepare import reproject_lu_raster).

####Mode 1: Basic (NO STREAMFLOW) In this example, it shows how to prepare inputs with just an elevation DEM and stream network shapefile.

from AutoRoutePy.prepare import prepare_autoroute_single_folder
prepare_autoroute_single_folder(sub_folder='/autoroute-io/input/watershed_directory/sub_directory',
                                autoroute_executable_location='/AutoRoute/src/autoroute',
                                stream_network_shapefile='/path/to/river_network.shp',
                                #dem_extension='img',
                                #river_id='COMID',
                                #slope_id='SLOPE',
                                #default_manning_n=0.035,
                                )

####Mode 2: Basic+Land Use (NO STREAMFLOW) WARNING: The land use raster must be in the same projection as your elevation raster! If it is not in the same projection, either reproject using a GIS tool or use this script.

from AutoRoutePy.prepare import reproject_lu_raster

dem_raster = '/autoroute-io/input/watershed-directory/sub_area-directory/elevation.img'
land_use_raster = '/autoroute_prepare/watershed-directory/NLCD2011_LC.tif'
reprojected_land_use_raster = '/autoroute_prepare/watershed-directory/NLCD2011_LC_repr.tif'

reproject_lu_raster(dem_raster, land_use_raster, reprojected_land_use_raster)

Once your land use raster is in the correct projection, use this process to generate the manning n raster.

from AutoRoutePy.prepare import prepare_autoroute_single_folder

land_use_to_mannning_n_table = '/AutoRoute/mannings_n_tabes/AR_Manning_n_for_NLCD_LOW.txt'

prepare_autoroute_single_folder(sub_folder='/autoroute-io/input/watershed_directory/sub_directory',
                                autoroute_executable_location='/AutoRoute/src/autoroute',
                                stream_network_shapefile='/path/to/river_network.shp',
                                land_use_raster=reprojected_land_use_raster,
                                manning_n_table=land_use_to_mannning_n_table,
                                #dem_extension='img',
                                #river_id='COMID',
                                #slope_id='SLOPE',
                                #default_manning_n=0.035,
                                )

####Mode 3: Streamflow Note: You can run with or without land use as shown in Mode 1 & Mode 2. This is the same for Mode 3, however only the basic mode will be shown here.

#####Mode 3.1: Streamflow from RAPID output In this mode it will search for the peak from the entire simulation unless bounds are given from date_peak_search_start or from the date_peak_search_end.

from datetime import datetime
from AutoRoutePy.prepare import prepare_autoroute_single_folder

prepare_autoroute_single_folder(watershed_folder='/autoroute-io/input/watershed_directory/sub_directory',
                                autoroute_executable_location='/AutoRoute/src/autoroute',
                                stream_network_shapefile='/path/to/river_network.shp',
                                #dem_extension='img',
                                #river_id='COMID',
                                #slope_id='SLOPE',
                                #default_manning_n=0.035,
                                rapid_output_file="/path/to/Qout.nc",
                                #date_peak_search_start=datetime(1990, 1, 1), #optional
                                #date_peak_search_end=datetime(1990, 3, 5), #optional
                                )

#####Mode 3.2: Streamflow from shapefile field

from AutoRoutePy.prepare import prepare_autoroute_single_folder

prepare_autoroute_single_folder(watershed_folder='/autoroute-io/input/watershed_directory/sub_directory',
                                autoroute_executable_location='/AutoRoute/src/autoroute',
                                stream_network_shapefile='/path/to/river_network.shp',
                                #dem_extension='img',
                                #river_id='COMID',
                                #slope_id='SLOPE',
                                streamflow_id='Flow_500',
                                #default_manning_n=0.035,
                                )

#####Mode 3.3: Streamflow from return period file

from AutoRoutePy.prepare import prepare_autoroute_single_folder

prepare_autoroute_single_folder(watershed_folder='/autoroute-io/input/watershed_directory/sub_directory',
                                autoroute_executable_location='/AutoRoute/src/autoroute',
                                stream_network_shapefile='/path/to/river_network.shp',
                                #dem_extension='img',
                                #river_id='COMID',
                                #slope_id='SLOPE',
                                #default_manning_n=0.035,
                                #NOTE: valid return_periods -> 'max_flow','return_period_20','return_period_10','return_period_2'
                                return_period="return_period_20", 
                                return_period_file="/path/to/return_period.nc", 
                                )