test_r_geom.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. """
  2. Name: r.geomorphon tests
  3. Purpose: Tests r.geomorphon input parsing.
  4. Uses NC Basic data set.
  5. Author: Luca Delucchi, Markus Neteler
  6. Copyright: (C) 2017 by Luca Delucchi, Markus Neteler and the GRASS Development Team
  7. Licence: This program is free software under the GNU General Public
  8. License (>=v2). Read the file COPYING that comes with GRASS
  9. for details.
  10. """
  11. from grass.gunittest.case import TestCase
  12. from grass.gunittest.main import test
  13. from grass.script.core import read_command
  14. synth_out = \
  15. """1 flat
  16. 3 ridge
  17. 4 shoulder
  18. 6 slope
  19. 8 footslope
  20. 9 valley
  21. """
  22. ele_out = \
  23. """1 flat
  24. 2 summit
  25. 3 ridge
  26. 4 shoulder
  27. 5 spur
  28. 6 slope
  29. 7 hollow
  30. 8 footslope
  31. 9 valley
  32. 10 depression
  33. """
  34. class TestClipling(TestCase):
  35. inele = 'elevation'
  36. insint = 'synthetic_dem'
  37. outele = 'ele_geomorph'
  38. outsint = 'synth_geomorph'
  39. @classmethod
  40. def setUpClass(cls):
  41. """Ensures expected computational region and generated data"""
  42. cls.use_temp_region()
  43. cls.runModule('g.region', raster=cls.inele)
  44. cls.runModule('r.mapcalc', expression="{ou} = sin(x() / 5.0) + (sin(x() / 5.0) * 100.0 + 200)".format(ou=cls.insint))
  45. @classmethod
  46. def tearDownClass(cls):
  47. """Remove the temporary region and generated data"""
  48. cls.runModule('g.remove', flags='f', type='raster',
  49. name=(cls.insint, cls.outele, cls.outsint))
  50. cls.del_temp_region()
  51. def test_ele(self):
  52. self.runModule('r.geomorphon', elevation=self.inele, forms=self.outele,
  53. search=10)
  54. category = read_command('r.category', map=self.outele)
  55. self.assertEqual(first=ele_out, second=category)
  56. def test_sint(self):
  57. self.runModule('r.geomorphon', elevation=self.insint,
  58. forms=self.outsint, search=10)
  59. category = read_command('r.category', map=self.outsint)
  60. self.assertEqual(first=synth_out, second=category)
  61. if __name__ == '__main__':
  62. test()