[GRASS-SVN] r46403 - in grass-addons/grass7/raster: . r.threshold

svn_grass at osgeo.org svn_grass at osgeo.org
Tue May 24 06:49:28 EDT 2011


Author: madi
Date: 2011-05-24 03:49:28 -0700 (Tue, 24 May 2011)
New Revision: 46403

Added:
   grass-addons/grass7/raster/r.threshold/
   grass-addons/grass7/raster/r.threshold/description.html
   grass-addons/grass7/raster/r.threshold/r.threshold.py
Log:
Module to find optimal threshold to extract streams

Added: grass-addons/grass7/raster/r.threshold/description.html
===================================================================
--- grass-addons/grass7/raster/r.threshold/description.html	                        (rev 0)
+++ grass-addons/grass7/raster/r.threshold/description.html	2011-05-24 10:49:28 UTC (rev 46403)
@@ -0,0 +1,21 @@
+<h2>DESCRIPTION</h2>
+<em>r.threshold</em> It finds optimal threshold for stream extraction. 
+
+<h2>NOTES</h2>
+<p>It allows to find the optimal value of upslope area in order to extract the river network using r.stream.extract or r.watershed. Real streams depend on rainfall and infiltration rate, i.e. the same topography in different parts of the world yields different real stream networks. This approach provides a best guess about what makes sense when looking only at the DEM.
+
+<h2>EXAMPLE</h2>
+
+<p>r.threshold.py acc=accumulation_map
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r.stream.extract.html">r.stream.extract</a>, <a href="r.watershed.html">r.watershed</a>
+</em>
+
+<h2>AUTHOR</h2>
+<p>Margherita Di Leo (dileomargherita AT gmail DOT com)
+<p><i>Last changed: (Tue May 24 2011)</i>
+
+

Added: grass-addons/grass7/raster/r.threshold/r.threshold.py
===================================================================
--- grass-addons/grass7/raster/r.threshold/r.threshold.py	                        (rev 0)
+++ grass-addons/grass7/raster/r.threshold/r.threshold.py	2011-05-24 10:49:28 UTC (rev 46403)
@@ -0,0 +1,73 @@
+#!/usr/bin/env python
+
+################################################################################
+#
+# MODULE:       r.threshold.py
+#
+# AUTHOR(S):    Margherita Di Leo 
+#               
+# PURPOSE:      Find optimal threshold for stream extraction
+#
+# COPYRIGHT:    (c) 2011 by Margherita Di Leo and the GRASS Development Team
+#               dileomargherita at gmail.com
+#
+#               This program is free software under the GNU General Public
+#               License (>=v2). Read the file COPYING that comes with GRASS
+#               for details.              
+#
+################################################################################
+#%module
+#%  description: Find optimal threshold for stream extraction
+#%  keywords: raster
+#%end
+#%option
+#%  key: acc
+#%  type: string
+#%  gisprompt: old, raster, raster
+#%  key_desc: acc
+#%  description: Name of accumulation raster map 
+#%  required: yes
+#%END
+
+
+import grass.script as grass
+import grass.script.array as garray
+import os, sys
+import math
+import numpy as np
+
+if not os.environ.has_key("GISBASE"):
+    sys.exit("You must be in GRASS GIS to run this program.")
+
+def main():
+
+    stats = grass.read_command('r.stats', input = options['acc'], fs = 'space', nv = '*', nsteps = '1000', flags = 'Anc').split('\n')[:-1]
+
+    mappatella = np.zeros((len(stats),3),float)
+    
+    ''' mappatella is a matrix, in the first column the value of upslope area is stored, 
+in the second the number of cells, in the third the distance from origin is calculated '''
+ 
+    for i in range(len(stats)):
+        mappatella[i,0],  mappatella[i,1] = map(float, stats[i].split(' '))
+
+        # calculating distance from origin of each point; origin of the plot is in low left point 
+
+        mappatella[i,2] = math.sqrt((mappatella[i,0]**2) + (mappatella[i,1]**2))
+
+    area = mappatella[:,0]
+    num_cells = mappatella[:,1]
+    distance = mappatella[:,2]
+
+    index = np.where(distance==min(distance))
+    th = area[index]
+
+    grass.message("Suggested threshold is %d" % th )
+
+    grass.message( 'Done!' )	 
+
+if __name__ == "__main__":
+    options, flags = grass.parser()
+    sys.exit(main())
+
+


Property changes on: grass-addons/grass7/raster/r.threshold/r.threshold.py
___________________________________________________________________
Added: svn:executable
   + *



More information about the grass-commit mailing list