示例#1
0
def make_plot(frame, show = False):
    # Set up figure
    #fig = plot.figure(figsize = (7, 6), dpi = dpi)
    #ax = fig.add_subplot(111)

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

    start = np.searchsorted(rad, 0.9)
    end = np.searchsorted(rad, 1.1)

    density_sliver = density[start:end]

    planet_x = 1
    planet_y = 0
    planet_r = np.sqrt(planet_x**2 + planet_y**2)

    dt = all_times[1] # 0.00410595556163

    accreted_mass = 0.0
    count1 = 0; count2 = 0

    for i, r_i in enumerate(rad[start:end]):
        for j, az_i in enumerate(theta):
            xc = r_i * np.cos(az_i)
            yc = r_i * np.sin(az_i)

            dx = planet_x - xc
            dy = planet_y - yc

            distance = np.sqrt(dx**2 + dy**2)
            r_roche = (planet_mass * 1e-3 / 3.0)**(1.0 / 3.0) * planet_r

            cell_mass = density[start+i, j] * (np.pi / num_theta) * (rad[start+i+1]**2 - r_i**2)
            dm = 0.0

            if distance < 0.75 * r_roche:
                dm = (1.0 / 3.0 * dt) * cell_mass
                cell_mass *= (1.0 - 1.0 / 3.0 * dt)

                count1 += 1
                accreted_mass += dm

            if distance < 0.45 * r_roche:
                dm = (2.0 / 3.0 * dt) * cell_mass

                count2 += 1
                accreted_mass += dm

    print count1, count2
    print accreted_mass, accreted[0]
