def shift_density(normalized_density, fargo_par, option="away", reference_density=None, frame=None): """ shift density based on option """ if reference_density is None: reference_density = normalized_density # Options if option == "peak": shift_c = az.get_azimuthal_peak(reference_density, fargo_par) elif option == "threshold": threshold = util.get_threshold(fargo_par["PSIZE"]) shift_c = az.get_azimuthal_center(reference_density, fargo_par, threshold=threshold) elif option == "away": shift_c = az.shift_away_from_minimum(reference_density, fargo_par) elif option == "lookup": shift_c = az.get_lookup_shift(frame) else: print "Invalid centering option. Choose (cm-)peak, (cm-)threshold, (cm-)away, or lookup" # Shift shifted_density = np.roll(normalized_density, shift_c) return shifted_density, shift_c
def center_vortex(density, frame, reference_density=None): """ Step 2: center the vortex so that the peak is at 180 degrees """ if taper_time < 1.1: for i, size in enumerate(sizes): shift_i = az.get_azimuthal_peak(density[:, :, i], fargo_par) density[:, :, i] = np.roll(density[:, :, i], shift_i, axis=1) return density elif taper_time > 1.1: for i, size_name in enumerate(size_names): if center == "lookup": pass #shift_i = az.get_lookup_shift(frame, directory = "../%s-size" % size_name) elif center == "threshold": threshold = util.get_threshold(size) * surface_density_zero shift_i = az.get_azimuthal_center(density[:, :, i], fargo_par, threshold=threshold) elif center == "away": shift_i = az.shift_away_from_minimum(reference_density, fargo_par) else: print "invalid centering option" density[:, :, i] = np.roll(density[:, :, i], shift_i, axis=1) return density
def measure_peak_offset(args): # Unpack i, frame = args intensity_polar = util.read_data(frame, 'polar_intensity', fargo_par, id_number=id_number) # Shift and get peak shift_c = az.shift_away_from_minimum(intensity_polar, fargo_par) intensity_polar = np.roll(intensity_polar, shift_c, axis=-1) peak_r_i, peak_phi_i = az.get_peak(intensity_polar, fargo_par) # Return peak relative to the center, where the edges are set by a threshold intensity_polar /= np.max(intensity_polar) # normalize intensity_polar_at_peak = intensity_polar[ peak_r_i, :] # take azimuthal profile left_index = az.my_searchsorted(intensity_polar_at_peak, threshold) right_index = len(intensity_polar_at_peak) - az.my_searchsorted( intensity_polar_at_peak[::-1], threshold) - 1 # Convert to theta left_theta = theta[left_index] * (180.0 / np.pi) right_theta = theta[right_index] * (180.0 / np.pi) center_theta = left_theta + (right_theta - left_theta) / 2.0 peak_theta = theta[peak_phi_i] * (180.0 / np.pi) peak_offset = peak_theta - center_theta print i, frame, peak_offset, center_theta, peak_theta # Store in mp_array peak_offsets[i] = peak_offset
def make_plot(frame, show=False): # Set up figure fig = plot.figure(figsize=(7, 6), dpi=dpi) ax = fig.add_subplot(111) # Data intensity_polar = util.read_data(frame, 'polar_intensity', fargo_par, id_number=id_number) if normalize: intensity_polar /= np.max(intensity_polar) _, azimuthal_profile = az.get_profiles(intensity_polar, fargo_par, args, shift=None) # Get Shift gas_density = util.read_data(frame, 'gas', fargo_par, directory="../../") # Shift gas density with center of dust density shift = az.shift_away_from_minimum(gas_density, fargo_par) ### Plot ### x = theta * (180.0 / np.pi) - 180.0 plot.plot(x, azimuthal_profile, linewidth=linewidth, alpha=alpha) if args.compare is not None: for i, directory in enumerate(args.compare): intensity_polar_c = util.read_data(frame, 'polar_intensity', fargo_par, id_number=id_number, directory=directory) if normalize: intensity_polar_c /= np.max(intensity_polar_c) _, azimuthal_profile_c = az.get_profiles(intensity_polar_c, fargo_par, args, shift=None) plot.plot(x, azimuthal_profile_c, linewidth=linewidth, alpha=alpha, label="%s" % i) plot.legend(loc="upper left") # Locate Planet if shift is None: planet_loc = theta[0] else: if shift < -len(theta): shift += len(theta) planet_loc = theta[shift] * (180.0 / np.pi) - 180.0 plot.scatter(planet_loc, 0, c="k", s=150, marker="D", zorder=100) # planet # 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] # Axes max_x = 180 plot.xlim(-max_x, max_x) angles = np.linspace(-max_x, max_x, 7) plot.xticks(angles) if max_y is None: plot.ylim(0, plot.ylim()[-1]) # No Input else: plot.ylim(0, max_y) # Input # Annotate Axes time = fargo_par["Ninterm"] * fargo_par["DT"] orbit = (time / (2 * np.pi)) * frame current_mass = util.get_current_mass(orbit, taper_time, planet_mass=planet_mass) plot.xlabel(r"$\phi - \phi_\mathrm{center}$ $\mathrm{(degrees)}$", fontsize=fontsize + 2) plot.ylabel(r"$I$ / $I_\mathrm{max}$", fontsize=fontsize) # Title title = "\n" + r"$t$ $=$ $%.1f$ " % ( orbit) + "[$m_p(t)$ $=$ $%.2f$ $M_J$]" % (current_mass) plot.title("%s" % (title), fontsize=fontsize + 1) # Save, Show, and Close if version is None: save_fn = "%s/id%04d_azimuthalIntensityProfiles_%04d.png" % ( save_directory, id_number, frame) else: save_fn = "%s/v%04d_id%04d_azimuthalIntensityProfiles_%04d.png" % ( save_directory, version, id_number, 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 intensity_cart = util.read_data(frame, 'cartesian_intensity', fargo_par, id_number = id_number) xs, ys, xs_grid, ys_grid = sq.get_cartesian_grid(rad) # Get Shift gas_density = util.read_data(frame, 'gas', fargo_par, directory = "../../") # Shift gas density with center of dust density shift = az.shift_away_from_minimum(gas_density, fargo_par) # Normalize if normalize: intensity_cart /= np.max(intensity_cart) # Arcseconds or Planet Radii if arc: arc_weight = planet_radius / distance # related to parallax else: arc_weight = 1 ### Plot ### result = plot.pcolormesh(xs * arc_weight, ys * arc_weight, np.transpose(intensity_cart), cmap = cmap) result.set_clim(clim[0], clim[1]) # Get rid of interior circle = plot.Circle((0, 0), min(rad) * arc_weight, color = "black") ax.add_artist(circle) # Add beam size beam = plot.Circle((1.7 * arc_weight, 1.7 * arc_weight), (beam_size / 2) * arc_weight, color = "white") fig.gca().add_artist(beam) # Add planet orbit planet_orbit = plot.Circle((0, 0), 1 * arc_weight, color = "white", fill = False, alpha = 0.8, linestyle = "dashed", zorder = 50) ax.add_artist(planet_orbit) # Locate Planet if shift < -len(theta): shift += len(theta) planet_theta = theta[shift] 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) - (np.pi) # Keep -np.pi < theta < np.pi planet_x = np.cos(planet_theta) planet_y = np.sin(planet_theta) # 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] planet_size = current_mass / planet_mass plot.scatter(0, 0, c = "white", s = 300, marker = "*", zorder = 100) # star plot.scatter(planet_x * arc_weight, planet_y * arc_weight, c = "white", s = int(70), marker = "D", zorder = 100) # planet # Axes box_size = args.box * arc_weight plot.xlim(-box_size, box_size) plot.ylim(-box_size, box_size) plot.axes().set_aspect('equal') 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 = 5) # Annotate Axes if arc: unit = "^{\prime\prime}" else: unit = "r_\mathrm{p}" ax.set_xlabel(r"$x$ [$%s$]" % unit, fontsize = fontsize) ax.set_ylabel(r"$y$ [$%s$]" % unit, fontsize = fontsize) # Title title = r"$t$ $=$ $%.1f$ [$m_p(t)$ $=$ $%.2f$ $M_J$]" % (orbit, current_mass) plot.title("%s" % (title), y = 1.015, fontsize = fontsize + 1) #plot.title("Intensity Map (t = %.1f)" % (orbit), fontsize = fontsize + 1) taper_title = r"$T_\mathrm{growth} = %d$" % taper_time #plot.text(0.0 * box_size, 2 * arc_weight, taper_title, fontsize = fontsize, color = 'white', horizontalalignment = 'center', bbox=dict(facecolor = 'black', edgecolor = 'white', pad = 10.0), zorder = 100) # Add Colorbar (Source: http://stackoverflow.com/questions/23270445/adding-a-colorbar-to-two-subplots-with-equal-aspect-ratios) if colorbar: # Only for last frame divider = make_axes_locatable(ax) cax = divider.append_axes("right", size = "8%", pad = 0.2) #cax = fig.add_axes([0.9, 0.1, 0.03, 0.8]) cbar = fig.colorbar(result, cax = cax) cbar.set_label("Normalized Intensity", fontsize = fontsize, rotation = 270, labelpad = 25) # Save, Show, and Close if version is None: save_fn = "%s/id%04d_intensityCartGrid_%04d.png" % (save_directory, id_number, frame) else: save_fn = "%s/v%04d_id%04d_intensityCartGrid_%04d.png" % (save_directory, version, id_number, 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(frame, fig, ax, frame_i): # Declare Subplot #ax = plot.subplot(1, num_frames, frame_i, sharex = prev_ax, sharey = prev_ax, aspect = "equal") # Taper if frame_i == 1: taper_time = 10 else: taper_time = 750 # Change directories cwd = os.getcwd() os.chdir(directories[frame_i - 1]) # Data vrad = (fromfile("gasvrad%d.dat" % frame).reshape(num_rad, num_theta) ) # add a read_vrad to util.py! vtheta = (fromfile("gasvtheta%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) # Shift density = (fromfile("gasdens%d.dat" % frame).reshape( num_rad, num_theta)) / surface_density_zero dust_density = (fromfile("gasddens%d.dat" % frame).reshape( num_rad, num_theta)) if center: if taper_time < 10.1: shift_c = az.get_azimuthal_peak(dust_density, fargo_par) else: if center == "lookup": shift_c = az.get_lookup_shift(frame) elif option == "away": shift_c = az.shift_away_from_minimum(dust_density, fargo_par) elif center == "threshold": threshold = util.get_threshold(size) shift_c = az.get_azimuthal_center(dust_density, fargo_par, threshold=threshold * surface_density_zero / 100.0) else: shift_c = 0 # Do not center vorticity = np.roll(vorticity, shift_c) density = np.roll(density, shift_c) ### Plot ### x = rad y = theta * (180.0 / np.pi) result = ax.pcolormesh(x, y, np.transpose(vorticity), cmap=cmap) #if frame_i == 2: # 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(density), levels=levels, origin='upper', linewidths=1, colors=colors, alpha=0.8) # Axes y_min = 0 y_max = 360 plot.xlim(x_min, x_max) plot.ylim(y_min, y_max) angles = np.linspace(y_min, y_max, 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) if frame_i == 1: plot.ylabel(r"$\phi$ $\mathrm{(degrees)}$", fontsize=fontsize + 2) #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{J}$]" % ( orbit, current_mass) plot.title("%s" % (title2), y=1.015, fontsize=fontsize + 1) plot.text(x_mid, y_text * (plot.ylim()[-1] - plot.ylim()[0]) + 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{J}$" % (int(planet_mass)) text_visc = r"$\nu = 10^{%d}$" % (int(np.log(viscosity) / np.log(10))) #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)) if frame_i == 1: plot.text(-0.84 * x_range / 2.0 + x_mid, y_text * (plot.ylim()[-1] - plot.ylim()[0]) + plot.ylim()[0], text_mass, fontsize=fontsize, color='black', horizontalalignment='right') if frame_i == 2: plot.text(0.84 * x_range / 2.0 + x_mid, y_text * (plot.ylim()[-1] - plot.ylim()[0]) + plot.ylim()[0], text_visc, fontsize=fontsize, color='black', horizontalalignment='left') # Label colorbar # Add Colorbar (Source: http://stackoverflow.com/questions/23270445/adding-a-colorbar-to-two-subplots-with-equal-aspect-ratios) if frame_i < 5: # Only for last frame 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) if frame_i == 2: 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=32) #if frame_i != num_frames: # fig.delaxes(cax) # to balance out frames that don't have colorbar with the one that does # Set Aspect Ratio #unit_aspect_ratio = (360) / (x_range) #ax.set_aspect(1.12 / unit_aspect_ratio) # Return to previous directory os.chdir(cwd) return ax
def add_to_plot(i): # Identify Subplot frame = frames[i] number = i + 1 ax = plot.subplot(1, 2, number) # Data intensity_cart = util.read_data(frame, 'cartesian_intensity', fargo_par, id_number=id_number) xs, ys, xs_grid, ys_grid = sq.get_cartesian_grid(rad) # Get Shift gas_density = util.read_data(frame, 'gas', fargo_par, directory="../../") # Shift gas density with center of dust density shift = az.shift_away_from_minimum(gas_density, fargo_par) # Normalize if normalize: intensity_cart /= np.max(intensity_cart) # Arcseconds or Planet Radii if arc: arc_weight = planet_radius / distance # related to parallax else: arc_weight = 1 ### Plot ### result = plot.pcolormesh(xs * arc_weight, ys * arc_weight, np.transpose(intensity_cart), cmap=cmap) result.set_clim(clim[0], clim[1]) # Get rid of interior circle = plot.Circle((0, 0), min(rad) * arc_weight, color="black") ax.add_artist(circle) # Add beam size beam = plot.Circle((1.7 * arc_weight, 1.7 * arc_weight), (beam_size / 2) * arc_weight, color="white") fig.gca().add_artist(beam) # Add planet orbit planet_orbit = plot.Circle((0, 0), 1 * arc_weight, color="white", fill=False, alpha=0.8, linestyle="dashed", zorder=50) ax.add_artist(planet_orbit) # Locate Planet if shift < -len(theta): shift += len(theta) planet_theta = theta[shift] 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) - ( np.pi) # Keep -np.pi < theta < np.pi planet_x = np.cos(planet_theta) planet_y = np.sin(planet_theta) # 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] plot.scatter(0, 0, c="white", s=250, marker="*", zorder=100) # star plot.scatter(planet_x * arc_weight, planet_y * arc_weight, c="white", s=60, marker="D", zorder=100) # planet # Axes box_size = args.box * arc_weight ax.set_xlim(-box_size, box_size) ax.set_ylim(-box_size, box_size) ax.set_aspect('equal') 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=5, direction="in") # Annotate Axes if arc: ticks = np.arange(-0.3, 0.31, 0.1) ax.set_xticks(ticks) ax.set_xticklabels(["", "-0.2", "", "0.0", "", "0.2", ""]) ax.set_yticks(ticks) unit = "^{\prime\prime}" else: unit = "r_\mathrm{p}" ax.set_xlabel(r"$x$ [$%s$]" % unit, fontsize=fontsize) if number == 1: ax.set_ylabel(r"$y$ [$%s$]" % unit, fontsize=fontsize) # Title title = r"$t = %d$ [$m_\mathrm{p}=%.2f$ $M_\mathrm{J}$]" % ( orbit, current_mass) plot.title("%s" % (title), y=1.035, fontsize=fontsize) # Add Colorbar (Source: http://stackoverflow.com/questions/23270445/adding-a-colorbar-to-two-subplots-with-equal-aspect-ratios) if args.colorbar: 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"Normalized Intensity", 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