def testEBV(self): ebvObject = EBVbase() ra = [] dec = [] gLat = [] gLon = [] for i in range(10): ra.append(i*2.0*np.pi/10.0) dec.append(i*np.pi/10.0) gLat.append(-0.5*np.pi+i*np.pi/10.0) gLon.append(i*2.0*np.pi/10.0) equatorialCoordinates = np.array([ra, dec]) galacticCoordinates = np.array([gLon, gLat]) ebvOutput = ebvObject.calculateEbv(equatorialCoordinates=equatorialCoordinates) self.assertEqual(len(ebvOutput), len(ra)) ebvOutput = ebvObject.calculateEbv(galacticCoordinates=galacticCoordinates) self.assertEqual(len(ebvOutput), len(gLon)) self.assertGreater(len(ebvOutput), 0) self.assertRaises(RuntimeError, ebvObject.calculateEbv, equatorialCoordinates=equatorialCoordinates, galacticCoordinates=galacticCoordinates) self.assertRaises(RuntimeError, ebvObject.calculateEbv, equatorialCoordinates=None, galacticCoordinates=None) self.assertRaises(RuntimeError, ebvObject.calculateEbv)
def run_observation(self, dataSlice, slicePoint=None): #dataSlice = dataSlice[np.where(dataSlice[self.fieldID]==self.fieldID_ref)] self.fieldID_ref = dataSlice[self.fieldID][0] print 'Processing', self.fieldID_ref, len(dataSlice[self.fieldID]) if len(dataSlice) > 0: dataSlice.sort(order=self.mjdCol) #print 'hello',dataSlice[self.fieldRA],len(dataSlice[self.fieldRA]),set(dataSlice[self.fieldRA]),len(set(dataSlice[self.fieldRA])) ra_field = list(set(dataSlice[self.fieldRA]))[0] dec_field = list(set(dataSlice[self.fieldDec]))[0] lsstmwebv = EBVbase() ebvofMW = lsstmwebv.calculateEbv( equatorialCoordinates=np.array([[ra_field], [dec_field]]))[0] dictout = {} dictout['ebvofMW'] = ebvofMW dictout['dataSlice'] = dataSlice outdir = self.outputdir.replace('Sim', 'Obs') #name_for_pkl=outdir+'/Observations_'+self.fieldName+'_'+str(int(self.fieldID_ref))+'_'+str(ra_field)+'_'+str(dec_field) name_for_pkl = outdir + '/Observations_' + self.fieldName + '_' + str( int(self.fieldID_ref)) pkl_file = open(name_for_pkl + '.pkl', 'wb') pkl.dump(dictout, pkl_file) pkl_file.close() """
def model_for_fit(self): #print 'there man, to fit' dust = sncosmo.OD94Dust() self.fit_model = 'salt2-extended' self.fit_version = '1.0' source = sncosmo.get_source(self.fit_model, version=self.fit_version) self.SN_fit_model = sncosmo.Model(source=source, effects=[dust, dust], effect_names=['host', 'mw'], effect_frames=['rest', 'obs']) self.SN_fit_model.set(z=self.z) self.SN_fit_model.set_source_peakabsmag(self.peakAbsMagBesselB, 'bessellB', 'vega', cosmo=cosmology.WMAP9) self.lsstmwebv = EBVbase() self.ebvofMW = self.lsstmwebv.calculateEbv( equatorialCoordinates=np.array([[np.radians(self.radeg)], [np.radians(self.decdeg)]]))[0] self.SN_fit_model.set(mwebv=self.ebvofMW) self.SN_fit_model.set(mwebv=0.)
def __init__(self, ra, dec, z, t0, c=0, x1=0, peakAbsMagBesselB=-19.0906, model='salt2-extended', version='1.0', sn_type='Ia', mwdust=True): self.radeg = ra self.decdeg = dec self.z = z self.t0 = t0 self.c = c self.x1 = x1 self.peakAbsMagBesselB = peakAbsMagBesselB self.model = model self.version = version self.sn_type = sn_type self.id_SED = '' self.cosmology = cosmology.WMAP9 self.cosmology = FlatLambdaCDM(H0=70, Om0=0.25) astropy_cosmo = FlatLambdaCDM(H0=self.cosmology.H0, Om0=self.cosmology.Om0) self.lumidist = astropy_cosmo.luminosity_distance(self.z).value * 1.e6 #print 'SN Lumidist',self.lumidist,self.cosmology.H0,self.cosmology.Om0 #print 'sntype',self.sn_type dust = sncosmo.OD94Dust() self.lsstmwebv = EBVbase() self.ebvofMW = self.lsstmwebv.calculateEbv( equatorialCoordinates=np.array([[np.radians(self.radeg)], [np.radians(self.decdeg)]]))[0] if self.sn_type == 'Ia': if version == '': source = sncosmo.get_source(self.model) else: source = sncosmo.get_source(self.model, version=self.version) self.SN = sncosmo.Model(source=source, effects=[dust, dust], effect_names=['host', 'mw'], effect_frames=['rest', 'obs']) #self.SN=sncosmo.Model(source=self.source) #self.SN=sncosmo.Model(source=self.source) #print 'blabla',self.SN.minwave(),self.SN.maxwave() lowrange = -30. highrange = 50. self.SN.set(z=self.z) self.SN.set(t0=self.t0) self.SN.set(c=self.c) self.SN.set(x1=self.x1) self.SN.set_source_peakabsmag(self.peakAbsMagBesselB, 'bessellB', 'vega', cosmo=self.cosmology) #self.SN.set(mwebv=self.ebvofMW) #self.SN.set(mwebv=0.) else: self.Fill_nonIa_ID() resu = self.Get_nonIa_Template_ID() #id_SED='SDSS-018109' #id_SED='SDSS-018457' """ if id_SED != None: self.id_SED=id_SED print 'tagged',self.id_SED #self.SED_all_phases=self.Load_SED('NON1A/'+id_SED+'.SED') phase, wave, values = read_griddata_ascii('NON1A/'+id_SED+'.SED') print 'min max',np.min(wave),np.max(wave) self.SED_template = Spline2d(phase, wave, values, kx=2, ky=2) """ self.model = thename = resu[0] self.version = resu[1] #print 'the choice',resu[0],resu[1] """ thename='snana-2007kw' theversion='1.0' """ if thename != None: #print 'Getting the source' source = sncosmo.get_source(self.model, self.version) #print 'Getting the model' self.SN = sncosmo.Model(source=source, effects=[dust, dust], effect_names=['host', 'mw'], effect_frames=['rest', 'obs']) #print 'Setting z and T0' self.SN.set(z=self.z) self.SN.set(t0=self.t0) #print 'SN here',self.z,self.t0,thename,theversion self.SN.set_source_peakabsmag(-18., 'bessellB', 'vega', cosmo=self.cosmology) #MW extinction if mwdust: self.SN.set(mwebv=self.ebvofMW) self.SN.set(mwebv=0.) self.model_for_fit()
def __init__(self, parameters, fit=False, model='salt2-extended', version='1.0', telescope=None, ra=6.0979440, dec=-1.1051600, airmass=1.2, X0=None, dL=None): #time_begin=time.time() self.lc = [] self.m5 = { 'u': 23.61, 'g': 24.83, 'r': 24.35, 'i': 23.88, 'z': 23.30, 'y': 22.43 } self.radeg = np.rad2deg(ra) self.decdeg = np.rad2deg(dec) self.model = model self.version = version self.peakAbsMagBesselB = -19.0906 if self.model == 'salt2-extended': model_min = 300. model_max = 180000. wave_min = 3000. wave_max = 11501. if self.model == 'salt2': model_min = 3400. model_max = 11501. wave_min = model_min wave_max = model_max self.wave = np.arange(wave_min, wave_max, 1.) self.sn_type = 'Ia' source = sncosmo.get_source(self.model, version=self.version) #self.mycosmology=FlatLambdaCDM(H0=70, Om0=0.25) #astropy_cosmo=FlatLambdaCDM(H0= self.mycosmology.H0, Om0=self.mycosmology.Om0) dust = sncosmo.OD94Dust() #self.transmission=Throughputs(through_dir='FAKE_THROUGH',atmos_dir='FAKE_THROUGH',atmos=False,aerosol=False) self.transmission = telescope.throughputs #self.transmission.Load_Atmosphere(airmass) #print 'total elapse time init a',time.time()-time_begin self.telescope = telescope """ for band in self.bands: themax=np.max(self.transmission.lsst_system[band].sb) idx = self.transmission.lsst_system[band].sb >= 0.2*themax sel=self.transmission.lsst_system[band].wavelen[idx] print band,np.min(sel),np.max(sel) """ """ self.airmass=airmass if self.airmass > 0: self.transmission.Load_Atmosphere(airmass) """ #self.lc={} #print 'there we go',parameters,len(parameters),parameters.dtype self.param = parameters """ SN=sncosmo.Model(source=source,effects=[dust, dust], effect_names=['host', 'mw'], effect_frames=['rest', 'obs']) """ self.SN = sncosmo.Model(source=source) self.z = self.param['z'] if X0 is None: self.Cosmology() lumidist = self.astropy_cosmo.luminosity_distance( self.param['z']).value * 1.e3 self.dL = lumidist #X0_snsim = self.X0_norm_snsim() / lumidist** 2 X0 = self.X0_norm() / lumidist**2 #print 'before alpha beta',X0 alpha = 0.13 beta = 3. X0 *= np.power( 10., 0.4 * (alpha * self.param['X1'] - beta * self.param['Color'])) self.X0 = X0 else: self.X0 = X0 self.dL = dL #print 'llla',X0,alpha,beta,param['X1'],param['Color'],param['z'],lumidist #self.X0=X0 #print 'hello x0',X0,lumidist #SN=sncosmo.Model(source=source) self.SN.set(z=self.param['z']) self.SN.set(t0=self.param['DayMax']) self.SN.set(c=self.param['Color']) self.SN.set(x1=self.param['X1']) self.SN.set(x0=self.X0) #print 'total elapse time init b',time.time()-time_begin #self.SED={} #print 'sncosmo parameters',self.SN.param_names,self.SN.parameters lsstmwebv = EBVbase() ebvofMW = lsstmwebv.calculateEbv(equatorialCoordinates=np.array( [[np.radians(self.radeg)], [np.radians(self.decdeg)]]))[0] #self.SN.set(mwebv=ebvofMW) #self.SN.set_source_peakabsmag(self.peakAbsMagBesselB, 'bessellB', 'vega',cosmo=self.astropy_cosmo) if self.sn_type == 'Ia': self.mbsim = self.SN._source.peakmag('bessellb', 'vega')
def __init__(self, ra=None, dec=None, source='salt2-extended'): """ Instantiate object Parameters ---------- ra : float ra of the SN in degrees dec : float dec of the SN in degrees source : instance of `sncosmo.SALT2Source`, optional, defaults to using salt2-extended source class to define the model """ dust = sncosmo.OD94Dust() sncosmo.Model.__init__(self, source=source, effects=[dust, dust], effect_names=['host', 'mw'], effect_frames=['rest', 'obs']) # Current implementation of Model has a default value of mwebv = 0. # ie. no extinction, but this is not part of the API, so should not # depend on it, set explicitly in order to unextincted SED from # SNCosmo. We will use catsim extinction from `lsst.sims.photUtils`. self.ModelSource = source self.set(mwebv=0.) # self._ra, self._dec is initialized as None for cases where ra, dec # is not provided self._ra = None self._dec = None # ra, dec is input in degrees # If provided, set _ra, _dec in radians self._hascoords = True if dec is None: self._hascoords = False if ra is None: self._hascoords = False # Satisfied that coordinates provided are floats if self._hascoords: self.setCoords(ra, dec) # For values of ra, dec, the E(B-V) is calculated directly # from DustMaps self.lsstmwebv = EBVbase() self.ebvofMW = None if self._hascoords: self.mwEBVfromMaps() # Behavior of model outside temporal range : # if 'zero' then all fluxes outside the temporal range of the model # are set to 0. self._modelOutSideTemporalRange = 'zero' # SED will be rectified to 0. for negative values of SED if this # attribute is set to True self.rectifySED = True return
if pass_event: dust = sncosmo.OD94Dust() SN = sncosmo.Model(source='salt2-extended', effects=[dust, dust], effect_names=['host', 'mw'], effect_frames=['rest', 'obs']) SN.set(z=obj['z']) SN.set(t0=obj['t0']) SN.set(c=obj['c']) SN.set(x1=obj['x1']) SN.set_source_peakabsmag(-19.3, 'bessellB', 'vega', cosmo=cosmology.WMAP9) lsstmwebv = EBVbase() ebvofMW = lsstmwebv.calculateEbv( equatorialCoordinates=np.array( [[obj['ra']], [obj['dec']]]))[0] print 'hello', obj['ra'], obj['dec'], ebvofMW SN.set(mwebv=ebvofMW) print 'simulated', obj['z'], obj['t0'], obj[ 'c'], obj['x1'] resb, fitted_modelb = sncosmo.fit_lc( dict_tag['table_for_fit'], SN, ['z', 't0', 'x0', 'x1', 'c'], bounds={ 'z': (obj['z'] - 0.01, obj['z'] + 0.01) }) sncosmo.plot_lc(dict_tag['table_for_fit'], model=fitted_modelb,