def test_randomly_rough(self):
     surface = fourier_synthesis((511, 511), (1., 1.), 0.8, rms_height=1)
     self.assertTrue(surface.is_uniform)
     cut = Topography(surface[:64, :64], physical_sizes=(64., 64.))
     self.assertTrue(cut.is_uniform)
     untilt1 = cut.detrend(detrend_mode='height')
     untilt2 = cut.detrend(detrend_mode='slope')
     self.assertTrue(untilt1.is_uniform)
     self.assertTrue(untilt2.is_uniform)
     self.assertTrue(untilt1.rms_height_from_area() < untilt2.rms_height_from_area())
     self.assertTrue(untilt1.rms_gradient() > untilt2.rms_gradient())
Пример #2
0
 def test_checkerboard_detrend_with_no_subdivisions(self):
     r = 32
     x, y = np.mgrid[:r, :r]
     h = 1.3 * x - 0.3 * y + 0.02 * x * x + 0.03 * y * y - 0.013 * x * y
     t = Topography(h, (1, 1), periodic=False)
     # This should be the same as a detrend with detrend_mode='height'
     ut1 = t.checkerboard_detrend((1, 1))
     ut2 = t.detrend().heights()
     np.testing.assert_allclose(ut1, ut2)
Пример #3
0
def test_positions_and_heights():
    X = np.arange(3).reshape(1, 3)
    Y = np.arange(4).reshape(4, 1)
    h = X + Y

    t = Topography(h, (8, 6))

    assert t.nb_grid_pts == (4, 3)

    assert_array_equal(t.heights(), h)
    X2, Y2, h2 = t.positions_and_heights()
    assert_array_equal(X2, [
        (0, 0, 0),
        (2, 2, 2),
        (4, 4, 4),
        (6, 6, 6),
    ])
    assert_array_equal(Y2, [
        (0, 2, 4),
        (0, 2, 4),
        (0, 2, 4),
        (0, 2, 4),
    ])
    assert_array_equal(h2, [(0, 1, 2), (1, 2, 3), (2, 3, 4), (3, 4, 5)])

    #
    # After detrending, the position and heights should have again
    # just 3 arrays and the third array should be the same as .heights()
    #
    dt = t.detrend(detrend_mode='slope')

    np.testing.assert_allclose(dt.heights(), [(0, 0, 0), (0, 0, 0), (0, 0, 0),
                                              (0, 0, 0)],
                               atol=1e-15)

    X2, Y2, h2 = dt.positions_and_heights()

    assert h2.shape == (4, 3)
    assert_array_equal(X2, [
        (0, 0, 0),
        (2, 2, 2),
        (4, 4, 4),
        (6, 6, 6),
    ])
    assert_array_equal(Y2, [
        (0, 2, 4),
        (0, 2, 4),
        (0, 2, 4),
        (0, 2, 4),
    ])
    np.testing.assert_allclose(h2, [(0, 0, 0), (0, 0, 0), (0, 0, 0),
                                    (0, 0, 0)],
                               atol=1e-15)
 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)