Esempio n. 1
0
 def setUpClass(ModelTestCase):
     """ Setup the tmap grid as it is smaller and thus faster as kurucz"""
     model.set_defaults(grid='kurucztest')
     grid1 = dict(grid='tmaptest')
     grid2 = dict(grid='tmaptest')
     model.set_defaults_multiple(grid1,grid2)
     model.copy2scratch(z='*', Rv='*')      
Esempio n. 2
0
 def testiGrid_searchSingleHot(self):
     """ INTEGRATION igrid_search single star (tmap) """
     sed = builder.SED(ID='TEST', load_fits=False)
     np.random.seed(111)
     meas = self.measHot + np.random.uniform(0, 0.04, size=len(self.measHot)) * self.measHot
     emeas = meas / 100.0
     units = ['erg/s/cm2/AA' for i in meas]
     source = ['SYNTH' for i in meas]
     sed.add_photometry_fromarrays(meas, emeas, units, self.photbands, source)
     
     model.set_defaults(grid='tmaptest')
     model.copy2scratch(z='*', Rv='*')
     
     np.random.seed(111)
     sed.igrid_search(points=100000,teffrange=(25000, 35000),loggrange=(5.0, 6.0), 
                      ebvrange=(0.005, 0.015),zrange=(0,0),rvrange=(3.1,3.1),
                      vradrange=(0,0),df=None,CI_limit=0.95,set_model=True)
     
     self.assertAlmostEqual(sed.results['igrid_search']['CI']['teff'], 30200, delta=250)
     self.assertAlmostEqual(sed.results['igrid_search']['CI']['logg'], 5.67, delta=0.1)
     self.assertAlmostEqual(sed.results['igrid_search']['CI']['ebv'], 0.0078, delta=0.02)
     self.assertAlmostEqual(sed.results['igrid_search']['CI']['teff_l'], 29337, delta=250)
     self.assertAlmostEqual(sed.results['igrid_search']['CI']['logg_l'], 5.0, delta=0.1)
     self.assertAlmostEqual(sed.results['igrid_search']['CI']['ebv_l'], 0.005, delta=0.02)
     self.assertAlmostEqual(sed.results['igrid_search']['CI']['teff_u'], 31623, delta=250)
     self.assertAlmostEqual(sed.results['igrid_search']['CI']['logg_u'], 6.0, delta=0.1)
     self.assertAlmostEqual(sed.results['igrid_search']['CI']['ebv_u'], 0.015, delta=0.02)
     
     # check that the best model is stored
     self.assertTrue('model' in sed.results['igrid_search'])
     self.assertTrue('synflux' in sed.results['igrid_search'])
     self.assertTrue('chi2' in sed.results['igrid_search'])
     self.assertEqual(len(sed.results['igrid_search']['model']), 3, msg='stored model has wrong number of collumns (should be 3)')
     self.assertEqual(len(sed.results['igrid_search']['synflux']), 3, msg='stored synflux has wrong number of collumns (should be 3)')
