taper_time = fargo_par["MassTaper"]

surface_density_zero = fargo_par["Sigma0"]
disk_mass = 2 * np.pi * surface_density_zero * (r_max - r_min) / jupiter_mass # M_{disk} = (2 \pi) * \Sigma_0 * r_p * (r_out - r_in)

scale_height = fargo_par["AspectRatio"]
viscosity = fargo_par["Viscosity"]

size = fargo_par["PSIZE"]
"""

### Get Input Parameters ###

# Frame
frame = args.frame
zs_range = util.get_frame_range(args.zs)

# Number of Cores
num_cores = args.num_cores

# Files
save_directory = args.save_directory
if not os.path.isdir(save_directory):
    os.mkdir(
        save_directory)  # make save directory if it does not already exist

merge = args.merge
mpi = args.mpi

# Plot Parameters (variable)
show = args.show
planet_mass = fargo_par["PlanetMass"] / jupiter_mass
taper_time = fargo_par["MassTaper"]

surface_density_zero = fargo_par["Sigma0"]
disk_mass = 2 * np.pi * surface_density_zero * (r_max - r_min) / jupiter_mass # M_{disk} = (2 \pi) * \Sigma_0 * r_p * (r_out - r_in)

scale_height = fargo_par["AspectRatio"]
viscosity = fargo_par["Viscosity"]

size = fargo_par["PSIZE"]
"""

### Get Input Parameters ###

# Frames
frame_range = util.get_frame_range(args.frames)

# Number of Cores 
num_cores = args.num_cores

# Files
save_directory = args.save_directory
if not os.path.isdir(save_directory):
    os.mkdir(save_directory) # make save directory if it does not already exist

# Quantity to Plot
rossby = args.rossby
residual = args.residual

# Plot Parameters (variable)
show = args.show
    if "low_mass" in directory:
        azimuthal_profile /= (0.3)  # low-mass case

    maxima_over_time[i] = np.percentile(azimuthal_profile, 90)
    minima_over_time[i] = np.percentile(azimuthal_profile, 5)
    contrasts_over_time[i] = maxima_over_time[i] / minima_over_time[i]
    differences_over_time[i] = maxima_over_time[i] - minima_over_time[i]

    print i, frame, differences_over_time[i], maxima_over_time[
        i], minima_over_time[i], contrasts_over_time[i]


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

maxima_over_time = mp_array("d",
                            10 * len(util.get_frame_range(frame_ranges[0])))
minima_over_time = mp_array("d",
                            10 * len(util.get_frame_range(frame_ranges[0])))
contrasts_over_time = mp_array("d",
                               10 * len(util.get_frame_range(frame_ranges[0])))
differences_over_time = mp_array(
    "d", 10 * len(util.get_frame_range(frame_ranges[0])))

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

##### PLOTTING #####

