RHESSysWorkflows  1.33
Functions | Variables
DelineateWatershed Namespace Reference

Use GRASS GIS to delineate a watershed for study area defined by a DEM. More...

Functions

def positive_odd_integer (string)
 

Variables

float AREA_THRESHOLD = 0.2
 
tuple parser = argparse.ArgumentParser(description='Delineate watershed using GRASS GIS')
 
string help = 'The configuration file. Must define section "GRASS" and option "GISBASE"'
 
tuple args = parser.parse_args()
 
tuple cmdline = RHESSysMetadata.getCommandLine()
 
 configFile = None
 
tuple context = Context(args.projectDir, configFile)
 
tuple metadata = RHESSysMetadata.readRHESSysEntries(context)
 
tuple studyArea = RHESSysMetadata.readStudyAreaEntries(context)
 
tuple grassMetadata = RHESSysMetadata.readGRASSEntries(context)
 
list demRast = grassMetadata['dem_rast']
 
tuple demRows = int(studyArea['dem_rows'])
 
 flowDirDem = demRast
 
tuple modulePath = context.config.get('GRASS', 'MODULE_PATH')
 
tuple grassDbase = os.path.join(context.projectDir, metadata['grass_dbase'])
 
tuple grassConfig = GRASSConfig(context, grassDbase, metadata['grass_location'], metadata['grass_mapset'])
 
tuple grassLib = GRASSLib(grassConfig=grassConfig)
 
tuple result = grassLib.script.run_command('r.mask', flags='r')
 
 flags = None
 
list t_srs = studyArea['dem_srs']
 
string point = "%f|%f\n"
 
tuple findTheRiver = os.path.join(modulePath, 'r.findtheriver')
 
tuple snappedCoords = result.split()
 
tuple easting = float(snappedCoords[0])
 
tuple northing = float(snappedCoords[1])
 
string basinName = 'basin'
 
dictionary rWatershedOptions
 
float area = -1.0
 
tuple areaRegex = re.compile('^\|1\|.*\|(.*)\|$')
 
tuple pipe = grassLib.script.pipe_command('r.report', map=basinName, units='k')
 
tuple m = areaRegex.match(line)
 

Detailed Description

Use GRASS GIS to delineate a watershed for study area defined by a DEM.

This software is provided free of charge under the New BSD License. Please see the following license information:

Copyright (c) 2013, University of North Carolina at Chapel Hill All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Author
Brian Miles brian.nosp@m._mil.nosp@m.es@un.nosp@m.c.ed.nosp@m.u

Pre conditions

  1. Configuration file must define the following sections and values: 'GRASS', 'GISBASE'
  2. The following metadata entry(ies) must be present in the RHESSys section of the metadata associated with the project directory: grass_dbase grass_location grass_mapset
  3. The following metadata entry(ies) must be present in the study area section of the metadata associated with the project directory: dem_rows dem_srs gage_lat_wgs84 gage_lon_wgs84
  4. The following metadata entry(ies) must be present in the GRASS section of the metadata associated with the project directory: dem_rast
  5. The following metadata entry(ies) will be used if present in the GRASS section of the metadata associated with the project directory: stream_burned_dem_rast

Post conditions

  1. Will write the following entry(ies) to the RHESSys section of metadata associated with the project directory: gage_easting_raw (raw gage X coordinate in study area spatial reference system coordinates) gage_northing_raw (raw gage Y coordinate in study area spatial reference system coordinates) gage_easting_snapped (gage X coordinate, snapped to nearest stream pixel, in study area spatial reference system coordinates) gage_northing_snapped (gage Y coordinate, snapped to nearest stream pixel, in study area spatial reference system coordinates) watershed_threshold watershed_area_km watershed_area_estimate_km
  2. Will write the following entry(ies) to the GRASS section of metadata associated with the project directory: gage_vect gage_snapped_vect drain_rast [drainage direction map] uaa_rast [upslope accumulated area] basin_rast [delineated watershed boundary] subbasins_rast [sub basins within the watershed boundary] hillslope_rast [hillslopes within the watershed boundary] zone_rast [climate zones, same as hillslope_rast] streams_rast [streams within the watershed boundary] stream_reaches_rast [streams within the watershed boundary, labeled by reach ID] east_horizon_rast west_horizon_rast slope_rast aspect_rast K_rast [default Ksat map] m_rast [default decay of Ksat with depth map] zero_rast [Map where all cells are set to zero] one_rast [Map where all cells are set to one] xmap_rast ymap_rast

Usage:

1 DelineateWatershedForGRASSLocation.py -p /path/to/project_dir -t 500
Note
EcoHydroWorkflowLib configuration file must be specified by environmental variable 'ECOHYDROWORKFLOW_CFG', or -i option must be specified.
Todo:

fill pits in DEM with GRASS tool, have an argument to turn it off

Factor out gage snapping into a separate script?

This software is provided free of charge under the New BSD License. Please see the following license information:

Copyright (c) 2013, University of North Carolina at Chapel Hill All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Author
Brian Miles brian.nosp@m._mil.nosp@m.es@un.nosp@m.c.ed.nosp@m.u