def make_plot(frame, show = False):
    # Set up figure
    fig = plot.figure(figsize = (7, 6), dpi = dpi)
    ax = fig.add_subplot(111)

    # Data
    if merge > 0:
        num_merged_cores = merge
        energy = util.read_merged_data(frame, num_merged_cores, num_rad, num_theta)
    elif mpi:
        field = "dens"
        energy = Fields("./", 'gas', frame).get_field(field).reshape(num_rad, num_theta)
    else:
        energy = fromfile("gasenergy%d.dat" % frame).reshape(num_rad, num_theta)
    averagedEnergy = np.average(energy, axis = 1)
    normalized_energy = averagedEnergy

    ### Plot ###
    x = rad
    y = normalized_energy
    result = plot.plot(x, y, linewidth = linewidth, zorder = 99)

    if args.zero:
        energy_zero = fromfile("gasenergy0.dat").reshape(num_rad, num_theta)
        averagedEnergy_zero = np.average(energy_zero, axis = 1)
        normalized_energy_zero = averagedEnergy_zero

        x = rad
        y_zero = normalized_energy_zero
        result = plot.plot(x, y_zero, linewidth = linewidth, zorder = 0)

    if args.compare is not None:
        directory = args.compare
        density_compare = (fromfile("%s/gasdens%d.dat" % (directory, frame)).reshape(num_rad, num_theta))
        averagedDensity_compare = np.average(density_compare, axis = 1)
        normalized_density_compare = averagedDensity_compare / surface_density_zero

        ### Plot ###
        x = rad
        y_compare = normalized_density_compare
        result = plot.plot(x, y_compare, linewidth = linewidth, alpha = 0.6, zorder = 99, label = "compare")

        plot.legend()

    # Axes
    if args.max_y is None:
        x_min_i = np.searchsorted(x, x_min)
        x_max_i = np.searchsorted(x, x_max)
        max_y = 1.1 * max(y[x_min_i : x_max_i])
    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()

    unit = "r_\mathrm{p}"
    plot.xlabel(r"Radius [$%s$]" % unit, 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/averagedEnergy_%04d.png" % (save_directory, frame)
    else:
        save_fn = "%s/v%04d_averagedEnergy_%04d.png" % (save_directory, version, frame)
    plot.savefig(save_fn, bbox_inches = 'tight', dpi = dpi)

    if show:
        plot.show()

    plot.close(fig) # Close Figure (to avoid too many figures)
    def add_to_plot(i, grain):
        # Identify Subplot
        number = i + 1
        ax = plot.subplot(3, 1, number)

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

        if center:
            if i > 0:
                normalized_density, shift_c = shift_density(
                    normalized_density,
                    fargo_par,
                    reference_density=normalized_gas_density)
            normalized_gas_density, shift_c = shift_density(
                normalized_gas_density,
                fargo_par,
                reference_density=normalized_gas_density)

        ### Plot ###
        x = theta * (180.0 / np.pi)
        y = rad

        if i == 0:
            cmap = 'viridis'
            result = ax.pcolormesh(x, y, normalized_gas_density, cmap=cmap)
            cbar = fig.colorbar(result)
            result.set_clim(0, cmaxGas)
        else:
            cmap = args.cmap
            result = ax.pcolormesh(x, y, normalized_density, cmap=cmap)
            cbar = fig.colorbar(result)
            result.set_clim(0, cmax[i - 1])

        if number == 1:
            cbar.set_label(r"$\Sigma$ / $\Sigma_\mathrm{0,}$ $_\mathrm{gas}$",
                           fontsize=fontsize,
                           rotation=270,
                           labelpad=25)
        elif number == 3:
            cbar.set_label(r"$\Sigma$ / $\Sigma_\mathrm{0,}$ $_\mathrm{dust}$",
                           fontsize=fontsize,
                           rotation=270,
                           labelpad=25)

        if use_contours and i > 0:
            levels = np.linspace(low_contour, high_contour, num_levels)
            colors = generate_colors(num_levels)
            plot.contour(x,
                         y,
                         normalized_gas_density,
                         levels=levels,
                         origin='upper',
                         linewidths=1,
                         colors=colors)

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

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

        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=6)

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

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

        if number == 1:
            plot.title(
                r"$t = %d$ $\mathrm{orbits}}$  [$m_\mathrm{p}(t)\ =\ %.2f$ $M_\mathrm{J}$]"
                % (orbit, current_mass),
                bbox=dict(facecolor='w', edgecolor='k', pad=10.0),
                y=1.08,
                fontsize=fontsize + 1)

        # Label
        left_x = plot.xlim()[0]
        right_x = plot.xlim()[-1]
        range_x = right_x - left_x
        margin_x = 0.05 * range_x
        bottom_y = plot.ylim()[0]
        top_y = plot.ylim()[-1]
        range_y = top_y - bottom_y
        margin_y = 0.15 * range_y

        if number == 1:
            # Gas
            title = r"$\mathrm{Gas\ Density}$"
            #plot.text(left_x + margin_x, top_y - margin_y, title, fontsize = fontsize, color = 'black', horizontalalignment = 'left', bbox=dict(facecolor = 'white', edgecolor = 'black', pad = 10.0))
        else:
            # Dust
            this_size = util.get_size(grain)

            size_label = util.get_size_label(this_size)
            stokes_number = util.get_stokes_number(this_size)

            title = r"%s$\mathrm{-size}$" % size_label
            stokes = r"$\mathrm{St}_\mathrm{0}$ $=$ $%.03f$" % stokes_number

            #plot.text(left_x + margin_x, top_y - margin_y, title, fontsize = fontsize, color = 'white', horizontalalignment = 'left', bbox=dict(facecolor = 'black', edgecolor = 'white', pad = 10.0))
            #plot.text(right_x - margin_x, top_y - margin_y, stokes, fontsize = fontsize, color = 'white', horizontalalignment = 'right', bbox=dict(facecolor = 'black', edgecolor = 'white', pad = 10.0))

        # Text
        line_y = top_y + 0.31 * range_y
        linebreak = 0.16 * range_y
        left_start_x = left_x - 3.0 * margin_x
        right_end_x = right_x + 4.0 * margin_x
        if number == 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_start_x,
                      line_y + linebreak,
                      line1,
                      horizontalalignment='left',
                      fontsize=fontsize + 1)
            plot.text(left_start_x,
                      line_y,
                      line2,
                      horizontalalignment='left',
                      fontsize=fontsize + 1)

            line3 = r'$T_\mathrm{growth} = %d$ $\rm{orbits}$' % taper_time
            line4 = r"$N_\mathrm{r} \times \ N_\mathrm{\phi} = %d \times \ %d$" % (
                num_rad, num_theta)

            plot.text(right_end_x,
                      line_y + linebreak,
                      line3,
                      horizontalalignment='right',
                      fontsize=fontsize + 1)
            plot.text(right_end_x,
                      line_y,
                      line4,
                      horizontalalignment='right',
                      fontsize=fontsize + 1)
