def verify(self, t): v, X = utils.fourier_transform(t, self.f(t)) self.assertTrue(utils.is_constant(np.diff(v), positive=True)) assert_allclose(X, self.F(v), atol=self.atol) v, X = utils.fourier_transform(t, self.f(t), sign=-1) self.assertTrue(utils.is_constant(np.diff(v), positive=True)) assert_allclose(X, self.F(-v), atol=self.atol) v, X = utils.fourier_transform(t, self.f(t), rw_freq=5) self.assertTrue(utils.is_constant(np.diff(v), positive=True)) assert_allclose(X, self.F(v - 5), atol=self.atol)
def test_is_constant(): assert utils.is_constant([1, 1, 1]) assert utils.is_constant([-1, -1, -1]) assert not utils.is_constant([1, 1, 1, 0]) assert not utils.is_constant([1, 1, 1, 1], positive=False) assert utils.is_constant([1, 1, 1, 1], positive=True) assert utils.is_constant([-1, -1, -1], positive=False) assert utils.is_constant([-1, -1, -1], positive=False)
def test_absorption_spectra(self): f, X = absorption_spectra(self.dyn, 10000) self.assertAlmostEqual(f[np.argmax(X)], 12500) self.assertTrue(is_constant(np.diff(f))) self.assertTrue(np.all(np.diff(X)[:int(len(X) / 2.0 - 1)] > 0)) self.assertTrue(np.all(np.diff(X)[-int(len(X) / 2.0 - 1):] < 0)) dyn2 = RedfieldModel(self.ham, rw_freq=12400, discard_imag_corr=True, unit_convert=CM_FS) f2, X2 = absorption_spectra(dyn2, 10000) self.assertAlmostEqual(f2[np.argmax(X2)], 12500, 0)