def get_lick_regions(): """ Read definitions of bands of the Lick indices and return bands. """ table = os.path.join(tables_dir, "BANDS") return np.loadtxt(table, usecols=(2,3)), np.loadtxt(table, usecols=(4,5)),\ np.loadtxt(table, usecols=(6,7)) if __name__ == "__main__": wdir = home + "/single2" os.chdir(wdir) # plt.switch_backend('macosx') plt.ioff() save = True block = False specs = speclist() specs = ["fin1_n3311cen1_s27.fits", "fin1_n3311cen2_s37.fits"] # Workaround to deal with cases where you have only one object in the file if isinstance(specs, str): specs = [specs] ########################################################################### xlims = [4800, 5850] w_tem = w_temp(velscale) red, bands, blue = get_lick_regions() names = [ r'Hd$_A$', r'Hd$_F$', r'CN$_1$', r'CN$_2$', 'Ca4227', r'G4300', r'Hg_A', r'Hg_F', r'Fe4383', r'Ca4455', r'Fe4531', r'C4668', r'H$\beta$', r'Fe5015', r'Mg$_1$', r'Mg$_2', r'Mg $b$', r'Fe5270', r'Fe5335', r'Fe5406', r'Fe5709', r'Fe5782', r'Na_D', r'TiO_1', r'TiO_2' ] textsize = 16
Prepare files for alternative pPXF run. """ import os import pyfits as pf import matplotlib.pyplot as plt from config import * from run_ppxf import speclist if __name__ == "__main__": spec_dir = os.path.join(home, "single1") sky_dir = os.path.join(home, "sky/1D") for spectrum in speclist(): print spectrum spec = os.path.join(spec_dir, spectrum) sky = os.path.join(sky_dir, spectrum.replace("fin", "sky")) outdir = os.path.join(home, "single3") output = os.path.join(outdir, spectrum) if not (os.path.exists(spec) and os.path.exists(sky)): continue sdata = pf.getdata(spec) skydata = pf.getdata(sky) header = pf.getheader(spec, verify="ignore") sdata += skydata ax = plt.subplot(111) ax.plot(sdata, "-k") ax.plot(sdata - skydata, "-b") ax.plot(skydata, "-y")
mad = 1.4826 * np.median(np.abs(data - median), axis=0) line = "{0:26s}".format(spec) + \ "".join(["{0:10s}".format("{0:.5f}".format(x)) for x in mad]) results.append(line) with open("mc_lick_nsim{0}.txt".format(Nsim), "w") as f: f.write("\n".join(results)) return if __name__ == "__main__": wdir = os.path.join(home, "m6pc") outdir = os.path.join(wdir, "mc_logs") if not os.path.exists(outdir): os.mkdir(outdir) os.chdir(wdir) bcorr = BroadCorr(os.path.join(tables_dir, "lickcorr_m.txt")) specs = speclist() bands = os.path.join(tables_dir, "BANDS") lick_types = np.loadtxt(bands, usecols=(8,)) lick_indices = np.genfromtxt(bands, usecols=(0,), dtype=None).tolist() Nsim = 100 header = table_header() if True: pool = mp.Pool() for i, spec in enumerate(specs): pool.apply_async(run_mc, args=(spec, i)) # print spec # run_mc(spec, i) # break pool.close() pool.join() write_table(specs, Nsim)
"summary.txt") if not os.path.exists(logfile): continue with open(logfile, "r") as f: header = f.readline() lines.append(f.readline()) table = os.path.join(working_dir, "populations_{0}.txt".format(modelname)) with open(table, "w") as f: f.write(header) f.write("\n".join(lines)) if __name__ == "__main__": working_dir = os.path.join(home, "single2") os.chdir(working_dir) plt.ioff() specs = speclist() # specs = ["fin1_n3311cen1_s23.fits", "fin1_n3311cen1_s30.fits"] db = "" modelname = "miles" if db == "2" else "thomas" dirs = [x.replace(".fits", "_db{0}".format(db)) for x in specs] lims = [[9 + np.log10(1.), 9 + np.log10(15.)], [-2.25, 0.90], [-0.3, 0.5]] plims = [[np.log10(1.), 1.2], [-2.3, 0.7], [-0.4, 0.6]] fignums = [4, 7, 8] pairs = [[0,1], [0,2], [1,2]] plt.ioff() pp = PdfPages(os.path.join(working_dir, "mcmc_results_{0}.pdf".format(modelname))) plt.figure(1, figsize=(9,6.5)) plt.minorticks_on() table_summary, table_results = [], [] sndata = dict(np.loadtxt("ppxf_results.dat", usecols=(0,10), dtype=str))
if not os.path.exists(logfile): continue with open(logfile, "r") as f: header = f.readline() lines.append(f.readline()) table = os.path.join(working_dir, "populations_{0}.txt".format(modelname)) with open(table, "w") as f: f.write(header) f.write("\n".join(lines)) if __name__ == "__main__": working_dir = os.path.join(home, "single2") os.chdir(working_dir) plt.ioff() specs = speclist() # specs = ["fin1_n3311cen1_s23.fits", "fin1_n3311cen1_s30.fits"] db = "" modelname = "miles" if db == "2" else "thomas" dirs = [x.replace(".fits", "_db{0}".format(db)) for x in specs] lims = [[9 + np.log10(1.), 9 + np.log10(15.)], [-2.25, 0.90], [-0.3, 0.5]] plims = [[np.log10(1.), 1.2], [-2.3, 0.7], [-0.4, 0.6]] fignums = [4, 7, 8] pairs = [[0, 1], [0, 2], [1, 2]] plt.ioff() pp = PdfPages( os.path.join(working_dir, "mcmc_results_{0}.pdf".format(modelname))) plt.figure(1, figsize=(9, 6.5)) plt.minorticks_on() table_summary, table_results = [], [] sndata = dict(np.loadtxt("ppxf_results.dat", usecols=(0, 10), dtype=str))