[GRASS-SVN] r67111 - in grass-addons/grass7/raster: . r.terrain.texture

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Dec 13 21:53:27 PST 2015


Author: spawley
Date: 2015-12-13 21:53:27 -0800 (Sun, 13 Dec 2015)
New Revision: 67111

Added:
   grass-addons/grass7/raster/r.terrain.texture/
   grass-addons/grass7/raster/r.terrain.texture/Makefile
   grass-addons/grass7/raster/r.terrain.texture/r.terrain.texture.html
   grass-addons/grass7/raster/r.terrain.texture/r.terrain.texture.py
Log:
First commit of new module r.terrain.texture

Added: grass-addons/grass7/raster/r.terrain.texture/Makefile
===================================================================
--- grass-addons/grass7/raster/r.terrain.texture/Makefile	                        (rev 0)
+++ grass-addons/grass7/raster/r.terrain.texture/Makefile	2015-12-14 05:53:27 UTC (rev 67111)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = r.terrain.texture
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script


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

Added: grass-addons/grass7/raster/r.terrain.texture/r.terrain.texture.html
===================================================================
--- grass-addons/grass7/raster/r.terrain.texture/r.terrain.texture.html	                        (rev 0)
+++ grass-addons/grass7/raster/r.terrain.texture/r.terrain.texture.html	2015-12-14 05:53:27 UTC (rev 67111)
@@ -0,0 +1,23 @@
+<h2>DESCRIPTION</h2>
+
+<i>r.terrain.texture </i>calculates the Terrain Surface Texture of Iwahashi and Pike (2007). The calculation measures the frequency of peaks and pits in a DEM over a user specified window size. In practice, this measure represents terrain 'texture' or 'grain'.
+
+The calculation attempts to follow the description in Iwahashi and Pike (2007). Pits and peaks are firstly identified in the DEM by passing the DEM through a median filter with a 3x3 neighbourhood, and the pits and peaks are identified based on the difference between this smoothed DEM and the original terrain surface. By default, the algorithm uses a threshold of zero (i.e., any difference is identified as a pit or peak), however a user specified 'flatness' threshold can also be specified.
+
+The final terrain surface texture calculation involves <i>r.neighbors</i> to count the number of pits and peaks occurring within a user specified window size (default is 21 x 21, as per Iwahashi and Pike (2007)), and then this is converted into a percentage.
+
+<h2>NOTES</h2>
+<i>r.terrain.texture</i> performs best when using larger window sizes, either 21 x 21 or 11 x 11 represent reasonable parameters. 
+
+<h2>TODO</h2>
+The same approach was also used by Iwahashi and Pike (2007) to calculate terrain surface convexity, but using convexities and concavities rather than pits and peaks. The ability to calculate this will be implemented in the future. Also, these two morphometric variables can serve as a basis to classify the landscape into generic geomorphic categories.
+
+<h2>EXAMPLE</h2>
+r.terrain.texture.py elevation=DEM thres=0 pitdensity=Texture
+
+<h2>REFERENCES</h2>
+Iwahashi, J., and Pike, R.J. 2007. Automated classifications of topography from DEMs by an unsupervised nested-means algorithm and a three-part geometric signature. Geomorphology 86, 409-440.
+
+<h2>AUTHOR</h2>
+Steven Pawley
+<br><i>Last changed: Saturday 12 December 2015</i>
\ No newline at end of file


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

