[GRASS-SVN] r69509 - in grass/trunk/temporal/t.rast.neighbors: . testsuite
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Sep 16 15:23:02 PDT 2016
Author: huhabla
Date: 2016-09-16 15:23:02 -0700 (Fri, 16 Sep 2016)
New Revision: 69509
Modified:
grass/trunk/temporal/t.rast.neighbors/t.rast.neighbors.py
grass/trunk/temporal/t.rast.neighbors/testsuite/test_neighbors.py
Log:
temporal modules: Enabled raster region specific parallel processing by using the MultiModule class
Modified: grass/trunk/temporal/t.rast.neighbors/t.rast.neighbors.py
===================================================================
--- grass/trunk/temporal/t.rast.neighbors/t.rast.neighbors.py 2016-09-16 22:20:28 UTC (rev 69508)
+++ grass/trunk/temporal/t.rast.neighbors/t.rast.neighbors.py 2016-09-16 22:23:02 UTC (rev 69509)
@@ -83,6 +83,13 @@
#% key: n
#% description: Register Null maps
#%end
+
+
+#%flag
+#% key: r
+#% description: Ignore the current region settings and use the raster map regions
+#%end
+
from __future__ import print_function
import copy
@@ -102,6 +109,7 @@
size = options["size"]
base = options["basename"]
register_null = flags["n"]
+ use_raster_region = flags["r"]
method = options["method"]
nprocs = options["nprocs"]
time_suffix = options["suffix"]
@@ -131,6 +139,9 @@
method=method, overwrite=overwrite,
quiet=True)
+ gregion_module = pymod.Module("g.region", raster="dummy", run_=False,
+ finish_=False,)
+
# The module queue for parallel execution
process_queue = pymod.ParallelModuleQueue(int(nprocs))
@@ -158,12 +169,32 @@
mod = copy.deepcopy(neighbor_module)
mod(input=map.get_id(), output=new_map.get_id())
- print(mod.get_bash())
- process_queue.put(mod)
+ if use_raster_region is True:
+ reg = copy.deepcopy(gregion_module)
+ reg(raster=map.get_id())
+ print(reg.get_bash())
+ print(mod.get_bash())
+ mm = pymod.MultiModule([reg, mod], sync=False, set_temp_region=True)
+ process_queue.put(mm)
+ else:
+ print(mod.get_bash())
+ process_queue.put(mod)
+
# Wait for unfinished processes
process_queue.wait()
+ proc_list = process_queue.get_finished_modules()
+ # Check return status of all finished modules
+ error = 0
+ for proc in proc_list:
+ if proc.popen.returncode != 0:
+ grass.error(_("Error running module: %\n stderr: %s") %(proc.get_bash(), proc.outputs.stderr))
+ error += 1
+
+ if error > 0:
+ grass.fatal(_("Error running modules."))
+
# Open the new space time raster dataset
ttype, stype, title, descr = sp.get_initial_values()
new_sp = tgis.open_new_stds(output, "strds", ttype, title,
Modified: grass/trunk/temporal/t.rast.neighbors/testsuite/test_neighbors.py
===================================================================
--- grass/trunk/temporal/t.rast.neighbors/testsuite/test_neighbors.py 2016-09-16 22:20:28 UTC (rev 69508)
+++ grass/trunk/temporal/t.rast.neighbors/testsuite/test_neighbors.py 2016-09-16 22:23:02 UTC (rev 69509)
@@ -55,7 +55,7 @@
self.assertRasterExists('b_2001_01')
self.assertRasterMinMax('b_2001_02', 1, 10)
self.assertRasterDoesNotExist('b_2001_03')
-
+
def test_simple(self):
"""Test simple t.rast.neighbors"""
trast_list = SimpleModule("t.rast.neighbors", quiet=True, input="A",
@@ -81,6 +81,16 @@
self.assertModule(trast_list)
self.assertRasterExists('b_001')
+ def test_num_region(self):
+ """Test t.rast.neighbors with parallel region processes"""
+ trast_list = SimpleModule("t.rast.neighbors", quiet=True, input="A",
+ output="B", size="5", basename='b', nprocs=2,
+ suffix="num%03", flags="r", overwrite=True)
+ self.assertModule(trast_list)
+ self.assertRasterExists('b_001')
+ self.assertRasterExists('b_002')
+ self.assertRasterExists('b_003')
+
if __name__ == '__main__':
from grass.gunittest.main import test
test()
More information about the grass-commit
mailing list