[GRASS-SVN] r71488 - grass-addons/grass7/raster/r.tri

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Sep 13 08:46:35 PDT 2017


Author: spawley
Date: 2017-09-13 08:46:35 -0700 (Wed, 13 Sep 2017)
New Revision: 71488

Modified:
   grass-addons/grass7/raster/r.tri/r.tri.html
   grass-addons/grass7/raster/r.tri/r.tri.py
Log:
r.tri standardized arguments similar to other GRASS tools. Minor manual updates.

Modified: grass-addons/grass7/raster/r.tri/r.tri.html
===================================================================
--- grass-addons/grass7/raster/r.tri/r.tri.html	2017-09-13 03:53:04 UTC (rev 71487)
+++ grass-addons/grass7/raster/r.tri/r.tri.html	2017-09-13 15:46:35 UTC (rev 71488)
@@ -1,19 +1,19 @@
 <h2>DESCRIPTION</h2>
 
-<i>r.tri </i>calculates the Terrain Ruggedness Index (TRI) of Riley et al. (1999). The index represents the mean change in elevation between a grid cell and its neighbours, over a user-specified moving window size. The original calculation in Riley et al., (1999)  used only a 3x3 neighbourhood and represented the sum of the absolute deviations between the center pixel and its immediate 8 neighbours. In r.tri, this calculation is modified so that the calculation can be extended over any scale by taking the mean of the absolute deviations. The results scale in a similar way to other packages that allow a multi-scale calculation (i.e., SAGA-GIS).
+<i>r.tri </i>calculates the Terrain Ruggedness Index (TRI) of Riley et al. (1999). The index represents the mean change in elevation between a grid cell and its neighbours, over a user-specified moving window size. The original calculation in Riley et al., (1999)  used only a 3x3 neighbourhood and represented the sum of the absolute deviations between the center pixel and its immediate 8 neighbours. In r.tri, this calculation is modified so that the calculation can be extended over any scale by taking the mean of the absolute deviations.
 
 <h2>NOTES</h2>
 <i>r.tri</i> produces fairly similar results to the average deviation of elevation values, apart from the center pixel is used in place of the mean. In practice, this produces a slightly 'less smoothed' result, which in some cases can better highlight smaller-scale terrain features.
 
-<h2>TODO</h2>
-Like in many GRASS GIS algorithms, null values are not evaluated at present and there will be an edge effect. The resulting TRI will not be calculated at the image edges so there will be missing pixels along the margins relative to the size of the input raster. There is potential to calculate TRI at the image edges by using a boolean operator to test for null values.
+Like in many GRASS GIS algorithms, cell padding is not performed automatically and there will be an edge effect. The resulting TRI will not be calculated at the image edges so there will be missing pixels along the margins relative to the size of the input raster. To avoid this the input DEM can be grown by the chosen radius that is to be used for the TRI calculation.
 
 <h2>EXAMPLE</h2>
-r.tri dem=srtm wsize=1 output=tri
+r.tri input=srtm size=1 output=tri
 
 <h2>REFERENCES</h2>
 Riley, S. J., S. D. DeGloria and R. Elliot (1999). A terrain ruggedness index that quantifies topographic heterogeneity, Intermountain Journal of Sciences, vol. 5, No. 1-4, 1999.
 
 <h2>AUTHOR</h2>
 Steven Pawley
-<br><i>Last changed: Tuesday 15 December 2015</i>
\ No newline at end of file
+
+<p><em>Last changed: $Date$</em></p>
\ No newline at end of file

Modified: grass-addons/grass7/raster/r.tri/r.tri.py
===================================================================
--- grass-addons/grass7/raster/r.tri/r.tri.py	2017-09-13 03:53:04 UTC (rev 71487)
+++ grass-addons/grass7/raster/r.tri/r.tri.py	2017-09-13 15:46:35 UTC (rev 71488)
@@ -6,12 +6,12 @@
 #
 # AUTHOR(S):    Steven Pawley
 #
-# PURPOSE:      Calculates the Terrain Ruggedness Index (TRI) of
-#                           Riley et al. (1999)
+# PURPOSE:      Simple script to calculate the Terrain Ruggedness Index (TRI)
+#               of Riley et al. (1999)
 #
-# COPYRIGHT:    (C) 2015 Steven Pawley, and by the GRASS Development Team
+# COPYRIGHT:    (C) 2015 Steven Pawley and by the GRASS Development Team
 #
-##############################################################################
+###############################################################################
 
 #%module
 #% description: Terrain Ruggedness Index
@@ -19,42 +19,44 @@
 
 #%option G_OPT_R_INPUT
 #% description: Input elevation raster
-#% key: dem
+#% key: input
 #% required : yes
 #%end
 
 #%option G_OPT_R_OUTPUT
 #% description: Output Terrain Ruggedness Index (TRI)
-#% key: tri
+#% key: output
 #% required : yes
 #%end
 
 #%option
-#% key: wsize
+#% key: size
 #% type: integer
-#% description: Radius of neighbourhood in cells
-#% answer: 1
+#% description: Size of neighbourhood in cells
+#% answer: 3
 #% guisection: Required
 #%end
 
 import sys
 import os
-import grass.script as grass
+import grass.script as gs
 
 def main():
-    dem = options['dem']
-    tri = options['tri']
-    wsize = int(options['wsize'])
-    neighcells = ((wsize*2+1)**2)-1
+    dem = options['input']
+    tri = options['output']
+    size = int(options['size'])
 
+    radius = (size-1)/2
+    neighcells = (size**2)-1
+
     # calculate TRI based on map calc statements
-    grass.message("Calculating the Topographic Ruggedness Index:")
+    gs.message("Calculating the Topographic Ruggedness Index:")
 
     # generate a list of spatial neighbourhood indexs for the chosen radius
     # ignoring the center cell
     offsets = []
-    for j in range(-wsize, wsize+1):
-        for i in range(-wsize, wsize+1):
+    for j in range(-radius, radius+1):
+        for i in range(-radius, radius+1):
             if (j,i) != (0,0):
                 offsets.append((j,i))
 
@@ -65,10 +67,10 @@
     expr = "$tri = (%s" % " + ".join(terms) + ") / $neighcells"
 
     # perform the r.mapcalc calculation with the moving window
-    grass.mapcalc(expr, tri=tri, dem=dem, neighcells=neighcells)
+    gs.mapcalc(expr, tri=tri, dem=dem, neighcells=neighcells)
     
     return 0
 
 if __name__ == "__main__":
-    options, flags = grass.parser()
+    options, flags = gs.parser()
     sys.exit(main())



More information about the grass-commit mailing list