예제 #1
0
def get_velocity(args_here):
    # Unwrap Args
    i, frame = args_here

    # Data
    if mpi:
      density = Fields("./", 'gas', frame).get_field("dens").reshape(num_z, num_rad, num_theta)
      vz = Fields("./", 'gas', frame).get_field("vz").reshape(num_z, num_rad, num_theta)
      vrad = Fields("./", 'gas', frame).get_field("vy").reshape(num_z, num_rad, num_theta)
      vtheta = Fields("./", 'gas', frame).get_field("vx").reshape(num_z, num_rad, num_theta)
    else:
      density = fromfile("gasdens%d.dat" % frame).reshape(num_z, num_rad, num_theta)
      vz = (fromfile("gasvz%d.dat" % frame).reshape(num_z, num_rad, num_theta)) # add a read_vrad to util.py!
      vrad = (fromfile("gasvy%d.dat" % frame).reshape(num_z, num_rad, num_theta)) # add a read_vrad to util.py!
      vtheta = (fromfile("gasvx%d.dat" % frame).reshape(num_z, num_rad, num_theta)) # add a read_vrad to util.py!
    midplane_density = density[num_z / 2 + args.sliver, :, :]
    midplane_vrad = vrad[num_z / 2 + args.sliver, :, :]
    midplane_vtheta = vtheta[num_z / 2 + args.sliver, :, :]
    midplane_vz = vz[num_z / 2 + args.sliver, :, :]

    dz = z_angles[1] - z_angles[0]
    surface_density = np.sum(density[:, :, :], axis = 0) * dz
    averagedDensity = np.average(surface_density, axis = -1)

    average_midplane_vz = np.average(np.abs(midplane_vz), axis = -1)
    composite_vz[i, :] = average_midplane_vz

    peak, _ = az.get_radial_peak(averagedDensity, fargo_par)
    composite_peak[i] = peak
예제 #2
0
def get_contrasts(args_here):
    # Unwrap Args
    i, frame = args_here

    # Get Data
    density = fromfile("gasdens%d.dat" % frame).reshape(
        num_rad, num_theta) / surface_density_zero
    averagedDensity = np.average(density, axis=-1)
    peak_rad, peak_density = az.get_radial_peak(averagedDensity, fargo_par)

    vrad = (fromfile("gasvy%d.dat" % frame).reshape(num_rad, num_theta)
            )  # add a read_vrad to util.py!
    vtheta = (fromfile("gasvx%d.dat" % frame).reshape(num_rad, num_theta)
              )  # add a read_vrad to util.py!
    vorticity = utilVorticity.velocity_curl(vrad,
                                            vtheta,
                                            rad,
                                            theta,
                                            rossby=True,
                                            residual=True)

    #vorticity, shift_c = shift_data(vorticity, fargo_par, reference_density = density)

    # Find minimum
    start_rad_i = np.searchsorted(rad, peak_rad - 0.1)  # Is this necessary?
    end_rad_i = np.searchsorted(rad, peak_rad + 1.0)
    azimuthal_profile = vorticity[start_rad_i:end_rad_i]

    rossby_number_over_time[i] = np.min(azimuthal_profile)
    rossby_number_over_time_98[i] = np.percentile(azimuthal_profile, 0.2)
    rossby_number_over_time_95[i] = np.percentile(azimuthal_profile, 0.5)

    print i, frame, rossby_number_over_time[i], rossby_number_over_time_98[
        i], rossby_number_over_time_95[i]
def get_rossby_number(args_here):
    # Unwrap Args
    i, frame, directory = args_here

    if frame == 8800:
        frame = 8801  # Remove problem frame

    # Get Data
    density = fromfile("../%s/gasdens%d.dat" % (directory, frame)).reshape(
        num_rad, num_theta) / surface_density_zero
    averagedDensity = np.average(density, axis=-1)
    peak_rad, peak_density = az.get_radial_peak(averagedDensity, fargo_par)

    vrad = (fromfile("../%s/gasvy%d.dat" % (directory, frame)).reshape(
        num_rad, num_theta))  # add a read_vrad to util.py!
    vtheta = (fromfile("../%s/gasvx%d.dat" % (directory, frame)).reshape(
        num_rad, num_theta))  # add a read_vrad to util.py!
    vorticity = utilVorticity.velocity_curl(vrad,
                                            vtheta,
                                            rad,
                                            theta,
                                            rossby=True,
                                            residual=True)

    #vorticity, shift_c = shift_data(vorticity, fargo_par, reference_density = density)

    # Find minimum
    start_rad = min([peak_rad - 0.05, 1.5])
    start_rad_i = np.searchsorted(rad, start_rad)  # Is this necessary?
    end_rad_i = np.searchsorted(rad, 2.5)
    azimuthal_profile = vorticity[start_rad_i:end_rad_i]

    rossby_number_over_time[i] = np.percentile(azimuthal_profile, 0.25)

    print i, frame, rossby_number_over_time[i]
def get_total_mass(args, num_scale_heights=3):
    # Args
    i, frame = args

    # Get Data
    density = util.read_dust_data(frame, fargo_par)  # Dust!!!!

    # Find Center
    avgDensity = np.average(density, axis=-1)
    peak_rad, peak_density = az.get_radial_peak(avgDensity, fargo_par)

    # Zoom in on annulus
    start_rad = peak_rad - 0.5 * num_scale_heights * scale_height
    end_rad = peak_rad + 0.5 * num_scale_heights * scale_height

    start_rad_i = np.searchsorted(rad, start_rad)
    end_rad_i = np.searchsorted(rad, end_rad)

    rad_annulus = rad[start_rad_i:end_rad_i]
    density_annulus = density[start_rad_i:end_rad_i]

    # Multiply by Grid Cell size
    dr = rad[1] - rad[0]
    dphi = theta[1] - theta[0]
    density_annulus = (
        dr * dphi
    ) * rad_annulus[:, None] * density_annulus  # (r * dr * d\phi) * \rho

    # Calculate and store total mass
    total_mass = np.sum(density_annulus)
    total_masses[i] = total_mass
예제 #5
0
def get_min(args_here):
    # Unwrap Args
    i, frame, directory = args_here

    # Get Data
    density = fromfile("../%s/gasdens%d.dat" % (directory, frame)).reshape(
        num_rad, num_theta)
    avg_density = np.average(density, axis=1)
    normalized_density = avg_density / surface_density_zero

    # Get Minima
    radial_peak_a, _ = az.get_radial_peak(avg_density, fargo_par, end=1.6)

    # Print Update
    print "%d: %.3f" % (frame, radial_peak_a)

    # Store Data
    radial_peak_over_time[i] = radial_peak_a
