def scatterplot_vinit_Tfinal(): from pltastro import frame, draw, legend from numpy import histogram frm = frame.multi(2, 1) pars = frm.params pars.left = 0.2 pars.figsize = (6, 8) pnls = frm.panels pars.height_ratios = [4, 1] pnls.ylabels = ["Vinit [km/s]", "frac"] pnls.set_xlabels("log(T_final)") pnls.set_xlims(3.0, 7.0) pnls.ylims[0] = (0.0, 1500.) pnls.ylims[1] = (0.0, 0.3) fig, axs = draw(frm) vi, Tf = [], [] for p in pg3: vi.append(p.track['dv'][0]) Tf.append(log10(p.track['T'][-1])) # Tf.append(p.track['T'][-1]) axs[0].plot(Tf, vi, "b.", alpha=0.3, markersize=4) hist, edges = histogram(Tf, bins=linspace(3, 7, 30)) mid = 0.5 * (edges[1:] + edges[:-1]) norm = sum(hist) hist = array(hist) / (float)(norm) axs[1].plot(mid, hist, "b.-") vi, Tf = [], [] for p in pparts: vi.append(p.track['dv'][0]) Tf.append(p.track['T'][-1]) axs[0].plot(Tf, vi, "r.", alpha=0.3, markersize=4) hist, edges = histogram(Tf, bins=linspace(3, 7, 30)) mid = 0.5 * (edges[1:] + edges[:-1]) norm = sum(hist) hist = array(hist) / (float)(norm) axs[1].plot(mid, hist, "r.-") lgd = legend.legend(axs[0]) lgd.addLine(("Gadget3", "blue", "-", 1)) lgd.addLine(("GIZMO", "red", "-", 1)) lgd.loc = "upper left" lgd.fontsize = 12 lgd.draw() plt.savefig("/scratch/shuiyao/figures/tmp.pdf") plt.show()
pars.left = 0.2 pars.top = 0.92 pars.bottom = 0.2 panels = frm.panels panels.set_xlabels(r"$z$") panels.set_ylabels("Fraction") # panels.set_xlims(0.0, 1.0) # panels.set_xlims(REDSHIFT, 3.0) panels.set_xlims(0.0, 10.0) if(CUMULATIVE_DISTRIBUTION): panels.set_ylims(0.0, 1.0) else: panels.set_ylims(0.0, 0.4) panels.set_yticks([0.0, 0.1, 0.2, 0.3]) fig, axs = draw(frm) captions = [ r"$11.0 < M_\mathrm{vir} < 11.5$",\ r"$11.85 < M_\mathrm{vir} < 12.15$",\ r"$12.85 < M_\mathrm{vir} < 13.15$"\ ] mmin = [11.0, 11.85, 12.85] mmax = [11.5, 12.15, 13.15] for modeli in range(len(models)): fname = "/home/shuiyao_umass_edu/scidata/gadget3io/"+models[modeli]+"/"+models[modeli]+"_"+zstr+".starinfo" soname = "/nas/astro-th-nas/shuiyao/"+models[modeli]+"/so_z"+zstr+".sovcirc" foutname = "/home/shuiyao_umass_edu/scidata/gadget3io/"+models[modeli]+"/"+models[modeli]+"_"+zstr+".mprof." print ("Doing: ", fname) stars = genfromtxt(fname, names=True)
def figure_sfhistory(): # Show how stars accumulated to form these galaxies at z = 0 from pltastro import draw import pltastro frm = pltastro.frame.multi(3, 3) # frm.panels.ylabels[0] = r"$\frac{M(a)}{M(1)}$" # frm.panels.ylabels[3] = r"$\frac{M}{M_{tot}}$" frm.panels.ylabels[0] = r"$\log(\frac{M_*(<z)}{M_b})$" frm.panels.ylabels[3] = r"$\log(\frac{\Delta M_*(z)}{M_b\Delta_z})$" frm.panels.ylabels[6] = r"$f_{acc}$" frm.panels.set_xlabels(r"$z_{sf}$") for i in [6, 7, 8]: # bottom panels frm.panels.ylims[i] = (0.0, 1.1) frm.panels.yticks[i] = [0.2, 0.4, 0.6, 0.8, 1.0] for i in [0, 1, 2]: # upper panels frm.panels.ylims[i] = (-4.0, 0.0) frm.panels.yticks[i] = [-4.0, -3.0, -2.0, -1.0] for i in [3, 4, 5]: # middle panels frm.panels.ylims[i] = (-5.0, 0.0) frm.panels.yticks[i] = [-5.0, -4.0, -3.0, -2.0, -1.0] # frm.panels.set_ylims(0.0, 1.1) # frm.panels.set_yticks([0.0, 0.2, 0.4, 0.6, 0.8, 1.0]) # frm.panels.set_xticks([0.0, 0.33, 0.5, 0.8]) frm.panels.set_xticks([log10(5.0), log10(3.0), log10(2.0), 0.0]) frm.panels.set_xticklabels(["4.0", "2.0", "1.0", "0.0"]) frm.panels.set_ytickformat('%3.1f') frm.panels.set_xlims(log10(7.0), 0.0) frm.params.figsize = (9, 9) frm.params.left = 0.12 fig, axs = draw(frm) mstrs = ['mh11', 'mh12', 'mh13'] # fi # modelnames = ["p50n288sw", "p50n288fiducial", "p50n288beta2"] # mi # modelnames = ["l25n144-gadget3","l25n144-phewoff", "l25n144-phew"] # mi # labels = ["G3Winds", "PhEWOFF", "PhEW"] # modelnames = ["l25n144-phew-m5kh100fs10","l25n144-phew-m4kh50fs10", "l25n144-phew-m4kh100fs10"] # mi # labels = ["mc5", "mc4kh50", "mc4kh100"] # modelnames = ["l25n144-phewoff","l25n144-phew-m5kh30fs10", "l25n144-phew-mach1"] # mi # labels = ["PhEWOff", "m5kh30fs10", "m5kh30fs10"] # modelnames = ["l25n144-phew-m4kh100fs100","l25n144-phew-m4kh50fs10", "l25n144-phew-m4kh100fs10"] # mi # labels = ["mc4fs100", "mc4kh50", "mc4fs10"] # modelnames = ["p50n288fiducial","l25n144-gadget3", "l25n144-phewoff"] # mi # labels = ["p50n288", "Gadget3", "GIZMO"] # modelnames = ["l25n288-phew-m5","l25n144-phew-m5"] # mi # labels = ["PhEW,25/288", "PhEW,25/144"] modelnames = ["l25n288-phew-m5", "l25n144-phew-m5-spl"] # mi labels = ["PhEW,25/288", "PhEW,25/288, Split"] # modelnames = ["l25n288-phewoff-fw","l25n144-phewoff"] # mi # labels = ["PhEWOff,25/288", "PhEWOff,25/144"] # titlestr = [r'$11.0 < \log(\frac{M_{vir}}{M_\odot}) < 11.5$',\ # r'$11.85 < \log(\frac{M_{vir}}{M_\odot}) < 12.15$',\ # r'$12.85 < \log(\frac{M_{vir}}{M_\odot}) < 13.15$'] titlestr = ["low-mass",\ "intermediate",\ "massive"] lstyles = ["-", "--", ":"] moster18 = [8.92, 10.4, 10.96] # Moster 18 M* for the three bins moster18 = (array(moster18) - array([11.25, 12.0, 13.0])) - log10( OMEGAB / OMEGAM) from matplotlib.lines import Line2D lgds = [] for fi in range(3): # Mass bins for mi in [0, 1]: # Models sfrinfoname, soname = find_fnames(modelnames[mi], mstrs[fi]) print sfrinfoname, soname if (mi == -1): stars = load_central_stars(sfrinfoname, fformat="old") abins = build_abins(stars, cumulative=False) else: stars = load_central_stars(sfrinfoname, fformat="new") abins = build_abins_phew(stars, cumulative=False) abins.totalmass = find_total_mass(stars, soname) print "Total Mass ----> ", abins.totalmass abins.draw(axs[3 + fi], lstyle=lstyles[mi], method="differential") # Normed cumulative abins.cumulate() abins.draw(axs[0 + fi], lstyle=lstyles[mi], method="normed") # Normed by total Mass abins.draw(axs[6 + fi], lstyle=lstyles[mi], method="cumulative") # Normed cumulative axs[fi].set_title(titlestr[fi]) if (fi == 0): lgds.append( Line2D([0], [0], color="black", linestyle=lstyles[mi], label=labels[mi])) axs[fi].plot([log10(3.), log10(3.)], [-4.0, 0.0], ":", color="lightgrey") axs[fi].plot([log10(2.), log10(2.)], [-4.0, 0.0], ":", color="lightgrey") axs[fi].plot(log10(1.1), moster18[fi], "*", color="black", markersize=18) axs[fi + 3].plot([log10(3.), log10(3.)], [-5.0, 0.0], ":", color="lightgrey") axs[fi + 3].plot([log10(2.), log10(2.)], [-5.0, 0.0], ":", color="lightgrey") axs[fi + 6].plot([log10(3.), log10(3.)], [0.0, 1.1], ":", color="lightgrey") axs[fi + 6].plot([log10(2.), log10(2.)], [0.0, 1.1], ":", color="lightgrey") # from matplotlib.lines import Line2D # lgds = [Line2D([0], [0], color="black", linestyle=":", label="G3Cool"),\ # Line2D([0], [0], color="black", linestyle="-", label="GIZMO")] axs[0].legend(handles=lgds, loc="upper left") lgds = [Line2D([0], [0], color="black", linestyle="-", label="total"),\ Line2D([0], [0], color="blue", linestyle="-", label="cold"),\ Line2D([0], [0], color="red", linestyle="-", label="hot")] if (SEPARATE_COLD_HOT_WINDS): lgds.append( Line2D([0], [0], color=color_coldw, linestyle="-", label="cold wind")) lgds.append( Line2D([0], [0], color=color_hotw, linestyle="-", label="hot wind")) # lgds.append(Line2D([0], [0], color="green", linestyle="-", label="wind")) if (SHOW_WINDS_MIXED): lgds.append(Line2D([0], [0], color="cyan", linestyle="-", label="wmix")) lgds.append( Line2D([0], [0], color="lightgrey", linestyle="-", label="M(z)/M(z=0)")) axs[6].legend(handles=lgds, loc="upper left") plt.savefig(FIGNAME)
def figure(): from pltastro import frame, draw import config_mpl pparts = load_particles(filename, fphewsname) frm = frame.multi(3, 2) params = frm.params params.figsize = (9, 10) params.left = 0.12 params.right = 0.95 params.bottom = 0.28 params.top = 0.93 params.wspace = 0.30 params.hspace = 0.05 panels = frm.panels # panels.set_xticks([0., 0.2, 0.4, 0.6, 0.8, 1.0]) panels.set_xlabels(r"$Time [Myr]$") panels.set_xlims(0., 800.) panels.ylims[0] = (0., 1.) panels.ylims[1] = (0., 20.) panels.ylims[2] = (0., 1.) # panels.ylims[3] = (3.5, 5.) panels.ylims[3] = (4.0, 7.0) panels.ylims[4] = (-28., -22.) panels.ylims[5] = (-30., -24.) panels.yticks[0] = [0.2, 0.4, 0.6, 0.8, 1.0] panels.yticks[1] = [5., 10., 15., 20.] panels.yticks[2] = [0.2, 0.4, 0.6, 0.8, 1.0] # panels.yticks[3] = [4.0, 4.5, 5.0] panels.yticks[3] = [5.0, 6.0, 7.0] panels.yticks[4] = [-28., -26., -24., -22.] panels.yticks[5] = [-30., -28., -26., -24.] for i in range(6): panels.yticksON[i] = True panels.ylabels[0] = r"$R/R_\mathrm{vir}$" panels.ylabels[1] = r"$\mathcal{M}$" panels.ylabels[2] = r"$M_\mathrm{c}$" panels.ylabels[3] = r"$T_\mathrm{a}$" panels.ylabels[4] = r"$\rho_\mathrm{c}$" panels.ylabels[5] = r"$\rho_\mathrm{a}$" fig, axs = draw(frm) parts_to_show = select_particles(pparts) # parts_to_show = select_hard_particles(pparts) draw_phew_particles(parts_to_show, axs[0], 'time', 'r/rvir', 'Mvir', nskip=NSKIP, logyscale=False, color_min=11.0, color_max=13.5, alpha=0.4) print(counter_spurious_particles) draw_phew_particles(parts_to_show, axs[1], 'time', 'Mach', 'Mvir', nskip=NSKIP, logyscale=False, color_min=11.0, color_max=13.5, alpha=0.4) draw_phew_particles(parts_to_show, axs[2], 'time', 'M_cloud', 'Mvir', nskip=NSKIP, logyscale=False, color_min=11.0, color_max=13.5, alpha=0.4) draw_phew_particles(parts_to_show, axs[3], 'time', 'T_a', 'Mvir', nskip=NSKIP, logyscale=True, color_min=11.0, color_max=13.5, alpha=0.4) draw_phew_particles(parts_to_show, axs[4], 'time', 'rho_c', 'Mvir', nskip=NSKIP, logyscale=True, color_min=11.0, color_max=13.5, alpha=0.4) draw_phew_particles(parts_to_show, axs[5], 'time', 'rho_a', 'Mvir', nskip=NSKIP, logyscale=True, color_min=11.0, color_max=13.5, alpha=0.4) # axs[1].text(0.5, 0.85, modelname, fontsize=12, transform=axs[1].transAxes) axcbar = fig.add_axes([0.15, 0.15, 0.7, 0.01]) norm1 = mpl.colors.Normalize(vmin=11.0, vmax=13.5) cdcbar = mpl.colorbar.ColorbarBase(axcbar, cmap=plt.get_cmap(CMAP), norm=norm1, orientation="horizontal") cdcbar.set_ticks([11, 11.5, 12, 12.5, 13.0, 13.5]) cdcbar.set_ticklabels(["11", "11.5", "12", "12.5", "13", "13.5"]) cdcbar.set_label(r"$M_\mathrm{vir}$") plt.savefig(DIRS['FIGURE'] + "tmp.pdf") plt.show()
def figure(): from pltastro import frame, draw import config_mpl frm = frame.multi(2, 1) params = frm.params params.figsize = (5, 9) params.hspace = 0.35 params.top = 0.93 params.bottom = 0.28 params.left = 0.20 panels = frm.panels panels.set_ylims(2.5, 8.) panels.xlims[0] = (0., 6000.) panels.xlims[1] = (-31., -23.) panels.xticks[0] = [0, 2000, 4000, 6000] panels.xticks[1] = [-31., -29., -27., -25., -23.] panels.set_yticks([3, 4, 5, 6, 7]) panels.ylabels[0] = r'$\log(T)$' panels.ylabels[1] = r'$\log(T)$' panels.xlabels[0] = "Time [Myr]" panels.xlabels[1] = r"$\log(\rho_a\ [\mathrm{g/cm^3}])$" for i in range(2): panels.yticksON[i] = True for i in range(2): panels.xticksON[i] = True fig, axs = draw(frm) pparts = load_particles() # tracks print("Draw Tracks.....") keys = draw_phew_particles(pparts, axs[0], 'time', 'T', 'Mvir', nskip=NSKIP, logyscale=False, color_min=11.0, color_max=13.5, alpha=0.3, post_recouple=False) keys = draw_phew_particles(pparts, axs[1], 'rho', 'T', 'Mvir', nskip=NSKIP, logyscale=False, color_min=11.0, color_max=13.5, alpha=0.3, post_recouple=False) phews = phew.load_particles(filename_phews, fphewsname) # phews for p in phews: key_to_phew[p.key] = p phews_to_show = [] for key in keys: phews_to_show.append(key_to_phew[key]) print("Draw PhEWs (%d) ....." % (len(phews_to_show))) phew.draw_phew_particles(phews_to_show, axs[0], 'time', 'T_c', 'Mvir', nskip=1, logyscale=True, logxscale=False, color_min=11.0, color_max=13.5, alpha=0.3, allparts=True) phew.draw_phew_particles(phews_to_show, axs[1], 'rho_a', 'T_c', 'Mvir', nskip=1, logyscale=True, logxscale=True, color_min=11.0, color_max=13.5, alpha=0.3, allparts=True) draw_phase_diagram_contour(axs[1]) # axs[0].text(0.5, 0.85, modelname, fontsize=12, transform=axs[1].transAxes) axs[0].set_title(model + ", z = " + str(REDSHIFT)) axcbar = fig.add_axes([0.15, 0.15, 0.7, 0.01]) norm1 = mpl.colors.Normalize(vmin=11.0, vmax=13.5) cdcbar = mpl.colorbar.ColorbarBase(axcbar, cmap=plt.get_cmap(CMAP), norm=norm1, orientation="horizontal") cdcbar.set_ticks([11, 11.5, 12, 12.5, 13.0, 13.5]) cdcbar.set_ticklabels(["11", "11.5", "12", "12.5", "13", "13.5"]) cdcbar.set_label(r"$M_\mathrm{vir}$") plt.savefig("/scratch/shuiyao/figures/tmp.pdf") plt.show()