Esempio n. 1
0
def get_velocity(args_here):
    # Unwrap Args
    i, frame = args_here

    # Data
    if mpi:
        density = Fields("./", 'gas', frame).get_field("dens").reshape(
            num_z, num_rad, num_theta)
        vz = Fields("./", 'gas',
                    frame).get_field("vz").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)
        vz = (fromfile("gasvz%d.dat" % frame).reshape(num_z, num_rad,
                                                      num_theta)
              )  # add a read_vrad to util.py!
        #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, :, :]
    midplane_vz = vz[num_z / 2 + args.sliver, :, :]

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

    average_midplane_vz = np.average(midplane_vz, axis=-1)
    composite_vz[i, :] = average_midplane_vz
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"
    if mpi:
      density = Fields("./", 'dust1', frame).get_field(field).reshape(num_z, num_rad, num_theta)
    else:
      density = fromfile("dust1dens%d.dat" % frame).reshape(num_z, num_rad, num_theta)

    scale_height_function = np.zeros(num_rad)
    mean_function = np.zeros(num_rad)
    meridional_density = np.average(density, axis = -1)

    for i in range(num_rad):
        popt, pcov = curve_fit(gaussian, z_angles, meridional_density[:, i])
        (A, mean, sigma) = popt
        scale_height_function[i] = sigma # scale height (as an angle)
        mean_function[i] = np.abs(mean - np.pi / 2.0)

    ### Plot ###
    x = rad
    y = scale_height_function / scale_height
    y2 = (mean_function + scale_height_function) / scale_height
    result,  = plot.plot(x, y, linewidth = linewidth, c = "b", zorder = 99)
    result2, = plot.plot(x, y2, linewidth = linewidth - 1, c = "r", zorder = 90)

    if args.zero:
        density_zero = fromfile("gasdens0.dat").reshape(num_rad, num_theta)
        averagedDensity_zero = np.average(density_zero, axis = 1)
        normalized_density_zero = averagedDensity_zero / surface_density_zero

        x = rad
        y_zero = normalized_density_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()

    if args.derivative:
        twin = ax.twinx()

        ### Plot ###
        dr = rad[1] - rad[0]
        normalized_density_derivative = np.diff(normalized_density) / dr

        x2 = rad[1:]
        y2 = normalized_density_derivative
        result = twin.plot(x2, y2, c = "purple", linewidth = linewidth, alpha = 0.6, zorder = 99, label = "derivative")

        plot.legend()

        twin.set_ylim(-10, 10)

    # Axes
    if args.max_y is None:
        max_y = 1.1 * max(y)
    else:
        max_y = args.max_y

    ax.set_xlim(x[0], x[-1])
    ax.set_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}"
    ax.set_xlabel(r"Radius [$%s$]" % unit, fontsize = fontsize)
    ax.set_ylabel(r"Dust Scale Height $H_d$ $/$ $h$", 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[-1] - x[0]; x_mid = x[0] + 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"$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)
    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)
    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)
    ax.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')

    if args.maximum_condition:
        bump, _ = az.get_radial_peak(normalized_density, fargo_par, end = 1.6)
        plot.plot([bump, bump], [0, max_y], c = "b", linewidth = linewidth - 2, alpha = alpha, linestyle = "--", zorder = 20)

        twin = ax.twinx()

        vrad = (fromfile("gasvy%d.dat" % frame).reshape(num_rad, num_theta)) # add a read_vrad to util.py!
        vtheta = (fromfile("gasvx%d.dat" % frame).reshape(num_rad, num_theta)) # add a read_vrad to util.py!
        vorticity = utilVorticity.velocity_curl(vrad, vtheta, rad, theta, rossby = rossby, residual = residual)

        averaged_vorticity = np.average(vorticity, axis = 1)
        #averaged_density = np.average(normalized_density, axis = 1) # normalized_density
        maximum_condition = (normalized_density[1:] / averaged_vorticity) * (np.power(scale_height, 2) / np.power(rad[1:], 1))

        x2 = rad[1:]
        y2 = maximum_condition
        result2, = twin.plot(x2, y2, c = 'darkviolet', linewidth = linewidth, zorder = 99)

        bump, _ = az.get_radial_peak(maximum_condition, fargo_par, end = 1.6)
        plot.plot([bump, bump], y2_range, c = "darkviolet", linewidth = linewidth - 2, alpha = alpha, linestyle = "--", zorder = 20)

        # Axes
        twin.set_ylim(y2_range[0], y2_range[1])
        twin.set_yticks(np.arange(y2_range[0], y2_range[1] + 1e-9, 0.005))

        twin.set_ylabel(r"$\Sigma$ $/$ ($\nabla \times v$)$_\mathrm{z}$", fontsize = fontsize, rotation = 270, labelpad = 25)

        tkw = dict(size=4, width=1.5)
        ax.tick_params(axis = 'y', colors = result.get_color(), **tkw)
        twin.tick_params(axis = 'y', colors = result2.get_color(), **tkw)

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

    # Data
    field = "dens"
    if mpi:
        density = Fields("./", 'gas', frame).get_field(field).reshape(
            num_z, num_rad, num_theta)
    else:
        density = fromfile("gasdens%d.dat" % frame).reshape(
            num_z, num_rad, num_theta)
    midplane_density = density[num_z / 2 + z_level, :, :]

    scale_height_function = scale_height * rad
    normalized_density = midplane_density / (surface_density_zero / np.sqrt(
        2.0 * np.pi) / scale_height_function[:, None])

    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 Density  $\rho$ $/$ $\rho_0$",
                   fontsize=fontsize,
                   rotation=270,
                   labelpad=25)

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

    if show:
        plot.show()

    plot.close(fig)  # Close Figure (to avoid too many figures)
