[GRASS-SVN] r67113 - in grass-addons/grass7/raster: . r.vector.ruggedness

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Dec 13 22:39:27 PST 2015


Author: spawley
Date: 2015-12-13 22:39:27 -0800 (Sun, 13 Dec 2015)
New Revision: 67113

Added:
   grass-addons/grass7/raster/r.vector.ruggedness/
   grass-addons/grass7/raster/r.vector.ruggedness/Makefile
   grass-addons/grass7/raster/r.vector.ruggedness/r.vector.ruggedness.html
   grass-addons/grass7/raster/r.vector.ruggedness/r.vector.ruggedness.py
Log:
First comit of new module r.vector.ruggedness

Added: grass-addons/grass7/raster/r.vector.ruggedness/Makefile
===================================================================
--- grass-addons/grass7/raster/r.vector.ruggedness/Makefile	                        (rev 0)
+++ grass-addons/grass7/raster/r.vector.ruggedness/Makefile	2015-12-14 06:39:27 UTC (rev 67113)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = r.vector.ruggedness
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script


Property changes on: grass-addons/grass7/raster/r.vector.ruggedness/Makefile
___________________________________________________________________
Added: svn:eol-style
   + native

Added: grass-addons/grass7/raster/r.vector.ruggedness/r.vector.ruggedness.html
===================================================================
--- grass-addons/grass7/raster/r.vector.ruggedness/r.vector.ruggedness.html	                        (rev 0)
+++ grass-addons/grass7/raster/r.vector.ruggedness/r.vector.ruggedness.html	2015-12-14 06:39:27 UTC (rev 67113)
@@ -0,0 +1,30 @@
+<h2>DESCRIPTION</h2>
+
+<em><b>r.vector.ruggedness</b></em> represents a measurement of terrain
+ruggedness based on the methodology conceived by Sappington et al.
+(2007). The measure is calculated by decomposing slope and aspect into
+3-dimensional vectors, and calculating the resultant vector magnitude
+within a user-specified moving window size, using <i>r.neighbors</i>.
+The user can specify neighborhood size to measure ruggedness across
+larger landscale scales. Neighborhood operations are performed using a
+rectangular window shape.
+
+<h2>NOTES</h2>
+
+<p>This script was adapted from the original Sappington et al. (2007)
+script.
+
+<h2>EXAMPLE</h2>
+
+r.vector.ruggedness elevation=srtm wsize=5 output=vrm
+
+<h2>REFERENCES</h2>
+
+Sappington, J.M., K.M. Longshore, and D.B. Thomson. 2007. Quantifying
+Landscape Ruggedness for Animal Habitat Analysis: A case Study Using
+Bighorn Sheep in the Mojave Desert. Journal of Wildlife Management.
+71(5): 1419 -1426.
+
+<h2>AUTHOR</h2>
+
+Steven Pawley <br><i>Last changed: Sunday 13 December 2015</i>
\ No newline at end of file


Property changes on: grass-addons/grass7/raster/r.vector.ruggedness/r.vector.ruggedness.html
___________________________________________________________________
Added: svn:eol-style
   + native