Esempio n. 3
0
 def testiMinimizeSingleCold(self):
     """ INTEGRATION iminimize single star (kurucz) """
     sed = builder.SED(ID='TEST', load_fits=False)
     np.random.seed(111)
     meas = self.measCold + np.random.uniform(0, 0.04, size=len(self.measCold)) * self.measCold
     emeas = meas / 100.0
     units = ['erg/s/cm2/AA' for i in meas]
     source = ['SYNTH' for i in meas]
     sed.add_photometry_fromarrays(meas, emeas, units, self.photbands, source)
     
     model.set_defaults(grid='kurucztest')
     model.copy2scratch(z='*', Rv='*')
     
     np.random.seed(111)        
     sed.iminimize(teff=6000, logg=4.0, ebv=0.007, z=-0.3, rv=2.4, vrad=0,
                   teffrange=(5000, 7000),loggrange=(3.5, 4.5),zrange=(-0.5,0.0),
                   ebvrange=(0.005, 0.015), rvrange=(2.1,3.1),vradrange=(0,0),
                   points=None,df=None,CI_limit=0.60,calc_ci=True, set_model=True)
     
     self.assertAlmostEqual(sed.results['iminimize']['CI']['teff'], 6036, delta=50)
     self.assertAlmostEqual(sed.results['iminimize']['CI']['logg'], 4.19, delta=0.1)
     self.assertAlmostEqual(sed.results['iminimize']['CI']['ebv'], 0.015, delta=0.02)
     self.assertAlmostEqual(sed.results['iminimize']['CI']['z'], -0.21, delta=0.1)
     self.assertAlmostEqual(sed.results['iminimize']['CI']['rv'], 2.1, delta=0.3)
     self.assertAlmostEqual(sed.results['iminimize']['CI']['scale'], 1, delta=0.5)
     
     self.assertAlmostEqual(sed.results['iminimize']['CI']['teff_l'], 6025, delta=50)
     self.assertAlmostEqual(sed.results['iminimize']['CI']['teff_u'], 6036, delta=50)
     self.assertAlmostEqual(sed.results['iminimize']['CI']['scale_l'], 1, delta=0.5)
     self.assertAlmostEqual(sed.results['iminimize']['CI']['scale_u'], 1, delta=0.5)
     
     self.assertEqual(sed.results['iminimize']['grid']['teffstart'][0], 6000)
     self.assertEqual(sed.results['iminimize']['grid']['loggstart'][0], 4.0)
     self.assertEqual(sed.results['iminimize']['grid']['ebvstart'][0], 0.007)
     self.assertEqual(sed.results['iminimize']['grid']['zstart'][0], -0.3)
     self.assertEqual(sed.results['iminimize']['grid']['rvstart'][0], 2.4)
     self.assertAlmostEqual(sed.results['iminimize']['grid']['chisq'][0], 3.9, delta=1)
     
     self.assertTrue('model' in sed.results['iminimize'])
     self.assertTrue('synflux' in sed.results['iminimize'])
     self.assertTrue('chi2' in sed.results['iminimize'])
     self.assertEqual(len(sed.results['iminimize']['model']), 3, msg='stored model has wrong number of collumns (should be 3)')
     self.assertEqual(len(sed.results['iminimize']['synflux']), 3, msg='stored synflux has wrong number of collumns (should be 3)')
Esempio n. 4
0
 def testiGrid_searchSingleCold(self):
     """ INTEGRATION igrid_search single star (kurucz)"""
     sed = builder.SED(ID='TEST', load_fits=False)
     np.random.seed(111)
     meas = self.measCold + np.random.uniform(0, 0.01, size=len(self.measCold)) * self.measCold
     emeas = meas / 100.0
     units = ['erg/s/cm2/AA' for i in meas]
     source = ['SYNTH' for i in meas]
     sed.add_photometry_fromarrays(meas, emeas, units, self.photbands, source)
     
     model.set_defaults(grid='kurucztest')
     model.copy2scratch(z='*', Rv='*')
     
     np.random.seed(111)
     sed.igrid_search(points=100000,teffrange=(5000, 7000),loggrange=(3.5, 4.5), 
                      ebvrange=(0.005, 0.015),zrange=(-0.5,0.0),rvrange=(2.1,3.1),
                      vradrange=(0,0),df=None,CI_limit=0.95,set_model=True)
     
     self.assertAlmostEqual(sed.results['igrid_search']['CI']['teff'], 6000, delta=50)
     self.assertAlmostEqual(sed.results['igrid_search']['CI']['logg'], 3.98, delta=0.1)
     self.assertAlmostEqual(sed.results['igrid_search']['CI']['ebv'], 0.011, delta=0.02)
     self.assertAlmostEqual(sed.results['igrid_search']['CI']['rv'], 2.13, delta=0.5)
     self.assertAlmostEqual(sed.results['igrid_search']['CI']['z'], -0.28, delta=0.1)
     self.assertAlmostEqual(sed.results['igrid_search']['CI']['teff_l'], 5949, delta=50)
     self.assertAlmostEqual(sed.results['igrid_search']['CI']['logg_l'], 3.62, delta=0.1)
     self.assertAlmostEqual(sed.results['igrid_search']['CI']['ebv_l'], 0.005, delta=0.02)
     self.assertAlmostEqual(sed.results['igrid_search']['CI']['rv_l'], 2.1, delta=0.1)
     self.assertAlmostEqual(sed.results['igrid_search']['CI']['z_l'], -0.46, delta=0.1)
     self.assertAlmostEqual(sed.results['igrid_search']['CI']['teff_u'], 6060, delta=50)
     self.assertAlmostEqual(sed.results['igrid_search']['CI']['logg_u'], 4.5, delta=0.1)
     self.assertAlmostEqual(sed.results['igrid_search']['CI']['ebv_u'], 0.015, delta=0.02)
     self.assertAlmostEqual(sed.results['igrid_search']['CI']['rv_u'], 3.1, delta=0.1)
     self.assertAlmostEqual(sed.results['igrid_search']['CI']['z_u'], -0.05, delta=0.1)
     
     # check that the best model is stored
     self.assertTrue('model' in sed.results['igrid_search'])
     self.assertTrue('synflux' in sed.results['igrid_search'])
     self.assertTrue('chi2' in sed.results['igrid_search'])
     self.assertEqual(len(sed.results['igrid_search']['model']), 3, msg='stored model has wrong number of collumns (should be 3)')
     self.assertEqual(len(sed.results['igrid_search']['synflux']), 3, msg='stored synflux has wrong number of collumns (should be 3)')
