def test_smooth_without_size(self):
     arr = self._flat_arr
     surf = Topography(arr, (1, 1)).detrend(detrend_mode='height')
     self.assertEqual(surf.dim, 2)
     self.assertTrue(surf.is_uniform)
     self.assertAlmostEqual(surf.mean(), 0)
     self.assertAlmostEqual(surf.rms_gradient(), 0)
     self.assertTrue(
         surf.rms_height_from_area() < Topography(arr, (1, 1)).rms_height_from_area())
    def test_smooth_flat_2d(self):
        arr = self._flat_arr

        a = 1.2
        b = 2.5
        d = .2
        arr = np.arange(5) * a + d
        arr = arr + np.arange(6).reshape((-1, 1)) * b

        surf = Topography(arr, (1, 1)).detrend(detrend_mode='center')
        self.assertTrue(surf.is_uniform)
        self.assertAlmostEqual(surf.mean(), 0)

        surf = Topography(arr, (1.5, 3.2)).detrend(detrend_mode='slope')
        self.assertEqual(surf.dim, 2)
        self.assertTrue(surf.is_uniform)
        self.assertAlmostEqual(surf.mean(), 0)
        self.assertAlmostEqual(surf.rms_gradient(), 0)

        surf = Topography(arr, arr.shape).detrend(detrend_mode='height')
        self.assertEqual(surf.dim, 2)
        self.assertTrue(surf.is_uniform)
        self.assertAlmostEqual(surf.mean(), 0)
        self.assertAlmostEqual(surf.rms_gradient(), 0)
        self.assertTrue(
            surf.rms_height_from_area() < Topography(arr, arr.shape).rms_height_from_area())

        surf2 = Topography(arr, (1, 1)).detrend(detrend_mode='height')
        self.assertEqual(surf.dim, 2)
        self.assertTrue(surf2.is_uniform)
        self.assertAlmostEqual(surf2.rms_gradient(), 0)
        self.assertTrue(
            surf2.rms_height_from_area() < Topography(arr, arr.shape).rms_height_from_area())

        self.assertAlmostEqual(surf.rms_height_from_area(), surf2.rms_height_from_area())

        x, y, z = surf2.positions_and_heights()
        self.assertAlmostEqual(np.mean(np.diff(x[:, 0])),
                               surf2.physical_sizes[0] / surf2.nb_grid_pts[0])
        self.assertAlmostEqual(np.mean(np.diff(y[0, :])),
                               surf2.physical_sizes[1] / surf2.nb_grid_pts[1])
 def test_smooth_curved(self):
     a = 1.2
     b = 2.5
     c = 0.1
     d = 0.2
     e = 0.3
     f = 5.5
     x = np.arange(5).reshape((1, -1))
     y = np.arange(6).reshape((-1, 1))
     arr = f + x * a + y * b + x * x * c + y * y * d + x * y * e
     sx, sy = 3, 2.5
     nx, ny = arr.shape
     surf = Topography(arr, physical_sizes=(sx, sy))
     surf = surf.detrend(detrend_mode='curvature')
     self.assertTrue(surf.is_uniform)
     self.assertAlmostEqual(surf.coeffs[0], b * nx)
     self.assertAlmostEqual(surf.coeffs[1], a * ny)
     self.assertAlmostEqual(surf.coeffs[2], d * (nx * nx))
     self.assertAlmostEqual(surf.coeffs[3], c * (ny * ny))
     self.assertAlmostEqual(surf.coeffs[4], e * (nx * ny))
     self.assertAlmostEqual(surf.coeffs[5], f)
     self.assertAlmostEqual(surf.rms_height_from_area(), 0.0)
     self.assertAlmostEqual(surf.rms_gradient(), 0.0)
     self.assertAlmostEqual(surf.rms_curvature_from_area(), 0.0)