def get_excess_mass(args_here):
    # Unwrap Args
    i, frame = args_here

    # Get Data
    if mpi:
        field = "dens"
        density = Fields("./", 'gas', frame).get_field(field).reshape(
            num_rad, num_theta) / surface_density_zero
        #background_density = Fields("./", 'gas', frame - 1).get_field(field).reshape(num_rad, num_theta) / surface_density_zero
    else:
        density = fromfile("dust%ddens%d.dat" % (dust_number, frame)).reshape(
            num_rad, num_theta) / dust_surface_density_zero
        #background_density = fromfile("dust1dens%d.dat" % (frame - 1)).reshape(num_rad, num_theta) / dust_surface_density_zero

    if args.compare:
        fargo_directory = args.compare
        density_compare = (fromfile(
            "%s/dust%ddens%d.dat" %
            (fargo_directory, dust_number, frame)).reshape(
                num_rad, num_theta)) / dust_surface_density_zero
        #background_density_compare = (fromfile("%s/dust1dens%d.dat" % (fargo_directory, frame - 1)).reshape(num_rad, num_theta)) / dust_surface_density_zero

    def helper(density):
        diff_density = density  # - background_density
        #diff_density[diff_density < 0] = 0 # only include excess

        # Extract Near Vortex
        averagedDensity = np.average(density, axis=1)
        peak_rad, peak_density = find_peak(averagedDensity)

        vortex_start = np.max([1.0, peak_rad - 5.0 * scale_height])
        vortex_end = peak_rad + 5.0 * scale_height

        vortex_start_i = np.searchsorted(rad, vortex_start)
        vortex_end_i = np.searchsorted(rad, vortex_end)

        vortex_rad = rad[vortex_start_i:vortex_end_i]
        vortex_diff_density = diff_density[vortex_start_i:vortex_end_i]

        vortex_excess = np.average(vortex_diff_density, axis=0)

        variance = np.std(vortex_excess)
        average = np.average(vortex_excess)

        # Add up mass
        #dr = rad[1] - rad[0] # assumes arithmetic grid
        #d_phi = theta[1] - theta[0]

        #excess_mass = np.sum((dr * d_phi) * vortex_rad[:, None] * vortex_diff_density)
        #return excess_mass, vortex_excess

        return variance / average, vortex_excess

    excess_mass, vortex_excess = helper(density)
    if args.compare:
        excess_mass_compare, vortex_excess_compare = helper(density_compare)

    # Get Peak
    peak_diff_density = np.max(vortex_excess)
    if args.compare:
        peak_diff_density_compare = np.max(vortex_excess_compare)

    # Print Update
    print "%d: %.4f, %.4f" % (frame, excess_mass, peak_diff_density)
    if args.compare:
        print "%d: %.4f, %.4f" % (frame, excess_mass_compare,
                                  peak_diff_density_compare)

    # Store Data
    mass_over_time[i] = excess_mass
    peak_over_time[i] = peak_diff_density

    if args.compare:
        mass_over_time_compare[i] = excess_mass_compare
        peak_over_time_compare[i] = peak_diff_density_compare
