[GRASS-SVN] r66557 - grass/trunk/temporal/t.rast.accumulate/testsuite
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Oct 21 05:40:20 PDT 2015
Author: huhabla
Date: 2015-10-21 05:40:20 -0700 (Wed, 21 Oct 2015)
New Revision: 66557
Added:
grass/trunk/temporal/t.rast.accumulate/testsuite/test_accumulation.py
Removed:
grass/trunk/temporal/t.rast.accumulate/testsuite/data/
grass/trunk/temporal/t.rast.accumulate/testsuite/test.t.rast.accumulate.sh
Log:
temporal modules: Converted bash test of t.rast.accumulate into Python gunittest
Deleted: grass/trunk/temporal/t.rast.accumulate/testsuite/test.t.rast.accumulate.sh
===================================================================
--- grass/trunk/temporal/t.rast.accumulate/testsuite/test.t.rast.accumulate.sh 2015-10-21 12:01:57 UTC (rev 66556)
+++ grass/trunk/temporal/t.rast.accumulate/testsuite/test.t.rast.accumulate.sh 2015-10-21 12:40:20 UTC (rev 66557)
@@ -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
-
-
Added: grass/trunk/temporal/t.rast.accumulate/testsuite/test_accumulation.py
===================================================================
--- grass/trunk/temporal/t.rast.accumulate/testsuite/test_accumulation.py (rev 0)
+++ grass/trunk/temporal/t.rast.accumulate/testsuite/test_accumulation.py 2015-10-21 12:40:20 UTC (rev 66557)
@@ -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.
+
+ at 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()
More information about the grass-commit
mailing list