test_aggregation_absolute_parallel.py 6.1 KB

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