Exemplo n.º 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]
Exemplo n.º 2
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)
Exemplo n.º 4
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)
Exemplo n.º 5
0
def make_plot(frame, show=False):
    # Set up figure
    fig = plot.figure(figsize=(7, 6), dpi=dpi)
    ax = fig.add_subplot(111)

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

    # Data
    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)
Exemplo n.º 8
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)
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)