def getSpecNorms(self, sedfile, mag, filtstr):
     band = Bandpass()
     band.readThroughput(os.path.join(self.tpath, "total_%s.dat"%(filtstr)))
     imsimband = Bandpass()
     imsimband.imsimBandpass()
     sed = Sed()
     sed.readSED_flambda(self.spath+"/"+sedfile)
     fluxNorm = sed.calcFluxNorm(mag, band)
     sed.multiplyFluxNorm(fluxNorm)
     magNorm = sed.calcMag(imsimband)
     return magNorm, fluxNorm
 def calcLSSTMags(self, sedfile, fluxnorm):
     sed = Sed()
     sed.readSED_flambda(self.spath+"/"+sedfile)
     sed.multiplyFluxNorm(fluxnorm)
     mags = []
     for filtstr in ('u', 'g', 'r', 'i', 'z', 'y'):
         band = Bandpass()
         band.readThroughput(os.path.join(self.tpath, "total_%s.dat"%(filtstr)))
         imsimband = Bandpass()
         imsimband.imsimBandpass()
         mags.append(sed.calcMag(band))
     return mags
 def getSpecNorms(self, sedfile, mag, filtstr):
     band = Bandpass()
     band.readThroughput(
         os.path.join(self.tpath, "total_%s.dat" % (filtstr)))
     imsimband = Bandpass()
     imsimband.imsimBandpass()
     sed = Sed()
     sed.readSED_flambda(self.spath + "/" + sedfile)
     fluxNorm = sed.calcFluxNorm(mag, band)
     sed.multiplyFluxNorm(fluxNorm)
     magNorm = sed.calcMag(imsimband)
     return magNorm, fluxNorm
 def calcLSSTMags(self, sedfile, fluxnorm):
     sed = Sed()
     sed.readSED_flambda(self.spath + "/" + sedfile)
     sed.multiplyFluxNorm(fluxnorm)
     mags = []
     for filtstr in ('u', 'g', 'r', 'i', 'z', 'y'):
         band = Bandpass()
         band.readThroughput(
             os.path.join(self.tpath, "total_%s.dat" % (filtstr)))
         imsimband = Bandpass()
         imsimband.imsimBandpass()
         mags.append(sed.calcMag(band))
     return mags
Example #5
0
 def mkGalPhot(self):
     ifh = open(self.mfile)
     lnum = 0
     k = None
     for l in ifh:
         flds = l.rstrip().split()
         if l.startswith("Opsim_filter"):
             self.filter = self.filtmap[int(flds[1])]
             k = self.filter
     ifh.close()
     ifh = open(self.tfile)
     for l in ifh:
         flds = l.rstrip().split()
         if not flds[0] == "object":
             continue
         otype = flds[12]
         if otype != "sersic2D":
             continue
         id = float(flds[1])
         if not self.centdata.has_key(id):
             continue
         magNorm = float(flds[4])
         spec = flds[5]
         redshift = float(flds[6])
         ind = float(flds[16])
         mwav = float(flds[21])
         av = float(flds[18])
         sed = Sed()
         sed.readSED_flambda(self.spath+"/"+spec)
         a_int, b_int = sed.setupCCMab()
         self.outdata['id'].append(id)
         if lnum > self.donum and self.donum is not None:
             break
         if lnum%10000 == 0:
             print id
         fluxNorm = sed.calcFluxNorm(magNorm, self.imsimband)
         sed.multiplyFluxNorm(fluxNorm/(1+redshift))
         sed.addCCMDust(a_int, b_int, A_v=av)
         sed.redshiftSED(redshift, dimming=False)
         a_mw, b_mw = sed.setupCCMab()
         sed.addCCMDust(a_mw, b_mw, A_v=mwav)
         line = {'flux':None, 'mag':None}
         mag = sed.calcMag(self.bands[k])
         flux = sed.calcADU(self.bands[k], gain=1.0)
         line['mag'] = mag
         line['flux'] = flux
         self.outdata[k].append(line)
         lnum += 1
     ifh.close()
 def calcAbsMag(self, mag, D_L, spec, redshift, filter='i'):
   """Calculate an absolute magnitude given a filter, luminosity distance,
   apparent magnitude, sed, and redshift
   """
   #Get default locations for filters and seds
   #Set up filters and sed
   imsimband = Bandpass()
   imsimband.imsimBandpass()
   sed = Sed()
   sed.readSED_flambda(os.path.join(self.spath,spec))
   #Calculate rest frame magnitude
   magr = sed.calcMag(self.bands[filter])
   #redshift spectrum
   sed.redshiftSED(redshift, dimming=False)
   #calculate observed frame magnitude
   mago = sed.calcMag(self.bands[filter])
   #SED portion of the K-correction
   Kcorr = mago-magr
   #Cosmological portion of the K-correction due to the dilation of the
   #filter
   Kcorrz = 2.5*numpy.log10(1+redshift)
   #D_L is in Mpc so the normal relation goes 5.(log(D_L) +6.-1.)
   absMag = mag - (5.*(numpy.log10(D_L) + 5.)) - Kcorr - Kcorrz
   return absMag
 def calcAbsMag(self, mag, D_L, spec, redshift, filter='i'):
     """Calculate an absolute magnitude given a filter, luminosity distance,
 apparent magnitude, sed, and redshift
 """
     #Get default locations for filters and seds
     #Set up filters and sed
     imsimband = Bandpass()
     imsimband.imsimBandpass()
     sed = Sed()
     sed.readSED_flambda(os.path.join(self.spath, spec))
     #Calculate rest frame magnitude
     magr = sed.calcMag(self.bands[filter])
     #redshift spectrum
     sed.redshiftSED(redshift, dimming=False)
     #calculate observed frame magnitude
     mago = sed.calcMag(self.bands[filter])
     #SED portion of the K-correction
     Kcorr = mago - magr
     #Cosmological portion of the K-correction due to the dilation of the
     #filter
     Kcorrz = 2.5 * numpy.log10(1 + redshift)
     #D_L is in Mpc so the normal relation goes 5.(log(D_L) +6.-1.)
     absMag = mag - (5. * (numpy.log10(D_L) + 5.)) - Kcorr - Kcorrz
     return absMag
Example #8
0
 def mkStarPhot(self):
     ifh = open(self.mfile)
     lnum = 0
     k = None
     for l in ifh:
         flds = l.rstrip().split()
         if l.startswith("Opsim_filter"):
             self.filter = self.filtmap[int(flds[1])]
             k = self.filter
     ifh.close()
     ifh = open(self.tfile)
     for l in ifh:
         flds = l.rstrip().split()
         if not flds[0] == "object":
             continue
         otype = flds[12]
         if otype != "point":
             continue
         id = float(flds[1])
         if not self.centdata.has_key(id):
             continue
         magNorm = float(flds[4])
         spec = flds[5]
         av = float(flds[14])
         sed = Sed()
         self.outdata['id'].append(id)
         if re.search("kurucz", spec):
           sed.readSED_flambda(self.spath+"/"+spec)
         else:
           sed.readSED_flambda(self.spath+"/"+spec)
         fluxNorm = sed.calcFluxNorm(magNorm, self.imsimband)
         sed.multiplyFluxNorm(fluxNorm)
         a, b = sed.setupCCMab()
         sed.addCCMDust(a, b, A_v=av)
         line = {'flux':None, 'mag':None}
         mag = sed.calcMag(self.bands[k])
         flux = sed.calcADU(self.bands[k], gain=1.)
         line['mag'] = mag
         line['flux'] = flux
         self.outdata[k].append(line)
         lnum += 1
     ifh.close()