Esempio n. 1
0
def plot_radius_density(data_dir, halo_id):
    xfield = 'radius'
    yfield = 'density'
    filename = os.path.join(data_dir, "%s_%06d.h5" % (yfield, halo_id))

    fontsize = 14
    my_fig = GridFigure(1,
                        1,
                        figsize=(6, 4.5),
                        top_buffer=0.14,
                        bottom_buffer=0.13,
                        left_buffer=0.16,
                        right_buffer=0.19)

    my_axes = my_fig[0]
    my_axes.set_xscale('log')
    my_axes.set_yscale('log')

    my_cax = my_fig.add_cax(my_axes,
                            "right",
                            buffer=0.02,
                            length=0.95,
                            width=0.04)
    plot_phase(filename,
               'cell_mass',
               'Msun',
               my_axes,
               my_cax=my_cax,
               cmap=yt_colormaps['dusk'])

    my_cax.yaxis.set_label_text("M [M$_{\\odot}$]")

    xlim = (2e-6, 2e2)
    tx = twin_unit_axes(my_axes, xlim, "r", "pc", top_units="AU")

    ylim = (1e-25, 1e-10)
    ymajor = np.logspace(-25, -10, 6)
    yminor = np.logspace(-25, -10, 16)
    ylabel = "$\\rho$ [g/cm$^{-3}$]"
    mirror_yticks(my_axes, ylim, ymajor, yminor=yminor)
    draw_major_grid(my_axes, 'y', ymajor)
    my_axes.yaxis.set_label_text(ylabel)

    output_filename = "figures/%s_%s.pdf" % \
      (xfield, yfield)
    pyplot.savefig(output_filename)
Esempio n. 2
0
def plot_density_H2_fraction(data_dir, halo_id):
    xfield = 'density'
    yfield = 'H2_fraction'
    filename = os.path.join(data_dir, "%s_%06d.h5" % (yfield, halo_id))

    fontsize = 14
    my_fig = GridFigure(1,
                        1,
                        figsize=(6, 4.5),
                        top_buffer=0.03,
                        bottom_buffer=0.13,
                        left_buffer=0.14,
                        right_buffer=0.19)

    my_axes = my_fig[0]
    xscale = 'log'
    yscale = 'log'

    field = 'cell_mass'
    units = 'Msun'
    cmap = yt_colormaps['dusk']
    clabel = "M [M$_{\\odot}$]"

    xlim = (1e-3, 1e13)
    xmajor = np.logspace(-3, 12, 6)
    xminor = np.logspace(-3, 13, 17)
    xlabel = "n [cm$^{-3}$]"

    ylim = (1e-8, 1)
    ymajor = np.logspace(-8, 0, 9)
    yminor = None
    ylabel = "f$_{\\rm H_{2}}$"

    output_filename = "figures/%s_%s.pdf" % \
      (xfield, yfield)

    make_phase_plot(my_fig, my_axes, filename, field, units, cmap, clabel,
                    xlim, xmajor, xminor, xscale, xlabel, ylim, ymajor, yminor,
                    yscale, ylabel, output_filename)
Esempio n. 3
0
def get_distribution(vals, n=101):
    if vals.size == 0:
        return np.zeros(n)
    id_sort = np.argsort(vals)
    dist = vals[id_sort[np.clip(
        np.round(np.linspace(0, 1, n) * id_sort.size).astype(int), 0,
        id_sort.size - 1)]]
    return dist


if __name__ == "__main__":
    my_fig = GridFigure(1,
                        1,
                        figsize=(6, 4.5),
                        left_buffer=0.17,
                        right_buffer=0.04,
                        bottom_buffer=0.13,
                        top_buffer=0.11,
                        vertical_buffer=0)

    # palette = sns.color_palette(palette="colorblind")
    palette = \
      [(0.0, 0.4470588235294118, 0.6980392156862745),
       (0.0, 0.6196078431372549, 0.45098039215686275),
       (0.8352941176470589, 0.3686274509803922, 0.0),
       (0.8, 0.4745098039215686, 0.6549019607843137),
       (0.9411764705882353, 0.8941176470588236, 0.25882352941176473),
       (0.33725490196078434, 0.7058823529411765, 0.9137254901960784)]

    cmap = yt_colormaps["arbre"]
