test_r_horizon.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. """
  2. TEST: test_r_horizon.py
  3. AUTHOR(S): Anna Petrasova <kratochanna at gmail>
  4. PURPOSE: Test r.horizon
  5. COPYRIGHT: (C) 2015 Anna Petrasova
  6. This program is free software under the GNU General Public
  7. License (>=v2). Read the file COPYING that comes with GRASS
  8. for details.
  9. """
  10. from grass.gunittest.case import TestCase
  11. from grass.gunittest.main import test
  12. from grass.gunittest.gmodules import SimpleModule
  13. ref1 = """azimuth,horizon_height
  14. 180.000000,0.023101
  15. """
  16. ref2 = """azimuth,horizon_height
  17. 180.000000,0.023101
  18. 200.000000,0.034850
  19. 220.000000,0.050549
  20. 240.000000,0.048211
  21. 260.000000,0.053101
  22. 280.000000,0.039774
  23. 300.000000,0.032360
  24. 320.000000,0.014804
  25. 340.000000,0.000000
  26. 360.000000,0.004724
  27. 20.000000,0.012612
  28. 40.000000,0.015207
  29. 60.000000,0.014344
  30. 80.000000,0.011044
  31. 100.000000,0.012192
  32. 120.000000,0.007462
  33. 140.000000,0.004071
  34. 160.000000,0.015356
  35. """
  36. ref3 = """azimuth,horizon_height
  37. 180.000000,0.023101
  38. 200.000000,0.034850
  39. 220.000000,0.050549
  40. 240.000000,0.048211
  41. 260.000000,0.053101
  42. 280.000000,0.039774
  43. 300.000000,0.032360
  44. 320.000000,0.014804
  45. 340.000000,0.000000
  46. 360.000000,0.004724
  47. 20.000000,0.012612
  48. 40.000000,0.015207
  49. 60.000000,0.014344
  50. 80.000000,0.011044
  51. 100.000000,0.012192
  52. 120.000000,0.007462
  53. 140.000000,0.004071
  54. 160.000000,0.015356
  55. """
  56. class TestHorizon(TestCase):
  57. horizon = 'test_horizon_from_elevation'
  58. horizon_output = 'test_horizon_output_from_elevation'
  59. @classmethod
  60. def setUpClass(cls):
  61. cls.use_temp_region()
  62. cls.runModule('g.region', raster='elevation')
  63. @classmethod
  64. def tearDownClass(cls):
  65. cls.del_temp_region()
  66. def tearDown(self):
  67. """Remove horizon map after each test method"""
  68. self.runModule('g.remove', flags='f', type='raster',
  69. name=self.horizon)
  70. self.runModule('g.remove', flags='f', type='raster',
  71. pattern=self.horizon_output + '*')
  72. def test_point_mode_one_direction(self):
  73. """Test mode with 1 point and 1 direction"""
  74. module = SimpleModule('r.horizon', elevation='elevation',
  75. coordinates=(634720, 216180), output=self.horizon, direction=180)
  76. self.assertModule(module)
  77. stdout = module.outputs.stdout
  78. self.assertMultiLineEqual(first=ref1, second=stdout)
  79. def test_point_mode_multiple_direction(self):
  80. """Test mode with 1 point and multiple directions"""
  81. module = SimpleModule('r.horizon', elevation='elevation',
  82. coordinates=(634720, 216180), output=self.horizon, direction=180, step=20)
  83. self.assertModule(module)
  84. stdout = module.outputs.stdout
  85. self.assertMultiLineEqual(first=ref2, second=stdout)
  86. def test_raster_mode_one_direction(self):
  87. """Test mode with 1 point and one direction"""
  88. module = SimpleModule('r.horizon', elevation='elevation',
  89. output=self.horizon_output, direction=50)
  90. self.assertModule(module)
  91. ref = {'min': 0, 'max': 0.70678365230560, 'stddev': 0.0360724286360789}
  92. self.assertRasterFitsUnivar(raster='test_horizon_output_from_elevation_050', reference=ref, precision=1e6)
  93. def test_raster_mode_multiple_direction(self):
  94. module = SimpleModule('r.horizon', elevation='elevation',
  95. output=self.horizon_output, start=10, end=50, step=15.512)
  96. self.assertModule(module)
  97. module_list = SimpleModule('g.list', type='raster', pattern=self.horizon_output + '*')
  98. self.runModule(module_list)
  99. stdout = module_list.outputs.stdout.strip()
  100. self.assertMultiLineEqual(first="test_horizon_output_from_elevation_010_000\ntest_horizon_output_from_elevation_025_512", second=stdout)
  101. def test_raster_mode_multiple_direction_offset(self):
  102. module = SimpleModule('r.horizon', elevation='elevation',
  103. output=self.horizon_output, start=10, end=50, step=15.512, direction=80)
  104. self.assertModule(module)
  105. module_list = SimpleModule('g.list', type='raster', pattern=self.horizon_output + '*')
  106. self.runModule(module_list)
  107. stdout = module_list.outputs.stdout.strip()
  108. self.assertMultiLineEqual(first="test_horizon_output_from_elevation_090_000\ntest_horizon_output_from_elevation_105_512", second=stdout)
  109. if __name__ == '__main__':
  110. test()