|
@@ -19,25 +19,33 @@ cols: 5
|
|
|
|
|
|
class TestSlopeAspect(TestCase):
|
|
|
|
|
|
+ slope = 'limits_slope'
|
|
|
+ aspect = 'limits_aspect'
|
|
|
+
|
|
|
+ def setUp(self):
|
|
|
+ self.use_temp_region()
|
|
|
+ call_module('g.region', raster='elevation')
|
|
|
+
|
|
|
+ def tearDown(self):
|
|
|
+ self.del_temp_region()
|
|
|
+ call_module('g.remove', flags='f', type_='raster',
|
|
|
+ name=[self.slope, self.aspect])
|
|
|
+
|
|
|
def test_limits(self):
|
|
|
- slope = 'limits_slope'
|
|
|
- aspect = 'limits_aspect'
|
|
|
self.assertModule('r.slope.aspect', elevation='elevation',
|
|
|
- slope=slope, aspect=aspect)
|
|
|
- self.assertRasterMinMax(map=slope, refmin=0, refmax=90,
|
|
|
+ slope=self.slope, aspect=self.aspect)
|
|
|
+ self.assertRasterMinMax(map=self.slope, refmin=0, refmax=90,
|
|
|
msg="Slope in degrees must be between 0 and 90")
|
|
|
- self.assertRasterMinMax(map=aspect, refmin=0, refmax=360,
|
|
|
+ self.assertRasterMinMax(map=self.aspect, refmin=0, refmax=360,
|
|
|
msg="Aspect in degrees must be between 0 and 360")
|
|
|
|
|
|
def test_limits_precent(self):
|
|
|
"""Assumes NC elevation and allows slope up to 100% (45deg)"""
|
|
|
- slope = 'limits_percent_slope'
|
|
|
- aspect = 'limits_percent_aspect'
|
|
|
self.assertModule('r.slope.aspect', elevation='elevation',
|
|
|
- slope=slope, aspect=aspect, format='percent')
|
|
|
- self.assertRasterMinMax(map=slope, refmin=0, refmax=100,
|
|
|
+ slope=self.slope, aspect=self.aspect, format='percent')
|
|
|
+ self.assertRasterMinMax(map=self.slope, refmin=0, refmax=100,
|
|
|
msg="Slope in percent must be between 0 and 100")
|
|
|
- self.assertRasterMinMax(map=aspect, refmin=0, refmax=360,
|
|
|
+ self.assertRasterMinMax(map=self.aspect, refmin=0, refmax=360,
|
|
|
msg="Aspect in degrees must be between 0 and 360")
|
|
|
|
|
|
|
|
@@ -58,6 +66,10 @@ class TestSlopeAspectAgainstReference(TestCase):
|
|
|
|
|
|
# precision for comparisons
|
|
|
precision = 0.0001
|
|
|
+ ref_aspect = 'reference_aspect'
|
|
|
+ aspect = 'fractal_aspect'
|
|
|
+ ref_slope = 'reference_slope'
|
|
|
+ slope = 'fractal_slope'
|
|
|
|
|
|
@classmethod
|
|
|
def setUpClass(cls):
|
|
@@ -65,48 +77,49 @@ class TestSlopeAspectAgainstReference(TestCase):
|
|
|
call_module('g.region', n=20, s=10, e=25, w=15, res=1)
|
|
|
cls.elevation = 'fractal_surf'
|
|
|
cls.runModule('r.in.ascii', input='data/fractal_surf.ascii',
|
|
|
- output=cls.elevation)
|
|
|
+ output=cls.elevation)
|
|
|
|
|
|
@classmethod
|
|
|
def tearDownClass(cls):
|
|
|
cls.del_temp_region()
|
|
|
- cls.runModule('g.remove', flags='f', type='raster', name=cls.elevation)
|
|
|
+ cls.runModule('g.remove', flags='f', type='raster',
|
|
|
+ name=[cls.elevation, cls.slope, cls.aspect, cls.ref_aspect, cls.ref_slope])
|
|
|
|
|
|
def test_slope(self):
|
|
|
- ref_slope = 'reference_slope'
|
|
|
- slope = 'fractal_slope'
|
|
|
-
|
|
|
# TODO: using gdal instead of ascii because of cannot seek error
|
|
|
self.runModule('r.in.gdal', flags='o',
|
|
|
- input='data/gdal_slope.grd', output=ref_slope)
|
|
|
+ input='data/gdal_slope.grd', output=self.ref_slope)
|
|
|
self.assertModule('r.slope.aspect', elevation=self.elevation,
|
|
|
- slope=slope)
|
|
|
+ slope=self.slope)
|
|
|
# check we have expected values
|
|
|
- self.assertRasterMinMax(map=slope, refmin=0, refmax=90,
|
|
|
+ self.assertRasterMinMax(map=self.slope, refmin=0, refmax=90,
|
|
|
msg="Slope in degrees must be between 0 and 90")
|
|
|
# check against reference data
|
|
|
- self.assertRastersNoDifference(actual=slope, reference=ref_slope,
|
|
|
+ self.assertRastersNoDifference(actual=self.slope, reference=self.ref_slope,
|
|
|
precision=self.precision)
|
|
|
|
|
|
def test_aspect(self):
|
|
|
- ref_aspect = 'reference_aspect'
|
|
|
- aspect = 'fractal_aspect'
|
|
|
# TODO: using gdal instead of ascii because of cannot seek error
|
|
|
self.runModule('r.in.gdal', flags='o',
|
|
|
- input='data/gdal_aspect.grd', output=ref_aspect)
|
|
|
+ input='data/gdal_aspect.grd', output=self.ref_aspect)
|
|
|
self.assertModule('r.slope.aspect', elevation=self.elevation,
|
|
|
- aspect=aspect)
|
|
|
+ aspect=self.aspect)
|
|
|
# check we have expected values
|
|
|
- self.assertRasterMinMax(map=aspect, refmin=0, refmax=360,
|
|
|
+ self.assertRasterMinMax(map=self.aspect, refmin=0, refmax=360,
|
|
|
msg="Aspect in degrees must be between 0 and 360")
|
|
|
# check against reference data
|
|
|
- self.assertRastersNoDifference(actual=aspect, reference=ref_aspect,
|
|
|
+ self.assertRastersNoDifference(actual=self.aspect, reference=self.ref_aspect,
|
|
|
precision=self.precision)
|
|
|
|
|
|
|
|
|
class TestSlopeAspectAgainstItself(TestCase):
|
|
|
|
|
|
precision = 0.0000001
|
|
|
+ elevation = 'elevation'
|
|
|
+ t_aspect = 'sa_together_aspect'
|
|
|
+ t_slope = 'sa_together_slope'
|
|
|
+ s_aspect = 'sa_separately_aspect'
|
|
|
+ s_slope = 'sa_separately_slope'
|
|
|
|
|
|
@classmethod
|
|
|
def setUpClass(cls):
|
|
@@ -116,48 +129,48 @@ class TestSlopeAspectAgainstItself(TestCase):
|
|
|
@classmethod
|
|
|
def tearDownClass(cls):
|
|
|
cls.del_temp_region()
|
|
|
+ call_module('g.remove', flags='f', type_='raster',
|
|
|
+ name=[cls.t_aspect, cls.t_slope, cls.s_slope, cls.s_aspect])
|
|
|
|
|
|
def test_slope_aspect_together(self):
|
|
|
"""Slope and aspect computed separately and together should be the same
|
|
|
"""
|
|
|
- elevation = 'elevation'
|
|
|
- t_aspect = 'sa_together_aspect'
|
|
|
- t_slope = 'sa_together_slope'
|
|
|
- s_aspect = 'sa_separately_aspect'
|
|
|
- s_slope = 'sa_separately_slope'
|
|
|
- self.assertModule('r.slope.aspect', elevation=elevation,
|
|
|
- aspect=s_aspect)
|
|
|
- self.assertModule('r.slope.aspect', elevation=elevation,
|
|
|
- slope=s_slope)
|
|
|
- self.assertModule('r.slope.aspect', elevation=elevation,
|
|
|
- slope=t_slope, aspect=t_aspect)
|
|
|
- self.assertRastersNoDifference(actual=t_aspect, reference=s_aspect,
|
|
|
+ self.assertModule('r.slope.aspect', elevation=self.elevation,
|
|
|
+ aspect=self.s_aspect)
|
|
|
+ self.assertModule('r.slope.aspect', elevation=self.elevation,
|
|
|
+ slope=self.s_slope)
|
|
|
+ self.assertModule('r.slope.aspect', elevation=self.elevation,
|
|
|
+ slope=self.t_slope, aspect=self.t_aspect)
|
|
|
+ self.assertRastersNoDifference(actual=self.t_aspect, reference=self.s_aspect,
|
|
|
precision=self.precision)
|
|
|
- self.assertRastersNoDifference(actual=t_slope, reference=s_slope,
|
|
|
+ self.assertRastersNoDifference(actual=self.t_slope, reference=self.s_slope,
|
|
|
precision=self.precision)
|
|
|
|
|
|
|
|
|
# TODO: implement this class
|
|
|
class TestExtremes(TestCase):
|
|
|
|
|
|
+ slope = 'small_slope'
|
|
|
+ aspect = 'small_aspect'
|
|
|
+ elevation = 'small_elevation'
|
|
|
+
|
|
|
def setUp(self):
|
|
|
self.use_temp_region()
|
|
|
|
|
|
def tearDown(self):
|
|
|
self.del_temp_region()
|
|
|
+ call_module('g.remove', flags='f', type_='raster',
|
|
|
+ name=[self.slope, self.aspect, self.elevation])
|
|
|
|
|
|
def test_small(self):
|
|
|
- elevation = 'small_elevation'
|
|
|
- slope = 'small_slope'
|
|
|
- aspect = 'small_aspect'
|
|
|
- self.runModule('r.in.ascii', input='-', output=elevation,
|
|
|
+ self.runModule('r.in.ascii', input='-', output=self.elevation,
|
|
|
stdin_=SMALL_MAP)
|
|
|
- call_module('g.region', raster=elevation)
|
|
|
- self.assertModule('r.slope.aspect', elevation=elevation,
|
|
|
- slope=slope, aspect=aspect)
|
|
|
- self.assertRasterMinMax(map=slope, refmin=0, refmax=90,
|
|
|
+ call_module('g.region', raster=self.elevation)
|
|
|
+ self.assertModule('r.slope.aspect', elevation=self.elevation,
|
|
|
+ slope=self.slope, aspect=self.aspect)
|
|
|
+ self.assertRasterMinMax(map=self.slope, refmin=0, refmax=90,
|
|
|
msg="Slope in degrees must be between 0 and 90")
|
|
|
- self.assertRasterMinMax(map=aspect, refmin=0, refmax=360,
|
|
|
+ self.assertRasterMinMax(map=self.aspect, refmin=0, refmax=360,
|
|
|
msg="Aspect in degrees must be between 0 and 360")
|
|
|
|
|
|
|