예제 #6
0
def get_extents(args_here):
    # Unwrap Args
    i, frame = args_here

    # Get Data
    density = fromfile("gasdens%d.dat" % frame).reshape(
        num_rad, num_theta) / surface_density_zero
    avg_density = np.average(density, axis=1)

    azimuthal_extent = az.get_extent(density, fargo_par, threshold=1.0)
    radial_extent, radial_peak = az.get_radial_extent(density,
                                                      fargo_par,
                                                      threshold=1.0)
    radial_peak_a, _ = az.get_radial_peak(avg_density, fargo_par)

    azimuthal_extent_over_time[i] = azimuthal_extent * (180.0 / np.pi)
    radial_extent_over_time[i] = radial_extent / scale_height
    radial_peak_over_time[i] = radial_peak
    radial_peak_over_time_a[i] = radial_peak_a

    print i, frame, azimuthal_extent_over_time[i], radial_extent_over_time[
        i], radial_peak_over_time[i], radial_peak_over_time_a[i]
def find_rossby_density(averaged_density, averaged_vorticity):
    # Maximum Condition (and its derivative)
    maximum_condition = (averaged_density[1:] / averaged_vorticity) * (
        np.power(scale_height, 2) / np.power(rad[1:], 1))

    dr = rad[1] - rad[0]
    diff_maximum_condition = np.diff(maximum_condition) / dr

    # Diagnostics
    peak_rad, peak_density = az.get_radial_peak(averaged_density, fargo_par)
    peak_rad_i = np.searchsorted(rad, peak_rad)
    inner_limit_i = np.searchsorted(
        rad, 1.1)  # Make inner limit a variable in the future
    outer_limit_i = np.searchsorted(
        rad, 2.0)  # Make outer limit a variable in the future

    inner_max_diff_i = np.argmax(
        diff_maximum_condition[inner_limit_i:peak_rad_i])
    inner_max_diff_i += inner_limit_i  # put the "inner disk" back

    rossby_min_density = averaged_density[
        inner_max_diff_i]  # Density at location with the steepest gradient in the maximum condition (c_s^2 * density / vorticity)

    return rossby_min_density
def make_plot(frame, show = False):
    # Set up figure
    fig = plot.figure(figsize = (7, 6), dpi = dpi)
    ax = fig.add_subplot(111)

    # Data
    field = "dens"
    if mpi:
      density = Fields("./", 'dust1', frame).get_field(field).reshape(num_z, num_rad, num_theta)
    else:
      density = fromfile("dust1dens%d.dat" % frame).reshape(num_z, num_rad, num_theta)

    scale_height_function = np.zeros(num_rad)
    mean_function = np.zeros(num_rad)
    meridional_density = np.average(density, axis = -1)

    for i in range(num_rad):
        popt, pcov = curve_fit(gaussian, z_angles, meridional_density[:, i])
        (A, mean, sigma) = popt
        scale_height_function[i] = sigma # scale height (as an angle)
        mean_function[i] = np.abs(mean - np.pi / 2.0)

    ### Plot ###
    x = rad
    y = scale_height_function / scale_height
    y2 = (mean_function + scale_height_function) / scale_height
    result,  = plot.plot(x, y, linewidth = linewidth, c = "b", zorder = 99)
    result2, = plot.plot(x, y2, linewidth = linewidth - 1, c = "r", zorder = 90)

    if args.zero:
        density_zero = fromfile("gasdens0.dat").reshape(num_rad, num_theta)
        averagedDensity_zero = np.average(density_zero, axis = 1)
        normalized_density_zero = averagedDensity_zero / surface_density_zero

        x = rad
        y_zero = normalized_density_zero
        result = plot.plot(x, y_zero, linewidth = linewidth, zorder = 0)

    if args.compare is not None:
        directory = args.compare
        density_compare = (fromfile("%s/gasdens%d.dat" % (directory, frame)).reshape(num_rad, num_theta))
        averagedDensity_compare = np.average(density_compare, axis = 1)
        normalized_density_compare = averagedDensity_compare / surface_density_zero

        ### Plot ###
        x = rad
        y_compare = normalized_density_compare
        result = plot.plot(x, y_compare, linewidth = linewidth, alpha = 0.6, zorder = 99, label = "compare")

        plot.legend()

    if args.derivative:
        twin = ax.twinx()

        ### Plot ###
        dr = rad[1] - rad[0]
        normalized_density_derivative = np.diff(normalized_density) / dr

        x2 = rad[1:]
        y2 = normalized_density_derivative
        result = twin.plot(x2, y2, c = "purple", linewidth = linewidth, alpha = 0.6, zorder = 99, label = "derivative")

        plot.legend()

        twin.set_ylim(-10, 10)

    # Axes
    if args.max_y is None:
        max_y = 1.1 * max(y)
    else:
        max_y = args.max_y

    ax.set_xlim(x[0], x[-1])
    ax.set_ylim(0, max_y)

    # Annotate Axes
    orbit = (dt / (2 * np.pi)) * frame

    if orbit >= taper_time:
        current_mass = planet_mass
    else:
        current_mass = np.power(np.sin((np.pi / 2) * (1.0 * orbit / taper_time)), 2) * planet_mass

    #current_mass += accreted_mass[frame]

    #title = readTitle()

    unit = "r_\mathrm{p}"
    ax.set_xlabel(r"Radius [$%s$]" % unit, fontsize = fontsize)
    ax.set_ylabel(r"Dust Scale Height $H_d$ $/$ $h$", fontsize = fontsize)

    #if title is None:
    #    plot.title("Dust Density Map\n(t = %.1f)" % (orbit), fontsize = fontsize + 1)
    #else:
    #    plot.title("Dust Density Map\n%s\n(t = %.1f)" % (title, orbit), fontsize = fontsize + 1)

    x_range = x[-1] - x[0]; x_mid = x[0] + x_range / 2.0
    y_text = 1.14

    alpha_coefficent = "3"
    if scale_height == 0.08:
        alpha_coefficent = "1.5"
    elif scale_height == 0.04:
        alpha_coefficent = "6"

    #title1 = r"$T_\mathrm{growth} = %d$ $\mathrm{orbits}$" % (taper_time)
    #title1 = r"$\Sigma_0 = %.3e$  $M_c = %.2f\ M_J$  $A = %.2f$" % (surface_density_zero, planet_mass, accretion)
    title1 = r"$h/r = %.2f$     $\alpha \approx %s \times 10^{%d}$    $A = %.2f$" % (scale_height, alpha_coefficent, int(np.log(viscosity) / np.log(10)) + 2, accretion)
    title2 = r"$t = %d$ $\mathrm{orbits}}$  [$m_\mathrm{p}(t)\ =\ %.2f$ $M_\mathrm{Jup}$]" % (orbit, current_mass)
    plot.title("%s" % (title2), y = 1.015, fontsize = fontsize + 1)
    ax.text(x_mid, y_text * plot.ylim()[-1], title1, horizontalalignment = 'center', bbox = dict(facecolor = 'none', edgecolor = 'black', linewidth = 1.5, pad = 7.0), fontsize = fontsize + 2)

    # Text
    text_mass = r"$M_\mathrm{p} = %d$ $M_\mathrm{Jup}$" % (int(planet_mass))
    text_visc = r"$\alpha_\mathrm{disk} = 3 \times 10^{%d}$" % (int(np.log(viscosity) / np.log(10)) + 2)
    #plot.text(-0.9 * box_size, 2, text_mass, fontsize = fontsize, color = 'black', horizontalalignment = 'left', bbox=dict(facecolor = 'white', edgecolor = 'black', pad = 10.0))
    #plot.text(0.9 * box_size, 2, text_visc, fontsize = fontsize, color = 'black', horizontalalignment = 'right', bbox=dict(facecolor = 'white', edgecolor = 'black', pad = 10.0))
    #plot.text(-0.84 * x_range / 2.0 + x_mid, y_text * plot.ylim()[-1], text_mass, fontsize = fontsize, color = 'black', horizontalalignment = 'right')
    #plot.text(0.84 * x_range / 2.0 + x_mid, y_text * plot.ylim()[-1], text_visc, fontsize = fontsize, color = 'black', horizontalalignment = 'left')

    if args.maximum_condition:
        bump, _ = az.get_radial_peak(normalized_density, fargo_par, end = 1.6)
        plot.plot([bump, bump], [0, max_y], c = "b", linewidth = linewidth - 2, alpha = alpha, linestyle = "--", zorder = 20)

        twin = ax.twinx()

        vrad = (fromfile("gasvy%d.dat" % frame).reshape(num_rad, num_theta)) # add a read_vrad to util.py!
        vtheta = (fromfile("gasvx%d.dat" % frame).reshape(num_rad, num_theta)) # add a read_vrad to util.py!
        vorticity = utilVorticity.velocity_curl(vrad, vtheta, rad, theta, rossby = rossby, residual = residual)

        averaged_vorticity = np.average(vorticity, axis = 1)
        #averaged_density = np.average(normalized_density, axis = 1) # normalized_density
        maximum_condition = (normalized_density[1:] / averaged_vorticity) * (np.power(scale_height, 2) / np.power(rad[1:], 1))

        x2 = rad[1:]
        y2 = maximum_condition
        result2, = twin.plot(x2, y2, c = 'darkviolet', linewidth = linewidth, zorder = 99)

        bump, _ = az.get_radial_peak(maximum_condition, fargo_par, end = 1.6)
        plot.plot([bump, bump], y2_range, c = "darkviolet", linewidth = linewidth - 2, alpha = alpha, linestyle = "--", zorder = 20)

        # Axes
        twin.set_ylim(y2_range[0], y2_range[1])
        twin.set_yticks(np.arange(y2_range[0], y2_range[1] + 1e-9, 0.005))

        twin.set_ylabel(r"$\Sigma$ $/$ ($\nabla \times v$)$_\mathrm{z}$", fontsize = fontsize, rotation = 270, labelpad = 25)

        tkw = dict(size=4, width=1.5)
        ax.tick_params(axis = 'y', colors = result.get_color(), **tkw)
        twin.tick_params(axis = 'y', colors = result2.get_color(), **tkw)

    # Save, Show, and Close
    if version is None:
        save_fn = "%s/dustScaleHeight_%04d.png" % (save_directory, frame)
    else:
        save_fn = "%s/v%04d_dustScaleHeight_%04d.png" % (save_directory, version, frame)
    plot.savefig(save_fn, bbox_inches = 'tight', dpi = dpi)

    if show:
        plot.show()

    plot.close(fig) # Close Figure (to avoid too many figures)
