def test_call(): """ Check generated Gaussian function """ from numpy import arange gaussian = Gaussian("gaussian", 0.4, 5.0, 1.5, 0.3, 4, 1.5, 0) t = arange(0.0, 100.0) A = gaussian.generate(t) P = abs(A)**2 assert_almost_equal(max(P), 1.5)
def test_call(): """ Check generated Gaussian function """ from numpy import arange gaussian = Gaussian("gaussian", 0.4, 5.0, 1.5, 0.3, 4, 1.5, 0) t = arange(0.0, 100.0) A = gaussian.generate(t) P = abs(A) ** 2 assert_almost_equal(max(P), 1.5)
def test_conversion(self): """ Should calculate a FWHM pulse width from the HWIeM value. """ gaussian = Gaussian(width=100.0) fwhm = gaussian.calculate_fwhm() self.assertEqual(fwhm, 166.51092223153952) gaussian = Gaussian(width=100.0, m=3) fwhm = gaussian.calculate_fwhm() self.assertEqual(fwhm, 188.14856305595509)
def test_output(self): """ Check Gaussian outputs its values correctly """ gaussian = Gaussian("gaussian", 0.2, 5.0, 1.4, 0.3, 4, 0.4, 0.0, 1) expected_string = [ 'position = 0.200000', 'width = 5.000000 ps', 'fwhm = 9.552195 ps', 'peak_power = 1.400000 W', 'offset_nu = 0.300000 THz', 'm = 4', 'C = 0.400000', 'initial_phase = 0.000000 rad', 'channel = 1' ] self.assertEqual(str(gaussian), '\n'.join(expected_string))
def test_none(self): """ Should use default value if no parameter given """ gaussian = Gaussian() self.assertEqual(gaussian.name, "gaussian") self.assertEqual(gaussian.position, 0.5) self.assertEqual(gaussian.width, 10.0) self.assertEqual(gaussian.peak_power, 1e-3) self.assertEqual(gaussian.offset_nu, 0.0) self.assertEqual(gaussian.m, 1) self.assertEqual(gaussian.C, 0.0) self.assertEqual(gaussian.initial_phase, 0.0) self.assertEqual(gaussian.channel, 0) self.assertIsNone(gaussian.fwhm)
def test_bad_t(self): """ Should raise exception when temporal array has too few values """ from numpy import arange t = arange(0.0, 4.0) self.assertRaises(OutOfRangeError, Gaussian().generate, t)