Added: grass-addons/grass7/raster/r.terrain.texture/r.terrain.texture.py
===================================================================
--- grass-addons/grass7/raster/r.terrain.texture/r.terrain.texture.py	                        (rev 0)
+++ grass-addons/grass7/raster/r.terrain.texture/r.terrain.texture.py	2015-12-14 05:53:27 UTC (rev 67111)
@@ -0,0 +1,101 @@
+#! /usr/bin/env python
+##############################################################################
+#
+# MODULE:       Pit and peak density
+#
+# AUTHOR(S):    Steven Pawley
+#
+# PURPOSE:      Calculates the density of pits and peaks in a DEM
+#                           Based on the methodology of Iwahashi & Pike (2007)
+#                           Automated classifications of topography from DEMs by an unsupervised
+#                           nested-means algorithm and a three-part geometric signature.
+#                           Geomorphology. 86, 409-440
+#
+# COPYRIGHT:    (C) 2015 Steven Pawley, and by the GRASS Development Team
+#
+##############################################################################
+
+#%module
+#% description: Pit and peak density
+#%end
+
+#%option G_OPT_R_INPUT
+#% description: Input elevation raster:
+#% key: elevation
+#% required : yes
+#%end
+
+#%option
+#% key: thres
+#% type: double
+#% description: Height threshold for pit and peak detection:
+#% answer: 1
+#% required: yes
+#%end
+
+#%option
+#% key: window
+#% type: double
+#% description: Size of counting window:
+#% answer: 21
+#% guisection: Optional
+#%end
+
+#%option G_OPT_R_OUTPUT
+#% description: Output Texture Image:
+#% key: pitdensity
+#% required : yes
+#%end
+
+import sys
+import random
+import string
+import grass.script as grass
+
+def main():
+    elevation = options['elevation']
+    thres = options['thres']
+    window = options['window']
+    pitdensity = options['pitdensity']
+
+    # Internal grid calculations - to be removed at end of process
+    median = 'tmp_' + ''.join([random.choice(string.ascii_letters + string.digits) for n in range(8)])
+    pitpeaks = 'tmp_' + ''.join([random.choice(string.ascii_letters + string.digits) for n in range(8)])
+    pitcount = 'tmp_' + ''.join([random.choice(string.ascii_letters + string.digits) for n in range(8)])
+    pitdensity_tmp = 'tmp_' + ''.join([random.choice(string.ascii_letters + string.digits) for n in range(8)])
+
+    # Smooth the DEM
+    grass.message("Smooth DEM with a 3x3 median filter:")
+    grass.run_command("r.neighbors", input = elevation, method = "median", size = 3, output = median)
+
+    # Extract the pits and peaks based on the threshold
+    grass.message("Extract pits and peaks:")
+    grass.mapcalc('{x} = if ( abs({dem}-{median})>{thres}, 1, null())'.format(x=pitpeaks, dem=elevation, thres=thres, median=median))
+
+    # Count the number of pits and peaks
+    grass.message("Count the number of pits and peaks in a moving window:")
+    grass.run_command("r.neighbors", input = pitpeaks, method = "count", size = window, output = pitcount, flags = 'c')
+
+    # Convert the pit and peak counts into a percentage
+    grass.message("Convert the pit and peak counts into a percentage:")
+    size = int(window)*int(window)
+    grass.mapcalc('{x} = 100*{pitcount}/float({size})'.format(x=pitdensity_tmp, pitcount=pitcount, size = size))
+ 
+    # Mask the raster to remove the background
+    grass.message("Mask the terrain surface texture with the input DEM:")
+    grass.run_command("r.mask", raster = elevation, maskcats = "*", layer = "1")
+    grass.mapcalc('{x} = {pitdensity_tmp}'.format(x=pitdensity, pitdensity_tmp=pitdensity_tmp))
+    grass.run_command("r.mask", raster = elevation, maskcats = "*", layer = "1", flags = 'r')
+
+    # Clean-up
+    grass.message("Deleting intermediate files:")
+    grass.run_command("g.remove", type="raster", name=median, flags="f", quiet=True)
+    grass.run_command("g.remove", type="raster", name=pitpeaks, flags="f", quiet=True)
+    grass.run_command("g.remove", type="raster", name=pitcount, flags="f", quiet=True)
+    grass.run_command("g.remove", type="raster", name=pitdensity_tmp, flags="f", quiet=True)
+
+    return 0
+
+if __name__ == "__main__":
+    options, flags = grass.parser()
+    sys.exit(main())


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



More information about the grass-commit mailing list