colors = ['k', 'cornflowerblue', 'darkorange', 'r', 'purple']
labelsize = 19
size = 100
alpha = 0.8
def make_plot(show=False):
    # Set up figure
    fig, (ax1, ax2,
          ax3) = plot.subplots(3,
                               1,
                               figsize=(6, 12),
                               gridspec_kw={'height_ratios': [4, 6, 5]})

    # Iterate
    for i, directory in enumerate(directories):
        # Frame Range
        frame_range = util.get_frame_range(frame_ranges[i])
        dt = (frame_range[1] - frame_range[0]) * (
            2.0 * np.pi)  # for growth rate calculation

        start_time = start_times[i]
        start_time_i = az.my_searchsorted(frame_range, start_time)

        # Label
        if args.choice > 0:
            scale_height = float(directories[0].split("_")[0][1:]) / 100.0
            log_viscosity = float(directories[0].split("_")[1][2:]) - 2.0
        else:
            scale_height = 0.06
            log_viscosity = 5.0
        accretion_rate = accretion_rates[i]

        start_time = start_times[i]
        end_time = end_times[i]

        #label = r"$h =$ $%.02f$, $\alpha_\mathrm{visc} = 3 \times 10^{-%d}$, A = %.02f" % (scale_height, log_viscosity, accretion_rate)
        if args.choice > 0:
            if i == 4:
                master_label = r"$0.3$ $\Sigma_0$"
            else:
                master_label = r"$A = %.02f$" % (accretion_rate)
        else:
            labels = ["Default", "Restart"]
            label = labels[i]

        # Data
        #gap_depth_over_time = np.zeros(len(frame_range))

        #for i, frame in enumerate(frame_range):
        #    get_min((i, frame))

        pool_args = [(j, frame, directory)
                     for j, frame in enumerate(frame_range)]

        p = Pool(num_cores)
        p.map(get_contrasts, pool_args)
        p.terminate()

        num_frames = len(frame_range)
        this_maxima_over_time = np.array(maxima_over_time[:num_frames])
        this_minima_over_time = np.array(minima_over_time[:num_frames])
        this_contrasts_over_time = np.array(contrasts_over_time[:num_frames])
        this_differences_over_time = np.array(
            differences_over_time[:num_frames])

        this_smoothed_differences_over_time = smooth(
            this_differences_over_time, 5)
        this_growth_rates_over_time = np.diff(
            np.log(this_smoothed_differences_over_time)) / dt

        ##### Top Plot #####

        # Plot
        x = frame_range
        y1 = this_contrasts_over_time
        p1, = ax1.plot(x[start_time_i:],
                       y1[start_time_i:],
                       c=colors[i],
                       linewidth=linewidth,
                       zorder=99 - i)

        # Axes
        ax1.set_yscale('log')

        ax1.yaxis.set_major_formatter(ScalarFormatter())
        ax1.yaxis.set_minor_formatter(NullFormatter())

        if i == 3:
            ax1.set_xlim(x[0], x[-1])

        if scale_height == 0.08:
            ax1.set_ylim(1, 15)
            ax1.set_yticks([1, 3, 10])
        else:
            ax1.set_ylim(1, 7)
            ax1.set_yticks([1, 3, 7])

        # Annotate
        #ax1.set_xlabel("", fontsize = fontsize)
        ax1.set_ylabel("Contrast", fontsize=fontsize)

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

        title1 = r"$h = %.2f$    $\alpha = %s \times 10^{%d}$" % (
            scale_height, alpha_coefficent,
            int(round(np.log(viscosity) / np.log(10), 0)) + 2)
        #title1 = r"$A = %.2f$" % (accretion)
        ax1.set_title("%s" % (title1), y=1.035, fontsize=fontsize + 2)

        ##### Middle Plot #####

        label1 = ""
        label2 = ""
        if i == 0:
            label1 = r"$\Sigma_\mathrm{max}$"
            label2 = r"$\Sigma_\mathrm{min}$"

        y2 = this_maxima_over_time
        p2, = ax2.plot(x[start_time_i:],
                       y2[start_time_i:],
                       c=colors[i],
                       linewidth=linewidth,
                       label=label1,
                       zorder=99 - i)
        y3 = this_minima_over_time
        p3, = ax2.plot(x[start_time_i:],
                       y3[start_time_i:],
                       c=colors[i],
                       linewidth=linewidth - 2,
                       label=label2,
                       zorder=90 - i)

        # Axes
        if i == 3:
            ax2.set_xlim(x[0], x[-1])

        if scale_height == 0.08:
            ax2.set_ylim(0, 2.8)
            ax2.set_yticks([0, 0.5, 1, 1.5, 2, 2.5])
        else:
            ax2.set_ylim(0, 1.8)
            ax2.set_yticks([0, 0.5, 1, 1.5])

        # Annotate
        ax2.set_ylabel(r"$\Sigma$ $/$ $\Sigma_0$", fontsize=fontsize)
        ax2.legend(loc="upper right", fontsize=fontsize - 5)

        ##### Bottom Plot #####

        # Plot
        y4 = this_growth_rates_over_time
        p4, = ax3.plot(x[start_time_i:-5],
                       y4[start_time_i:-4],
                       c=colors[i],
                       linewidth=linewidth,
                       alpha=alpha,
                       label=master_label,
                       zorder=90 - i)

        # Axes
        if i == 3:
            ax3.set_xlim(x[0], x[-1])
        ax3.set_ylim(0.4 * 10**(-5), 0.4 * 10**(-2))
        ax3.set_yscale('log')

        ax3.set_yticks([10**(-5), 10**(-4), 10**(-3)])

        # Annotate
        ax3.set_xlabel("Time (planet orbits)", fontsize=fontsize)
        ax3.set_ylabel(r"Growth Rate", fontsize=fontsize)
        ax3.legend(loc="upper right", fontsize=fontsize - 5)

    # Save, Show, and Close
    if version is None:
        save_fn = "%s/growthRatesOverTime_choice%d.png" % (save_directory,
                                                           args.choice)
    else:
        save_fn = "%s/v%04d_growthRatesOverTime_choice%d.png" % (
            save_directory, version, arg.choice)
    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(show=False):
    # Set up figure
    if args.choice > 0:
        fig = plot.figure(figsize=(7, 6), dpi=dpi)
    else:
        fig = plot.figure(figsize=(7, 2), dpi=dpi)
    ax = fig.add_subplot(111)

    # Iterate
    max_gap_depth = 0
    for i, directory in enumerate(directories):
        # Frame Range
        frame_range = util.get_frame_range(frame_ranges[i])

        # Label
        if args.choice > 0:
            scale_height = float(directories[0].split("_")[0][1:]) / 100.0
            log_viscosity = float(directories[0].split("_")[1][2:]) - 2.0
        else:
            scale_height = 0.06
            log_viscosity = 5.0
        accretion_rate = accretion_rates[i]

        start_time = start_times[i]
        end_time = end_times[i]

        #label = r"$h =$ $%.02f$, $\alpha_\mathrm{visc} = 3 \times 10^{-%d}$, A = %.02f" % (scale_height, log_viscosity, accretion_rate)
        if args.choice > 0:
            label = r"$A = %.02f$" % (accretion_rate)
        else:
            labels = ["Default", "Restart"]
            label = labels[i]

        # Data
        #gap_depth_over_time = np.zeros(len(frame_range))

        #for i, frame in enumerate(frame_range):
        #    get_min((i, frame))

        pool_args = [(j, frame, directory)
                     for j, frame in enumerate(frame_range)]

        p = Pool(num_cores)
        p.map(get_min, pool_args)
        p.terminate()

        if np.max(gap_depth_over_time) > max_gap_depth:
            max_gap_depth = np.max(gap_depth_over_time)

        num_frames = len(frame_range)
        this_gap_depth_over_time = np.array(gap_depth_over_time[:num_frames])

        if i >= 4:
            this_gap_depth_over_time = this_gap_depth_over_time * (
                0.3)  # low-mass case

        ### Plot ###
        # Basic
        x = frame_range
        y = this_gap_depth_over_time
        result = plot.plot(x,
                           y,
                           c=colors[i],
                           linewidth=linewidth - 1,
                           zorder=99,
                           label=label)

        # Vortex Lifetime
        if start_time > 0:
            start_time_i = az.my_searchsorted(x, start_time)
            end_time_i = az.my_searchsorted(x, end_time)

            result = plot.plot(x[start_time_i:end_time_i],
                               y[start_time_i:end_time_i],
                               c=colors[i],
                               linewidth=linewidth + 3,
                               zorder=99)

            plot.scatter(x[start_time_i],
                         y[start_time_i],
                         c=colors[i],
                         s=150,
                         marker="o",
                         zorder=120)
            if args.choice > 0:
                plot.scatter(x[end_time_i],
                             y[end_time_i],
                             c=colors[i],
                             s=175,
                             marker="H",
                             zorder=120)

    if args.choice > 0:
        plot.legend(loc="upper right", fontsize=fontsize - 4)
    else:
        plot.legend(loc="upper left", fontsize=fontsize - 4)

    # Axes
    if args.choice > 0:
        plot.xlim(0, frame_range[-1])
    else:
        plot.xlim(0, frame_ranges[0][1])

    if args.choice > 0:
        plot.ylim(1, 3.0 * 10**(1))
        plot.yscale('log')
    else:
        plot.ylim(1, 5)
        plot.yscale('log')
        ax.set_major_formatter(ScalarFormatter())
        plot.yticks([1, 3, 5], ["1", "3", "5"])

    #title = readTitle()

    unit = "planet orbits"
    plot.xlabel(r"Time [%s]" % unit, fontsize=fontsize)
    if args.choice > 0:
        plot.ylabel(
            r" Gap Depth ($\delta_\mathrm{gap}$ $\equiv$ $\Sigma_{0}$ $/$ $\Sigma_\mathrm{min}$)",
            fontsize=fontsize)
    else:
        plot.ylabel(r"Gap Depth", fontsize=fontsize)

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

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

    title = r"$h = %.02f$          $\alpha \approx %s \times 10^{%d}$" % (
        scale_height, alpha_coefficent,
        int(np.log(viscosity) / np.log(10)) + 2)
    #title = r"$h = %.02f$          $\alpha_\mathrm{disk} = 3 \times 10^{-%d}$" % (scale_height, log_viscosity)
    if args.choice > 0:
        plot.title("%s" % (title), y=1.015, fontsize=fontsize + 2)
    #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)

    #title = readTitle()

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

    if show:
        plot.show()

    plot.close(fig)  # Close Figure (to avoid too many figures)
