def test_positions_and_heights(self): h = np.array((0, 1, 2, 3, 4)) t = UniformLineScan(h, 4) assert_array_equal(t.heights(), h) expected_x = np.array((0., 0.8, 1.6, 2.4, 3.2)) np.testing.assert_allclose(t.positions(), expected_x) x2, h2 = t.positions_and_heights() np.testing.assert_allclose(x2, expected_x) assert_array_equal(h2, h)
def test_detrend_same_positions(self): """asserts that the detrended topography has the same x """ n = 10 dx = 0.5 h = np.random.normal(size=n) t = UniformLineScan(h, dx * n) for mode in ["curvature", "slope", "height"]: detrended = t.detrend(detrend_mode=mode) np.testing.assert_allclose(detrended.positions(), t.positions()) np.testing.assert_allclose(detrended.positions_and_heights()[0], t.positions_and_heights()[0])
def test_smooth_flat_1d(self): arr = self._flat_arr a = 1.2 d = .2 arr = np.arange(5) * a + d surf = UniformLineScan(arr, (1,)).detrend(detrend_mode='center') self.assertTrue(surf.is_uniform) self.assertAlmostEqual(surf.mean(), 0) surf = UniformLineScan(arr, (1.5,)).detrend(detrend_mode='slope') self.assertEqual(surf.dim, 1) self.assertTrue(surf.is_uniform) self.assertAlmostEqual(surf.mean(), 0) self.assertAlmostEqual(surf.rms_slope_from_profile(), 0) surf = UniformLineScan(arr, arr.shape).detrend(detrend_mode='height') self.assertEqual(surf.dim, 1) self.assertTrue(surf.is_uniform) self.assertAlmostEqual(surf.mean(), 0) self.assertAlmostEqual(surf.rms_slope_from_profile(), 0) self.assertTrue( surf.rms_height_from_profile() < UniformLineScan(arr, arr.shape).rms_height_from_profile()) surf2 = UniformLineScan(arr, (1,)).detrend(detrend_mode='height') self.assertEqual(surf.dim, 1) self.assertTrue(surf2.is_uniform) self.assertAlmostEqual(surf2.rms_slope_from_profile(), 0) self.assertTrue( surf2.rms_height_from_profile() < UniformLineScan(arr, arr.shape).rms_height_from_profile()) self.assertAlmostEqual(surf.rms_height_from_profile(), surf2.rms_height_from_profile()) x, z = surf2.positions_and_heights() self.assertAlmostEqual(np.mean(np.diff(x)), surf2.physical_sizes[0] / surf2.nb_grid_pts[0])