ソースを参照

temporal modules: Converted bash test of t.rast.accumulate into Python gunittest

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@66557 15284696-431f-4ddb-bdfa-cd5b030d7da7
Soeren Gebbert 9 年 前
コミット
b93bfb2fc4

+ 0 - 39
temporal/t.rast.accumulate/testsuite/data/acc_1.ref

@@ -1,39 +0,0 @@
- +-------------------- Space Time Raster Dataset -----------------------------+
- |                                                                            |
- +-------------------- Basic information -------------------------------------+
- | Name: ...................... precip_abs2
- | Creator: ................... soeren
- | Temporal type: ............. absolute
- | Semantic type:.............. mean
- +-------------------- Absolute time -----------------------------------------+
- | Start time:................. 2001-01-01 00:00:00
- | End time:................... 2002-01-01 00:00:00
- | Granularity:................ 4 months
- | Temporal type of maps:...... interval
- +-------------------- Spatial extent ----------------------------------------+
- | North:...................... 80.0
- | South:...................... 0.0
- | East:.. .................... 120.0
- | West:....................... 0.0
- | Top:........................ 0.0
- | Bottom:..................... 0.0
- +-------------------- Metadata information ----------------------------------+
- | North-South resolution min:. 10.0
- | North-South resolution max:. 10.0
- | East-west resolution min:... 10.0
- | East-west resolution max:... 10.0
- | Minimum value min:.......... 0.0
- | Minimum value max:.......... 0.0
- | Maximum value min:.......... 21.5
- | Maximum value max:.......... 60.0
- |
- | Title:
- | A test
- | Description:
- | A test
- | Command history:
- | t.rast.accumulate input="precip_abs1"
- |     output="precip_abs2" base="prec_acc" limits="10,30" start="2001-01-01"
- |     gran="4 months" cycle="12 months"
- | 
- +----------------------------------------------------------------------------+

+ 0 - 39
temporal/t.rast.accumulate/testsuite/data/acc_2.ref

@@ -1,39 +0,0 @@
- +-------------------- Space Time Raster Dataset -----------------------------+
- |                                                                            |
- +-------------------- Basic information -------------------------------------+
- | Name: ...................... precip_abs2
- | Creator: ................... soeren
- | Temporal type: ............. absolute
- | Semantic type:.............. mean
- +-------------------- Absolute time -----------------------------------------+
- | Start time:................. 2001-01-01 00:00:00
- | End time:................... 2001-09-01 00:00:00
- | Granularity:................ 4 months
- | Temporal type of maps:...... interval
- +-------------------- Spatial extent ----------------------------------------+
- | North:...................... 80.0
- | South:...................... 0.0
- | East:.. .................... 120.0
- | West:....................... 0.0
- | Top:........................ 0.0
- | Bottom:..................... 0.0
- +-------------------- Metadata information ----------------------------------+
- | North-South resolution min:. 10.0
- | North-South resolution max:. 10.0
- | East-west resolution min:... 10.0
- | East-west resolution max:... 10.0
- | Minimum value min:.......... 0.0
- | Minimum value max:.......... 0.0
- | Maximum value min:.......... 21.5
- | Maximum value max:.......... 39.5
- |
- | Title:
- | A test
- | Description:
- | A test
- | Command history:
- | t.rast.accumulate input="precip_abs1"
- |     output="precip_abs2" base="prec_acc" limits="10,30" start="2001-01-01"
- |     stop="2002-01-01" gran="4 months" cycle="7 months"
- | 
- +----------------------------------------------------------------------------+

+ 0 - 39
temporal/t.rast.accumulate/testsuite/data/acc_3.ref

