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 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_sn(self, dataDir='data/sn', epochs=['10', '15', '20'], redshifts=numpy.arange(0, 1.0, 0.1)): """Reads SN at a variety of epochs and then redshifts to the desired range of z. Stores seds as well as epochs and redshifts. """ # Read sn spectra and redshift allfilelist = os.listdir(dataDir) snlist = [] # Pull out the filenames we want (which match epochs and SNIa template) for filename in allfilelist: if filename.endswith('.dat') & filename.startswith('sn1a_'): #snlist.append(filename) tmp = filename.split('_') epoch = tmp[1].split('.')[0] if epoch in epochs: snlist.append(filename) # Read base SEDs for these epochs. sns_base = {} for sn, epoch in zip(snlist, epochs): sns_base[epoch] = Sed() sns_base[epoch].readSED_flambda(os.path.join(dataDir, sn)) # Then redshift to build stored set of SEDs. self.sns = {} self.snlist = [] for e in epochs: for z in redshifts: sn_name = "%d_%.1f" % (int(e), z) wavelen, flambda = sns_base[e].redshiftSED( z, wavelen=sns_base[e].wavelen, flambda=sns_base[e].flambda) self.sns[sn_name] = Sed(wavelen=wavelen, flambda=flambda) self.snlist.append(sn_name) print "# Generated %d sn's at redshifts between %f and %f for epochs %s" %(len(self.snlist), \ redshifts.min(), \ redshifts.max(), epochs) self.epochs = epochs self.redshifts = redshifts return
def read_eline_galaxy(self, dataDir='data/eline_galaxy', redshifts=numpy.arange(0, 1.0, 0.1)): """Reads starburst galaxy and then redshifts to the desired range of z. Stores seds as well as epochs and redshifts. """ # Read sn spectra and redshift allfilelist = os.listdir(dataDir) gallist = [] #get filenames for filename in allfilelist: if filename.endswith('.dat'): gallist.append(filename) gal_base = {} for gal in gallist: gal_base = Sed() gal_base.readSED_flambda(os.path.join(dataDir, gal)) # Then redshift to build stored set of SEDs. self.gals = {} self.gallist = [] for z in redshifts: gal_name = "%.1f" % (z) wavelen, flambda = gal_base.redshiftSED(z, wavelen=gal_base.wavelen, flambda=gal_base.flambda) self.gals[gal_name] = Sed(wavelen=wavelen, flambda=flambda) self.gallist.append(gal_name) print "# Generated %d galaxies at redshifts between %f and %f" %(len(self.gallist), \ redshifts.min(), \ redshifts.max()) self.redshifts = redshifts return
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 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 read_whitedwarf(self, dataDir='data/white_dwarfs_r'): # read white dwarf bergeron models # get the H dwarfs Hdir = os.path.join(dataDir, "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(dataDir, "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) self.temperatures = numpy.array(temperatures) self.loggs = numpy.array(loggs) self.hlist = hlist self.helist = helist self.wdlist = hlist + helist self.wds = {} for w in self.wdlist: self.wds[w] = Sed() if w in hlist: self.wds[w].readSED_flambda(os.path.join(Hdir, w)) if w in helist: self.wds[w].readSED_flambda(os.path.join(Hedir, w)) return
def read_kurucz(self, dataDir='data/kurucz_r', g40_only=True): """Read selected kurucz seds. Stores metallicity, logg and temperature information as well.""" # read kurucz model MS, [g40_only?] stars SEDs allfilelist = os.listdir(dataDir) starlist = [] # make preliminary cut for ms, g40 stars. if g40_only: for filename in allfilelist: if filename[-3:] == 'g40': starlist.append(filename) else: starlist = allfilelist atemperature = [] amet = [] alogg = [] starlist2 = [] # Make secondary cut for stars with temperature > 4000 deg (kurucz models are unreliable below 4000K). 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) # Update what we're keeping for star information. self.temperature = numpy.array(atemperature) self.met = numpy.array(amet) self.logg = numpy.array(alogg) self.starlist = starlist2 # And now, actually read the stars SEDS from disk. self.stars = {} for s in self.starlist: self.stars[s] = Sed() self.stars[s].readSED_flambda(os.path.join(dataDir, s)) print "# Read %d MS stars from %s" % (len(self.starlist), dataDir) return