Example #1
0
 def test_norm_at_point_spectrum3(self):
     
     spectrum = Spectrum(x = range(0, 101),
                         y = range(0, 101))
     norm_spectrum = spectrum.normalize_at_point(20, 50, dx=50)
     control_avg_flux = 35.0
     control_norm_constant = 50.0/control_avg_flux
     self.assertEqual(norm_spectrum.norm_constant, control_norm_constant)
Example #2
0
    def test_norm_at_point_spectrum1(self):
        
        spectrum = Spectrum(x = numpy.linspace(3000.0, 10000.0, num=10000),
                            y = numpy.linspace(1e-13, 1e-11, num=10000))
        
        norm_spectrum = spectrum.normalize_at_point(5000.0, 1e-13)

        assert abs(norm_spectrum.norm_constant - 0.034145) < 0.00001
        self.assertEqual(len(norm_spectrum.yerr), len(norm_spectrum.x))
        self.assert_(numpy.isnan(norm_spectrum.yerr[1]))
Example #3
0
    def test_norm_at_point_spectrum2(self):
        
        spectrum = Spectrum(x = range(0, 101),
                            y = range(0, 101))
        
        norm_spectrum = spectrum.normalize_at_point(20, 50, dx=10)

        control_norm_constant = 50.0/20.0
        control_norm_spectrum_y = spectrum.y*control_norm_constant

        self.assertEqual(norm_spectrum.norm_constant, 2.5)
        numpy.testing.assert_array_almost_equal(norm_spectrum.y, control_norm_spectrum_y)
Example #4
0
    def test_normalize_by_int_spectrum(self):
        
        spectrum = Spectrum(x = numpy.linspace(3000.0, 10000.0, num=10000),
                            y = numpy.linspace(1e-13, 1e-11, num=10000))
        norm_spectrum = spectrum.normalize_by_int()

        astlib_spectrum = astsed.SED(wavelength=numpy.linspace(3000.0, 10000.0, num=10000),
                                     flux = numpy.linspace(1e-13, 1e-11, num=10000))
        astlib_spectrum.normalise()


        self.assertEqual(norm_spectrum.y[200], astlib_spectrum.flux[200])
        self.assertAlmostEqual(norm_spectrum.y[200] / norm_spectrum.norm_constant, spectrum.y[200])
Example #5
0
    def test_shift_spectrum(self):

        spectrum = Spectrum(x = numpy.linspace(3000.0, 10000.0, num=10000),
                            y = numpy.linspace(1e-13, 1e-11, num=10000), 
                            z = 1.65)

        shifted_spectrum_cfeqTrue = spectrum.shift(0.1)
        shifted_spectrum_cfeqFalse = spectrum.shift(0.1, correct_flux = False)

        # spec_z0 = spectrum.x*(1+0.1)/(spectrum.z)
        # zflux = numpy.trapz(spectrum.y, spectrum.x)
        # z0flux = numpy.trapz(spectrum.y, spec_z0)
        # const = zflux/z0flux
        const = 1.4673584905660368e-08/3.5350000000000254e-08

        self.assertEqual(shifted_spectrum_cfeqTrue.z, 0.1)
        self.assertAlmostEqual(shifted_spectrum_cfeqTrue.x[9], 1247.8983747) #, delta=1e-6)
        numpy.testing.assert_array_almost_equal(shifted_spectrum_cfeqTrue.y, spectrum.y*const)
        numpy.testing.assert_array_equal(shifted_spectrum_cfeqFalse.x, shifted_spectrum_cfeqTrue.x)
        numpy.testing.assert_array_equal(shifted_spectrum_cfeqFalse.y, spectrum.y)
Example #6
0
 def test_spectrum_write_file_exists(self):
     spectrum = Spectrum(x=self.x, y=self.y, yerr=self.yerr)
     filename = test_directory+'spectrum_file_exists.dat'
     spectrum.write(filename)
     self.assertEqual(os.path.exists(filename), True)