示例#5
0
def make_plot(frame, show=False):
    # Set up figure
    fig = plot.figure(figsize=(7, 6), dpi=dpi)
    ax = fig.add_subplot(111)

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

    if center:
        velocity, shift_c = shift_data(
            velocity, fargo_par, reference_density=normalized_gas_density)
        normalized_gas_density, shift_c = shift_data(
            normalized_gas_density,
            fargo_par,
            reference_density=normalized_gas_density)

    # Take Residual
    keplerian_velocity = rad * (np.power(
        rad, -1.5) - 1)  # in rotating frame, v_k = r * (r^-1.5 - r_p^-1.5)
    sub_keplerian_velocity = keplerian_velocity - 0.5 * np.power(
        scale_height, 2)
    velocity -= keplerian_velocity[:, None]

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

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

    if ref:
        for i, value in enumerate(np.arange(x[0], x[-1], 0.1)):
            plot.plot([value, value], [0, 360], c='k', linewidth=1)
        for i, value in enumerate(np.arange(y[0], y[-1], 10)):
            plot.plot([x[0], x[-1]], [value, value], c='k', linewidth=1)

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

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

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

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

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

    current_mass += accreted_mass[frame]

    #title = readTitle()

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

    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)

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

    if show:
        plot.show()

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

    # Data
    if merge > 0:
        num_merged_cores = merge
        gas_density = util.read_merged_data(frame, num_merged_cores, num_rad,
                                            num_theta)
        velocity = util.read_merged_data(frame,
                                         num_merged_cores,
                                         num_rad,
                                         num_theta,
                                         field="vx",
                                         fluid="dust%d" % dust_number)
    elif mpi:
        gas_density = Fields("./", 'gas', frame).get_field("dens").reshape(
            num_rad, num_theta)
        velocity = Fields("./", 'dust%d' % dust_number,
                          frame).get_field("vx").reshape(num_rad, num_theta)
    else:
        gas_density = fromfile("gasdens%d.dat" % frame).reshape(
            num_rad, num_theta)
        velocity = fromfile("dust%dvx%d.dat" % (dust_number, frame)).reshape(
            num_rad, num_theta)
    normalized_gas_density = gas_density / surface_density_zero

    ## Subtract Keplerian Velocity ##
    keplerian_velocity = rad * (np.power(rad, -1.5) - 1)
    velocity -= keplerian_velocity[:, np.newaxis]

    ### Plot ###
    x = rad
    y = theta * (180.0 / np.pi)
    result = ax.pcolormesh(x, y, np.transpose(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(normalized_density),
                     levels=levels,
                     origin='upper',
                     linewidths=1,
                     colors=colors)

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

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

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

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

    #title = readTitle()

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

    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)

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

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

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

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

    if use_contours:
        gas_density = Fields("./", 'gas', frame).get_field(field).reshape(
            num_rad, num_theta) / surface_density_zero
        levels = np.linspace(low_contour, high_contour, num_levels)
        colors = generate_colors(num_levels)
        plot.contour(x,
                     y,
                     np.transpose(gas_density),
                     levels=levels,
                     origin='upper',
                     linewidths=1,
                     colors=colors)

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

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

    # Annotate Axes
    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/dustDensityMap_%04d.png" % (save_directory, frame)
    else:
        save_fn = "%s/v%04d_dustDensityMap_%04d.png" % (save_directory,
                                                        version, frame)
    plot.savefig(save_fn, bbox_inches='tight', dpi=dpi)

    if show:
        plot.show()

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

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

    normalized_gas_density = gas_density / surface_density_zero
    normalized_density = density / dust_surface_density_zero

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

    ### Plot ###
    x = rad
    y = theta * (180.0 / np.pi)
    result = ax.pcolormesh(x, y, np.transpose(normalized_density), 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(normalized_gas_density),
                     levels=levels,
                     origin='upper',
                     linewidths=1,
                     colors=colors)

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

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

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

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

    current_mass += accreted_mass[frame]

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

    #title = readTitle()
    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)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    current_mass += accreted_mass[frame]

    #title = readTitle()

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

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

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

    title1 = r"$h/r = %.2f$     $\alpha \approx %s \times 10^{%d}$    $A = %.2f$" % (
        scale_height, alpha_coefficent,
        int(np.log(viscosity) / np.log(10)) + 2, accretion)
    #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)

    cbar.set_label(r"Gas Surface Density  $\Sigma$ $/$ $\Sigma_0$",
                   fontsize=fontsize,
                   rotation=270,
                   labelpad=25)

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

    if show:
        plot.show()

    plot.close(fig)  # Close Figure (to avoid too many figures)
示例#10
0
from pylab import *
import sys
sys.path.insert(0, '../../utils/python')
from reader import Fields
from advanced import Parameters

n = 1
outputdir = "../../outputs/fargo_dusty"
fluids = ["gas", "dust1", "dust2", "dust3"]
field = "dens"
fig = figure(figsize=(20, 5))

p = Parameters(outputdir)
for i, fluid in enumerate(fluids):
    data = Fields("../../outputs/fargo_dusty", fluid,
                  n).get_field(field).reshape(p.ny, p.nx)
    ax = fig.add_subplot(1, len(fluids), i + 1)
    ax.imshow(log10(data), origin='lower', aspect='auto')