예제 #9
0
def get_rossby_criteria(args_here):
    # Unwrap Args
    i, frame, directory = args_here

    # Data
    normalized_density = (fromfile(
        "../%s/gasdens%d.dat" %
        (directory, frame)).reshape(num_rad, num_theta)) / surface_density_zero

    vrad = (fromfile("../%s/gasvy%d.dat" % (directory, frame)).reshape(
        num_rad, num_theta))  # add a read_vrad to util.py!
    vtheta = (fromfile("../%s/gasvx%d.dat" % (directory, frame)).reshape(
        num_rad, num_theta))  # add a read_vrad to util.py!
    vorticity = utilVorticity.velocity_curl(vrad,
                                            vtheta,
                                            rad,
                                            theta,
                                            rossby=rossby,
                                            residual=residual)

    averaged_vorticity = np.average(vorticity, axis=1)
    averaged_density = np.average(normalized_density, axis=1)
    maximum_condition = (averaged_density[1:] / averaged_vorticity) * (
        np.power(scale_height, 2) / np.power(rad[1:], 1))

    dr = rad[1] - rad[0]
    diff_maximum_condition = np.diff(maximum_condition) / dr

    # Diagnostics
    peak_rad, peak_density = az.get_radial_peak(averaged_density, fargo_par)
    peak_rad_i = np.searchsorted(rad, peak_rad)
    inner_limit_i = np.searchsorted(
        rad, 1.1)  # Make inner limit a variable in the future
    outer_limit_i = np.searchsorted(
        rad, 2.0)  # Make outer limit a variable in the future

    inner_max_diff_i = np.argmax(
        diff_maximum_condition[inner_limit_i:peak_rad_i])
    outer_max_diff_i = np.argmin(
        diff_maximum_condition[peak_rad_i:outer_limit_i])

    inner_max_diff_i += inner_limit_i  # put the "inner disk" back
    outer_max_diff_i += peak_rad_i

    # Alternate: For inner rossby rad, use minimum in vorticity profile
    inner_rossby_rad, _ = az.get_radial_peak(-1.0 * averaged_vorticity,
                                             fargo_par)

    #inner_rossby_rad = rad[inner_max_diff_i]
    outer_rossby_rad = rad[outer_max_diff_i]
    difference = outer_rossby_rad - inner_rossby_rad

    inner_rossby_value = diff_maximum_condition[inner_max_diff_i]
    outer_rossby_value = diff_maximum_condition[
        outer_max_diff_i] * -1.0  # absolute value

    # Store Data
    inner_rossby_rad_over_time[i] = inner_rossby_rad
    peak_rad_over_time[i] = peak_rad
    outer_rossby_rad_over_time[i] = outer_rossby_rad

    rossby_rad_difference_over_time[i] = outer_rossby_rad - inner_rossby_rad
    inner_peak_difference_over_time[i] = peak_rad - inner_rossby_rad
    outer_peak_difference_over_time[i] = outer_rossby_rad - peak_rad

    inner_rossby_value_over_time[i] = inner_rossby_value
    outer_rossby_value_over_time[i] = outer_rossby_value

    print i, frame, "Rad: ", inner_rossby_rad_over_time[i], peak_rad_over_time[
        i], outer_rossby_rad_over_time[i]
    print i, frame, "Diff:", rossby_rad_difference_over_time[
        i], inner_peak_difference_over_time[
            i], outer_peak_difference_over_time[i]
    print i, frame, "Val: ", inner_rossby_value_over_time[
        i], outer_rossby_value_over_time[i]
