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])
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)
def test_lbfgsb_1D(dx, n): # test the 1D periodic objective is working s = n * dx Es = 1. substrate = PeriodicFFTElasticHalfSpace((n,), young=Es, physical_sizes=(s,), fft='serial') surface = UniformLineScan(np.cos(2 * np.pi * np.arange(n) / n), (s,)) system = make_system(substrate, surface) offset = 0.005 lbounds = np.zeros(n) bnds = system._reshape_bounds(lbounds, ) init_gap = np.zeros(n, ) # .flatten() disp = init_gap + surface.heights() + offset res = optim.minimize(system.primal_objective(offset, gradient=True), disp, method='L-BFGS-B', jac=True, bounds=bnds, options=dict(gtol=1e-5 * Es * surface.rms_slope_from_profile() * surface.area_per_pt, ftol=0)) forces = res.jac gap = res.x converged = res.success assert converged if hasattr(res.message, "decode"): decoded_message = res.message.decode() else: decoded_message = res.message assert decoded_message == \ 'CONVERGENCE: NORM_OF_PROJECTED_GRADIENT_<=_PGTOL' x = np.arange(n) * s / n mean_pressure = np.mean(forces) / substrate.area_per_pt assert mean_pressure > 0 pth = mean_pressure * _pressure( x / s, mean_pressure=s * mean_pressure / Es) if False: import matplotlib.pyplot as plt plt.figure() # plt.plot(np.arange(n)*s/n, surface.heights()) plt.plot(x, gap + (surface.heights()[:] + offset), 'r-') plt.plot(x, (surface.heights()[:] + offset), 'k-') plt.figure() plt.plot(x, forces / substrate.area_per_pt, 'k-') plt.plot(x, pth, 'r-') plt.show() assert (np.allclose( forces / substrate.area_per_pt, pth, atol=1e-2))