Ejemplo n.º 1
0
def center_vortex(density, frame, reference_density=None):
    """ Step 2: center the vortex so that the peak is at 180 degrees """
    if taper_time < 1.1:
        for i, size in enumerate(sizes):
            shift_i = az.get_azimuthal_peak(density[:, :, i], fargo_par)
            density[:, :, i] = np.roll(density[:, :, i], shift_i, axis=1)
        return density

    elif taper_time > 1.1:
        for i, size_name in enumerate(size_names):
            if center == "lookup":
                pass
                #shift_i = az.get_lookup_shift(frame, directory = "../%s-size" % size_name)
            elif center == "threshold":
                threshold = util.get_threshold(size) * surface_density_zero
                shift_i = az.get_azimuthal_center(density[:, :, i],
                                                  fargo_par,
                                                  threshold=threshold)
            elif center == "away":
                shift_i = az.shift_away_from_minimum(reference_density,
                                                     fargo_par)
            else:
                print "invalid centering option"
            density[:, :, i] = np.roll(density[:, :, i], shift_i, axis=1)
        return density
def shift_density(normalized_density,
                  fargo_par,
                  option="away",
                  reference_density=None,
                  frame=None):
    """ shift density based on option """
    if reference_density is None:
        reference_density = normalized_density

    # Options
    if option == "peak":
        shift_c = az.get_azimuthal_peak(reference_density, fargo_par)
    elif option == "threshold":
        threshold = util.get_threshold(fargo_par["PSIZE"])
        shift_c = az.get_azimuthal_center(reference_density,
                                          fargo_par,
                                          threshold=threshold)
    elif option == "away":
        shift_c = az.shift_away_from_minimum(reference_density, fargo_par)
    elif option == "lookup":
        shift_c = az.get_lookup_shift(frame)
    else:
        print "Invalid centering option. Choose (cm-)peak, (cm-)threshold, (cm-)away, or lookup"

    # Shift
    shifted_density = np.roll(normalized_density, shift_c)
    return shifted_density, shift_c
def full_procedure(frame, show=False):
    """ Every Step """
    # Read Data
    density = util.read_data(frame,
                             'input_density',
                             fargo_par,
                             id_number=id_number).T  # Note: Transpose!!!!

    # Choose shift option
    if center:
        #### Note: Re-work this section! The input density is already centered, but you still need the shift for the plot
        # Center vortex
        if fargo_par["MassTaper"] < 10.1:
            shift_c = az.get_azimuthal_peak(density, fargo_par)
        else:
            gas_fargo_par = util.get_pickled_parameters(
                directory="../cm-size")  ## 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']
            dust_surface_density_zero = gas_surface_density_zero / 100.0

            dust_density = util.read_data(frame,
                                          'dust',
                                          gas_fargo_par,
                                          id_number=id_number,
                                          directory="../cm-size")

            # Shift input density with center of dust density
            shift_c = az.get_azimuthal_center(dust_density,
                                              gas_fargo_par,
                                              threshold=10.0 *
                                              dust_surface_density_zero)
    else:
        shift_c = None

    # Get and plot profiles
    azimuthal_radii, azimuthal_profiles = az.get_profiles(density,
                                                          fargo_par,
                                                          args,
                                                          shift=None)
    make_plot(frame, shift_c, azimuthal_radii, azimuthal_profiles, show=show)
Ejemplo n.º 4
0
def full_procedure(frame, show=False):
    """ Every Step """
    # Read Data
    density = util.read_dust_data(frame, fargo_par)

    # Choose shift option
    if center:
        """
        # Choose source
        if taper < 10.1:
            src_density = np.copy(density)
            this_threshold = threshold
        elif taper > 999.9:
            # hum-size or larger (for now, T = 1000)
            src_density = np.copy(density)
            this_threshold = threshold
        else:
            # smaller than hmm-size (right now micron only)
            hmm_directory = "/rsgrps/kkratterstudents/mhammer/fargo_tests/fargoDUST/one_jupiter_old/half-mm-size/no_diffusion/taper%d" % taper
            src_density = util.read_dust_data(frame, fargo_par, directory = hmm_directory)

            ##### Set threshold here!!!! ####
            this_threshold = util.get_threshold(0.01)
        """

        # Center vortex
        if fargo_par["MassTaper"] < 10.1:
            shift_c = az.get_azimuthal_peak(density, fargo_par)
        else:
            shift_c = az.get_azimuthal_center(density,
                                              fargo_par,
                                              threshold=threshold)
    else:
        shift_c = None

    # Get and plot profiles
    azimuthal_radii, azimuthal_profiles = az.get_profiles(density,
                                                          fargo_par,
                                                          args,
                                                          shift=shift_c)
    make_plot(frame, shift_c, azimuthal_radii, azimuthal_profiles, show=show)