예제 #10
0
def make_plot(frame, show=False):
    # Set up figure
    fig = plot.figure(figsize=(7, 6), dpi=dpi)
    ax = fig.add_subplot(111)

    # Data
    density = fromfile("gasdens%d.dat" % frame).reshape(num_rad, num_theta)
    averagedDensity = np.average(density, axis=1)

    radial_velocity = fromfile("gasvy%d.dat" % frame).reshape(
        num_rad, num_theta)
    azimuthal_velocity = fromfile("gasvx%d.dat" % frame).reshape(
        num_rad, num_theta)

    keplerian_velocity = rad * (np.power(
        rad, -1.5) - 1)  # in rotating frame, v_k = r * (r^-1.5 - r_p^-1.5)
    sub_keplerian_velocity = keplerian_velocity - 0.5 * np.power(
        scale_height, 2)
    #azimuthal_velocity -= sub_keplerian_velocity[:, None]

    radial_velocity -= np.average(radial_velocity, axis=1)[:, None]
    azimuthal_velocity -= np.average(azimuthal_velocity, axis=1)[:, None]

    sound_speed = scale_height * np.power(rad, -1.5)

    stress = np.multiply(radial_velocity, azimuthal_velocity)
    averagedStress = np.abs(
        np.average(stress, axis=1) / np.power(sound_speed, 2))

    ### Plot ###
    x = rad
    y = averagedStress
    result = plot.plot(x, y, linewidth=linewidth, zorder=99)

    radial_peak_a, _ = az.get_radial_peak(averagedDensity, fargo_par, end=2.0)
    plot.plot([radial_peak_a, radial_peak_a], [10**(-10), 10**(1)], c='k')

    if args.zero:
        density_zero = fromfile("gasdens0.dat").reshape(num_rad, num_theta)
        averagedDensity_zero = np.average(density_zero, axis=1)
        normalized_density_zero = averagedDensity_zero / surface_density_zero

        x = rad
        y_zero = normalized_density_zero
        result = plot.plot(x, y_zero, linewidth=linewidth, zorder=0)

    if args.compare is not None:
        directory = args.compare
        density_compare = (fromfile("%s/gasdens%d.dat" %
                                    (directory, frame)).reshape(
                                        num_rad, num_theta))
        averagedDensity_compare = np.average(density_compare, axis=1)
        normalized_density_compare = averagedDensity_compare / surface_density_zero

        ### Plot ###
        x = rad
        y_compare = normalized_density_compare
        result = plot.plot(x,
                           y_compare,
                           linewidth=linewidth,
                           alpha=0.6,
                           zorder=99,
                           label="compare")

        plot.legend()

    # Axes
    if args.max_y is None:
        x_min_i = np.searchsorted(x, x_min)
        x_max_i = np.searchsorted(x, x_max)
        max_y = 1.1 * max(y[x_min_i:x_max_i])
    else:
        max_y = args.max_y

    plot.xlim(x_min, x_max)
    plot.ylim(10**(-5), 3 * 10**(-1))
    plot.yscale('log')

    # Annotate Axes
    orbit = (dt / (2 * np.pi)) * frame

    if orbit >= taper_time:
        current_mass = planet_mass
    else:
        current_mass = np.power(
            np.sin((np.pi / 2) * (1.0 * orbit / taper_time)), 2) * planet_mass

    current_mass += accreted_mass[frame]

    #title = readTitle()

    unit = "r_\mathrm{p}"
    plot.xlabel(r"Radius [$%s$]" % unit, fontsize=fontsize)
    plot.ylabel(r"$<\Delta v_r \Delta v_{\phi}> / c_s^2$", fontsize=fontsize)

    #if title is None:
    #    plot.title("Dust Density Map\n(t = %.1f)" % (orbit), fontsize = fontsize + 1)
    #else:
    #    plot.title("Dust Density Map\n%s\n(t = %.1f)" % (title, orbit), fontsize = fontsize + 1)

    x_range = x_max - x_min
    x_mid = x_min + x_range / 2.0
    y_text = 1.14

    #title1 = r"$T_\mathrm{growth} = %d$ $\mathrm{orbits}$" % (taper_time)
    title1 = r"$\Sigma_0 = %.3e$  $M_c = %.2f\ M_J$  $A = %.2f$" % (
        surface_density_zero, planet_mass, accretion)
    title2 = r"$t = %d$ $\mathrm{orbits}}$  [$m_\mathrm{p}(t)\ =\ %.2f$ $M_\mathrm{Jup}$]" % (
        orbit, current_mass)
    plot.title("%s" % (title2), y=1.015, fontsize=fontsize + 1)
    #plot.text(x_mid, y_text * plot.ylim()[-1], title1, horizontalalignment = 'center', bbox = dict(facecolor = 'none', edgecolor = 'black', linewidth = 1.5, pad = 7.0), fontsize = fontsize + 2)

    # Text
    text_mass = r"$M_\mathrm{p} = %d$ $M_\mathrm{Jup}$" % (int(planet_mass))
    text_visc = r"$\alpha_\mathrm{disk} = 3 \times 10^{%d}$" % (
        int(np.log(viscosity) / np.log(10)) + 2)
    #plot.text(-0.9 * box_size, 2, text_mass, fontsize = fontsize, color = 'black', horizontalalignment = 'left', bbox=dict(facecolor = 'white', edgecolor = 'black', pad = 10.0))
    #plot.text(0.9 * box_size, 2, text_visc, fontsize = fontsize, color = 'black', horizontalalignment = 'right', bbox=dict(facecolor = 'white', edgecolor = 'black', pad = 10.0))
    #plot.text(-0.84 * x_range / 2.0 + x_mid, y_text * plot.ylim()[-1], text_mass, fontsize = fontsize, color = 'black', horizontalalignment = 'right')
    #plot.text(0.84 * x_range / 2.0 + x_mid, y_text * plot.ylim()[-1], text_visc, fontsize = fontsize, color = 'black', horizontalalignment = 'left')

    # Save, Show, and Close
    if version is None:
        save_fn = "%s/averagedStress_%04d.png" % (save_directory, frame)
    else:
        save_fn = "%s/v%04d_averagedStress_%04d.png" % (save_directory,
                                                        version, frame)
    plot.savefig(save_fn, bbox_inches='tight', dpi=dpi)

    if show:
        plot.show()

    plot.close(fig)  # Close Figure (to avoid too many figures)