Added: grass-addons/grass7/raster/r.vector.ruggedness/r.vector.ruggedness.py
===================================================================
--- grass-addons/grass7/raster/r.vector.ruggedness/r.vector.ruggedness.py	                        (rev 0)
+++ grass-addons/grass7/raster/r.vector.ruggedness/r.vector.ruggedness.py	2015-12-14 06:39:27 UTC (rev 67113)
@@ -0,0 +1,130 @@
+#!/usr/bin/env python
+#
+##############################################################################
+#
+# MODULE:       Vector Ruggedness Measure
+#
+# AUTHOR(S):    Adaption of original Sappington et al. (2007) script
+#               by Steven Pawley
+#
+# PURPOSE:      This tool measures terrain ruggedness by calculating the vector
+#               ruggedness measure described in Sappington, J.M., K.M. Longshore,
+#               and D.B. Thomson. 2007. Quantifiying Landscape Ruggedness for
+#               Animal Habitat Anaysis: A case Study Using Bighorn Sheep in
+#               the Mojave Desert.
+#               Journal of Wildlife Management. 71(5): 1419 -1426.
+#
+# COPYRIGHT:    (C) 2015 Steven Pawley, and by the GRASS Development Team
+#
+# DATE:         21 April 2015
+#
+##############################################################################
+
+#%module
+#% description: Vector Ruggedness Measure
+#%end
+
+import grass.script as grass
+import random
+import string
+import atexit
+
+#%option G_OPT_R_INPUTS
+#% key: elevation
+#% label: DEM Raster Input
+#%end
+
+#%option
+#% key: size
+#% type: integer
+#% description: Size of neighbourhood
+#% answer: 3
+#% guisection: Required
+#%end
+
+#%option G_OPT_R_OUTPUTS
+#% key: output
+#% label: Vector Ruggedness Index Output
+#%end
+
+tmp_rast = []
+
+def cleanup():
+    for rast in tmp_rast:
+        grass.run_command("g.remove", name = rast, type = 'raster', flags = 'fb', quiet = True)
+
+def main():
+    # User specified variables
+    dem = options['elevation']
+    neighborhood_size = options['size']
+    OutRaster = options['output']
+
+    # Internal raster map names
+    SlopeRaster = 'tmp_' + ''.join([random.choice(string.ascii_letters + string.digits) for n in xrange(8)])
+    AspectRaster = 'tmp_' + ''.join([random.choice(string.ascii_letters + string.digits) for n in xrange(8)])
+    xyRaster = 'tmp_' + ''.join([random.choice(string.ascii_letters + string.digits) for n in xrange(8)])
+    zRaster = 'tmp_' + ''.join([random.choice(string.ascii_letters + string.digits) for n in xrange(8)])
+    xRaster = 'tmp_' + ''.join([random.choice(string.ascii_letters + string.digits) for n in xrange(8)])
+    yRaster = 'tmp_' + ''.join([random.choice(string.ascii_letters + string.digits) for n in xrange(8)])
+    xSumRaster = 'tmp_' + ''.join([random.choice(string.ascii_letters + string.digits) for n in xrange(8)])
+    ySumRaster = 'tmp_' + ''.join([random.choice(string.ascii_letters + string.digits) for n in xrange(8)])
+    zSumRaster = 'tmp_' + ''.join([random.choice(string.ascii_letters + string.digits) for n in xrange(8)])
+    ResultRaster = 'tmp_' + ''.join([random.choice(string.ascii_letters + string.digits) for n in xrange(8)])
+
+    tmp_rast.append(SlopeRaster)
+    tmp_rast.append(AspectRaster)
+    tmp_rast.append(xyRaster)
+    tmp_rast.append(zRaster)
+    tmp_rast.append(xRaster)
+    tmp_rast.append(yRaster)
+    tmp_rast.append(xSumRaster)
+    tmp_rast.append(ySumRaster)
+    tmp_rast.append(zSumRaster)
+    tmp_rast.append(ResultRaster)
+
+    # Create Slope and Aspect rasters
+    grass.message("Calculating slope and aspect...")
+    grass.run_command("r.slope.aspect",
+                      elevation = dem,
+                      slope = SlopeRaster,
+                      aspect = AspectRaster,
+                      format = "degrees",
+                      precision = "FCELL",
+                      zscale = 1.0,
+                      min_slope = 0.0,
+                      quiet = True)
+
+    # Calculate x y and z rasters
+    # Note - GRASS sin/cos functions differ from ArcGIS which expects input grid in radians, whereas GRASS functions expect degrees
+    # No need to convert slope and aspect to radians as in the original ArcGIS script
+    grass.message("Calculating x, y, and z rasters...")
+    grass.mapcalc('{x} = sin({a})'.format(x=xyRaster, a=SlopeRaster))
+    grass.mapcalc('{x} = cos({a})'.format(x=zRaster, a=SlopeRaster))
+    grass.mapcalc('{x} = sin({a}) * {b}'.format(x=xRaster, a=AspectRaster, b=xyRaster))
+    grass.mapcalc('{x} = cos({a}) * {b}'.format(x=yRaster, a=AspectRaster, b=xyRaster))
+
+    # Calculate sums of x, y, and z rasters for selected neighborhood size
+    grass.message("Calculating sums of x, y, and z rasters in selected neighborhood...")
+    grass.run_command("r.neighbors", input = xRaster, output = xSumRaster, method = "average", size = neighborhood_size)
+    grass.run_command("r.neighbors", input = yRaster, output = ySumRaster, method = "average", size = neighborhood_size)
+    grass.run_command("r.neighbors", input = zRaster, output = zSumRaster, method = "average", size = neighborhood_size)
+
+    # Calculate the resultant vector
+    # Modified from the original script to multiple each SumRaster by the n neighborhood cells to get the sum
+    grass.message("Calculating the resultant vector...")
+    maxValue = int(neighborhood_size) * int(neighborhood_size)
+    grass.mapcalc('{x} = sqrt(({a}*{d})^2 + ({b}*{d})^2 + ({c}*{d})^2)'.format(x=ResultRaster, a=xSumRaster, b=ySumRaster, c=zSumRaster, d=maxValue))
+
+    # Calculate the Ruggedness raster
+    grass.message("Calculating the final ruggedness raster...")
+    grass.mapcalc('{x} = 1-({a} / {b})'.format(x=OutRaster, a=ResultRaster, b=maxValue))
+
+    # Set the default color table
+    grass.run_command("r.colors", flags = 'e', map = OutRaster, color = "ryb")
+
+    return 0
+
+if __name__ == "__main__":
+    options, flags = grass.parser()
+    atexit.register(cleanup)
+    main()


Property changes on: grass-addons/grass7/raster/r.vector.ruggedness/r.vector.ruggedness.py
___________________________________________________________________
Added: svn:executable
   + *
Added: svn:eol-style
   + native



More information about the grass-commit mailing list