Skip to content

Commit

Permalink
add basic slope / aspect tests
Browse files Browse the repository at this point in the history
  • Loading branch information
njwilson23 committed Oct 8, 2016
1 parent 4368e5b commit 4f7eb22
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tests/band_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def test_setblock_getblock_full(self):
band[:, :] = d

self.assertEqual(np.sum(band[:,:] - d), 0.0)
return

def test_setblock_getblock_partial(self):

Expand All @@ -31,6 +32,7 @@ def test_setblock_getblock_partial(self):
band[128:960, :] = d

self.assertEqual(np.sum(band[128:960,:]-d), 0.0)
return

def test_setblock_getblock_striped(self):

Expand All @@ -41,6 +43,7 @@ def test_setblock_getblock_striped(self):
band[::2, 128:960:3] = d

self.assertEqual(np.sum(band[::2,128:960:3]-d), 0.0)
return

def test_get_scalar(self):

Expand Down
28 changes: 28 additions & 0 deletions tests/raster_misc_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,34 @@ def test_hillshade(self):
0.87979538950981906]))
return

def test_slope(self):
x = np.arange(64)
y = np.arange(64).reshape(-1, 1)
grid = RegularGrid((0, 0, 10, 10, 0, 0), values=x*np.ones_like(y))
slope = misc.slope(grid)
self.assertTrue(np.all(0.1 == slope[:,:]))

grid = RegularGrid((0, 0, 10, 10, 0, 0), values=x+y)
slope = misc.slope(grid)
self.assertTrue(np.allclose(0.14142136, slope[:,:]))
return

def test_aspect(self):
x = np.arange(64)
y = np.arange(64).reshape(-1, 1)
grid = RegularGrid((0, 0, 10, 10, 0, 0), values=x*np.ones_like(y))
aspect = misc.aspect(grid)
self.assertTrue(np.all(np.pi == aspect[1:-1,1:-1]))
self.assertTrue(np.all(np.isnan(aspect[0,:])))
self.assertTrue(np.all(np.isnan(aspect[-1,:])))
self.assertTrue(np.all(np.isnan(aspect[:,0])))
self.assertTrue(np.all(np.isnan(aspect[:,-1])))

grid = RegularGrid((0, 0, 10, 10, 0, 0), values=np.ones_like(x)*y)
aspect = misc.aspect(grid)
self.assertTrue(np.allclose(0.5*np.pi, aspect[1:-1,1:-1]))
pass

if __name__ == "__main__":
unittest.main()

Expand Down

0 comments on commit 4f7eb22

Please sign in to comment.