Exemple #6
0
def make_plot(show=False):
    # Set up figure
    if args.choice > 0:
        fig = plot.figure(figsize=(7, 6), dpi=dpi)
    else:
        fig = plot.figure(figsize=(7, 2), dpi=dpi)
    ax = fig.add_subplot(111)

    # Iterate
    #max_gap_depth = 0
    for i, directory in enumerate(directories):
        # Frame Range
        frame_range = util.get_frame_range(frame_ranges[i])

        # Label
        if args.choice > 0:
            scale_height = float(directories[0].split("_")[0][1:]) / 100.0
            log_viscosity = float(directories[0].split("_")[1][2:]) - 2.0
        else:
            scale_height = 0.06
            log_viscosity = 5.0
        accretion_rate = accretion_rates[i]

        start_time = start_times[i]
        end_time = end_times[i]

        #label = r"$h =$ $%.02f$, $\alpha_\mathrm{visc} = 3 \times 10^{-%d}$, A = %.02f" % (scale_height, log_viscosity, accretion_rate)
        if args.choice > 0:
            label = r"$A = %.02f$" % (accretion_rate)
        else:
            labels = ["Default", "Restart"]
            label = labels[i]

        # Data
        #gap_depth_over_time = np.zeros(len(frame_range))

        #for i, frame in enumerate(frame_range):
        #    get_min((i, frame))

        pool_args = [(j, frame, directory)
                     for j, frame in enumerate(frame_range)]

        p = Pool(num_cores)
        p.map(get_rossby_criteria, pool_args)
        p.terminate()

        #if np.max(gap_depth_over_time) > max_gap_depth:
        #    max_gap_depth = np.max(gap_depth_over_time)

        num_frames = len(frame_range)
        this_inner_peak_difference_over_time = np.array(
            inner_peak_difference_over_time[:num_frames])

        #if i == 4:
        #    this_gap_depth_over_time = this_gap_depth_over_time * (0.3) # low-mass case

        ### Plot ###
        # Basic
        x = frame_range
        y = this_inner_peak_difference_over_time
        result = plot.plot(x,
                           y,
                           c=colors[i],
                           linewidth=linewidth + 1,
                           zorder=99,
                           label=label,
                           alpha=0.65)

        # Vortex Lifetime
        if start_time > 1e6:
            # Set to > 0 to use this
            start_time_i = az.my_searchsorted(x, start_time)
            end_time_i = az.my_searchsorted(x, end_time)

            result = plot.plot(x[start_time_i:end_time_i],
                               y[start_time_i:end_time_i],
                               c=colors[i],
                               linewidth=linewidth + 3,
                               zorder=99)

            plot.scatter(x[start_time_i],
                         y[start_time_i],
                         c=colors[i],
                         s=150,
                         marker="o",
                         zorder=120)
            if args.choice > 0:
                plot.scatter(x[end_time_i],
                             y[end_time_i],
                             c=colors[i],
                             s=175,
                             marker="H",
                             zorder=120)

    # Reference Line
    plot.plot([0, frame_ranges[3][1]], [-0.15, -0.15], c='k',
              linewidth=1)  # Ro = -0.15 is critical value

    if args.choice > 0:
        plot.legend(loc="lower right", fontsize=fontsize - 4)
    else:
        plot.legend(loc="upper left", fontsize=fontsize - 4)

    # Axes
    if args.choice > 0:
        x_max = frame_ranges[3][1]
        plot.xlim(0, x_max)
    else:
        x_max = frame_ranges[0][1]
        plot.xlim(0, x_max)

    plot.ylim(0, 0.3)

    unit = "planet orbits"
    plot.xlabel(r"Time [%s]" % unit, fontsize=fontsize)
    plot.ylabel("Radii", fontsize=fontsize)

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

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

    title = r"$h = %.02f$          $\alpha \approx %s \times 10^{%d}$" % (
        scale_height, alpha_coefficent,
        int(np.log(viscosity) / np.log(10)) + 2)
    #title = r"$h = %.02f$          $\alpha_\mathrm{disk} = 3 \times 10^{-%d}$" % (scale_height, log_viscosity)
    if args.choice > 0:
        plot.title("%s" % (title), y=1.015, fontsize=fontsize + 2)

    #top_text = "Incompressible"; top_y = -0.02
    #bottom_text = "Compressible"; bottom_y = -0.38
    #plot.text(0.9 * x_max, top_y, top_text, horizontalalignment = 'right', verticalalignment = 'top', fontsize = fontsize - 3)
    #plot.text(0.1 * x_max, bottom_y, bottom_text, horizontalalignment = 'left', verticalalignment = 'bottom', fontsize = fontsize - 3)

    #title = readTitle()

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

    if show:
        plot.show()

    plot.close(fig)  # Close Figure (to avoid too many figures)
        '--ref',
        dest="reference_id",
        type=int,
        default=None,
        help='ref id number (up to 4 digits) to compare to (default: ids[0])')

    return parser


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

