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

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Aug 29 09:14:38 EDT 2011


Author: madi
Date: 2011-08-29 06:14:38 -0700 (Mon, 29 Aug 2011)
New Revision: 47939

Added:
   grass-addons/raster/r.threshold/
   grass-addons/raster/r.threshold/Makefile
   grass-addons/raster/r.threshold/r.threshold.html
   grass-addons/raster/r.threshold/r.threshold.py
Log:
backported from grass7

Added: grass-addons/raster/r.threshold/Makefile
===================================================================
--- grass-addons/raster/r.threshold/Makefile	                        (rev 0)
+++ grass-addons/raster/r.threshold/Makefile	2011-08-29 13:14:38 UTC (rev 47939)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = r.threshold
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script

Added: grass-addons/raster/r.threshold/r.threshold.html
===================================================================
--- grass-addons/raster/r.threshold/r.threshold.html	                        (rev 0)
+++ grass-addons/raster/r.threshold/r.threshold.html	2011-08-29 13:14:38 UTC (rev 47939)
@@ -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/raster/r.threshold/r.threshold.py
===================================================================
--- grass-addons/raster/r.threshold/r.threshold.py	                        (rev 0)
+++ grass-addons/raster/r.threshold/r.threshold.py	2011-08-29 13:14:38 UTC (rev 47939)
@@ -0,0 +1,75 @@
+#!/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 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]
+
+    if th < 0:
+        grass.message("Warning: Flow accumulation contains negative values")
+    else:
+        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/raster/r.threshold/r.threshold.py
___________________________________________________________________
Added: svn:executable
   + *



More information about the grass-commit mailing list