コード例 #1
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)
    averagedDensity = np.average(density, axis=1)
    normalized_density = averagedDensity / 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)

    # Get Minima
    min_density = find_rossby_density(normalized_density, averaged_vorticity)

    # Print Update
    print "%d: %.3f, %.3f" % (frame, min_density, 1.0 / min_density)

    # Store Data
    gap_depth_over_time[i] = 1.0 / min_density
コード例 #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]
コード例 #3
0
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]
コード例 #4
0
def polish(density,
           frame,
           shift_i,
           size,
           cavity_cutoff=0.92,
           scale_density=1,
           scale_sizes=1):
    """ Step 1: get rid of inner cavity, scale dust densities to different grain size, and only keep dust with negative vorticity """
    # Cavity
    if cavity_cutoff is not None:
        cavity_cutoff_i = np.searchsorted(rad, cavity_cutoff)
        density[:cavity_cutoff_i] = 0.0

        outer_cutoff = 2.75
        outer_cutoff_i = np.searchsorted(rad, outer_cutoff)
        density[outer_cutoff_i:] = 0.0

    # Scale
    density *= scale_density
    size *= scale_sizes

    if negative_vorticity_only > 0:
        tmp_density = density[1:, 1:]

        # Get rid of dust where there is positive vorticity
        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)

        # Remember to shift the vorticity!
        vorticity = np.roll(vorticity, shift_i, axis=1)

        tmp_density[vorticity > 0] = 0.0
        density[1:, 1:] = tmp_density

        # Get rid of dust where density is below a threshold
        gas_density = fromfile("gasdens%d.dat" % frame).reshape(
            num_rad, num_theta) / surface_density_zero
        gas_density = np.roll(gas_density, shift_i, axis=1)

        threshold = negative_vorticity_only
        density[gas_density < threshold] = 0.0

    return density, size
コード例 #5
0
def make_plot(frame, show=False):
    # Set up figure
    fig = plot.figure(figsize=(7, 6), dpi=dpi)
    ax = fig.add_subplot(111)

    # Data
    if mpi:
        density = Fields("./", 'gas', frame).get_field("dens").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)
        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, :, :]

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

    normalized_midplane_density = midplane_density / surface_density_zero  # / np.sqrt(2.0 * np.pi) / scale_height_function[:, None]
    normalized_density = surface_density / surface_density_zero  # / np.sqrt(2.0 * np.pi) / scale_height_function[:, None]

    vorticity = utilVorticity.velocity_curl(midplane_vrad,
                                            midplane_vtheta,
                                            rad,
                                            theta,
                                            rossby=rossby,
                                            residual=residual)
    averaged_vorticity = np.average(vorticity, axis=1)

    delta_midplane_vtheta = midplane_vtheta - np.average(midplane_vtheta,
                                                         axis=1)
    delta_midplane_velocity = midplane_vrad * delta_midplane_vtheta

    scale_height_function = scale_height * np.power(rad, 1.0 + flaring_index)
    omega_function = np.power(rad, -1.5)
    sound_speed = scale_height_function * omega_function

    alpha = midplane_vrad * delta_midplane_vtheta / np.power(sound_speed, 2.0)
    average_alpha = np.average(alpha, axis=1)

    ### Plot ###
    x = rad
    y = average_alpha

    result, = plot.plot(x,
                        y,
                        linewidth=linewidth,
                        c="b",
                        label="min",
                        zorder=90)

    # Axes
    plot.xlim(x_min, x_max)
    plot.ylim(10**(-8), 3 * 10**(-1))
    plot.yscale('log')
    #plot.yticks(np.arange(y_range[0], y_range[1] + 1e-9, 0.005))

    # 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"$<\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

    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()[0], 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/averagedReynoldsStress_%04d.png" % (save_directory,
                                                          frame)
    else:
        save_fn = "%s/v%04d_averagedReynoldsStress_%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)
