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))
    normalized_density = density / surface_density_zero

    # Shift
    if center is "off":
        shift_c = 0
    #elif center.startswith("cm"):
    #   normalized_density, shift_c = shift_density(normalized_density, fargo_par, option = center[3:], reference_density = cm_dust_density, frame = frame)
    else:
        normalized_density, shift_c = shift_density(normalized_density,
                                                    fargo_par,
                                                    option=center,
                                                    frame=frame)

    # Convert to cartesian
    xs, ys, _, _, normalized_density_cart = sq.polar_to_cartesian(
        normalized_density, rad, theta)

    ### Plot ###
    result = ax.pcolormesh(xs,
                           ys,
                           np.transpose(normalized_density_cart),
                           cmap=cmap)

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

    cbar.set_label(r"Normalized Surface Density",
                   fontsize=fontsize + 2,
                   rotation=270,
                   labelpad=20)

    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_cart),
                     levels=levels,
                     origin='upper',
                     linewidths=1,
                     colors=colors)

    # Get rid of interior
    circle = plot.Circle((0, 0), min(rad), color="black")
    fig.gca().add_artist(circle)

    # Label star and planet
    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

    planet_size = (current_mass / planet_mass)
    plot.scatter(0, 0, c="white", s=300, marker="*", zorder=100)  # star
    plot.scatter(0, 1, c="white", s=int(70 * planet_size),
                 marker="D")  # planet

    # Add minor grid lines
    alpha = 0.2
    dashes = [1, 5]
    #plot.grid(b = True, which = 'major', color = "black", dashes = dashes, alpha = alpha)
    #plot.grid(b = True, which = 'minor', color = "black", dashes = dashes, alpha = alpha)
    #plot.minorticks_on()

    # Axes
    plot.xlim(-box, box)
    plot.ylim(-box, box)
    plot.axes().set_aspect('equal')

    # Annotate Axes
    unit = "r_\mathrm{p}"
    plot.xlabel(r"$x$ [$%s$]" % unit, fontsize=fontsize)
    plot.ylabel(r"$y$ [$%s$]" % unit, fontsize=fontsize)

    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(0.0,
              3.24,
              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(-1.7,
              3.24,
              text_mass,
              fontsize=fontsize,
              color='black',
              horizontalalignment='right')
    plot.text(1.7,
              3.24,
              text_visc,
              fontsize=fontsize,
              color='black',
              horizontalalignment='left')
    # Save, Show, and Close
    if version is None:
        save_fn = "%s/squareDensityMap_%04d.png" % (save_directory, frame)
    else:
        save_fn = "%s/v%04d_squareDensityMap_%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)
예제 #2
0
def polar_to_cartesian(intensity, order=3):
    """ Step 2: convert to cartesian """
    xs, ys, _, _, cartesian_intensity = sq.polar_to_cartesian(
        intensity, rad, theta)
    return xs, ys, cartesian_intensity
def make_plot(frame, show=False):
    # Set up figure
    fig = plot.figure(figsize=(7, 6), dpi=dpi)
    ax = fig.add_subplot(111)

    # Data
    fn = "id%04d_gasddens%d.p" % (id_number, frame)
    density = np.transpose(pickle.load(open(fn, "rb")))
    density /= surface_density_zero
    xs, ys, xs_grid, ys_grid, density_cart = sq.polar_to_cartesian(
        density, rad, theta)

    ### Plot ###
    result = plot.pcolormesh(xs_grid,
                             ys_grid,
                             np.transpose(density_cart),
                             cmap=cmap)
    cbar = fig.colorbar(result)

    result.set_clim(clim[0], clim[1])
    cbar.set_label(r"Normalized Surface Density",
                   fontsize=fontsize + 2,
                   rotation=270,
                   labelpad=20)

    # Get rid of interior
    circle = plot.Circle((0, 0), min(rad), color="black")
    fig.gca().add_artist(circle)

    # Add planet orbit
    planet_orbit = plot.Circle((0, 0),
                               1,
                               color="white",
                               fill=False,
                               alpha=0.8,
                               linestyle="dashed",
                               zorder=50)
    fig.gca().add_artist(planet_orbit)

    # Label star and planet
    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

    planet_size = current_mass / planet_mass
    plot.scatter(0, 0, c="white", s=300, marker="*", zorder=100)  # star
    plot.scatter(0,
                 1,
                 c="white",
                 s=int(70 * planet_size),
                 marker="D",
                 zorder=100)  # planet

    # Axes
    box_size = box
    plot.xlim(-box_size, box_size)
    plot.ylim(-box_size, box_size)
    plot.axes().set_aspect('equal')

    # Annotate Axes
    unit = "r_\mathrm{p}"
    plot.xlabel(r"$x$ [$%s$]" % unit, fontsize=fontsize)
    plot.ylabel(r"$y$ [$%s$]" % unit, fontsize=fontsize)

    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(0.0,
              3.24,
              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(-1.7,
              3.24,
              text_mass,
              fontsize=fontsize,
              color='black',
              horizontalalignment='right')
    plot.text(1.7,
              3.24,
              text_visc,
              fontsize=fontsize,
              color='black',
              horizontalalignment='left')

    # Save, Show,  and Close
    if version is None:
        save_fn = "%s/densityMap_%04d.png" % (save_directory, frame)
    else:
        save_fn = "%s/v%04d_densityMap_%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)
def add_to_plot(frame, fig, ax, size_name, num_sizes, frame_i):
    # Convert size to number
    size = util.get_size(size_name)

    # Declare Subplot
    #ax = plot.subplot(1, num_frames, frame_i, sharex = prev_ax, sharey = prev_ax, aspect = "equal")

    # Data
    this_fargo_par = fargo_par.copy()
    this_fargo_par["PSIZE"] = size

    if size_name == "um":
        # Gas case is separate!
        density = util.read_data(frame, 'dust', fargo_par, directory = "../cm-size")
        gas_density = util.read_data(frame, 'gas', fargo_par, directory = "../cm-size")
    else:
        density = util.read_data(frame, 'dust', this_fargo_par, directory = "../%s-size" % size_name)

    if center:
        if taper_time < 10.1:
            shift = az.get_azimuthal_peak(density, fargo_par)
        else:
            if size_name == "um":
                threshold = util.get_threshold(1.0) # get cm-size threshold instead
            else:
                threshold = util.get_threshold(size)
            shift = az.get_azimuthal_center(density, fargo_par, threshold = threshold * surface_density_zero)

        # Shift! (Handle gas case separately)
        if size_name == "um":
            density = np.roll(gas_density, shift) / 100.0
        else:
            density = np.roll(density, shift)
    normalized_density = density / surface_density_zero

    # Convert gas density to cartesian
    _, _, xs_grid, ys_grid, normalized_density = sq.polar_to_cartesian(normalized_density, rad, theta)

    ### Plot ###
    if size_name == "um":
        colormap = "viridis"
    else:
        colormap = cmap
    result = plot.pcolormesh(xs_grid, ys_grid, np.transpose(normalized_density), cmap = colormap)

    if size_name == "um":
        result.set_clim(0, 1.5)
    else:
        result.set_clim(clim[0], clim[1])

    # Get rid of interior
    circle = plot.Circle((0, 0), min(rad), color = "black")
    ax.add_artist(circle)

    # Add planet orbit
    planet_orbit = plot.Circle((0, 0), 1, color = "white", fill = False, alpha = 0.8, linestyle = "dashed", zorder = 50)
    ax.add_artist(planet_orbit)

    # Locate Planet
    if shift < -len(theta):
        shift += len(theta)
    planet_theta = theta[shift]
    planet_theta += (np.pi / 2.0) # Note: the conversion from polar to cartesian rotates everything forward by 90 degrees
    planet_theta = planet_theta % (2 * np.pi) # Keep 0 < theta < 2 * np.pi

    planet_x = np.cos(planet_theta)
    planet_y = np.sin(planet_theta)

    # Label star and planet
    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

    planet_size = current_mass / planet_mass
    plot.scatter(0, 0, c = "white", s = 300, marker = "*", zorder = 100) # star
    plot.scatter(planet_x, planet_y, c = "white", s = int(70 * planet_size), marker = "D", zorder = 100) # planet

    # Annotate Axes
    if frame_i > 2:
        ax.set_xlabel(r"$x$ [$r_\mathrm{p}$]", fontsize = fontsize)
    if frame_i % 2 == 1:
        ax.set_ylabel(r"$y$ [$r_\mathrm{p}$]", fontsize = fontsize)

    # Axes
    box_size = 2.5
    ax.set_xlim(-box_size, box_size)
    ax.set_ylim(-box_size, box_size)
    ax.set_aspect('equal')

    if frame_i > 1:
        ax.spines['bottom'].set_color('w'); ax.spines['top'].set_color('w'); ax.spines['left'].set_color('w'); ax.spines['right'].set_color('w')
        ax.tick_params(colors = 'white', labelcolor = 'black', width = 1, length = 5)

    # Label
    size_label = util.get_size_label(size)
    stokes_number = util.get_stokes_number(size)

    title = r"%s$\mathrm{-size}$" % size_label
    stokes = r"$\mathrm{St}_\mathrm{0}$ $=$ $%.03f$" % stokes_number
    if size_name == "um":
        title = r"$\mathrm{Gas\ Density}$"
        plot.text(-0.9 * box_size, 2, title, fontsize = fontsize, color = 'black', horizontalalignment = 'left', bbox=dict(facecolor = 'white', edgecolor = 'black', pad = 10.0))
    else:
        plot.text(-0.9 * box_size, 2, title, fontsize = fontsize, color = 'white', horizontalalignment = 'left', bbox=dict(facecolor = 'black', edgecolor = 'white', pad = 10.0))
        plot.text(0.9 * box_size, 2, stokes, fontsize = fontsize, color = 'white', horizontalalignment = 'right')
    #ax.set_title(title)
    frame_title = r"$t$ $=$ $%.1f$ [$m_p(t)$ $=$ $%.2f$ $M_J$]" % (orbit, current_mass)

    # Title
    left_x = -0.8 * box_size; line_y = 1.1 * box_size; linebreak = 0.2 * box_size
    right_x = 1.3 * box_size
    if frame_i == 1:
        line1 = r'$M_p = %d$ $M_J$' % planet_mass
        line2 = r'$\nu = 10^{%d}$' % round(np.log(viscosity) / np.log(10), 0)
        plot.text(left_x, line_y + linebreak, line1, horizontalalignment = 'left', fontsize = fontsize + 2)
        plot.text(left_x, line_y, line2, horizontalalignment = 'left', fontsize = fontsize + 2)

        if orbit < taper_time:
            # Add this white line to keep supertitle in the save frame
            plot.text(left_x, line_y + 2.0 * linebreak, line1, color = "white", horizontalalignment = 'left', fontsize = fontsize + 2)
    elif frame_i == 2 :
        line3 = r'$T_\mathrm{growth} = %d$ $\rm{orbits}$' % taper_time
        plot.text(right_x, line_y + 0.5 * linebreak, line3, horizontalalignment = 'right', fontsize = fontsize + 2)

    #if frame_i != 1:
    #    # Remove unless 1st frame
    #    ax.set_yticklabels([])

    # Add Colorbar (Source: http://stackoverflow.com/questions/23270445/adding-a-colorbar-to-two-subplots-with-equal-aspect-ratios)
    if colorbar:
        # Only for last frame
        divider = make_axes_locatable(ax)
        cax = divider.append_axes("right", size = "8%", pad = 0.2)
        #cax = fig.add_axes([0.9, 0.1, 0.03, 0.8])
        cbar = fig.colorbar(result, cax = cax)
        if frame_i == 1:
            cbar.set_label(r"$\Sigma$ / $\Sigma_\mathrm{0,}$ $_\mathrm{gas}$", fontsize = fontsize, rotation = 270, labelpad = 25)
        else:
            cbar.set_label(r"$\Sigma$ / $\Sigma_\mathrm{0,}$ $_\mathrm{dust}$", fontsize = fontsize, rotation = 270, labelpad = 25)

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

    return ax
예제 #5
0
def add_to_plot(frame, ax, size, num_sizes, frame_i):
    print frame, num_frames, frame_i

    # Declare Subplot
    #ax = plot.subplot(1, num_frames, frame_i, sharex = prev_ax, sharey = prev_ax, aspect = "equal")

    # Data
    this_fargo_par = fargo_par.copy()
    this_fargo_par["PSIZE"] = size

    density = util.read_data(frame,
                             'dust',
                             this_fargo_par,
                             id_number=id_number,
                             directory="../%s-size" % size)
    if center:
        if taper < 10.1:
            shift = az.get_azimuthal_peak(density, fargo_par)
        else:
            threshold = util.get_threshold(size)
            shift = az.get_azimuthal_center(density,
                                            fargo_par,
                                            threshold=threshold *
                                            surface_density_zero)
        density = np.roll(density, shift_c)
    normalized_density = density / surface_density_zero

    # Convert gas density to cartesian
    _, _, xs_grid, ys_grid, normalized_density = sq.polar_to_cartesian(
        normalized_density, rad, theta)

    ### Plot ###
    if size == "um":
        cmap = "viridis"
    result = plot.pcolormesh(xs_grid,
                             ys_grid,
                             np.transpose(normalized_density),
                             cmap=cmap)
    result.set_clim(clim[0], clim[1])

    # Get rid of interior
    circle = plot.Circle((0, 0), min(rad), color="black")
    ax.add_artist(circle)

    # Add planet orbit
    planet_orbit = plot.Circle((0, 0),
                               1,
                               color="white",
                               fill=False,
                               alpha=0.8,
                               linestyle="dashed",
                               zorder=50)
    ax.add_artist(planet_orbit)

    # Locate Planet
    if shift < -len(gas_theta):
        shift += len(gas_theta)
    planet_theta = gas_theta[shift]
    planet_theta += (
        np.pi / 2.0
    )  # Note: the conversion from polar to cartesian rotates everything forward by 90 degrees
    planet_theta = planet_theta % (2 * np.pi)  # Keep 0 < theta < 2 * np.pi

    planet_x = np.cos(planet_theta)
    planet_y = np.sin(planet_theta)

    # Label star and planet
    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

    planet_size = current_mass / planet_mass
    plot.scatter(0, 0, c="white", s=300, marker="*", zorder=100)  # star
    plot.scatter(planet_x,
                 planet_y,
                 c="white",
                 s=int(70 * planet_size),
                 marker="D",
                 zorder=100)  # planet

    # Annotate Axes
    ax.set_xlabel(r"$x$ [$r_p$]", fontsize=fontsize)
    if frame_i == 1:
        ax.set_ylabel(r"$y$ [$r_p$]", fontsize=fontsize)

    title = "Dust (%s-size) Density" % size
    if size == "um":
        title = "Gas Density"
    ax.set_title(title)
    frame_title = r"$t$ $=$ $%.1f$ [$m_p(t)$ $=$ $%.2f$ $M_J$]" % (
        orbit, current_mass)

    # Axes
    box_size = 2.5
    ax.set_xlim(-box_size, box_size)
    ax.set_ylim(-box_size, box_size)
    ax.set_aspect('equal')

    if frame_i != 1:
        # Remove unless 1st frame
        ax.set_yticklabels([])

    # Add Colorbar (Source: http://stackoverflow.com/questions/23270445/adding-a-colorbar-to-two-subplots-with-equal-aspect-ratios)
    if colorbar:
        # Only for last frame
        divider = make_axes_locatable(ax)
        cax = divider.append_axes("right", size="8%", pad=0.2)
        #cax = fig.add_axes([0.9, 0.1, 0.03, 0.8])
        cbar = fig.colorbar(result, cax=cax)
        cbar.set_label(r"$\Sigma$ / $\Sigma_\mathrm{0,}$ $_\mathrm{dust}$",
                       fontsize=fontsize,
                       rotation=270,
                       labelpad=25)

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

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

    # Data
    intensity = util.read_data(frame,
                               'polar_intensity',
                               fargo_par,
                               id_number=id_number)
    _, _, xs_grid, ys_grid, intensity_cart = sq.polar_to_cartesian(
        intensity, rad, theta)

    ### Plot ###
    result = plot.pcolormesh(xs_grid,
                             ys_grid,
                             np.transpose(intensity_cart),
                             cmap=cmap)
    cbar = fig.colorbar(result)

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

    # Get rid of interior
    circle = plot.Circle((0, 0), min(rad), color="black")
    fig.gca().add_artist(circle)

    # Add beam size
    beam = plot.Circle((-2, -2), beam_size / 2, color="white")
    fig.gca().add_artist(beam)

    # Label star and planet
    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

    planet_size = current_mass / planet_mass
    plot.scatter(0, 0, c="white", s=300, marker="*", zorder=100)  # star
    plot.scatter(0,
                 1,
                 c="white",
                 s=int(70 * planet_size),
                 marker="D",
                 zorder=100)  # planet

    # Annotate Axes
    plot.xlabel("Radius", fontsize=fontsize)
    plot.ylabel(r"$\phi$", fontsize=fontsize)
    plot.title("Intensity Map (t = %.1f)" % (orbit), fontsize=fontsize + 1)

    # Axes
    box_size = 2.5
    plot.xlim(-box_size, box_size)
    plot.ylim(-box_size, box_size)
    plot.axes().set_aspect('equal')

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

    if show:
        plot.show()

    plot.close(fig)  # Close Figure (to avoid too many figures)
예제 #7
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)
    normalized_density = density / surface_density_zero

    xs, ys, _, _, cartesian_density = sq.polar_to_cartesian(normalized_density, rad, theta)

    # Wave
    radii, wave_locations = getWaveLocations(density)
    wave_x, wave_y = cartesian_wave(radii, wave_locations + np.pi / 2)
    coefficients = np.polyfit(wave_x, wave_y, 3) # coefficients
    fit = np.poly1d(coefficients) # polynomial function

    fit_y = fit(wave_x)
    fit_r = np.sqrt(np.power(wave_x, 2) + np.power(wave_y, 2))
    fit_angle = np.arctan2(wave_y, wave_x)

    # Normal
    derivative_coefficients = np.polyder(coefficients) # derivative
    fit_derivative = np.poly1d(derivative_coefficients) # derivative function

    print coefficients
    print derivative_coefficients

    normal_vector_x = fit_derivative(wave_x)
    normal_vector_y = -1.0
    normalization = np.sqrt(1.0 + np.power(normal_vector_x, 2))

    normal_vector_x /= normalization
    normal_vector_y /= normalization

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

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

    # Trace wave
    #plot.plot(radii, wave_locations * (180.0 / np.pi), linewidth = linewidth, c = 'b', alpha = 0.75)
    plot.plot(wave_x, fit_y, linewidth = linewidth, c = 'r', alpha = 0.75)

    #print len(radii), len(fit_angle), np.shape(normal_r), np.shape(normal_angle)

    # Show normal
    rate = 4
    #plot.quiver(radii, wave_locations * (180.0 / np.pi), normal_r, normal_angle, scale = 0.1, color = "b")
    plot.quiver(wave_x[::rate], wave_y[::rate], normal_vector_x[::rate], normal_vector_y[::rate], scale = 10, color = "b")

    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)

    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
    box_size = 1.5
    plot.xlim(-box_size, box_size)
    plot.ylim(-box_size, box_size)
    plot.axes().set_aspect('equal')

    # 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"x [$%s$]" % unit, fontsize = fontsize)
    plot.ylabel(r"y [$%s$]" % unit, fontsize = fontsize)

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

    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)

    # Save, Show, and Close
    if version is None:
        save_fn = "%s/densityMap_%04d.png" % (save_directory, frame)
    else:
        save_fn = "%s/v%04d_densityMap_%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)