Esempio n. 4
0
def plot_velocity_profiles(data_dir, file_prefix):
    my_fig = GridFigure(1,
                        1,
                        figsize=(6, 4.5),
                        top_buffer=0.14,
                        bottom_buffer=0.12,
                        left_buffer=0.09,
                        right_buffer=0.02)

    # http://www.colourlovers.com/palette/1329926/graphic_artist.
    # colors = ["#B00029", "#90B004", "#19849C", "#851370", "#544D4D", "black"]
    colors = ["red", "green", "blue", "purple", "#544D4D", "black"]

    my_axes = my_fig[0]
    my_axes.set_xscale('log')

    fields = [
        "velocity_magnitude", "tangential_velocity_magnitude",
        "velocity_spherical_radius", "sound_speed"
    ]

    for i, field in enumerate(fields):
        filename = os.path.join(
            data_dir, f"{file_prefix}_2D_profile_radius_{field}_None.h5")
        plot_profile_distribution(my_axes,
                                  filename,
                                  'cell_mass',
                                  x_units="pc",
                                  y_units='km/s',
                                  alpha_scale=0.7,
                                  pkwargs=dict(color=colors[i], linewidth=1))

    fn = os.path.join(data_dir,
                      f"{file_prefix}_1D_profile_radius_cell_mass.h5")
    pds = yt.load(fn)
    pradius = pds.profile.x.to("pc")
    vsigma = pds.profile.standard_deviation['data',
                                            'velocity_magnitude'].to("km/s")
    my_axes.plot(pradius[vsigma > 0],
                 vsigma[vsigma > 0],
                 alpha=0.9,
                 linewidth=1,
                 color=colors[4],
                 zorder=998)

    field = "matter_mass"
    fn = os.path.join(data_dir, f"{file_prefix}_1D_profile_radius_None.h5")
    mds = yt.load(fn)
    radius = mds.profile.x.to("pc")
    mass = mds.profile[field]
    dfil = mass > 0
    v_sp = np.sqrt(G * mass[dfil].cumsum() / radius[dfil]).to("km/s")
    my_axes.plot(radius[dfil],
                 v_sp,
                 alpha=0.9,
                 linewidth=1,
                 color=colors[5],
                 zorder=997)

    ylim = (-5, 13)
    ymajor = np.arange(-5, 16, 5.)
    yminor = np.arange(-5, 15, 1.)
    my_axes.yaxis.set_label_text("v [km / s]")
    my_axes.yaxis.labelpad = -3
    draw_major_grid(my_axes,
                    'y',
                    ymajor,
                    color='black',
                    linestyle='-',
                    linewidth=1,
                    alpha=0.2)
    ty = mirror_yticks(my_axes, ylim, ymajor, yminor=yminor)

    xlim = (1e-1, 2e2)
    tx = twin_unit_axes(my_axes, xlim, "r", "pc", top_units="AU")

    labels = [
        "|v|", "v$_{\\rm tan}$", "v$_{\\rm rad}$", "c$_{\\rm s}$", "$\\sigma$",
        "v$_{\\rm c}$"
    ]
    dist = [True] * 4 + [False] * 2
    plot_items = list(zip(colors, labels, dist))
    plot_profile_distribution_legend(my_axes, plot_items, alpha_scale=0.7)

    pyplot.savefig("figures/velocity_profiles.pdf")
Esempio n. 5
0
    image = my_axes.scatter(px,
                            py,
                            c=color,
                            s=s,
                            norm=mynorm,
                            cmap=cmap,
                            edgecolor="black",
                            linewidth=0.5)
    return image