### Parse Arguments ###
args = new_argument_parser().parse_args()

### Get Input Parameters ###
frames = util.get_frame_range(args.frames)
ids = util.get_frame_range(args.ids)  # gets any range, really

reference_id = args.reference_id
if reference_id is None:
    reference_id = ids[0]

### Get ID%04d Parameters ###
fn = "id%04d_par.p" % reference_id
fargo_par = pickle.load(open(fn, "rb"))

num_rad = fargo_par["Nrad"]
num_theta = fargo_par["Nsec"]
r_min = fargo_par["Rmin"]
r_max = fargo_par["Rmax"]
Exemple #8
0
def make_plot(show = False):
    # Set up figure
    fig = plot.figure(figsize = (7, 6), dpi = dpi)
    ax = fig.add_subplot(111)

    # Iterate
    max_gap_depth = 0
    for i, directory in enumerate(directories):
        # Frame Range 
        frame_range = util.get_frame_range(frame_ranges[i])

        # Label
        scale_height = float(directories[0].split("_")[0][1:]) / 100.0
        log_viscosity = float(directories[0].split("_")[1][2:]) - 2.0
        accretion_rate = accretion_rates[i]

        start_time = start_times[i]
        end_time = end_times[i]

        #label = r"$h =$ $%.02f$, $\alpha_\mathrm{visc} = 3 \times 10^{-%d}$, A = %.02f" % (scale_height, log_viscosity, accretion_rate)
        label = r"$A = %.02f$" % (accretion_rate)

        # Data
        #gap_depth_over_time = np.zeros(len(frame_range))

        #for i, frame in enumerate(frame_range):
        #    get_min((i, frame))

        pool_args = [(j, frame, directory) for j, frame in enumerate(frame_range)]

        p = Pool(num_cores)
        p.map(get_min, pool_args)
        p.terminate()

        if np.max(gap_depth_over_time) > max_gap_depth:
            max_gap_depth = np.max(gap_depth_over_time)

        num_frames = len(frame_range)
        this_gap_depth_over_time = np.array(gap_depth_over_time[:num_frames])

        # Mass Data
        data = np.loadtxt("../%s/planet0.dat" % directory)
        times = data[:, 0]
        base_mass = data[:, 7]
        accreted_mass = data[:, 8]

        total_mass = base_mass + accreted_mass

        if negative:
            negative_mass = data[:, 13]
            total_mass -= negative_mass

        accretion = total_mass[1:] - total_mass[:-1]

        # Filter out repeats
        times = (times[1:])[accretion > 0]
        total_mass = total_mass[total_mass > 0]

        ### Plot ###
        # Basic
        x = total_mass[frame_range] / jupiter_mass
        y = this_gap_depth_over_time
        result = plot.plot(x, y, c = colors[i], linewidth = linewidth - 1, zorder = 99, label = label)

        # Vortex Lifetime
        #if start_time > 0:
        #    start_time_i = az.my_searchsorted(x, start_time)
        #    end_time_i = az.my_searchsorted(x, end_time)

        #    result = plot.plot(x[start_time_i:end_time_i], y[start_time_i:end_time_i], c = colors[i], linewidth = linewidth + 3, zorder = 99)

        #    plot.scatter(x[start_time_i], y[start_time_i], c = colors[i], s = 150, marker = "o", zorder = 120)
        #    plot.scatter(x[end_time_i], y[end_time_i], c = colors[i], s = 175, marker = "H", zorder = 120)

    plot.legend(loc = "upper right", fontsize = fontsize - 4)

    # Axes
    plot.xlim(0, x[-1])
    plot.ylim(1, 10**(5))

    plot.yscale('log')

    #title = readTitle()

    unit = r"$M_\mathrm{Jup}$"
    plot.xlabel(r"Planet Mass [%s]" % unit, fontsize = fontsize)
    plot.ylabel(r" Gap Depth ($\Sigma_{0}$ $/$ $\Sigma_\mathrm{min}$)", fontsize = fontsize)

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

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

    title = r"$h = %.02f$          $\alpha = %s \times 10^{%d}$" % (scale_height, alpha_coefficent, int(np.log(viscosity) / np.log(10)) + 2)
    #title = r"$h = %.02f$          $\alpha_\mathrm{disk} = 3 \times 10^{-%d}$" % (scale_height, log_viscosity)
    plot.title("%s" % (title), y = 1.015, fontsize = fontsize + 2)
    #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)

    #title = readTitle()

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

    if show:
        plot.show()

    plot.close(fig) # Close Figure (to avoid too many figures)
