Exemplo n.º 1
0
    def test_add_segment(self):

        segment1 = Spectrum(x = numpy.arange(1000,10000,10),
                            y = numpy.arange(1000,10000,10),
                            yerr=numpy.arange(1000,10000,10)*.01,
                            z=1.0)
        segment2 = Sed(x=numpy.arange(1000,10000,500),
                       y=numpy.arange(1000,10000,500),
                       yerr=numpy.arange(1000,10000,500)*.01)
        segment3 = Sed(x=numpy.arange(1000,10000,500),
                       y=numpy.arange(1000,10000,500),
                       yerr=numpy.arange(1000,10000,500)*.01,
                       z = 0.35)
        segment4 = Spectrum(x = numpy.arange(1000,10000,10),
                            y = numpy.arange(1000,10000,10),
                            yerr=numpy.arange(1000,10000,10)*.01,
                            z=1.0)

        aggsed = Stack([segment1, segment2, segment3])

        aggsed.add_segment(segment4)

        self.assertEqual(len(aggsed), 4)
        self.assertEqual(len(aggsed.x[3]), len(segment4.x))
        
        aggsed.add_segment(segment3)

        self.assertEqual(len(aggsed), 5)
        self.assertEqual(len(aggsed.x[4]), len(segment3))  
Exemplo n.º 2
0
    def test_norm_at_point_correct_flux(self):

        segment1 = Spectrum(x = numpy.arange(1000,10000,10),
                            y = numpy.arange(1000,10000,10),
                            yerr=numpy.arange(1000,10000,10)*.01,
                            z=0)
        segment2 = Sed(x=numpy.arange(1000,10000,500),
                       y=numpy.arange(1000,10000,500),
                       yerr=numpy.arange(1000,10000,500)*.01,
                       z=0.0)
        segment3 = Sed(x=numpy.arange(1000,10000,500),
                       y=numpy.arange(1000,10000,500),
                       yerr=numpy.arange(1000,10000,500)*.01,
                       z = 0)
        segment4 = Spectrum(x = numpy.arange(1000,10000,10),
                            y = numpy.arange(1000,10000,10),
                            yerr=numpy.arange(1000,10000,10)*.01,
                            z=0)

        aggsed = Stack([segment1, segment2, segment3, segment4])
        norm_aggsed = aggsed.normalize_at_point(5000,1000,
                                                correct_flux=True,
                                                z0=[1.0,0.5,0.35,1.0])


        self.assertAlmostEqual(norm_aggsed[2].norm_constant, 0.148148148)
        self.assertAlmostEqual(norm_aggsed[3].norm_constant, 0.1)
Exemplo n.º 3
0
    def test_norm_at_point(self):

        segment1 = Spectrum(x = numpy.arange(1000,10000,1),
                            y = numpy.arange(1000,10000,1),
                            yerr=numpy.arange(1000,10000,1)*.01,
                            z=1.0)
        segment2 = Sed(x=numpy.arange(1000,10000,500),
                       y=numpy.arange(1000,10000,500),
                       yerr=numpy.arange(1000,10000,500)*.01)
        segment3 = Sed(x=numpy.arange(1000,10000,500),
                       y=numpy.arange(1000,10000,500),
                       yerr=numpy.arange(1000,10000,500)*.01,
                       z = 0.35)
        segment4 = Spectrum(x = numpy.arange(1000,10000,10),
                            y = numpy.arange(1000,10000,10),
                            yerr=numpy.arange(1000,10000,10)*.01,
                            z=1.0)

        x0 = 5025
        y0 = 1000

        aggsed = Stack([segment1, segment2, segment3, segment4])
        norm_aggsed = aggsed.normalize_at_point(x0,y0)

        sedarray = segment3._toarray()
        control_norm_aggsed_segment3 = sedarray[1]*0.2

        self.assertEqual(norm_aggsed[1][8].y, 1000)
        sedarray = norm_aggsed[2]._toarray()
        numpy.testing.assert_array_almost_equal(sedarray[1], control_norm_aggsed_segment3)
        self.assertEqual(norm_aggsed[0].norm_constant, numpy.float_(y0)/5025)
