def test_sed_write_file_exists(self): sed = Sed(x=self.x,y=self.y,yerr=self.yerr) filename = test_directory+'sed_file_exists.dat' sed.write(filename) self.assertEqual(os.path.exists(filename), True)
def test_shift_sed(self): sed = Sed(x = self._x, y = self._y, yerr = self._yerr, xunit = self._xunit, yunit = self._yunit, z = self._z) shifted_sed_cfeqTrue = sed.shift(0.1) shifted_sed_cfeqTrue_arr = shifted_sed_cfeqTrue._toarray() # what sed.shift() should do spec_z0 = self._x*(1+0.1)/(1+sed.z) zflux = numpy.trapz(self._y, self._x) z0flux = numpy.trapz(self._y, spec_z0) const = zflux/z0flux self.assertEqual(shifted_sed_cfeqTrue.z, 0.1) self.assertEqual(isinstance(shifted_sed_cfeqTrue, Sed), True) numpy.testing.assert_array_almost_equal(shifted_sed_cfeqTrue_arr[1], self._y*const) # not correcting for dimming: correct_flux = False shifted_sed_cfeqFalse = sed.shift(0.1, correct_flux = False) shifted_sed_cfeqFalse_arr = shifted_sed_cfeqFalse._toarray() numpy.testing.assert_array_equal(shifted_sed_cfeqFalse_arr[1], self._y) numpy.testing.assert_array_equal(shifted_sed_cfeqFalse_arr[0],shifted_sed_cfeqTrue_arr[0]) numpy.testing.assert_array_equal(shifted_sed_cfeqFalse_arr[0],spec_z0)
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)
def test_toarray(self): sed = Sed(x = self._x, y = self._y, yerr = self._yerr, xunit = self._xunit, yunit = self._yunit, z = self._z) sedarray = sed._toarray() self.assertEqual(sedarray[1][0], self._y[0])
def test_normalize_by_int(self): sed = Sed(x = self._x, y = self._y, yerr = self._yerr, xunit = self._xunit, yunit = self._yunit, z = self._z) norm_sed = sed.normalize_by_int() self.assert_(hasattr(norm_sed, 'norm_constant'))
def test_sed_write_with_counts(self): sed = Sed(x=self.x,y=self.y,yerr=self.yerr) sed.counts = numpy.ones(numpy.array(sed._toarray()[0]).size, dtype=numpy.int_) filename = test_directory+'sed_counts.dat' sed.write(filename) self.assertEqual(os.path.exists(filename), True) data = astropy.io.ascii.read(filename) self.assertEqual(data['counts'][3],1.0)
def test_normalize_at_point_sed1(self): sed = Sed(x = self._x, y = self._y, yerr = self._yerr, xunit = self._xunit, yunit = self._yunit, z = self._z) norm_sed = sed.normalize_at_point(5000.0, 1e-11, norm_operator=1) self.assertAlmostEqual(norm_sed[2].y, 6.33e-11) self.assertAlmostEqual(norm_sed[1].y, 1e-11)
def test_shift(self): sed = Sed(x = self._x, y = self._y, yerr = self._yerr, xunit = self._xunit, yunit = self._yunit, z = self._z) shifted_sed_cfTrue = sed.shift(0.1) self.assertEqual(shifted_sed_cfTrue.z, 0.1) self.assertAlmostEqual(shifted_sed_cfTrue[1].x, 1858.75094339)
def test_get_setattr(self): sed = Sed(x=[1,2,3],y=[1,2,3,]) sed.id = 2051 sed.stuff = 'check me out' sed2 = Sed(x=[4,5,6],y=[4,5,6]) _get_setattr(sed2,sed) self.assertEqual(sed2.id, sed.id) self.assertNotEqual(sed2[0].x,sed[0].x) self.assertEqual(sed.stuff, sed2.stuff)
def test_aggsed_counts1(self): sed = Sed(x=self.x,y=self.y,yerr=self.yerr) sed.counts = numpy.ones(numpy.array(sed._toarray()[0]).size, dtype=numpy.int_) spectrum = Spectrum(x=self.x, y=self.y, yerr=self.yerr) aggsed = AggregateSed([sed, spectrum]) filename = test_directory+'aggsed_counts1.dat' aggsed.write(filename) self.assert_(os.path.exists(filename)) data = astropy.io.ascii.read(filename) self.assertEqual(all(counts == numpy.nan for counts in data['counts']), False)
def test_normalize_by_int_sed(self): sed = Sed(x = self._x, y = self._y, yerr = self._yerr, xunit = self._xunit, yunit = self._yunit, z = self._z) norm_sed = sed.normalize_by_int() norm_const = 1.0/numpy.trapz(abs(self._y),self._x) flux = self._y*norm_const fluxerr = self._yerr*norm_const self.assertEqual(norm_sed.norm_constant, norm_const) self.assertEqual(norm_sed[2].y, flux[2])
def test_remove_point(self): sed = Sed() point1 = PhotometricPoint(x=1.0, y=1.0) point2 = PhotometricPoint(x=2.0, y=-2.0) sed.add_point(point1) sed.add_point(point2) self.assert_(len(sed) == 2) sed.remove_point(0) self.assert_(len(sed) == 1) self.assertEqual(sed[0].x, 2.0)
def test_add_point(self): sed = Sed() point = PhotometricPoint(x=1.0, y=1.0) sed.add_point(point) self.assertEqual(sed[0].x, 1.0) self.assertEqual(sed[0].y, 1.0) self.assert_(numpy.isnan(sed[0].yerr)) self.assertEqual(len(sed[0].__dict__), 6, 'length of sed[0]') sed.add_point(PhotometricPoint(x=2.0, y=-2.0)) self.assertEqual(sed[0].x, 1.0) self.assertEqual(sed[1].y, -2.0) self.assertEqual(len(sed[1].__dict__), 6, 'length of sed[2]')
def test_add_sed(self): sed1 = Sed() sed2 = Sed(x = self._x, y = self._y, yerr = self._yerr, xunit = self._xunit, yunit = self._yunit, z = self._z) sed1.add_segment(sed2) self.assertEqual(len(sed1), 4) self.assertEqual(sed1[0].x, self._x[0]) sed3 = Sed(x = self._x, y = self._y, yerr = self._yerr, xunit = self._xunit, yunit = self._yunit, z = self._z) sed1.add_segment(sed2, sed3) self.assertEqual(len(sed1), 12) self.assertEqual(sed1[7].y, self._y[3]) total = 0 for points in sed1: total += points.x self.assertEqual(total, sum(self._x)*3) sed4 = Sed(x=numpy.linspace(1000,10000,num=100), y=numpy.linspace(1000,10000,num=100), yerr=numpy.linspace(1000,10000,num=100)*0.01) sed1.add_segment(sed4) self.assertEqual(len(sed1), 112)
def test_read_to_sed(self): xarr = numpy.array([16.0, 24.0, 70.0]) xunits = numpy.array(['micron','micron','micron']) yunits = numpy.array(['uJy','uJy','uJy']) sed = io.load_cat(test_directory+"one_source.dat", column_map1) self.assertEqual(type(sed), Sed) self.assertAlmostEqual(sed[0].x, xarr[0]) sed1 = Sed(x=xarr, y=numpy.array([46.1, 104.0, -99.0]), yerr=numpy.array([2.9, 6.2, -99.0]), xunit=xunits, yunit=yunits, z=2.69) sed1.id = 'num1' sed1.ra = '03:32:00.00' sed1.dec = '-27:46:35.0' self.assertEqual(sed.ra, sed1.ra)
def test_mask_point(self): sed = Sed(x=[0.0], y=[0.0]) point1 = PhotometricPoint(x=1.0, y=1.0) point2 = PhotometricPoint(x=2.0, y=-2.0) sed.add_point(point1) sed.add_point(point2) sed.mask_point(1) self.assert_(sed[1].mask) sed.unmask_point(1) self.failIf(sed[1].mask)
def test_xyyerr_properties(self): sed = Sed(x = self._x, y = self._y, yerr = self._yerr, xunit = self._xunit, yunit = self._yunit, z = self._z) numpy.testing.assert_array_equal(sed.x, self._x) numpy.testing.assert_array_equal(sed.y, self._y) numpy.testing.assert_array_equal(sed.yerr, self._yerr) sed.remove_point(0) numpy.testing.assert_array_equal(sed.x, self._x[1:]) numpy.testing.assert_array_equal(sed.y, self._y[1:]) numpy.testing.assert_array_equal(sed.yerr, self._yerr[1:]) p=PhotometricPoint(240000.,4.5e-9) sed.add_point(p) numpy.testing.assert_array_equal(sed.x, numpy.array([4477.9, 5657.1, 6370.0, 240000.])) sed.yerr = 1e-10 numpy.testing.assert_array_equal(sed.yerr, numpy.array([1e-10]*len(sed)))
def test_read_to_aggregateSed_simple(self): aggsed1 = io.load_cat(test_directory+"three_sources.dat", column_map1) xarr = numpy.array([16.0, 24.0, 70.0]) xunits = numpy.array(['micron','micron','micron']) yunits = numpy.array(['uJy','uJy','uJy']) self.assertEqual(len(aggsed1),3) self.assertAlmostEqual(aggsed1[0][0].x, xarr[0]) self.assertAlmostEqual(aggsed1[2][2].y, 2690.0) self.assert_(aggsed1.xunit[0][0] == xunits[0]) sed1 = Sed(x=xarr, y=numpy.array([46.1, 104.0, -99.0]), yerr=numpy.array([2.9, 6.2, -99.0]), xunit=xunits, yunit=yunits, z=2.69) sed1.id = 'num1' sed1.ra = '03:32:00.00' sed1.dec = '-27:46:35.0' sed2 = Sed(x=xarr, y=numpy.array([163.1, 115.0, -99.0]), yerr=numpy.array([2.8, 6.9, -99.0]), xunit=xunits, yunit=yunits, z=1.10) sed2.id = 'num2' sed2.ra = '03:32:00.00' sed2.dec = '-27:46:40.0' sed3 = Sed(x=xarr, y=numpy.array([2417.4, 3560.0, 2690.0]), yerr=numpy.array([53.3, 36.0, 500.9]), xunit=xunits, yunit=yunits, z=0.55) sed3.id = 'num3' sed3.ra = '03:32:00.00' sed3.dec = '-27:47:34.4' aggsed2 = AggregateSed([sed1, sed2, sed3]) self.failUnless(aggsed1[0][1].x == aggsed2[0][1].x) self.assertEqual(aggsed1[0].ra, sed1.ra) self.assertEqual(aggsed1[2].id, sed3.id) self.assertEqual(hasattr(aggsed1[1], 'z'), True) self.assertEqual(hasattr(aggsed1[1], 's24'), True) self.assertEqual(aggsed1[1][0].xunit, 'micron')