[GRASS-SVN] r62640 - in grass/trunk/temporal: t.rast.algebra t.rast.algebra/testsuite t.rast3d.algebra t.rast3d.algebra/testsuite t.vect.algebra/testsuite
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Nov 6 12:07:09 PST 2014
Author: huhabla
Date: 2014-11-06 12:07:09 -0800 (Thu, 06 Nov 2014)
New Revision: 62640
Added:
grass/trunk/temporal/t.rast.algebra/testsuite/
grass/trunk/temporal/t.rast.algebra/testsuite/test_raster_algebra.py
grass/trunk/temporal/t.rast3d.algebra/testsuite/
grass/trunk/temporal/t.rast3d.algebra/testsuite/test_raster3d_algebra.py
grass/trunk/temporal/t.vect.algebra/testsuite/test_vector_algebra.py
Removed:
grass/trunk/temporal/t.vect.algebra/testsuite/test.t.vect.algebra.sh
Log:
temporal modules: New temporal algebra tests
Added: grass/trunk/temporal/t.rast.algebra/testsuite/test_raster_algebra.py
===================================================================
--- grass/trunk/temporal/t.rast.algebra/testsuite/test_raster_algebra.py (rev 0)
+++ grass/trunk/temporal/t.rast.algebra/testsuite/test_raster_algebra.py 2014-11-06 20:07:09 UTC (rev 62640)
@@ -0,0 +1,694 @@
+"""
+(C) 2013 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.
+
+:authors: Soeren Gebbert
+"""
+
+import datetime
+import os
+import grass.script
+import grass.temporal as tgis
+import grass.gunittest as gunittest
+
+class TestTRastAlgebra(gunittest.TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ """Initiate the temporal GIS and set the region
+ """
+ os.putenv("GRASS_OVERWRITE", "1")
+ tgis.init(True) # Raise on error instead of exit(1)
+ cls.use_temp_region()
+ cls.runModule("g.region", n=80.0, s=0.0, e=120.0,
+ w=0.0, t=1.0, b=0.0, res=10.0)
+
+ cls.runModule("r.mapcalc", quiet=True, expression="a1 = 1")
+ cls.runModule("r.mapcalc", quiet=True, expression="a2 = 2")
+ cls.runModule("r.mapcalc", quiet=True, expression="a3 = 3")
+ cls.runModule("r.mapcalc", quiet=True, expression="a4 = 4")
+ cls.runModule("r.mapcalc", quiet=True, expression="b1 = 5")
+ cls.runModule("r.mapcalc", quiet=True, expression="b2 = 6")
+ cls.runModule("r.mapcalc", quiet=True, expression="c1 = 7")
+ cls.runModule("r.mapcalc", quiet=True, expression="d1 = 8")
+ cls.runModule("r.mapcalc", quiet=True, expression="d2 = 9")
+ cls.runModule("r.mapcalc", quiet=True, expression="d3 = 10")
+ cls.runModule("r.mapcalc", quiet=True, expression="singletmap = 99")
+ cls.runModule("r.mapcalc", quiet=True, expression="singlemap = 100")
+
+ tgis.open_new_stds(name="A", type="strds", temporaltype="absolute",
+ title="A", descr="A", semantic="field")
+ tgis.open_new_stds(name="B", type="strds", temporaltype="absolute",
+ title="B", descr="B", semantic="field")
+ tgis.open_new_stds(name="C", type="strds", temporaltype="absolute",
+ title="B", descr="C", semantic="field")
+ tgis.open_new_stds(name="D", type="strds", temporaltype="absolute",
+ title="D", descr="D", semantic="field")
+
+ tgis.register_maps_in_space_time_dataset(type="rast", name="A", maps="a1,a2,a3,a4",
+ start="2001-01-01", increment="1 day", interval=True)
+ tgis.register_maps_in_space_time_dataset(type="rast", name="B", maps="b1,b2",
+ start="2001-01-01", increment="2 day", interval=True)
+ tgis.register_maps_in_space_time_dataset(type="rast", name="C", maps="c1",
+ start="2001-01-02", increment="2 day", interval=True)
+ tgis.register_maps_in_space_time_dataset(type="rast", name="D", maps="d1,d2,d3",
+ start="2001-01-03", increment="1 day", interval=True)
+ tgis.register_maps_in_space_time_dataset(type="rast", name=None, maps="singletmap",
+ start="2001-01-03", end="2001-01-04", interval=True)
+
+ def tearDown(self):
+ self.runModule("t.remove", flags="rf", inputs="R", quiet=True)
+
+ @classmethod
+ def tearDownClass(cls):
+ """Remove the temporary region
+ """
+ cls.runModule("t.remove", flags="rf", inputs="A,B,C,D", quiet=True)
+ cls.runModule("t.unregister", maps="singletmap", quiet=True)
+ cls.del_temp_region()
+
+ def test_temporal_conditional_time_dimension_bug(self):
+ """Testing the conditional time dimension bug, that uses the time
+ dimension of the conditional statement instead the time dimension
+ of the then/else statement."""
+ self.assertModule("t.rast.algebra", expression="R = if({contains}, B == 5, A - 1, A + 1)",
+ basename="r")
+
+ D = tgis.open_old_stds("R", type="strds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 4)
+ self.assertEqual(D.metadata.get_min_min(), 0) # 1 - 1
+ self.assertEqual(D.metadata.get_max_max(), 5) # 4 + 1
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 1))
+ self.assertEqual(end, datetime.datetime(2001, 1, 5))
+ self.assertEqual( D.check_temporal_topology(), True)
+ self.assertEqual(D.get_granularity(), u'1 day')
+
+ def test_simple_arith_hash_1(self):
+ """Simple arithmetic test including the hash operator"""
+
+ self.assertModule("t.rast.algebra", expression='R = A + A {#, equal,l} A', basename="r")
+
+ D = tgis.open_old_stds("R", type="strds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 4)
+ self.assertEqual(D.metadata.get_min_min(), 2)
+ self.assertEqual(D.metadata.get_max_max(), 5)
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 1))
+ self.assertEqual(end, datetime.datetime(2001, 1, 5))
+
+
+ def test_simple_arith_td_1(self):
+ """Simple arithmetic test"""
+
+ self.assertModule("t.rast.algebra", expression='R = A + td(A)', basename="r")
+
+ D = tgis.open_old_stds("R", type="strds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 4)
+ self.assertEqual(D.metadata.get_min_min(), 2)
+ self.assertEqual(D.metadata.get_max_max(), 5)
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 1))
+ self.assertEqual(end, datetime.datetime(2001, 1, 5))
+
+ def test_simple_arith_td_2(self):
+ """Simple arithmetic test"""
+
+ self.assertModule("t.rast.algebra", expression='R = A / td(A)', basename="r")
+
+ D = tgis.open_old_stds("R", type="strds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 4)
+ self.assertEqual(D.metadata.get_min_min(), 1)
+ self.assertEqual(D.metadata.get_max_max(), 4)
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 1))
+ self.assertEqual(end, datetime.datetime(2001, 1, 5))
+
+ def test_simple_arith_td_3(self):
+ """Simple arithmetic test"""
+
+ self.assertModule("t.rast.algebra", expression='R = A {+,equal} td(A)', basename="r")
+
+ D = tgis.open_old_stds("R", type="strds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 4)
+ self.assertEqual(D.metadata.get_min_min(), 2)
+ self.assertEqual(D.metadata.get_max_max(), 5)
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 1))
+ self.assertEqual(end, datetime.datetime(2001, 1, 5))
+
+ def test_simple_arith_td_4(self):
+ """Simple arithmetic test"""
+
+ self.assertModule("t.rast.algebra", expression='R = A {/, equal} td(A)', basename="r")
+
+ D = tgis.open_old_stds("R", type="strds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 4)
+ self.assertEqual(D.metadata.get_min_min(), 1)
+ self.assertEqual(D.metadata.get_max_max(), 4)
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 1))
+ self.assertEqual(end, datetime.datetime(2001, 1, 5))
+
+
+ def test_simple_arith_if_1(self):
+ """Simple arithmetic test with if condition"""
+
+ self.assertModule("t.rast.algebra", expression='R = if({equal}, start_date(A) >= "2001-01-02", A + A)', basename="r")
+
+ D = tgis.open_old_stds("R", type="strds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 3)
+ self.assertEqual(D.metadata.get_min_min(), 4)
+ self.assertEqual(D.metadata.get_max_max(), 8)
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 2))
+ self.assertEqual(end, datetime.datetime(2001, 1, 5))
+
+ def test_simple_arith_if_2(self):
+ """Simple arithmetic test with if condition"""
+
+ self.assertModule("t.rast.algebra", expression='R = if({equal}, A#A == 1, A - A)', basename="r")
+
+ D = tgis.open_old_stds("R", type="strds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 4)
+ self.assertEqual(D.metadata.get_min_min(), 0)
+ self.assertEqual(D.metadata.get_max_max(), 0)
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 1))
+ self.assertEqual(end, datetime.datetime(2001, 1, 5))
+
+ def test_complex_arith_if_1(self):
+ """Complex arithmetic test with if condition"""
+
+ self.assertModule("t.rast.algebra", expression='R = if(start_date(A) < "2001-01-03" && A#A == 1, A{+, starts,l}C, A{+, finishes,l}C)', \
+ basename="r")
+
+ D = tgis.open_old_stds("R", type="strds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 2)
+ self.assertEqual(D.metadata.get_min_min(), 9) # 2 + 7 a2 + c1
+ self.assertEqual(D.metadata.get_max_max(), 10) # 3 + 7 a3 + c1
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 2))
+ self.assertEqual(end, datetime.datetime(2001, 1, 4))
+
+ def test_simple_arith_1(self):
+ """Simple arithmetic test"""
+
+ self.assertModule("t.rast.algebra", expression="R = A {*, equal} A {+, equal} A", basename="r")
+
+ D = tgis.open_old_stds("R", type="strds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 4)
+ self.assertEqual(D.metadata.get_min_min(), 2) # 1*1 + 1
+ self.assertEqual(D.metadata.get_max_max(), 20) # 4*4 + 4
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 1))
+ self.assertEqual(end, datetime.datetime(2001, 1, 5))
+
+ def test_simple_arith_2(self):
+ """Simple arithmetic test that creates an empty strds"""
+
+ self.assertModule("t.rast.algebra", expression="R = A {*, during} A {+, during} A", basename="r")
+ D = tgis.open_old_stds("R", type="strds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 0)
+
+ def test_simple_arith_3(self):
+ """Simple arithmetic test"""
+
+ self.assertModule("t.rast.algebra", expression="R = A / A + A*A/A", basename="r")
+
+ D = tgis.open_old_stds("R", type="strds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 4)
+ self.assertEqual(D.metadata.get_min_min(), 2) # 1/1 + 1*1/1
+ self.assertEqual(D.metadata.get_max_max(), 5) # 4/4 + 4*4/4
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 1))
+ self.assertEqual(end, datetime.datetime(2001, 1, 5))
+
+ def test_temporal_intersection_1(self):
+ """Simple temporal intersection test"""
+
+ self.assertModule("t.rast.algebra", expression="R = A {+,equal,i} B", basename="r")
+ D = tgis.open_old_stds("R", type="strds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 0)
+
+ def test_temporal_intersection_2(self):
+ """Simple temporal intersection test"""
+
+ self.assertModule("t.rast.algebra", expression="R = A {+,during,i} B", basename="r")
+
+ D = tgis.open_old_stds("R", type="strds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 4)
+ self.assertEqual(D.metadata.get_min_min(), 6) # 1 + 5
+ self.assertEqual(D.metadata.get_max_max(), 10) # 4 + 6
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 1))
+ self.assertEqual(end, datetime.datetime(2001, 1, 5))
+
+ def test_temporal_intersection_3(self):
+ """Simple temporal intersection test"""
+
+ self.assertModule("t.rast.algebra", expression="R = A {+,starts,i} B", basename="r")
+
+ D = tgis.open_old_stds("R", type="strds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 2)
+ self.assertEqual(D.metadata.get_min_min(), 6) # 1 + 5
+ self.assertEqual(D.metadata.get_max_max(), 9) # 3 + 6
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 1))
+ self.assertEqual(end, datetime.datetime(2001, 1, 4))
+
+ def test_temporal_intersection_4(self):
+ """Simple temporal intersection test"""
+
+ self.assertModule("t.rast.algebra", expression="R = A {+,finishes,intersect} B", basename="r")
+
+ D = tgis.open_old_stds("R", type="strds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 2)
+ self.assertEqual(D.metadata.get_min_min(), 7) # 2 + 5
+ self.assertEqual(D.metadata.get_max_max(), 10) # 4 + 6
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 2))
+ self.assertEqual(end, datetime.datetime(2001, 1, 5))
+
+ def test_temporal_intersection_5(self):
+ """Simple temporal intersection test"""
+
+ self.assertModule("t.rast.algebra", expression="R = A {+,starts|finishes,i} B", basename="r")
+
+ D = tgis.open_old_stds("R", type="strds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 4)
+ self.assertEqual(D.metadata.get_min_min(), 6) # 1 + 5
+ self.assertEqual(D.metadata.get_max_max(), 10) # 4 + 6
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 1))
+ self.assertEqual(end, datetime.datetime(2001, 1, 5))
+
+ def test_temporal_intersection_6(self):
+ """Simple temporal intersection test"""
+
+ self.assertModule("t.rast.algebra", expression="R = B {+,overlaps,u} C", basename="r")
+
+ D = tgis.open_old_stds("R", type="strds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 1)
+ self.assertEqual(D.metadata.get_min_min(), 12) # 5 + 7
+ self.assertEqual(D.metadata.get_max_max(), 12) # 5 + 7
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 1))
+ self.assertEqual(end, datetime.datetime(2001, 1, 4))
+
+ def test_temporal_intersection_7(self):
+ """Simple temporal intersection test"""
+
+ self.assertModule("t.rast.algebra", expression="R = B {+,overlapped,u} C", basename="r")
+
+ D = tgis.open_old_stds("R", type="strds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 1)
+ self.assertEqual(D.metadata.get_min_min(), 13) # 6 + 7
+ self.assertEqual(D.metadata.get_max_max(), 13) # 6 + 7
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 2))
+ self.assertEqual(end, datetime.datetime(2001, 1, 5))
+
+ def test_temporal_intersection_8(self):
+ """Simple temporal intersection test"""
+
+ self.assertModule("t.rast.algebra", expression='R = A {+,during,l} buff_t(C, "1 day") ',
+ basename="r")
+
+ D = tgis.open_old_stds("R", type="strds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 4)
+ self.assertEqual(D.metadata.get_min_min(), 8) # 1 + 7 a1 + c1
+ self.assertEqual(D.metadata.get_max_max(), 11) # 4 + 7 a4 + c1
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 1))
+ self.assertEqual(end, datetime.datetime(2001, 1, 5))
+
+ def test_temporal_neighbors_1(self):
+ """Simple temporal neighborhood computation test"""
+
+ self.assertModule("t.rast.algebra", expression='R = A[-1] + A[1]',
+ basename="r")
+
+ D = tgis.open_old_stds("R", type="strds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 2)
+ self.assertEqual(D.metadata.get_min_min(), 4) # 1 + 3
+ self.assertEqual(D.metadata.get_max_max(), 6) # 2 + 4
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 2))
+ self.assertEqual(end, datetime.datetime(2001, 1, 4))
+
+ def test_temporal_neighbors_2(self):
+ """Simple temporal neighborhood computation test"""
+
+ self.assertModule("t.rast.algebra", expression='R = A[0,0,-1] + A[0,0,1]',
+ basename="r")
+
+ D = tgis.open_old_stds("R", type="strds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 2)
+ self.assertEqual(D.metadata.get_min_min(), 4) # 1 + 3
+ self.assertEqual(D.metadata.get_max_max(), 6) # 2 + 4
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 2))
+ self.assertEqual(end, datetime.datetime(2001, 1, 4))
+
+ def test_tmap_function1(self):
+ """Testing the tmap function. """
+
+ self.assertModule("t.rast.algebra", expression='R = tmap(singletmap)', basename="r")
+
+ D = tgis.open_old_stds("R", type="strds")
+
+ maplist = D.get_registered_maps_as_objects()
+ self.assertEqual(D.metadata.get_number_of_maps(), 1)
+ self.assertEqual(D.metadata.get_min_min(), 99)
+ self.assertEqual(D.metadata.get_max_max(), 99)
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 3))
+ self.assertEqual(end, datetime.datetime(2001, 1, 4))
+ self.assertEqual( D.check_temporal_topology(), True)
+ self.assertEqual(D.get_granularity(), u'1 day')
+
+ def test_tmap_function2(self):
+ """Testing the tmap function. """
+
+ self.assertModule("t.rast.algebra", expression='R = tmap(singletmap) + 1', basename="r")
+
+ D = tgis.open_old_stds("R", type="strds")
+
+ maplist = D.get_registered_maps_as_objects()
+ self.assertEqual(D.metadata.get_number_of_maps(), 1)
+ self.assertEqual(D.metadata.get_min_min(), 100)
+ self.assertEqual(D.metadata.get_max_max(), 100)
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 3))
+ self.assertEqual(end, datetime.datetime(2001, 1, 4))
+ self.assertEqual( D.check_temporal_topology(), True)
+ self.assertEqual(D.get_granularity(), u'1 day')
+
+ def test_map_function1(self):
+ """Testing the map function. """
+
+ self.assertModule("t.rast.algebra", expression='R = map(singlemap) + A', basename="r")
+
+ D = tgis.open_old_stds("R", type="strds")
+
+ maplist = D.get_registered_maps_as_objects()
+ self.assertEqual(D.metadata.get_number_of_maps(), 4)
+ self.assertEqual(D.metadata.get_min_min(), 101)
+ self.assertEqual(D.metadata.get_max_max(), 104)
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 1))
+ self.assertEqual(end, datetime.datetime(2001, 1, 5))
+ self.assertEqual( D.check_temporal_topology(), True)
+ self.assertEqual(D.get_granularity(), u'1 day')
+
+ def test_map_function2(self):
+ """Testing the map function. """
+
+ self.assertModule("t.rast.algebra", expression='R = A * map(singlemap)', basename="r")
+
+ D = tgis.open_old_stds("R", type="strds")
+
+ maplist = D.get_registered_maps_as_objects()
+ self.assertEqual(D.metadata.get_number_of_maps(), 4)
+ self.assertEqual(D.metadata.get_min_min(), 100)
+ self.assertEqual(D.metadata.get_max_max(), 400)
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 1))
+ self.assertEqual(end, datetime.datetime(2001, 1, 5))
+ self.assertEqual( D.check_temporal_topology(), True)
+ self.assertEqual(D.get_granularity(), u'1 day')
+
+ def test_temporal_select(self):
+ """Testing the temporal select operator. """
+
+ self.assertModule("t.rast.algebra", expression="R = A : A", basename="r")
+
+ D = tgis.open_old_stds("R", type="strds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 4)
+ self.assertEqual(D.metadata.get_min_min(), 1)
+ self.assertEqual(D.metadata.get_max_max(), 4)
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 1))
+ self.assertEqual(end, datetime.datetime(2001, 1, 5))
+ self.assertEqual( D.check_temporal_topology(), True)
+ self.assertEqual(D.get_granularity(), u'1 day')
+
+ def test_temporal_select(self):
+ """Testing the temporal select operator. """
+
+ self.assertModule("t.rast.algebra", expression="R = A : D", basename="r")
+
+ D = tgis.open_old_stds("R", type="strds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 2)
+ self.assertEqual(D.metadata.get_min_min(), 3)
+ self.assertEqual(D.metadata.get_max_max(), 4)
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 3))
+ self.assertEqual(end, datetime.datetime(2001, 1, 5))
+ self.assertEqual( D.check_temporal_topology(), True)
+ self.assertEqual(D.get_granularity(), u'1 day')
+
+ def test_temporal_select_operators1(self):
+ """Testing the temporal select operator. Including temporal relations. """
+
+ self.assertModule("t.rast.algebra", expression="R = A : D", basename="r")
+
+ D = tgis.open_old_stds("R", type="strds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 2)
+ self.assertEqual(D.metadata.get_min_min(), 3)
+ self.assertEqual(D.metadata.get_max_max(), 4)
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 3))
+ self.assertEqual(end, datetime.datetime(2001, 1, 5))
+ self.assertEqual( D.check_temporal_topology(), True)
+ self.assertEqual(D.get_granularity(), u'1 day')
+
+ def test_temporal_select_operators2(self):
+ """Testing the temporal select operator. Including temporal relations. """
+
+ self.assertModule("t.rast.algebra", expression="R = A {!:,during} C", basename="r")
+
+ D = tgis.open_old_stds("R", type="strds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 2)
+ self.assertEqual(D.metadata.get_min_min(), 1)
+ self.assertEqual(D.metadata.get_max_max(), 4)
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 1))
+ self.assertEqual(end, datetime.datetime(2001, 1, 5))
+ self.assertEqual( D.check_temporal_topology(), True)
+ self.assertEqual(D.get_granularity(), u'1 day')
+
+ def test_temporal_select_operators3(self):
+ """Testing the temporal select operator. Including temporal relations and
+ different temporal operators (lr|+&)"""
+
+ self.assertModule("t.rast.algebra", expression="R = A {:,during,d} B", basename="r")
+
+ D = tgis.open_old_stds("R", type="strds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 4)
+ self.assertEqual(D.metadata.get_min_min(), 1)
+ self.assertEqual(D.metadata.get_max_max(), 4)
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 1))
+ self.assertEqual(end, datetime.datetime(2001, 1, 5))
+ self.assertEqual( D.check_temporal_topology(), False)
+ self.assertEqual(D.get_granularity(), u'2 days')
+
+ def test_temporal_select_operators4(self):
+ """Testing the temporal select operator. Including temporal relations and
+ different temporal operators (lr|+&)"""
+
+ self.assertModule("t.rast.algebra", expression="R = A {:,equal|during,r} C", basename="r")
+
+ D = tgis.open_old_stds("R", type="strds")
+
+ maplist = D.get_registered_maps_as_objects()
+ for map_i in maplist:
+ start_map, end_map = map_i.get_absolute_time()
+ self.assertEqual(start_map, datetime.datetime(2001, 1, 2))
+ self.assertEqual(end_map, datetime.datetime(2001, 1, 4))
+ self.assertEqual(D.metadata.get_number_of_maps(), 2)
+ self.assertEqual(D.metadata.get_min_min(), 2)
+ self.assertEqual(D.metadata.get_max_max(), 3)
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 2))
+ self.assertEqual(end, datetime.datetime(2001, 1, 4))
+ self.assertEqual( D.check_temporal_topology(), False)
+ self.assertEqual(D.get_granularity(), u'2 days')
+
+ def test_temporal_hash_operator1(self):
+ """Testing the temporal hash operator in the raster algebra. """
+
+ self.assertModule("t.rast.algebra", expression="R = if(A # D == 1, A)", basename="r")
+
+ D = tgis.open_old_stds("R", type="strds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 2)
+ self.assertEqual(D.metadata.get_min_min(), 3)
+ self.assertEqual(D.metadata.get_max_max(), 4)
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 3))
+ self.assertEqual(end, datetime.datetime(2001, 1, 5))
+ self.assertEqual( D.check_temporal_topology(), True)
+ self.assertEqual(D.get_granularity(), u'1 day')
+
+ def test_temporal_hash_operator2(self):
+ """Testing the temporal hash operator in the raster algebra. """
+
+ self.assertModule("t.rast.algebra", expression="R = A # D", basename="r")
+
+ D = tgis.open_old_stds("R", type="strds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 2)
+ self.assertEqual(D.metadata.get_min_min(), 1)
+ self.assertEqual(D.metadata.get_max_max(), 1)
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 3))
+ self.assertEqual(end, datetime.datetime(2001, 1, 5))
+ self.assertEqual( D.check_temporal_topology(), True)
+ self.assertEqual(D.get_granularity(), u'1 day')
+
+ def test_temporal_hash_operator3(self):
+ """Testing the temporal hash operator in the raster algebra. """
+
+ self.assertModule("t.rast.algebra", expression="R = C {#,contains} A", basename="r")
+
+ D = tgis.open_old_stds("R", type="strds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 1)
+ self.assertEqual(D.metadata.get_min_min(), 2)
+ self.assertEqual(D.metadata.get_max_max(), 2)
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 2))
+ self.assertEqual(end, datetime.datetime(2001, 1, 4))
+ self.assertEqual( D.check_temporal_topology(), True)
+ self.assertEqual(D.get_granularity(), u'2 days')
+
+ def test_temporal_hash_operator4(self):
+ """Testing the temporal hash operator in the raster algebra. """
+
+ self.assertModule("t.rast.algebra", expression="R = if({contains},A # D == 1, C {#,contains} A)", basename="r")
+
+ D = tgis.open_old_stds("R", type="strds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 1)
+ self.assertEqual(D.metadata.get_min_min(), 2)
+ self.assertEqual(D.metadata.get_max_max(), 2)
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 2))
+ self.assertEqual(end, datetime.datetime(2001, 1, 4))
+ self.assertEqual( D.check_temporal_topology(), True)
+ self.assertEqual(D.get_granularity(), u'2 days')
+
+ def test_raster_arithmetic_relation_1(self):
+ """Arithmetic test with temporal intersection"""
+
+ self.assertModule("t.rast.algebra", expression="R = B {+,contains,l} A ", basename="r")
+
+ D = tgis.open_old_stds("R", type="strds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 2)
+ self.assertEqual(D.metadata.get_min_min(), 8)
+ self.assertEqual(D.metadata.get_max_max(), 13)
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 1))
+ self.assertEqual(end, datetime.datetime(2001, 1, 5))
+ self.assertEqual( D.check_temporal_topology(), True)
+ self.assertEqual(D.get_granularity(), u'2 days')
+
+ def test_raster_arithmetic_relation_2(self):
+ """Arithmetic test with temporal intersection"""
+
+ self.assertModule("t.rast.algebra", expression="R = B {*,contains,l} A ", basename="r")
+
+ D = tgis.open_old_stds("R", type="strds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 2)
+ self.assertEqual(D.metadata.get_min_min(), 10)
+ self.assertEqual(D.metadata.get_max_max(), 72)
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 1))
+ self.assertEqual(end, datetime.datetime(2001, 1, 5))
+ self.assertEqual( D.check_temporal_topology(), True)
+ self.assertEqual(D.get_granularity(), u'2 days')
+
+ def test_raster_arithmetic_relation_3(self):
+ """Arithmetic test with temporal intersection"""
+
+ self.assertModule("t.rast.algebra", expression="R = B {+,contains,l} A ", basename="r")
+
+ D = tgis.open_old_stds("R", type="strds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 2)
+ self.assertEqual(D.metadata.get_min_min(), 8)
+ self.assertEqual(D.metadata.get_max_max(), 13)
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 1))
+ self.assertEqual(end, datetime.datetime(2001, 1, 5))
+ self.assertEqual( D.check_temporal_topology(), True)
+ self.assertEqual(D.get_granularity(), u'2 days')
+
+ def test_raster_arithmetic_relation_4(self):
+ """Arithmetic test with temporal intersection"""
+
+ self.assertModule("t.rast.algebra", expression="R = B {+,contains,r} A ", basename="r")
+
+ D = tgis.open_old_stds("R", type="strds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(),4)
+ self.assertEqual(D.metadata.get_min_min(), 8)
+ self.assertEqual(D.metadata.get_max_max(), 13)
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 1))
+ self.assertEqual(end, datetime.datetime(2001, 1, 5))
+ self.assertEqual( D.check_temporal_topology(), True)
+ self.assertEqual(D.get_granularity(), u'1 day')
+
+ def test_raster_arithmetic_relation_5(self):
+ """Complex arithmetic test with temporal intersection"""
+
+ self.assertModule("t.rast.algebra", expression="R = tmap(singletmap) {+,equal| precedes| follows,l} A + map(singlemap)", basename="r")
+
+ D = tgis.open_old_stds("R", type="strds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(),1)
+ self.assertEqual(D.metadata.get_min_min(), 208)
+ self.assertEqual(D.metadata.get_max_max(), 208)
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 3))
+ self.assertEqual(end, datetime.datetime(2001, 1, 4))
+ self.assertEqual( D.check_temporal_topology(), True)
+ self.assertEqual(D.get_granularity(), u'1 day')
+
+if __name__ == '__main__':
+ gunittest.test()
Added: grass/trunk/temporal/t.rast3d.algebra/testsuite/test_raster3d_algebra.py
===================================================================
--- grass/trunk/temporal/t.rast3d.algebra/testsuite/test_raster3d_algebra.py (rev 0)
+++ grass/trunk/temporal/t.rast3d.algebra/testsuite/test_raster3d_algebra.py 2014-11-06 20:07:09 UTC (rev 62640)
@@ -0,0 +1,84 @@
+"""
+(C) 2014 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.
+
+:authors: Soeren Gebbert and Thomas Leppelt
+"""
+
+
+import grass.script
+import grass.temporal as tgis
+import grass.gunittest as gunittest
+import datetime
+import os
+
+class TestTRast3dAlgebra(gunittest.TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ """Initiate the temporal GIS and set the region
+ """
+ os.putenv("GRASS_OVERWRITE", "1")
+ tgis.init(True) # Raise on error instead of exit(1)
+ cls.use_temp_region()
+ ret = grass.script.run_command("g.region", n=80.0, s=0.0, e=120.0,
+ w=0.0, t=100.0, b=0.0, res=10.0)
+
+ cls.runModule("r3.mapcalc", overwrite=True, quiet=True, expression="a1 = 1")
+ cls.runModule("r3.mapcalc", overwrite=True, quiet=True, expression="a2 = 2")
+ cls.runModule("r3.mapcalc", overwrite=True, quiet=True, expression="a3 = 3")
+ cls.runModule("r3.mapcalc", overwrite=True, quiet=True, expression="a4 = 4")
+
+ tgis.open_new_stds(name="A", type="str3ds", temporaltype="absolute",
+ title="A", descr="A", semantic="field", overwrite=True)
+
+ tgis.register_maps_in_space_time_dataset(type="rast3d", name="A", maps="a1,a2,a3,a4",
+ start="2001-01-01", increment="1 day", interval=True)
+
+ def tearDown(self):
+ self.runModule("t.remove", type="str3ds", flags="rf", inputs="D", quiet=True)
+
+ @classmethod
+ def tearDownClass(cls):
+ """Remove the temporary region
+ """
+ cls.runModule("t.remove", type="str3ds", flags="rf", inputs="A", quiet=True)
+ cls.del_temp_region()
+
+ def test_temporal_neighbors_1(self):
+ """Simple temporal neighborhood computation test"""
+
+ self.assertModule("t.rast3d.algebra", expression='D = A[-1] + A[1]',
+ basename="d")
+
+ D = tgis.open_old_stds("D", type="str3ds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 2)
+ self.assertEqual(D.metadata.get_min_min(), 4) # 1 + 3
+ self.assertEqual(D.metadata.get_max_max(), 6) # 2 + 4
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 2))
+ self.assertEqual(end, datetime.datetime(2001, 1, 4))
+
+ def test_temporal_neighbors_2(self):
+ """Simple temporal neighborhood computation test"""
+
+ self.assertModule("t.rast3d.algebra", expression='D = A[0,0,0,-1] + A[0,0,0,1]',
+ basename="d")
+
+ D = tgis.open_old_stds("D", type="str3ds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 2)
+ self.assertEqual(D.metadata.get_min_min(), 4) # 1 + 3
+ self.assertEqual(D.metadata.get_max_max(), 6) # 2 + 4
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 2))
+ self.assertEqual(end, datetime.datetime(2001, 1, 4))
+
+if __name__ == '__main__':
+ grass.gunittest.test()
+
+
+
Deleted: grass/trunk/temporal/t.vect.algebra/testsuite/test.t.vect.algebra.sh
===================================================================
--- grass/trunk/temporal/t.vect.algebra/testsuite/test.t.vect.algebra.sh 2014-11-06 14:48:12 UTC (rev 62639)
+++ grass/trunk/temporal/t.vect.algebra/testsuite/test.t.vect.algebra.sh 2014-11-06 20:07:09 UTC (rev 62640)
@@ -1,96 +0,0 @@
-#!/usr/bin/sh
-
-g.region s=0 n=80 w=0 e=120 b=0 t=50 res=10 -p
-
-export GRASS_OVERWRITE=1
-
-# Test for temporal algebra in LatLon location.
-if test -f vinput1_point_test ; then
- rm vinput1_point_test.txt
-fi
-if test -f vinput1_point_test ; then
- rm vinput2_point_test.txt
-fi
-if test -f vinput1_point_test ; then
- rm vinput3_point_test.txt
-fi
-if test -f vinput1_point_test ; then
- rm vinput4_point_test.txt
-fi
-
-if test -f vinput1_point_test ; then
- rm vinput1_area_test.txt
-fi
-if test -f vinput1_point_test ; then
- rm vinput2_area_test.txt
-fi
-if test -f vinput1_point_test ; then
- rm vinput3_area_test.txt
-fi
-if test -f vinput1_point_test ; then
- rm vinput4_area_test.txt
-fi
-
-LIST="1 2 3 4 5 6 7 8 9 0 10 11 12 13 14 15 16 17 18 19 20"
-
-# Create random area test maps.
-for i in ${LIST}
- do
- if test "$i" -le 10 ; then
- echo vtestpoint1_$i >> vinput1_point_test.txt
- echo vtestarea1_$i >> vinput1_area_test.txt
- v.random --o -z output=vtestpoint1_$i n=3 seed=$i+1
- v.voronoi --o input=vtestpoint1_$i output=vtestarea1_$i
- elif test "$i" -gt 10 && test "$i" -le 15 ; then
- echo vtestpoint2_$i >> vinput2_point_test.txt
- echo vtestarea2_$i >> vinput2_area_test.txt
- v.random --o -z output=vtestpoint2_$i n=3 seed=$i+1
- v.voronoi --o input=vtestpoint2_$i output=vtestarea2_$i
- else
- echo vtestpoint3_$i >> vinput3_point_test.txt
- echo vtestpoint4_$i >> vinput4_point_test.txt
- echo vtestarea3_$i >> vinput3_area_test.txt
- echo vtestarea4_$i >> vinput4_area_test.txt
- v.random --o -z output=vtestpoint3_$i n=3 seed=$i+1
- v.voronoi --o input=vtestpoint3_$i output=vtestarea3_$i
- v.random --o -z output=vtestpoint4_$i n=3 seed=$i+1
- v.voronoi --o input=vtestpoint4_$i output=vtestarea4_$i
- fi
- done
-
-# Create STVDS and register test maps.
-t.create output=A1 type=stvds title="Area test dataset" descr="Area test dataset"
-t.create output=A2 type=stvds title="Area test dataset" descr="Area test dataset"
-t.create output=A3 type=stvds title="Area test dataset" descr="Area test dataset"
-t.create output=A4 type=stvds title="Area test dataset" descr="Area test dataset"
-t.create output=P1 type=stvds title="Point test dataset" descr="Point test dataset"
-t.create output=P2 type=stvds title="Point test dataset" descr="Point test dataset"
-t.create output=P3 type=stvds title="Point test dataset" descr="Point test dataset"
-t.create output=P4 type=stvds title="Point test dataset" descr="Point test dataset"
-
-t.register -i type=vect input=A1 file=vinput1_area_test.txt increment="1 days" start="2013-01-01"
-t.register -i type=vect input=A2 file=vinput2_area_test.txt increment="1 days" start="2013-01-10"
-t.register -i type=vect input=A3 file=vinput3_area_test.txt increment="3 days" start="2013-01-01"
-t.register -i type=vect input=A4 file=vinput4_area_test.txt increment="3 days" start="2013-01-10"
-t.register -i type=vect input=P1 file=vinput1_point_test.txt increment="1 days" start="2013-01-01"
-t.register -i type=vect input=P2 file=vinput2_point_test.txt increment="1 days" start="2013-01-10"
-t.register -i type=vect input=P3 file=vinput3_point_test.txt increment="3 days" start="2013-01-01"
-t.register -i type=vect input=P4 file=vinput4_point_test.txt increment="3 days" start="2013-01-10"
-
-# Test different options.
-t.vect.algebra expression='B1 = A1 & A2' basename="bmap1"
-t.vect.list input=B1 column=name,start_time,end_time
-t.vect.algebra expression='B2 = A1 {+,equal|during,i} A3' basename="bmap2"
-t.vect.list input=B2 column=name,start_time,end_time
-t.vect.algebra expression='B3 = buff_p(P1,10)' basename="bmap3"
-t.vect.list input=B3 column=name,start_time,end_time
-t.vect.algebra expression='B4 = buff_p(P2,30) {|,equal|during} A4' basename="bmap4"
-t.vect.list input=B4 column=name,start_time,end_time
-t.vect.algebra expression='B5 = if(td(A1) == 1 || start_date(A1) >= "2010-01-10", A2)' basename="bmap5"
-t.vect.list input=B5 column=name,start_time,end_time
-t.vect.algebra expression='B6 = buff_p(P2,30) {&,equal|during|started,d} buff_p(P3,30)' basename="bmap6"
-t.vect.list input=B6 column=name,start_time,end_time
-t.vect.algebra expression='B7 = buff_p(P2,30) {&,starts,d} buff_p(P3,30)' basename="bmap7"
-t.vect.list input=B8 column=name,start_time,end_time
-t.vect.algebra expression='B8 = buff_p(P2,30) {|,starts,d} buff_p(P3,30)' basename="bmap8"
-t.vect.list input=B8 column=name,start_time,end_time
Added: grass/trunk/temporal/t.vect.algebra/testsuite/test_vector_algebra.py
===================================================================
--- grass/trunk/temporal/t.vect.algebra/testsuite/test_vector_algebra.py (rev 0)
+++ grass/trunk/temporal/t.vect.algebra/testsuite/test_vector_algebra.py 2014-11-06 20:07:09 UTC (rev 62640)
@@ -0,0 +1,194 @@
+"""
+(C) 2014 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.
+
+:authors: Soeren Gebbert and Thomas Leppelt
+"""
+
+import datetime
+import os
+import grass.script
+import grass.temporal as tgis
+import grass.gunittest as gunittest
+
+class TestTemporalVectorAlgebra(gunittest.TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ """Initiate the temporal GIS and set the region
+ """
+ os.putenv("GRASS_OVERWRITE", "1")
+ tgis.init(True) # Raise on error instead of exit(1)
+ cls.use_temp_region()
+ cls.runModule("g.region", n=80.0, s=0.0, e=120.0,
+ w=0.0, t=1.0, b=0.0, res=10.0)
+
+ cls.runModule("v.random", quiet=True, n=20, seed=1, output='a1')
+ cls.runModule("v.random", quiet=True, n=20, seed=1, output='a2')
+ cls.runModule("v.random", quiet=True, n=20, seed=1, output='a3')
+ cls.runModule("v.random", quiet=True, n=20, seed=1, output='a4')
+ cls.runModule("v.random", quiet=True, n=20, seed=2, output='b1')
+ cls.runModule("v.random", quiet=True, n=20, seed=2, output='b2')
+ cls.runModule("v.random", quiet=True, n=20, seed=3, output='c1')
+ cls.runModule("v.random", quiet=True, n=20, seed=4, output='d1')
+ cls.runModule("v.random", quiet=True, n=20, seed=4, output='d2')
+ cls.runModule("v.random", quiet=True, n=20, seed=4, output='d3')
+ cls.runModule("v.random", quiet=True, n=20, seed=5, output='singletmap')
+ cls.runModule("v.random", quiet=True, n=20, seed=6, output='singlemap')
+
+ tgis.open_new_stds(name="A", type="stvds", temporaltype="absolute",
+ title="A", descr="A", semantic="field")
+ tgis.open_new_stds(name="B", type="stvds", temporaltype="absolute",
+ title="B", descr="B", semantic="field")
+ tgis.open_new_stds(name="C", type="stvds", temporaltype="absolute",
+ title="B", descr="C", semantic="field")
+ tgis.open_new_stds(name="D", type="stvds", temporaltype="absolute",
+ title="D", descr="D", semantic="field")
+
+ tgis.register_maps_in_space_time_dataset(type="vect", name="A", maps="a1,a2,a3,a4",
+ start="2001-01-01", increment="1 day", interval=True)
+ tgis.register_maps_in_space_time_dataset(type="vect", name="B", maps="b1,b2",
+ start="2001-01-01", increment="2 day", interval=True)
+ tgis.register_maps_in_space_time_dataset(type="vect", name="C", maps="c1",
+ start="2001-01-02", increment="2 day", interval=True)
+ tgis.register_maps_in_space_time_dataset(type="vect", name="D", maps="d1,d2,d3",
+ start="2001-01-03", increment="1 day", interval=True)
+ tgis.register_maps_in_space_time_dataset(type="vect", name=None, maps="singletmap",
+ start="2001-01-03", end="2001-01-04", interval=True)
+
+ def tearDown(self):
+ self.runModule("t.remove", type="stvds", inputs="R", quiet=True)
+
+ @classmethod
+ def tearDownClass(cls):
+ """Remove the temporary region
+ """
+ cls.runModule("t.remove", flags="rf", inputs="A,B,C,D", type='stvds', quiet=True)
+ cls.del_temp_region()
+
+ def test_temporal_select(self):
+ """Testing the temporal select operator. """
+
+ self.assertModule("t.vect.algebra", expression="R = A : A", basename="r")
+
+ D = tgis.open_old_stds("R", type="stvds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 4)
+ self.assertEqual(D.metadata.get_number_of_points(), 80)
+ self.assertEqual(D.metadata.get_number_of_areas(), 0)
+ self.assertEqual(D.metadata.get_number_of_centroids(), 0)
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 1))
+ self.assertEqual(end, datetime.datetime(2001, 1, 5))
+ self.assertEqual( D.check_temporal_topology(), True)
+ self.assertEqual(D.get_granularity(), u'1 day')
+
+ def test_temporal_select_operators(self):
+ """Testing the temporal select operator. Including temporal relations. """
+
+ self.assertModule("t.vect.algebra", expression="R = A {:,during} C", basename="r")
+
+ D = tgis.open_old_stds("R", type="stvds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 2)
+ self.assertEqual(D.metadata.get_number_of_points(), 40)
+ self.assertEqual(D.metadata.get_number_of_areas(), 0)
+ self.assertEqual(D.metadata.get_number_of_centroids(), 0)
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 2))
+ self.assertEqual(end, datetime.datetime(2001, 1, 4))
+ self.assertEqual( D.check_temporal_topology(), True)
+ self.assertEqual(D.get_granularity(), u'1 day')
+
+ def test_temporal_buff_operators_1(self):
+ """Testing the bufferoperator."""
+
+ self.assertModule("t.vect.algebra", expression="R = buff_p(A,0.5)", basename="r")
+
+ D = tgis.open_old_stds("R", type="stvds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 4)
+ self.assertEqual(D.metadata.get_number_of_points(), 0)
+ self.assertEqual(D.metadata.get_number_of_areas(), 80)
+ self.assertEqual(D.metadata.get_number_of_centroids(), 80)
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 1))
+ self.assertEqual(end, datetime.datetime(2001, 1, 5))
+ self.assertEqual( D.check_temporal_topology(), True)
+ self.assertEqual(D.get_granularity(), u'1 day')
+
+ def test_temporal_buff_operators_2(self):
+ """Testing the bufferoperator."""
+
+ self.assertModule("t.vect.algebra", expression="R = buff_a(buff_p(A,1),10)", basename="r")
+
+ D = tgis.open_old_stds("R", type="stvds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 4)
+ self.assertEqual(D.metadata.get_number_of_points(), 0)
+ self.assertEqual(D.metadata.get_number_of_areas(), 20)
+ self.assertEqual(D.metadata.get_number_of_centroids(), 20)
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 1))
+ self.assertEqual(end, datetime.datetime(2001, 1, 5))
+ self.assertEqual( D.check_temporal_topology(), True)
+ self.assertEqual(D.get_granularity(), u'1 day')
+
+ def test_temporal_overlay_operators_1(self):
+ """Testing the spatial overlay operator."""
+
+ self.assertModule("t.vect.algebra", expression="R = buff_p(A,2) & buff_p(D,2)", basename="r")
+
+ D = tgis.open_old_stds("R", type="stvds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 2)
+ self.assertEqual(D.metadata.get_number_of_points(), 0)
+ self.assertEqual(D.metadata.get_number_of_areas(), 6)
+ self.assertEqual(D.metadata.get_number_of_centroids(), 6)
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 3))
+ self.assertEqual(end, datetime.datetime(2001, 1, 5))
+ self.assertEqual( D.check_temporal_topology(), True)
+ self.assertEqual(D.get_granularity(), u'1 day')
+
+ def test_temporal_overlay_operators_2(self):
+ """Testing the spatial overlay operator."""
+
+ self.assertModule("t.vect.algebra", expression="R = buff_p(A,1.5) {&,during,r} buff_p(B,1.5)", basename="r")
+
+ D = tgis.open_old_stds("R", type="stvds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 4)
+ self.assertEqual(D.metadata.get_number_of_points(), 0)
+ self.assertEqual(D.metadata.get_number_of_areas(), 8)
+ self.assertEqual(D.metadata.get_number_of_centroids(), 8)
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 1))
+ self.assertEqual(end, datetime.datetime(2001, 1, 5))
+ self.assertEqual( D.check_temporal_topology(), False)
+ self.assertEqual(D.get_granularity(), u'2 days')
+
+ def test_temporal_overlay_operators_3(self):
+ """Testing the spatial overlay operator."""
+
+ self.assertModule("t.vect.algebra", expression="R = buff_p(A,2.5) {&,during,l} buff_p(C,2.5)", basename="r")
+
+ D = tgis.open_old_stds("R", type="stvds")
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 2)
+ self.assertEqual(D.metadata.get_number_of_points(), 0)
+ self.assertEqual(D.metadata.get_number_of_areas(), 8)
+ self.assertEqual(D.metadata.get_number_of_centroids(), 8)
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 2))
+ self.assertEqual(end, datetime.datetime(2001, 1, 4))
+ self.assertEqual( D.check_temporal_topology(), True)
+ self.assertEqual(D.get_granularity(), u'1 day')
+
+if __name__ == '__main__':
+ gunittest.test()
+
+
+
More information about the grass-commit
mailing list