show()
示例#11
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)
示例#12
0
def make_plot(frame, show=False):
    # Set up figure
    fig = plot.figure(figsize=(7, 6), dpi=dpi)
    ax = fig.add_subplot(111)

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

    # Average
    averaged_velocity = np.average(velocity, axis=1)

    # Shift out of rotating frame
    rotating_frame = rad  # in rotating frame, v_k = r * (r^-1.5 - r_p^-1.5)
    averaged_velocity += rotating_frame

    averaged_orbital_frequency = averaged_velocity / rad

    # Reference Lines
    keplerian_velocity = np.power(rad, -1.5)
    y_ref1 = 1.0 * keplerian_velocity
    y_ref2 = y_ref1 - 0.5 * np.power(scale_height, 2)

    if args.normalize:
        averaged_orbital_frequency /= keplerian_velocity
        y_ref2 /= keplerian_velocity
        y_ref1 /= keplerian_velocity

    ### Plot ###
    x = rad
    y = averaged_orbital_frequency
    result = plot.plot(x, y, linewidth=linewidth, zorder=99)

    plot.plot(x, y_ref1, c='k', linewidth=linewidth - 1)
    plot.plot(x, y_ref2, c='midnightblue', linewidth=linewidth - 1)

    if args.normalize:
        resonance_curve = 0.5 * y_ref1 / keplerian_velocity
        plot.plot(x, resonance_curve)

        look_for_resonance = resonance_curve / y

        r_start_i = np.searchsorted(rad, 1.4)
        r_end_i = np.searchsorted(rad, 1.8)

        resonance_i = np.searchsorted(look_for_resonance[r_start_i:r_end_i],
                                      1.0)
        resonance_r = rad[r_start_i + resonance_i]

        plot.text(1.05 * x_min, 1.02, r"$r = %.3f$" % resonance_r)
    else:
        plot.plot([x[0], x[-1]], [0.5, 0.5], linewidth=linewidth - 1)

    # Axes
    if args.max_y is None:
        x_min_i = np.searchsorted(x, x_min)
        x_max_i = np.searchsorted(x, x_max)
        max_y = 1.1 * max(y[x_min_i:x_max_i])
    else:
        max_y = args.max_y

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

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

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

    current_mass += accreted_mass[frame]

    #title = readTitle()

    unit = "r_\mathrm{p}"
    plot.xlabel(r"Radius [$%s$]" % unit, fontsize=fontsize)
    plot.ylabel(r"$\Omega$ $/$ $\Omega_\mathrm{K}$", fontsize=fontsize)

    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)

    # Save, Show, and Close
    if version is None:
        save_fn = "%s/averagedOrbitalFrequency_%04d.png" % (save_directory,
                                                            frame)
    else:
        save_fn = "%s/v%04d_averagedOrbitalFrequency_%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)
示例#13
0
    def add_to_plot(i):
        # Identify Subplot
        frame = frames[i]; number = i + 1
        ax = plot.subplot(1, 4, number)

        # Data
        if mpi:
          density = Fields("./", 'gas', frame).get_field("dens").reshape(num_z, num_rad, num_theta)
          vrad = Fields("./", 'gas', frame).get_field("vy").reshape(num_z, num_rad, num_theta)
          vtheta = Fields("./", 'gas', frame).get_field("vx").reshape(num_z, num_rad, num_theta)
        else:
          density = fromfile("gasdens%d.dat" % frame).reshape(num_z, num_rad, num_theta)
          vrad = (fromfile("gasvy%d.dat" % frame).reshape(num_z, num_rad, num_theta)) # add a read_vrad to util.py!
          vtheta = (fromfile("gasvx%d.dat" % frame).reshape(num_z, num_rad, num_theta)) # add a read_vrad to util.py!
        midplane_density = density[num_z / 2 + args.sliver, :, :]
        midplane_vrad = vrad[num_z / 2 + args.sliver, :, :]
        midplane_vtheta = vtheta[num_z / 2 + args.sliver, :, :]

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

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

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

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

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

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

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

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

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

        current_mass += accreted_mass[frame]

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

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

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

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

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

        if number != len(frames):
            fig.delaxes(cax) # to balance out frames that don't have colorbar with the one that does