예제 #11
0
def make_plot(frame, show=False):
    # Set up figure
    fig = plot.figure(figsize=(7, 6), dpi=dpi)
    ax = fig.add_subplot(111)

    # Data
    density = fromfile("gasdens%d.dat" % frame).reshape(
        num_rad, num_theta) / surface_density_zero
    radial_velocity = fromfile("gasvy%d.dat" % frame).reshape(
        num_rad, num_theta)
    azimuthal_velocity = fromfile("gasvx%d.dat" % frame).reshape(
        num_rad, num_theta)

    shifted_density = np.roll(density, 1, axis=-1)
    diff_density = density - shifted_density

    keplerian_velocity = rad * (np.power(
        rad, -1.5) - 1)  # in rotating frame, v_k = r * (r^-1.5 - r_p^-1.5)
    azimuthal_velocity -= keplerian_velocity[:, None]

    # Extract Action
    wave_locations = np.argmax(diff_density, axis=-1)
    shift = np.searchsorted(theta, np.pi) - wave_locations

    print_a = np.searchsorted(rad, 1.1)
    print_b = np.searchsorted(rad, 1.4)
    print(theta[wave_locations[print_a:print_b]] * (180.0 / np.pi))
    print(theta[shift[print_a:print_b]] * (180.0 / np.pi))

    left = np.searchsorted(theta, 177 * (np.pi / 180.0))
    right = np.searchsorted(theta, 183 * (np.pi / 180.0))

    centered_density = np.roll(density, shift, axis=-1)[:, left:right]
    centered_radial_velocity = np.roll(radial_velocity, shift,
                                       axis=-1)[:, left:right]
    centered_azimuthal_velocity = np.roll(azimuthal_velocity, shift,
                                          axis=-1)[:, left:right]

    residual_density = centered_density - np.min(centered_density)

    dr = rad[1] - rad[0]
    dtheta = theta[1] - theta[0]
    grid_size = rad * dr * dtheta
    wave_action = np.sum(residual_density * centered_radial_velocity *
                         centered_azimuthal_velocity * rad[:, None] *
                         rad[:, None] * grid_size[:, None],
                         axis=-1)

    ### Plot ###
    x = rad
    y = wave_action
    result = plot.plot(x, y, linewidth=linewidth, zorder=99)
    result2 = plot.plot(x, -y, linewidth=linewidth, zorder=99)

    # Axes
    if args.max_y is None:
        x_min_i = np.searchsorted(x, x_min)
        x_max_i = np.searchsorted(x, x_max)
        max_y1 = 1.1 * max(y[x_min_i:x_max_i])
        max_y2 = 1.1 * max(-y[x_min_i:x_max_i])
        max_y = np.max([max_y1, max_y2])
    else:
        max_y = args.max_y

    plot.xlim(x_min, x_max)
    plot.ylim(0, max_y)

    # Reference
    x_vortex, _ = az.get_radial_peak(np.average(density, axis=1),
                                     fargo_par,
                                     end=2.0)
    plot.plot([x_vortex, x_vortex], [0, max_y], c="k", linewidth=1)

    # Annotate Axes
    orbit = (dt / (2 * np.pi)) * frame

    if orbit >= taper_time:
        current_mass = planet_mass
    else:
        current_mass = np.power(
            np.sin((np.pi / 2) * (1.0 * orbit / taper_time)), 2) * planet_mass

    current_mass += accreted_mass[frame]

    #title = readTitle()

    unit = "r_\mathrm{p}"
    plot.xlabel(r"Radius [$%s$]" % unit, fontsize=fontsize)
    plot.ylabel(r"Wave Action", fontsize=fontsize)

    #if title is None:
    #    plot.title("Dust Density Map\n(t = %.1f)" % (orbit), fontsize = fontsize + 1)
    #else:
    #    plot.title("Dust Density Map\n%s\n(t = %.1f)" % (title, orbit), fontsize = fontsize + 1)

    x_range = x_max - x_min
    x_mid = x_min + x_range / 2.0
    y_text = 1.14

    #title1 = r"$T_\mathrm{growth} = %d$ $\mathrm{orbits}$" % (taper_time)
    alpha_coefficent = "3"
    if scale_height == 0.08:
        alpha_coefficent = "1.5"
    elif scale_height == 0.04:
        alpha_coefficent = "6"
    title1 = r"$h = %.2f$     $\alpha \approx %s \times 10^{%d}$    $A = %.2f$" % (
        scale_height, alpha_coefficent,
        int(np.log(viscosity) / np.log(10)) + 2, accretion)
    #title1 = r"$\Sigma_0 = %.3e$  $M_c = %.2f\ M_J$  $A = %.2f$" % (surface_density_zero, planet_mass, accretion)
    title2 = r"$t = %d$ $\mathrm{orbits}}$  [$m_\mathrm{p}(t)\ =\ %.2f$ $M_\mathrm{Jup}$]" % (
        orbit, current_mass)
    plot.title("%s" % (title2), y=1.015, fontsize=fontsize + 1)
    plot.text(x_mid,
              y_text * plot.ylim()[-1],
              title1,
              horizontalalignment='center',
              bbox=dict(facecolor='none',
                        edgecolor='black',
                        linewidth=1.5,
                        pad=7.0),
              fontsize=fontsize + 2)

    # Text
    text_mass = r"$M_\mathrm{p} = %d$ $M_\mathrm{Jup}$" % (int(planet_mass))
    text_visc = r"$\alpha_\mathrm{disk} = 3 \times 10^{%d}$" % (
        int(np.log(viscosity) / np.log(10)) + 2)
    #plot.text(-0.9 * box_size, 2, text_mass, fontsize = fontsize, color = 'black', horizontalalignment = 'left', bbox=dict(facecolor = 'white', edgecolor = 'black', pad = 10.0))
    #plot.text(0.9 * box_size, 2, text_visc, fontsize = fontsize, color = 'black', horizontalalignment = 'right', bbox=dict(facecolor = 'white', edgecolor = 'black', pad = 10.0))
    #plot.text(-0.84 * x_range / 2.0 + x_mid, y_text * plot.ylim()[-1], text_mass, fontsize = fontsize, color = 'black', horizontalalignment = 'right')
    #plot.text(0.84 * x_range / 2.0 + x_mid, y_text * plot.ylim()[-1], text_visc, fontsize = fontsize, color = 'black', horizontalalignment = 'left')

    # Save, Show, and Close
    if version is None:
        save_fn = "%s/waveAction_%04d.png" % (save_directory, frame)
    else:
        save_fn = "%s/v%04d_waveAction_%04d.png" % (save_directory, version,
                                                    frame)
    plot.savefig(save_fn, bbox_inches='tight', dpi=dpi)

    if show:
        plot.show()

    plot.close(fig)  # Close Figure (to avoid too many figures)
