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_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")
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")
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")