Pre conditions

  1. Configuration file must define the following sections and values: 'GRASS', 'GISBASE'
  2. The following metadata entry(ies) must be present in the RHESSys section of the metadata associated with the project directory: grass_dbase grass_location grass_mapset
  3. The following metadata entry(ies) must be present in the study area section of the metadata associated with the project directory: dem_rows dem_srs gage_lat_wgs84 gage_lon_wgs84
  4. The following metadata entry(ies) must be present in the GRASS section of the metadata associated with the project directory: dem_rast
  5. The following metadata entry(ies) will be used if present in the GRASS section of the metadata associated with the project directory: stream_burned_dem_rast

Post conditions

  1. Will write the following entry(ies) to the RHESSys section of metadata associated with the project directory: gage_easting_raw (raw gage X coordinate in study area spatial reference system coordinates) gage_northing_raw (raw gage Y coordinate in study area spatial reference system coordinates) gage_easting_snapped (gage X coordinate, snapped to nearest stream pixel, in study area spatial reference system coordinates) gage_northing_snapped (gage Y coordinate, snapped to nearest stream pixel, in study area spatial reference system coordinates) watershed_threshold watershed_area_km watershed_area_estimate_km
  2. Will write the following entry(ies) to the GRASS section of metadata associated with the project directory: gage_vect gage_snapped_vect drain_rast [drainage direction map] uaa_rast [upslope accumulated area] basin_rast [delineated watershed boundary] subbasins_rast [sub basins within the watershed boundary] hillslope_rast [hillslopes within the watershed boundary] zone_rast [climate zones, same as hillslope_rast] streams_rast [streams within the watershed boundary] stream_reaches_rast [streams within the watershed boundary, labeled by reach ID] east_horizon_rast west_horizon_rast slope_rast aspect_rast K_rast [default Ksat map] m_rast [default decay of Ksat with depth map] zero_rast [Map where all cells are set to zero] one_rast [Map where all cells are set to one] xmap_rast ymap_rast

Usage:

1 DelineateWatershedForGRASSLocation.py -p /path/to/project_dir -t 500
Note
EcoHydroWorkflowLib configuration file must be specified by environmental variable 'ECOHYDROWORKFLOW_CFG', or -i option must be specified.
Todo:

fill pits in DEM with GRASS tool, have an argument to turn it off

Factor out gage snapping into a separate script?

Function Documentation

def DelineateWatershed.positive_odd_integer (   string)

Variable Documentation

tuple DelineateWatershed.area = -1.0
float DelineateWatershed.AREA_THRESHOLD = 0.2
tuple DelineateWatershed.areaRegex = re.compile('^\|1\|.*\|(.*)\|$')
tuple DelineateWatershed.args = parser.parse_args()
string DelineateWatershed.basinName = 'basin'
tuple DelineateWatershed.cmdline = RHESSysMetadata.getCommandLine()
DelineateWatershed.configFile = None
tuple DelineateWatershed.context = Context(args.projectDir, configFile)
list DelineateWatershed.demRast = grassMetadata['dem_rast']
tuple DelineateWatershed.demRows = int(studyArea['dem_rows'])
tuple DelineateWatershed.easting = float(snappedCoords[0])
tuple DelineateWatershed.findTheRiver = os.path.join(modulePath, 'r.findtheriver')
string DelineateWatershed.flags = None
list DelineateWatershed.flowDirDem = demRast
tuple DelineateWatershed.grassConfig = GRASSConfig(context, grassDbase, metadata['grass_location'], metadata['grass_mapset'])
tuple DelineateWatershed.grassDbase = os.path.join(context.projectDir, metadata['grass_dbase'])
tuple DelineateWatershed.grassLib = GRASSLib(grassConfig=grassConfig)
tuple DelineateWatershed.grassMetadata = RHESSysMetadata.readGRASSEntries(context)
string DelineateWatershed.help = 'The configuration file. Must define section "GRASS" and option "GISBASE"'
tuple DelineateWatershed.m = areaRegex.match(line)
tuple DelineateWatershed.metadata = RHESSysMetadata.readRHESSysEntries(context)
tuple DelineateWatershed.modulePath = context.config.get('GRASS', 'MODULE_PATH')
tuple DelineateWatershed.northing = float(snappedCoords[1])
tuple DelineateWatershed.parser = argparse.ArgumentParser(description='Delineate watershed using GRASS GIS')
tuple DelineateWatershed.pipe = grassLib.script.pipe_command('r.report', map=basinName, units='k')
string DelineateWatershed.point = "%f|%f\n"
tuple DelineateWatershed.result = grassLib.script.run_command('r.mask', flags='r')
dictionary DelineateWatershed.rWatershedOptions
Initial value:
1 = {'elevation': flowDirDem,
2  'threshold': args.threshold,
3  'basin': 'subbasins',
4  'half.basin': 'hillslopes',
5  'stream': 'streams',
6  'overwrite': args.overwrite,
7  'flags': flags }
tuple DelineateWatershed.snappedCoords = result.split()
tuple DelineateWatershed.studyArea = RHESSysMetadata.readStudyAreaEntries(context)
list DelineateWatershed.t_srs = studyArea['dem_srs']