@@ -1,39 +0,0 @@
- +-------------------- Space Time Raster Dataset -----------------------------+
- |                                                                            |
- +-------------------- Basic information -------------------------------------+
- | Name: ...................... precip_abs2
- | Creator: ................... soeren
- | Temporal type: ............. absolute
- | Semantic type:.............. mean
- +-------------------- Absolute time -----------------------------------------+
- | Start time:................. 2001-01-01 00:00:00
- | End time:................... 2002-01-01 00:00:00
- | Granularity:................ 2 months
- | Temporal type of maps:...... interval
- +-------------------- Spatial extent ----------------------------------------+
- | North:...................... 80.0
- | South:...................... 0.0
- | East:.. .................... 120.0
- | West:....................... 0.0
- | Top:........................ 0.0
- | Bottom:..................... 0.0
- +-------------------- Metadata information ----------------------------------+
- | North-South resolution min:. 10.0
- | North-South resolution max:. 10.0
- | East-west resolution min:... 10.0
- | East-west resolution max:... 10.0
- | Minimum value min:.......... 0.0
- | Minimum value max:.......... 0.0
- | Maximum value min:.......... 24.0
- | Maximum value max:.......... 120.0
- |
- | Title:
- | A test
- | Description:
- | A test
- | Command history:
- | t.rast.accumulate input="precip_abs1"
- |     output="precip_abs2" base="prec_acc" limits="10,30" start="2001-01-01"
- |     gran="2 months" cycle="12 months"
- | 
- +----------------------------------------------------------------------------+

+ 0 - 39
temporal/t.rast.accumulate/testsuite/data/acc_4.ref

@@ -1,39 +0,0 @@
- +-------------------- Space Time Raster Dataset -----------------------------+
- |                                                                            |
- +-------------------- Basic information -------------------------------------+
- | Name: ...................... precip_abs2
- | Creator: ................... soeren
- | Temporal type: ............. absolute
- | Semantic type:.............. mean
- +-------------------- Absolute time -----------------------------------------+
- | Start time:................. 2001-01-01 00:00:00
- | End time:................... 2002-01-01 00:00:00
- | Granularity:................ 1 month
- | Temporal type of maps:...... interval
- +-------------------- Spatial extent ----------------------------------------+
- | North:...................... 80.0
- | South:...................... 0.0
- | East:.. .................... 120.0
- | West:....................... 0.0
- | Top:........................ 0.0
- | Bottom:..................... 0.0
- +-------------------- Metadata information ----------------------------------+
- | North-South resolution min:. 10.0
- | North-South resolution max:. 10.0
- | East-west resolution min:... 10.0
- | East-west resolution max:... 10.0
- | Minimum value min:.......... 0.0
- | Minimum value max:.......... 0.0
- | Maximum value min:.......... 24.0
- | Maximum value max:.......... 240.0
- |
- | Title:
- | A test
- | Description:
- | A test
- | Command history:
- | t.rast.accumulate input="precip_abs1"
- |     output="precip_abs2" base="prec_acc" limits="10,30" start="2001-01-01"
- |     stop="2002-01-01" gran="1 months" cycle="12 months"
- | 
- +----------------------------------------------------------------------------+

+ 0 - 40
temporal/t.rast.accumulate/testsuite/data/acc_5.ref

@@ -1,40 +0,0 @@
- +-------------------- Space Time Raster Dataset -----------------------------+
- |                                                                            |
- +-------------------- Basic information -------------------------------------+
- | Name: ...................... precip_abs2
- | Creator: ................... soeren
- | Temporal type: ............. absolute
- | Semantic type:.............. mean
- +-------------------- Absolute time -----------------------------------------+
- | Start time:................. 2001-01-01 00:00:00
- | End time:................... 2002-01-01 00:00:00
- | Granularity:................ 1 month
- | Temporal type of maps:...... interval
- +-------------------- Spatial extent ----------------------------------------+
- | North:...................... 80.0
- | South:...................... 0.0
- | East:.. .................... 120.0
- | West:....................... 0.0
- | Top:........................ 0.0
- | Bottom:..................... 0.0
- +-------------------- Metadata information ----------------------------------+
- | North-South resolution min:. 10.0
- | North-South resolution max:. 10.0
- | East-west resolution min:... 10.0
- | East-west resolution max:... 10.0
- | Minimum value min:.......... 0.0
- | Minimum value max:.......... 0.0
- | Maximum value min:.......... 24.0
- | Maximum value max:.......... 240.0
- |
- | Title:
- | A test
- | Description:
- | A test
- | Command history:
- | t.rast.accumulate input="precip_abs1"
- |     output="precip_abs2" base="prec_acc" limits="8,33" lower="lower"
- |     upper="upper" start="2001-01-01" stop="2002-01-01" gran="1 months"
- |     cycle="12 months"
- | 
- +----------------------------------------------------------------------------+

+ 0 - 80
temporal/t.rast.accumulate/testsuite/test.t.rast.accumulate.sh

