def uncMagCalc(redshift, tempGalwav, tempGalfla, multiFlux=None, finish=None): tempName = Sed(wavelen=tempGalwav, flambda=tempGalfla) if multiFlux is not None: tempName.multiplyFluxNorm(multiFlux) if finish is not None: tempName.redshiftSED(redshift, dimming=True) tempName.resampleSED(wavelen_min=300, wavelen_max=1200, wavelen_step=wavelen_step) tempName.flambdaTofnu() return tempName
def __init__(self, file, posfile): self.keymap = ['u', 'g', 'r', 'i', 'z', 'y'] self.indmap = {'0':'u', '1':'g', '2':'r', '3':'i', '4':'z', '5':'y'} #Read the data file. This will presumably need to be specific to the data #Set paths to default throughputs and seds self.tpath = os.getenv('LSST_THROUGHPUTS_DEFAULT') self.spath = os.getenv('SIMS_SED_LIBRARY_DIR') self.bands = {} for k in self.keymap: self.bands[k] = Bandpass() self.bands[k].readThroughput(os.path.join(self.tpath, "total_%s.dat"%k)) sed = Sed() (self.phiarr, self.wavelen_step) = sed.setupPhiArray(self.mapFiltDictToArr(self.bands)) self.centpos = self.readPositionFile(posfile) (self.lensData, self.imgData) = self.readFile(file)
def read_mlt(): # read mlt stars - only keep 'm's # find the filenames and mark 'm', 'l', 't' stars separately homedir = os.getenv("HOME") mltdir = os.path.join(homedir, "seds/mlt") allfilelist = os.listdir(mltdir) mltlist = [] mlist = [] llist = [] tlist = [] for filename in allfilelist: if filename.endswith('.dat') & filename.startswith('m'): mlist.append(filename) elif filename.endswith('.dat') & filename.startswith('L'): llist.append(filename) elif filename.startswith('burrows'): tlist.append(filename) mltlist = mlist # + llist + tlist # read the mlt seds from disk mlts = {} for s in mltlist: mlts[s] = Sed() mlts[s].readSED_flambda(os.path.join(mltdir, s)) print "# Read %d mlt stars from %s" % (len(mltlist), mltdir) # resample onto the standard bandpass for Bandpass obj's and calculate fnu to speed later calculations for s in mltlist: mlts[s].synchronizeSED(wavelen_min=WMIN, wavelen_max=WMAX, wavelen_step=WSTEP) return mlts, mltlist, mlist, llist, tlist
def read_galaxies(): # read sn spectra and redshift homedir = os.getenv("HOME") galdir = os.path.join(homedir, "seds/galaxies") allfilelist = os.listdir(galdir) gallist_base = [] metal = ['002Z', '04Z', '25Z'] gtype = ['Const', 'Inst', 'Burst', 'Exp'] redshifts = numpy.arange(0, 1.7, 0.3) # pull out the filenames we want for filename in allfilelist: if filename.endswith('.spec'): tmp = filename.split('.') metallicity = tmp[2] galaxytype = tmp[0] if (metallicity in metal) & (galaxytype in gtype): gallist_base.append(filename) # read base SEDs for these galaxies gals_base = {} for g in gallist_base: gals_base[g] = Sed() gals_base[g].readSED_flambda(os.path.join(galdir, g)) # and redshift gals = {} gallist = [] for g in gallist_base: for z in redshifts: gal_name = "%s_%.1f" % (g, z) wavelen, flambda = gals_base[g].redshiftSED( z, wavelen=gals_base[g].wavelen, flambda=gals_base[g].flambda) gals[gal_name] = Sed(wavelen=wavelen, flambda=flambda) gallist.append(gal_name) print "# Generated %d galaxies at redshifts between %f and %f" % ( len(gallist), redshifts.min(), redshifts.max()) # resample onto the standard bandpass for Bandpass obj's and calculate fnu to speed later calculations for g in gallist: gals[g].synchronizeSED(wavelen_min=WMIN, wavelen_max=WMAX, wavelen_step=WSTEP) # add dust ax, bx = gals[gallist[0]].setupCCMab() for g in gallist: gals[g].addCCMDust(ax, bx, A_v=0.02) return gals, gallist, redshifts
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 read_sn(): # read sn spectra and redshift homedir = os.getenv("HOME") sndir = os.path.join(homedir, "seds/sn") allfilelist = os.listdir(sndir) snlist = [] days = ['0', '20', '40'] #redshifts = [0, 0.1, 0.2, 0.3, 0.5, 0.8, 1.0, 1.3, 1.6, 1.9, 2.2, 2.5] #redshifts = numpy.array(redshifts) redshifts = numpy.arange(0, 1.0, 0.1) # pull out the filenames we want for filename in allfilelist: if filename.endswith('.dat') & filename.startswith('sn1a_'): #snlist.append(filename) tmp = filename.split('_') day = tmp[1].split('.')[0] if day in days: snlist.append(filename) # read base SEDs for these days sns_base = {} for r in zip(snlist, days): day = r[1] sns_base[day] = Sed() sns_base[day].readSED_flambda(os.path.join(sndir, r[0])) # and redshift sns = {} snlist = [] for d in days: for z in redshifts: sn_name = "%d_%.1f" % (int(d), z) wavelen, flambda = sns_base[d].redshiftSED( z, wavelen=sns_base[d].wavelen, flambda=sns_base[d].flambda) sns[sn_name] = Sed(wavelen=wavelen, flambda=flambda) snlist.append(sn_name) print "# Generated %d sn's at redshifts between %f and %f on days %s" % ( len(snlist), redshifts.min(), redshifts.max(), days) # resample onto the standard bandpass for Bandpass obj's and calculate fnu to speed later calculations for s in snlist: sns[s].synchronizeSED(wavelen_min=WMIN, wavelen_max=WMAX, wavelen_step=WSTEP) return sns, snlist, days, redshifts
def read_quasar(): # read quasar spectra and redshift homedir = os.getenv("HOME") quasardir = os.path.join(homedir, "seds/quasar") # read zero redshift quasar base = Sed() base.readSED_flambda(os.path.join(quasardir, "quasar.dat")) # redshift #redshifts = [0, 0.1, 0.2, 0.3, 0.5, 0.8, 1.0, 1.3, 1.6, 1.9, 2.2, 2.5] #redshifts = numpy.array(redshifts) redshifts= numpy.arange(0, 2.8, 0.1) quasars = {} for z in redshifts: wavelen, flambda = base.redshiftSED(z, wavelen=base.wavelen, flambda=base.flambda) quasars[z] = Sed(wavelen=wavelen, flambda=flambda) print "# Generated %d quasars at redshifts between %f and %f" %(len(redshifts), redshifts.min(), redshifts.max()) # resample onto the standard bandpass for Bandpass obj's and calculate fnu to speed later calculations for z in redshifts: quasars[z].synchronizeSED(wavelen_min=WMIN, wavelen_max=WMAX, wavelen_step=WSTEP) return quasars, redshifts
def read_seds(total): # read SEDs - one blue star, one red star stars = {} homedir = os.getenv("HOME") seddir = os.path.join(homedir, 'seds/kurucz_r') key = "red" stars[key] = Sed() stars[key].readSED_flambda(os.path.join(seddir, "km01_6000.fits_g40")) normmag = 20 fluxnorm = stars[key].calcFluxNorm(normmag, total['standard']['r']) stars[key].multiplyFluxNorm(fluxnorm) stars[key].flambdaTofnu() key = "blue" stars[key] = Sed() stars[key].readSED_flambda(os.path.join(seddir, "kp02_35000.fits_g40")) normmag = 20 fluxnorm = stars[key].calcFluxNorm(normmag, total['standard']['r']) stars[key].multiplyFluxNorm(fluxnorm) stars[key].flambdaTofnu() return stars
def read_quasar(): # read quasar spectra and redshift homedir = os.getenv("HOME") quasardir = os.path.join(homedir, "seds/quasar") # read zero redshift quasar base = Sed() base.readSED_flambda(os.path.join(quasardir, "quasar.dat")) # redshift #redshifts = [0, 0.1, 0.2, 0.3, 0.5, 0.8, 1.0, 1.3, 1.6, 1.9, 2.2, 2.5] #redshifts = numpy.array(redshifts) redshifts = numpy.arange(0, 2.8, 0.1) quasars = {} for z in redshifts: wavelen, flambda = base.redshiftSED(z, wavelen=base.wavelen, flambda=base.flambda) quasars[z] = Sed(wavelen=wavelen, flambda=flambda) print "# Generated %d quasars at redshifts between %f and %f" % ( len(redshifts), redshifts.min(), redshifts.max()) # resample onto the standard bandpass for Bandpass obj's and calculate fnu to speed later calculations for z in redshifts: quasars[z].synchronizeSED(wavelen_min=WMIN, wavelen_max=WMAX, wavelen_step=WSTEP) return quasars, redshifts
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 doit(args): sed = args if sed.startswith("bergeron"): pref = "wDs" suff = ".gz" elif sed.startswith("k"): pref = "kurucz" suff = ".gz" elif sed.startswith("burrows") or sed.startswith("L") or sed.startswith("l") or sed.startswith("m"): pref = "mlt" suff = ".gz" star = Sed() star.readSED_flambda(os.path.join(catDir, "SEDs/starSED/%s/%s%s" % (pref, sed, suff))) star.flambdaTofnu() # Resample array elements wavelen = star.wavelen fnu = star.fnu wavelenu, fnuu = star.resampleSED(wavelen, fnu, wavelen_match=uBand.wavelen) waveleng, fnug = star.resampleSED(wavelen, fnu, wavelen_match=gBand.wavelen) wavelenr, fnur = star.resampleSED(wavelen, fnu, wavelen_match=rBand.wavelen) waveleni, fnui = star.resampleSED(wavelen, fnu, wavelen_match=iBand.wavelen) wavelenz, fnuz = star.resampleSED(wavelen, fnu, wavelen_match=zBand.wavelen) fluxu = fnuu * uBand.phi fluxg = fnug * gBand.phi fluxr = fnur * rBand.phi fluxi = fnui * iBand.phi fluxz = fnuz * zBand.phi fluxes = [fluxu, fluxg, fluxr, fluxi, fluxz] nflux = 5 colors = [] for i in range(5): for j in range(i+1, 5): color = -2.5 * np.log10( np.sum(fluxes[i]) / np.sum(fluxes[j]) ) colors.append(color) refrac = [] for zd in zds: # Find R ru = getOffset(wavelenu, fluxu, zd) rg = getOffset(waveleng, fluxg, zd) rr = getOffset(wavelenr, fluxr, zd) ri = getOffset(waveleni, fluxi, zd) rz = getOffset(wavelenz, fluxz, zd) refrac.append((zd, ru, rg, rr, ri, rz)) return sed, colors, refrac
def read_stars(): # read MS, g40 stars SEDs stars = {} homedir = os.getenv("HOME") stardir = os.path.join(homedir, "seds/kurucz_r") allfilelist = os.listdir(stardir) starlist = [] for filename in allfilelist: if filename[-3:] == 'g40': starlist.append(filename) stars = {} for s in starlist: stars[s] = Sed() stars[s].readSED_flambda(os.path.join(stardir, s)) print "#Read %d stars from %s" % (len(starlist), stardir) atemperature = [] amet = [] starlist2 = [] for s in starlist: tmp = s.split('_') met = float(tmp[0][2:]) if tmp[0][1] == 'm': met = -1 * met met = met / 10.0 temperature = float(tmp[1][:5]) if (temperature > 5000.0): amet.append(met) atemperature.append(temperature) starlist2.append(s) temperature = numpy.array(atemperature) met = numpy.array(amet) starlist = starlist2 stars = {} for s in starlist: stars[s] = Sed() stars[s].readSED_flambda(os.path.join(stardir, s)) print "#Kept %d stars from %s" % (len(starlist), stardir) return stars, starlist, temperature, met
def read_whitedwarf(): # read white dwarf bergeron models homedir = os.getenv("HOME") whitedwarfdir = os.path.join(homedir, "seds/white_dwarfs_r") # get the H dwarfs Hdir = os.path.join(whitedwarfdir, "H") allfilelist = os.listdir(Hdir) hlist = [] temperatures = [] loggs = [] for filename in allfilelist: if filename.startswith('bergeron'): tmp = filename.split('_') temperature = float(tmp[1]) logg = float(tmp[2].split('.')[0]) logg = logg / 10.0 if (logg > 7.0) & (temperature > 5000): hlist.append(filename) temperatures.append(temperature) loggs.append(logg) Hedir = os.path.join(whitedwarfdir, "He") allfilelist = os.listdir(Hedir) helist = [] for filename in allfilelist: if filename.startswith('bergeron_He'): tmp = filename.split('_') temperature = float(tmp[2]) logg = float(tmp[3].split('.')[0]) logg = logg / 10.0 if (logg > 7.0) & (temperature > 5000): helist.append(filename) temperatures.append(temperature) loggs.append(logg) temperatures = numpy.array(temperatures) loggs = numpy.array(loggs) wdlist = hlist + helist wds = {} for w in wdlist: wds[w] = Sed() if w in hlist: wds[w].readSED_flambda(os.path.join(Hdir, w)) if w in helist: wds[w].readSED_flambda(os.path.join(Hedir, w)) # synchronize seds for faster mag calcs later for w in wdlist: wds[w].synchronizeSED(wavelen_min=WMIN, wavelen_max=WMAX, wavelen_step=WSTEP) return wds, wdlist, hlist, helist, temperatures, loggs
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 doit(args): line, gBand, rBand, catDir = args sed, mag, nsed = line.split() nsed = int(nsed) if sed.startswith("bergeron"): pref = "wDs" suff = ".gz" elif sed.startswith("k"): pref = "kurucz" suff = ".gz" elif sed.startswith("burrows") or sed.startswith("L") or sed.startswith("l") or sed.startswith("m"): pref = "mlt" suff = ".gz" star = Sed() star.readSED_flambda(os.path.join(catDir, "SEDs/starSED/%s/%s%s" % (pref, sed, suff))) star.flambdaTofnu() gflux = integrate(star, gBand) rflux = integrate(star, rBand) color = -2.5 * np.log10(gflux/rflux) #if int(color*100)==45: # print sed, nsed return sed, color, nsed
def __init__(self, file, posfile): self.keymap = ['u', 'g', 'r', 'i', 'z', 'y'] self.indmap = { '0': 'u', '1': 'g', '2': 'r', '3': 'i', '4': 'z', '5': 'y' } #Read the data file. This will presumably need to be specific to the data #Set paths to default throughputs and seds self.tpath = os.getenv('LSST_THROUGHPUTS_DEFAULT') self.spath = os.getenv('SIMS_SED_LIBRARY_DIR') self.bands = {} for k in self.keymap: self.bands[k] = Bandpass() self.bands[k].readThroughput( os.path.join(self.tpath, "total_%s.dat" % k)) sed = Sed() (self.phiarr, self.wavelen_step) = sed.setupPhiArray( self.mapFiltDictToArr(self.bands)) self.centpos = self.readPositionFile(posfile) (self.lensData, self.imgData) = self.readFile(file)
def read_kurucz(): # read kurucz model MS, g40 stars SEDs homedir = os.getenv("HOME") stardir = os.path.join(homedir, "seds/kurucz_r") allfilelist = os.listdir(stardir) starlist = [] # make preliminary cut for ms, g40 stars for filename in allfilelist: if filename[-3:] == 'g40': starlist.append(filename) if filename[-3:] == 'g20': starlist.append(filename) atemperature = [] amet = [] alogg = [] starlist2 = [] # make secondary cut for stars with temperature > 4000 deg for s in starlist: tmp = s.split('_') met = float(tmp[0][2:]) if tmp[0][1] == 'm': met = -1 * met met = met / 10.0 temperature = float(tmp[1][:5]) logg = float(tmp[2][1:]) logg = logg / 10.0 if (temperature > 4000.0): amet.append(met) atemperature.append(temperature) alogg.append(logg) starlist2.append(s) temperature = numpy.array(atemperature) met = numpy.array(amet) logg = numpy.array(alogg) starlist = starlist2 # actually read the stars SEDS from disk stars = {} for s in starlist: stars[s] = Sed() stars[s].readSED_flambda(os.path.join(stardir, s)) print "# Read %d MS stars from %s" % (len(starlist), stardir) # resample onto the standard bandpass for Bandpass obj's and calculate fnu to speed later calculations for s in starlist: stars[s].synchronizeSED(wavelen_min=WMIN, wavelen_max=WMAX, wavelen_step=WSTEP) return stars, starlist, temperature, met, logg
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 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 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 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 calcLSSTMags(self, spec, fluxnorm, redshift): """Calculate the magnitude of the source given a flux normalization in the standard LSST bands. ***This does not take into account host extinction. """ #Get default sed and filter locations #setup and redshift the spectrum sed = Sed() sed.readSED_flambda(os.path.join(self.spath, spec)) sed.multiplyFluxNorm(fluxnorm) sed.redshiftSED(redshift, dimming=True) sed.resampleSED(wavelen_match=self.bands[self.indmap['0']].wavelen) sed.flambdaTofnu() return sed.manyMagCalc(self.phiarr, self.wavelen_step)
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) infile = 'obsids' f = open(infile, 'r') outfile = 'obsinfo' db, cursor = ui.sqlConnect() printheader = True newfile = True
filtDir = os.environ["LSST_THROUGHPUTS_BASELINE"] uBand = Bandpass() gBand = Bandpass() rBand = Bandpass() iBand = Bandpass() zBand = Bandpass() yBand = Bandpass() uBand.readThroughput(os.path.join(filtDir, "total_u.dat")) gBand.readThroughput(os.path.join(filtDir, "total_g.dat")) rBand.readThroughput(os.path.join(filtDir, "total_r.dat")) iBand.readThroughput(os.path.join(filtDir, "total_i.dat")) zBand.readThroughput(os.path.join(filtDir, "total_z.dat")) yBand.readThroughput(os.path.join(filtDir, "total_y.dat")) catDir = os.environ["CAT_SHARE_DATA"] aStar = Sed() gStar = Sed() mStar = Sed() aStar.readSED_flambda(os.path.join(catDir, "data/starSED/kurucz", "kp01_9750.fits_g45_9830.gz")) gStar.readSED_flambda(os.path.join(catDir, "data/starSED/kurucz", "km20_6000.fits_g30_6020.gz")) mStar.readSED_flambda(os.path.join(catDir, "data/starSED/mlt", "m2.0Full.dat")) for sname, sed in zip(("A", "G", "M"), (aStar, gStar, mStar)): sed.flambdaTofnu() rBand.sbTophi() rflux = integrate(sed, rBand) for bpname, bp in zip(("u", "g", "i", "z", "y"), (uBand, gBand, iBand, zBand, yBand)): bp.sbTophi() flux = integrate(sed, bp) dmag = -2.5 * np.log10(flux/rflux)
def findGalaxies(ra_center, dec_center, radius, rMagMax, baMin, baMax): # CONSTANTS rad2deg = 180./math.pi csize = 100000 obj = "ASSEMBLEDGALAXY" expmjd = 0. gal_count = 0 wavelen_step = 0.25 Sixflts = ['float','float','float','float','float','float'] # BANDPASSES # Instantiate bandpasses and read into lsstbp. bpdir = os.getenv("LSST_THROUGHPUTS_BASELINE") filterlist = ('u', 'g', 'r', 'i', 'z', 'y') lsstbp = {} for f in filterlist: lsstbp[f] = Bandpass(wavelen_min=300,wavelen_max=1200, wavelen_step=0.1) lsstbp[f].readThroughput(os.path.join(bpdir, 'total_' + f + '.dat'), wavelen_step=wavelen_step) # SEDS # Read in all of the galaxy seds in the root directory: galdir = "/astro/net/lsst1/shared/data/galaxySED/" gals = {} gallist = os.listdir(galdir) for i in range(len(gallist)): if gallist[i].endswith('.gz'): gallist[i] = gallist[i][:-3] for gal in gallist: gals[gal] = Sed() gals[gal].readSED_flambda(os.path.join(galdir, gal)) # Check on resampling - want all galaxy seds to have the same wavelength range. # (although our LSST ranges are 300 - 1200 nm, the SED's are ~27 to 2290 nm). if ((gals[gallist[0]].wavelen.min() < 30) & (gals[gallist[0]].wavelen.max() > 2000)): # If true, then gals[gallist[0]] is okay to use as a template -- this ought to be true. wavelen_match = gals[gallist[0]].wavelen else: print "Had to use simple wavelength array for matching" wavelen_match = numpy.arange(30, 2200, 0.1, dtype='float') for gal in gallist: if gals[gal].needResample(wavelen_match = wavelen_match): gals[gal].resampleSED(wavelen_match = wavelen_match) # Create the galactic a, b values from CCM 89 for the source galaxy and ours. # adjust for redshift, add Milky Way dust (recalculate a and b), # normalize fluxes and calculate magnitudes: # First: calculate source galaxy a/b on wavelength range required for # source galaxy (internal)from CCM 89. a_int, b_int = gals[gallist[0]].setupCCMab() # Second: calculate milky way a/b on wavelength range required for calculating # magnitudes - i.e. 300 to 1200 nm. # Set up a Sed object that is the same for all galaxies, all chunks. # Start with a flat SED with F_AB = 3631 Jy tmpgal = Sed() tmpgal.setFlatSED(wavelen_min=300, wavelen_max=1200, wavelen_step=wavelen_step) a_mw, b_mw = tmpgal.setupCCMab() # so this is a/b on 300-1200 range. # Set up phi, the wavelength-normalized system response for each filter, for each bandpass. # sb is the system response function (throughputs). Also set up a bandpass list, for # manyMagCalc method and initiate mags w/dust. bplist = [] for f in filterlist: lsstbp[f].sbTophi() bplist.append(lsstbp[f]) phiarray, dlambda = tmpgal.setupPhiArray(bplist) objId = numpy.empty(0) ra = numpy.empty(0) dec = numpy.empty(0) diskFluxNorm = numpy.empty(0) bulgeFluxNorm = numpy.empty(0) diskSedFilename = numpy.empty(0) bulgeSedFilename = numpy.empty(0) a_disk = numpy.empty(0) b_disk = numpy.empty(0) a_bulge = numpy.empty(0) b_bulge = numpy.empty(0) pa_d = numpy.empty(0) rdshft = numpy.empty(0) Rmags = numpy.empty(0) #QUERY #myqdb = queryDB.queryDB(chunksize=csize,objtype=obj, filetypes=('REFERENCECATALOG',)) myqdb = queryDB.queryDB(chunksize=csize,objtype=obj, filetypes=('TEST',)) # Specify a circular field of view: ic = myqdb.getInstanceCatalogByCirc(ra_center, dec_center, radius, expmjd=expmjd) # Begin iteratively acquiring data gal_count = 0 while ic is not None: gal_loop = len(ic.dataArray['raJ2000']) gal_count += gal_loop objId = numpy.concatenate((objId, ic.dataArray['objId']), axis=0) ra = numpy.concatenate((ra, ic.dataArray['raJ2000']*rad2deg), axis=0) dec = numpy.concatenate((dec, ic.dataArray['decJ2000']*rad2deg), axis=0) diskFluxNorm = numpy.concatenate((diskFluxNorm, ic.dataArray['diskFluxNorm']), axis=0) bulgeFluxNorm = numpy.concatenate((bulgeFluxNorm, ic.dataArray['bulgeFluxNorm']), axis=0) diskSedFilename = numpy.concatenate((diskSedFilename, ic.dataArray['diskSedFilename']), axis=0) bulgeSedFilename = numpy.concatenate((bulgeSedFilename, ic.dataArray['bulgeSedFilename']), axis=0) a_disk = numpy.concatenate((a_disk, ic.dataArray['semiMajorDisk']), axis=0) b_disk = numpy.concatenate((b_disk, ic.dataArray['semiMinorDisk']), axis=0) a_bulge = numpy.concatenate((a_bulge, ic.dataArray['semiMajorBulge']), axis=0) b_bulge = numpy.concatenate((b_bulge, ic.dataArray['semiMinorBulge']), axis=0) pa_d = numpy.concatenate((pa_d, ic.dataArray['positionAngleDisk']), axis=0) rdshft = numpy.concatenate((rdshft, ic.dataArray['redshift']), axis=0) # Get next chunk, if it exists. ic = myqdb.getNextChunk() myqdb.closeSession() # Calculate galactic coordinates: gLon = [] gLat = [] for i in range(gal_count): gcoord = afwCoord.IcrsCoord(ra[i], dec[i]).toGalactic() gLon.append(gcoord.getL(afwCoord.DEGREES)*math.pi/180.) gLat.append(gcoord.getB(afwCoord.DEGREES)*math.pi/180.) ebv_mw = (EBV.calculateEbv(gLon, gLat, ebvMapNorth, ebvMapSouth, interp = True)) del gLon del gLat print 'gLon, gLat calculated' # Now calculate magnitudes for each galaxy. If you have a bulge, initiate its Sed # instance, multiply fnu by the bulge flux normalization and apply the bulge dust # model (currently zero). Next initiate a Sed instance for the disk (if you have # one), multiply fnu by the disk flux normalization and apply the disk dust model. # If you have bulge and disk Sed's, add them together; if not you'll just use # whichever one you have. Correct for redshift, resample the Sed since now it's # shifted in wavelength, add the Milky Way dust and calculate magnitudes using the # manyMag method. Uncorrected Magnitudes (no dust, reddening, redshifting added) # are calculated as well. uncmags = numpy.zeros(gal_count, dtype={'names':['u','g','r','i','z','y'], 'formats':Sixflts}) raEdge = numpy.zeros(len(ra)) decEdge = numpy.zeros(len(ra)) option = numpy.zeros(len(ra)) + 5 raEdge = ra - a_disk/3600.*math.sin((pa_d)*math.pi/180.) decEdge = dec + a_disk/3600.*math.cos((pa_d)*math.pi/180.) # Uncorrected Magnitudes (no dust, reddening, redshifting added) for i in range(gal_count): galdisk = diskSedFilename[i] galbulge = bulgeSedFilename[i] #raEdge = ra[i] - a_disk[i]/3600.*math.sin((pa_d[i])*math.pi/180.) #decEdge = dec[i] + a_disk[i]/3600.*math.cos((pa_d[i])*math.pi/180.) if (galbulge is not None) and (galdisk is not None): ba_disk = b_disk[i]/a_disk[i] ba_bulge = b_bulge[i]/a_bulge[i] baRatio = (diskFluxNorm[i]*ba_disk + bulgeFluxNorm[i] *ba_bulge)/(diskFluxNorm[i] + bulgeFluxNorm[i]) if baMin <= baRatio <= baMax: option[i] = 2 else: continue tmpbulge = uncMagCalc(rdshft[i], gals[galbulge].wavelen, gals[galbulge].flambda, multiFlux=bulgeFluxNorm[i]) tmpdisk = uncMagCalc(rdshft[i], gals[galdisk].wavelen, gals[galdisk].flambda, multiFlux=diskFluxNorm[i]) newgal = uncMagCalc(rdshft[i], tmpdisk.wavelen, (tmpdisk.flambda+tmpbulge.flambda), finish=1) tmpmags = newgal.manyMagCalc(phiarray, dlambda) elif galbulge is not None: baRatio = b_disk[i]/a_disk[i] if baMin <= baRatio <= baMax: option[i] = 0 else: continue tmpbulge = uncMagCalc(rdshft[i], gals[galbulge].wavelen, gals[galbulge].flambda, multiFlux=bulgeFluxNorm[i], finish=1) tmpmags = tmpbulge.manyMagCalc(phiarray, dlambda) elif galdisk is not None: baRatio = b_disk[i]/a_disk[i] if baMin <= baRatio <= baMax: option[i] = 1 else: continue tmpdisk = uncMagCalc(rdshft[i], gals[galdisk].wavelen, gals[galdisk].flambda, multiFlux=diskFluxNorm[i], finish=1) tmpmags = tmpdisk.manyMagCalc(phiarray, dlambda) j = 0 for f in filterlist: uncmags[f][i] = tmpmags[j] j += 1 del diskSedFilename, bulgeSedFilename, tmpmags del Av_d, Rv_d, Av_b, Rv_b, rdshft, uncmags, raEdge, decEdge idx = numpy.where((tmpmags[2] <= rMagMax) & (option != 5)) rmags = tmpmags[2][idx] objId = ojbId[idx] option.append(option) ra = ra[idx] dec = dec[idx] baRatio = baRatio[idx] a_disk = a_disk[idx] b_disk = b_disk[idx] a_bulge = a_bulge[idx] b_bulge = b_bulge[idx] diskFluxNorm = diskFluxNorm[idx] bulgeFluxNorm = bulgeFluxNorm[idx] pa_d = pa_d[idx] raEdge = raEdge[idx] decEdge = decEdge[idx] #print '%11.7f %11.7f %11.7f %11.7f' % (ra[i], dec[i], tmpmags[2], baRatio) print '# iterations: ', iteration + 1 print 'Total # of galaxies: %d' % (gal_count) print 'Number of qualifying Galaxies within a radius of %s deg. is %s' % (radius, len(rmags)) #print 'len(ra), len(rmags), len(baRatio), len(option): ', len(ra), len(rmags), len(baRatio), len(option) return ra, dec, rmags, baRatio, option, objId, a_disk, b_disk, a_bulge, b_bulge, diskFluxNorm, bulgeFluxNorm, pa_d, raEdge, decEdge
catDir = os.environ["CAT_SHARE_DATA"] filtDir = os.environ["LSST_THROUGHPUTS_BASELINE"] gBand = Bandpass() rBand = Bandpass() iBand = Bandpass() zBand = Bandpass() gBand.readThroughput(os.path.join(filtDir, "total_g.dat")) rBand.readThroughput(os.path.join(filtDir, "total_r.dat")) iBand.readThroughput(os.path.join(filtDir, "total_i.dat")) zBand.readThroughput(os.path.join(filtDir, "total_z.dat")) gBand.sbTophi() rBand.sbTophi() iBand.sbTophi() zBand.sbTophi() ref = Sed() ref.readSED_flambda(os.path.join(catDir, "SEDs/starSED/kurucz/%s"%(sedName))) ref.flambdaTofnu() wavelen = ref.wavelen fnu = ref.fnu waveleng, fnug = ref.resampleSED(wavelen, fnu, wavelen_match=gBand.wavelen) wavelenr, fnur = ref.resampleSED(wavelen, fnu, wavelen_match=rBand.wavelen) waveleni, fnui = ref.resampleSED(wavelen, fnu, wavelen_match=iBand.wavelen) wavelenz, fnuz = ref.resampleSED(wavelen, fnu, wavelen_match=zBand.wavelen) fluxg = fnug * gBand.phi fluxr = fnur * rBand.phi fluxi = fnui * iBand.phi fluxz = fnuz * zBand.phi refOffset = {} refOffset["r"] = {}
import copy import numpy import pylab import lsst.sims.catalogs.measures.photometry.Sed as Sed wavelen= numpy.arange(12, 1200, 1.0) flat = Sed(wavelen, flambda=wavelen*0.0+1.0) redshifts = numpy.arange(0.1, 6.0, 1.5) #redshifts=[3.0,] for z in redshifts: flat2 = copy.deepcopy(flat) flat2.redshiftSED(z) flat3 = copy.deepcopy(flat2) rtau = 0.50 #/ ((1+z)**(3/2)) print z, rtau flat3.addIGMattenuation(z, rtau) pylab.plot(flat2.wavelen, flat2.flambda, 'k-') pylab.plot(flat3.wavelen, flat3.flambda, label='%.1f' %(z)) pylab.axvline(91.2*(1+z), color='r', linestyle=':') pylab.legend(loc='upper right') pylab.xlabel("Wavelength (nm)") pylab.ylabel("Flambda .. ==attenuation") pylab.xlim(30, 1200) pylab.show()
def calcLSSTMags(self, spec, fluxnorm, redshift): """Calculate the magnitude of the source given a flux normalization in the standard LSST bands. ***This does not take into account host extinction. """ #Get default sed and filter locations #setup and redshift the spectrum sed = Sed() sed.readSED_flambda(os.path.join(self.spath,spec)) sed.multiplyFluxNorm(fluxnorm) sed.redshiftSED(redshift, dimming=True) sed.resampleSED(wavelen_match=self.bands[self.indmap['0']].wavelen) sed.flambdaTofnu() return sed.manyMagCalc(self.phiarr, self.wavelen_step)
def calcAllMags(self, filt, mjdTaiList, rootSEDdir, rootFILTERdir=None, withErrors=True, fiveSigmaLimitingMag=None): """ Calculate the magnitude of all objects in the movingObjectList. Give the filter, the mjd (to find the ephemeris info) and the root directory of SEDS. Calculates magnitudes. Individual objects already know their SED and their expected V magnitude (part of ephemeris info). """ # Set up data needed to calculate magnitudes for each moving object. # First find location of lsst filter throughput curves, if not specified. import os if rootFILTERdir == None: # (assumes throughputs is setup) # Just use the default directory of the throughputs as this is probably correct. rootFILTERdir = os.getenv("LSST_THROUGHPUTS_DEFAULT") # Now rootFILTERdir should be defined. if rootFILTERdir == None: raise Exception( "Ack: rootFILTERdir is undefined and it seems that 'throughputs' is not setup." ) # Import Sed and Bandpass for calculating magnitudes. (assumes catalogs_measures is setup) import lsst.sims.catalogs.measures.photometry.Sed as Sed import lsst.sims.catalogs.measures.photometry.Bandpass as Bandpass # read in and set up filter files bandpass = {} filterlist = ('V', 'imsim', filt) for f in filterlist: if f == 'V': filename = os.path.join(rootSEDdir, 'harris_V.dat') # Instantiate and read the throughput file. bandpass[f] = Bandpass() bandpass[f].readThroughput(filename) elif f == 'imsim': filename = 'imsim' bandpass[f] = Bandpass() bandpass[f].imsimBandpass() else: filename = os.path.join(rootFILTERdir, 'total_' + f + '.dat') # Instantiate and read the throughput file. bandpass[f] = Bandpass() bandpass[f].readThroughput(filename) # Read in and set up sed files. Assumes asteroid SEDS end in .dat possiblesedtypes = os.listdir(rootSEDdir) sedtypes = [] for p in possiblesedtypes: if p.endswith('.dat'): sedtypes.append(p) sed = {} sedmag = {} sedcol = {} for sedfile in sedtypes: # read sed files filename = os.path.join(rootSEDdir, sedfile) sed[sedfile] = Sed() sed[sedfile].readSED_flambda(filename) # set up magnitudes for color calculation. sedmag[sedfile] = {} sedcol[sedfile] = {} for f in filterlist: sedmag[sedfile][f] = sed[sedfile].calcMag(bandpass[f]) sedcol[sedfile][f] = sedmag[sedfile][f] - sedmag[sedfile]['V'] # set up mjdTaiListStr for access to ephemeris dictionaries movingobj = self._mObjects[0] mjdTaiListStr = [] if isinstance(mjdTaiList, list) == False: mjdTaiList = [mjdTaiList] for mjdTai in mjdTaiList: mjdTaiListStr.append(movingobj.mjdTaiStr(mjdTai)) # mjdTaiListStr will be the same for all objects. # now loop through each object and assign appropriate magnitudes values for this observation for movingobj in self._mObjects: # loop through mjdTaiList for mjdTaiStr in mjdTaiListStr: try: # check ephemerides exist movingobj.Ephemerides[mjdTaiStr] except AttributeError: raise Exception("Do not have an ephemeride on date %s" % (mjdTaiStr)) vmag = movingobj.Ephemerides[mjdTaiStr].getmagV() sedname = movingobj.getsedname() # Check if sedname in list of known seds. if sed.has_key(sedname) == False: # HACK - FIX when catalogs updated sedname = 'S.dat' #raise Exception("SED (%s) of moving object (#%d) not in movingObjectList's directory." # %(sedname, movingobj.getobjid())) # calculate magnitudes filtmag = vmag + sedcol[sedname][filt] imsimmag = vmag + sedcol[sedname]['imsim'] # set filter magnitude in ephemeris movingobj.Ephemerides[mjdTaiStr].setmagFilter(filtmag) movingobj.Ephemerides[mjdTaiStr].setmagImsim(imsimmag) # Add SNR measurement if given 5-sigma limiting mag for exposure. if fiveSigmaLimitingMag != None: flux_ratio = n.power( 10, 0.4 * (fiveSigmaLimitingMag - filtmag)) snr = 5 * (flux_ratio) movingobj.Ephemerides[mjdTaiStr].setsnr(snr) # Calculate approx errors in ra/dec/mag from magnitude/m5. if withErrors: if fiveSigmaLimitingMag == None: raise Exception( "To calculate errors, fiveSigmaLimitingMag is needed." ) # calculate error in ra/dec rgamma = 0.039 # average seeing is 0.7" (or 700 mas) error_rand = n.sqrt((0.04 - rgamma) * flux_ratio + rgamma * flux_ratio * flux_ratio) ast_error_rand = 700.0 * error_rand ast_error_sys = 10.0 astrom_error = n.sqrt(ast_error_sys**2 + ast_error_rand**2) # convert from mas to deg astrom_error = astrom_error / 100.0 / 60.0 / 60.0 movingobj.Ephemerides[mjdTaiStr].setastErr(astrom_error) mag_error_sys = 0.005 mag_error = n.sqrt(error_rand**2 + mag_error_sys**2) movingobj.Ephemerides[mjdTaiStr].setmagErr(mag_error) # end of mjdTaiList loop return
xnm1 -= 10**-6 * f * (0.0624 - 0.000680/wavelength**2) / (1 + 0.003661 * T) xn = xnm1 + 1 r0 = (xn**2 - 1) / (2 * xn**2) of = r0 * np.tan(zd) return of if __name__ == "__main__": tp_dir = os.environ["THROUGHPUTS_DIR"] common_components = map(lambda x: os.path.join(tp_dir, "baseline", x), ["detector.dat", "m1.dat", "m2.dat", "m3.dat", "lens1.dat", "lens2.dat", "lens3.dat"]) seds = [] catDir = os.environ["CAT_SHARE_DATA"] oStar = Sed() gStar = Sed() mStar = Sed() oStar.readSED_flambda(os.path.join(catDir, "data/starSED/kurucz", "kp01_9750.fits_g45_9830.gz")) gStar.readSED_flambda(os.path.join(catDir, "data/starSED/kurucz", "km20_6000.fits_g30_6020.gz")) mStar.readSED_flambda(os.path.join(catDir, "data/starSED/mlt", "m2.0Full.dat")) seds.append(oStar) seds.append(gStar) seds.append(mStar) for sed in seds: sed.flambdaTofnu() filtDir = os.environ["LSST_THROUGHPUTS_BASELINE"] for airmass, zd in zip((15, 11), (50, 30)): for sidx, sed in enumerate(seds):
import numpy import pylab import lsst.sims.catalogs.measures.photometry.Sed as Sed import lsst.sims.catalogs.measures.photometry.Bandpass as Bandpass import os # read filters filterdir = os.getenv("LSST_THROUGHPUTS_DEFAULT") filterlist = ('u', 'g', 'r', 'i', 'z', 'y') lsst = {} for f in filterlist: lsst[f] = Bandpass() lsst[f].readThroughput(os.path.join(filterdir, "total_" + f + ".dat")) # read base quasar sed qso = Sed() qso.readSED_flambda("quasar.dat") # set redshift range redshifts = numpy.arange(0, 6, 0.2) # set up quasar seds for this redshift range qsoz = {} for z in redshifts: qsoz[z] = Sed(qso.wavelen, flambda=qso.flambda) qsoz[z].redshiftSED(z, dimming=True) qsoz[z].flambdaTofnu() # calculate colors mags = {} for f in filterlist:
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 doit(args): sed, gmag, nsed = args if sed.startswith("bergeron"): pref = "wDs" suff = ".gz" elif sed.startswith("k"): pref = "kurucz" suff = ".gz" elif sed.startswith("burrows") or sed.startswith("L") or sed.startswith("l") or sed.startswith("m"): pref = "mlt" suff = ".gz" star = Sed() star.readSED_flambda(os.path.join(catDir, "SEDs/starSED/%s/%s%s" % (pref, sed, suff))) star.flambdaTofnu() Mg = np.empty((len(dairmasses), len(dthetas))) Mr = np.empty((len(dairmasses), len(dthetas))) Mi = np.empty((len(dairmasses), len(dthetas))) Mz = np.empty((len(dairmasses), len(dthetas))) # Resample array elements wavelen = star.wavelen fnu = star.fnu waveleng, fnug = star.resampleSED(wavelen, fnu, wavelen_match=gBand.wavelen) wavelenr, fnur = star.resampleSED(wavelen, fnu, wavelen_match=rBand.wavelen) waveleni, fnui = star.resampleSED(wavelen, fnu, wavelen_match=iBand.wavelen) wavelenz, fnuz = star.resampleSED(wavelen, fnu, wavelen_match=zBand.wavelen) fluxg = fnug * gBand.phi fluxr = fnur * rBand.phi fluxi = fnui * iBand.phi fluxz = fnuz * zBand.phi gr = -2.5 * np.log10( np.sum(fluxg) / np.sum(fluxr) ) gi = -2.5 * np.log10( np.sum(fluxg) / np.sum(fluxi) ) gz = -2.5 * np.log10( np.sum(fluxg) / np.sum(fluxz) ) rmag = gmag - gr imag = gmag - gi zmag = gmag - gz # Find DCR at airmass zd1 dg1 = getOffset(waveleng, fluxg, zd1) - refOffset["g"][int(zd1)] dr1 = getOffset(wavelenr, fluxr, zd1) - refOffset["r"][int(zd1)] di1 = getOffset(waveleni, fluxi, zd1) - refOffset["i"][int(zd1)] dz1 = getOffset(wavelenz, fluxz, zd1) - refOffset["z"][int(zd1)] for ia, dairmass in enumerate(dairmasses): # Find DCR at other zds zd2 = np.arccos(1./(airmass1 + dairmass)) * 180/np.pi dg2 = getOffset(waveleng, fluxg, zd2) - refOffset["g"][int(zd2)] dr2 = getOffset(wavelenr, fluxr, zd2) - refOffset["r"][int(zd2)] di2 = getOffset(waveleni, fluxi, zd2) - refOffset["i"][int(zd2)] dz2 = getOffset(wavelenz, fluxz, zd2) - refOffset["z"][int(zd2)] for it, dtheta in enumerate(dthetas): #print ia, it, (airmass1 + dairmass), zd1, zd2, dtheta, dg1, dg2 Mg[ia, it] = np.sqrt(dg1**2 + dg2**2 - 2 * dg1 * dg2 * np.cos(dtheta * np.pi / 180)) Mr[ia, it] = np.sqrt(dr1**2 + dr2**2 - 2 * dr1 * dr2 * np.cos(dtheta * np.pi / 180)) Mi[ia, it] = np.sqrt(di1**2 + di2**2 - 2 * di1 * di2 * np.cos(dtheta * np.pi / 180)) Mz[ia, it] = np.sqrt(dz1**2 + dz2**2 - 2 * dz1 * dz2 * np.cos(dtheta * np.pi / 180)) #print Mg #print Mr if (gmag<16) or (gmag>25): Mg *= 0 ng = 0 else: ng = nsed if (rmag<16) or (rmag>24.7): Mr *= 0 nr = 0 else: nr = nsed if (imag<16) or (imag>24): Mi *= 0 ni = 0 else: ni = nsed if (zmag<16) or (zmag>23.3): Mz *= 0 nz = 0 else: nz = nsed return Mg, Mr, Mi, Mz, ng, nr, ni, nz
xnm1 -= 10**-6 * f * (0.0624 - 0.000680/wavelength**2) / (1 + 0.003661 * T) xn = xnm1 + 1 r0 = (xn**2 - 1) / (2 * xn**2) of = r0 * np.tan(zd) # RADIANS return of if __name__ == "__main__": tp_dir = os.environ["THROUGHPUTS_DIR"] common_components = map(lambda x: os.path.join(tp_dir, "baseline", x), ["detector.dat", "m1.dat", "m2.dat", "m3.dat", "lens1.dat", "lens2.dat", "lens3.dat"]) seds = [] catDir = os.environ["CAT_SHARE_DATA"] aStar = Sed() gStar = Sed() mStar = Sed() aStar.readSED_flambda(os.path.join(catDir, "SEDs/starSED/kurucz", "kp01_9750.fits_g45_9830.gz")) gStar.readSED_flambda(os.path.join(catDir, "SEDs/starSED/kurucz", "km20_6000.fits_g30_6020.gz")) mStar.readSED_flambda(os.path.join(catDir, "SEDs/starSED/mlt", "m2.0Full.dat")) seds.append(aStar) seds.append(gStar) seds.append(mStar) for sed in seds: sed.flambdaTofnu() filtDir = os.environ["LSST_THROUGHPUTS_BASELINE"] for bpname in ("g", "r", "i"): bp = Bandpass(wavelen_max=1200)