if __name__ == "__main__":
    my_fig = GridFigure(2,
                        1,
                        figsize=(5, 8),
                        square=True,
                        left_buffer=0.02,
                        right_buffer=0.2,
                        vertical_buffer=0.02)
    cbar_buffer = 0.02
    cbar_length = 0.95
    cbar_width = 0.05
    data_dir = "normal_BG1/halo_2170858"
    # data_dir = "normal_BG1/halo_2171203"
    dsfn = "RedshiftOutput0077"
    # data_dir = "Rarepeak_LWB/halo_1367222/"
    # data_dir = "Rarepeak_LWB/halo_1372918"
    # dsfn = "RedshiftOutput0041"

    proj_axis = "x"
    for i, my_axes in enumerate(my_fig):
from matplotlib import pyplot, ticker
import numpy as np
# import seaborn as sns
from scipy import stats
import yt

from grid_figure import GridFigure

if __name__ == "__main__":
    my_fig = GridFigure(3, 1, figsize=(4.5, 7),
                        left_buffer=0.22, right_buffer=0.02,
                        bottom_buffer=0.09, top_buffer=0.02,
                        vertical_buffer=0)

    # palette = sns.color_palette(palette="colorblind")
    palette = \
      [(0.0, 0.4470588235294118, 0.6980392156862745),
       (0.0, 0.6196078431372549, 0.45098039215686275),
       (0.8352941176470589, 0.3686274509803922, 0.0),
       (0.8, 0.4745098039215686, 0.6549019607843137),
       (0.9411764705882353, 0.8941176470588236, 0.25882352941176473),
       (0.33725490196078434, 0.7058823529411765, 0.9137254901960784)]

    labels = ["rare peak", "normal", "void"]
    ds_list = [
        yt.load("Rarepeak_LWB/black_hole_growth_stats.h5"),
        yt.load("normal_BG1/black_hole_growth_stats.h5"),
        yt.load("void_BG1/black_hole_growth_stats.h5")
    ]

    r_growth = [ds.data["relative_growth"] - 1 for ds in ds_list]
def plot_timescale_profiles(data_dir, file_prefix):
    my_fig = GridFigure(1,
                        1,
                        figsize=(6, 4.5),
                        top_buffer=0.13,
                        bottom_buffer=0.12,
                        left_buffer=0.14,
                        right_buffer=0.02,
                        horizontal_buffer=0.05,
                        vertical_buffer=0)

    my_axes = my_fig[0]
    my_axes.set_xscale('log')
    my_axes.set_yscale('log')

    xlim = (5e-3, 3e2)
    tx = twin_unit_axes(my_axes, xlim, "r", "pc", top_units="AU")

    fields = [
        "sound_crossing_time", "total_dynamical_time", "cooling_time",
        "vortical_time"
    ]
    units = ["yr", f"{np.sqrt(2)}*yr", "yr", f"{1/(2*np.pi)}*yr"]
    labels = ["sound-crossing", "free-fall", "cooling", "mixing"]
    colors = ["orange", "red", "green", "blue"]

    filename = os.path.join(data_dir, "DD0295_1D_profile_radius_cell_mass.h5")
    ds = yt.load(filename)

    x_data = ds.profile.x.to("pc")
    used = ds.profile.used
    for field, unit, label, color in zip(fields, units, labels, colors):
        if field == "sound_crossing_time":
            cs = ds.profile["data", "sound_speed"]
            vt = ds.profile.standard_deviation["data", "velocity_magnitude"]
            v = np.sqrt(cs**2 + vt**2)
            y_data = (2 * x_data / v).to(unit)
        else:
            y_data = ds.profile["data", field].to(unit)

        my_axes.plot(x_data[used],
                     y_data[used],
                     color=color,
                     alpha=0.7,
                     linewidth=1.5,
                     label=label)

    ylim = (1e4, 1e8)
    ymajor = np.logspace(2, 10, 5)
    yminor = np.logspace(1, 9, 5)
    draw_major_grid(my_axes,
                    'y',
                    ymajor,
                    color='black',
                    linestyle='-',
                    linewidth=1,
                    alpha=0.2)
    ty = mirror_yticks(my_axes, ylim, ymajor, yminor=yminor)
    my_axes.yaxis.set_label_text("t [yr]")
    my_axes.legend()
    # my_axes.yaxis.labelpad = 4

    pyplot.savefig("figures/timescale_profiles.pdf")