def make_plot(frame, show = False):
    # Set up figure
    fig = plot.figure(figsize = (14, 6), dpi = dpi)

    ############################## Left Panel #################################

    plot.subplot(1, 2, 1, aspect = 'equal')

    cwd = os.getcwd()
    os.chdir(dir1)

    # Data
    gas_fargo_par = util.get_pickled_parameters() ## shorten name?
    ######## Need to extract parameters, and add 'rad' and 'theta' ########
    gas_rad = np.linspace(gas_fargo_par['Rmin'], gas_fargo_par['Rmax'], gas_fargo_par['Nrad'])
    gas_theta = np.linspace(0, 2 * np.pi, gas_fargo_par['Nsec'])
    gas_fargo_par['rad'] = gas_rad; gas_fargo_par['theta'] = gas_theta
    gas_surface_density_zero = gas_fargo_par['Sigma0']

    gas_density = util.read_data(frame, 'gas', gas_fargo_par, id_number = id_number) / gas_surface_density_zero
    dust_density = util.read_data(frame, 'dust', gas_fargo_par, id_number = id_number)

    # Shift gas density with center of dust density
    shift = az.get_azimuthal_center(dust_density, gas_fargo_par, threshold = 10.0 * gas_surface_density_zero / 100.0)
    gas_density = np.roll(gas_density, shift)

    # Locate Planet
    if shift < -len(gas_theta):
        shift += len(gas_theta)
    planet_theta = gas_theta[shift]
    planet_theta += (np.pi / 2.0) # Note: the conversion from polar to cartesian rotates everything forward by 90 degrees
    planet_theta = planet_theta % (2 * np.pi) # Keep 0 < theta < 2 * np.pi

    planet_x = np.cos(planet_theta)
    planet_y = np.sin(planet_theta)

    # Convert gas density to cartesian
    _, _, xs_grid, ys_grid, gas_density = sq.polar_to_cartesian(gas_density, gas_rad, gas_theta)

    ### Plot ###
    result = plot.pcolormesh(xs_grid, ys_grid, np.transpose(gas_density), cmap = "viridis")
    cbar = fig.colorbar(result)

    result.set_clim(0, 1.5)

    # Get rid of interior
    circle = plot.Circle((0, 0), min(rad), color = "black")
    fig.gca().add_artist(circle)

    # Add planet orbit
    planet_orbit = plot.Circle((0, 0), 1, color = "white", fill = False, alpha = 0.8, linestyle = "dashed", zorder = 50)
    fig.gca().add_artist(planet_orbit)

    # Label star and planet
    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

    planet_size = current_mass / planet_mass
    plot.scatter(0, 0, c = "white", s = 300, marker = "*", zorder = 100) # star
    plot.scatter(planet_x, planet_y, c = "white", s = int(70 * planet_size), marker = "D", zorder = 100) # planet

    # Annotate Axes
    plot.xlabel("x", fontsize = fontsize)
    plot.ylabel("y", fontsize = fontsize)
    plot.title("Gas Density Map (t = %.1f)" % (orbit), fontsize = fontsize + 1)

    # Axes
    box_size = 2.5
    plot.xlim(-box_size, box_size)
    plot.ylim(-box_size, box_size)

    ############################# Right Panel #################################

    plot.subplot(1, 2, 2, aspect = 'equal')

    os.chdir(cwd)
    os.chdir(dir2)

    # Data
    intensity_cart = util.read_data(frame, 'cartesian_intensity', fargo_par, id_number = id_number)
    _, _, xs_grid, ys_grid = sq.get_cartesian_grid(rad)

    # Normalize
    if normalize:
        intensity_cart /= np.max(intensity_cart)

    ### Plot ###
    result = plot.pcolormesh(xs_grid, ys_grid, np.transpose(intensity_cart), cmap = cmap)
    cbar = fig.colorbar(result)

    if cmax is not None:
        result.set_clim(clim[0], clim[1])

    # Get rid of interior
    circle = plot.Circle((0, 0), min(rad), color = "black")
    fig.gca().add_artist(circle)

    # Add beam size
    beam = plot.Circle((-2, -2), beam_size / 2, color = "white")
    fig.gca().add_artist(beam)

    # Add planet orbit
    planet_orbit = plot.Circle((0, 0), 1, color = "white", fill = False, alpha = 0.8, linestyle = "dashed", zorder = 50)
    fig.gca().add_artist(planet_orbit)

    # Label star and planet
    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

    planet_size = current_mass / planet_mass
    plot.scatter(0, 0, c = "white", s = 300, marker = "*", zorder = 100) # star
    plot.scatter(planet_x, planet_y, c = "white", s = int(70 * planet_size), marker = "D", zorder = 100) # planet

    # Annotate Axes
    plot.xlabel("x", fontsize = fontsize)
    plot.ylabel("y", fontsize = fontsize)
    plot.title("Intensity Map (t = %.1f)" % (orbit), fontsize = fontsize + 1)

    # Axes
    box_size = 2.5
    plot.xlim(-box_size, box_size)
    plot.ylim(-box_size, box_size)

    ################################# End #####################################

    os.chdir(cwd)

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

    if show:
        plot.show()

    plot.close(fig) # Close Figure (to avoid too many figures)
