def main(): """ Produces the figure and saves it as a PDF. """ plt.clf() axes = setup_axes() plot_oscillatory(axes, vice.output("../../simulations/SFRoscil_amp0p3_per2"), "crimson") plot_oscillatory(axes, vice.output("../../simulations/SFEoscil_amp0p2_per2"), "deepskyblue") plot_pdf(axes[-1], vice.output("../../simulations/SFRoscil_amp0p3_per2"), "crimson") plot_pdf(axes[-1], vice.output("../../simulations/SFEoscil_amp0p2_per2"), "deepskyblue") axes[2].text(0.14, 150, r"%g $\leq$ [Fe/H] $\leq$ %g" % (_FEH_MIN_, _FEH_MAX_), fontsize=25) legend(axes[1]) plt.tight_layout() visuals.yticklabel_formatter(axes[2]) plt.savefig(sys.argv[1]) plt.clf()
def plot_output_3axes(axes, name, color, element, second_linestyle='-'): """ Plots the star formation rate and infall rate on axes[0], [X/Fe]-[Fe/H] tracks on axes[1], and the dN/d[X/Fe] MDF on axes[2]. Parameters ========== axes :: list A 3-element list of matplotlib subplots name :: str The name of the VICE output to plot color :: str The name of the color to pass to matplotlib's named colors mapping element :: str The symbol for the element X second_linestyle :: str [default :: '-'] The linestyle to use in the middle and right-hand panels """ out = vice.output(name) axes[0].plot(out.history["time"], out.history["sfr"], c=colors()[color]) axes[0].plot(out.history["time"], out.history["ifr"], c=colors()[color], linestyle='--') axes[1].plot(out.history["[Fe/H]"], out.history["[%s/Fe]" % (element)], c=colors()[color], linestyle=second_linestyle) axes[2].plot(list( map(lambda x, y: (x + y) / 2., out.mdf["bin_edge_left"], out.mdf["bin_edge_right"])), out.mdf["dN/d[%s/Fe]" % (element)], c=colors()[color], linestyle=second_linestyle)
def main(output, comparison, stem, colormap="winter", N=10000): r""" Produce a 15-panel figure showing a scatter plot of randomly sampled stellar populations in [O/Fe]-[Fe/H] space color-coded by birth radius for different present-day galactic regions. Parameters ---------- output : ``str`` The relative or absolute path to the VICE output whose predicted [O/Fe]-[Fe/H] distribution is to be visualized. comparison : ``str`` The relative or absolute path to the VICE output whose predicted gas-phase track for the solar circle (R = 8 kpc) will be plotted as a reference in all panels. stem : ``str`` The relative or absolute path to the output image, with no extension. This function will save the figure in both PDF and PNG formats. colormap : ``str`` [default : "winter"] The colormap to use in color-coding stellar populations by their birth radius. N : ``int`` [default : 10,000] The number of stellar populations to sample in each galactic region. """ axes = setup_axes() dummy = axes[-1] axes = axes[:-1] outputs = [vice.output(_) for _ in [output, comparison]] for i in outputs: i.stars["abszfinal"] = [ abs(_) for _ in zheights(i.name)[:i.stars.size[0]] ] for i in range(len(axes)): for j in range(len(axes[i])): sc = scatterplot_subsample(axes[i][j], filter_multioutput_stars( outputs[0].stars, int(RADII[j] / ZONE_WIDTH), int(RADII[j + 1] / ZONE_WIDTH) - 1, HEIGHTS[-2 - i], HEIGHTS[-1 - i], min_mass=0), colormap=colormap, N=N) plot_solar_annulus_track(axes[i][j], outputs[1]) cbar_ax = plt.gcf().add_axes([0.92, 0.05, 0.02, 0.95]) cbar = plt.colorbar(sc, cax=cbar_ax, pad=0.0, orientation="vertical") cbar.set_label(r"$R_\text{gal}$ of birth [kpc]", labelpad=10) cbar.set_ticks(range(2, 16, 2)) plt.tight_layout() plt.subplots_adjust(hspace=0, wspace=0, bottom=0.08, left=0.06, right=0.93) cbar_ax.set_position([ axes[-1][-1].get_position().x1, axes[-1][-1].get_position().y0, 0.025, axes[0][-1].get_position().y1 - axes[-1][-1].get_position().y0 ]) plt.savefig("%s.png" % (stem)) plt.savefig("%s.pdf" % (stem)) plt.close()
def main(output1, output2, stem, times = [2, 4, 6, 8, 10, END_TIME]): r""" Produce a two-panel figure comparing the gas-phase [O/Fe]-[Fe/H] tracks of two models in the left-hand panel and a comparison of their SN Ia rates in the right-hand panel. Parameters ---------- output1 : ``str`` The relative or absolute path to the first of the two VICE outputs. This one will be illustrated using solid lines. output2 : ``str`` The relative or absolute path to the second of the two VICE outputs. This one will be illustrated using dotted lines. stem : ``str`` The relative or absolute path to the output image, with no extension. This function will save the figure in both PDF and PNG formats. times : ``list`` [elements of type ``float``] [default : [2, 4, 6, 8, 10, 13.2]] The times in Gyr at which to mark the positions of the [O/Fe]-[Fe/H] tracks of the two models. """ axes = setup_axis() out1 = vice.output(output1) out2 = vice.output(output2) plot_tracks(axes[0], out1, label = True) plot_tracks(axes[0], out2, linestyle = ':') plot_ticks(axes[0], out1, times, marker = markers()['x']) plot_ticks(axes[0], out2, times, marker = markers()["point"]) plot_ia_rate_proxies(axes[1], out1) plot_ia_rate_proxies(axes[1], out2, linestyle = ':') leg = axes[0].legend(loc = mpl_loc("lower left"), ncol = 1, frameon = False, bbox_to_anchor = (0.01, 0.01), handlelength = 0, fontsize = 20) for i in range(len(RADII)): leg.get_texts()[i].set_color(COLORS[i]) leg.legendHandles[i].set_visible(False) plt.tight_layout() plt.savefig("%s.png" % (stem)) plt.savefig("%s.pdf" % (stem))
def main(static, insideout, lateburst, outerburst, stem): r""" Plot the surface densities of star formation, infall, and gas as functions of time for the four SFH models described in Johnson et al. (2021). Parameters ---------- static : ``str`` The relative path to the VICE output with a constant SFH. insideout : ``str`` The relative path to the VICE output with an inside-out SFH. lateburst : ``str`` The relative path to the VICE output with a late-burst SFH. outerburst : ``str`` The relative path to the VICE output with an outer-burst SFH. stem : ``str`` The relative or absolute path to the output image, with no extension. This function will save the figure in both PDF and PNG formats. """ axes = setup_axes() plot_evolution([row[0] for row in axes], vice.output(static), label=True) plot_evolution([row[1] for row in axes], vice.output(insideout)) plot_evolution([row[2] for row in axes], vice.output(lateburst)) plot_evolution([row[3] for row in axes], vice.output(outerburst)) leg = axes[1][0].legend(loc=mpl_loc("upper center"), ncol=4, frameon=False, bbox_to_anchor=(0.5, 0.99), handlelength=0, columnspacing=0.8, fontsize=20) for i in range(len(RADII)): leg.get_texts()[i].set_color(COLORS[i]) leg.legendHandles[i].set_visible(False) plt.tight_layout() plt.subplots_adjust(hspace=0, wspace=0, left=0.08) plt.savefig("%s.png" % (stem)) plt.savefig("%s.pdf" % (stem))
def plot_track(ax, name, ref, color, linestyle): """ Plots [O/X]-[X/H] tracks on a matplotlib subplot Args: ===== ax: The name of the subplot name: The name of the VICE output ref: The symbol for the reference element color: The color of the line linestyle: The linestyle to use """ out = vice.output(name) ax.plot(out.history["[%s/h]" % (ref)], out.history["[o/%s]" % (ref)], c = visuals.colors()[color], linestyle = linestyle)
def plot_vice_comparison(ax, name): """ Plots the [Mg/Fe]-[Fe/H] track of a given VICE model on the subplot. Parameters ========== ax :: matplotlib subplot The axis to plot on name :: str The relative path to the VICE output """ out = vice.output(name) ax.plot(out.history["[fe/h]"], out.history["[mg/fe]"], c=visuals.colors()["black"], linestyle='--')
def plot_track(ax, name, color): """ Plots a single [Sr/O]-[O/H] track Parameters ========== ax :: subplot The matplotlib axis object to plot on name :: str The name of the VICE output color :: str The name of the color to plot in """ output = vice.output(name) ax.plot(output.history["[O/H]"], output.history["[Sr/O]"], c = visuals.colors()[color])
def plot_ifr(ax, name, color): """ Plots the gas inflow rate on a given matplotlib subplot given the name of the VICE output Parameters ========== ax :: subplot The matplotlib axis to plot the inflow rate on name :: str The name of the VICE output color :: str The name of the color to plot in """ out = vice.output(name) ax.plot(out.history["time"], out.history["ifr"], linestyle = '--', c = visuals.colors()[color])
def plot_inset(inset, name, color, **kwargs): """ Plots [O/Fe]-[Fe/H] tracks on a set of inset axes Parameters ========== inset :: subplot The matplotlib axis object to plot the tracks on name :: str The name of the VICE output color :: str The color to plot the output in kwargs :: varying types Other keyword arguments to pass to inset.plot """ out = vice.output(name) inset.plot(out.history["[Fe/H]"], out.history["[O/Fe]"], c=colors()[color], **kwargs)
def plot_reference(axes): """ Plots the [O/Fe]-[Fe/H] tracks and the stellar [O/Fe] distribution on the proper set of axes Parameters ========== axes :: list The list of matplotlib axis objects to plot on """ out = vice.output("../../simulations/default") axes[-2].plot(out.history["[Fe/H]"], out.history["[O/Fe]"], c=colors()["black"], linestyle=':') bins = list( map(lambda x, y: (x + y) / 2., out.mdf["bin_edge_left"], out.mdf["bin_edge_right"])) axes[-1].plot(bins, out.mdf["dN/d[O/Fe]"], c=colors()["black"], linestyle=':')
def plot_output(axes, name, color): """ Plots a VICE output on the output figure Parameters ========== axes :: 1-D list The list of matplotlib axis objects to plot on name :: str The name of the VICE output color :: str The name of the color to plot in """ out = vice.output(name) axes[0].plot(out.history["[Fe/H]"], out.history["[Sr/Fe]"], c=visuals.colors()[color]) bin_centers = list( map(lambda x, y: (x + y) / 2., out.mdf["bin_edge_left"], out.mdf["bin_edge_right"])) axes[1].plot(bin_centers, out.mdf["dn/d[sr/fe]"], c=visuals.colors()[color])
def plot_output_3axes(axes, name, color): """ Overrides the visuals.plot_output_3axes function to omit time = 0 for the infall rate. VICE does not know the infall rate at time = 0 when ran in star formation mode. """ out = vice.output(name) axes[0].plot(out.history["time"][1:], out.history["ifr"][1:], c=visuals.colors()[color], linestyle='--') axes[0].plot(out.history["time"], out.history["sfr"], c=visuals.colors()[color], linestyle='-') axes[1].plot(out.history["[Fe/H]"], out.history["[O/Fe]"], c=visuals.colors()[color]) axes[2].plot(list( map(lambda x, y: (x + y) / 2., out.mdf["bin_edge_left"], out.mdf["bin_edge_right"])), out.mdf["dn/d[O/Fe]"], c=visuals.colors()[color])
def main(): """ Runs the tests on the singlezone object, the output object, and the mirror function. """ warnings.filterwarnings("ignore") print("=================================================================") print("TESTING: vice.singlezone") print(" vice.output") print(" vice.mirror") out = open("test_sz_output_mirror.out", 'w') _MODES_ = ["ifr", "sfr", "gas"] _IMF_ = ["kroupa", "salpeter"] _ETA_ = [2.5, lambda t: 2.5 * math.exp(-t / 4.0)] _ZIN_ = [ 0, 1.0e-8, lambda t: 1.0e-8 * (t / 10.0), { "o": lambda t: 0.0057 * (t / 10.0), "fe": 0.0013 } ] _RECYCLING_ = ["continuous", 0.4] _RIA_ = ["plaw", "exp", lambda t: t**-1.5] _TAU_STAR_ = [2.0, lambda t: 2.0 + t / 10.0] _SCHMIDT_ = [False, True] _AGB_MODEL_ = ["cristallo11", "karakas10"] a = 0 b = 2304 keys = ["success", "failure"] singlezone_tracker = dict(zip(keys, [0, 0])) mirror_tracker = dict(zip(keys, [0, 0])) output_tracker = dict(zip(keys, [0, 0])) history_tracker = dict(zip(keys, [0, 0])) mdf_tracker = dict(zip(keys, [0, 0])) for i in _MODES_: for j in _IMF_: for k in _ETA_: for l in _ZIN_: for m in _RECYCLING_: for n in _RIA_: for o in _TAU_STAR_: for p in _SCHMIDT_: for q in _AGB_MODEL_: metadata = dict( elements=["fe", "o", "c"], mode=i, IMF=j, eta=k, Zin=l, recycling=m, RIa=n, tau_star=o, schmidt=p, agb_model=q, dt=0.05) try: vice.singlezone(**metadata).run( _OUTTIMES_, overwrite=True) singlezone_tracker["success"] += 1 except: singlezone_tracker["failure"] += 1 try: foo = vice.history("onezonemodel") assert isinstance( foo, vice.dataframe) history_tracker["success"] += 1 except: history_tracker["failure"] += 1 try: foo = vice.mdf("onezonemodel") assert isinstance( foo, vice.dataframe) mdf_tracker["success"] += 1 except: mdf_tracker["failure"] += 1 success = True try: foo = vice.output("onezonemodel") assert isinstance(foo, vice.output) assert isinstance( foo.history, vice.dataframe) assert isinstance( foo.mdf, vice.dataframe) assert isinstance( foo.ccsne_yields, vice.dataframe) assert isinstance( foo.sneia_yields, vice.dataframe) assert isinstance( foo.elements, tuple) output_tracker["success"] += 1 try: mir = vice.mirror(foo) assert isinstance( mir, vice.singlezone) mirror_tracker["success"] += 1 except: mirror_tracker["failure"] += 1 except: output_tracker["failure"] += 1 a += 1 sys.stdout.write("Progress: %.1f%%\r" % (a / b * 100)) sys.stdout.flush() ####### message = """\ vice.singlezone :: %d successes :: %d failures vice.history :: %d successes :: %d failures vice.mdf :: %d successes :: %d failures vice.output :: %d successes :: %d failures vice.mirror :: %d successes :: %d failures \ """ % (singlezone_tracker["success"], singlezone_tracker["failure"], history_tracker["success"], history_tracker["failure"], mdf_tracker["success"], mdf_tracker["failure"], output_tracker["success"], output_tracker["failure"], mirror_tracker["success"], mirror_tracker["failure"]) print(message) out.write(message) out.close()
def main(output, stem): r""" Produce a figure comparing the model-predicted age-[O/H] and age-[Fe/H] relations in the solar annulus as predicted by VICE in comparison to the relations reported by Feuillet et al. (2018, 2019) [1]_ [2]_. Parameters ---------- output : ``str`` The relative or absolute path to the VICE output containing the model predicted data. stem : ``str`` The relative or absolute path to the output image, with no extension. This function will save the figure in both PDF and PNG formats. .. [1] Feuillet et al. (2018), MNRAS, 477, 2326 .. [2] Feuillet et al. (2019), MNRAS, 489, 1742 """ ax1, ax2 = setup_axes() output = vice.output(output) output.stars["abszfinal"] = [ abs(_) for _ in zheights(output.name)[:output.stars.size[0]] ] min_radius = 7 max_radius = 9 min_z = 0 max_z = 0.5 # majority of plotting and calculations done by these functions in # galactic_regions.py plot_amr(ax1, "O", "H", output, min_radius, max_radius, min_z, max_z) sc = plot_amr(ax2, "Fe", "H", output, min_radius, max_radius, min_z, max_z) median_ages(ax1, "O", "H", output, min_radius, max_radius, min_z, max_z, zorder=2) median_ages(ax2, "Fe", "H", output, min_radius, max_radius, min_z, max_z, label=True, zorder=2) feuillet2019_amr(ax1, "O", "H", min_radius, max_radius, min_z, max_z, zorder=2) feuillet2019_amr(ax2, "Fe", "H", min_radius, max_radius, min_z, max_z, label=True, zorder=2) feuillet2018_amr(ax1, 'o') feuillet2018_amr(ax2, 'fe', label=True) # legend and colorbar formatting kwargs = { "ncol": 1, "frameon": False, "fontsize": 20, "loc": mpl_loc("lower left"), "bbox_to_anchor": (0.01, 0.01) } handles, labels = ax2.get_legend_handles_labels() handles = [handles[1], handles[2], handles[0]] labels = [labels[1], labels[2], labels[0]] ax2.legend(handles, labels, **kwargs) cbar_ax = plt.gcf().add_axes([0.92, 0.05, 0.02, 0.95]) cbar = plt.colorbar(sc, cax=cbar_ax, pad=0.0, orientation="vertical") cbar.set_label(r"$R_\text{gal}$ of birth [kpc]", labelpad=10) cbar.set_ticks(range(2, 16, 2)) plt.tight_layout() plt.subplots_adjust(hspace=0, right=0.8) cbar_ax.set_position([ ax2.get_position().x1, ax2.get_position().y0, 0.05, ax1.get_position().y1 - ax2.get_position().y0 ]) plt.savefig("%s.pdf" % (stem)) plt.savefig("%s.png" % (stem)) plt.close()
def main(element, outputs, stem, radial_bins = [3, 5, 7, 9, 11, 13, 15], z_bins = [0.0, 0.5, 1.0, 2.0], labels = ["Inside-Out", "Late-Burst", "Outer-Burst"], # apogee = False, colors = ["black", "red", "gold", "green", "blue", "darkviolet"]): r""" For some element X, plot the metallicity distribution functions (MDFs) in [X/H] in different galactic regions as predicted by a given VICE model, with or without a comparison to the APOGEE data. Parameters ---------- element : ``str`` The element X to plot the distributions in [X/H] for. Must be included in the model output. outputs : ``list`` [elements of type ``str``] A list of relative or absolute or absolute paths to the VICE outputs to predictions of. stem : ``str`` The relative or absolute path to the output image, with no extension. This function will save the figure in both PDF and PNG formats. radial_bins : ``list`` [default : [3, 5, 7, 9, 11, 13, 15]] The bin-edges in galactocentric radius in kpc in which to compute the MDFs. Must be in ascending order. z_bins : ``list`` [default : [0.0, 0.5, 1.0, 2.0]] The bin-edges in height above/below the disk midplane in kpc in which to compute the MDFs. Must be in ascending order. Sign is neglected. labels : ``list`` [elements of type ``str``] [default : ["Inside-Out", "Late-Burst", "Outer-Burst"]] A descriptor to attach to each of the ``outputs`` to distinguish which panel belongs to which model visually. apogee : ``bool`` [default : False] Whether or not to plot the APOGEE data for comparison in another column of panels. colors : ``list`` [elements of type ``str``] [default : ["black", "red", "gold", "green", "blue", "darkviolet"]] The colors to use for each bin in radius. Must contain at least one the number of elements in ``radial_bins`` minus 1. The output figure will show each model as a column of panels, with a row for each bin in |z|, and bins in radius shown color-coded on the same panel. Points will be plotted at the top of the bottom row of panels corresopnding to what the mode abundance would be if it followed the Johnson et al. (2021) adopted form exactly. .. note:: The distributions will be normalized such that the area over their extent is equal to one. """ apogee = True # used to be keyword argument # finish setting up the subplots axes = setup_axes(element, ncols = len(outputs) + int(apogee), nrows = len(z_bins) - 1) if apogee: labels.append("APOGEE DR16") for i in range(len(axes[0])): axes[0][i].set_title(labels[i], fontsize = 25) z_bins = list(sorted(z_bins))[::-1] # reverse ordering -> high z at top for i in range(len(axes)): axes[i][-1].set_ylabel( r"$\left|z\right|$ = %g - %g" % (z_bins[i + 1], z_bins[i])) # read in the model-predicted data, calculate the plot distributions for # all models in all regions outputs = [vice.output(_) for _ in outputs] for i in outputs: i.stars["abszfinal"] = [abs(_) for _ in zheights( i.name)[:i.stars.size[0]]] for i in range(len(axes[-1])): for j in range(len(radial_bins) - 1): axes[-1][i].scatter(target_mode_abundance(radial_bins[j]), {"o": 4.25, "fe": 3.4}[element.lower()], c = named_colors()[colors[j]], marker = markers()["point"], s = 40, zorder = 10) for i in range(len(z_bins) - 1): for j in range(len(outputs)): for k in range(len(radial_bins) - 1): plot_predicted_mdf(axes[i][j], element, outputs[j].stars, radial_bins[k], radial_bins[k + 1], z_bins[i + 1], z_bins[i], colors[k]) # label = k in [2 * i, 2 * i + 1] and not j) if apogee: for k in range(len(radial_bins) - 1): plot_apogee_distributions(axes[i][-1], element, radial_bins[k], radial_bins[k + 1], z_bins[i + 1], z_bins[i], colors[k], label = not i) else: pass # plot the legends and save the figure # legend_kwargs = { # "loc": mpl_loc("upper left"), # "ncol": 1, # "fontsize": 20, # "frameon": False, # "bbox_to_anchor": (0.01, 0.99), # "handlelength": 0 # } # for i in range(len(z_bins) - 1): # leg = axes[i][0].legend(**legend_kwargs) # for j in range(len(leg.legendHandles)): # leg.get_texts()[j].set_color(colors[len(leg.legendHandles) * i + j]) # leg.legendHandles[j].set_visible(False) legend_kwargs = { "loc": mpl_loc("upper right"), "ncol": 1, "fontsize": 18, "frameon": False, "bbox_to_anchor": (0.99, 0.99), "handlelength": 0 } axes[0][1].legend(**legend_kwargs) for i in range(len(radial_bins) - 1): leg.get_texts()[i].set_color(colors[i]) leg.legendHandles[i].set_visible(False) plt.tight_layout() plt.subplots_adjust(wspace = 0, hspace = 0, bottom = 0.1, left = 0.08) plt.savefig("%s.png" % (stem)) plt.savefig("%s.pdf" % (stem)) plt.close()
def main(upperleft, upperright, lowerleft, lowerright, stem, min_rgal = 7, max_rgal = 9, min_absz = 0, max_absz = 0.5, names = [["Constant SFR", "Inside-Out"], ["Late-Burst", "Outer-Burst"]]): r""" Plot a 2x2 panel figure showing comparing the model-predicted age-[O/Fe] relations to the Feuillet et al. (2019) [1]_ measurements in a given galactic region. Parameters ---------- upperleft : ``str`` The relative or absolute path to the VICE output whose predicted age-[O/Fe] relation is to go in the upper-left panel. upperright: ``str`` The relative or absolute path to the VICE output whose predicted age-[O/Fe] relation is to go in the upper-right panel. lowerleft : ``str`` The relative or absolute path to the VICE output whose predicted age-[O/Fe] relation is to go in the lower-left panel. lowerright : ``str`` The relative or absolute path to the VICE output whose predicted age-[O/Fe] relation is to go in the lower-right panel. stem : ``str`` The relative or absolute path to the output image, with no extension. This function will save the figure in both PDF and PNG formats. min_rgal : ``float`` [default : 7.0] Minimum galactocentric radius in kpc. max_rgal : ``float`` [default : 9.0] Maximum galactocentric radius in kpc. min_absz : ``float`` [default : 0.0] Minimum height above/below the disk midplane |z| in kpc. max_absz : ``float`` [default : 0.5] Maximum height above/below the disk midplane |z| in kpc. names : 2x2 element ``list`` [elements of type ``str``] [default : [["Constant SFR", "Inside-Out"], ["Late-Burst", "Outer-Burst"]]] Short descriptors for each model to denote which is which on each panel. .. [1] Feuillet et al. (2019), MNRAS, 489, 1742 """ global MIN_RGAL global MAX_RGAL global MIN_ABSZ global MAX_ABSZ global ZONE_MIN global ZONE_MAX MIN_RGAL = min_rgal MAX_RGAL = max_rgal MIN_ABSZ = min_absz MAX_ABSZ = max_absz ZONE_MIN = int(MIN_RGAL / ZONE_WIDTH) ZONE_MAX = int((MAX_RGAL - ZONE_WIDTH) / ZONE_WIDTH) axes = setup_axes() outputs = [ [vice.output(upperleft), vice.output(upperright)], [vice.output(lowerleft), vice.output(lowerright)] ] for i in range(2): for j in range(2): axes[i][j].text(1, 0.4, names[i][j], fontsize = 18) feuillet2019_amr(axes[i][j], "O", "Fe", min_rgal, max_rgal, min_absz, max_absz, label = not i and not j) outputs[i][j].stars["abszfinal"] = [abs(k) for k in zheights( outputs[i][j].name)[:outputs[i][j].stars.size[0]]] sc = plot_relation(axes[i][j], outputs[i][j], label = i == 0 and j == 0) axes[0][0].legend(loc = mpl_loc("upper left"), ncol = 1, frameon = False, bbox_to_anchor = (0.01, 0.87), handletextpad = 0.4, fontsize = 18) cbar_ax = plt.gcf().add_axes([0.92, 0.05, 0.02, 0.95]) cbar = plt.colorbar(sc, cax = cbar_ax, pad = 0.0, orientation = "vertical") cbar.set_label(r"$R_\text{gal}$ of birth [kpc]", labelpad = 10) cbar.set_ticks(range(2, 16, 2)) plt.tight_layout() plt.subplots_adjust(hspace = 0, wspace = 0, left = 0.15, bottom = 0.1, right = 0.85) cbar_ax.set_position([ axes[-1][-1].get_position().x1, axes[-1][-1].get_position().y0, 0.05, axes[0][-1].get_position().y1 - axes[-1][-1].get_position().y0 ]) plt.savefig("%s.pdf" % (stem)) plt.savefig("%s.png" % (stem))
def main(element, outputs, stem, radii = [[5, 7], [7, 9], [9, 11], [11, 13]], feuillet2019 = True, labels = ["Constant SFR", "Inside-Out", "Late-Burst", "Outer-Burst"], **subplots_adjust_kwargs): r""" Produce a plot comparing the age-[X/H] relation predicted by a set of models in various galactic regions. Parameters ---------- element : ``str`` The element X in age-[X/H] relation. outputs : array-like [elements of type ``str``] The relative or absolute paths to the VICE outputs whose predicted age-[X/H] relations are to be visualized. stem : ``str`` The relative or absolute path to the output image, with no extension. This function will save the figure in both PDF and PNG formats. radii : ``list`` [elements are two-component ``list``s storing ``float``s] [default : [[5, 7], [7, 9], [9, 11], [11, 13]]] The ranges in radius defining the galactic regions to visualize the age-[X/H] relation within. feuillet2019 : ``bool`` [default : True] Whether or not to include the measurements of Feuillet et al. (2019) [1]_ as a comparison. labels : ``list`` [elements of type ``str``] Short descriptors distinguishing which model is which in the visualization. Models will be plotted in the order in which they appear in the ``outputs`` array. subplots_adjust_kwargs : varying types Additional keywords to pass to ``pyplot.subplots_adjust``. .. [1] Feuillet et al. (2019), MNRAS, 489, 1742 """ axes = setup_axes(element, nrows = len(outputs), radii = radii, labels = labels) outputs = [vice.output(_) for _ in outputs] for i in outputs: i.stars["abszfinal"] = [abs(_) for _ in zheights( i.name)[:i.stars.size[0]]] for i in range(len(axes)): for j in range(len(axes[i])): # majority of the plotting and calculations done by these # functions in galactic_regions.py print([i, j]) sc = plot_amr(axes[i][j], element, 'h', outputs[i], radii[j][0], radii[j][1], 0.0, 0.5) median_ages(axes[i][j], element, 'h', outputs[i], radii[j][0], radii[j][1], 0.0, 0.5, label = not i and not j and feuillet2019) if feuillet2019: feuillet2019_amr(axes[i][j], element, 'h', radii[j][0], radii[j][1], 0.0, 0.5, label = not i and not j) # legend, colorbar, and subplots formatting if feuillet2019: legend_kwargs = { "ncol": 1, "frameon": False, "fontsize": 20, "loc": mpl_loc("lower left"), "bbox_to_anchor": (0.01, 0.01) } axes[0][0].legend(**legend_kwargs) else: pass cbar_ax = plt.gcf().add_axes([0.92, 0.05, 0.02, 0.95]) cbar = plt.colorbar(sc, cax = cbar_ax, orientation = "vertical") cbar.set_label(r"$R_\text{gal}$ of birth [kpc]", labelpad = 10) cbar.set_ticks(range(2, 16, 2)) plt.tight_layout() default_adjustments = { "hspace": 0, "wspace": 0, "left": 0.09, "right": 0.91 } for i in subplots_adjust_kwargs.keys(): default_adjustments[i] = subplots_adjust_kwargs[i] plt.subplots_adjust(**default_adjustments) cbar_ax.set_position([ axes[-1][-1].get_position().x1, axes[-1][-1].get_position().y0, 0.025, axes[0][-1].get_position().y1 - axes[-1][-1].get_position().y0 ]) plt.savefig("%s.png" % (stem)) plt.savefig("%s.pdf" % (stem))
def main(element_x, element_y, output, stem): r""" Illustrate the age-[X/Y] relation in 12 galactic regions as predicted by a given VICE model in comparison to the measurements of Feuillet et al. (2019) [1]_. Parameters ---------- element_x : ``str`` The element X in age-[X/Y] relation. element_y : ``str`` The element Y in age-[X/Y] relation. output : ``str`` The relative or absolute path to the VICE output whose predicted age-[X/Y] relation is to be visualized here. stem : ``str`` The relative or absolute path to the output image, with no extension. This function will save the figure in both PDF and PNG formats. .. [1] Feuillet et al. (2019), MNRAS, 489, 1742 """ axes = setup_axes(element_x, element_y)[:-1] output = vice.output(output) output.stars["abszfinal"] = [ abs(i) for i in zheights(output.name)[:output.stars.size[0]] ] for i in range(len(axes)): for j in range(len(axes[i])): print([i, j]) sc = plot_amr(axes[i][j], element_x, element_y, output, RADII[j], RADII[j + 1], HEIGHTS[i + 1], HEIGHTS[i]) if i == 2 and j == 1: xvals, yvals = median_ages(axes[i][j], element_x, element_y, output, RADII[j], RADII[j + 1], HEIGHTS[i + 1], HEIGHTS[i]) else: median_ages(axes[i][j], element_x, element_y, output, RADII[j], RADII[j + 1], HEIGHTS[i + 1], HEIGHTS[i], label=not i and not j) feuillet2019_amr(axes[i][j], element_x, element_y, RADII[j], RADII[j + 1], HEIGHTS[i + 1], HEIGHTS[i], label=i == 0 and j == 0) for i in range(len(axes)): for j in range(len(axes[i])): axes[i][j].plot(xvals, yvals, c=named_colors()["black"]) legend_kwargs = {"ncol": 1, "frameon": False, "fontsize": 20} if element_y.lower() == 'h': legend_kwargs["loc"] = mpl_loc("lower left") legend_kwargs["bbox_to_anchor"] = (0.01, 0.01) else: legend_kwargs["loc"] = mpl_loc("upper left") legend_kwargs["bbox_to_anchor"] = (0.01, 0.99) axes[0][0].legend(**legend_kwargs) cbar_ax = plt.gcf().add_axes([0.92, 0.05, 0.02, 0.95]) cbar = plt.colorbar(sc, cax=cbar_ax, pad=0.0, orientation="vertical") cbar.set_label(r"$R_\text{gal}$ of birth [kpc]", labelpad=10) cbar.set_ticks(range(2, 16, 2)) plt.tight_layout() plt.subplots_adjust(hspace=0, wspace=0, bottom=0.08, right=0.91, left=0.09) cbar_ax.set_position([ axes[-1][-1].get_position().x1, axes[-1][-1].get_position().y0, 0.025, axes[0][-1].get_position().y1 - axes[-1][-1].get_position().y0 ]) plt.savefig("%s.png" % (stem)) plt.savefig("%s.pdf" % (stem)) plt.close()
def main(outputs, stem, labels=["Constant SFR", "Inside-Out", "Late-Burst", "Outer-Burst"], times=[2, 4, 6, 8, 10, END_TIME], colors=["red", "gold", "green", "blue", "darkviolet", "black"], ylim=[0.5, 20], yticks=[1, 10]): r""" Produce a plot of the SFE timescale :math:`\tau_\star` as a function of galactocentric radius at various timestamps for a set of VICE models. Parameters ---------- outputs : ``list`` [elements of type ``str``] The relative or absolute paths to the VICE outputs whose predicted SFE timescales are to be visualized here. They will be plotted in the order they appear in this list. stem : ``str`` The relative or absolute path to the output image, with no extension. This function will save the figure in both PDF and PNG formats. labels : array-like [elements of type ``str``] or ``None`` [default : ["Constant SFR", "Inside-Out", "Late-Burst", "Outer-Burst"]] Short descriptors for each of the models to be plotted. Must contain at least as many elements as ``outputs``. If ``None``, no labels will be included. times : array-like [elements of type ``float``] [default : [2, 4, 6, 8, 10, 13.2]] The time-stamps at which to plot the SFE timescale as a function of radius. colors : array-like [elements of type ``str``] [default : ["red", "gold", "green", "blue", "darkviolet", "black"]] The colors in which to plot the SFE timescales. Must contain at least as many elements as ``outputs``. ylim : array-like [default : [0.5, 20]] y-axis limits for :math:`\tau_\star` in Gyr. Note that this function will use a log-scaled y-axis. yticks : array-like [default : [1, 10]] The values to place major ticks on the y-axis at. """ axes = setup_axes(len(outputs)) for i in range(len(axes)): axes[i].set_yscale("log") axes[i].set_ylim(ylim) axes[i].set_yticks(yticks) yticklabel_formatter(axes[i]) if labels is not None: axes[i].set_title(labels[i], fontsize=25) outputs = [vice.output(_) for _ in outputs] for i in range(len(outputs)): plot_sfe(axes[i], outputs[i], times, colors, label=not i) leg = axes[0].legend( loc=mpl_loc("upper left"), ncol=1, frameon=False, bbox_to_anchor=(0.01, 0.99), handlelength=0, # fontsize = 20, labelspacing = 0.2) fontsize=20) for i in range(len(times)): leg.get_texts()[i].set_color(colors[i]) leg.legendHandles[i].set_visible(False) plt.tight_layout() plt.subplots_adjust(wspace=0, bottom=0.2) plt.savefig("%s.png" % (stem)) plt.savefig("%s.pdf" % (stem))