def test_rms_curvature_paraboloid_uniform_2D(): n = 16 X, Y = np.mgrid[slice(0, n), slice(0, n)] curvature = 0.1 heights = 0.5 * curvature * (X**2 + Y**2) surf = Topography(heights, physical_sizes=(n, n), periodic=False) # central finite differences are second order and so exact for the # paraboloid assert abs( (surf.rms_curvature_from_area() - curvature) / curvature) < 1e-15
def test_rms_curvature_sinewave_2D(periodic): precision = 5 n = 256 X, Y = np.mgrid[slice(0, n), slice(0, n)] hm = 0.3 L = float(n) size = (L, L) surf = Topography(np.sin(2 * np.pi / L * X) * hm, physical_sizes=size, periodic=periodic) numerical_lapl = surf.rms_laplacian() analytical_lapl = np.sqrt((2 * np.pi / L)**4 * hm**2 / 2) # print(numerical-analytical) np.testing.assert_almost_equal(numerical_lapl, analytical_lapl, precision) np.testing.assert_almost_equal(surf.rms_curvature_from_area(), analytical_lapl / 2, precision)
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)