Esempio n. 8
0
    fn_head = '%s' % fn_head

    # Get the list of ion_fields from the first file available

    ion_fields = [
        'density', 'metal_density', 'temperature', 'H_number_density',
        'C_p1_number_density', 'C_p2_number_density', 'Ne_p7_number_density',
        'O_p5_number_density', 'Si_p3_number_density'
    ]

    fig = GridFigure(3,
                     3,
                     top_buffer=0.01,
                     bottom_buffer=0.08,
                     left_buffer=0.12,
                     right_buffer=0.02,
                     vertical_buffer=0.08,
                     horizontal_buffer=0.08,
                     figsize=(12, 8))

    # Step through each ion and make plots of azimuthal angle vs N
    for i, field in enumerate(ion_fields):
        for c, (k, v) in enumerate(profiles_dict.items()):
            n_files = len(v)
            cdens_arr = np.array([])
            a_arr = np.array([])
            r_arr = np.array([])
            for j in range(n_files):
                f = h5.File(v[j], 'r')
                a_arr = np.concatenate((a_arr, f['phi'].value))
Esempio n. 9
0
import numpy as np
# import seaborn as sns
from scipy import stats
import yt
from yt.utilities.cosmology import Cosmology

from grid_figure import GridFigure

from yt.extensions.p3bh import *

if __name__ == "__main__":
    my_fig = GridFigure(2,
                        2,
                        figsize=(7, 5.5),
                        left_buffer=0.12,
                        right_buffer=0.04,
                        bottom_buffer=0.12,
                        top_buffer=0.02,
                        vertical_buffer=0.12,
                        horizontal_buffer=0.16)

    # palette = sns.color_palette(palette="colorblind")
    palette = \
      [(0.0, 0.4470588235294118, 0.6980392156862745),
       (0.0, 0.6196078431372549, 0.45098039215686275),
       (0.8352941176470589, 0.3686274509803922, 0.0),
       (0.8, 0.4745098039215686, 0.6549019607843137),
       (0.9411764705882353, 0.8941176470588236, 0.25882352941176473),
       (0.33725490196078434, 0.7058823529411765, 0.9137254901960784)]

    labels = ["rare peak", "normal", "void"]
Esempio n. 10
0
	log('Generating Plot 1')
	p1 = yt.OffAxisProjectionPlot(ds, E1, ('gas', 'H_number_density'), center=c, 
		width=width, data_source=box, north_vector=L, weight_field=None)
	log('Generating Plot 2')
	p2 = yt.OffAxisProjectionPlot(ds, E1, ('gas', 'Mg_p1_number_density'), center=c, 
		width=width, data_source=box, north_vector=L, weight_field=None)
	log('Generating Plot 3')
	p3 = yt.OffAxisProjectionPlot(ds, E1, ('gas', 'O_p5_number_density'), center=c, 
		width=width, data_source=box, north_vector=L, weight_field=None)
	log('Generating Plot 4')
	p4 = yt.OffAxisProjectionPlot(ds, E1, ('gas', 'Si_p3_number_density'), center=c,
		width=width, data_source=box, north_vector=L, weight_field=None)

	print("Stitching together")
	fig = GridFigure(2, 2, top_buffer=0.01, bottom_buffer=0.01, left_buffer=0.01, right_buffer=0.13, vertical_buffer=0.01, horizontal_buffer=0.01, figsize=(9,8))

	# Actually plot in the different axes
	plot1 = fig[0].imshow(p1.frb['H_number_density'], norm=LogNorm())
	# clim1 = plot1.get_clim()
	plot1.set_cmap('thermal')
	plot2 = fig[1].imshow(p2.frb['Mg_p1_number_density'], norm=LogNorm())
	# plot2.set_clim(clim)
	plot2.set_cmap('thermal')
	plot3 = fig[2].imshow(p3.frb['O_p5_number_density'], norm=LogNorm())
	# clim = plot3.get_clim()
	plot3.set_cmap('thermal')
	plot4 = fig[3].imshow(p4.frb['Si_p3_number_density'], norm=LogNorm())
	# plot4.set_clim(clim)
	plot4.set_cmap('thermal')
