def test_power_spectrum_1D(self): # # this test was added, because there were issues calling # power spectrum 1D with a window given # t = UniformLineScan([2, 4, 6, 8], 4) t.power_spectrum_1D(window='hann')
def test_uniform(): for periodic in [True, False]: for L in [1.3, 10.6]: for k in [2, 4]: for n in [16, 128]: x = np.arange(n) * L / n h = np.sin(2 * np.pi * k * x / L) t = UniformLineScan(h, physical_sizes=L, periodic=periodic) q, C = t.power_spectrum_1D() # The ms height of the sine is 1/2. The sum over the PSD # (from -q to +q) is the ms height. Our PSD only contains # *half* of the full PSD (on the +q branch, the -q branch # is identical), therefore the sum over it is 1/4. assert_almost_equal(C.sum() / L, 1 / 4) if periodic: # The value at the individual wavevector must also # equal 1/4. This is only exactly true for the # periodic case. In the nonperiodic, this is convolved # with the Fourier transform of the window function. C /= L r = np.zeros_like(C) r[k] = 1 / 4 assert_array_almost_equal(C, r)
def test_default_window_1D(): x = np.linspace(0, 1, 200) heights = np.cos(2 * np.pi * x * 8.3) topography = UniformLineScan(heights, physical_sizes=1, periodic=True) if True: import matplotlib.pyplot as plt fig, ax = plt.subplots() ax.plot(*topography.power_spectrum_1D(), label="periodic=True") ax.set_xscale("log") ax.set_yscale("log") topography = UniformLineScan(heights, physical_sizes=1, periodic=False) if True: import matplotlib.pyplot as plt ax.plot(*topography.power_spectrum_1D(), label="periodic=False") ax.set_xscale("log") ax.set_yscale("log") ax.set_ylim(bottom=1e-6) ax.legend() plt.show(block=True)