Exemplo n.º 4
0
    def test_shift_NoRedshift(self):

        segment1 = Spectrum(x = numpy.arange(1000,10000,10),
                            y = numpy.arange(1000,10000,10),
                            z=1.0)
        segment2 = Sed(x=numpy.arange(1000,10000,500),
                       y=numpy.arange(1000,10000,500))
        segment3 = Sed(x=numpy.arange(1000,10000,500),
                       y=numpy.arange(1000,10000,500),
                       z = 0.35)

        aggsed = Stack([segment1, segment2, segment3])

        shift_aggsed = aggsed.shift(0.5)

        self.assertEqual(len(shift_aggsed), 2)
        self.assertAlmostEqual(shift_aggsed.x[0][1], 757.5)
        self.assertAlmostEqual(shift_aggsed.x[1][1], 1666.6666667)
Exemplo n.º 5
0
    def test_shift(self):

        segment1 = Spectrum(x = numpy.arange(1000,10000,10),
                            y = numpy.arange(1000,10000,10),
                            z = 1.0)
        segment2 = Sed(x=numpy.arange(1000,10000,500),
                       y=numpy.arange(1000,10000,500),
                       z = 0.5)
        segment3 = Sed(x=numpy.arange(1000,10000,500),
                       y=numpy.arange(1000,10000,500),
                       z = 0.35)

        aggsed = Stack([segment1, segment2, segment3])

        shift_aggsed = aggsed.shift(0.4)

        self.assertEqual(shift_aggsed[0].z, shift_aggsed[1].z)
        self.assertEqual(shift_aggsed[0].z, 0.4)
        self.assertAlmostEqual(shift_aggsed.x[0][10], 770.0)
Exemplo n.º 6
0
    def test_norm_by_int_correct_flux(self):
        
        segment1 = Spectrum(x=numpy.arange(1000,10000,10),
                            y=numpy.arange(1000,10000,10),
                            yerr=numpy.arange(1000,10000,10)*.01,
                            z=0.0)
        segment2 = Sed(x=numpy.arange(1000,10000,500),
                       y=numpy.arange(1000,10000,500),
                       yerr=numpy.arange(1000,10000,500)*.01,
                       z=0.0)
        segment3 = Sed(x=numpy.arange(1000,10000,500),
                       y=numpy.arange(1000,10000,500),
                       yerr=numpy.arange(1000,10000,500)*.01,
                       z = 0)
        segment4 = Spectrum(x=numpy.arange(1000,10000,10),
                            y=numpy.arange(1000,10000,10),
                            yerr=numpy.arange(1000,10000,10)*.01,
                            z=0)

        aggsed = Stack([segment1, segment2, segment3, segment4])

        norm_aggsed = aggsed.normalize_by_int(correct_flux=True, z0=[1,.5,.1,1])

        aggsed[0].z=1.0
        aggsed[1].z=0.5
        aggsed[2].z=0.1
        aggsed[3].z=1.0
        rf_aggsed=aggsed.shift(0.0)
        rf_aggsed0=rf_aggsed[0].shift(1.0, correct_flux=False)
        rf_aggsed1=rf_aggsed[1].shift(0.5, correct_flux=False)
        rf_aggsed2=rf_aggsed[2].shift(0.1, correct_flux=False)
        rf_aggsed3=rf_aggsed[3].shift(1.0, correct_flux=False)
        rf_aggsed=Stack([rf_aggsed0,rf_aggsed1,rf_aggsed2,rf_aggsed3])
        control_norm_aggsed = rf_aggsed.normalize_by_int()

        self.assertAlmostEqual(norm_aggsed.segments[0].norm_constant, control_norm_aggsed[0].norm_constant)
        self.assertAlmostEqual(norm_aggsed[1].norm_constant,1.4939309057e-08)
        numpy.testing.assert_array_almost_equal(control_norm_aggsed[0].y,norm_aggsed[0].y)
        sed=norm_aggsed[1]
        control_sed=control_norm_aggsed[1]
        numpy.testing.assert_array_almost_equal(control_sed.y,sed.y)
        numpy.testing.assert_array_almost_equal(control_sed.y,sed.y)