示例#14
0
def get_excess_mass(args):
    # Unwrap Args
    i, frame = args

    # Get Data

    if mpi:
        field = "dens"
        density = Fields("./", 'gas', frame).get_field(field).reshape(
            num_rad, num_theta) / surface_density_zero
        background_density = Fields(
            "./", 'gas', frame - 1).get_field(field).reshape(
                num_rad, num_theta) / surface_density_zero
    else:
        density = fromfile("gasdens%d.dat" % frame).reshape(
            num_rad, num_theta) / surface_density_zero
        background_density = fromfile("gasdens%d.dat" % (frame - 1)).reshape(
            num_rad, num_theta) / surface_density_zero

    #fargo_directory = "taper750_fargo_comparison"
    #density_compare = (fromfile("../%s/gasdens%d.dat" % (fargo_directory, frame)).reshape(num_rad, num_theta)) / surface_density_zero
    #background_density_compare = (fromfile("../%s/gasdens%d.dat" % (fargo_directory, frame - 1)).reshape(num_rad, num_theta)) / surface_density_zero

    def helper(density, background_density):
        diff_density = density - background_density
        diff_density[diff_density < 0] = 0  # only include excess

        # Extract Near Vortex
        averagedDensity = np.average(density, axis=1)
        peak_rad, peak_density = find_peak(averagedDensity)

        vortex_start = np.max([1.0, peak_rad - 5.0 * scale_height])
        vortex_end = peak_rad + 5.0 * scale_height

        vortex_start_i = np.searchsorted(rad, vortex_start)
        vortex_end_i = np.searchsorted(rad, vortex_end)

        vortex_rad = rad[vortex_start_i:vortex_end_i]
        vortex_diff_density = diff_density[vortex_start_i:vortex_end_i]

        vortex_excess = np.average(vortex_diff_density, axis=1)

        # Add up mass
        dr = rad[1] - rad[0]  # assumes arithmetic grid
        d_phi = theta[1] - theta[0]

        excess_mass = np.sum(
            (dr * d_phi) * vortex_rad[:, None] * vortex_diff_density)
        return excess_mass, vortex_excess

    excess_mass, vortex_excess = helper(density, background_density)
    #excess_mass_compare, vortex_excess_compare = helper(density_compare, background_density_compare)

    # Get Peak
    peak_diff_density = np.max(vortex_excess)
    #peak_diff_density_compare = np.max(vortex_excess_compare)

    # Print Update
    print "%d: %.4f, %.4f" % (frame, excess_mass, peak_diff_density)
    #print "%d: %.4f, %.4f" % (frame, excess_mass_compare, peak_diff_density_compare)

    # Store Data
    mass_over_time[i] = excess_mass
    peak_over_time[i] = peak_diff_density
def make_plot(frame, show=False):
    # Set up figure
    fig = plot.figure(figsize=(7, 6), dpi=dpi)
    ax = fig.add_subplot(111)

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

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

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

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

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

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

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

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

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

    # Label star and planet
    time = fargo_par["Ninterm"] * fargo_par["DT"]
    orbit = (time / (2 * np.pi)) * frame

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

    #current_mass += accreted_mass[frame]

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

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

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

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

    # Annotate Axes

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

    title1 = r"$T_\mathrm{growth} = %d$ $\mathrm{orbits}$" % (taper_time)
    title2 = r"$t = %d$ $\mathrm{orbits}}$  [$m_\mathrm{p}(t)\ =\ %.2f$ $M_\mathrm{Jup}$]" % (
        orbit, current_mass)
    plot.title("%s" % (title2), y=1.015, fontsize=fontsize + 1)
    plot.text(0.0,
              3.24,
              title1,
              horizontalalignment='center',
              bbox=dict(facecolor='none',
                        edgecolor='black',
                        linewidth=1.5,
                        pad=7.0),
              fontsize=fontsize + 2)

    # Text
    text_mass = r"$M_\mathrm{p} = %d$ $M_\mathrm{Jup}$" % (int(planet_mass))
    text_visc = r"$\alpha_\mathrm{disk} = 3 \times 10^{%d}$" % (
        int(np.log(viscosity) / np.log(10)) + 2)
    #plot.text(-0.9 * box_size, 2, text_mass, fontsize = fontsize, color = 'black', horizontalalignment = 'left', bbox=dict(facecolor = 'white', edgecolor = 'black', pad = 10.0))
    #plot.text(0.9 * box_size, 2, text_visc, fontsize = fontsize, color = 'black', horizontalalignment = 'right', bbox=dict(facecolor = 'white', edgecolor = 'black', pad = 10.0))
    plot.text(-1.7,
              3.24,
              text_mass,
              fontsize=fontsize,
              color='black',
              horizontalalignment='right')
    plot.text(1.7,
              3.24,
              text_visc,
              fontsize=fontsize,
              color='black',
              horizontalalignment='left')
    # Save, Show, and Close
    if version is None:
        save_fn = "%s/squareDensityMap_%04d.png" % (save_directory, frame)
    else:
        save_fn = "%s/v%04d_squareDensityMap_%04d.png" % (save_directory,
                                                          version, frame)
    plot.savefig(save_fn, bbox_inches='tight', dpi=dpi)

    if show:
        plot.show()

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