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(), 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(), 0) self.assertTrue( surf.rms_height() < UniformLineScan(arr, arr.shape).rms_height()) surf2 = UniformLineScan(arr, (1, )).detrend(detrend_mode='height') self.assertEqual(surf.dim, 1) self.assertTrue(surf2.is_uniform) self.assertAlmostEqual(surf2.rms_slope(), 0) self.assertTrue( surf2.rms_height() < UniformLineScan(arr, arr.shape).rms_height()) self.assertAlmostEqual(surf.rms_height(), surf2.rms_height()) x, z = surf2.positions_and_heights() self.assertAlmostEqual(np.mean(np.diff(x)), surf2.physical_sizes[0] / surf2.nb_grid_pts[0])
def test_detrend_reduces(self): """ tests if detrending really reduces the heights (or slope) as claimed """ n = 10 dx = 0.5 h = [ 0.82355941, -1.32205074, 0.77084813, 0.49928252, 0.57872149, 2.80200331, 0.09551251, -1.11616977, 2.07630937, -0.65408072 ] t = UniformLineScan(h, dx * n) for mode in ['height', 'curvature', 'slope']: detrended = t.detrend(detrend_mode=mode) self.assertAlmostEqual(detrended.mean(), 0) if mode == 'slope': self.assertGreater(t.rms_slope(), detrended.rms_slope(), msg=mode) else: self.assertGreater(t.rms_height(), detrended.rms_height(), msg=mode)