コード例 #6
0
def add_to_plot(frame, fig, ax, frame_i):
    # Declare Subplot
    #ax = plot.subplot(1, num_frames, frame_i, sharex = prev_ax, sharey = prev_ax, aspect = "equal")

    # Taper
    if frame_i == 1:
        taper_time = 10
    else:
        taper_time = 750

    # Change directories
    cwd = os.getcwd()
    os.chdir(directories[frame_i - 1])

    # Data
    vrad = (fromfile("gasvrad%d.dat" % frame).reshape(num_rad, num_theta)
            )  # add a read_vrad to util.py!
    vtheta = (fromfile("gasvtheta%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)

    # Shift
    density = (fromfile("gasdens%d.dat" % frame).reshape(
        num_rad, num_theta)) / surface_density_zero
    dust_density = (fromfile("gasddens%d.dat" % frame).reshape(
        num_rad, num_theta))
    if center:
        if taper_time < 10.1:
            shift_c = az.get_azimuthal_peak(dust_density, fargo_par)
        else:
            if center == "lookup":
                shift_c = az.get_lookup_shift(frame)
            elif option == "away":
                shift_c = az.shift_away_from_minimum(dust_density, fargo_par)
            elif center == "threshold":
                threshold = util.get_threshold(size)
                shift_c = az.get_azimuthal_center(dust_density,
                                                  fargo_par,
                                                  threshold=threshold *
                                                  surface_density_zero / 100.0)
            else:
                shift_c = 0  # Do not center
        vorticity = np.roll(vorticity, shift_c)
        density = np.roll(density, shift_c)

    ### Plot ###
    x = rad
    y = theta * (180.0 / np.pi)
    result = ax.pcolormesh(x, y, np.transpose(vorticity), cmap=cmap)

    #if frame_i == 2:
    #    cbar = fig.colorbar(result)

    result.set_clim(clim[0], clim[1])

    if use_contours:
        levels = np.linspace(low_contour, high_contour, num_levels)
        colors = generate_colors(num_levels)
        plot.contour(x,
                     y,
                     np.transpose(density),
                     levels=levels,
                     origin='upper',
                     linewidths=1,
                     colors=colors,
                     alpha=0.8)

    # Axes
    y_min = 0
    y_max = 360
    plot.xlim(x_min, x_max)
    plot.ylim(y_min, y_max)

    angles = np.linspace(y_min, y_max, 7)
    plot.yticks(angles)

    # Annotate Axes
    time = fargo_par["Ninterm"] * fargo_par["DT"]
    orbit = (time / (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

    #title = readTitle()

    unit = "r_\mathrm{p}"
    plot.xlabel(r"Radius [$%s$]" % unit, fontsize=fontsize)
    if frame_i == 1:
        plot.ylabel(r"$\phi$ $\mathrm{(degrees)}$", fontsize=fontsize + 2)

    #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)
    title2 = r"$t = %d$ $\mathrm{orbits}}$  [$m_\mathrm{p}(t)\ =\ %.2f$ $M_\mathrm{J}$]" % (
        orbit, current_mass)
    plot.title("%s" % (title2), y=1.015, fontsize=fontsize + 1)
    plot.text(x_mid,
              y_text * (plot.ylim()[-1] - plot.ylim()[0]) + plot.ylim()[0],
              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{J}$" % (int(planet_mass))
    text_visc = r"$\nu = 10^{%d}$" % (int(np.log(viscosity) / np.log(10)))
    #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))
    if frame_i == 1:
        plot.text(-0.84 * x_range / 2.0 + x_mid,
                  y_text * (plot.ylim()[-1] - plot.ylim()[0]) + plot.ylim()[0],
                  text_mass,
                  fontsize=fontsize,
                  color='black',
                  horizontalalignment='right')
    if frame_i == 2:
        plot.text(0.84 * x_range / 2.0 + x_mid,
                  y_text * (plot.ylim()[-1] - plot.ylim()[0]) + plot.ylim()[0],
                  text_visc,
                  fontsize=fontsize,
                  color='black',
                  horizontalalignment='left')

    # Label colorbar
    # Add Colorbar (Source: http://stackoverflow.com/questions/23270445/adding-a-colorbar-to-two-subplots-with-equal-aspect-ratios)
    if frame_i < 5:
        # Only for last frame
        divider = make_axes_locatable(ax)
        cax = divider.append_axes("right", size="6%", pad=0.2)
        #cax = fig.add_axes([0.9, 0.1, 0.03, 0.8])
        cbar = fig.colorbar(result, cax=cax)

        if frame_i == 2:
            if rossby:
                cbar_name = r"$\mathrm{Rossby}$ $\mathrm{number}$"
            else:
                cbar_name = r"$\mathrm{Vorticity}$"
            cbar.set_label(cbar_name,
                           fontsize=fontsize,
                           rotation=270,
                           labelpad=32)

        #if frame_i != num_frames:
        #    fig.delaxes(cax) # to balance out frames that don't have colorbar with the one that does

    # Set Aspect Ratio
    #unit_aspect_ratio = (360) / (x_range)
    #ax.set_aspect(1.12 / unit_aspect_ratio)

    # Return to previous directory
    os.chdir(cwd)

    return ax
コード例 #7
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]
コード例 #8
0
    def add_to_plot(i):
        # Identify Subplot
        frame = frames[i]; number = i + 1
        ax = plot.subplot(1, 4, number)

        # Data
        if mpi:
          density = Fields("./", 'gas', frame).get_field("dens").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)
          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, :, :]

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

        normalized_midplane_density = midplane_density / surface_density_zero # / np.sqrt(2.0 * np.pi) / scale_height_function[:, None]
        normalized_density = surface_density / surface_density_zero # / np.sqrt(2.0 * np.pi) / scale_height_function[:, None]

        vorticity = utilVorticity.velocity_curl(midplane_vrad, midplane_vtheta, rad, theta, rossby = rossby, residual = residual)

        ### Plot ###
        x = rad
        y = theta * (180.0 / np.pi)
        result = ax.pcolormesh(x, y, np.transpose(vorticity), cmap = cmap)
        result.set_clim(clim[0], clim[1])

        # Contours
        if use_contours:
            levels = np.linspace(low_contour, high_contour, num_levels)
            colors = generate_colors(num_levels)
            plot.contour(x, y, np.transpose(normalized_density), levels = levels, origin = 'upper', linewidths = 1, colors = colors)

        # Axes
        plot.xlim(x_min, x_max)
        plot.ylim(0, 360)

        angles = np.linspace(0, 360, 7)
        plot.yticks(angles)

        # 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]

        unit = "r_\mathrm{p}"
        plot.xlabel(r"Radius [$%s$]" % unit, fontsize = fontsize)
        if number == 1:
           plot.ylabel(r"$\phi$ [degrees]", fontsize = fontsize)

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

        title = r"$t = %d$ [$m_\mathrm{p}=%.2f$ $M_\mathrm{J}$]" % (orbit, current_mass)
        plot.title("%s" % (title), y = 1.035, fontsize = fontsize + 1)

        # Add Colorbar (Source: http://stackoverflow.com/questions/23270445/adding-a-colorbar-to-two-subplots-with-equal-aspect-ratios)
        divider = make_axes_locatable(ax)
        cax = divider.append_axes("right", size = "6%", pad = 0.2)
        #cax = fig.add_axes([0.9, 0.1, 0.03, 0.8])
        cbar = fig.colorbar(result, cax = cax)

        # Label colorbar
        if rossby:
           cbar_name = r"$\mathrm{Rossby}$ $\mathrm{number}$"
        else:
           cbar_name = r"$\mathrm{Vorticity}$"
        cbar.set_label(cbar_name, fontsize = fontsize, rotation = 270, labelpad = 25)

        if number != len(frames):
            fig.delaxes(cax) # to balance out frames that don't have colorbar with the one that does
コード例 #9
0
def make_plot(frame, show=False):
    # Set up figure
    fig = plot.figure(figsize=(7, 6), dpi=dpi)
    ax = fig.add_subplot(111)

    # Data
    vrad = (fromfile("gasvrad%d.dat" % frame).reshape(num_rad, num_theta)
            )  # add a read_vrad to util.py!
    vtheta = (fromfile("gasvtheta%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)

    # Shift
    density = (fromfile("gasdens%d.dat" % frame).reshape(
        num_rad, num_theta)) / surface_density_zero
    dust_density = (fromfile("gasddens%d.dat" % frame).reshape(
        num_rad, num_theta))
    if center:
        if taper_time < 10.1:
            shift_c = az.get_azimuthal_peak(dust_density, fargo_par)
        else:
            threshold = util.get_threshold(size)
            shift_c = az.get_azimuthal_center(dust_density,
                                              fargo_par,
                                              threshold=threshold *
                                              surface_density_zero / 100.0)
        vorticity = np.roll(vorticity, shift_c)
        density = np.roll(density, shift_c)

    ### Plot ###
    x = rad
    y = theta * (180.0 / np.pi)
    result = ax.pcolormesh(x, y, np.transpose(vorticity), cmap=cmap)

    cbar = fig.colorbar(result)
    result.set_clim(clim[0], clim[1])

    if use_contours:
        levels = np.linspace(low_contour, high_contour, num_levels)
        colors = generate_colors(num_levels)
        plot.contour(x,
                     y,
                     np.transpose(density),
                     levels=levels,
                     origin='upper',
                     linewidths=1,
                     colors=colors,
                     alpha=0.8)

    # Axes
    plot.xlim(x_min, x_max)
    plot.ylim(0, 360)

    angles = np.linspace(0, 360, 7)
    plot.yticks(angles)

    # Annotate Axes
    time = fargo_par["Ninterm"] * fargo_par["DT"]
    orbit = (time / (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

    #title = readTitle()

    unit = "r_\mathrm{p}"
    plot.xlabel(r"Radius [$%s$]" % unit, fontsize=fontsize)
    plot.ylabel(r"$\phi$", 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)
    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')

    # Label colorbar
    if rossby:
        cbar_name = r"$\mathrm{Rossby}$ $\mathrm{number}$"
    else:
        cbar_name = r"$\mathrm{Vorticity}$"
    cbar.set_label(cbar_name, fontsize=fontsize, rotation=270, labelpad=25)

    # Save, Show, and Close
    if version is None:
        save_fn = "%s/vorticityMap_%04d.png" % (save_directory, frame)
    else:
        save_fn = "%s/v%04d_vorticityMap_%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)
コード例 #10
0
def make_plot(frame_range, show=False):
    # Set up figure
    fig = plot.figure(figsize=(7, 6), 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)
        averaged_vortensity = averaged_vorticity / averaged_density[1:]

        ### Plot ###
        x = rad[1:]
        y = averaged_vortensity
        result = plot.plot(x,
                           y,
                           c=colors[i % len(colors)],
                           linewidth=linewidth,
                           linestyle=linestyles[i % 2],
                           zorder=99,
                           label=r"$t$ $=$ $%d$ $T_\mathrm{p}$" % frame)

    plot.legend(loc="lower right", fontsize=fontsize - 7)

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

    #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"($\nabla \times v$)$_\mathrm{z}$ $/$ $\Sigma$ [$v_\mathrm{K}$ $/$ $r_\mathrm{p}$ $\Sigma_0$]",
        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)
    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]

    if version is None:
        save_fn = "%s/averagedVortensity_%s_%04d-%04d-%04d.png" % (
            save_directory, directory_name, args.frames[0], args.frames[1],
            args.frames[2])
    else:
        save_fn = "%s/v%04d_averagedVortensity_%s_%04d-%04d-%04d.png" % (
            save_directory, version, directory_name, args.frames[0],
            args.frames[1], args.frames[2])
    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_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)
コード例 #12
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]
コード例 #13
0
    def add_to_plot(i):
        # Identify Subplot
        frame = frames[i]
        number = i + 1
        ax = plot.subplot(1, 2, number)

        # 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)

        # Shift
        if center:
            normalized_density, vorticity, shift_c = shift_density(
                normalized_density,
                vorticity,
                fargo_par,
                reference_density=normalized_density)

        ### Plot ###
        x = rad
        y = theta * (180.0 / np.pi)
        result = ax.pcolormesh(x, y, np.transpose(vorticity), cmap=cmap)
        result.set_clim(clim[0], clim[1])

        # Contours
        if use_contours:
            levels = np.linspace(low_contour, high_contour, num_levels)
            colors = generate_colors(num_levels)
            plot.contour(x,
                         y,
                         np.transpose(normalized_density),
                         levels=levels,
                         origin='upper',
                         linewidths=1,
                         colors=colors)

        if quiver:
            # Velocity
            radial_velocity = np.array(
                fromfile("gasvy%d.dat" % frame).reshape(num_rad,
                                                        num_theta))  # Radial
            azimuthal_velocity = np.array(
                fromfile("gasvx%d.dat" % frame).reshape(
                    num_rad, num_theta))  # Azimuthal
            keplerian_velocity = rad * (np.power(rad, -1.5) - 1)
            azimuthal_velocity -= keplerian_velocity[:, None]

            if center:
                radial_velocity = np.roll(radial_velocity, shift_c, axis=-1)
                azimuthal_velocity = np.roll(azimuthal_velocity,
                                             shift_c,
                                             axis=-1)

            # Sub-sample the grid
            start_i = np.searchsorted(rad, start_quiver)
            end_i = np.searchsorted(rad, end_quiver)

            x_q = x[start_i:end_i]
            y_q = y[:]
            u = np.transpose(radial_velocity)[:, start_i:end_i]
            v = np.transpose(azimuthal_velocity)[:, start_i:end_i]

            plot.quiver(x_q[::rate_x],
                        y_q[::rate_y],
                        u[::rate_y, ::rate_x],
                        v[::rate_y, ::rate_x],
                        scale=scale)

        # Axes
        plot.xlim(x_min, x_max)
        plot.ylim(0, 360)

        angles = np.linspace(0, 360, 7)
        plot.yticks(angles)

        # 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]
        #current_gap_depth = get_gap_depth(normalized_density)

        unit = "r_\mathrm{p}"
        plot.xlabel(r"Radius [$%s$]" % unit, fontsize=fontsize)
        if number == 1:
            plot.ylabel(r"$\phi$ [degrees]", fontsize=fontsize)

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

        title = r"$t = %d$ [$m_\mathrm{p}=%.2f$ $M_\mathrm{J}$]" % (
            orbit, current_mass)
        #title = r"$t = %d$ [$\delta_\mathrm{gap}=%.1f$]" % (orbit, current_gap_depth)
        plot.title("%s" % (title), y=1.035, fontsize=fontsize + 1)

        # Add Colorbar (Source: http://stackoverflow.com/questions/23270445/adding-a-colorbar-to-two-subplots-with-equal-aspect-ratios)
        divider = make_axes_locatable(ax)
        cax = divider.append_axes("right", size="6%", pad=0.2)
        #cax = fig.add_axes([0.9, 0.1, 0.03, 0.8])
        cbar = fig.colorbar(result, cax=cax)

        # Label colorbar
        if rossby:
            cbar_name = r"$\mathrm{Rossby}$ $\mathrm{number}$"
        else:
            cbar_name = r"$\mathrm{Vorticity}$"
        cbar.set_label(cbar_name, fontsize=fontsize, rotation=270, labelpad=25)

        if number != len(frames):
            fig.delaxes(
                cax
            )  # to balance out frames that don't have colorbar with the one that does
コード例 #14
0
def make_plot(frame, show=False):
    # Set up figure
    fig = plot.figure(figsize=(7, 6), dpi=dpi)
    ax = fig.add_subplot(111)

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

    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=False,
                                            residual=False)
    averaged_vorticity = np.average(vorticity, axis=1)

    #keplerian_velocity = 0.0 # put in rotating frame of spiral waves (it's already in rotating frame!)
    keplerian_velocity = rad * (np.power(
        rad, -1.5) - 1)  # in rotating frame, v_k = r * (r^-1.5 - r_p^-1.5)
    keplerian_frequency = np.power(rad, -1.5)
    #vtheta -= keplerian_velocity

    averaged_vtheta = np.average(vtheta, axis=1)
    dr = rad[1] - rad[0]
    averaged_dvtheta = np.diff(averaged_vtheta) / dr

    sound_speed_sq = np.power(scale_height * rad * keplerian_frequency, 2)
    diff_sound_speed_sq = np.diff(sound_speed_sq) / dr

    mach_number = averaged_vtheta / (scale_height * rad * keplerian_frequency
                                     )  # u_perp / c_s

    coefficient_one = -1.0 * np.power(np.power(mach_number, 2) - 1,
                                      2) / np.power(mach_number, 2)
    coefficient_two = np.power(mach_number, 2) - 1
    coefficient_three = -1.0 * np.power(mach_number, 2) - 1 / averaged_vtheta

    vorticityJump = coefficient_one[1:] * averaged_dvtheta + coefficient_two[
        1:] * averaged_vorticity + coefficient_three[1:] * diff_sound_speed_sq

    ### Plot ###
    x = rad[1:]
    y = vorticityJump
    result = plot.plot(x, y, linewidth=linewidth, zorder=99)

    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
    plot.xlim(x_min, x_max)
    plot.ylim(y_range[0], y_range[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"$\Delta \omega$", 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.5

    #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/averagedVorticityJump_%04d.png" % (save_directory, frame)
    else:
        save_fn = "%s/v%04d_averagedVorticityJump%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)
コード例 #15
0
def make_plot(frame, show = False):
    # Set up figure
    fig = plot.figure(figsize = (7, 6), dpi = dpi)
    host = fig.add_subplot(111)

    # 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))

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

    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])

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

    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"$\Sigma$ $/$ ($\nabla \times v$)$_\mathrm{z}$", 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/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)
    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)

    # 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)
