def testPhiArray(self): """ Test that the phi array is correctly calculated by BandpassDict upon construction. """ for nBp in range(3, 10, 1): nameList, bpList = self.getListOfBandpasses(nBp) testDict = BandpassDict(bpList, nameList) dummySed = Sed() controlPhi, controlWavelenStep = dummySed.setupPhiArray(bpList) numpy.testing.assert_array_almost_equal(controlPhi, testDict.phiArray, 19) self.assertAlmostEqual(controlWavelenStep, testDict.wavelenStep, 10)
def __init__(self, bandpassList, bandpassNameList): """ @param [in] bandpassList is a list of Bandpass instantiations @param [in] bandpassNameList is a list of tags to be associated with those Bandpasses. These will be used as keys for the BandpassDict. """ self._bandpassDict = OrderedDict() for bandpassName, bandpass in zip(bandpassNameList, bandpassList): if bandpassName in self._bandpassDict: raise RuntimeError("The bandpass %s occurs twice in your input " % bandpassName \ + "to BandpassDict") self._bandpassDict[bandpassName] = copy.deepcopy(bandpass) dummySed = Sed() self._phiArray, self._wavelenStep = dummySed.setupPhiArray(self._bandpassDict.values()) self._wavelen_match = self._bandpassDict.values()[0].wavelen
def __init__(self, bandpassList, bandpassNameList): """ @param [in] bandpassList is a list of Bandpass instantiations @param [in] bandpassNameList is a list of tags to be associated with those Bandpasses. These will be used as keys for the BandpassDict. """ self._bandpassDict = OrderedDict() for bandpassName, bandpass in zip(bandpassNameList, bandpassList): if bandpassName in self._bandpassDict: raise RuntimeError("The bandpass %s occurs twice in your input " % bandpassName \ + "to BandpassDict") self._bandpassDict[bandpassName] = copy.deepcopy(bandpass) dummySed = Sed() self._phiArray, self._wavelenStep = dummySed.setupPhiArray( self._bandpassDict.values()) self._wavelen_match = self._bandpassDict.values()[0].wavelen
def get_TotalMags(result, bandpasses=('u','g','r','i','z','y')): datadir = os.environ.get("SIMS_SED_LIBRARY_DIR") tpath = os.getenv('LSST_THROUGHPUTS_DEFAULT') bands = {"u":None, "g":None, "r":None, "i":None, "z":None, "y":None} for k in bands: bands[k] = Bandpass() bands[k].readThroughput(os.path.join(tpath, "total_%s.dat"%k)) # Set up phi, the wavelength-normalized system response for each filter, # for each bandpass for manyMagCalc method. bplist = [] for f in ['u','g','r','i','z','y']: bands[f].sbTophi() bplist.append(bands[f]) ids = result['galid'] diskfile = result['sedFilenameDisk'] bulgefile = result['sedFilenameBulge'] agnfile = result['sedFilenameAgn'] diskmn = result['magNormDisk'] bulgemn = result['magNormBulge'] agnmn = result['magNormAgn'] bulgeAv = result['internalAvBulge'] diskAv = result['internalAvDisk'] redshift = result['redshift'] imsimband = Bandpass() imsimband.imsimBandpass() sedDict = {} retMags = dict([(k, []) for k in bands]) a_int = None b_int = None tmpwavelen = None for id, df, dm, dav, bf, bm, bav, af, am, z in zip(ids, diskfile, diskmn, diskAv, bulgefile, bulgemn, bulgeAv, agnfile, agnmn, redshift): tmpflux = None for comp in ((df, dm, dav, 'galaxySED', False), (bf, bm, bav, 'galaxySED', False), (af, am, None, 'agnSED', True)): #Zero out the AGN contribution #for comp in ((df, dm, dav, 'galaxySED', False), (bf, bm, bav, 'galaxySED', False), (af, 99.99, None, 'agnSED', True)): if not comp[0] == u'None': if sedDict.has_key(comp[0]): sed = copy.deepcopy(sedDict[comp[0]]) else: sed = Sed() print os.path.join(datadir,comp[3],comp[0]) sed.readSED_flambda(os.path.join(datadir,comp[3],comp[0])) if comp[4]: sed.resampleSED(wavelen_match=tmpwavelen) sedDict[comp[0]] = sed if a_int is None: phiarray, dlambda = sed.setupPhiArray(bplist) a_int, b_int = sed.setupCCMab() #Careful, this assumes that a disk or bulge sed is read #before any agn sed tmpwavelen = sed.wavelen fNorm = sed.calcFluxNorm(comp[1], imsimband) sed.multiplyFluxNorm(fNorm) #I guess this assumes rv=3.1?? if comp[2]: sed.addCCMDust(a_int, b_int, A_v=comp[2]) wavelenArr=sed.wavelen if tmpflux is None: tmpflux = sed.flambda else: tmpflux += sed.flambda newgal = Sed(wavelen=wavelenArr, flambda=tmpflux) #a_mw, b_mw = sed.setupCCMab() #sed.addCCMDust(a_mw, b_mw, A_v=mwav) newgal.redshiftSED(z, dimming=True) newgal.resampleSED(wavelen_match=bplist[0].wavelen) newgal.flambdaTofnu() mags = newgal.manyMagCalc(phiarray, dlambda) for i,k in enumerate(['u','g','r','i','z','y']): retMags[k].append(mags[i]) return retMags
# First: calculate internal a/b on wavelength range required for internal dust extinction. a_int, b_int = gals[ gallist[0]].setupCCMab() # this is a/b on native galaxy sed range. # Next: calculate milky way a/b on wavelength range required for calculating magnitudes - i.e. 300 to 1200 nm. tmpgal = Sed() tmpgal.setFlatSED(wavelen_min=wavelen_min, wavelen_max=wavelen_max, wavelen_step=wavelen_step) a_mw, b_mw = tmpgal.setupCCMab() # so this is a/b on native MW bandpass range. # Also: set up phi for each bandpass - ahead of time. And set up a list of bandpasses, then create phiarray # and dlambda to set up for manyMagCalc method. bplist = [] for f in filterlist: lsstbp[f].sbTophi() bplist.append(lsstbp[f]) phiarray, dlambda = tmpgal.setupPhiArray(bplist) # Set up dictionary + arrays to hold calculated magnitude information. mags2 = {} for f in filterlist: mags2[f] = numpy.zeros(num_gal, dtype='float') # For each galaxy (in num_gal's), apply internal dust, redshift, resample to 300-1200 nm, apply MW dust on # shorter (and standardized) wavelength range, fluxnorm, and then calculate mags using manyMagCalc. for i in range(num_gal): galname = gallist[gal_name[i]] tmpgal = Sed(wavelen=gals[galname].wavelen, flambda=gals[galname].flambda) tmpgal.addCCMDust(a_int, b_int, ebv=ebv_int[i]) tmpgal.redshiftSED(redshifts[i]) tmpgal.resampleSED(wavelen_min=wavelen_min, wavelen_max=wavelen_max, wavelen_step=wavelen_step) tmpgal.addCCMDust(a_mw, b_mw, ebv=ebv_mw[i])
for filter in lsstfilterlist: lsst[filter] = Bandpass() lsst[filter].readThroughput(rootdir + "exampleBandpass.dat") # you have to do this now - sbToPhi to use the multi-mag calc lsst[filter].sbTophi() # I *do* know that all bandpasses are using the same wavlength array, so let's take it # for granted that bandpass.wavelen is the same for each. # Now, we can calculate the magnitudes in multiple bandpasses, for each SED. # make the bandpass list bplist = [] for filter in lsstfilterlist: bplist.append(lsst[filter]) phiArray, dlambda = tmpstar.setupPhiArray(bplist) # store the values in a 2-d array (could do in a dictionary of arrays too) mags = n.empty((len(starskeys), len(bplist)), dtype="float") for i in range(len(starskeys)): # make a copy of the original SED *if* you want to 'reuse' the SED for multiple magnitude # calculations with various fluxnorms and dust applications (otherwise just use the object # you instantiated above) tmpstar = Sed(wavelen=stars[starskeys[i]].wavelen, flambda=stars[starskeys[i]].flambda) tmpstar.addCCMDust(a, b, ebv=ebv[i]) tmpstar.multiplyFluxNorm(fluxnorm[i]) mags[i] = tmpstar.manyMagCalc(phiArray, dlambda) print "#sedname mag_u mag_g mag_r mag_i mag_z mag_y" for i in range(len(starskeys)): print "%s %.4f %.4f %.4f %.4f %.4f %.4f" % ( starskeys[i],
for filter in lsstfilterlist: lsst[filter] = Bandpass() lsst[filter].readThroughput(rootdir + "exampleBandpass.dat") # you have to do this now - sbToPhi to use the multi-mag calc lsst[filter].sbTophi() # I *do* know that all bandpasses are using the same wavlength array, so let's take it # for granted that bandpass.wavelen is the same for each. # Now, we can calculate the magnitudes in multiple bandpasses, for each SED. # make the bandpass list bplist = [] for filter in lsstfilterlist: bplist.append(lsst[filter]) phiArray, dlambda = tmpstar.setupPhiArray(bplist) # store the values in a 2-d array (could do in a dictionary of arrays too) mags = n.empty((len(starskeys), len(bplist)), dtype='float') for i in range(len(starskeys)): # make a copy of the original SED *if* you want to 'reuse' the SED for multiple magnitude # calculations with various fluxnorms and dust applications (otherwise just use the object # you instantiated above) tmpstar = Sed(wavelen=stars[starskeys[i]].wavelen, flambda=stars[starskeys[i]].flambda) tmpstar.addCCMDust(a, b, ebv=ebv[i]) tmpstar.multiplyFluxNorm(fluxnorm[i]) mags[i] = tmpstar.manyMagCalc(phiArray, dlambda) print "#sedname mag_u mag_g mag_r mag_i mag_z mag_y" for i in range(len(starskeys)): print "%s %.4f %.4f %.4f %.4f %.4f %.4f" % (
# For next test: want to also do all the same steps, but in an optimized form. This means # doing some things that Sed does 'behind the scenes' explicitly, but also means the code may be a little # harder to read at first. # First: calculate internal a/b on wavelength range required for internal dust extinction. a_int, b_int = gals[gallist[0]].setupCCMab() # this is a/b on native galaxy sed range. # Next: calculate milky way a/b on wavelength range required for calculating magnitudes - i.e. 300 to 1200 nm. tmpgal = Sed() tmpgal.setFlatSED(wavelen_min=wavelen_min, wavelen_max=wavelen_max, wavelen_step = wavelen_step) a_mw, b_mw = tmpgal.setupCCMab() # so this is a/b on native MW bandpass range. # Also: set up phi for each bandpass - ahead of time. And set up a list of bandpasses, then create phiarray # and dlambda to set up for manyMagCalc method. bplist = [] for f in filterlist: lsstbp[f].sbTophi() bplist.append(lsstbp[f]) phiarray, dlambda = tmpgal.setupPhiArray(bplist) # Set up dictionary + arrays to hold calculated magnitude information. mags2 = {} for f in filterlist: mags2[f] = numpy.zeros(num_gal, dtype='float') # For each galaxy (in num_gal's), apply internal dust, redshift, resample to 300-1200 nm, apply MW dust on # shorter (and standardized) wavelength range, fluxnorm, and then calculate mags using manyMagCalc. for i in range(num_gal): galname = gallist[gal_name[i]] tmpgal = Sed(wavelen=gals[galname].wavelen, flambda=gals[galname].flambda) tmpgal.addCCMDust(a_int, b_int, ebv=ebv_int[i]) tmpgal.redshiftSED(redshifts[i]) tmpgal.resampleSED(wavelen_min=wavelen_min, wavelen_max=wavelen_max, wavelen_step=wavelen_step) tmpgal.addCCMDust(a_mw, b_mw, ebv=ebv_mw[i]) tmpgal.multiplyFluxNorm(fluxnorm[i]) #tmpgal.flambdaTofnu() #Not needed because multiplyFluxNorm calculates fnu