@@ -1,80 +0,0 @@
-#!/bin/sh -e
-# Space time raster dataset neighborhood operations
-# We need to set a specific region in the
-# @preprocess step of this test. 
-# The region setting should work for UTM and LL test locations
-g.region s=0 n=80 w=0 e=120 b=0 t=50 res=10 -p
-
-export GRASS_OVERWRITE=1
-
-# Generate data
-r.mapcalc expr="prec_1 = rand(0, 25)" -s
-r.mapcalc expr="prec_2 = rand(0, 24)" -s
-r.mapcalc expr="prec_3 = rand(0, 23)" -s
-r.mapcalc expr="prec_4 = rand(0, 25)" -s
-r.mapcalc expr="prec_5 = rand(0, 23)" -s
-r.mapcalc expr="prec_6 = rand(0, 26)" -s
-
-t.create type=strds temporaltype=absolute output=precip_abs1 title="A test" descr="A test"
-t.register -i type=raster input=precip_abs1 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 \
-    start="2001-01-01" increment="2 months"
-
-# The first @test
-
-t.rast.accumulate input=precip_abs1 output=precip_abs2 base=prec_acc \
-    limits=10,30 start="2001-01-01" gran="4 months" \
-    cycle="12 months"
-
-# We need to filter the identifier that may be different on different systems
-# like creation time and mapset 
-t.info input=precip_abs2 | grep -v \# | grep -v Creation | grep -v register | grep -v Id | grep -v Mapset > data/acc_1.txt
-
-t.rast.accumulate input=precip_abs1 output=precip_abs2 base=prec_acc \
-    limits=10,30 start="2001-01-01" stop="2002-01-01" gran="4 months" \
-    cycle="7 months"
-
-t.info input=precip_abs2 | grep -v \# | grep -v Creation | grep -v register | grep -v Id | grep -v Mapset > data/acc_2.txt
-
-t.rast.accumulate input=precip_abs1 output=precip_abs2 base=prec_acc \
-    limits=10,30 start="2001-01-01" gran="2 months" \
-    cycle="12 months"
-
-t.info input=precip_abs2 | grep -v \# | grep -v Creation | grep -v register | grep -v Id | grep -v Mapset > data/acc_3.txt
-
-t.rast.accumulate input=precip_abs1 output=precip_abs2 base=prec_acc \
-    limits=10,30 start="2001-01-01" stop="2002-01-01" gran="1 months" \
-    cycle="12 months"
-
-t.info input=precip_abs2 | grep -v \# | grep -v Creation | grep -v register | grep -v Id | grep -v Mapset > data/acc_4.txt
-
-# Second test
-
-r.mapcalc expr="lower = 10"
-r.mapcalc expr="upper = 35"
-
-t.create type=strds temporaltype=absolute output=lower title="lower limit" descr="lower limit"
-t.register -i type=raster input=lower maps=lower start="2001-01-01" increment="8 months"
-
-t.create type=strds temporaltype=absolute output=upper title="upper limit" descr="upper limit"
-t.register -i type=raster input=upper maps=upper start="2001-01-01" increment="10 months"
-
-t.rast.accumulate input=precip_abs1 output=precip_abs2 base=prec_acc \
-    limits=8,33 lower=lower upper=upper start="2001-01-01" stop="2002-01-01" gran="1 months" \
-    cycle="12 months"
-
-t.info input=precip_abs2 | grep -v \# | grep -v Creation | grep -v register | grep -v Id | grep -v Mapset > data/acc_5.txt
-
-t.remove -rf type=strds input=precip_abs1,precip_abs2,lower,upper
-
-cd data
-
-for i in `ls acc_*.txt` ; do
-    diff $i "`basename $i .txt`.ref" >> out.diff
-done
-
-CHAR_NUM=`cat out.diff | wc -c`
-
-# Return as exit status 0 in case no diffs are found
-exit $CHAR_NUM
-
-

+ 212 - 0
temporal/t.rast.accumulate/testsuite/test_accumulation.py