コード例 #16
0
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)
コード例 #17
0
def make_plot(z_level, show=False):
    # Set up figure
    fig = plot.figure(figsize=(7, 6), dpi=dpi)
    ax = fig.add_subplot(111)

    # Data
    if mpi:
        density = Fields("./", 'gas', frame).get_field("dens").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)
        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 + z_level, :, :]
    midplane_vrad = vrad[num_z / 2 + z_level, :, :]
    midplane_vtheta = vtheta[num_z / 2 + z_level, :, :]

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

    normalized_midplane_density = midplane_density / surface_density_zero  # / np.sqrt(2.0 * np.pi) / scale_height_function[:, None]
    normalized_density = surface_density / surface_density_zero  # / np.sqrt(2.0 * np.pi) / scale_height_function[:, None]

    vorticity = utilVorticity.velocity_curl(midplane_vrad,
                                            midplane_vtheta,
                                            rad,
                                            theta,
                                            rossby=rossby,
                                            residual=residual)

    # Shift
    if center:
        normalized_density, vorticity, shift_c = shift_density(
            normalized_density,
            vorticity,
            fargo_par,
            reference_density=normalized_density)

    ### Plot ###
    x = rad
    y = theta * (180.0 / np.pi)
    result = ax.pcolormesh(x, y, np.transpose(vorticity), cmap=cmap)

    cbar = fig.colorbar(result)
    result.set_clim(clim[0], clim[1])

    if use_contours:
        levels = np.linspace(low_contour, high_contour, num_levels)
        colors = generate_colors(num_levels)
        plot.contour(x,
                     y,
                     np.transpose(normalized_density),
                     levels=levels,
                     origin='upper',
                     linewidths=1,
                     colors=colors,
                     alpha=0.8)

    if quiver:
        # Velocity
        radial_velocity = vrad
        azimuthal_velocity = vtheta
        keplerian_velocity = rad * (np.power(rad, -1.5) - 1)
        azimuthal_velocity -= keplerian_velocity[:, None]

        if center:
            radial_velocity = np.roll(radial_velocity, shift_c, axis=-1)
            azimuthal_velocity = np.roll(azimuthal_velocity, shift_c, axis=-1)

        # Sub-sample the grid
        start_i = np.searchsorted(rad, start_quiver)
        end_i = np.searchsorted(rad, end_quiver)

        x_q = x[start_i:end_i]
        y_q = y[:]
        u = np.transpose(radial_velocity)[:, start_i:end_i]
        v = np.transpose(azimuthal_velocity)[:, start_i:end_i]

        plot.quiver(x_q[::rate_x],
                    y_q[::rate_y],
                    u[::rate_y, ::rate_x],
                    v[::rate_y, ::rate_x],
                    scale=scale)

    # Axes
    plot.xlim(x_min, x_max)
    plot.ylim(0, 360)

    angles = np.linspace(0, 360, 7)
    plot.yticks(angles)

    # Annotate Axes
    time = fargo_par["Ninterm"] * fargo_par["DT"]
    orbit = (time / (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"$\phi$", 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)
    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')

    # Label colorbar
    if rossby:
        cbar_name = r"$\mathrm{Rossby}$ $\mathrm{number}$"
    else:
        cbar_name = r"$\mathrm{Vorticity}$"
    cbar.set_label(cbar_name, fontsize=fontsize, rotation=270, labelpad=25)

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

    if show:
        plot.show()

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

    # 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)

    vortex_tracker = np.percentile(normalized_density, 98, axis = 1)[1:] * np.percentile(vorticity, 2, axis = 1)

    ### Plot ###
    x = rad[1:]
    y = vortex_tracker
    result = plot.plot(x, y, linewidth = linewidth, zorder = 99)

    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
    plot.xlim(x_min, x_max)
    plot.ylim(y_range[0], y_range[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"($\nabla \times v$)$_\mathrm{z}$ $\times$ $\Sigma$ [$\Sigma_0$ $v_\mathrm{K}$ $/$ $r_\mathrm{p}$]", 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 = -0.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()[0], 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/radialVortexTracker_%04d.png" % (save_directory, frame)
    else:
        save_fn = "%s/v%04d_radialVortexTracker_%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)
コード例 #19
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)