[GRASS-SVN] r73625 - in grass-addons/grass7/raster: . r.texture.tiled

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Oct 30 08:37:49 PDT 2018


Author: mlennert
Date: 2018-10-30 08:37:49 -0700 (Tue, 30 Oct 2018)
New Revision: 73625

Added:
   grass-addons/grass7/raster/r.texture.tiled/
   grass-addons/grass7/raster/r.texture.tiled/Makefile
   grass-addons/grass7/raster/r.texture.tiled/r.texture.tiled.html
   grass-addons/grass7/raster/r.texture.tiled/r.texture.tiled.py
Log:
r.texture.tiled: simple frontend to r.texture using GridModule to allow tiled parallelization

Added: grass-addons/grass7/raster/r.texture.tiled/Makefile
===================================================================
--- grass-addons/grass7/raster/r.texture.tiled/Makefile	                        (rev 0)
+++ grass-addons/grass7/raster/r.texture.tiled/Makefile	2018-10-30 15:37:49 UTC (rev 73625)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = r.texture.tiled
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script

Added: grass-addons/grass7/raster/r.texture.tiled/r.texture.tiled.html
===================================================================
--- grass-addons/grass7/raster/r.texture.tiled/r.texture.tiled.html	                        (rev 0)
+++ grass-addons/grass7/raster/r.texture.tiled/r.texture.tiled.html	2018-10-30 15:37:49 UTC (rev 73625)
@@ -0,0 +1,42 @@
+<h2>DESCRIPTION</h2>
+
+<em>r.texture.tiled</em> cuts a raster input map into tiles and runs 
+<a href="r.texture.html">r.texture</a> over these tiles before patching the
+result together into a single output raster map.
+
+<p>
+The overlap between tiles is calculated internally in order to correspond to 
+the window <b>size</b> in order to avoid any border effects.
+
+<p>
+Tiles can be defined with the <b>tile_width</b>, <b>tile_height</b> and 
+<b>overlap</b> parameters. If <b>processes</b> is higher than one, these tiles 
+will be processed in parallel.
+
+<h2>NOTES</h2>
+
+The parameters for texture calculation are identical to those of 
+<a href="r.texture.html">r.texture</a>. Currently, this module only allows
+calculating one texture feature at a time. The <b>n</b> flag allowing null 
+cells is automatically set in order to avoid issues at the border of the
+current computational region / of the input map.
+
+<h2>EXAMPLE</h2>
+
+Run r.texture over tiles with size 1000x1000 using 4 parallel processes:
+
+<div class="code"><pre> 
+g.region rast=ortho_2001_t792_1m
+r.texture.tiled ortho_2001_t792_1m output=ortho_texture method=idm \
+   tile_width=1000 tile_height=1000 processes=4
+</pre></div>
+
+<h2>SEE ALSO</h2>
+
+<a href="r.texture.html">r.texture</a> 
+
+<h2>AUTHOR</h2> 
+
+Moritz Lennert
+
+<p><i>Last changed: $Date: 2018-03-12 12:24:32 +0100 (lun 12 mar 2018) $</i>

Added: grass-addons/grass7/raster/r.texture.tiled/r.texture.tiled.py
===================================================================
--- grass-addons/grass7/raster/r.texture.tiled/r.texture.tiled.py	                        (rev 0)
+++ grass-addons/grass7/raster/r.texture.tiled/r.texture.tiled.py	2018-10-30 15:37:49 UTC (rev 73625)
@@ -0,0 +1,139 @@
+#!/usr/bin/env python
+
+############################################################################
+#
+# MODULE:	r.texture.tiled
+# AUTHOR(S):	Moritz Lennert
+#
+# PURPOSE:	Run r.texture over tiles of the input map
+#               to allow parallel processing
+# COPYRIGHT:	(C) 1997-2018 by the GRASS Development Team
+#
+#		This program is free software under the GNU General Public
+#		License (>=v2). Read the file COPYING that comes with GRASS
+#		for details.
+#############################################################################
+
+#%Module
+#% description: Runs r.texture in parallel over tiles
+#% keyword: raster
+#% keyword: texture
+#% keyword: tiling
+#%end
+#
+#%option G_OPT_R_INPUT
+#% required: yes
+#%end
+#
+#%option G_OPT_R_BASENAME_OUTPUT
+#% required: yes
+#%end
+#
+#%option
+#% key: method
+#% type: string
+#% description: Texture method to apply
+#% required: yes
+#% multiple: no
+#% options: asm,contrast,corr,var,idm,sa,sv,se,entr,dv,de,moc1,moc2
+#%end
+#
+#%option
+#% key: size
+#% type: integer
+#% description: The size of moving window (odd and >= 3)
+#% answer: 3
+#% required: yes
+#%end
+#
+#%option
+#% key: distance
+#% type: integer
+#% label: The distance between two samples (>= 1)
+#% description: The distance must be smaller than the size of the moving window
+#% answer: 1
+#% required: yes
+#%end
+#
+#%option
+#% key: tile_width
+#% type: integer
+#% description: Width of tiles
+#% answer: 1000
+#% required: yes
+#%end
+#
+#%option
+#% key: tile_height
+#% type: integer
+#% description: Height of tiles
+#% answer: 1000
+#% required: yes
+#%end
+#
+#%option
+#% key: processes
+#% type: integer
+#% description: Number of parallel processes
+#% answer: 1
+#% required: yes
+#%end
+
+
+import math
+import grass.script as gscript
+from grass.pygrass.modules.grid.grid import *
+
+class MyGridModule(GridModule):
+    """inherit GridModule, but handle the specific output naming of r.texture"""
+
+    def patch(self):
+        """Patch the final results."""
+        bboxes = split_region_tiles(width=self.width, height=self.height)
+        loc = Location()
+        mset = loc[self.mset.name]
+        mset.visible.extend(loc.mapsets())
+        method = self.module.inputs['method'].value[0]
+        for otmap in self.module.outputs:
+            otm = self.module.outputs[otmap]
+            if otm.typedesc == 'raster' and otm.value:
+                otm.value = '%s_%s' % (otm.value, method.upper())
+                rpatch_map(otm.value,
+                           self.mset.name, self.msetstr, bboxes,
+                           self.module.flags.overwrite,
+                           self.start_row, self.start_col, self.out_prefix)
+
+
+
+def main():
+
+    inputraster = options['input']
+    outputprefix = options['output']
+    windowsize = int(options['size'])
+    distance = int(options['distance'])
+    texture_method = options['method']
+    width = int(options['tile_width'])
+    height = int(options['tile_height'])
+    overlap = math.ceil(windowsize/2.0)
+    processes = int(options['processes'])
+
+    kwargs = {'input' : inputraster,
+              'output' : outputprefix,
+              'size' : windowsize,
+              'distance' : distance,
+              'method' : texture_method,
+              'flags' : 'n',
+              'quiet' : True}
+
+    grd = MyGridModule('r.texture',
+                       width=width,
+                       height=height,
+                       overlap=overlap,
+                       processes=processes,
+                       split=False,
+                       **kwargs)
+    grd.run()
+
+if __name__ == "__main__":
+    options, flags = gscript.parser()
+    main()


Property changes on: grass-addons/grass7/raster/r.texture.tiled/r.texture.tiled.py
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property


More information about the grass-commit mailing list