[GRASS-SVN] r61122 - grass-addons/grass7/raster/r.valley.bottom

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Jul 2 11:22:56 PDT 2014


Author: hellik
Date: 2014-07-02 11:22:56 -0700 (Wed, 02 Jul 2014)
New Revision: 61122

Modified:
   grass-addons/grass7/raster/r.valley.bottom/r.valley.bottom.html
   grass-addons/grass7/raster/r.valley.bottom/r.valley.bottom.py
Log:
r.valley.bottom: add flag s for a square moving window in calculations

Modified: grass-addons/grass7/raster/r.valley.bottom/r.valley.bottom.html
===================================================================
--- grass-addons/grass7/raster/r.valley.bottom/r.valley.bottom.html	2014-07-02 17:16:24 UTC (rev 61121)
+++ grass-addons/grass7/raster/r.valley.bottom/r.valley.bottom.html	2014-07-02 18:22:56 UTC (rev 61122)
@@ -6,6 +6,11 @@
 raster</b> map. 
 </p>
 
+<p>
+Default moving window is cells in 8 directions. With the <b>-s</b> flag 
+a square moving window is used in calculations.
+</p>
+
 <h2>EXAMPLE</h2>
 
 <div class="code">

Modified: grass-addons/grass7/raster/r.valley.bottom/r.valley.bottom.py
===================================================================
--- grass-addons/grass7/raster/r.valley.bottom/r.valley.bottom.py	2014-07-02 17:16:24 UTC (rev 61121)
+++ grass-addons/grass7/raster/r.valley.bottom/r.valley.bottom.py	2014-07-02 18:22:56 UTC (rev 61122)
@@ -1,4 +1,5 @@
 #!/usr/bin/env python
