[GRASS-SVN] r62168 - in grass/trunk/raster/r.viewshed: . testsuite

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Oct 3 08:17:59 PDT 2014


Author: wenzeslaus
Date: 2014-10-03 08:17:59 -0700 (Fri, 03 Oct 2014)
New Revision: 62168

Modified:
   grass/trunk/raster/r.viewshed/main.cpp
   grass/trunk/raster/r.viewshed/testsuite/test_r_viewshed.py
Log:
r.viewshed: improve error messages; fix test (set region, delete maps, remove prints)

Modified: grass/trunk/raster/r.viewshed/main.cpp
===================================================================
--- grass/trunk/raster/r.viewshed/main.cpp	2014-10-03 07:47:03 UTC (rev 62167)
+++ grass/trunk/raster/r.viewshed/main.cpp	2014-10-03 15:17:59 UTC (rev 62168)
@@ -175,9 +175,12 @@
        the algorithm will work correctly in theory. But this
        requires some changes. To do. */
     if (!(vp.row < hd->nrows && vp.col < hd->ncols)) {
-	G_warning(_("Viewpoint outside grid"));
-	G_warning(_("viewpont: (row=%d, col=%d)"), vp.row, vp.col);
-	G_fatal_error(_("grid: (rows=%d, cols=%d)"), hd->nrows, hd->ncols);
+	/* unfortunately, we don't know the point coordinates now */
+	G_warning(_("Region extent: north=%d, south=%d, east=%d, west=%d"),
+	    hd->window.north, hd->window.south, hd->window.east, hd->window.west);
+	G_warning(_("Region extent: rows=%d, cols=%d"), hd->nrows, hd->ncols);
+	G_warning(_("Viewpont: row=%d, col=%d"), vp.row, vp.col);
+	G_fatal_error(_("Viewpoint outside of computational region"));
     }
 
 

Modified: grass/trunk/raster/r.viewshed/testsuite/test_r_viewshed.py
===================================================================
--- grass/trunk/raster/r.viewshed/testsuite/test_r_viewshed.py	2014-10-03 07:47:03 UTC (rev 62167)
+++ grass/trunk/raster/r.viewshed/testsuite/test_r_viewshed.py	2014-10-03 15:17:59 UTC (rev 62168)
@@ -1,16 +1,49 @@
 import grass.gunittest
 from grass.gunittest.gmodules import call_module
 
+
 class TestViewshed(grass.gunittest.TestCase):
 
+    viewshed = 'test_viewshed_from_elevation'
+
+    @classmethod
+    def setUpClass(cls):
+        cls.use_temp_region()
+        cls.runModule('g.region', rast='elevation')
+
+    @classmethod
+    def tearDownClass(cls):
+        cls.del_temp_region()
+
+    def tearDown(cls):
+        """Remove viewshed map after each test method"""
+        # TODO: eventually, removing maps should be handled through testing framework fucntions
+        cls.runModule('g.remove', flags='f', type='rast',
+                      pattern=cls.viewshed)
+
     def test_limits(self):
+        """Test if results is in expected limits"""
         obs_elev = '1.72'
-        viewshed = 'limits_obs_elev'
         self.assertModule('r.viewshed', input='elevation',
-                          coordinates=(634720,216180), output=viewshed, obs_elev=obs_elev)
-        self.assertRasterMinMax(map=viewshed, refmin=0, refmax=180,
-                                msg="Viewing angle above the ground must be between 0 and 180 deg")
+            coordinates=(634720,216180), output=self.viewshed,
+            obs_elev=obs_elev)
+        self.assertRasterMinMax(map=self.viewshed, refmin=0, refmax=180,
+            msg="Viewing angle above the ground must be between 0 and 180 deg")
 
+    def test_limits_extreme_value(self):
+        """Test extremely high observer elevation
+
+        Unfortunatelly, this takes very long time to compute
+        (something like ten times more).
+        """
+        obs_elev = '500000'
+        self.assertModule('r.viewshed', input='elevation',
+            coordinates=(634720,216180), output=self.viewshed,
+            obs_elev=obs_elev)
+        self.assertRasterMinMax(map=self.viewshed, refmin=0, refmax=180,
+            msg="Viewing angle above the ground must be between 0 and 180 deg")
+
+
 class TestViewshedAgainstReference(grass.gunittest.TestCase):
     """
 
@@ -26,10 +59,15 @@
     # precision for comparisons
     precision = 0.0001
 
+    # list to hold rasters to be removed
+    # here we accumulate all rasters created during tests
+    # then we remove them at the end in class tear down
+    to_remove = []
+
     @classmethod
     def setUpClass(cls):
         cls.use_temp_region()
-        call_module('g.region', n=216990, s=215520, e=635950, w=633730, res=10)
+        cls.runModule('g.region', n=216990, s=215520, e=635950, w=633730, res=10)
         cls.elevation = 'ref_elevation'
         cls.runModule('r.in.ascii', input='data/elevation.ascii',
                        output=cls.elevation)
@@ -37,7 +75,11 @@
     @classmethod
     def tearDownClass(cls):
         cls.del_temp_region()
-        cls.runModule('g.remove', flags='f', type='rast', pattern=cls.elevation)
+        cls.runModule('g.remove', flags='f', type='rast',
+                      pattern=cls.elevation)
+        if cls.to_remove:
+            cls.runModule('g.remove', flags='f', type='rast',
+                          pattern=','.join(cls.to_remove))
 
     def test_viewshed(self):
         ref_viewshed = 'reference_viewshed'
@@ -46,18 +88,20 @@
 
         self.runModule('r.in.ascii',
                        input='data/lake_viewshed.ascii', output=ref_viewshed)
-        print "assertModule..."
+        self.to_remove.append(ref_viewshed)
+
         self.assertModule('r.viewshed', input=self.elevation,
                           coordinates=(634720,216180), output=viewshed, obs_elev=obs_elev)
+        self.to_remove.append(viewshed)
+
         # check we have expected values
-        print "assertRasterMinMax..."
         self.assertRasterMinMax(map=viewshed, refmin=0, refmax=180,
                                 msg="Viewshed in degrees must be between 0 and 180")
         # check against reference data
-        print "assertRastersNoDifference..."
         self.assertRastersNoDifference(actual=viewshed, reference=ref_viewshed,
                                        precision=self.precision)
-        # TODO: add self.assertRasterFitsUnivar()                                      
+        # TODO: add self.assertRasterFitsUnivar()
 
+
 if __name__ == '__main__':
     grass.gunittest.test()



More information about the grass-commit mailing list