Exemplo n.º 7
0
    def test_norm_by_int(self):
        
        segment1 = Spectrum(x = numpy.arange(1000,10000,10),
                            y = numpy.arange(1000,10000,10),
                            yerr=numpy.arange(1000,10000,10)*.01,
                            z=1.0)
        segment2 = Sed(x=numpy.arange(1000,10000,500),
                       y=numpy.arange(1000,10000,500),
                       yerr=numpy.arange(1000,10000,500)*.01)
        segment3 = Sed(x=numpy.arange(1000,10000,500),
                       y=numpy.arange(1000,10000,500),
                       yerr=numpy.arange(1000,10000,500)*.01,
                       z = 0.35)
        segment4 = Spectrum(x = numpy.arange(1000,10000,10),
                            y = numpy.arange(1000,10000,10),
                            yerr=numpy.arange(1000,10000,10)*.01,
                            z=1.0)

        aggsed = Stack([segment1, segment2, segment3, segment4])

        norm_aggsed = aggsed.normalize_by_int()

        self.assertAlmostEqual(norm_aggsed.segments[0].norm_constant, 2.0288029e-08)
Exemplo n.º 8
0
    def test_redshift_correct_flux(self):

        sed1 = IrisSed(x=self.x,y=self.y,yerr=self.yerr, id='sed1', z=0.1)
        sed2 = IrisSed(x=numpy.array([2,4,5,8,10]), y=numpy.arange(5)+1.0, yerr=numpy.arange(5)+1.0*0.1, id='sed2', z=0.1)
        y = numpy.array([5.0, 15.0, 7.0, 4.5, 13.5, 10.5])
        x = numpy.array([0.5, 1.5, 3.0, 5.0, 10.5, 21.0])
        sed3 = IrisSed(x=x, y=y, yerr=y*0.1, id='sed3', z=0.1)

        iris_stack = IrisStack([sed1, sed2, sed3])
        shifted_iris_stack = iris_stack.shift(0.0, correct_flux=True)

        sed1 = IrisSed(x=self.x,y=self.y,yerr=self.yerr, z=0.1)
        sed2 = IrisSed(x=numpy.array([2,4,5,8,10]), y=numpy.arange(5)+1.0, yerr=numpy.arange(5)+1.0*0.1, z=0.2)
        y = numpy.array([5.0, 15.0, 7.0, 4.5, 13.5, 10.5])
        x = numpy.array([0.5, 1.5, 3.0, 5.0, 10.5, 21.0])
        sed3 = IrisSed(x=x, y=y, yerr=y*0.1, z=0.3)

        stack = Stack([sed1, sed2, sed3])

        shifted_stack = stack.shift(0.0, correct_flux=True)

        self.assertEqual(len(shifted_iris_stack.segments), 3)
        numpy.testing.assert_array_almost_equal(shifted_stack[0].x, shifted_iris_stack[0].x)
        numpy.testing.assert_array_almost_equal(shifted_stack[0].y, shifted_iris_stack[0].y)
Exemplo n.º 9
0
    def test_remove_segment(self):
        
        segment1 = Spectrum(x = numpy.arange(1000,10000,10),
                            y = numpy.arange(1000,10000,10),
                            yerr=numpy.arange(1000,10000,10)*.01,
                            z=1.0)
        segment2 = Sed(x=numpy.arange(1000,10000,500),
                       y=numpy.arange(1000,10000,500),
                       yerr=numpy.arange(1000,10000,500)*.01)
        segment3 = Sed(x=numpy.arange(1000,10000,500),
                       y=numpy.arange(1000,10000,500),
                       yerr=numpy.arange(1000,10000,500)*.01,
                       z = 0.35)
        segment4 = Spectrum(x = numpy.arange(1000,10000,10),
                            y = numpy.arange(1000,10000,10),
                            yerr=numpy.arange(1000,10000,10)*.01,
                            z=1.0)

        aggsed = Stack([segment1, segment2, segment3, segment4])

        aggsed.remove_segment(segment1)

        self.assertEqual(len(aggsed), 3)
        self.assertEqual(len(aggsed.x[0]), len(numpy.arange(1000,10000,500)))