Esempio 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 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)
    averaged_vorticity = np.average(vorticity, axis=1)

    delta_midplane_vtheta = midplane_vtheta - np.average(midplane_vtheta,
                                                         axis=1)
    delta_midplane_velocity = midplane_vrad * delta_midplane_vtheta

    scale_height_function = scale_height * np.power(rad, 1.0 + flaring_index)
    omega_function = np.power(rad, -1.5)
    sound_speed = scale_height_function * omega_function

    alpha = midplane_vrad * delta_midplane_vtheta / np.power(sound_speed, 2.0)
    average_alpha = np.average(alpha, axis=1)

    ### Plot ###
    x = rad
    y = average_alpha

    result, = plot.plot(x,
                        y,
                        linewidth=linewidth,
                        c="b",
                        label="min",
                        zorder=90)

    # Axes
    plot.xlim(x_min, x_max)
    plot.ylim(10**(-8), 3 * 10**(-1))
    plot.yscale('log')
    #plot.yticks(np.arange(y_range[0], y_range[1] + 1e-9, 0.005))

    # 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}"
    ax.set_xlabel(r"Radius [$%s$]" % unit, fontsize=fontsize)
    ax.set_ylabel(r"$<\Delta v_r \Delta v_{\phi}> / c_s^2$", 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

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

    #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)
    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)
    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)
    #ax.text(x_mid, y_text * plot.ylim()[0], title1, horizontalalignment = 'center', bbox = dict(facecolor = 'none', edgecolor = 'black', linewidth = 1.5, pad = 7.0), fontsize = fontsize + 2)

    # Text
    text_mass = r"$M_\mathrm{p} = %d$ $M_\mathrm{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/averagedReynoldsStress_%04d.png" % (save_directory,
                                                          frame)
    else:
        save_fn = "%s/v%04d_averagedReynoldsStress_%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(z_level, show=False):
    # Set up figure
    fig = plot.figure(figsize=(7, 6), dpi=dpi)
    ax = fig.add_subplot(111)

    # 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 + z_level, :, :]
    midplane_vrad = vrad[num_z / 2 + z_level, :, :]
    midplane_vtheta = vtheta[num_z / 2 + z_level, :, :]

    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)

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

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

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

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

    if quiver:
        # Velocity
        radial_velocity = vrad
        azimuthal_velocity = vtheta
        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
    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]

    #title = readTitle()

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

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

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

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

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

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

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

    if show:
        plot.show()

    plot.close(fig)  # Close Figure (to avoid too many figures)
Esempio n. 6
0
    def add_to_plot(i):
        # Identify Subplot
        frame = frames[i]
        number = i + 1
        ax = plot.subplot(1, 2, number)

        # Data
        field = "dens"
        if mpi:
            density = Fields("./", 'dust1', frame).get_field(field).reshape(
                num_z, num_rad, num_theta)
            gas_density = Fields("./", 'gas', frame).get_field(field).reshape(
                num_z, num_rad, num_theta)
        else:
            density = fromfile("dust1dens%d.dat" % frame).reshape(
                num_z, num_rad, num_theta)
            gas_density = fromfile("gasdens%d.dat" % frame).reshape(
                num_z, num_rad, num_theta)

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

        normalized_density = surface_density / dust_surface_density_zero  # / np.sqrt(2.0 * np.pi) / scale_height_function[:, None]
        normalized_gas_density = gas_surface_density / 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)
        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_gas_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,
                        color="cyan")

        # 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]
        #current_gap_depth = get_gap_depth(density)

        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)
        #title = r"$t = %d$ [$\delta_\mathrm{gap}=%.1f$]" % (orbit, current_gap_depth)
        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)
        cbar.set_label(r"Dust Surface Density  $\Sigma$ $/$ $\Sigma_0$",
                       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