def plot_all_filters(): fig = plt.figure(figsize=(11, 4)) ax = fig.add_subplot(111) fnames = ["U", "B", "V", "R", "I", "u", "g", "r", "i", "z"] for name in fnames: wl, trans = np.load("filters/" + name + ".npy") ax.plot(wl, trans, label=name) ax.legend() ax.set_ylabel("Normalized transmission") ax.set_xlabel(r"$\lambda$ [\AA]") ax.xaxis.set_major_formatter(FSF("%.0f")) ax.set_ylim(-1e-4, 2e-3) fig.subplots_adjust(bottom=0.12) fig.savefig("plots/filter_responses.png")
def plot_broadened_gauss(): '''Gaussian centered at 6500 A''' #ones stretches from 6300 to 6700 ang fig = plt.figure() ax = fig.add_subplot(111) wl_full = karray(6500, 3, 0.01) orig = np.ones_like(wl_full) sigma_l = 6.5 / (2.355 * 3e5) * 6500. #A wl_gauss = karray(6500., 4 * sigma_l, 0.01) ind = (wl_full >= wl_gauss[0]) & (wl_full <= wl_gauss[-1]) init = 10. - gauss_series(0.01) norm = init / 10. orig[ind] = norm k20 = vsini_ang(6500., 20.) f20 = convolve(orig, k20) k40 = vsini_ang(6500., 40.) f40 = convolve(orig, k40) k60 = vsini_ang(6500., 60.) f60 = convolve(orig, k60) k80 = vsini_ang(6500., 80.) f80 = convolve(orig, k80) ax.plot(wl_full, orig) ax.plot(wl_full, f20) ax.plot(wl_full, f40) ax.plot(wl_full, f60) ax.plot(wl_full, f80) ax.xaxis.set_major_formatter(FSF("%.0f")) #ax.set_ylim(0.3,1.05) ax.set_ylabel(r"$F/F_c$") ax.set_xlabel(r"$\lambda\quad[\AA]$") plt.show()
temps = np.unique(pcagrid.gparams[:, 0]) loggs = np.unique(pcagrid.gparams[:, 1]) Zs = np.unique(pcagrid.gparams[:, 2]) points = {"temp": temps, "logg": loggs, "Z": Zs} base = cfg['outdir'] # Plot the eigenspectra for i, comp in enumerate(pcagrid.pcomps): print("plotting {}".format(i)) fig = plt.figure(figsize=(8, 5)) ax = fig.add_subplot(111) ax.xaxis.set_major_formatter(FSF("%.0f")) ax.set_xlabel(r"$\lambda$ [\AA]") ax.set_ylabel(r"$\propto f_\lambda$") ax.plot(wl, comp, label="{}".format(i + 1)) ax.set_xlim(5150, 5200) fig.savefig(base + "eigenspectrum_{:0>3}.png".format(i)) plt.close() fig = plt.figure(figsize=(8, 5)) ax = fig.add_subplot(111) ax.xaxis.set_major_formatter(FSF("%.0f")) ax.set_xlabel(r"$\lambda$ [\AA]") ax.set_ylabel(r"$\propto f_\lambda$") ax.plot(wl, pcagrid.flux_mean)
def explore(weight_index): weights = pcagrid.w[weight_index] #Set up the emulator EMw = WeightEmulator(pcagrid, params[weight_index], weight_index, None) #samples[weight_index]) nsamp = 5 figt, axt = plt.subplots(nrows=nls, ncols=nzs, figsize=(12, 12), sharex=True, sharey=True) for i in range(nls): for j in range(nzs): logg = loggs[i] Z = Zs[j] ww = [] for temp in temps: pars = np.array([temp, logg, Z]) index = pcagrid.get_index(pars) ww.append(weights[index]) axt[i, j].plot(temps, ww, "k") axt[i, j].plot(temps, ww, "bo") axt[i, j].annotate(r"$\log g = {:.1f}$".format(logg), (0.1, 0.90), xycoords="axes fraction", ha="left", color="k", size=9) axt[i, j].annotate(r"$Z = {:.1f}$".format(Z), (0.1, 0.8), xycoords="axes fraction", ha="left", color="k", size=9) fparams = [] for temp in int_temps: fparams.append([temp, logg, Z]) fparams = np.array(fparams) for k in range(nsamp): axt[i, j].plot(int_temps, EMw(fparams), "b", lw=0.5) axt[-1, -1].xaxis.set_major_formatter(FSF("%.0f")) axt[-1, -1].xaxis.set_major_locator(MultipleLocator(200)) figl, axl = plt.subplots(nrows=nzs, ncols=nts, figsize=(18, 12), sharex=True, sharey=True) for i in range(nzs): for j in range(nts): Z = Zs[i] temp = temps[j] ww = [] for logg in loggs: pars = np.array([temp, logg, Z]) index = pcagrid.get_index(pars) ww.append(weights[index]) axl[i, j].plot(loggs, ww, "k") axl[i, j].plot(loggs, ww, "bo") axl[i, j].annotate(r"$T_{\rm eff}$" + "$= {:.0f}$".format(temp), (0.1, 0.90), xycoords="axes fraction", ha="left", color="k", size=9) axl[i, j].annotate(r"$Z = {:.1f}$".format(Z), (0.1, 0.8), xycoords="axes fraction", ha="left", color="k", size=9) fparams = [] for logg in int_loggs: fparams.append([temp, logg, Z]) fparams = np.array(fparams) for k in range(nsamp): #EMw.emulator_params = samples[np.random.choice(indexes)] axl[i, j].plot(int_loggs, EMw(fparams), "b", lw=0.5) axl[-1, -1].xaxis.set_major_formatter(FSF("%.1f")) axl[-1, -1].xaxis.set_major_locator(MultipleLocator(0.5)) figz, axz = plt.subplots(nrows=nls, ncols=nts, figsize=(18, 12), sharex=True, sharey=True) for i in range(nls): for j in range(nts): logg = loggs[i] temp = temps[j] ww = [] for Z in Zs: pars = np.array([temp, logg, Z]) index = pcagrid.get_index(pars) ww.append( weights[index]) #np.sum(emulator.fluxes[index] * pcomp)) axz[i, j].plot(Zs, ww, "k") axz[i, j].plot(Zs, ww, "bo") axz[i, j].annotate(r"$\log g = {:.1f}$".format(logg), (0.1, 0.90), xycoords="axes fraction", ha="left", color="k", size=9) axz[i, j].annotate(r"$T_{\rm eff}$" + "$ = {:.0f}$".format(temp), (0.1, 0.8), xycoords="axes fraction", ha="left", color="k", size=9) fparams = [] for Z in int_Zs: fparams.append([temp, logg, Z]) fparams = np.array(fparams) for k in range(nsamp): #EMw.emulator_params = samples[np.random.choice(indexes)] axz[i, j].plot(int_Zs, EMw(fparams), "b", lw=0.5) axz[-1, -1].xaxis.set_major_formatter(FSF("%.1f")) axz[-1, -1].xaxis.set_major_locator(MultipleLocator(0.5)) figt.savefig(base + "weight{}_temp.png".format(weight_index)) figl.savefig(base + "weight{}_logg.png".format(weight_index)) figz.savefig(base + "weight{}_Z.png".format(weight_index)) plt.close()
def plot_paper(flatchain, base=args.outdir, triangle_plot=args.triangle, chain_plot=args.chain, lnprob=args.lnprob, clip_stellar='all', format=".pdf"): ''' Make a bunch of plots to diagnose how the run went. ''' import matplotlib matplotlib.rc("font", size=8) #matplotlib.rc("axes", labelpad=10) import matplotlib.pyplot as plt from matplotlib.ticker import FormatStrFormatter as FSF from matplotlib.ticker import MaxNLocator #Navigate the flatchain tree, and plot just the stellar parameters #flatchain = [flatchain for flatchain in flatchainTree.flatchains if flatchain.id == "stellar"][0] #Just assume that we're getting the stellar flatchain. assert flatchain.id == "stellar", "Paper plotting mode only available for Stellar parameters at the moment." if clip_stellar != "all": flatchain.clip_param(clip_stellar) params = flatchain.param_tuple samples = flatchain.samples if args.replicate: #Concatenate the samples a few times samples = np.vstack([samples for i in range(30)]) labels = [label_dict.get(key, "unknown") for key in params] K = len(labels) fig, axes = plt.subplots(K, K, figsize=(3.5, 3.35)) figure = triangle.corner( samples, labels=labels, # quantiles=[0.16, 0.5, 0.84], show_titles=False, title_args={"fontsize": 8}, plot_contours=True, plot_datapoints=False, fig=fig) if K == 3: figure.subplots_adjust(left=0.13, right=0.87, top=0.95, bottom=0.16) if K == 4: figure.subplots_adjust(left=0.13, right=0.87, top=0.95, bottom=0.15) axes[-1, 0].xaxis.set_major_formatter(FSF("%.0f")) if K == 4: #Yaxis for ax in axes[:, 0]: ax.yaxis.set_label_coords(-0.48, 0.5) for ax in axes[-1, :]: ax.xaxis.set_label_coords(0.5, -0.48) axes[-1, -1].xaxis.set_major_locator(MaxNLocator(nbins=5, prune='lower')) if K == 3: #Yaxis for ax in axes[:, 0]: ax.yaxis.set_label_coords(-0.40, 0.5) for ax in axes[-1, :]: ax.xaxis.set_label_coords(0.5, -0.39) for ax in axes[:, 1]: ax.xaxis.set_major_locator(MaxNLocator(nbins=4, prune='lower')) axes[1, 0].yaxis.set_major_locator(MaxNLocator(nbins=5)) figure.savefig(base + flatchain.id + format) figure.savefig(base + flatchain.id + ".svg")