def choose_axis(i, axis):
        # Orbit Number
        time = float(fargo_par["Ninterm"]) * float(fargo_par["DT"])
        orbit = int(round(time / (2 * np.pi), 0)) * i

        # Set up figure
        fig = plot.figure(figsize=(700 / my_dpi, 600 / my_dpi), dpi=my_dpi)
        ax = fig.add_subplot(111)

        # Axis
        angles = np.linspace(0, 2 * np.pi, 7)
        degree_angles = ["%d" % d_a for d_a in np.linspace(0, 360, 7)]

        plot.ylim(0, 2 * np.pi)
        plot.yticks(angles, degree_angles)

        if axis == "zoom":
            x = (rad - 1) / scale_height
            prefix = "zoom_"
            plot.xlim(0, 40)  # to match the ApJL paper
            xlabel = r"($r - r_p$) $/$ $h$"
        else:
            x = rad
            prefix = ""
            plot.xlim(float(fargo_par["Rmin"]), float(fargo_par["Rmax"]))
            xlabel = "Radius"

        # Data
        density = (fromfile("gasdens%d.dat" % i).reshape(num_rad, num_theta))
        normalized_density = density / surface_density_zero

        torque_map = util.torque(rad, theta, normalized_density)
        abs_torque = np.abs(torque_map)
        log_torque = np.log(abs_torque) / np.log(10)  # log torque in base 10

        ### Plot ###
        result = ax.pcolormesh(x, theta, np.transpose(log_torque), cmap=cmap)

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

        # Annotate
        plot.xlabel(xlabel, fontsize=fontsize)
        plot.ylabel(r"$\phi$", fontsize=fontsize)
        plot.title("Torque Map at Orbit %d" % orbit, fontsize=fontsize + 1)

        # Save and Close
        plot.savefig("%s/%storqueMap_%03d.png" % (save_directory, prefix, i),
                     bbox_inches='tight',
                     dpi=my_dpi)
        if show:
            plot.show()
        plot.close(fig)  # Close Figure (to avoid too many figures)
Example #2
0
    def choose_axis(i, axis):
        # Orbit Number
        time = float(fargo_par["Ninterm"]) * float(fargo_par["DT"])
        orbit = int(round(time / (2 * np.pi), 0)) * i

        # Set up figure
        fig = plot.figure(figsize = (700 / my_dpi, 600 / my_dpi), dpi = my_dpi)
        ax = fig.add_subplot(111)

        # Axis
        angles = np.linspace(0, 2 * np.pi, 7)
        degree_angles = ["%d" % d_a for d_a in np.linspace(0, 360, 7)]

        plot.ylim(0, 2 * np.pi)
        plot.yticks(angles, degree_angles)

        if axis == "zoom":
            x = (rad - 1) / scale_height
            prefix = "zoom_"
            plot.xlim(0, 40) # to match the ApJL paper
            xlabel = r"($r - r_p$) $/$ $h$"
        else:
            x = rad
            prefix = ""
            plot.xlim(float(fargo_par["Rmin"]), float(fargo_par["Rmax"]))
            xlabel = "Radius"

        # Data
        density = (fromfile("gasdens%d.dat" % i).reshape(num_rad, num_theta))
        normalized_density = density / surface_density_zero

        torque_map = util.torque(rad, theta, normalized_density, )
        abs_torque = np.abs(torque_map)
        log_torque = np.log(abs_torque) / np.log(10) # log torque in base 10

        ### Plot ###
        result = ax.pcolormesh(x, theta, np.transpose(abs_torque), cmap = cmap)
    
        fig.colorbar(result)
        result.set_clim(clim[0], clim[1])

        # Annotate
        plot.xlabel(xlabel, fontsize = fontsize)
        plot.ylabel(r"$\phi$", fontsize = fontsize)
        plot.title("Torque Map at Orbit %d" % orbit, fontsize = fontsize + 1)

        # Save and Close
        plot.savefig("%s/%storqueMap_%03d.png" % (save_directory, prefix, i), bbox_inches = 'tight', dpi = my_dpi)
        if show:
            plot.show()
        plot.close(fig) # Close Figure (to avoid too many figures)