Esempio n. 11
0
        my_axes.axhline(y=ymaj,
                        color="black",
                        alpha=0.2,
                        linestyle=":",
                        zorder=1)

    return my_cax


if __name__ == "__main__":
    fontsize = 16
    cmap = yt_colormaps["algae"]
    my_fig = GridFigure(3,
                        1,
                        figsize=(6, 9),
                        left_buffer=0.18,
                        right_buffer=0.16,
                        bottom_buffer=0.08,
                        top_buffer=0.02,
                        vertical_buffer=0)

    data_dirs = ["Rarepeak_LWB", "normal_BG1", "void_BG1"]
    titles = ["rare peak", "normal", "void"]

for i, my_axes in enumerate(my_fig):
    my_cax = plot_profile(my_fig, my_axes, data_dirs[i], titles[i])

    if i == len(my_fig) - 1:
        my_axes.xaxis.set_label_text(
            "Bondi-Hoyle to Eddington ratio [1 / M$_{\\odot}$]",
            fontsize=fontsize)
    else:
Esempio n. 12
0
    if grid:
        for my_y in major:
            my_axes.axhline(y=my_y,
                            color="black",
                            linestyle=":",
                            linewidth=1.0,
                            alpha=0.2,
                            zorder=-100)


if __name__ == "__main__":
    my_fig = GridFigure(2,
                        2,
                        figsize=(8, 6),
                        left_buffer=0.13,
                        right_buffer=0.03,
                        bottom_buffer=0.10,
                        top_buffer=0.09,
                        vertical_buffer=0,
                        horizontal_buffer=0.13)

    # palette = sns.color_palette(palette="colorblind")
    palette = \
      [(0.0, 0.4470588235294118, 0.6980392156862745),
       (0.0, 0.6196078431372549, 0.45098039215686275),
       (0.8352941176470589, 0.3686274509803922, 0.0),
       (0.8, 0.4745098039215686, 0.6549019607843137),
       (0.9411764705882353, 0.8941176470588236, 0.25882352941176473),
       (0.33725490196078434, 0.7058823529411765, 0.9137254901960784)]

    cmap = yt_colormaps["arbre"]
Esempio n. 13
0
        ticklabel.set_fontsize(lfontsize)


