[GRASS-SVN] r71379 - in grass/trunk/lib/python/temporal: . testsuite
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Aug 10 13:46:33 PDT 2017
Author: huhabla
Date: 2017-08-10 13:46:33 -0700 (Thu, 10 Aug 2017)
New Revision: 71379
Added:
grass/trunk/lib/python/temporal/testsuite/unittests_temporal_raster_conditionals_complement_else.py
Modified:
grass/trunk/lib/python/temporal/open_stds.py
grass/trunk/lib/python/temporal/testsuite/unittests_temporal_raster_algebra_spatial_topology.py
Log:
temporal framework: Implementing temporal algebra complement tests that show the current condition bugs
Modified: grass/trunk/lib/python/temporal/open_stds.py
===================================================================
--- grass/trunk/lib/python/temporal/open_stds.py 2017-08-10 20:40:25 UTC (rev 71378)
+++ grass/trunk/lib/python/temporal/open_stds.py 2017-08-10 20:46:33 UTC (rev 71379)
@@ -49,7 +49,7 @@
# Check if the dataset name contains the mapset as well
if name.find("@") < 0:
- id = name + "@" + mapset
+ id = name.decode("utf-8") + "@" + mapset.decode("utf-8")
else:
id = name
Modified: grass/trunk/lib/python/temporal/testsuite/unittests_temporal_raster_algebra_spatial_topology.py
===================================================================
--- grass/trunk/lib/python/temporal/testsuite/unittests_temporal_raster_algebra_spatial_topology.py 2017-08-10 20:40:25 UTC (rev 71378)
+++ grass/trunk/lib/python/temporal/testsuite/unittests_temporal_raster_algebra_spatial_topology.py 2017-08-10 20:46:33 UTC (rev 71379)
@@ -13,7 +13,7 @@
from grass.gunittest.main import test
-class TestTemporalRasterAlgebraImplicitAggregation(TestCase):
+class TestTemporalRasterAlgebraSpatialTopology(TestCase):
@classmethod
def setUpClass(cls):
@@ -57,6 +57,7 @@
def tearDown(self):
self.runModule("t.remove", flags="rf", inputs="R", quiet=True)
+ pass
@classmethod
def tearDownClass(cls):
@@ -76,10 +77,10 @@
spatial equal extents pairs: a1,b1 a2,b2 a3,b3 a4,b4
- r1 = a1 + b1 # 2
+ r0 = a1 + b1 # 2
r1 = a2 + b2 # 4
- r1 = a3 + b3 # 6
- r1 = a4 + b4 # 8
+ r2 = a3 + b3 # 6
+ r3 = a4 + b4 # 8
"""
ta = tgis.TemporalRasterAlgebraParser(run=True, debug=True, spatial=True)
@@ -96,7 +97,124 @@
self.assertEqual( D.check_temporal_topology(), False)
self.assertEqual(D.get_granularity(), None)
+ def test_equal_overlap_sum(self):
+ """Spatial topology distinction with equal timestamps
+ STRDS A and B have identical time stamps, hence the differentiation
+ is based on the spatial topological relations
+
+ R = A {+,equal|overlap,l} B
+
+ spatial overlap extents pairs: a3,b1 a1,b2,b3 a2,b1,b4 a4,b2
+
+ r0 = a3 + b1 # 4
+ r1 = a1 + b2 + b3 # NULL
+ r2 = a2 + b1 + b4 # NULL
+ r3 = a4 + b2 # 6
+
+ """
+ ta = tgis.TemporalRasterAlgebraParser(run=True, debug=True, spatial=True)
+ ta.parse(expression="R = A {+,equal|overlap,l} B", basename="r", overwrite=True)
+
+ D = tgis.open_old_stds("R", type="strds")
+ D.select()
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 2)
+ self.assertEqual(D.metadata.get_min_min(), 4)
+ self.assertEqual(D.metadata.get_max_max(), 6)
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 1))
+ self.assertEqual( D.check_temporal_topology(), False)
+ self.assertEqual(D.get_granularity(), None)
+
+ def test_equal_overlap_sum_with_null(self):
+ """Spatial topology distinction with equal timestamps
+
+ STRDS A and B have identical time stamps, hence the differentiation
+ is based on the spatial topological relations
+
+ R = A {+,equal|cover,l} B
+
+ spatial overlap extents pairs: a3,b1 a1,b2,b3 a2,b1,b4 a4,b2
+
+ r0 = a3 + b1 # 4
+ r1 = a1 + b2 + b3 # NULL
+ r2 = a2 + b1 + b4 # NULL
+ r3 = a4 + b2 # 6
+
+ """
+ ta = tgis.TemporalRasterAlgebraParser(run=True, debug=True, spatial=True, register_null=True)
+ ta.parse(expression="R = A {+,equal|overlap,l} B", basename="r", overwrite=True)
+
+ D = tgis.open_old_stds("R", type="strds")
+ D.select()
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 4)
+ self.assertEqual(D.metadata.get_min_min(), 4)
+ self.assertEqual(D.metadata.get_max_max(), 6)
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 1))
+ self.assertEqual( D.check_temporal_topology(), False)
+ self.assertEqual(D.get_granularity(), None)
+
+ def test_equal_contain_sum(self):
+ """Spatial topology distinction with equal timestamps
+
+ STRDS A and B have identical time stamps, hence the differentiation
+ is based on the spatial topological relations
+
+ R = A {+,equal|overlap,l} B
+
+ spatial overlap extents pairs: a2,b3
+
+ r0 = a2 + b3 # 4
+
+ """
+ ta = tgis.TemporalRasterAlgebraParser(run=True, debug=True, spatial=True)
+ ta.parse(expression="R = A {+,equal|contain,l} B", basename="r", overwrite=True)
+
+ D = tgis.open_old_stds("R", type="strds")
+ D.select()
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 1)
+ self.assertEqual(D.metadata.get_min_min(), 5)
+ self.assertEqual(D.metadata.get_max_max(), 5)
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 1))
+ self.assertEqual( D.check_temporal_topology(), True)
+ self.assertEqual(D.get_granularity(), None)
+
+ def test_equal_equivalent_contain_sum(self):
+ """Spatial topology distinction with equal timestamps
+
+ STRDS A and B have identical time stamps, hence the differentiation
+ is based on the spatial topological relations
+
+ R = A {+,equal|equivalent|contain,l} B
+
+ spatial overlap extents pairs: a2,b3
+ spatial equal extents pairs: a1,b1 a2,b2 a3,b3 a4,b4
+
+ r0 = a1 + b1 # 2
+ r1 = a2 + b2 + b3 # 7
+ r2 = a3 + b3 # 6
+ r3 = a4 + b4 # 8
+
+ """
+ ta = tgis.TemporalRasterAlgebraParser(run=True, debug=True, spatial=True)
+ ta.parse(expression="R = A {+,equal|equivalent|contain,l} B", basename="r", overwrite=True)
+
+ D = tgis.open_old_stds("R", type="strds")
+ D.select()
+
+ self.assertEqual(D.metadata.get_number_of_maps(), 4)
+ self.assertEqual(D.metadata.get_min_min(), 2)
+ self.assertEqual(D.metadata.get_max_max(), 8)
+ start, end = D.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 1))
+ self.assertEqual( D.check_temporal_topology(), False)
+ self.assertEqual(D.get_granularity(), None)
+
def test_equal_equivalent_compare(self):
"""Test implicit aggregation
@@ -107,10 +225,10 @@
spatial equal extents pairs: a1,b1 a2,b2 a3,b3 a4,b4
- r1 = a1 + b1 # 2
+ r0 = a1 + b1 # 2
r1 = a2 + b2 # 4
- r1 = a3 + b3 # 6
- r1 = a4 + b4 # 8
+ r2 = a3 + b3 # 6
+ r3 = a4 + b4 # 8
"""
ta = tgis.TemporalRasterAlgebraParser(run=True, debug=True, spatial=True)
Added: grass/trunk/lib/python/temporal/testsuite/unittests_temporal_raster_conditionals_complement_else.py
===================================================================
--- grass/trunk/lib/python/temporal/testsuite/unittests_temporal_raster_conditionals_complement_else.py (rev 0)
+++ grass/trunk/lib/python/temporal/testsuite/unittests_temporal_raster_conditionals_complement_else.py 2017-08-10 20:46:33 UTC (rev 71379)
@@ -0,0 +1,127 @@
+"""
+(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 grass.temporal as tgis
+from grass.gunittest.case import TestCase
+from grass.gunittest.main import test
+
+
+class TestTemporalRasterAlgebraConditionalComplements(TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ """Initiate the temporal GIS and set the region
+ """
+ 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", overwrite=True, quiet=True, expression="a1 = 1")
+ cls.runModule("r.mapcalc", overwrite=True, quiet=True, expression="a2 = 2")
+ cls.runModule("r.mapcalc", overwrite=True, quiet=True, expression="a3 = 3")
+ cls.runModule("r.mapcalc", overwrite=True, quiet=True, expression="a4 = 4")
+ cls.runModule("r.mapcalc", overwrite=True, quiet=True, expression="a5 = 5")
+ cls.runModule("r.mapcalc", overwrite=True, quiet=True, expression="a6 = 6")
+ cls.runModule("r.mapcalc", overwrite=True, quiet=True, expression="b1 = 7")
+ cls.runModule("r.mapcalc", overwrite=True, quiet=True, expression="b2 = 8")
+
+ tgis.open_new_stds(name="A", type="strds", temporaltype="absolute",
+ title="A", descr="A", semantic="field", overwrite=True)
+ tgis.open_new_stds(name="B", type="strds", temporaltype="absolute",
+ title="B", descr="B", semantic="field", overwrite=True)
+
+ tgis.register_maps_in_space_time_dataset(type="raster", name="A", maps="a1,a2,a3,a4,a5,a6",
+ start="2001-01-01", increment="1 day", interval=True)
+ tgis.register_maps_in_space_time_dataset(type="raster", name="B", maps="b1,b2",
+ start="2001-01-02", increment="2 day", 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", quiet=True)
+ cls.del_temp_region()
+
+ def test_temporal_conditional_complement(self):
+ """Test the conditional expression that evaluate if then else statements
+ so that the else statement is a complement operation
+
+ R = if({equal|contains}, B {#,contains,r} A == 2, B {+,contains,l} A, A)
+
+ IF B contains two maps from A
+ THEN add maps from A and B that fulfill the B contains A condition using implicit aggregation
+ ELSE copy the maps from A
+
+ The connection between the if then else statements are the topological relations equal and contains
+
+ r0 = a1 # 1
+ r1 = b1 + a2 + a3 # 12
+ r2 = b2 + a4 + a5 # 16
+ r4 = a6 # 6
+
+ """
+ tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra.parse(expression='R = if({equal|contains}, B {#,contains,r} A == 2, B {+,contains,l} A, A)',
+ basename="r", overwrite=True)
+
+ R = tgis.open_old_stds("R", type="strds")
+ R.select()
+ self.assertEqual(R.metadata.get_number_of_maps(), 4)
+ self.assertEqual(R.metadata.get_min_min(), 1)
+ self.assertEqual(R.metadata.get_max_max(), 16)
+ start, end = R.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 1))
+ self.assertEqual(end, datetime.datetime(2001, 1, 7))
+ self.assertEqual( R.check_temporal_topology(), True)
+ self.assertEqual(R.get_granularity(), u'1 day')
+
+ def test_temporal_conditional_complement_right_side_timestamps(self):
+ """Test the conditional expression that evaluate if then else statements
+ so that the else statement is a complement operation
+
+ R = if({equal|contains|during}, B {#,contains,r} A == 2, B {+,contains,r} A, A)
+
+ IF B contains two maps from A
+ THEN add maps from A and B that fulfill the B contains A condition using the right side timestamps
+ ELSE copy the maps from A
+
+ The connection between the if then else statements are the
+ topological relations equal, contains and during
+
+ r0 = a1 # 1
+ r1 = b1 + a2 + a3 # 12
+ r2 = b1 + a2 + a3 # 12
+ r3 = b2 + a4 + a5 # 16
+ r4 = b2 + a4 + a5 # 16
+ r5 = a6 # 6
+
+ """
+ tra = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+ tra.parse(expression='R = if({equal|contains|during}, B {#,contains,r} A == 2, B {+,contains,r} A, A)',
+ basename="r", overwrite=True)
+
+ R = tgis.open_old_stds("R", type="strds")
+ R.select()
+ self.assertEqual(R.metadata.get_number_of_maps(), 6)
+ self.assertEqual(R.metadata.get_min_min(), 1)
+ self.assertEqual(R.metadata.get_max_max(), 16)
+ start, end = R.get_absolute_time()
+ self.assertEqual(start, datetime.datetime(2001, 1, 1))
+ self.assertEqual(end, datetime.datetime(2001, 1, 7))
+ self.assertEqual( R.check_temporal_topology(), True)
+ self.assertEqual(R.get_granularity(), u'1 day')
+
+
+if __name__ == '__main__':
+ test()
More information about the grass-commit
mailing list