def test_detrend_heights_call(self):
        """ tests if the call of heights make no mistake
        """
        n = 10
        dx = 0.5
        h = np.random.normal(size=n)

        t = UniformLineScan(h, dx * n)
        for mode in ["height", "curvature", "slope"]:
            detrended = t.detrend(detrend_mode=mode)
            detrended.heights()
    def test_detrend_curvature(self):
        n = 10
        dx = 0.5
        x = np.arange(n) * dx

        R = 4.
        h = x ** 2 / R

        t = UniformLineScan(h, dx * n)

        detrended = t.detrend(detrend_mode="curvature")

        assert abs(detrended.coeffs[-1] / detrended.physical_sizes[0] ** 2 - 1 / R) < 1e-12
    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_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_from_profile(),
                                detrended.rms_slope_from_profile(),
                                msg=mode)
         else:
             self.assertGreater(t.rms_height_from_profile(),
                                detrended.rms_height_from_profile(),
                                msg=mode)