Ejemplo n.º 1
0
def get_middle_profile(directory):
    # Change directories
    cwd = os.getcwd()
    os.chdir(directory)

    ### Data ###
    intensity_polar = util.read_data(frame,
                                     'polar_intensity',
                                     fargo_par,
                                     id_number=id_number,
                                     directory=".")
    if normalize:
        intensity_polar /= np.max(intensity_polar)
    azimuthal_radii, azimuthal_profiles = az.get_profiles(intensity_polar,
                                                          fargo_par,
                                                          args,
                                                          shift=None)

    # Middle Profile
    middle_i = (num_profiles - 1) / 2
    middle_profile = azimuthal_profiles[middle_i]

    # Return to previous directory
    os.chdir(cwd)

    return middle_profile
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.º 3
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)
def make_plot(frame, show=False):
    # Set up figure
    fig = plot.figure(figsize=(7, 6), dpi=dpi)
    ax = fig.add_subplot(111)

    # Data
    intensity_polar = util.read_data(frame,
                                     'polar_intensity',
                                     fargo_par,
                                     id_number=id_number)
    if normalize:
        intensity_polar /= np.max(intensity_polar)
    _, azimuthal_profile = az.get_profiles(intensity_polar,
                                           fargo_par,
                                           args,
                                           shift=None)

    # Get Shift
    gas_density = util.read_data(frame, 'gas', fargo_par, directory="../../")

    # Shift gas density with center of dust density
    shift = az.shift_away_from_minimum(gas_density, fargo_par)

    ### Plot ###
    x = theta * (180.0 / np.pi) - 180.0
    plot.plot(x, azimuthal_profile, linewidth=linewidth, alpha=alpha)

    if args.compare is not None:
        for i, directory in enumerate(args.compare):
            intensity_polar_c = util.read_data(frame,
                                               'polar_intensity',
                                               fargo_par,
                                               id_number=id_number,
                                               directory=directory)
            if normalize:
                intensity_polar_c /= np.max(intensity_polar_c)
            _, azimuthal_profile_c = az.get_profiles(intensity_polar_c,
                                                     fargo_par,
                                                     args,
                                                     shift=None)
            plot.plot(x,
                      azimuthal_profile_c,
                      linewidth=linewidth,
                      alpha=alpha,
                      label="%s" % i)

        plot.legend(loc="upper left")

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

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

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

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

    ### Data ###
    intensity_polar = util.read_data(frame, 'polar_intensity', fargo_par, id_number = id_number)
    if normalize:
        intensity_polar /= np.max(intensity_polar)
    azimuthal_radii, azimuthal_profiles = az.get_profiles(intensity_polar, fargo_par, args, shift = None)

    ### 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], dashes = dashes[i], alpha = alpha, label = labels[i])

    # Mark Planet (get shift first)
    shift = az.get_lookup_shift(frame, directory = "../../../cm-size")

    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) # 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.ylabel(r"$I$ / $I_\mathrm{max}$", fontsize = fontsize)

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

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

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

    # Annotate Peak Offsets
    if annotate:
        frames = pickle.load(open("id%04d_b%d_t30_intensityFrames.p" % (id_number, beam_size * planet_radius), 'rb'))
        offsets_t3 = pickle.load(open("id%04d_b%d_t30_intensityPeaks.p" % (id_number, beam_size * planet_radius), 'rb'))
        offsets_t4 = pickle.load(open("id%04d_b%d_t40_intensityPeaks.p" % (id_number, beam_size * planet_radius), 'rb'))
        offsets_t5 = pickle.load(open("id%04d_b%d_t50_intensityPeaks.p" % (id_number, beam_size * planet_radius), 'rb'))

        this_frame = np.searchsorted(frames, frame)
        offset_t3 = offsets_t3[this_frame]; offset_t4 = offsets_t4[this_frame]; offset_t5 = offsets_t5[this_frame] 

        t3_line = "t = 0.3: %.1f" % (offset_t3)
        t4_line = "t = 0.4: %.1f" % (offset_t4)
        t5_line = "t = 0.5: %.1f" % (offset_t5)

        start_y = 0.08 * plot.ylim()[-1]; linebreak = 0.08 * plot.ylim()[-1]
        plot.text(0, start_y + 2.0 * linebreak, t5_line, fontsize = fontsize, horizontalalignment = 'center')
        plot.text(0, start_y + 1.0 * linebreak, t4_line, fontsize = fontsize, horizontalalignment = 'center')
        plot.text(0, start_y + 0.0 * linebreak, t3_line, fontsize = fontsize, horizontalalignment = 'center')

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

    # Title
    box_size = plot.xlim()[-1]; top_y = plot.ylim()[-1]
    left_x = -0.8 * box_size; line_y = 1.18 * top_y; linebreak = 0.2 * box_size
    right_x = 1.3 * box_size
    line1 = r"$%.03f^{\prime\prime} \times \ \ %.03f^{\prime\prime}$" % (arc_beam, arc_beam)
    plot.text(right_x, line_y, line1, horizontalalignment = 'right', fontsize = fontsize + 2)

    # 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)