Ejemplo n.º 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
    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)
def make_plot(frame, show=False):
    # Set up figure
    fig = plot.figure(figsize=(7, 6), dpi=dpi)
    ax = fig.add_subplot(111)

    # Data
    gas_density = (fromfile("gasdens%d.dat" % frame).reshape(
        num_rad, num_theta))
    dust_density = (fromfile("gasddens%d.dat" % frame).reshape(
        num_rad, num_theta))
    radial_velocity = (fromfile("gasdvrad%d.dat" % frame).reshape(
        num_rad, num_theta))
    azimuthal_velocity = (fromfile("gasdvtheta%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) * 1.5
            shift_c = az.get_azimuthal_center(dust_density,
                                              fargo_par,
                                              threshold=threshold *
                                              surface_density_zero)
        radial_velocity = np.roll(radial_velocity, shift_c)
        azimuthal_velocity = np.roll(azimuthal_velocity, shift_c)

    # Calculate Limiting Velocity
    d_rad = np.diff(rad)
    d_theta = np.diff(theta)

    dv_rad = np.diff(radial_velocity, axis=1)
    print np.max(dv_rad)
    dv_theta = np.diff(rad[:, None] * azimuthal_velocity, axis=0)
    print np.max(dv_theta)

    r_maxes = np.max(dv_rad, axis=1)
    t_maxes = np.max(dv_theta, axis=1)

    for (r_i, r_max_i, t_max_i) in zip(rad[1:], r_maxes, t_maxes):
        print r_i, r_max_i, t_max_i

    #limiting_velocity_grid = [np.max([dv_rad, dv_theta], axis = 0)]
    limiting_velocity_grid = dv_rad

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

    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(gas_density / gas_surface_density_zero),
                     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
    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')

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

    # Data
    field = "dens"
    density = Fields("./", 'gas',
                     frame).get_field(field).reshape(num_rad, num_theta)
    normalized_density = density / surface_density_zero

    field = "dens"
    density = Fields("./", 'dust%d' % dust_number,
                     frame).get_field(field).reshape(num_rad, num_theta)
    normalized_density = density / dust_surface_density_zero

    field = "vx"  # radial
    radial_velocity = Fields("./", 'dust%d' % dust_number,
                             frame).get_field(field).reshape(
                                 num_rad, num_theta)

    field = "vy"  # azimuthal
    azimuthal_velocity = Fields("./", 'dust%d' % dust_number,
                                frame).get_field(field).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) * 1.5
            shift_c = az.get_azimuthal_center(dust_density,
                                              fargo_par,
                                              threshold=threshold *
                                              surface_density_zero)
        radial_velocity = np.roll(radial_velocity, shift_c)
        azimuthal_velocity = np.roll(azimuthal_velocity, shift_c)

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

    delta_r = rad[1] - rad[0]
    r_delta_theta = (rad * (theta[1] - theta[0]))[:, None]
    cfl = np.abs(radial_velocity) / (delta_r) + np.abs(azimuthal_velocity) / (
        r_delta_theta)

    cfl_max = 0.4
    delta_t = cfl_max / cfl

    critical_location = np.unravel_index(np.argmin(delta_t), np.shape(delta_t))
    critical_location = (rad[critical_location[0]], theta[critical_location[1]]
                         )  # convert to rad and theta

    # Print Overall Min
    print np.min(delta_t), critical_location

    # Print min at each radius
    minima = np.min(delta_t, axis=0)
    for i, (rad_i, min_i) in enumerate(zip(rad, minima)):
        if i % 4 == 0:
            print rad_i, min_i

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

    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(gas_density / gas_surface_density_zero),
                     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
    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')

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

    ### Data ###
    density1 = util.read_data(frame_range[0], 'dust', fargo_par, directory = "../taper10/%s-size" % size_name) / surface_density_zero
    density2 = util.read_data(frame_range[1], 'dust', fargo_par, directory = "../taper750/%s-size" % size_name) / surface_density_zero

    # Choose shift option
    if center:
        shift1 = az.get_azimuthal_peak(density1, fargo_par)

        threshold = util.get_threshold(size)
        shift2 = az.get_lookup_shift(frame_range[1], directory = "../taper750/%s-size" % size_name)
    else:
        shift1 = None; shift2 = None

    azimuthal_radii1, azimuthal_profiles1 = az.get_profiles(density1, fargo_par, args, shift = shift1)
    azimuthal_radii2, azimuthal_profiles2 = az.get_profiles(density2, fargo_par, args, shift = shift2)

    ### Plot ###
    # Profiles
    x = theta * (180.0 / np.pi)
    if num_profiles > 1:
        for i, (radius, azimuthal_profile) in enumerate(zip(azimuthal_radii1, azimuthal_profiles1)):
            plot.plot(x, azimuthal_profile, linewidth = linewidth, dashes = dashes[i], c = colors1[i], alpha = alpha, label = labels1[i])
    else:
        i = 1
        plot.plot(x, azimuthal_profiles1, linewidth = linewidth, dashes = dashes[i], c = colors1[i], alpha = alpha, label = labels1[i])

    # Add a beak in the legend
    if num_profiles > 1:
        plot.plot([0.1, 0.1], [0.2, 0.2], c = 'white', label = "\t")

    if num_profiles > 1:
        for i, (radius, azimuthal_profile) in enumerate(zip(azimuthal_radii2, azimuthal_profiles2)):
            plot.plot(x, azimuthal_profile, linewidth = linewidth, dashes = dashes[i], c = colors2[i], alpha = alpha, label = labels2[i])
    else:
        i = 1
        plot.plot(x, azimuthal_profiles2, linewidth = linewidth, dashes = dashes[i], c = colors2[i], alpha = alpha, label = labels2[i])

    # Plot analytic
    if num_profiles > 1:
        middle_i = (num_profiles - 1) / 2; radius = azimuthal_radii1[middle_i] # middle
        #center_density = azimuthal_profiles[middle_i][(len(azimuthal_profiles[middle_i]) - 1) / 2]
        max_density = np.max(azimuthal_profiles1[middle_i])
    else:
        radius = azimuthal_radii1
        max_density = np.max(azimuthal_profiles1)

    aspect_ratio = (r_a / dr_a) * (dtheta_a * np.pi / 180.0) # (r / dr) * d\theta
    S = util.get_stokes_number(size) / (diffusion_factor * viscosity / scale_height**2) # St / \alpha

    analytic = np.array([az.get_analytic_profile(angle, r_a, dr_a, dtheta_a, aspect_ratio, S) for angle in (x - 180.0)])
    analytic = analytic / np.max(analytic) * max_density # Normalize and re-scale to max density

    # Mask outside vortex and plot
    masked_i = np.abs(x - 180.0) <= (dtheta_a / 2.0); masked_x = x[masked_i]; masked_y = analytic[masked_i]
    plot.plot(masked_x, masked_y, linewidth = linewidth, linestyle = "--", c = "k", label = r"$\mathrm{Analytic}$")

    # Mark Planet
    if shift1 is None:
        planet_loc1 = theta[0]
    else:
        if shift1 < -len(theta):
            shift1 += len(theta)
        planet_loc1 = theta[shift1] * (180.0 / np.pi)

    if shift2 is None:
        planet_loc2 = theta[0]
    else:
        if shift2 < -len(theta):
            shift2 += len(theta)
        planet_loc2 = theta[shift2] * (180.0 / np.pi)
    #plot.scatter(planet_loc1, 0, c = "r", s = 150, marker = "D", zorder = 100) # planet
    #plot.scatter(planet_loc2, 0, c = "b", s = 150, marker = "D", zorder = 100) # planet

    # Axes
    min_x = 0; max_x = 360
    plot.xlim(min_x, max_x)
    angles = np.linspace(min_x, max_x, 7)
    plot.xticks(angles)

    if max_y is None:
        plot.ylim(0, plot.ylim()[-1]) # No Input
    else:
        plot.ylim(0, max_y[frame_i - 1]) # Input

    # Annotate Axes
    time = fargo_par["Ninterm"] * fargo_par["DT"]
    orbit = (time / (2 * np.pi)) * frame
    current_mass = util.get_current_mass(orbit, taper_time, planet_mass = planet_mass)

    #plot.xlabel(r"$\phi - \phi_\mathrm{center}$ $\mathrm{(degrees)}$", fontsize = fontsize + 2)
    plot.xlabel(r"$\phi$ $\mathrm{(degrees)}$", fontsize = fontsize + 2)

    if frame_i == 1:
        plot.ylabel(r"$\Sigma$ / $\Sigma_\mathrm{0,}$ $_\mathrm{dust}$", fontsize = fontsize)

    # Legend
    #if frame_i == 2:
    #    plot.legend(loc = "upper right", bbox_to_anchor = (1.34, 0.94)) # outside of plot
    plot.legend(loc = "upper left")

    # Extra Annotation
    #rc_line1 = r"$r_\mathrm{c,\ T=10} = %.02f \ r_\mathrm{p}$" % azimuthal_radii1[(num_profiles - 1) / 2]
    #rc_line2 = r"$r_\mathrm{c,\ T=1000} = %.02f \ r_\mathrm{p}$" % azimuthal_radii2[(num_profiles - 1) / 2]
    #plot.text(-170, 0.90 * plot.ylim()[-1], rc_line1, fontsize = fontsize, horizontalalignment = 'left')
    #plot.text(-170, 0.80 * plot.ylim()[-1], rc_line2, fontsize = fontsize, horizontalalignment = 'left')

    if frame_i == 2:    
        center_x = 1.34 * plot.xlim()[-1]
        top_y = plot.ylim()[-1]

        line1 = "Radii"
        #plot.text(center_x, 0.95 * top_y, line1, fontsize = fontsize, horizontalalignment = 'center')

    # Title
    #title = "\n" + r"$t$ $=$ $%.1f$   " % (orbit) + "[$m_p(t)$ $=$ $%.2f$ $M_J$]" % (current_mass)
    size_label = util.get_size_label(size)
    stokes_number = util.get_stokes_number(size)

    title = r"%s$\mathrm{-size}$ $\mathrm{(St}_\mathrm{0}$ $=$ $%.03f \mathrm{)}$" % (size_label, stokes_number)
    plot.title("%s" % (title), fontsize = fontsize + 1, y = 1.015)
def add_to_plot(frame, fig, ax, num_frames, frame_i):
    # Convert size to number
    size_name = "cm"
    size = util.get_size(size_name)

    ### Data ###
    density = util.read_data(
        frame, 'dust', fargo_par,
        directory="../%s-size" % size_name) / surface_density_zero

    # Choose shift option
    if center:
        # Center vortex
        if fargo_par["MassTaper"] < 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)
    else:
        shift = None

    azimuthal_radii, azimuthal_profiles = az.get_profiles(density,
                                                          fargo_par,
                                                          args,
                                                          shift=shift)

    ### Plot ###
    # Profiles
    x = theta * (180.0 / np.pi) - 180.0
    for i, (radius, azimuthal_profile) in enumerate(
            zip(azimuthal_radii, azimuthal_profiles)):
        plot.plot(x,
                  azimuthal_profile,
                  linewidth=linewidth,
                  c=colors[i],
                  alpha=alpha,
                  label=labels[i])

    # Analytic
    middle_i = (num_profiles - 1) / 2
    radius = azimuthal_radii[middle_i]  # middle
    #center_density = azimuthal_profiles[middle_i][(len(azimuthal_profiles[middle_i]) - 1) / 2]
    max_density = np.max(azimuthal_profiles[middle_i])

    aspect_ratio = (r_a / dr_a) * (dtheta_a * np.pi / 180.0
                                   )  # (r / dr) * d\theta
    S = util.get_stokes_number(size) / (
        diffusion_factor * viscosity / scale_height**2)  # St / \alpha

    analytic = np.array([
        az.get_analytic_profile(angle, r_a, dr_a, dtheta_a, aspect_ratio, S)
        for angle in x
    ])
    analytic = analytic / np.max(
        analytic) * max_density  # Normalize and re-scale to max density

    # Mask outside vortex and plot
    masked_i = np.abs(x) <= (dtheta_a / 2.0)
    masked_x = x[masked_i]
    masked_y = analytic[masked_i]
    plot.plot(masked_x, masked_y, linewidth=linewidth, linestyle="--", c="k")

    # Mark Planet
    if shift is None:
        planet_loc = theta[0]
    else:
        if shift < -len(theta):
            shift += len(theta)
        planet_loc = theta[shift] * (180.0 / np.pi) - 180.0
    plot.scatter(planet_loc, 0, c="k", s=150, marker="D", zorder=100)  # planet

    # Axes
    if taper_time < 10.1:
        # T = 10
        max_x = 60
    else:
        # T = 1000
        max_x = 180
    plot.xlim(-max_x, max_x)
    angles = np.linspace(-max_x, max_x, 7)
    plot.xticks(angles)

    if max_y is None:
        plot.ylim(0, plot.ylim()[-1])  # No Input
    else:
        plot.ylim(0, max_y[frame_i - 1])  # Input

    if frame_i <= 2:
        # Remove unless bottom
        ax.set_xticklabels([])

    # Annotate Axes
    time = fargo_par["Ninterm"] * fargo_par["DT"]
    orbit = (time / (2 * np.pi)) * frame
    current_mass = util.get_current_mass(orbit,
                                         taper_time,
                                         planet_mass=planet_mass)

    if frame_i > 2:
        plot.xlabel(r"$\phi - \phi_\mathrm{center}$ $\mathrm{(degrees)}$",
                    fontsize=fontsize + 2)

    if frame_i % 2 == 1:
        plot.ylabel(r"$\Sigma$ / $\Sigma_\mathrm{0,}$ $_\mathrm{dust}$",
                    fontsize=fontsize)

    # Legend
    if frame_i == 2:
        plot.legend(loc="upper right",
                    bbox_to_anchor=(1.34, 0.94))  # outside of plot

    # Extra Annotation
    rc_line = r"$r_\mathrm{c} = %.02f$" % azimuthal_radii[(num_profiles - 1) /
                                                          2]
    plot.text(-170,
              0.85 * plot.ylim()[-1],
              rc_line,
              fontsize=fontsize,
              horizontalalignment='left')

    if frame_i % 2 == 0:
        center_x = 1.38 * plot.xlim()[-1]
        top_y = plot.ylim()[-1]

        if frame_i == 2:
            line = "Radii"
        elif frame_i == 4:
            line = "Analytic"
        plot.text(center_x,
                  0.95 * top_y,
                  line,
                  fontsize=fontsize,
                  horizontalalignment='center')
        plot.text(center_x,
                  0.95 * top_y,
                  line,
                  fontsize=fontsize,
                  horizontalalignment='center')

        if frame_i == 4:
            half_width = 0.12 * plot.xlim()[-1]
            analytic_legend_y0 = 0.85 * top_y

            analytic_legend_x = [
                1.005 * center_x - half_width, 1.005 * center_x + half_width
            ]
            analytic_legend_y = [analytic_legend_y0, analytic_legend_y0]
            plot.plot(analytic_legend_x,
                      analytic_legend_y,
                      linewidth=linewidth,
                      c='k',
                      linestyle="--",
                      clip_on=False)

    # Title
    title = "\n" + r"$t$ $=$ $%.1f$   " % (
        orbit) + "[$m_p(t)$ $=$ $%.2f$ $M_J$]" % (current_mass)
    plot.title("%s" % (title), fontsize=fontsize + 1)