def make_plot(frame, show = False):
    # Set up figure
    fig = plot.figure(figsize = (14, 6), dpi = dpi)

    # Data
    gas_density = util.read_data(frame, 'gas', fargo_par) / surface_density_zero
    dust_density = util.read_data(frame, 'dust', fargo_par) / dust_surface_density_zero

    # Shift gas density with center of dust density
    threshold = util.get_threshold(size)
    shift = az.get_azimuthal_center(dust_density, fargo_par, threshold = threshold)
    gas_density = np.roll(gas_density, shift)
    dust_density = np.roll(dust_density, shift)

    # Locate Planet
    if shift < -len(theta):
        shift += len(theta)
    planet_theta = theta[shift]
    planet_theta += (np.pi / 2.0) # Note: the conversion from polar to cartesian rotates everything forward by 90 degrees
    planet_theta = planet_theta % (2 * np.pi) # Keep 0 < theta < 2 * np.pi

    planet_x = np.cos(planet_theta)
    planet_y = np.sin(planet_theta)

    # Convert density to cartesian
    _, _, xs_grid, ys_grid, gas_density = sq.polar_to_cartesian(gas_density, rad, theta)
    _, _, _, _, dust_density = sq.polar_to_cartesian(dust_density, rad, theta)

    ############################## Left Panel #################################

    plot.subplot(1, 2, 1, aspect = 'equal')

    ### Plot ###
    result = plot.pcolormesh(xs_grid, ys_grid, np.transpose(gas_density), cmap = "viridis")
    cbar = fig.colorbar(result)

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

    # Get rid of interior
    circle = plot.Circle((0, 0), min(rad), color = "black")
    fig.gca().add_artist(circle)

    # Add planet orbit
    planet_orbit = plot.Circle((0, 0), 1, color = "white", fill = False, alpha = 0.8, linestyle = "dashed", zorder = 50)
    fig.gca().add_artist(planet_orbit)

    # Label star and planet
    time = fargo_par["Ninterm"] * fargo_par["DT"]
    orbit = (time / (2 * np.pi)) * frame
    orbit = 550 + (time / (2 * np.pi)) * (frame - 550)
    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

    # Use Fixed Mass
    current_mass = np.power(np.sin((np.pi / 2) * (550.0 / taper_time)), 2) * planet_mass

    planet_size = current_mass / planet_mass
    plot.scatter(0, 0, c = "white", s = 300, marker = "*", zorder = 100) # star
    plot.scatter(planet_x, planet_y, c = "white", s = int(70 * planet_size), marker = "D", zorder = 100) # planet

    # Annotate Axes
    plot.xlabel("x", fontsize = fontsize)
    plot.ylabel("y", fontsize = fontsize)
    plot.title("Gas Density Map (t = %.1f)" % (orbit), fontsize = fontsize + 1)

    # Axes
    box_size = 2.5
    plot.xlim(-box_size, box_size)
    plot.ylim(-box_size, box_size)

    ############################# Right Panel #################################

    plot.subplot(1, 2, 2, aspect = 'equal')

    ### Plot ###
    result = plot.pcolormesh(xs_grid, ys_grid, np.transpose(dust_density), cmap = cmap)
    cbar = fig.colorbar(result)

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

    # Get rid of interior
    circle = plot.Circle((0, 0), min(rad), color = "black")
    fig.gca().add_artist(circle)

    # Add planet orbit
    planet_orbit = plot.Circle((0, 0), 1, color = "white", fill = False, alpha = 0.8, linestyle = "dashed", zorder = 50)
    fig.gca().add_artist(planet_orbit)

    # Label star and planet
    planet_size = current_mass / planet_mass
    plot.scatter(0, 0, c = "white", s = 300, marker = "*", zorder = 100) # star
    plot.scatter(planet_x, planet_y, c = "white", s = int(70 * planet_size), marker = "D", zorder = 100) # planet

    # Annotate Axes
    plot.xlabel("x", fontsize = fontsize)
    plot.ylabel("y", fontsize = fontsize)
    plot.title("Dust Density Map (t = %.1f)" % (orbit), fontsize = fontsize + 1)

    # Axes
    box_size = 2.5
    plot.xlim(-box_size, box_size)
    plot.ylim(-box_size, box_size)

    ################################# End #####################################

    # Save, Show,  and Close
    if version is None:
        save_fn = "%s/bothDensityMaps_%04d.png" % (save_directory, frame)
    else:
        save_fn = "%s/v%04d_bothDensityMaps_%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)