Exemple #9
0
    density = fromfile("../%s/gasdens%d.dat" % (directory, frame)).reshape(num_rad, num_theta)
    averagedDensity = np.average(density, axis = 1)
    normalized_density = averagedDensity / surface_density_zero
    
    # Get Minima
    min_density = find_min(normalized_density)

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

    # Store Data
    gap_depth_over_time[i] = 1.0 / min_density

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

gap_depth_over_time = mp_array("d", 10 * len(util.get_frame_range(frame_ranges[0])))

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

##### PLOTTING #####

colors = ['k', 'cornflowerblue', 'darkorange', 'r']
labelsize = 19
size = 100

rc['xtick.labelsize'] = labelsize
rc['ytick.labelsize'] = labelsize

def make_plot(show = False):
    # Set up figure
    fig = plot.figure(figsize = (7, 6), dpi = dpi)
def make_plot(show=False):
    # Set up figure
    fig, (ax1, ax2,
          ax3) = plot.subplots(3,
                               1,
                               figsize=(6, 12),
                               gridspec_kw={'height_ratios': [1, 1, 1]})

    # Iterate
    for i, directory in enumerate(directories):
        # Frame Range
        frame_range = util.get_frame_range(frame_ranges[i])
        dt = (frame_range[1] - frame_range[0]) * (
            2.0 * np.pi)  # for growth rate calculation

        start_time = start_times[i]
        start_time_i = az.my_searchsorted(frame_range, start_time)

        check_rossby = check_rossby_frames[i]

        # Label
        if args.choice > 0:
            scale_height = float(directories[0].split("_")[0][1:]) / 100.0
            log_viscosity = float(directories[0].split("_")[1][2:]) - 2.0
        else:
            scale_height = 0.06
            log_viscosity = 5.0
        accretion_rate = accretion_rates[i]

        start_time = start_times[i]
        end_time = end_times[i]

        #label = r"$h =$ $%.02f$, $\alpha_\mathrm{visc} = 3 \times 10^{-%d}$, A = %.02f" % (scale_height, log_viscosity, accretion_rate)
        if args.choice > 0:
            if i == 4:
                master_label = r"$0.3$ $\Sigma_0$"
            else:
                master_label = r"$A = %.02f$" % (accretion_rate)
        else:
            labels = ["Default", "Restart"]
            label = labels[i]

        # Data
        #for j, frame in enumerate(frame_range):
        #    get_extents((j, frame, directory))

        pool_args = [(j, frame, directory, check_rossby)
                     for j, frame in enumerate(frame_range)]

        p = Pool(num_cores)
        p.map(get_extents, pool_args)
        p.terminate()

        num_frames = len(frame_range)
        this_azimuthal_extent_over_time = np.array(
            azimuthal_extent_over_time[:num_frames])
        this_radial_extent_over_time = np.array(
            radial_extent_over_time[:num_frames])
        this_radial_peak_over_time = np.array(
            radial_peak_over_time[:num_frames])

        #this_smoothed_differences_over_time = smooth(this_differences_over_time, 5)
        #this_growth_rates_over_time = np.diff(np.log(this_smoothed_differences_over_time)) / dt

        ##### Top Plot #####

        # Plot
        x = frame_range
        y1 = this_azimuthal_extent_over_time
        p1, = ax1.plot(x, y1, c=colors[i], linewidth=linewidth, zorder=99 - i)

        # Axes
        if i == 3:
            ax1.set_xlim(0, x[-1])

        angles = np.linspace(0, 360, 7)
        ax1.set_ylim(0, 360)
        ax1.set_yticks(angles)

        # Annotate
        #ax1.set_xlabel("", fontsize = fontsize)
        ax1.set_ylabel("Azimuthal Extent (degrees)", fontsize=fontsize)

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

        title1 = r"$h = %.2f$    $\alpha = %s \times 10^{%d}$" % (
            scale_height, alpha_coefficent,
            int(round(np.log(viscosity) / np.log(10), 0)) + 2)
        #title1 = r"$A = %.2f$" % (accretion)
        ax1.set_title("%s" % (title1), y=1.035, fontsize=fontsize + 2)

        ##### Middle Plot #####
        y2 = this_radial_extent_over_time
        p2, = ax2.plot(x, y2, c=colors[i], linewidth=linewidth, zorder=99 - i)

        # Axes
        if i == 3:
            ax2.set_xlim(0, x[-1])

        if scale_height == 0.08:
            ax2.set_ylim(0, 0.75)
        else:
            ax2.set_ylim(0, 0.50)

        # Annotate
        ax2.set_ylabel(r"Radial Extent (planet radii)", fontsize=fontsize)

        ##### Bottom Plot #####

        # Plot
        y3 = this_radial_peak_over_time
        p3, = ax3.plot(x,
                       y3,
                       c=colors[i],
                       linewidth=linewidth,
                       alpha=alpha,
                       zorder=90 - i)

        # Axes
        if i == 3:
            ax3.set_xlim(0, x[-1])

        if scale_height == 0.08:
            ax3.set_ylim(1.0, 2.5)
        else:
            ax3.set_ylim(1.0, 1.6)

        # Annotate
        ax3.set_xlabel("Time (planet orbits)", fontsize=fontsize)
        ax3.set_ylabel(r"Radial Center (planet radii)", fontsize=fontsize)
        #ax3.legend(loc = "upper right", fontsize = fontsize - 5)

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

    if show:
        plot.show()

    plot.close(fig)  # Close Figure (to avoid too many figures)