예제 #12
0
def make_plot(frame_range, show=False):
    # Set up figure
    fig = plot.figure(figsize=(7, 5), dpi=dpi)
    ax = fig.add_subplot(111)

    # Data
    for i, frame in enumerate(frame_range):
        normalized_density = (fromfile("gasdens%d.dat" % frame).reshape(
            num_rad, num_theta)) / surface_density_zero

        vrad = (fromfile("gasvy%d.dat" % frame).reshape(num_rad, num_theta)
                )  # add a read_vrad to util.py!
        vtheta = (fromfile("gasvx%d.dat" % frame).reshape(num_rad, num_theta)
                  )  # add a read_vrad to util.py!
        vorticity = utilVorticity.velocity_curl(vrad,
                                                vtheta,
                                                rad,
                                                theta,
                                                rossby=rossby,
                                                residual=residual)

        averaged_vorticity = np.average(vorticity, axis=1)
        averaged_density = np.average(normalized_density, axis=1)
        maximum_condition = (averaged_density[1:] / averaged_vorticity) * (
            np.power(scale_height, 2) / np.power(rad[1:], 1))

        ### Plot ###
        x = rad[1:]
        y = maximum_condition  # Highlight middle two!
        result = plot.plot(x,
                           y,
                           c=colors[i % len(colors)],
                           linewidth=linewidth + np.ceil(i / 10.0),
                           linestyle=linestyles[i % 2],
                           zorder=99 - abs(1.5 - i),
                           label=r"$t$ $=$ $%d$ $T_\mathrm{p}$" % frame)

        # Reference line for pressure bump
        if scale_height == 0.08:
            bump, _ = az.get_radial_peak(averaged_density, fargo_par, end=3.0)
        else:
            bump, _ = az.get_radial_peak(averaged_density, fargo_par, end=1.6)
        plot.plot([bump, bump],
                  y_range,
                  c=colors[i % len(colors)],
                  linewidth=linewidth,
                  linestyle="--",
                  zorder=20)

    legend = plot.legend(loc="upper right",
                         fontsize=fontsize - 4,
                         framealpha=1.0,
                         fancybox=False)
    legend.set_zorder(150)

    # Axes
    plot.xlim(x_min, x_max)
    plot.ylim(y_range[0], y_range[1])

    plot.yticks(np.arange(y_range[0], y_range[1] + 1e-9, 0.005))

    #plot.ylim(10**(-3), 3.0)
    #plot.yscale("log")

    # Annotate Axes
    orbit = (dt / (2 * np.pi)) * frame

    if orbit >= taper_time:
        current_mass = planet_mass
    else:
        current_mass = np.power(
            np.sin((np.pi / 2) * (1.0 * orbit / taper_time)), 2) * planet_mass

    current_mass += accreted_mass[frame]

    #title = readTitle()

    unit = "r_\mathrm{p}"
    plot.xlabel(r"Radius [$%s$]" % unit, fontsize=fontsize)
    plot.ylabel(
        r"$L_\mathrm{iso}$ $\equiv$ $c_s^2$ $\Sigma$ $/$ ($\nabla \times v$)$_\mathrm{z}$",
        fontsize=fontsize)

    #if title is None:
    #    plot.title("Dust Density Map\n(t = %.1f)" % (orbit), fontsize = fontsize + 1)
    #else:
    #    plot.title("Dust Density Map\n%s\n(t = %.1f)" % (title, orbit), fontsize = fontsize + 1)

    x_range = x_max - x_min
    x_mid = x_min + x_range / 2.0
    y_text = 1.14

    alpha_coefficent = "3"
    if scale_height == 0.08:
        alpha_coefficent = "1.5"
    elif scale_height == 0.04:
        alpha_coefficent = "6"

    #title1 = r"$T_\mathrm{growth} = %d$ $\mathrm{orbits}$" % (taper_time)
    #title1 = r"$h = %.2f$     $\alpha \approx %s \times 10^{%d}$    $A = %.2f$" % (scale_height, alpha_coefficent, int(np.log(viscosity) / np.log(10)) + 2, accretion)
    #title2 = r"$t = %d$ $\mathrm{orbits}}$  [$m_\mathrm{p}(t)\ =\ %.2f$ $M_\mathrm{Jup}$]" % (orbit, current_mass)
    title1 = title = r"$h = %.2f$     $\Sigma_0 = %.3e$   (2-D)" % (
        scale_height, surface_density_zero)
    plot.title("%s" % (title1), y=1.015, fontsize=fontsize + 1)
    #plot.text(x_mid, y_text * plot.ylim()[-1], title1, horizontalalignment = 'center', bbox = dict(facecolor = 'none', edgecolor = 'black', linewidth = 1.5, pad = 7.0), fontsize = fontsize + 2)

    # Text
    text_mass = r"$M_\mathrm{p} = %d$ $M_\mathrm{Jup}$" % (int(planet_mass))
    text_visc = r"$\alpha_\mathrm{disk} = 3 \times 10^{%d}$" % (
        int(np.log(viscosity) / np.log(10)) + 2)
    #plot.text(-0.9 * box_size, 2, text_mass, fontsize = fontsize, color = 'black', horizontalalignment = 'left', bbox=dict(facecolor = 'white', edgecolor = 'black', pad = 10.0))
    #plot.text(0.9 * box_size, 2, text_visc, fontsize = fontsize, color = 'black', horizontalalignment = 'right', bbox=dict(facecolor = 'white', edgecolor = 'black', pad = 10.0))
    #plot.text(-0.84 * x_range / 2.0 + x_mid, y_text * plot.ylim()[-1], text_mass, fontsize = fontsize, color = 'black', horizontalalignment = 'right')
    #plot.text(0.84 * x_range / 2.0 + x_mid, y_text * plot.ylim()[-1], text_visc, fontsize = fontsize, color = 'black', horizontalalignment = 'left')

    if args.start is not None:
        text_start = r"$t_\mathrm{start}$ $=$ $%d$ $T_\mathrm{p}$" % args.start
        plot.text(0.55,
                  0.0025,
                  text_start,
                  fontsize=fontsize - 4,
                  color='black',
                  horizontalalignment='left')
    if args.end is not None:
        text_end = r"$t_\mathrm{end}$  $=$ $%d$ $T_\mathrm{p}$" % args.end
        plot.text(0.55,
                  0.0015,
                  text_end,
                  fontsize=fontsize - 4,
                  color='black',
                  horizontalalignment='left')

    # Save, Show, and Close
    directory_name = os.getcwd().split("/")[-1].split("-")[0]
    frame_string = ""
    for frame in frame_range:
        frame_string += ("%04d-" % frame)
    frame_string = frame_string[:-1]  # get rid of trailing '-'

    if version is None:
        save_fn = "%s/maximumCondition_%s_%s.png" % (
            save_directory, directory_name, frame_string)
    else:
        save_fn = "%s/v%04d_maximumCondition_%s_%s.png" % (
            save_directory, version, directory_name, frame_string)
    plot.savefig(save_fn, bbox_inches='tight', dpi=dpi)

    if show:
        plot.show()

    plot.close(fig)  # Close Figure (to avoid too many figures)