Esempio n. 5
0
 def testiMinimizeSingleHot(self):
     """ INTEGRATION iminimize single star (tmap) """
     sed = builder.SED(ID='TEST', load_fits=False)
     np.random.seed(111)
     meas = self.measHot + np.random.uniform(0, 0.04, size=len(self.measHot)) * self.measHot
     emeas = meas / 100.0
     units = ['erg/s/cm2/AA' for i in meas]
     source = ['SYNTH' for i in meas]
     sed.add_photometry_fromarrays(meas, emeas, units, self.photbands, source)
     
     model.set_defaults(grid='tmaptest')
     model.copy2scratch(z='*', Rv='*')
     
     np.random.seed(111)
     sed.iminimize(teff=27000, logg=5.1, ebv=0.01, z=0, rv=3.1, vrad=0,
                   teffrange=(25000, 35000),loggrange=(5.0, 6.0), 
                   ebvrange=(0.005, 0.015),zrange=(0,0),rvrange=(3.1,3.1),
                   vradrange=(0,0),df=None,CI_limit=0.95,set_model=False)
     
     self.assertAlmostEqual(sed.results['iminimize']['CI']['teff'], 30250, delta=100)
     self.assertAlmostEqual(sed.results['iminimize']['CI']['logg'], 5.66, delta=0.1)
     self.assertAlmostEqual(sed.results['iminimize']['CI']['ebv'], 0.008, delta=0.02)
     self.assertAlmostEqual(sed.results['iminimize']['grid']['chisq'][0], 3.8, delta=1)
Esempio n. 6
0
 def setUpClass(cls):
     if not noMock:
         sesame.search = mock.Mock(return_value={'plx':(0.0,0.0)})
     if not noIntegration:
         # ==== COLD model ====
         model.set_defaults(grid='kurucztest')
         model.copy2scratch(z='*', Rv='*')
         measCold = model.get_itable_pix(photbands=cls.photbands, teff=array([6000]), \
                             logg=array([4.0]),ebv=array([0.01]), rv=array([2.8]), z=array([-0.25]))[0][:,0]
         
         np.random.seed(111)
         cls.measCold = measCold
         
         # ==== HOT model ====
         model.set_defaults(grid='tmaptest')
         model.copy2scratch(z='*', Rv='*')
         measHot = model.get_itable_pix(photbands=cls.photbands, teff=array([30000]), \
                             logg=array([5.5]),ebv=array([0.01]), rv=3.1, z=0.0)[0][:,0]
         
         np.random.seed(111)
         cls.measHot = measHot
         
         # ==== BINARY model ====
         grid1 = dict(grid='kurucztest')
         grid2 = dict(grid='tmaptest')
         model.set_defaults_multiple(grid1,grid2)
         model.clean_scratch(z='*', Rv='*')
         model.copy2scratch(z='*', Rv='*')
         
         G, Msol, Rsol = constants.GG_cgs, constants.Msol_cgs, constants.Rsol_cgs
         masses = [0.85, 0.50]
         rad = array([np.sqrt(G*masses[0]*Msol/10**4.0)/Rsol])
         rad2 = array([np.sqrt(G*masses[1]*Msol/10**5.5)/Rsol])
         
         measBin = model.get_itable_pix(photbands=cls.photbands, teff=array([6000]), \
                             logg=array([4.0]),ebv=array([0.01]), teff2=array([30000]),
                             logg2=array([5.5]), ebv2=array([0.01]), rad=rad,
                             rad2=rad2)[0][:,0]
                             
         np.random.seed(111)
         cls.measBin = measBin
         cls.masses = masses