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
示例#3
0
 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
示例#4
0
 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 calcMagNorm(self, spec, mag, redshift, filter='i'):
   """Calculate the SED normalization given a spectrum, redshift, and
   reference magnitude.  ***This assumes not host redenning.***
   """
   #Setup the filters
   imsimband = Bandpass()
   imsimband.imsimBandpass()
   #setup the sed
   sed = Sed()
   sed.readSED_flambda(os.path.join(self.spath,spec))
   #need the rest frame spectrum for calculating the mag norm since
   #the normalization is applied in the rest frame
   sed_orig = deepcopy(sed)
   #Redshift the spectrum
   sed.redshiftSED(redshift, dimming=True)
   #Calculate the normalization using the reference magnitude
   fluxNorm = sed.calcFluxNorm(mag, self.bands[filter])
   sed_orig.multiplyFluxNorm(fluxNorm)
   #Calculate the normalization in units of magnitudes
   magNorm = sed_orig.calcMag(imsimband)
   return magNorm, fluxNorm
 def calcMagNorm(self, spec, mag, redshift, filter='i'):
     """Calculate the SED normalization given a spectrum, redshift, and
 reference magnitude.  ***This assumes not host redenning.***
 """
     #Setup the filters
     imsimband = Bandpass()
     imsimband.imsimBandpass()
     #setup the sed
     sed = Sed()
     sed.readSED_flambda(os.path.join(self.spath, spec))
     #need the rest frame spectrum for calculating the mag norm since
     #the normalization is applied in the rest frame
     sed_orig = deepcopy(sed)
     #Redshift the spectrum
     sed.redshiftSED(redshift, dimming=True)
     #Calculate the normalization using the reference magnitude
     fluxNorm = sed.calcFluxNorm(mag, self.bands[filter])
     sed_orig.multiplyFluxNorm(fluxNorm)
     #Calculate the normalization in units of magnitudes
     magNorm = sed_orig.calcMag(imsimband)
     return magNorm, fluxNorm
 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
示例#9
0
class testPhotTrim (object):
    def __init__(self, metafile, trimfilename, centfilename, outfile, donum = None):
        self.datadir = os.environ.get("SIMS_DATA_DIR")

        self.tpath = os.getenv('LSST_THROUGHPUTS_DEFAULT')
        self.spath = os.getenv('SIMS_SED_LIBRARY_DIR')
        self.bands = {"u":None, "g":None, "r":None, "i":None, "z":None, "y":None}
        keys = self.bands.keys()
        for k in keys:
            self.bands[k] = Bandpass()
            self.bands[k].readThroughput(os.path.join(self.tpath, "total_%s.dat"%k))
        self.imsimband = Bandpass()
        self.imsimband.imsimBandpass()
        self.mfile = metafile
        self.tfile = trimfilename
        self.ofile = outfile
        self.outdata = {'id':[],'u':[], 'g':[], 'r':[], 'i':[], 'z':[],
                'y':[]}
        self.centdata = self.readCentroid(centfilename)
        self.filtmap = {0:'u', 1:'g', 2:'r', 3:'i', 4:'z', 5:'y'}
        self.filter = None
        self.donum = donum

    def readCentroid(self,file):
        ifh = open(file)
        data = {}
        for l in ifh:
            flds = l.rstrip().split()
            if flds[0].startswith("Source") or int(flds[1]) == 0:
                continue
            data[float(flds[0])] = {'photons':int(flds[1]), 'x':float(flds[2]), 'y':float(flds[3])}
        return data

    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 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()

    def printComp(self):
        ofh = open(self.ofile, "w")
        for id, mag in zip(self.outdata['id'], self.outdata[self.filter]):
            if self.centdata.has_key(id):
                line = (id,mag['mag'],mag['flux'],self.centdata[id]['photons'])
                ofh.write(",".join([str(el) for el in line])+"\n")
        ofh.close()
示例#10
0
import os
import numpy
import selfcal.analyze.useful_input as ui
import lsst.sims.catalogs.measures.photometry.Sed as Sed
import lsst.sims.catalogs.measures.photometry.Bandpass as Bandpass

# filter id table:
filterlist = ('u', 'g', 'r', 'i', 'z', 'y')
filterdict = {'u':0, 'g':1, 'r':2, 'i':3, 'z':4, 'y':5}
rootdir = os.getenv("LSST_THROUGHPUTS_BASELINE")
lsst = {}
for f in filterlist:
    lsst[f] = Bandpass()
    lsst[f].readThroughput(rootdir + "/total_" + f + ".dat")
imsimband = Bandpass()
imsimband.imsimBandpass()

# set up colors of objects in all bandpasses
rootdir_sed = "."
sedlist = ('S.dat', 'C.dat')
simobjs = {}
simmags = {}
for sed in sedlist:
    simobjs[sed] = Sed()
    simobjs[sed].readSED_flambda(rootdir_sed + sed)
    simmags[sed] = {}
    for filter in filterlist:
        simmags[sed][filter] = simobjs[sed].calcMag(lsst[filter])
    simmags[sed]['ims'] = simobjs[sed].calcMag(imsimband)
    
示例#11
0
import os
import numpy
import selfcal.analyze.useful_input as ui
import lsst.sims.catalogs.measures.photometry.Sed as Sed
import lsst.sims.catalogs.measures.photometry.Bandpass as Bandpass

# filter id table:
filterlist = ('u', 'g', 'r', 'i', 'z', 'y')
filterdict = {'u': 0, 'g': 1, 'r': 2, 'i': 3, 'z': 4, 'y': 5}
rootdir = os.getenv("LSST_THROUGHPUTS_BASELINE")
lsst = {}
for f in filterlist:
    lsst[f] = Bandpass()
    lsst[f].readThroughput(rootdir + "/total_" + f + ".dat")
imsimband = Bandpass()
imsimband.imsimBandpass()

# set up colors of objects in all bandpasses
rootdir_sed = "."
sedlist = ('S.dat', 'C.dat')
simobjs = {}
simmags = {}
for sed in sedlist:
    simobjs[sed] = Sed()
    simobjs[sed].readSED_flambda(rootdir_sed + sed)
    simmags[sed] = {}
    for filter in filterlist:
        simmags[sed][filter] = simobjs[sed].calcMag(lsst[filter])
    simmags[sed]['ims'] = simobjs[sed].calcMag(imsimband)

# open and read file containing obshistids (key to catalog and to opsim)