if __name__ == "__main__":
    halo_dir = "halo_2170858"
    # halo_dir = "halo_2171203"
    ds = yt.load(os.path.join(halo_dir, "bh_clump_distance_edge_1e-03.h5"))
    ds_i = yt.load(
        os.path.join(halo_dir, "bh_clump_distance_edge_1e-03_inner_0.25.h5"))

    fontsize = 12
    my_fig = GridFigure(1,
                        1,
                        top_buffer=0.12,
                        bottom_buffer=0.13,
                        left_buffer=0.14,
                        right_buffer=0.04,
                        horizontal_buffer=0.05,
                        vertical_buffer=0.1,
                        figsize=(6, 4.5))
    my_axes = my_fig[0]
    my_axes.set_yscale("log")
    plot_distribution(my_axes,
                      ds.data["time"].to("Myr"),
                      ds.data["distance_distribution"].to("pc"),
                      step=10)
    plot_distribution(my_axes,
                      ds_i.data["time"].to("Myr"),
                      ds_i.data["distance_distribution"].to("pc"),
                      step=3,
                      show_dist=False,
Esempio n. 14
0
PlotWindow objects (e.g., slices, projections)
"""

import matplotlib
matplotlib.use('Agg')
from matplotlib import pyplot as plt
from grid_figure import GridFigure
from matplotlib.colors import LogNorm
import yt

# Create GridFigure object
fig = GridFigure(1,
                 1,
                 top_buffer=0.02,
                 bottom_buffer=0.15,
                 left_buffer=0.18,
                 right_buffer=0.01,
                 vertical_buffer=0.01,
                 horizontal_buffer=0.005,
                 figsize=(4, 4))

# Now treat fig like a list of NxN elements.  Each element is a MPL axis object
ax = fig[0]

# Generate your desired projection or slice or whatever
ds = yt.load('IsolatedGalaxy/galaxy0030/galaxy0030')
proj = yt.ProjectionPlot(ds, 'x', 'density')

# Use imshow with your axis object to show the FixedResolutionBuffer
# of the projection image data; Render in Log space.
plot = ax.imshow(proj.frb['density'].v, norm=LogNorm())
def plot_timescale_profiles(data_dir, halo_id):
    my_fig = GridFigure([3, 1],
                        1,
                        figsize=(6, 4.5),
                        top_buffer=0.13,
                        bottom_buffer=0.12,
                        left_buffer=0.14,
                        right_buffer=0.02,
                        horizontal_buffer=0.05,
                        vertical_buffer=0)

    colors = ["red", "green", "blue"]

    for i, my_axes in enumerate(my_fig):
        my_axes.set_xscale('log')
        my_axes.set_yscale('log')

        xlim = (2e-6, 3e2)
        tx = twin_unit_axes(my_axes, xlim, "r", "pc", top_units="AU")

        if i == 0:

            fields = ["dynamical_time", "cooling_time", "vortical_time"]
            units = ["%f*yr" % np.sqrt(2), "yr", "%f*yr" % (1 / (2 * np.pi))]
            for i, field in enumerate(fields):
                filename = os.path.join(data_dir,
                                        "%s_%06d.h5" % (field, halo_id))
                plot_profile_distribution(my_axes,
                                          filename,
                                          'cell_mass',
                                          x_units="pc",
                                          y_units=units[i],
                                          alpha_scale=0.7,
                                          pkwargs=dict(color=colors[i],
                                                       linewidth=1))

            my_axes.xaxis.set_visible(False)

            ylim = (10, 1e10)
            ymajor = np.logspace(2, 10, 5)
            yminor = np.logspace(1, 9, 5)
            draw_major_grid(my_axes,
                            'y',
                            ymajor,
                            color='black',
                            linestyle='-',
                            linewidth=1,
                            alpha=0.2)
            ty = mirror_yticks(my_axes, ylim, ymajor, yminor=yminor)
            my_axes.yaxis.set_label_text("t [yr]")
            # my_axes.yaxis.labelpad = 4

            labels = ("free-fall", "cooling", "mixing")
            dist = [True] * 3
            plot_items = list(zip(colors, labels, dist))
            plot_profile_distribution_legend(my_axes,
                                             plot_items,
                                             alpha_scale=0.7,
                                             lheight=0.27,
                                             label_rotation=315)

        if i == 1:

            fields = ["cooling_dynamical_ratio", "vortical_dynamical_ratio"]
            units = [str(1 / np.sqrt(2)), str(1 / (2 * np.pi * np.sqrt(2)))]
            for i, field in enumerate(fields):
                filename = os.path.join(data_dir,
                                        "%s_%06d.h5" % (field, halo_id))
                plot_profile_distribution(my_axes,
                                          filename,
                                          'cell_mass',
                                          x_units="pc",
                                          y_units=units[i],
                                          alpha_scale=0.7,
                                          pkwargs=dict(color=colors[i + 1],
                                                       linewidth=1))

            ds = yt.load(filename)
            x_data = ds.profile.x.to("pc")
            z_data = ds.profile['cell_mass'].transpose()
            z_sum = z_data.sum(axis=0)
            rfil = z_sum > 0
            my_axes.plot(x_data[rfil],
                         np.ones(x_data[rfil].size),
                         alpha=0.9,
                         color=colors[0],
                         linewidth=1,
                         zorder=1)

            tx.xaxis.set_visible(False)

            ylim = (0.01, 100)
            ymajor = np.logspace(-1, 1, 2)
            yminor = np.logspace(-2, 2, 5)
            draw_major_grid(my_axes,
                            'y',
                            ymajor,
                            color='black',
                            linestyle='-',
                            linewidth=1,
                            alpha=0.2)
            ty = mirror_yticks(my_axes, ylim, ymajor, yminor=yminor)
            my_axes.yaxis.set_label_text("t / t$_{\\rm ff}$")
            my_axes.yaxis.labelpad = 0

    pyplot.savefig("figures/timescale_profile_distributions.pdf")