@@ -0,0 +1,212 @@
+"""Test t.rast.accumulate
+
+(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.
+
+@author Soeren Gebbert
+"""
+
+import grass.temporal as tgis
+import datetime
+from grass.gunittest.case import TestCase
+from grass.gunittest.gmodules import SimpleModule
+
+class TestAccumulate(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",  s=0,  n=80,  w=0,  e=120,  b=0,  t=50,  res=10,  res3=10)
+
+        cls.runModule("r.mapcalc", expression="a_1 = 5",  overwrite=True)
+        cls.runModule("r.mapcalc", expression="a_2 = 10",  overwrite=True)
+        cls.runModule("r.mapcalc", expression="a_3 = 20",  overwrite=True)
+        cls.runModule("r.mapcalc", expression="a_4 = 35",  overwrite=True)
+        cls.runModule("r.mapcalc", expression="a_5 = 20",  overwrite=True)
+        cls.runModule("r.mapcalc", expression="a_6 = 10",  overwrite=True)
+        cls.runModule("r.mapcalc", expression="a_7 = 5",  overwrite=True)
+
+
+        cls.runModule("r.mapcalc", expression="lower = 10",  overwrite=True)
+        cls.runModule("r.mapcalc", expression="upper = 30",  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="a_1,a_2,a_3,a_4,a_5,a_6,a_7",
+                                     start="2001-01-01",
+                                     increment="1 day",  overwrite=True)
+
+        cls.runModule("t.create",  type="strds",  temporaltype="absolute",
+                                   output="Lower",  title="Lower",
+                                   description="Lower", overwrite=True)
+        cls.runModule("t.register",  type="raster",  input="Lower",
+                                     maps="lower",
+                                     start="2001-01-01",
+                                     end="2001-01-10",
+                                     overwrite=True)
+
+        cls.runModule("t.create",  type="strds",  temporaltype="absolute",
+                                   output="Upper",  title="Upper",
+                                   description="Upper", overwrite=True)
+        cls.runModule("t.register",  type="raster",  input="Upper",
+                                     maps="upper",
+                                     start="2001-01-01",
+                                     end="2001-01-10",
+                                     overwrite=True)
+
+    @classmethod
+    def tearDownClass(cls):
+        """Remove the temporary region
+        """
+        cls.runModule("t.remove",  flags="rf",  type="strds",
+                                   inputs="A")
+        cls.runModule("t.remove",  flags="rf",  type="strds",
+                                   inputs="B")
+        cls.runModule("t.remove",  flags="rf",  type="strds",
+                                   inputs="Lower")
+        cls.runModule("t.remove",  flags="rf",  type="strds",
+                                   inputs="Upper")
+        cls.del_temp_region()
+
+    def test_1(self):
+        self.assertModule("t.rast.accumulate",  input="A", output="B",
+                          limits=[0,40], method="gdd",
+                          start="2001-01-01", cycle="7 days",
+                          basename="b",
+                          overwrite=True,  verbose=True)
+
+        D = tgis.open_old_stds("B", type="strds")
+
+        self.assertEqual(D.metadata.get_number_of_maps(), 7)
+        self.assertEqual(D.metadata.get_min_min(), 5)
+        self.assertEqual(D.metadata.get_max_max(), 105)
+        start, end = D.get_absolute_time()
+        self.assertEqual(start, datetime.datetime(2001, 1, 1))
+        self.assertEqual(end, datetime.datetime(2001, 1, 8))
+        self.assertEqual( D.check_temporal_topology(),  True)
+        self.assertEqual(D.get_granularity(),  u'1 day')
+
+    def test_2(self):
+        self.assertModule("t.rast.accumulate",  input="A", output="B",
+                          limits=[10,40], method="gdd",
+                          start="2001-01-01", cycle="7 days",
+                          basename="b",
+                          overwrite=True,  verbose=True)
+
+        D = tgis.open_old_stds("B", type="strds")
+
+        self.assertEqual(D.metadata.get_number_of_maps(), 7)
+        self.assertEqual(D.metadata.get_min_min(), 0.0)
+        self.assertEqual(D.metadata.get_max_max(), 45.0)
+        start, end = D.get_absolute_time()
+        self.assertEqual(start, datetime.datetime(2001, 1, 1))
+        self.assertEqual(end, datetime.datetime(2001, 1, 8))
+        self.assertEqual( D.check_temporal_topology(),  True)
+        self.assertEqual(D.get_granularity(),  u'1 day')
+
+    def test_3(self):
+        self.assertModule("t.rast.accumulate",  input="A", output="B",
+                          limits=[10,30], method="bedd",
+                          start="2001-01-01", cycle="7 days",
+                          basename="b",
+                          overwrite=True,  verbose=True)
+
+        D = tgis.open_old_stds("B", type="strds")
+
+        self.assertEqual(D.metadata.get_number_of_maps(), 7)
+        self.assertEqual(D.metadata.get_min_min(), 0.0)
+        self.assertEqual(D.metadata.get_max_max(), 40.0)
+        start, end = D.get_absolute_time()
+        self.assertEqual(start, datetime.datetime(2001, 1, 1))
+        self.assertEqual(end, datetime.datetime(2001, 1, 8))
+        self.assertEqual( D.check_temporal_topology(),  True)
+        self.assertEqual(D.get_granularity(),  u'1 day')
+
+    def test_3_a(self):
+        self.assertModule("t.rast.accumulate",  input="A", output="B",
+                          lower="Lower",
+                          upper="Upper",
+                          limits=[0,40],
+                          method="bedd",
+                          start="2001-01-01", cycle="7 days",
+                          basename="b",
+                          overwrite=True,  verbose=True)
+
+        D = tgis.open_old_stds("B", type="strds")
+
+        self.assertEqual(D.metadata.get_number_of_maps(), 7)
+        self.assertEqual(D.metadata.get_min_min(), 0.0)
+        self.assertEqual(D.metadata.get_max_max(), 40.0)
+        start, end = D.get_absolute_time()
+        self.assertEqual(start, datetime.datetime(2001, 1, 1))
+        self.assertEqual(end, datetime.datetime(2001, 1, 8))
+        self.assertEqual( D.check_temporal_topology(),  True)
+        self.assertEqual(D.get_granularity(),  u'1 day')
+
+    def test_4(self):
+        self.assertModule("t.rast.accumulate",  input="A", output="B",
+                          limits=[10,30], method="bedd",
+                          start="2001-01-01", cycle="7 days",
+                          basename="b", granularity="2 days",
+                          overwrite=True,  verbose=True)
+
+        D = tgis.open_old_stds("B", type="strds")
+
+        self.assertEqual(D.metadata.get_number_of_maps(), 4)
+        self.assertEqual(D.metadata.get_min_min(), 0.0)
+        self.assertEqual(D.metadata.get_max_max(), 22.5)
+        start, end = D.get_absolute_time()
+        self.assertEqual(start, datetime.datetime(2001, 1, 1))
+        self.assertEqual(end, datetime.datetime(2001, 1, 9))
+        self.assertEqual( D.check_temporal_topology(),  True)
+        self.assertEqual(D.get_granularity(),  u'2 days')
+
+    def test_4_a(self):
+        self.assertModule("t.rast.accumulate",  input="A", output="B",
+                          lower="Lower",
+                          upper="Upper",
+                          limits=[0,40],
+                          method="bedd",
+                          start="2001-01-01", cycle="7 days",
+                          basename="b", granularity="2 days",
+                          overwrite=True,  verbose=True)
+
+        D = tgis.open_old_stds("B", type="strds")
+
+        self.assertEqual(D.metadata.get_number_of_maps(), 4)
+        self.assertEqual(D.metadata.get_min_min(), 0.0)
+        self.assertEqual(D.metadata.get_max_max(), 22.5)
+        start, end = D.get_absolute_time()
+        self.assertEqual(start, datetime.datetime(2001, 1, 1))
+        self.assertEqual(end, datetime.datetime(2001, 1, 9))
+        self.assertEqual( D.check_temporal_topology(),  True)
+        self.assertEqual(D.get_granularity(),  u'2 days')
+
+    def test_5(self):
+        self.assertModule("t.rast.accumulate",  input="A", output="B",
+                          limits=[0,40], method="gdd",
+                          start="2001-01-01", cycle="7 days",
+                          basename="b", stop="2001-01-05",
+                          overwrite=True,  verbose=True)
+
+        D = tgis.open_old_stds("B", type="strds")
+
+        self.assertEqual(D.metadata.get_number_of_maps(), 4)
+        self.assertEqual(D.metadata.get_min_min(), 5)
+        self.assertEqual(D.metadata.get_max_max(), 70)
+        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')
+
+if __name__ == '__main__':
+    from grass.gunittest.main import test
+    test()