+# -*- coding: utf-8
 
 """
 MODULE:    r.valley.bottom
@@ -30,6 +31,12 @@
 #% required: yes
 #%end
 
+#%flag
+#% key: s
+#% description: Use square moving window instead of moving window in 8 directions
+#%end
+
+
 	##################################################################################
 	# TODO: Design the script independent of input elevation raster resolution. At 
 	# the moment the input elevation raster map must have a resolution of 25m 
@@ -48,7 +55,8 @@
 def main():
     r_elevation = options['elevation'].split('@')[0] # elevation raster
     r_slope_degree = r_elevation+'_slope_degree' # slope (percent) step 1
-
+    moving_window_square = flags['s']
+	
 	##################################################################################
 	# Region settings	
     current_region = grass.region()
@@ -114,18 +122,34 @@
     grass.message( "..." )
     grass.mapcalc("elevation_step1 = $r_elevation", 
                                      r_elevation = r_elevation)
+
+    if moving_window_square :
+
+        offsets1 = [d
+             for j in xrange(1,3+1)
+             for i in [j,-j]
+             for d in [(i,0),(i,1),(i,2),(i,3),(i,-1),(i,-2),(i,-3)]]	
+
+        grass.message( "..." )
+		 
+        terms = ["(elevation_step1[%d,%d] < elevation_step1)" % d
+             for d in offsets1]	
+		 
+        expr1 = "PCTL1 = (100.0 / 48.0) * (%s)" % " + ".join(terms)	
 	
-    offsets = [d
-         for j in xrange(1,3+1)
-         for i in [j,-j]
-         for d in [(i,0),(0,i),(i,i),(i,-i)]]	
+    else :
+									 
+        offsets1 = [d
+             for j in xrange(1,3+1)
+             for i in [j,-j]
+             for d in [(i,0),(0,i),(i,i),(i,-i)]]	
 
-    grass.message( "..." )
+        grass.message( "..." )
 		 
-    terms = ["(elevation_step1[%d,%d] < elevation_step1)" % d
-         for d in offsets]	
+        terms = ["(elevation_step1[%d,%d] < elevation_step1)" % d
+             for d in offsets1]	
 		 
-    expr1 = "PCTL1 = (100.0 / 24.0) * (%s)" % " + ".join(terms)
+        expr1 = "PCTL1 = (100.0 / 24.0) * (%s)" % " + ".join(terms)
 	
     grass.mapcalc( expr1 )
 	
@@ -174,21 +198,37 @@
     grass.message( "----" )
 
     # Calculation of elevation percentile PCTL2 step 2
-	# elevation of percentile step 2: radius of 3 cells
+	# elevation of percentile step 2: radius of 6 cells
     grass.message( "Step 2: Calculation of elevation percentile PCTL2" )
     grass.message( "..." )
+
+    if moving_window_square :
+
+        offsets2 = [d
+             for j in xrange(1,6+1)
+             for i in [j,-j]
+             for d in [(i,0),(i,1),(i,2),(i,3),(i,4),(i,5),(i,6),(i,-1),(i,-2),(i,-3),(i,-4),(i,-5),(i,-6)]]	
+
+        grass.message( "..." )
+		 
+        terms2 = ["(elevation_step1[%d,%d] < elevation_step1)" % d
+             for d in offsets2]	
+		 
+        expr2 = "PCTL2 = (100.0 / 168.0) * (%s)" % " + ".join(terms2)	
 	
-    offsets2 = [d
-         for j in xrange(1,6+1)
-         for i in [j,-j]
-         for d in [(i,0),(0,i),(i,i),(i,-i)]]	
+    else :	
+	
+        offsets2 = [d
+             for j in xrange(1,6+1)
+             for i in [j,-j]
+             for d in [(i,0),(0,i),(i,i),(i,-i)]]	
 
-    grass.message( "..." )
+        grass.message( "..." )
 		 
-    terms2 = ["(elevation_step1[%d,%d] < elevation_step1)" % d
-         for d in offsets2]	
+        terms2 = ["(elevation_step1[%d,%d] < elevation_step1)" % d
+             for d in offsets2]	
 		 
-    expr2 = "PCTL2 = (100.0 / 48.0) * (%s)" % " + ".join(terms2)
+        expr2 = "PCTL2 = (100.0 / 48.0) * (%s)" % " + ".join(terms2)
 	
     grass.mapcalc( expr2 )
     grass.run_command("g.remove", rast = "elevation_step1",
@@ -291,7 +331,7 @@
     grass.message( "----" )
 
 	# change resolution
-    grass.message( "Step 3: change to resolution to 3 x base resolution" )
+    grass.message( "Step 3: change to resolution of 3 x base resolution" )
     grass.run_command('g.region', res = Xres_step3, 
                                     flags = 'a')
 
@@ -307,18 +347,34 @@
     grass.message( "..." )
     grass.mapcalc("DEM_smoothed_step3_coarsed = DEM_smoothed_step3") 
 
-    offsets3 = [d
-         for j in xrange(1,6+1)
-         for i in [j,-j]
-         for d in [(i,0),(0,i),(i,i),(i,-i)]]	
+    if moving_window_square :	
 
-    grass.message( "..." )
+        offsets3 = [d
+             for j in xrange(1,6+1)
+             for i in [j,-j]
+             for d in [(i,0),(i,1),(i,2),(i,3),(i,4),(i,5),(i,6),(i,-1),(i,-2),(i,-3),(i,-4),(i,-5),(i,-6)]]	
+
+        grass.message( "..." )
 		 
-    terms3 = ["(DEM_smoothed_step3_coarsed[%d,%d] < DEM_smoothed_step3_coarsed)" % d
-         for d in offsets3]	
+        terms3 = ["(DEM_smoothed_step3_coarsed[%d,%d] < DEM_smoothed_step3_coarsed)" % d
+             for d in offsets3]
 		 
-    expr3 = "PCTL3 = (100.0 / 48.0) * (%s)" % " + ".join(terms3)
+        expr3 = "PCTL3 = (100.0 / 168.0) * (%s)" % " + ".join(terms3)
 	
+    else :		
+	
+        offsets3 = [d
+             for j in xrange(1,6+1)
+             for i in [j,-j]
+             for d in [(i,0),(0,i),(i,i),(i,-i)]]	
+
+        grass.message( "..." )
+		 
+        terms3 = ["(DEM_smoothed_step3_coarsed[%d,%d] < DEM_smoothed_step3_coarsed)" % d
+             for d in offsets3]	
+		 
+        expr3 = "PCTL3 = (100.0 / 48.0) * (%s)" % " + ".join(terms3)
+	
     grass.mapcalc( expr3 )
 
     grass.message( "Step 3: Calculation of elevation percentile PCTL3 done." )
@@ -472,18 +528,34 @@
     grass.message( "..." )
     grass.mapcalc("DEM_smoothed_step4_coarsed = DEM_smoothed_step4") 
 
-    offsets4 = [d
-         for j in xrange(1,6+1)
-         for i in [j,-j]
-         for d in [(i,0),(0,i),(i,i),(i,-i)]]	
+    if moving_window_square :
 
-    grass.message( "..." )
+        offsets4 = [d
+             for j in xrange(1,6+1)
+             for i in [j,-j]
+             for d in [(i,0),(i,1),(i,2),(i,3),(i,4),(i,5),(i,6),(i,-1),(i,-2),(i,-3),(i,-4),(i,-5),(i,-6)]]	
+
+        grass.message( "..." )
 		 
-    terms4 = ["(DEM_smoothed_step4_coarsed[%d,%d] < DEM_smoothed_step4_coarsed)" % d
-         for d in offsets4]	
+        terms4 = ["(DEM_smoothed_step4_coarsed[%d,%d] < DEM_smoothed_step4_coarsed)" % d
+             for d in offsets4]		
 		 
-    expr4 = "PCTL4 = (100.0 / 48.0) * (%s)" % " + ".join(terms4)
+        expr4 = "PCTL4 = (100.0 / 168.0) * (%s)" % " + ".join(terms4)	
 	
+    else :	
+	
+        offsets4 = [d
+             for j in xrange(1,6+1)
+             for i in [j,-j]
+             for d in [(i,0),(0,i),(i,i),(i,-i)]]	
+
+        grass.message( "..." )
+		 
+        terms4 = ["(DEM_smoothed_step4_coarsed[%d,%d] < DEM_smoothed_step4_coarsed)" % d
+             for d in offsets4]	
+		 
+        expr4 = "PCTL4 = (100.0 / 48.0) * (%s)" % " + ".join(terms4)
+	
     grass.mapcalc( expr4 )
 
     grass.message( "Step 4: Calculation of elevation percentile PCTL4 done." )



More information about the grass-commit mailing list