Ejemplo n.º 13
0
def make_plot(frame, show=False):
    # Set up figure
    fig = plot.figure(figsize=(7, 6), dpi=dpi)

    ### Data ###
    for i, beam_i in enumerate(beams[::-1]):
        arc_beam_i = beam_i / distance
        label_i = r"$%.02f^{\prime\prime} (%2d \mathrm{\ AU})$" % (arc_beam_i,
                                                                   beam_i)

        intensity_polar = util.read_data(frame,
                                         'polar_intensity',
                                         fargo_par,
                                         id_number=id_number,
                                         directory="../beam%03d" % beam_i)
        if normalize:
            intensity_polar /= np.max(intensity_polar)
        azimuthal_radius, azimuthal_profile = az.get_profiles(intensity_polar,
                                                              fargo_par,
                                                              args,
                                                              shift=None)
        if normalize:
            azimuthal_profile /= np.max(azimuthal_profile)

        x = theta * (180.0 / np.pi)
        plot.plot(x,
                  azimuthal_profile,
                  linewidth=linewidths[i],
                  c=colors[i],
                  alpha=alphas[i],
                  linestyle=linestyles[i],
                  label=label_i)

    # Mark Planet (get shift first)
    if taper_time > 99.9:
        shift = az.get_lookup_shift(frame, directory="../../../cm-size")
    else:
        dust_density = util.read_data(frame,
                                      'dust',
                                      fargo_par,
                                      directory="../../../cm-size")
        shift = az.get_azimuthal_peak(dust_density, fargo_par)

    if shift is None:
        planet_loc = theta[0]
    else:
        if shift < -len(theta):
            shift += len(theta)
        planet_loc = theta[shift] * (180.0 / np.pi)
    plot.scatter(planet_loc, 0, c="k", s=150, marker="D", zorder=100)  # planet

    # Axes
    min_x = 0
    max_x = 360
    plot.xlim(min_x, max_x)
    angles = np.linspace(min_x, max_x, 7)
    plot.xticks(angles)

    if max_y is None:
        plot.ylim(0, plot.ylim()[-1])  # No Input
    else:
        plot.ylim(0, max_y)  # Input

    # Annotate Axes
    time = fargo_par["Ninterm"] * fargo_par["DT"]
    orbit = (time / (2 * np.pi)) * frame
    current_mass = util.get_current_mass(orbit,
                                         taper_time,
                                         planet_mass=planet_mass)

    plot.xlabel(r"$\phi$ $\mathrm{(degrees)}$", fontsize=fontsize + 2)
    plot.ylabel(r"$I$ / $I_\mathrm{max}$", fontsize=fontsize)

    # Title
    title = "\n" + r"$t$ $=$ $%.1f$   " % (
        orbit) + "[$m_p(t)$ $=$ $%.2f$ $M_J$]" % (current_mass)
    plot.title("%s" % (title), fontsize=fontsize + 1)

    # Legend
    #plot.legend(loc = "upper right", bbox_to_anchor = (1.38, 0.94)) # outside of plot
    if annotate:
        pass
    else:
        plot.legend(loc="upper left")

    # Extra Annotation (Location, Legend Label)
    center_x = 1.38 * plot.xlim()[-1]
    top_y = plot.ylim()[-1]

    line = r"$\mathrm{Beam\ Diameters}$"
    #plot.text(center_x, 0.95 * top_y, line, fontsize = fontsize - 1, horizontalalignment = 'center')

    # Annotate Peak Offsets
    # if False:
    #     this_frame = np.searchsorted(frames, frame)
    #     offset1 = offsets1[this_frame]; offset2 = offsets2[this_frame]; offset3 = offsets3[this_frame]; offset4 = offsets4[this_frame]

    #     line4 = "b = 40: %.1f" % (offset4)
    #     line3 = "b = 30: %.1f" % (offset3)
    #     line2 = "b = 20: %.1f" % (offset2)
    #     line1 = "b = 10: %.1f" % (offset1)

    #     start_y = 0.08 * plot.ylim()[-1]; linebreak = 0.08 * plot.ylim()[-1]
    #     plot.text(180, start_y + 3.0 * linebreak, line4, fontsize = fontsize, horizontalalignment = 'center')
    #     plot.text(180, start_y + 2.0 * linebreak, line3, fontsize = fontsize, horizontalalignment = 'center')
    #     plot.text(180, start_y + 1.0 * linebreak, line2, fontsize = fontsize, horizontalalignment = 'center')
    #     plot.text(180, start_y + 0.0 * linebreak, line1, fontsize = fontsize, horizontalalignment = 'center')

    if annotate:
        this_frame = np.searchsorted(frames, frame - 0.1)
        offset0 = offsets1[this_frame - 3]
        offset1 = offsets1[this_frame - 2]
        offset2 = offsets1[this_frame - 1]
        offset3 = offsets1[this_frame]
        offset4 = offsets1[this_frame + 1]
        offset5 = offsets1[this_frame + 2]

        line5 = "t = %d: %.1f (%.1f)" % (frame + 2, offset5, offset5 - offset4)
        line4 = "t = %d: %.1f (%.1f)" % (frame + 1, offset4, offset4 - offset3)
        line3 = "t = %d: %.1f (%.1f)" % (frame - 0, offset3, offset3 - offset2)
        line2 = "t = %d: %.1f (%.1f)" % (frame - 1, offset2, offset2 - offset1)
        line1 = "t = %d: %.1f (%.1f)" % (frame - 2, offset1, offset1 - offset0)

        start_y = 0.08 * plot.ylim()[-1]
        linebreak = 0.08 * plot.ylim()[-1]
        plot.text(180,
                  start_y + 4.0 * linebreak,
                  line1,
                  fontsize=fontsize,
                  horizontalalignment='center')
        plot.text(180,
                  start_y + 3.0 * linebreak,
                  line2,
                  fontsize=fontsize,
                  horizontalalignment='center')
        plot.text(180,
                  start_y + 2.0 * linebreak,
                  line3,
                  fontsize=fontsize,
                  horizontalalignment='center')
        plot.text(180,
                  start_y + 1.0 * linebreak,
                  line4,
                  fontsize=fontsize,
                  horizontalalignment='center')
        plot.text(180,
                  start_y + 0.0 * linebreak,
                  line5,
                  fontsize=fontsize,
                  horizontalalignment='center')

    # Save, Show, and Close
    plot.tight_layout()

    png = "png"
    pdf = "pdf"
    if version is None:
        save_fn = "%s/azimuthalIntensityProfiles_%04d.%s" % (save_directory,
                                                             frame, png)
        pdf_save_fn = "%s/azimuthalIntensityProfiles_%04d.%s" % (
            save_directory, frame, pdf)
    else:
        save_fn = "%s/v%04d_azimuthalIntensityProfiles_%04d.%s" % (
            save_directory, version, frame, png)
        pdf_save_fn = "%s/v%04d_azimuthalIntensityProfiles_%04d.%s" % (
            save_directory, version, frame, pdf)
    plot.savefig(save_fn, bbox_inches='tight', dpi=dpi)
    plot.savefig(pdf_save_fn, bbox_inches='tight', format="pdf")

    if show:
        plot.show()

    plot.close(fig)  # Close Figure (to avoid too many figures)