def make_plot(frame, show=False):
    # Set up figure
    fig = plot.figure(figsize=(7, 6), dpi=dpi)
    ax = fig.add_subplot(111)

    # Data
    if merge > 0:
        num_merged_cores = merge
        density = util.read_merged_data(frame, num_merged_cores, num_rad,
                                        num_theta)
    elif mpi:
        field = "dens"
        density = Fields("./", 'gas',
                         frame).get_field(field).reshape(num_rad, num_theta)
    else:
        density = fromfile("gasdens%d.dat" % frame).reshape(num_rad, num_theta)
    normalized_density = density / surface_density_zero

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

    # Convert to cartesian
    xs, ys, _, _, normalized_density_cart = sq.polar_to_cartesian(
        normalized_density, rad, theta)

    ### Plot ###
    result = ax.pcolormesh(xs,
                           ys,
                           np.transpose(normalized_density_cart),
                           cmap=cmap)

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

    cbar.set_label(r"Normalized Surface Density",
                   fontsize=fontsize + 2,
                   rotation=270,
                   labelpad=20)

    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_cart),
                     levels=levels,
                     origin='upper',
                     linewidths=1,
                     colors=colors)

    # Get rid of interior
    circle = plot.Circle((0, 0), min(rad), color="black")
    fig.gca().add_artist(circle)

    # Add planet orbit
    planet_orbit = plot.Circle((0, 0),
                               1,
                               color="white",
                               fill=False,
                               alpha=0.8,
                               linestyle="dashed",
                               zorder=50)
    fig.gca().add_artist(planet_orbit)

    # Label star and planet
    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]

    if center:
        # Locate Planet
        if shift_c < -len(theta):
            shift_c += len(theta)
        planet_theta = theta[shift_c]
        planet_theta -= (
            np.pi / 2.0
        )  # Note: the conversion from polar to cartesian rotates everything forward by 90 degrees
        planet_theta = planet_theta % (2 * np.pi)  # Keep 0 < theta < 2 * np.pi

        planet_x = np.cos(planet_theta)
        planet_y = np.sin(planet_theta)
    else:
        planet_x = 0
        planet_y = 1

    planet_size = (current_mass / planet_mass)
    plot.scatter(0, 0, c="white", s=300, marker="*", zorder=100)  # star
    plot.scatter(planet_x,
                 planet_y,
                 c="white",
                 s=int(70 * planet_size),
                 marker="D")  # planet

    # Axes
    plot.xlim(-box, box)
    plot.ylim(-box, box)
    plot.axes().set_aspect('equal')

    # Annotate Axes

    # Annotate Axes
    unit = "r_\mathrm{p}"
    plot.xlabel(r"$x$ [$%s$]" % unit, fontsize=fontsize)
    plot.ylabel(r"$y$ [$%s$]" % unit, fontsize=fontsize)

    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(0.0,
              3.24,
              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(-1.7,
              3.24,
              text_mass,
              fontsize=fontsize,
              color='black',
              horizontalalignment='right')
    plot.text(1.7,
              3.24,
              text_visc,
              fontsize=fontsize,
              color='black',
              horizontalalignment='left')
    # Save, Show, and Close
    if version is None:
        save_fn = "%s/squareDensityMap_%04d.png" % (save_directory, frame)
    else:
        save_fn = "%s/v%04d_squareDensityMap_%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)