def test_kk_no_bg_norm(): x = np.linspace(-100, 100, 1000) y = 2/(2**2 + x**2) kk = KramersKronig(norm_to_nrb=False) kkd = kk.calculate(y, 0*y + 1) assert_array_almost_equal(np.abs(kkd), np.sqrt(y))
def test_kk_transform_fail(): x = np.linspace(-100, 100, 1000) y = 2/(2**2 + x**2) y_complex = y.astype(np.complex) kk = KramersKronig(norm_to_nrb=False) success = kk._transform(y, 0*y + 1) assert not success
def test_kk_transform(): x = np.linspace(-100, 100, 1000) y = 2/(2**2 + x**2) y_complex = y.astype(np.complex) kk = KramersKronig(norm_to_nrb=False) success = kk._transform(y_complex, 0*y_complex + 1) assert success assert_array_almost_equal(np.abs(y_complex), np.sqrt(y))
def test_kk_rng(): x = np.linspace(-100, 100, 1000) y = 2/(2**2 + x**2) rng = np.arange(5, x.size) kk = KramersKronig(norm_to_nrb=False, rng=rng) kkd = kk.calculate(y, 0*y + 1) assert_array_almost_equal(np.abs(kkd[rng]), np.sqrt(y[rng]))
def test_kk(): x = np.linspace(-100, 100, 1000) y = 2/(2**2 + x**2) hilb_y_analytical = x/(2**2 + x**2) kk = KramersKronig(pad_factor=10) kkd = kk.calculate(np.exp(2*y), 0*y + 1) kkd_angle = np.angle(kkd) assert_array_almost_equal(hilb_y_analytical, kkd_angle, decimal=4)
def test_kk_properties_setter(): x = np.linspace(-100, 100, 1000) y = 2/(2**2 + x**2) hilb_y_analytical = x/(2**2 + x**2) kk = KramersKronig() kk.pad_factor=10 kk.norm_to_nrb=True kk.phase_offset=3.0 assert kk.pad_factor == 10 assert kk.norm_to_nrb assert kk.phase_offset == 3.0
SPECT_LEN = 878 WN = _np.linspace(4000, 500, SPECT_LEN) chi = (1 / ((WN - 1000 - 1j * 10)) + 1 / ((WN - 1020 - 1j * 10)) + 1 / ((WN - 2800 - 1j * 10))) chiNR = 0*chi + 0.055 exc = WN sig = _np.abs(chi + chiNR)**2 sigNR = _np.abs(chiNR)**2 sigRef = chiNR*(WN/1e3)**.5 NUM_REPS = 10 kk = KramersKronig() kkd = kk.calculate(sig, sigRef) kkd = _np.dot(_np.random.rand(NUM_REPS,NUM_REPS,1)*_np.ones((NUM_REPS, NUM_REPS, 1)), kkd[None, :]) # plt.plot(chi.imag/chiNR.real, label='Ideal') plt.plot(kkd[5, 5, :].imag, label='Before Correction') start = timeit.default_timer() phase_err_correct_als = PhaseErrCorrectALS(fix_end_points=True, smoothness_param=1e8, asym_param=1e-3, redux=1) success = phase_err_correct_als.transform(kkd, verbose=False) print('Success? : {}'.format(success)) stop = timeit.default_timer() print('Sec/spectrum: {:.3g}'.format((stop-start)/NUM_REPS**2))