-
-
Notifications
You must be signed in to change notification settings - Fork 295
/
unittests_temporal_raster_algebra_equal_ts.py
191 lines (144 loc) · 7.07 KB
/
unittests_temporal_raster_algebra_equal_ts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
"""
(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 TestTemporalRasterAlgebraImplicitAggregation(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="singletmap = 100")
cls.runModule("r.mapcalc", overwrite=True, quiet=True, expression="singlemap = 1000")
tgis.open_new_stds(name="A", type="strds", temporaltype="absolute",
title="A", descr="A", semantic="field", overwrite=True)
tgis.register_maps_in_space_time_dataset(type="raster", name="A", maps="a1,a2,a3,a4",
start="2001-01-01", interval=False)
tgis.register_maps_in_space_time_dataset(type="raster", name=None, maps="singletmap",
start="2001-01-01")
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", quiet=True)
cls.runModule("t.unregister", maps="singletmap", quiet=True)
cls.del_temp_region()
def test_simple_operator(self):
"""Test implicit aggregation
R = A + A
result with implicit aggregation to:
r1 = a1 + a1 + a2 + a3 + a4 # 11
r2 = a2 + a1 + a2 + a3 + a4 # 12
r3 = a3 + a1 + a2 + a3 + a4 # 13
r4 = a4 + a1 + a2 + a3 + a4 # 14
"""
ta = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
ta.parse(expression="R = A + A", 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(), 11)
self.assertEqual(D.metadata.get_max_max(), 14)
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_complex_operator(self):
"""Test implicit aggregation
R = A {+,equal,l} A
result with implicit aggregation to:
r1 = a1 + a1 + a2 + a3 + a4 # 11
r2 = a2 + a1 + a2 + a3 + a4 # 12
r3 = a3 + a1 + a2 + a3 + a4 # 13
r4 = a4 + a1 + a2 + a3 + a4 # 14
"""
ta = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
ta.parse(expression="R = A {+, equal,l} A", 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(), 11)
self.assertEqual(D.metadata.get_max_max(), 14)
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_single_map_complex_operator(self):
"""Test implicit aggregation
R = singletmap {+,equal,l} A
result with implicit aggregation to:
r1 = singletmap + a1 + a2 + a3 + a4 # 110
r2 = singletmap + a1 + a2 + a3 + a4 # 110
r3 = singletmap + a1 + a2 + a3 + a4 # 110
r4 = singletmap + a1 + a2 + a3 + a4 # 110
"""
ta = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
ta.parse(expression="R = tmap(singletmap) {+, equal,l} A", 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(), 110)
self.assertEqual(D.metadata.get_max_max(), 110)
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_single_map_simple_operator(self):
"""Test implicit aggregation
R = singletmap + A
result with implicit aggregation to:
r1 = singletmap + a1 + a2 + a3 + a4 # 110
r2 = singletmap + a1 + a2 + a3 + a4 # 110
r3 = singletmap + a1 + a2 + a3 + a4 # 110
r4 = singletmap + a1 + a2 + a3 + a4 # 110
"""
ta = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
ta.parse(expression="R = tmap(singletmap) + A", 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(), 110)
self.assertEqual(D.metadata.get_max_max(), 110)
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_single_map_complex_operator_right_ts(self):
"""Test implicit aggregation
TODO: Ist this the correct result? Implicit aggregation and full permutation?
R = singletmap {+,equal,r} A
result with implicit aggregation to:
r1 = singletmap + a1 + a2 + a3 + a4 # 110
r2 = singletmap + a1 + a2 + a3 + a4 # 110
r3 = singletmap + a1 + a2 + a3 + a4 # 110
r4 = singletmap + a1 + a2 + a3 + a4 # 110
"""
ta = tgis.TemporalRasterAlgebraParser(run=True, debug=True)
ta.parse(expression="R = tmap(singletmap) {+, equal,r} A", 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(), 110)
self.assertEqual(D.metadata.get_max_max(), 110)
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)
if __name__ == '__main__':
test()