1
"""Test t.rast.aggregation
3
(C) 2014 by the GRASS Development Team
4
This program is free software under the GNU General Public
5
License (>=v2). Read the file COPYING that comes with GRASS
8
:authors: Soeren Gebbert
11
import grass.pygrass.modules as pymod
12
import grass.temporal as tgis
13
from grass.gunittest.case import TestCase
14
from grass.gunittest.gmodules import SimpleModule
16
class TestAggregationAbsolute(TestCase):
20
"""Initiate the temporal GIS and set the region
22
os.putenv("GRASS_OVERWRITE", "1")
25
cls.runModule("g.region", s=0, n=80, w=0, e=120, b=0,
26
t=50, res=10, res3=10)
27
cls.runModule("r.mapcalc", expression="a1 = 100", overwrite=True)
28
cls.runModule("r.mapcalc", expression="a2 = 200", overwrite=True)
29
cls.runModule("r.mapcalc", expression="a3 = 300", overwrite=True)
30
cls.runModule("r.mapcalc", expression="a4 = 400", overwrite=True)
31
cls.runModule("r.mapcalc", expression="a5 = 500", overwrite=True)
32
cls.runModule("r.mapcalc", expression="a6 = 600", overwrite=True)
33
cls.runModule("r.mapcalc", expression="a7 = null()", overwrite=True)
35
cls.runModule("t.create", type="strds", temporaltype="absolute",
36
output="A", title="A test",
37
description="A test", overwrite=True)
39
cls.runModule("t.register", flags="i", type="raster", input="A",
40
maps="a1,a2,a3,a4,a5,a6,a7",
41
start="2001-01-15 12:05:45",
45
def tearDownClass(cls):
46
"""Remove the temporary region
49
cls.runModule("t.remove", flags="rf", type="strds", inputs="A")
52
"""Remove generated data"""
53
self.runModule("t.remove", flags="rf", type="strds", inputs="B")
55
def test_disaggregation(self):
56
"""Disaggregation with empty maps"""
57
self.assertModule("t.rast.aggregate", input="A", output="B",
58
basename="b", granularity="2 days",
60
sampling=["overlaps","overlapped","during"],
63
tinfo_string="""start_time=2001-01-15 00:00:00
64
end_time=2001-04-25 00:00:00
66
aggregation_type=average
74
info = SimpleModule("t.info", flags="g", input="B")
76
#print info.outputs.stdout
77
self.assertModuleKeyValue(module=info, reference=tinfo_string,
80
def test_aggregation_1month(self):
81
"""Aggregation one month"""
82
self.assertModule("t.rast.aggregate", input="A", output="B",
83
basename="b", granularity="1 months",
84
method="maximum", sampling=["contains"],
87
tinfo_string="""start_time=2001-01-01 00:00:00
88
end_time=2001-04-01 00:00:00
91
aggregation_type=maximum
98
info = SimpleModule("t.info", flags="g", input="B")
100
#print info.outputs.stdout
101
self.assertModuleKeyValue(module=info, reference=tinfo_string,
102
precision=2, sep="=")
104
# Check the map names are correct
105
lister = SimpleModule("t.rast.list", input="B", columns="name",
107
self.runModule(lister)
108
#print lister.outputs.stdout
109
maps="b_2001_01" + os.linesep + "b_2001_02" + os.linesep + \
110
"b_2001_03" + os.linesep
111
self.assertEqual(maps, lister.outputs.stdout)
113
def test_aggregation_2months(self):
114
"""Aggregation two month"""
115
self.assertModule("t.rast.aggregate", input="A", output="B",
116
basename="b", granularity="2 months",
117
method="minimum", sampling=["contains"],
120
tinfo_string="""start_time=2001-01-01 00:00:00
121
end_time=2001-05-01 00:00:00
124
aggregation_type=minimum
131
info = SimpleModule("t.info", flags="g", input="B")
133
#print info.outputs.stdout
134
self.assertModuleKeyValue(module=info, reference=tinfo_string,
135
precision=2, sep="=")
137
# Check the map names are correct
138
lister = SimpleModule("t.rast.list", input="B", columns="name",
140
self.runModule(lister)
141
#print lister.outputs.stdout
142
maps="b_11" + os.linesep + "b_12" + os.linesep
143
self.assertEqual(maps, lister.outputs.stdout)
145
def test_aggregation_3months(self):
146
"""Aggregation three month"""
147
self.assertModule("t.rast.aggregate", input="A", output="B",
148
basename="b", granularity="3 months",
149
method="sum", sampling=["contains"],
150
nprocs=9, offset=100)
152
tinfo_string="""start_time=2001-01-01 00:00:00
153
end_time=2001-04-01 00:00:00
163
info = SimpleModule("t.info", flags="g", input="B")
165
#print info.outputs.stdout
166
self.assertModuleKeyValue(module=info, reference=tinfo_string,
167
precision=2, sep="=")
169
# Check the map names are correct
170
lister = SimpleModule("t.rast.list", input="B", columns="name",
172
self.runModule(lister)
173
#print lister.outputs.stdout
174
maps="b_101" + os.linesep
175
self.assertEqual(maps, lister.outputs.stdout)
177
if __name__ == '__main__':
178
from grass.gunittest.main import test