Пример #1
0
def plot_extra_info(ax, filename):
    """
    Plots all of the extra information on the final axis.

    Give it a filename of any of the snapshots.
    """

    metadata = get_metadata(filename)
    
    git = metadata['code']['Git Revision'].decode("utf-8")
    compiler_name = metadata['code']['Compiler Name'].decode("utf-8")
    compiler_version = metadata['code']['Compiler Version'].decode("utf-8")
    scheme = metadata['hydro']['Scheme'].decode("utf-8")
    kernel = metadata['hydro']['Kernel function'].decode("utf-8")
    gas_gamma = metadata["hydro"]["Adiabatic index"][0]
    neighbors = metadata["hydro"]["Kernel target N_ngb"][0]
    eta = metadata["hydro"]["Kernel eta"][0]
    

    ax.text(-0.49, 0.9, "Keplerian Ring with  $\\gamma={:4.4f}$ in 2/3D".format(gas_gamma), fontsize=11)
    ax.text(-0.49, 0.8, f"Compiler: {compiler_name} {compiler_version}", fontsize=10)
    ax.text(-0.49, 0.7, "Rotations are quoted at $r=1$", fontsize=10)
    ax.plot([-0.49, 0.1], [0.62, 0.62], 'k-', lw=1)
    ax.text(-0.49, 0.5, f"$\\textsc{{Swift}}$ {git}", fontsize=10)
    ax.text(-0.49, 0.4, scheme, fontsize=10)
    ax.text(-0.49, 0.3, kernel, fontsize=10)
    ax.text(-0.49, 0.2, "${:2.2f}$ neighbours ($\\eta={:3.3f}$)".format(neighbors, eta), fontsize=10)

    ax.set_axis_off()
    ax.set_xlim(-0.5, 0.5)
    ax.set_ylim(0, 1)

    return
Пример #2
0
def surface_density_plot_no_yt(ax,
                               snapnum,
                               filename="keplerian_ring",
                               density_limits=None,
                               vlim=None):
    """
    Make the surface density plot (sans yt).

    Also returns the max and minimum values for the density so these can
    be passed to the next call, as well as vlim which are the colourmap
    max/min.
    """

    with h5py.File("{}_{:04d}.hdf5".format(filename, snapnum)) as filehandle:
        density = filehandle["PartType0"]["Density"][...]
        x, y = filehandle["PartType0"]["Coordinates"][:, 0:2].T

    new_vlim = (density.min(), density.max())

    if vlim is None:
        vlim = new_vlim

    ax.scatter(x, y, c=density, vmin=vlim[0], vmax=vlim[1], s=0.1)

    metadata = get_metadata("{}_{:04d}.hdf5".format(filename, snapnum))
    period = metadata["period"]

    t = ax.text(
        2.5,
        7.5,
        "Snapshot = {:04d}\nRotations = {:1.2f}".format(
            snapnum,
            float(metadata["header"]["Time"]) / period),
        color="black",
    )

    t.set_bbox(dict(alpha=0.5, color="white"))

    ax.axis("equal")

    ax.set_xlim(2, 8)
    ax.set_ylim(2, 8)

    # We now want to remove all of the ticklabels.

    for axis in ["x", "y"]:
        ax.tick_params(
            axis=axis,
            which="both",
            bottom="off",
            top="off",
            left="off",
            right="off",
            labelleft="off",
            labelbottom="off",
        )

    return density_limits, vlim
Пример #3
0
def convert_snapshot_number_to_rotations_at(r, snapnum, filename):
    """
    Opens the file and extracts metadata to find the number of rotations.
    """

    metadata = get_metadata("{}_{:04d}.hdf5".format(filename, snapnum))

    t = metadata["period"]
    current_time = float(metadata["header"]["Time"])

    return current_time / t
Пример #4
0
def surface_density_plot(ax, snapnum, filename="keplerian_ring", density_limits=None, vlim=None):
    """
    Make the surface density plot (via yt).

    Also returns the max and minimum values for the density so these can
    be passed to the next call, as well as vlim which are the colourmap
    max/min.
    """

    unit_base = {
        'length': (1.0, 'cm'),
        'velocity': (1.0, 'cm/s'),
        'mass': (1.0, 'g')
    }

    filename = "{}_{:04d}.hdf5".format(filename, snapnum)

    try:
        snap = yt.load(filename, unit_base=unit_base, over_refine_factor=2)
    except yt.utilities.exceptions.YTOutputNotIdentified:
        # Probably the file isn't here because we supplied a too high snapshot
        # number. Just return what we're given.
        return density_limits, vlim

    projection_plot = yt.ProjectionPlot(
        snap,
        "z",
        ("gas", "cell_mass"),
        width=5.5
    )

    max_density = snap.all_data()[("gas", "cell_mass")].max()
    min_density = snap.all_data()[("gas", "cell_mass")].min()
    
    new_density_limits = (min_density, max_density)

    if density_limits is None:
        density_limits = new_density_limits

    projection_plot.set_zlim("cell_mass", *density_limits)

    data = get_yt_actual_data(projection_plot, ("gas", "cell_mass"))

    # Becuase of the way plotting works, we also need a max/min for the colourmap.

    new_vlim = (data[0].min(), data[0].max())

    if vlim is None:
        vlim = new_vlim

    ax.imshow(
        data[0],
        cmap=data[1],
        vmin=vlim[0],
        vmax=vlim[1]
    )

    metadata = get_metadata(filename)
    period = metadata["period"]

    ax.text(
        20,
        80,
        "Snapshot = {:04d}\nRotations = {:1.2f}".format(
            snapnum,
            float(snap.current_time)/period
        ),
        color='white'
    )

    # We now want to remove all of the ticklabels.

    for axis in ['x', 'y']:
        ax.tick_params(
            axis=axis,          
            which='both',      
            bottom='off',      
            top='off',         
            left='off',
            right='off',
            labelleft='off',
            labelbottom='off'
        ) 

    return density_limits, vlim