Example #3
0
    def choose_axis(i, axis):
        # Orbit Number
        time = float(fargo_par["Ninterm"]) * float(fargo_par["DT"])
        orbit = int(round(time / (2 * np.pi), 0)) * i

        # Set up figure
        fig = plot.figure(figsize = (700 / my_dpi, 600 / my_dpi), dpi = my_dpi)
        ax = fig.add_subplot(111, polar = True)

        # Axis
        angles = np.linspace(0, 2 * np.pi, 7)
        degree_angles = ["%d" % d_a for d_a in np.linspace(0, 360, 7)]

        plot.ylim(0, 2 * np.pi)
        plot.yticks(angles, degree_angles)

        # Axis
        if axis == "zoom":
            prefix = "zoom_"
            rmax = 2.4 # to match ApJL paper
        else:
            prefix = ""
            rmax = float(fargo_par["Rmax"])

        plot.xticks([], []) # Angles
        plot.yticks([rmax], ["%.1f" % rmax]) # Max Radius
        plot.ylim(0, rmax)

        # Data
        density = (fromfile("gasdens%d.dat" % i).reshape(num_rad, num_theta))
        normalized_density = density / surface_density_zero

        torque_map = util.torque(rad, theta, normalized_density, planet_mass = planet_mass)
        abs_torque = np.abs(torque_map)
        log_torque = np.log(abs_torque) / np.log(10) # log torque in base 10

        ### Plot ###
        result = ax.pcolormesh(theta, rad, log_torque, cmap = cmap)
    
        fig.colorbar(result)
        result.set_clim(clim[0], clim[1])

        # Annotate
        plot.title("Torque Map at Orbit %d" % orbit, fontsize = fontsize + 1)

        # Save and Close
        plot.savefig("%s/%storqueMap_%03d.png" % (save_directory, prefix, i), bbox_inches = 'tight', dpi = my_dpi)
        if show:
            plot.show()
        plot.close(fig) # Close Figure (to avoid too many figures)
Example #4
0
for frame in range(num_frames):
    density = (fromfile("gasdens%d.dat" % frame).reshape(num_rad, num_theta))
    normalized_density = density / surface_density_zero

    vrad = (fromfile("gasvrad%d.dat" % frame).reshape(num_rad, num_theta))
    vtheta = (fromfile("gasvtheta%d.dat" % frame).reshape(num_rad, num_theta))

    vorticity = curl(vrad, vtheta, rad, theta)
    vortensity = vorticity / normalized_density[1:, 1:]
    averaged_w = np.average(vortensity, axis=1)

    ### Vortex Torque ###
    # the vortex is any cell where the vortensity is between the thresholds of 0.0 and 0.2
    #vortex_indices = np.where(vortensity < 0.2 and vortensity > 0.0)

    torqueMap = util.torque(rad, theta, density)
    vortexTorque = np.sum(torqueMap[(vortensity < 0.2) & (vortensity > 0.0)])

    ### Get Phase Too ###
    outer_disk_start = np.searchsorted(
        rad, 1.2)  # look for min vortensity beyond r = 1.2
    outer_disk_end = np.searchsorted(
        rad, 2.5)  # look for min vortensity before r = 2.5
    vortex_rad_outer_index = np.argmin(
        averaged_w[outer_disk_start:outer_disk_end])

    vortex_rad_index = vortex_rad_outer_index + outer_disk_start

    # Check 10 + 1 + 10 profiles
    dr = 10  # 10 indices
    vortex_width = range(vortex_rad_index - dr, vortex_rad_index + dr + 1)
a = "Frame".center(column_widths[0])
b = "Total".center(column_widths[1])
c = "Inner".center(column_widths[2])
d = "Outer".center(column_widths[3])
e = "Inner (+)".center(column_widths[4])
f = "Inner (-)".center(column_widths[5])
g = "Outer (+)".center(column_widths[6])
h = "Outer (-)".center(column_widths[7])
first_line = "%s %s %s %s %s %s %s %s\n" % (a, b, c, d, e, f, g, h)
dat_file.write(first_line)
dat_file.close()

#### Calculate Data and Write to Files ####
for frame in range(num_frames):
    density = (fromfile("gasdens%d.dat" % frame).reshape(num_rad, num_theta))
    torqueMap = util.torque(rad, theta, density)

    inner_torque_halves = util.inner_torque_contributions(rad, theta, torqueMap)
    outer_torque_halves = util.outer_torque_contributions(rad, theta, torqueMap)

    inner_torque = inner_torque_halves[0] + inner_torque_halves[1]
    outer_torque = outer_torque_halves[0] + outer_torque_halves[1]
    net_torque = inner_torque + outer_torque

    # Format into strings
    scaling = 10**6 # multiply by one million to make things readable
    a = ("%d" % frame).center(column_widths[0])
    b = ("%.8f" % (net_torque * scaling)).center(column_widths[1])
    c = ("%.8f" % (inner_torque * scaling)).center(column_widths[2])
    d = ("%.8f" % (outer_torque * scaling)).center(column_widths[3])
    e = ("%.8f" % (inner_torque_halves[0] * scaling)).center(column_widths[4])