def add_to_plot(frame, fig, size_name, num_frames, frame_i):
    # Convert size to number
    size = util.get_size(size_name)

    ### Data ###
    density1 = util.read_data(
        frame_range[0],
        'dust',
        fargo_par,
        directory="../taper10/%s-size" % size_name) / surface_density_zero
    density2 = util.read_data(
        frame_range[1],
        'dust',
        fargo_par,
        directory="../taper1000/%s-size" % size_name) / surface_density_zero

    # Choose shift option
    if center:
        shift1 = az.get_azimuthal_peak(density1, fargo_par)

        threshold = util.get_threshold(size)
        shift2 = az.get_azimuthal_center(density2,
                                         fargo_par,
                                         threshold=threshold)
    else:
        shift1 = None
        shift2 = None

    azimuthal_radii1, azimuthal_profiles1 = az.get_profiles(density1,
                                                            fargo_par,
                                                            args,
                                                            shift=shift1)
    azimuthal_radii2, azimuthal_profiles2 = az.get_profiles(density2,
                                                            fargo_par,
                                                            args,
                                                            shift=shift2)

    ### Plot ###
    # Profiles
    x = theta * (180.0 / np.pi) - 180.0
    middle_i = (num_profiles - 1) / 2

    middle_profile1 = azimuthal_profiles1[middle_i]
    plot.plot(x,
              middle_profile1,
              linewidth=linewidth,
              dashes=dashes[frame_i],
              c=colors[0],
              alpha=alpha,
              label=labels[frame_i])

    # Add a break in the legend
    plot.plot([0.1, 0.1], [0.2, 0.2], c='white', label="\t")

    middle_profile2 = azimuthal_profiles2[middle_i]
    plot.plot(x,
              middle_profile2,
              linewidth=linewidth,
              dashes=dashes[frame_i],
              c=colors[1],
              alpha=1.0,
              label=labels[frame_i])

    # Mark Planet
    if shift1 is None:
        planet_loc1 = theta[0]
    else:
        if shift1 < -len(theta):
            shift1 += len(theta)
        planet_loc1 = theta[shift1] * (180.0 / np.pi) - 180.0

    if shift2 is None:
        planet_loc2 = theta[0]
    else:
        if shift2 < -len(theta):
            shift2 += len(theta)
        planet_loc2 = theta[shift2] * (180.0 / np.pi) - 180.0
    #plot.scatter(planet_loc1, 0, c = "r", s = 150, marker = "D", zorder = 100) # planet
    #plot.scatter(planet_loc2, 0, c = "b", s = 150, marker = "D", zorder = 100) # planet

    # Axes
    max_x = 180
    plot.xlim(-max_x, max_x)
    angles = np.linspace(-max_x, max_x, 7)
    plot.xticks(angles)

    if max_y is None:
        plot.ylim(0, plot.ylim()[-1])  # No Input
    else:
        plot.ylim(0, max_y)  # Input

    # Annotate Axes
    time = fargo_par["Ninterm"] * fargo_par["DT"]
    orbit = (time / (2 * np.pi)) * frame
    current_mass = util.get_current_mass(orbit,
                                         taper_time,
                                         planet_mass=planet_mass)

    plot.xlabel(r"$\phi - \phi_\mathrm{center}$ $\mathrm{(degrees)}$",
                fontsize=fontsize + 2)

    if frame_i == 1:
        plot.ylabel(r"$\Sigma$ / $\Sigma_\mathrm{0,}$ $_\mathrm{dust}$",
                    fontsize=fontsize)

    # Legend
    if frame_i == 2:
        plot.legend(loc="upper right",
                    bbox_to_anchor=(1.34, 0.94))  # outside of plot

    # Extra Annotation
    #rc_line1 = r"$r_\mathrm{c,\ T=10} = %.02f \ r_\mathrm{p}$" % azimuthal_radii1[(num_profiles - 1) / 2]
    #rc_line2 = r"$r_\mathrm{c,\ T=1000} = %.02f \ r_\mathrm{p}$" % azimuthal_radii2[(num_profiles - 1) / 2]
    #plot.text(-170, 0.90 * plot.ylim()[-1], rc_line1, fontsize = fontsize, horizontalalignment = 'left')
    #plot.text(-170, 0.80 * plot.ylim()[-1], rc_line2, fontsize = fontsize, horizontalalignment = 'left')

    if frame_i == 2:
        center_x = 1.34 * plot.xlim()[-1]
        top_y = plot.ylim()[-1]

        line1 = "Radii"
        plot.text(center_x,
                  0.95 * top_y,
                  line1,
                  fontsize=fontsize,
                  horizontalalignment='center')

    # Title
    #title = "\n" + r"$t$ $=$ $%.1f$   " % (orbit) + "[$m_p(t)$ $=$ $%.2f$ $M_J$]" % (current_mass)
    size_label = util.get_size_label(size)
    stokes_number = util.get_stokes_number(size)

    title = r"%s$\mathrm{-size}$ $\mathrm{(St}_\mathrm{0}$ $=$ $%.03f \mathrm{)}$" % (
        size_label, stokes_number)
    plot.title("%s" % (title), fontsize=fontsize + 1)
