Exemple #1
0
    def calc_slope(self, dem):
        """Calculate the slope

        Arguments:
            dem {numpy} -- dem array
        """

        return gradient_d8(dem, self.dx, self.dy, aspect_rad=True)
    def test_gradient_d8_flat(self):
        """ Test for the gradient_d8 for flat """

        # test south slope and aspect
        dem = np.ones((10, 10))
        py_slope, asp = gradient.gradient_d8(dem, self.dx, self.dy)
        ipw_a = gradient.aspect_to_ipw_radians(asp)

        self.assertTrue(np.all(py_slope == 0))
        self.assertTrue(np.all(asp == 180))
        self.assertTrue(np.all(ipw_a == 0))
    def test_gradient_d8_ne(self):
        """ Test for the gradient_d8 for ne """

        # test northeast slope and aspect
        dem = self.gen_dem_ne()
        py_slope, asp = gradient.gradient_d8(dem, self.dx, self.dy)
        ipw_a = gradient.aspect_to_ipw_radians(asp)

        self.assertTrue(np.all(py_slope == self.slope_val))
        self.assertTrue(np.all(asp == 45))
        self.assertTrue(np.all(ipw_a == (np.pi / 2 + np.pi / 4)))
    def test_gradient_d8_sw(self):
        """ Test for the gradient_d8 for sw """

        # test southwest slope and aspect
        dem = self.gen_dem_sw()
        py_slope, asp = gradient.gradient_d8(dem, self.dx, self.dy)
        ipw_a = gradient.aspect_to_ipw_radians(asp)

        self.assertTrue(np.all(py_slope == self.slope_val))
        self.assertTrue(np.all(asp == 225))
        self.assertTrue(np.all(ipw_a == -np.pi / 4))
    def test_gradient_d8_south(self):
        """ Test for the gradient_d8 for south """

        # test south slope and aspect
        dem = np.flipud(np.tile(range(10), (10, 1)).transpose())
        py_slope, asp = gradient.gradient_d8(dem, self.dx, self.dy)
        ipw_a = gradient.aspect_to_ipw_radians(asp)

        self.assertTrue(np.all(py_slope == np.pi / 4))
        self.assertTrue(np.all(asp == 180))
        self.assertTrue(np.all(ipw_a == 0))
    def test_gradient_d8_east(self):
        """ Test for the gradient_d8 for east """

        # test east slope and aspect
        dem = np.fliplr(np.tile(range(10), (10, 1)))
        py_slope, asp = gradient.gradient_d8(dem, self.dx, self.dy)
        ipw_a = gradient.aspect_to_ipw_radians(asp)

        self.assertTrue(np.all(py_slope == np.pi / 4))
        self.assertTrue(np.all(asp == 90))
        self.assertTrue(np.all(ipw_a == np.pi / 2))