Exemple #11
0
def make_plot(show=False):
    # Set up figure
    if args.choice > 0:
        fig = plot.figure(figsize=(7, 6), dpi=dpi)
    else:
        fig = plot.figure(figsize=(7, 2), dpi=dpi)
    ax = fig.add_subplot(111)

    # Iterate
    max_gap_depth = 0
    for i, directory in enumerate(directories):
        # Frame Range
        frame_range = util.get_frame_range(frame_ranges[i])

        # Label
        if args.choice > 0:
            scale_height = float(directories[0].split("_")[0][1:]) / 100.0
            log_viscosity = float(directories[0].split("_")[1][2:]) - 2.0
        else:
            scale_height = 0.06
            log_viscosity = 5.0
        accretion_rate = accretion_rates[i]

        start_time = start_times[i]
        end_time = end_times[i]

        #label = r"$h =$ $%.02f$, $\alpha_\mathrm{visc} = 3 \times 10^{-%d}$, A = %.02f" % (scale_height, log_viscosity, accretion_rate)
        if args.choice > 0:
            label = r"$A = %.02f$" % (accretion_rate)
        else:
            labels = ["Default", "Restart"]
            label = labels[i]

        # Data
        #gap_depth_over_time = np.zeros(len(frame_range))

        #for i, frame in enumerate(frame_range):
        #    get_min((i, frame))

        pool_args = [(j, frame, directory)
                     for j, frame in enumerate(frame_range)]

        p = Pool(num_cores)
        p.map(get_min, pool_args)
        p.terminate()

        #if np.max(gap_depth_over_time) > max_gap_depth:
        #    max_gap_depth = np.max(radial_peak_over_time)

        num_frames = len(frame_range)
        this_radial_peak_over_time = np.array(
            radial_peak_over_time[:num_frames])

        ### Plot ###
        # Basic
        x = frame_range
        y = this_radial_peak_over_time
        result = plot.plot(x,
                           y,
                           c=colors[i],
                           linewidth=linewidth - 1,
                           zorder=99,
                           label=label)

        # Vortex Lifetime
        if start_time > 0:
            start_time_i = az.my_searchsorted(x, start_time)
            end_time_i = az.my_searchsorted(x, end_time)

            result = plot.plot(x[start_time_i:end_time_i],
                               y[start_time_i:end_time_i],
                               c=colors[i],
                               linewidth=linewidth + 3,
                               zorder=99)

            #plot.scatter(x[start_time_i], y[start_time_i], c = colors[i], s = 150, marker = "o", zorder = 120)
            if args.choice > 0:
                plot.scatter(x[end_time_i],
                             y[end_time_i],
                             c=colors[i],
                             s=175,
                             marker="H",
                             zorder=120)

    # Scatter critical points
    if scale_height == 0.04:
        i_h4 = plot.scatter(initial_times_h4,
                            initial_critical_maxima_h4,
                            s=120,
                            c=colors[initial_accretion_numbers_h4 - 1],
                            zorder=100,
                            alpha=alpha)
        s_h4 = plot.scatter(second_times_h4,
                            second_critical_maxima_h4,
                            s=170,
                            c=colors[second_accretion_numbers_h4 - 1],
                            zorder=100,
                            alpha=alpha,
                            marker="*")
        d_h4 = plot.scatter(interior_times_h4,
                            interior_critical_maxima_h4,
                            s=120,
                            c=colors[interior_accretion_numbers_h4 - 1],
                            zorder=100,
                            alpha=alpha,
                            marker="D")
        t_h4 = plot.scatter(too_interior_times_h4,
                            too_interior_critical_maxima_h4,
                            s=120,
                            c=colors[too_interior_accretion_numbers_h4 - 1],
                            zorder=100,
                            alpha=alpha,
                            marker="x")
    elif scale_height == 0.06:
        i_h6 = plot.scatter(initial_times_h6,
                            initial_critical_maxima_h6,
                            s=120,
                            c=colors[initial_accretion_numbers_h6 - 1],
                            zorder=100,
                            alpha=alpha)
        s_h4 = plot.scatter(second_times_h6,
                            second_critical_maxima_h6,
                            s=170,
                            c=colors[second_accretion_numbers_h6 - 1],
                            zorder=100,
                            alpha=alpha,
                            marker="*")
        d_h4 = plot.scatter(interior_times_h6,
                            interior_critical_maxima_h6,
                            s=120,
                            c=colors[interior_accretion_numbers_h6 - 1],
                            zorder=100,
                            alpha=alpha,
                            marker="D")
        t_h4 = plot.scatter(too_interior_times_h6,
                            too_interior_critical_maxima_h6,
                            s=120,
                            c=colors[too_interior_accretion_numbers_h6 - 1],
                            zorder=100,
                            alpha=alpha,
                            marker="x")

    if scale_height == 0.04:
        plot.legend(loc="upper left", fontsize=fontsize - 4)

        # Pressure Bump label
        x1 = 1200
        x2 = 2800
        x_center = (x1 + x2) / 2.0
        y_base = 1.45
        dy = 0.08

        plot.text(x_center,
                  y_base + dy,
                  r"$r_\mathrm{pressure}$",
                  horizontalalignment='center',
                  fontsize=fontsize)
        top_brace_x, top_brace_y = range_brace(x1, x2, height=0.06)
        plot.plot(top_brace_x, y_base + top_brace_y, c="k", linewidth=2)

        # Critical Bump label
        x1 = 800
        x2 = 2200
        x_center = (x1 + x2) / 2.0
        y_base = 1.14
        dy = 0.10

        plot.text(x_center,
                  y_base - dy,
                  r"$r_\mathrm{crit}$",
                  horizontalalignment='center',
                  fontsize=fontsize)
        bottom_brace_x, bottom_brace_y = range_brace(x1, x2, height=0.06)
        plot.plot(bottom_brace_x, y_base - bottom_brace_y, c="k", linewidth=2)

    elif scale_height == 0.06:
        plot.legend(loc="lower right", fontsize=fontsize - 4)

        # Pressure Bump label
        x1 = 4000
        x2 = 6000
        x_center = (x1 + x2) / 2.0
        y_base = 1.48
        dy = 0.08

        plot.text(x_center,
                  y_base + dy,
                  r"$r_\mathrm{pressure}$",
                  horizontalalignment='center',
                  fontsize=fontsize)
        top_brace_x, top_brace_y = range_brace(x1, x2, height=0.06)
        plot.plot(top_brace_x, y_base + top_brace_y, c="k", linewidth=2)

        # Critical Bump label
        x1 = 1500
        x2 = 4800
        x_center = (x1 + x2) / 2.0
        y_base = 1.18
        dy = 0.10

        plot.text(x_center,
                  y_base - dy,
                  r"$r_\mathrm{crit}$",
                  horizontalalignment='center',
                  fontsize=fontsize)
        bottom_brace_x, bottom_brace_y = range_brace(x1, x2, height=0.06)
        plot.plot(bottom_brace_x, y_base - bottom_brace_y, c="k", linewidth=2)

    # Axes
    if args.choice > 0:
        plot.xlim(0, frame_range[-1])
    else:
        plot.xlim(0, frame_ranges[0][1])

    start_y = 1.0
    end_y = 1.6
    plot.ylim(start_y, end_y)

    #title = readTitle()

    unit_x = "planet orbits"
    unit_y = "r_\mathrm{p}"
    plot.xlabel(r"Time [%s]" % unit_x, fontsize=fontsize)
    plot.ylabel(r"$r$ [$%s$]" % unit_y, fontsize=fontsize)

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

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

    title = r"$h = %.02f$          $\alpha \approx %s \times 10^{%d}$" % (
        scale_height, alpha_coefficent,
        int(np.log(viscosity) / np.log(10)) + 2)
    #title = r"$h = %.02f$          $\alpha_\mathrm{disk} = 3 \times 10^{-%d}$" % (scale_height, log_viscosity)
    if args.choice > 0:
        plot.title("%s" % (title), y=1.015, fontsize=fontsize + 2)
    #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)

    #title = readTitle()

    # Set twin axis
    twin = ax.twinx()
    twin.set_ylim(0, (end_y - start_y) / scale_height)
    twin.set_ylabel(r"$(r - r_\mathrm{p})$ $/$ $H_0$",
                    fontsize=fontsize,
                    rotation=270,
                    labelpad=30)

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

    if show:
        plot.show()

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