test_aggregation_absolute_parallel.py 6.1 KB

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