Ejemplo n.º 15
0
def add_to_plot(frame, fig, ax, num_sizes, frame_i):
    # Declare Subplot
    #ax = plot.subplot(1, num_frames, frame_i, sharex = prev_ax, sharey = prev_ax, aspect = "equal")

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

    # Get Shift
    dust_fargo_par = util.get_pickled_parameters(directory = "../../../cm-size") ## shorten name?
    ######## Need to extract parameters, and add 'rad' and 'theta' ########
    dust_rad = np.linspace(dust_fargo_par['Rmin'], dust_fargo_par['Rmax'], dust_fargo_par['Nrad'])
    dust_theta = np.linspace(0, 2 * np.pi, dust_fargo_par['Nsec'])
    dust_fargo_par['rad'] = dust_rad; dust_fargo_par['theta'] = dust_theta
    gas_surface_density_zero = dust_fargo_par['Sigma0']

    dust_density = util.read_data(frame, 'dust', dust_fargo_par, id_number = id_number, directory = "../../../cm-size")

    # Shift gas density with peak or lookup shift
    if taper_time < 100:
        shift = az.get_azimuthal_peak(dust_density, fargo_par)
    else:
        shift = az.get_lookup_shift(frame, directory = "../../../cm-size")

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

    # Arcseconds or Planet Radii
    if arc:
        arc_weight = planet_radius / distance # related to parallax
    else:
        arc_weight = 1

    ## Plot! ##
    result = plot.pcolormesh(xs * arc_weight, ys * arc_weight, np.transpose(intensity_cart), cmap = cmap)
    result.set_clim(clim[0], clim[1])

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

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

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

    # Locate Planet
    if shift < -len(dust_theta):
        shift += len(dust_theta)
    planet_theta = dust_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 * arc_weight, planet_y * arc_weight, c = "white", s = int(70 * planet_size), marker = "D", zorder = 100) # planet

    # Annotate Axes
    if arc:
        unit = "^{\prime\prime}"
    else:
        unit = "r_\mathrm{p}"

    ax.set_xlabel(r"$x$ [$%s$]" % unit, fontsize = fontsize)
    if frame_i == 1:
        ax.set_ylabel(r"$y$ [$%s$]" % unit, fontsize = fontsize)

    # Axes
    box_size = args.box * arc_weight
    ax.set_xlim(-box_size, box_size)
    ax.set_ylim(-box_size, box_size)
    ax.set_aspect('equal')

    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
    taper_title = r"$T_\mathrm{growth} = %d$" % taper_time
    plot.text(0.0 * box_size, 2 * arc_weight, taper_title, fontsize = fontsize, color = 'white', horizontalalignment = 'center', bbox=dict(facecolor = 'black', edgecolor = 'white', pad = 10.0))

    # Title
    title = r"$t$ $=$ $%.1f$  [$m_p(t)$ $=$ $%.2f$ $M_J$]" % (orbit, current_mass)
    plot.title("%s" % (title), y = 1.015, fontsize = fontsize + 1)

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

    # 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 == 2:
            cbar.set_label("Normalized Intensity", 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
Ejemplo n.º 16
0
def make_plot(frame, show=False):
    # Set up figure
    fig = plot.figure(figsize=(1400 / dpi, 600 / dpi), dpi=dpi)

    # Data
    gas_density = (fromfile("gasdens%d.dat" % frame).reshape(
        num_rad, num_theta))
    dust_density = (fromfile("gasddens%d.dat" % frame).reshape(
        num_rad, num_theta))
    if center:
        if taper < 10.1:
            shift_c = az.get_azimuthal_peak(dust_density, fargo_par)
        else:
            shift_c = az.get_azimuthal_center(dust_density,
                                              fargo_par,
                                              threshold=0.05 *
                                              surface_density_zero)
        gas_density = np.roll(gas_density, shift_c)
        dust_density = np.roll(dust_density, shift_c)

    ############################ Gas Density ##################################
    plot.subplot(1, 2, 1)

    # Data
    normalized_density = gas_density / surface_density_zero

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

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

    # 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

    title = readTitle()

    plot.xlabel("Radius", fontsize=fontsize)
    plot.ylabel(r"$\phi$", fontsize=fontsize)

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

    ############################ Dust Density #################################
    plot.subplot(1, 2, 2)

    # Data
    normalized_density = dust_density / (surface_density_zero / 100.0)

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

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

    # 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

    title = readTitle()

    plot.xlabel("Radius", 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)

    ###########################################################################

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