Ejemplo n.º 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 and Plot
    for i in range(num_dust):
        j = i + 1
        density = fromfile("dust%ddens%d.dat" % (j, frame)).reshape(
            num_rad, num_theta)
        azimuthal_radius, azimuthal_profile = az.get_profiles(
            density, fargo_par, args)

        if normalize:
            azimuthal_profile /= np.max(azimuthal_profile)

        x = theta * (180.0 / np.pi)
        y = azimuthal_profile
        result = plot.plot(x,
                           y,
                           linewidth=linewidth,
                           zorder=99,
                           label="%d" % j)
    plot.legend()

    # Axes
    x_min = theta_min
    x_max = theta_max

    if args.max_y is None:
        max_y = 1
    else:
        max_y = args.max_y

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

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

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

    current_mass += accreted_mass[frame]

    #title = readTitle()

    plot.xlabel(r"$\phi$", fontsize=fontsize)
    plot.ylabel(r"$\Sigma / \Sigma_0$", fontsize=fontsize)

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

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

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

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

    # Save, Show, and Close
    if version is None:
        save_fn = "%s/azimuthalDustProfiles_%04d.png" % (save_directory, frame)
    else:
        save_fn = "%s/v%04d_azimuthalDustProfiles_%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, 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.º 9
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)
Ejemplo n.º 10
0
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 ###
    intensity_polar = util.read_data(frame,
                                     'polar_intensity',
                                     fargo_par,
                                     id_number=id_number)
    if normalize:
        intensity_polar /= np.max(intensity_polar)
    azimuthal_radii, azimuthal_profiles = az.get_profiles(intensity_polar,
                                                          fargo_par,
                                                          args,
                                                          shift=None)

    # 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 center of dust density
    shift = az.get_azimuthal_center(dust_density,
                                    dust_fargo_par,
                                    threshold=10.0 * gas_surface_density_zero /
                                    100.0)

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

    # Mark Planet
    if shift is None:
        planet_loc = theta[0]
    else:
        if shift < -len(dust_theta):
            shift += len(dust_theta)
        planet_loc = dust_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)  # 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"$I$ / $I_\mathrm{0}$", 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:
        center_x = 1.38 * plot.xlim()[-1]
        top_y = plot.ylim()[-1]

        line = "Radii"
        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')

    # Title
    title = "\n" + r"$t$ $=$ $%.1f$   " % (
        orbit) + "[$m_p(t)$ $=$ $%.2f$ $M_J$]" % (current_mass)
    plot.title("%s" % (title), fontsize=fontsize + 1)
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)
def add_to_plot(frame, fig, ax, num_frames, frame_i):
    # Convert size to number
    size_name = "cm"
    size = util.get_size(size_name)

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

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

    ### Data ###
    intensity_polar = util.read_data(frame,
                                     'polar_intensity',
                                     fargo_par,
                                     id_number=id_number,
                                     directory="lambda%04d/beam%03d" %
                                     (args.wavelength, args.beam_size))
    if normalize:
        intensity_polar /= np.max(intensity_polar)
    azimuthal_radii, azimuthal_profiles = az.get_profiles(intensity_polar,
                                                          fargo_par,
                                                          args,
                                                          shift=None)

    # 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 center of dust density
    shift = az.get_azimuthal_center(dust_density,
                                    dust_fargo_par,
                                    threshold=10.0 * gas_surface_density_zero /
                                    100.0)

    ### 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],
                  dashes=dashes[i],
                  alpha=alpha,
                  label=labels[i])

    # Mark Planet
    if shift is None:
        planet_loc = theta[0]
    else:
        if shift < -len(dust_theta):
            shift += len(dust_theta)
        planet_loc = dust_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 = 180
    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)  # 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"$I$ / $I_\mathrm{max}$", 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.885 * plot.ylim()[-1],
              rc_line,
              fontsize=fontsize,
              horizontalalignment='left')

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

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

    # Label
    taper_title = r"$T_\mathrm{growth} = %d$" % taper_time
    plot.text(0.95 * plot.xlim()[-1],
              0.885 * plot.ylim()[-1],
              taper_title,
              fontsize=fontsize,
              color='black',
              horizontalalignment='right',
              bbox=dict(facecolor='white', edgecolor='black', pad=10.0))

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

    # Title
    box_size = plot.xlim()[-1]
    top_y = plot.ylim()[-1]
    left_x = -0.8 * box_size
    line_y = 1.18 * top_y
    linebreak = 0.2 * box_size
    right_x = 1.3 * box_size
    if frame_i == 1:
        pass
    elif frame_i == 2:
        line1 = r"$%.03f^{\prime\prime} \times \ \ %.03f^{\prime\prime}$" % (
            arc_beam, arc_beam)
        plot.text(right_x,
                  line_y,
                  line1,
                  horizontalalignment='right',
                  fontsize=fontsize + 2)

    # Return to previous directory
    os.chdir(cwd)
