[GRASS-SVN] r67942 - in grass/trunk/temporal: t.rast.neighbors t.rast.neighbors/testsuite t.rast.to.vect t.rast.to.vect/testsuite
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Feb 24 12:45:01 PST 2016
Author: lucadelu
Date: 2016-02-24 12:45:01 -0800 (Wed, 24 Feb 2016)
New Revision: 67942
Added:
grass/trunk/temporal/t.rast.neighbors/testsuite/
grass/trunk/temporal/t.rast.neighbors/testsuite/test_neighbors.py
Modified:
grass/trunk/temporal/t.rast.neighbors/t.rast.neighbors.py
grass/trunk/temporal/t.rast.to.vect/t.rast.to.vect.py
grass/trunk/temporal/t.rast.to.vect/testsuite/test_to_vect.py
Log:
t.rast.neighbors, t.rast.to.vect: added suffix option
Modified: grass/trunk/temporal/t.rast.neighbors/t.rast.neighbors.py
===================================================================
--- grass/trunk/temporal/t.rast.neighbors/t.rast.neighbors.py 2016-02-24 19:28:23 UTC (rev 67941)
+++ grass/trunk/temporal/t.rast.neighbors/t.rast.neighbors.py 2016-02-24 20:45:01 UTC (rev 67942)
@@ -62,6 +62,15 @@
#%end
#%option
+#% key: suffix
+#% type: string
+#% description: Suffix to add at basename: set 'gran' for granularity, 'time' for the full time format, 'num' for numerical suffix with a specific number of digits (default %05)
+#% answer: gran
+#% required: no
+#% multiple: no
+#%end
+
+#%option
#% key: nprocs
#% type: integer
#% description: Number of r.neighbor processes to run in parallel
@@ -94,6 +103,7 @@
register_null = flags["n"]
method = options["method"]
nprocs = options["nprocs"]
+ time_suffix = options["suffix"]
# Make sure the temporal database exists
tgis.init()
@@ -130,7 +140,16 @@
# run r.neighbors all selected maps
for map in maps:
count += 1
- map_name = "%s_%i" % (base, count)
+ if sp.get_temporal_type() == 'absolute' and time_suffix == 'gran':
+ suffix = tgis.create_suffix_from_datetime(map.temporal_extent.get_start_time(),
+ sp.get_granularity())
+ map_name = "{ba}_{su}".format(ba=base, su=suffix)
+ elif sp.get_temporal_type() == 'absolute' and time_suffix == 'time':
+ suffix = tgis.create_time_suffix(map)
+ map_name = "{ba}_{su}".format(ba=base, su=suffix)
+ else:
+ map_name = tgis.create_numeric_suffic(base, count, time_suffix)
+
new_map = tgis.open_new_map_dataset(map_name, None, type="raster",
temporal_extent=map.get_temporal_extent(),
overwrite=overwrite, dbif=dbif)
Added: grass/trunk/temporal/t.rast.neighbors/testsuite/test_neighbors.py
===================================================================
--- grass/trunk/temporal/t.rast.neighbors/testsuite/test_neighbors.py (rev 0)
+++ grass/trunk/temporal/t.rast.neighbors/testsuite/test_neighbors.py 2016-02-24 20:45:01 UTC (rev 67942)
@@ -0,0 +1,86 @@
+# -*- coding: utf-8 -*-
+"""
+Created on Wed Feb 17 19:53:04 2016
+
+ at author: lucadelu
+"""
+
+import os
+import grass.temporal as tgis
+from grass.gunittest.case import TestCase
+from grass.gunittest.gmodules import SimpleModule
+
+class TestAggregationAbsolute(TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ """Initiate the temporal GIS and set the region
+ """
+ os.putenv("GRASS_OVERWRITE", "1")
+ tgis.init()
+ cls.use_temp_region()
+ cls.runModule("g.region", s=0, n=80, w=0, e=120, b=0,
+ t=50, res=10, res3=10)
+ cls.runModule("r.mapcalc", expression="a1 = rand(1,10)", flags=['s'],
+ overwrite=True)
+ cls.runModule("r.mapcalc", expression="a2 = rand(1,10)", flags=['s'],
+ overwrite=True)
+ cls.runModule("r.mapcalc", expression="a3 = rand(1,10)", flags=['s'],
+ overwrite=True)
+
+ cls.runModule("t.create", type="strds", temporaltype="absolute",
+ output="A", title="A test", description="A test",
+ overwrite=True)
+
+ cls.runModule("t.register", flags="i", type="raster", input="A",
+ maps="a1,a2,a3", start="2001-01-01 00:00:00",
+ increment="1 month", overwrite=True)
+ @classmethod
+ def tearDownClass(cls):
+ """Remove the temporary region
+ """
+ cls.del_temp_region()
+ cls.runModule("t.remove", flags="rf", type="strds", inputs="A")
+
+ def tearDown(self):
+ """Remove generated data"""
+ self.runModule("t.remove", flags="rf", type="strds", inputs="B")
+
+ def test_where(self):
+ """Test simple t.rast.neighbors"""
+ trast_list = SimpleModule("t.rast.neighbors", quiet=True, input="A",
+ output="B", basename='b', overwrite=True,
+ size="5", where="start_time <= '2001-02-01 00:00:00'")
+ self.assertModule(trast_list)
+ 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",
+ output="B", size="5", basename='b',
+ overwrite=True)
+ self.assertModule(trast_list)
+ self.assertRasterMinMax('b_2001_01', 1, 10)
+ self.assertRasterMinMax('b_2001_02', 1, 10)
+
+ def test_time_suffix(self):
+ """Test simple t.rast.neighbors"""
+ trast_list = SimpleModule("t.rast.neighbors", quiet=True, input="A",
+ output="B", size="5", basename='b',
+ suffix="time", overwrite=True)
+ self.assertModule(trast_list)
+ self.assertRasterExists('b_2001_01_01T00_00_00')
+
+ def test_num_suffix(self):
+ """Test simple t.rast.neighbors"""
+ trast_list = SimpleModule("t.rast.neighbors", quiet=True, input="A",
+ output="B", size="5", basename='b',
+ suffix="num%03", overwrite=True)
+ self.assertModule(trast_list)
+ self.assertRasterExists('b_001')
+
+if __name__ == '__main__':
+ from grass.gunittest.main import test
+ test()
Modified: grass/trunk/temporal/t.rast.to.vect/t.rast.to.vect.py
===================================================================
--- grass/trunk/temporal/t.rast.to.vect/t.rast.to.vect.py 2016-02-24 19:28:23 UTC (rev 67941)
+++ grass/trunk/temporal/t.rast.to.vect/t.rast.to.vect.py 2016-02-24 20:45:01 UTC (rev 67942)
@@ -52,6 +52,15 @@
#%end
#%option
+#% key: suffix
+#% type: string
+#% description: Suffix to add at basename: set 'gran' for granularity, 'time' for the full time format, 'num' for numerical suffix with a specific number of digits (default %05)
+#% answer: gran
+#% required: no
+#% multiple: no
+#%end
+
+#%option
#% key: column
#% type: string
#% description: Name of attribute column to store value
@@ -120,6 +129,7 @@
method = options["type"]
nprocs = int(options["nprocs"])
column = options["column"]
+ time_suffix = options["suffix"]
register_null = flags["n"]
t_flag = flags["t"]
@@ -185,7 +195,15 @@
# run r.to.vect all selected maps
for map in maps:
count += 1
- map_name = "%s_%i" % (base, count)
+ if sp.get_temporal_type() == 'absolute' and time_suffix == 'gran':
+ suffix = tgis.create_suffix_from_datetime(map.temporal_extent.get_start_time(),
+ sp.get_granularity())
+ map_name = "{ba}_{su}".format(ba=base, su=suffix)
+ elif sp.get_temporal_type() == 'absolute' and time_suffix == 'time':
+ suffix = tgis.create_time_suffix(map)
+ map_name = "{ba}_{su}".format(ba=base, su=suffix)
+ else:
+ map_name = tgis.create_numeric_suffic(base, count, time_suffix)
new_map = tgis.open_new_map_dataset(map_name, None, type="vector",
temporal_extent=map.get_temporal_extent(),
overwrite=overwrite, dbif=dbif)
Modified: grass/trunk/temporal/t.rast.to.vect/testsuite/test_to_vect.py
===================================================================
--- grass/trunk/temporal/t.rast.to.vect/testsuite/test_to_vect.py 2016-02-24 19:28:23 UTC (rev 67941)
+++ grass/trunk/temporal/t.rast.to.vect/testsuite/test_to_vect.py 2016-02-24 20:45:01 UTC (rev 67942)
@@ -131,6 +131,21 @@
info = SimpleModule("t.info", flags="g", type="stvds", input="result")
self.assertModuleKeyValue(module=info, reference=tinfo_string, precision=2, sep="=")
+ def test_num_suffix(self):
+ self.assertModule("t.rast.to.vect", input="A", output="result",
+ type="point", flags="t", column="values",
+ basename="test", suffix="num%03",
+ nprocs=4, overwrite=True, verbose=True)
+ self.assertVectorExists("test_001")
+
+ def test_time_suffix(self):
+ self.assertModule("t.rast.to.vect", input="A", output="result",
+ type="point", flags="t", column="values",
+ basename="test", suffix="time",
+ nprocs=4, overwrite=True, verbose=True)
+ self.assertVectorExists("test_2001_01_01T00_00_00")
+
+
class TestRasterToVectorFails(TestCase):
@classmethod
def setUpClass(cls):
More information about the grass-commit
mailing list