[GRASS-SVN] r62626 - in grass/trunk/temporal/t.rast.aggregate: . testsuite
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Nov 5 12:30:53 PST 2014
Author: huhabla
Date: 2014-11-05 12:30:53 -0800 (Wed, 05 Nov 2014)
New Revision: 62626
Added:
grass/trunk/temporal/t.rast.aggregate/testsuite/test_aggregation_absolute.py
grass/trunk/temporal/t.rast.aggregate/testsuite/test_aggregation_relative.py
Removed:
grass/trunk/temporal/t.rast.aggregate/testsuite/test.t.rast.aggregate.relative_time.sh
grass/trunk/temporal/t.rast.aggregate/testsuite/test.t.rast.aggregate.sh
Modified:
grass/trunk/temporal/t.rast.aggregate/t.rast.aggregate.py
Log:
temporal modules: fixed aggregation computation, converted bash tests into python tests
Modified: grass/trunk/temporal/t.rast.aggregate/t.rast.aggregate.py
===================================================================
--- grass/trunk/temporal/t.rast.aggregate/t.rast.aggregate.py 2014-11-05 20:29:17 UTC (rev 62625)
+++ grass/trunk/temporal/t.rast.aggregate/t.rast.aggregate.py 2014-11-05 20:30:53 UTC (rev 62626)
@@ -176,7 +176,12 @@
output_strds = tgis.open_new_stds(output, "strds", temporal_type,
title, description, semantic_type,
dbif, gcore.overwrite())
- tgis.register_map_object_list("rast", output_list, output_strds, register_null,
+ if register_null:
+ register_null=False
+ else:
+ register_null=True
+
+ tgis.register_map_object_list("rast", output_list, output_strds, register_null,
sp.get_relative_time_unit(), dbif)
# Update the raster metadata table entries with aggregation type
Deleted: grass/trunk/temporal/t.rast.aggregate/testsuite/test.t.rast.aggregate.relative_time.sh
===================================================================
--- grass/trunk/temporal/t.rast.aggregate/testsuite/test.t.rast.aggregate.relative_time.sh 2014-11-05 20:29:17 UTC (rev 62625)
+++ grass/trunk/temporal/t.rast.aggregate/testsuite/test.t.rast.aggregate.relative_time.sh 2014-11-05 20:30:53 UTC (rev 62626)
@@ -1,42 +0,0 @@
-#!/bin/sh
-# Space time raster dataset aggregation
-
-# 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 res3=10 -p3
-
-# Data generation
-r.mapcalc --o expr="prec_1 = rand(0, 550)" -s
-r.mapcalc --o expr="prec_2 = rand(0, 450)" -s
-r.mapcalc --o expr="prec_3 = rand(0, 320)" -s
-r.mapcalc --o expr="prec_4 = null()"
-r.mapcalc --o expr="prec_5 = rand(0, 300)" -s
-r.mapcalc --o expr="prec_6 = rand(0, 650)" -s
-
-t.create --o type=strds temporaltype=relative output=precip_abs1 title="A test" descr="A test"
-t.register -i type=rast input=precip_abs1 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start=0 unit=days increment=3
-
-# The first @test
-
-t.rast.aggregate --o --v input=precip_abs1 output=precip_abs2 base=prec_sum \
- granularity=6 method=average sampling=overlaps,overlapped,contains -ns nprocs=2
-t.info type=strds input=precip_abs2
-t.rast.list input=precip_abs2
-
-t.rast.aggregate --o --v input=precip_abs1 output=precip_abs2 base=prec_sum \
- granularity=9 method=maximum sampling=contains offset=130 nprocs=3
-t.info type=strds input=precip_abs2
-t.rast.list input=precip_abs2
-
-t.rast.aggregate --o --v input=precip_abs1 output=precip_abs2 base=prec_sum \
- granularity=4 method=minimum sampling=contains -s
-t.info type=strds input=precip_abs2
-t.rast.list input=precip_abs2
-
-t.rast.aggregate --o --v input=precip_abs1 output=precip_abs2 base=prec_sum \
- granularity=5 method=sum sampling=overlaps,overlapped,contains -n
-t.info type=strds input=precip_abs2
-t.rast.list input=precip_abs2
-
-t.remove -rf type=strds input=precip_abs1,precip_abs2
Deleted: grass/trunk/temporal/t.rast.aggregate/testsuite/test.t.rast.aggregate.sh
===================================================================
--- grass/trunk/temporal/t.rast.aggregate/testsuite/test.t.rast.aggregate.sh 2014-11-05 20:29:17 UTC (rev 62625)
+++ grass/trunk/temporal/t.rast.aggregate/testsuite/test.t.rast.aggregate.sh 2014-11-05 20:30:53 UTC (rev 62626)
@@ -1,51 +0,0 @@
-#!/bin/sh
-# Space time raster dataset aggregation
-# We need to set a specific region in the
-# @preprocess step of this test.
-
-export GRASS_OVERWRITE=1
-
-# 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 res3=10 -p3
-
-# Generate data
-r.mapcalc expr="prec_1 = rand(0, 550)" -s
-r.mapcalc expr="prec_2 = rand(0, 450)" -s
-r.mapcalc expr="prec_3 = rand(0, 320)" -s
-r.mapcalc expr="prec_4 = rand(0, 510)" -s
-r.mapcalc expr="prec_5 = rand(0, 300)" -s
-r.mapcalc expr="prec_6 = rand(0, 650)" -s
-r.mapcalc expr="prec_7 = null()"
-
-t.create type=strds temporaltype=absolute output=precip_abs1 title="A test" descr="A test"
-t.register -i type=rast input=precip_abs1 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6,prec_7 \
- start="2001-01-15 12:05:45" increment="14 days"
-
-# The first @test
-t.rast.aggregate --v input=precip_abs1 output=precip_abs2 \
- base=prec_sum granularity="2 days" method=average \
- sampling=overlaps,overlapped,during nprocs=5 -sn
-t.info type=strds input=precip_abs2
-t.rast.list input=precip_abs1
-t.rast.list input=precip_abs2
-
-t.rast.aggregate --v input=precip_abs1 output=precip_abs2 \
- base=prec_sum granularity="1 months" method=maximum \
- sampling=contains nprocs=5 -n
-t.info type=strds input=precip_abs2
-t.rast.list input=precip_abs1
-t.rast.list input=precip_abs2
-
-t.rast.aggregate --v input=precip_abs1 output=precip_abs3 offset=10 \
- base=prec_sum granularity="2 months" method=minimum \
- sampling=contains
-t.info type=strds input=precip_abs3
-t.rast.list input=precip_abs3
-
-t.rast.aggregate --v input=precip_abs1 output=precip_abs4 offset=100 \
- base=prec_sum granularity="3 months" method=sum \
- sampling=contains
-t.info type=strds input=precip_abs4
-t.rast.list input=precip_abs4
-
-t.remove -rf type=strds input=precip_abs1,precip_abs2,precip_abs3,precip_abs4
Added: grass/trunk/temporal/t.rast.aggregate/testsuite/test_aggregation_absolute.py
===================================================================
--- grass/trunk/temporal/t.rast.aggregate/testsuite/test_aggregation_absolute.py (rev 0)
+++ grass/trunk/temporal/t.rast.aggregate/testsuite/test_aggregation_absolute.py 2014-11-05 20:30:53 UTC (rev 62626)
@@ -0,0 +1,178 @@
+"""Test t.rast.aggregation
+
+(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
+"""
+import os
+import grass.pygrass.modules as pymod
+import grass.temporal as tgis
+from grass.gunittest.case import TestCase
+from grass.gunittest.gmodules import SimpleModule
+
+class TestUnregister(TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ """Initiate the temporal GIS and set the region
+ """
+ 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 = 100", overwrite=True)
+ cls.runModule("r.mapcalc", expression="a2 = 200", overwrite=True)
+ cls.runModule("r.mapcalc", expression="a3 = 300", overwrite=True)
+ cls.runModule("r.mapcalc", expression="a4 = 400", overwrite=True)
+ cls.runModule("r.mapcalc", expression="a5 = 500", overwrite=True)
+ cls.runModule("r.mapcalc", expression="a6 = 600", overwrite=True)
+ cls.runModule("r.mapcalc", expression="a7 = null()", 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="rast", input="A",
+ maps="a1,a2,a3,a4,a5,a6,a7",
+ start="2001-01-15 12:05:45",
+ increment="14 days",
+ 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_disaggregation(self):
+ """Disaggregation with empty maps"""
+ self.assertModule("t.rast.aggregate", input="A", output="B",
+ basename="b", granularity="2 days",
+ method="average",
+ sampling=["overlaps","overlapped","during"],
+ nprocs=2, flags="n")
+
+ tinfo_string="""start_time=2001-01-15 00:00:00
+ end_time=2001-04-25 00:00:00
+ granularity=2 days
+ aggregation_type=average
+ number_of_maps=50
+ map_time=interval
+ min_min=100.0
+ min_max=600.0
+ max_min=100.0
+ max_max=600.0"""
+
+ info = SimpleModule("t.info", flags="g", input="B")
+ #info.run()
+ #print info.outputs.stdout
+ self.assertModuleKeyValue(module=info, reference=tinfo_string,
+ precision=2, sep="=")
+
+ def test_aggregation_1month(self):
+ """Aggregation one month"""
+ self.assertModule("t.rast.aggregate", input="A", output="B",
+ basename="b", granularity="1 months",
+ method="maximum", sampling=["contains"],
+ nprocs=3, flags="s")
+
+ tinfo_string="""start_time=2001-01-01 00:00:00
+ end_time=2001-04-01 00:00:00
+ granularity=1 month
+ map_time=interval
+ aggregation_type=maximum
+ number_of_maps=3
+ min_min=100.0
+ min_max=500.0
+ max_min=100.0
+ max_max=500.0"""
+
+ info = SimpleModule("t.info", flags="g", input="B")
+ #info.run()
+ #print info.outputs.stdout
+ self.assertModuleKeyValue(module=info, reference=tinfo_string,
+ precision=2, sep="=")
+
+ # Check the map names are correct
+ lister = SimpleModule("t.rast.list", input="B", columns="name",
+ flags="s")
+ self.runModule(lister)
+ #print lister.outputs.stdout
+ maps="b_2001_01" + os.linesep + "b_2001_02" + os.linesep + \
+ "b_2001_03" + os.linesep
+ self.assertEqual(maps, lister.outputs.stdout)
+
+ def test_aggregation_2months(self):
+ """Aggregation two month"""
+ self.assertModule("t.rast.aggregate", input="A", output="B",
+ basename="b", granularity="2 months",
+ method="minimum", sampling=["contains"],
+ nprocs=4, offset=10)
+
+ tinfo_string="""start_time=2001-01-01 00:00:00
+ end_time=2001-05-01 00:00:00
+ granularity=2 months
+ map_time=interval
+ aggregation_type=minimum
+ number_of_maps=2
+ min_min=100.0
+ min_max=500.0
+ max_min=100.0
+ max_max=500.0"""
+
+ info = SimpleModule("t.info", flags="g", input="B")
+ #info.run()
+ #print info.outputs.stdout
+ self.assertModuleKeyValue(module=info, reference=tinfo_string,
+ precision=2, sep="=")
+
+ # Check the map names are correct
+ lister = SimpleModule("t.rast.list", input="B", columns="name",
+ flags="s")
+ self.runModule(lister)
+ #print lister.outputs.stdout
+ maps="b_11" + os.linesep + "b_12" + os.linesep
+ self.assertEqual(maps, lister.outputs.stdout)
+
+ def test_aggregation_3months(self):
+ """Aggregation three month"""
+ self.assertModule("t.rast.aggregate", input="A", output="B",
+ basename="b", granularity="3 months",
+ method="sum", sampling=["contains"],
+ nprocs=9, offset=100)
+
+ tinfo_string="""start_time=2001-01-01 00:00:00
+ end_time=2001-04-01 00:00:00
+ granularity=3 months
+ map_time=interval
+ aggregation_type=sum
+ number_of_maps=1
+ min_min=1500.0
+ min_max=1500.0
+ max_min=1500.0
+ max_max=1500.0"""
+
+ info = SimpleModule("t.info", flags="g", input="B")
+ #info.run()
+ #print info.outputs.stdout
+ self.assertModuleKeyValue(module=info, reference=tinfo_string,
+ precision=2, sep="=")
+
+ # Check the map names are correct
+ lister = SimpleModule("t.rast.list", input="B", columns="name",
+ flags="s")
+ self.runModule(lister)
+ #print lister.outputs.stdout
+ maps="b_101" + os.linesep
+ self.assertEqual(maps, lister.outputs.stdout)
+
+if __name__ == '__main__':
+ from grass.gunittest.main import test
+ test()
Added: grass/trunk/temporal/t.rast.aggregate/testsuite/test_aggregation_relative.py
===================================================================
--- grass/trunk/temporal/t.rast.aggregate/testsuite/test_aggregation_relative.py (rev 0)
+++ grass/trunk/temporal/t.rast.aggregate/testsuite/test_aggregation_relative.py 2014-11-05 20:30:53 UTC (rev 62626)
@@ -0,0 +1,162 @@
+"""Test t.rast.aggregation
+
+(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
+"""
+import os
+import grass.pygrass.modules as pymod
+import grass.temporal as tgis
+from grass.gunittest.case import TestCase
+from grass.gunittest.gmodules import SimpleModule
+
+class TestUnregister(TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ """Initiate the temporal GIS and set the region
+ """
+ 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 = 100", overwrite=True)
+ cls.runModule("r.mapcalc", expression="a2 = 200", overwrite=True)
+ cls.runModule("r.mapcalc", expression="a3 = 300", overwrite=True)
+ cls.runModule("r.mapcalc", expression="a4 = 400", overwrite=True)
+ cls.runModule("r.mapcalc", expression="a5 = 500", overwrite=True)
+ cls.runModule("r.mapcalc", expression="a6 = 600", overwrite=True)
+ cls.runModule("r.mapcalc", expression="a7 = null()", overwrite=True)
+
+ cls.runModule("t.create", type="strds", temporaltype="relative",
+ output="A", title="A test",
+ description="A test", overwrite=True)
+
+ cls.runModule("t.register", flags="i", type="rast", input="A",
+ maps="a1,a2,a3,a4,a5,a6,a7",
+ start=0, unit="days", increment=3,
+ 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_1(self):
+ """Simple test"""
+ self.assertModule("t.rast.aggregate", input="A", output="B",
+ basename="b", granularity=6,
+ method="average",
+ sampling=["overlaps","overlapped","contains"],
+ nprocs=2)
+
+ tinfo_string="""start_time=0
+ end_time=18
+ unit=days
+ granularity=6
+ map_time=interval
+ aggregation_type=average
+ number_of_maps=3
+ min_min=150.0
+ min_max=550.0
+ max_min=150.0
+ max_max=550.0"""
+
+ info = SimpleModule("t.info", flags="g", input="B")
+ #info.run()
+ #print info.outputs.stdout
+ self.assertModuleKeyValue(module=info, reference=tinfo_string,
+ precision=2, sep="=")
+
+ def test_2(self):
+ """Simple test register null maps"""
+ self.assertModule("t.rast.aggregate", input="A", output="B",
+ basename="b", granularity=9,
+ method="maximum",
+ sampling=["contains"],
+ nprocs=4, flags="n")
+
+ tinfo_string="""semantic_type=mean
+ start_time=0
+ end_time=27
+ unit=days
+ granularity=9
+ map_time=interval
+ aggregation_type=maximum
+ number_of_maps=3
+ min_min=300.0
+ min_max=600.0
+ max_min=300.0
+ max_max=600.0"""
+
+ info = SimpleModule("t.info", flags="g", input="B")
+ #info.run()
+ #print info.outputs.stdout
+ self.assertModuleKeyValue(module=info, reference=tinfo_string,
+ precision=2, sep="=")
+
+ def test_3(self):
+ """Simple test"""
+ self.assertModule("t.rast.aggregate", input="A", output="B",
+ basename="b", granularity=9,
+ method="maximum",
+ sampling=["contains"],
+ nprocs=4)
+
+ tinfo_string="""semantic_type=mean
+ start_time=0
+ end_time=18
+ unit=days
+ granularity=9
+ map_time=interval
+ aggregation_type=maximum
+ number_of_maps=2
+ min_min=300.0
+ min_max=600.0
+ max_min=300.0
+ max_max=600.0"""
+
+ info = SimpleModule("t.info", flags="g", input="B")
+ #info.run()
+ #print info.outputs.stdout
+ self.assertModuleKeyValue(module=info, reference=tinfo_string,
+ precision=2, sep="=")
+
+ def test_4(self):
+ """Simple test"""
+ self.assertModule("t.rast.aggregate", input="A", output="B",
+ basename="b", granularity=21,
+ method="average",
+ sampling=["contains"],
+ nprocs=4)
+
+ tinfo_string="""semantic_type=mean
+ start_time=0
+ end_time=21
+ unit=days
+ granularity=21
+ map_time=interval
+ aggregation_type=average
+ number_of_maps=2
+ min_min=350.0
+ min_max=350.0
+ max_min=350.0
+ max_max=350.0"""
+
+ info = SimpleModule("t.info", flags="g", input="B")
+ #info.run()
+ #print info.outputs.stdout
+ self.assertModuleKeyValue(module=info, reference=tinfo_string,
+ precision=2, sep="=")
+
+if __name__ == '__main__':
+ from grass.gunittest.main import test
+ test()
More information about the grass-commit
mailing list