~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to temporal/t.rast.aggregate/testsuite/test_aggregation_absolute_parallel.py

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""Test t.rast.aggregation
 
2
 
 
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
 
6
for details.
 
7
 
 
8
:authors: Soeren Gebbert
 
9
"""
 
10
import os
 
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
 
15
from datetime import datetime
 
16
 
 
17
class TestAggregationAbsoluteParallel(TestCase):
 
18
 
 
19
    @classmethod
 
20
    def setUpClass(cls):
 
21
        """Initiate the temporal GIS and set the region
 
22
        """
 
23
        os.putenv("GRASS_OVERWRITE",  "1")
 
24
        tgis.init()
 
25
        cls.use_temp_region()
 
26
        cls.runModule("g.region",  s=0,  n=80,  w=0,  e=120,  b=0,  
 
27
                      t=50,  res=10,  res3=10)
 
28
                      
 
29
        name_list =  []
 
30
        for i in range(540):
 
31
            cls.runModule("r.mapcalc", expression="a%i = %i"%(i + 1, i + 1),  overwrite=True)
 
32
            name_list.append("a%i"%(i + 1))
 
33
 
 
34
        cls.runModule("t.create",  type="strds",  temporaltype="absolute",  
 
35
                                    output="A",  title="A test",  
 
36
                                    description="A test",  overwrite=True)
 
37
 
 
38
        cls.runModule("t.register", flags="i",  type="raster",  input="A",  
 
39
                                     maps=name_list,
 
40
                                     start="2001-01-01", 
 
41
                                     increment="4 hours",  
 
42
                                     overwrite=True)
 
43
 
 
44
    @classmethod
 
45
    def tearDownClass(cls):
 
46
        """Remove the temporary region
 
47
        """
 
48
        cls.del_temp_region()        
 
49
        cls.runModule("t.remove", flags="rf", type="strds", inputs="A")
 
50
 
 
51
    def tearDown(self):
 
52
        """Remove generated data"""    
 
53
        self.runModule("t.remove", flags="rf", type="strds", inputs="B")
 
54
 
 
55
    def test_aggregation_12hours(self):
 
56
        """Aggregation one month"""
 
57
        self.assertModule("t.rast.aggregate", input="A", output="B",
 
58
                          basename="b", granularity="12 hours",
 
59
                          method="sum", sampling=["contains"], 
 
60
                          nprocs=9, flags="s")
 
61
 
 
62
        tinfo_string="""start_time=2001-01-01 00:00:00
 
63
                        end_time=2001-04-01 00:00:00
 
64
                        granularity=12 hours
 
65
                        map_time=interval
 
66
                        aggregation_type=sum
 
67
                        number_of_maps=180
 
68
                        min_min=6.0
 
69
                        min_max=1617.0
 
70
                        max_min=6.0
 
71
                        max_max=1617.0"""
 
72
 
 
73
        info = SimpleModule("t.info", flags="g", input="B")
 
74
        #info.run()
 
75
        #print info.outputs.stdout
 
76
        self.assertModuleKeyValue(module=info, reference=tinfo_string, 
 
77
                                  precision=2, sep="=")
 
78
 
 
79
    def test_aggregation_1day_4procs(self):
 
80
        """Aggregation one month"""
 
81
        start = datetime.now()
 
82
        self.assertModule("t.rast.aggregate", input="A", output="B",
 
83
                          basename="b", granularity="1 day",
 
84
                          method="sum", sampling=["contains"], 
 
85
                          nprocs=4, flags="s")
 
86
        end = datetime.now()
 
87
        
 
88
        delta = end - start
 
89
        print "test_aggregation_1day_4procs:",  delta.total_seconds()
 
90
 
 
91
        tinfo_string="""start_time=2001-01-01 00:00:00
 
92
                        end_time=2001-04-01 00:00:00
 
93
                        granularity=1 day
 
94
                        map_time=interval
 
95
                        aggregation_type=sum
 
96
                        number_of_maps=90"""
 
97
 
 
98
        info = SimpleModule("t.info", flags="g", input="B")
 
99
        #info.run()
 
100
        #print info.outputs.stdout
 
101
        self.assertModuleKeyValue(module=info, reference=tinfo_string, 
 
102
                                  precision=2, sep="=")
 
103
 
 
104
    def test_aggregation_1day_3procs(self):
 
105
        """Aggregation one month"""
 
106
        start = datetime.now()
 
107
        self.assertModule("t.rast.aggregate", input="A", output="B",
 
108
                          basename="b", granularity="1 day",
 
109
                          method="sum", sampling=["contains"], 
 
110
                          nprocs=3, flags="s")
 
111
        end = datetime.now()
 
112
        
 
113
        delta = end - start
 
114
        print "test_aggregation_1day_3procs:",  delta.total_seconds()
 
115
 
 
116
 
 
117
        tinfo_string="""start_time=2001-01-01 00:00:00
 
118
                        end_time=2001-04-01 00:00:00
 
119
                        granularity=1 day
 
120
                        map_time=interval
 
121
                        aggregation_type=sum
 
122
                        number_of_maps=90
 
123
                        min_min=21.0
 
124
                        min_max=3225.0
 
125
                        max_min=21.0
 
126
                        max_max=3225.0"""
 
127
 
 
128
        info = SimpleModule("t.info", flags="g", input="B")
 
129
        #info.run()
 
130
        #print info.outputs.stdout
 
131
        self.assertModuleKeyValue(module=info, reference=tinfo_string, 
 
132
                                  precision=2, sep="=")
 
133
 
 
134
    def test_aggregation_1day_2procs(self):
 
135
        """Aggregation one month"""
 
136
        start = datetime.now()
 
137
        self.assertModule("t.rast.aggregate", input="A", output="B",
 
138
                          basename="b", granularity="1 day",
 
139
                          method="sum", sampling=["contains"], 
 
140
                          nprocs=2, flags="s")
 
141
        end = datetime.now()
 
142
        
 
143
        delta = end - start
 
144
        print "test_aggregation_1day_2procs:",  delta.total_seconds()
 
145
 
 
146
 
 
147
        tinfo_string="""start_time=2001-01-01 00:00:00
 
148
                        end_time=2001-04-01 00:00:00
 
149
                        granularity=1 day
 
150
                        map_time=interval
 
151
                        aggregation_type=sum
 
152
                        number_of_maps=90
 
153
                        min_min=21.0
 
154
                        min_max=3225.0
 
155
                        max_min=21.0
 
156
                        max_max=3225.0"""
 
157
 
 
158
        info = SimpleModule("t.info", flags="g", input="B")
 
159
        #info.run()
 
160
        #print info.outputs.stdout
 
161
        self.assertModuleKeyValue(module=info, reference=tinfo_string, 
 
162
                                  precision=2, sep="=")
 
163
if __name__ == '__main__':
 
164
    from grass.gunittest.main import test
 
165
    test()