예제 #13
0
def get_extents(args_here):
    # Unwrap Args
    i, frame = args_here

    if frame in problem_frames:
        frame += 3  # switch to an adjacent frame

    # Get Data
    density = fromfile("gasdens%d.dat" % frame).reshape(
        num_rad, num_theta) / surface_density_zero
    avg_density = np.average(density, axis=1)
    peak_rad, peak_density = az.get_radial_peak(avg_density, fargo_par)

    normal = True
    if frame > check_rossby:
        vrad = (fromfile("gasvy%d.dat" % frame).reshape(num_rad, num_theta)
                )  # add a read_vrad to util.py!
        vtheta = (fromfile("gasvx%d.dat" % frame).reshape(num_rad, num_theta)
                  )  # add a read_vrad to util.py!
        vorticity = utilVorticity.velocity_curl(vrad,
                                                vtheta,
                                                rad,
                                                theta,
                                                rossby=True,
                                                residual=True)

        # Find minimum
        if accretion > 0.015:
            start_rad = min([peak_rad - 0.05, 1.5])
            start_rad_i = np.searchsorted(rad, start_rad)  # Is this necessary?
            end_rad_i = np.searchsorted(rad, 2.5)
        else:
            start_rad_i = np.searchsorted(rad, 1.0)  # Is this necessary?
            end_rad_i = np.searchsorted(rad, 1.8)
        zoom_vorticity = vorticity[start_rad_i:end_rad_i]

        min_rossby_number = np.percentile(zoom_vorticity, 0.25)
        if min_rossby_number < -0.15:
            normal = False  # Compressible regime from Surville+ 15

    if normal:
        azimuthal_extent = az.get_extent(
            density, fargo_par, threshold=args.threshold
        )  # Use 0.9 for h = 0.08 (Add as a parameter)
        radial_extent, radial_peak = az.get_radial_extent(
            density, fargo_par, threshold=args.threshold)
        radial_peak_a, _ = az.get_radial_peak(avg_density, fargo_par)

        azimuthal_extent_over_time[i] = azimuthal_extent * (180.0 / np.pi)
        radial_extent_over_time[i] = radial_extent / scale_height
        radial_peak_over_time[i] = radial_peak_a  # radial_peak
        #radial_peak_over_time_a[i] = radial_peak_a
    else:
        # Shift everything
        density, vorticity, shift_c = shift_density(density,
                                                    vorticity,
                                                    fargo_par,
                                                    reference_density=density)

        # Locate minimum
        if accretion > 0.015:
            start_rad = min([peak_rad - 0.05, 1.5])
            start_rad_i = np.searchsorted(rad, start_rad)  # Is this necessary?
            end_rad_i = np.searchsorted(rad, 2.5)
        else:
            start_rad_i = np.searchsorted(rad, 1.0)  # Is this necessary?
            end_rad_i = np.searchsorted(rad, 1.8)
        zoom_vorticity = vorticity[start_rad_i:end_rad_i]

        min_rossby_number = np.percentile(zoom_vorticity, 0.25)
        abs_zoom_vorticity = np.abs(zoom_vorticity - min_rossby_number)
        minimum_location = np.argmin(abs_zoom_vorticity)

        rad_min_i, theta_min_i = np.unravel_index(minimum_location,
                                                  np.shape(zoom_vorticity))

        # Locate radial and azimuthal center
        left_side = zoom_vorticity[rad_min_i, :theta_min_i]
        right_side = zoom_vorticity[rad_min_i, theta_min_i:]
        front_side = zoom_vorticity[:rad_min_i, theta_min_i]
        back_side = zoom_vorticity[rad_min_i:, theta_min_i]

        if frame < extreme_cutoff:
            cutoff = -0.04
        else:
            cutoff = -0.12  # Extreme! (neglects "vortex" that develops around the minimum)

        left_i = theta_min_i - az.my_searchsorted(
            left_side[::-1], cutoff)  # at location of minimum
        right_i = theta_min_i + az.my_searchsorted(right_side, cutoff)
        front_i = rad_min_i - az.my_searchsorted(front_side[::-1], cutoff)
        back_i = rad_min_i + az.my_searchsorted(back_side, cutoff)

        radial_center_i = start_rad_i + int((front_i + back_i) / 2.0)
        azimuthal_center_i = int((left_i + right_i) / 2.0)

        radial_center = (rad[start_rad_i + front_i] +
                         rad[start_rad_i + back_i]) / 2.0
        azimuthal_center = (
            (theta[left_i] + theta[right_i]) / 2.0) * (180.0 / np.pi)

        print i, frame, rad[start_rad_i + rad_min_i], theta[theta_min_i] * (
            180.0 / np.pi), "Minimum Rossby Number"
        print i, frame, rad[start_rad_i + front_i], radial_center, rad[
            start_rad_i + back_i], "Radial: Left, Center, Right"
        print i, frame, theta[left_i] * (
            180.0 / np.pi), azimuthal_center, theta[right_i] * (
                180.0 / np.pi), "Azimuthal: Left, Center, Right"

        # Measure radial and azimuthal extents
        left_side = vorticity[radial_center_i, :azimuthal_center_i]
        right_side = vorticity[radial_center_i, azimuthal_center_i:]
        front_side = vorticity[:radial_center_i, azimuthal_center_i]
        back_side = vorticity[radial_center_i:, azimuthal_center_i]

        left_i = azimuthal_center_i - az.my_searchsorted(
            left_side[::-1], cutoff)  # relative to center
        right_i = azimuthal_center_i + az.my_searchsorted(right_side, cutoff)
        front_i = radial_center_i - az.my_searchsorted(front_side[::-1],
                                                       cutoff)
        back_i = radial_center_i + az.my_searchsorted(back_side, cutoff)

        radial_peak_over_time[i] = radial_center
        radial_extent_over_time[i] = (rad[back_i] -
                                      rad[front_i]) / scale_height
        azimuthal_extent_over_time[i] = theta[right_i - left_i] * (180.0 /
                                                                   np.pi)

        print i, frame, rad[front_i], radial_center, rad[
            back_i], "Final Radial: Left, Center, Right"
        print i, frame, theta[left_i] * (
            180.0 / np.pi), azimuthal_center, theta[right_i] * (
                180.0 / np.pi), "Final Azimuthal: Left, Center, Right"

    #contrasts_over_time[i] = az.get_contrast(density, fargo_par)

    print i, frame, azimuthal_extent_over_time[i], radial_extent_over_time[
        i], radial_peak_over_time[i]