Ejemplo n.º 13
0
def make_plot(show = False):
    # Set up figure
    fig = plot.figure(figsize = (7, 6), dpi = dpi)
    ax = fig.add_subplot(111)

    px_scale = header['cdelt2'] * 3600
    num_x = header['naxis1']; num_y = header['naxis2']
    width = num_x * px_scale; height = num_y * px_scale

    xs = np.linspace(-width / 2, width / 2, num_x)
    ys = np.linspace(-height / 2, height / 2, num_x)

    ### Data ###
    intensity_cart = np.copy(deprojected_intensity)
    rs, thetas, rs_grid, thetas_grid, intensity_polar = sq.cartesian_to_polar(intensity_cart, xs, ys)
    if normalize:
        intensity_polar /= np.max(intensity_polar)

    intensity_polar = np.roll(intensity_polar, len(thetas) / 2, axis = 0) # Note: Must transpose after!!!
    azimuthal_radii, azimuthal_profiles = az.get_profiles(intensity_polar.T, header, args, shift = None, start = 0.2, end = 1)

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

    # 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
    plot.xlabel(r"$\phi - \phi_\mathrm{0}$ $\mathrm{(degrees)}$", fontsize = fontsize + 2)
    plot.ylabel(r"$\mathrm{Intensity}$", fontsize = fontsize)

    # Legend
    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.90 * plot.ylim()[-1], rc_line, fontsize = fontsize, horizontalalignment = 'left')
 
    center_x = 1.38 * plot.xlim()[-1]
    top_y = plot.ylim()[-1]

    line = "Radii"
    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')

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

    # Save, Show, and Close
    if version is None:
        save_fn = "%s/almaAzimuthalProfiles_%s.png" % (save_directory, header['savename'])
    else:
        save_fn = "%s/v%04d_almaAzimuthalProfiles_%s.png" % (save_directory, version, header['savename'])
    plot.savefig(save_fn, bbox_inches = 'tight', dpi = dpi)

    if show:
        plot.show()

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