예제 #14
0
def make_plot(frame, show=False):
    # Set up figure
    fig = plot.figure(figsize=(7, 6), dpi=dpi)
    host = fig.add_subplot(111)
    twin = host.twinx()

    # Data
    normalized_density = (fromfile("gasdens%d.dat" % frame).reshape(
        num_rad, num_theta)) / surface_density_zero

    vrad = (fromfile("gasvy%d.dat" % frame).reshape(num_rad, num_theta)
            )  # add a read_vrad to util.py!
    vtheta = (fromfile("gasvx%d.dat" % frame).reshape(num_rad, num_theta)
              )  # add a read_vrad to util.py!
    vorticity = utilVorticity.velocity_curl(vrad,
                                            vtheta,
                                            rad,
                                            theta,
                                            rossby=rossby,
                                            residual=residual)

    averaged_vorticity = np.average(vorticity, axis=1)
    averaged_density = np.average(normalized_density, axis=1)
    maximum_condition = (averaged_density[1:] / averaged_vorticity) * (
        np.power(scale_height, 2) / np.power(rad[1:], 1))

    dr = rad[1] - rad[0]
    diff_maximum_condition = np.diff(maximum_condition) / dr

    # Diagnostics
    peak_rad, peak_density = az.get_radial_peak(averaged_density, fargo_par)
    peak_rad_i = np.searchsorted(rad, peak_rad)
    inner_limit_i = np.searchsorted(
        rad, 1.1)  # Make inner limit a variable in the future
    outer_limit_i = np.searchsorted(
        rad, 2.0)  # Make outer limit a variable in the future

    inner_max_diff_i = np.argmax(
        diff_maximum_condition[inner_limit_i:peak_rad_i])
    outer_max_diff_i = np.argmin(
        diff_maximum_condition[peak_rad_i:outer_limit_i])

    inner_max_diff_i += inner_limit_i  # put the "inner disk" back
    outer_max_diff_i += peak_rad_i

    inner_rossby_rad = rad[inner_max_diff_i]
    outer_rossby_rad = rad[outer_max_diff_i]
    difference = outer_rossby_rad - inner_rossby_rad

    inner_rossby_value = diff_maximum_condition[inner_max_diff_i]
    outer_rossby_value = diff_maximum_condition[
        outer_max_diff_i] * -1.0  # absolute value

    ### Plot ###
    x = rad[1:]
    y = maximum_condition
    result, = host.plot(x,
                        y,
                        c='b',
                        linewidth=linewidth + 1,
                        zorder=99,
                        label="Condition")

    x2 = x[:-1]
    y2 = diff_maximum_condition
    result2, = twin.plot(x2,
                         y2,
                         c='purple',
                         linewidth=linewidth,
                         zorder=99,
                         label="Derivative")

    # Reference
    y_min = y_range[0]
    y_max = y_range[-1]
    host.plot([inner_rossby_rad, inner_rossby_rad],
              [y_min, y_min + 0.7 * (y_max - y_min)],
              c='k',
              linewidth=1,
              zorder=201)
    host.plot([peak_rad, peak_rad], [y_min, y_min + 0.8 * (y_max - y_min)],
              c='k',
              linewidth=1,
              zorder=201)
    host.plot([outer_rossby_rad, outer_rossby_rad],
              [y_min, y_min + 0.7 * (y_max - y_min)],
              c='k',
              linewidth=1,
              zorder=201)

    twin.plot([x_min, x_max], [0, 0], c='k', linewidth=1, zorder=1)

    if args.zero:
        density_zero = fromfile("gasdens0.dat").reshape(num_rad, num_theta)
        averagedDensity_zero = np.average(density_zero, axis=1)
        normalized_density_zero = averagedDensity_zero / surface_density_zero

        x = rad
        y_zero = normalized_density_zero
        result = plot.plot(x, y_zero, linewidth=linewidth, zorder=0)

    if args.compare is not None:
        directory = args.compare
        density_compare = (fromfile("%s/gasdens%d.dat" %
                                    (directory, frame)).reshape(
                                        num_rad, num_theta))
        averagedDensity_compare = np.average(density_compare, axis=1)
        normalized_density_compare = averagedDensity_compare / surface_density_zero

        ### Plot ###
        x = rad
        y_compare = normalized_density_compare
        result = plot.plot(x,
                           y_compare,
                           linewidth=linewidth,
                           alpha=0.6,
                           zorder=99,
                           label="compare")

    plot.legend(loc="upper left")

    # Axes
    host.set_xlim(x_min, x_max)
    host.set_ylim(y_range[0], y_range[1])
    twin.set_ylim(y2_range[0], y2_range[1])

    tkw = dict(size=4, width=1.5)
    host.tick_params(axis='y', colors=result.get_color(), **tkw)
    twin.tick_params(axis='y', colors=result2.get_color(), **tkw)

    # Annotate Axes
    orbit = (dt / (2 * np.pi)) * frame

    if orbit >= taper_time:
        current_mass = planet_mass
    else:
        current_mass = np.power(
            np.sin((np.pi / 2) * (1.0 * orbit / taper_time)), 2) * planet_mass

    current_mass += accreted_mass[frame]

    #title = readTitle()

    unit = "r_\mathrm{p}"
    host.set_xlabel(r"Radius [$%s$]" % unit, fontsize=fontsize)
    host.set_ylabel(r"$c_s^2$ $\Sigma$ $/$ ($\nabla \times v$)$_\mathrm{z}$",
                    fontsize=fontsize)

    #if title is None:
    #    plot.title("Dust Density Map\n(t = %.1f)" % (orbit), fontsize = fontsize + 1)
    #else:
    #    plot.title("Dust Density Map\n%s\n(t = %.1f)" % (title, orbit), fontsize = fontsize + 1)

    x_range = x_max - x_min
    x_mid = x_min + x_range / 2.0
    y_text = 1.14

    alpha_coefficent = "3"
    if scale_height == 0.08:
        alpha_coefficent = "1.5"
    elif scale_height == 0.04:
        alpha_coefficent = "6"

    #title1 = r"$T_\mathrm{growth} = %d$ $\mathrm{orbits}$" % (taper_time)
    #title1 = r"$\Sigma_0 = %.3e$  $M_c = %.2f\ M_J$  $A = %.2f$" % (surface_density_zero, planet_mass, accretion)
    title1 = r"$h = %.2f$     $\alpha \approx %s \times 10^{%d}$    $A = %.2f$" % (
        scale_height, alpha_coefficent,
        int(np.log(viscosity) / np.log(10)) + 2, accretion)
    title2 = r"$t = %d$ $\mathrm{orbits}}$  [$m_\mathrm{p}(t)\ =\ %.2f$ $M_\mathrm{Jup}$]" % (
        orbit, current_mass)
    plot.title("%s" % (title2), y=1.015, fontsize=fontsize + 1)
    host.text(x_mid,
              y_text * y_range[-1],
              title1,
              horizontalalignment='center',
              bbox=dict(facecolor='none',
                        edgecolor='black',
                        linewidth=1.5,
                        pad=7.0),
              fontsize=fontsize + 2)

    # Text
    x_text = x_min + 0.75 * (x_max - x_min)
    y_text = 0.95 * y_range[-1]
    linebreak = 0.04 * y_range[-1]
    host.text(x_text,
              y_text - 0.0 * linebreak,
              r"$r_1 = %.2f$     ($%.3f$)" %
              (inner_rossby_rad, inner_rossby_value),
              color='black')
    host.text(x_text,
              y_text - 1.0 * linebreak,
              r"$r_2 = %.2f$     ($%.3f$)" %
              (outer_rossby_rad, outer_rossby_value),
              color='black')
    host.text(x_text,
              y_text - 2.0 * linebreak,
              r"$\Delta r = %.2f$" % difference,
              color='black')

    #text_mass = r"$M_\mathrm{p} = %d$ $M_\mathrm{Jup}$" % (int(planet_mass))
    #text_visc = r"$\alpha_\mathrm{disk} = 3 \times 10^{%d}$" % (int(np.log(viscosity) / np.log(10)) + 2)
    #plot.text(-0.9 * box_size, 2, text_mass, fontsize = fontsize, color = 'black', horizontalalignment = 'left', bbox=dict(facecolor = 'white', edgecolor = 'black', pad = 10.0))
    #plot.text(0.9 * box_size, 2, text_visc, fontsize = fontsize, color = 'black', horizontalalignment = 'right', bbox=dict(facecolor = 'white', edgecolor = 'black', pad = 10.0))
    #plot.text(-0.84 * x_range / 2.0 + x_mid, y_text * plot.ylim()[-1], text_mass, fontsize = fontsize, color = 'black', horizontalalignment = 'right')
    #plot.text(0.84 * x_range / 2.0 + x_mid, y_text * plot.ylim()[-1], text_visc, fontsize = fontsize, color = 'black', horizontalalignment = 'left')

    # Save, Show, and Close
    if version is None:
        save_fn = "%s/maximumCondition_%04d.png" % (save_directory, frame)
    else:
        save_fn = "%s/v%04d_maximumCondition_%04d.png" % (save_directory,
                                                          version, frame)
    plot.savefig(save_fn, bbox_inches='tight', dpi=dpi)

    if show:
        plot.show()

    plot.close(fig)  # Close Figure (to avoid too many figures)