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 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 make_plot(frame, show = False): # Set up figure fig = plot.figure(figsize = (7, 6), dpi = dpi) ### Data ### intensity_polar = util.read_data(frame, 'polar_intensity', fargo_par, id_number = id_number) if normalize: intensity_polar /= np.max(intensity_polar) azimuthal_radii, azimuthal_profiles = az.get_profiles(intensity_polar, fargo_par, args, shift = None) ### Plot ### # Profiles x = theta * (180.0 / np.pi) - 180.0 for i, (radius, azimuthal_profile) in enumerate(zip(azimuthal_radii, azimuthal_profiles)): plot.plot(x, azimuthal_profile, linewidth = linewidth, c = colors[i], dashes = dashes[i], alpha = alpha, label = labels[i]) # Mark Planet (get shift first) shift = az.get_lookup_shift(frame, directory = "../../../cm-size") 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 # Axes if taper_time < 10.1: # T = 10 max_x = 60 else: # T = 1000 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) # Legend plot.legend(loc = "upper right", bbox_to_anchor = (1.34, 0.94)) # outside of plot # Extra Annotation (Location, Legend Label) rc_line = r"$r_\mathrm{c} = %.02f$" % azimuthal_radii[(num_profiles - 1) / 2] plot.text(-170, 0.885 * plot.ylim()[-1], rc_line, fontsize = fontsize, horizontalalignment = 'left') center_x = 1.38 * plot.xlim()[-1] top_y = plot.ylim()[-1] line = "Radii" plot.text(center_x, 0.95 * top_y, line, fontsize = fontsize - 1, horizontalalignment = 'center') # Annotate Peak Offsets if annotate: frames = pickle.load(open("id%04d_b%d_t30_intensityFrames.p" % (id_number, beam_size * planet_radius), 'rb')) offsets_t3 = pickle.load(open("id%04d_b%d_t30_intensityPeaks.p" % (id_number, beam_size * planet_radius), 'rb')) offsets_t4 = pickle.load(open("id%04d_b%d_t40_intensityPeaks.p" % (id_number, beam_size * planet_radius), 'rb')) offsets_t5 = pickle.load(open("id%04d_b%d_t50_intensityPeaks.p" % (id_number, beam_size * planet_radius), 'rb')) this_frame = np.searchsorted(frames, frame) offset_t3 = offsets_t3[this_frame]; offset_t4 = offsets_t4[this_frame]; offset_t5 = offsets_t5[this_frame] t3_line = "t = 0.3: %.1f" % (offset_t3) t4_line = "t = 0.4: %.1f" % (offset_t4) t5_line = "t = 0.5: %.1f" % (offset_t5) start_y = 0.08 * plot.ylim()[-1]; linebreak = 0.08 * plot.ylim()[-1] plot.text(0, start_y + 2.0 * linebreak, t5_line, fontsize = fontsize, horizontalalignment = 'center') plot.text(0, start_y + 1.0 * linebreak, t4_line, fontsize = fontsize, horizontalalignment = 'center') plot.text(0, start_y + 0.0 * linebreak, t3_line, fontsize = fontsize, horizontalalignment = 'center') # Title title = "\n" + r"$t$ $=$ $%.1f$ " % (orbit) + "[$m_p(t)$ $=$ $%.2f$ $M_J$]" % (current_mass) plot.title("%s" % (title), fontsize = fontsize + 1) # Title box_size = plot.xlim()[-1]; top_y = plot.ylim()[-1] left_x = -0.8 * box_size; line_y = 1.18 * top_y; linebreak = 0.2 * box_size right_x = 1.3 * box_size line1 = r"$%.03f^{\prime\prime} \times \ \ %.03f^{\prime\prime}$" % (arc_beam, arc_beam) plot.text(right_x, line_y, line1, horizontalalignment = 'right', fontsize = fontsize + 2) # Save, Show, and Close plot.tight_layout() png = "png"; pdf = "pdf" if version is None: save_fn = "%s/azimuthalIntensityProfiles_%04d.%s" % (save_directory, frame, png) pdf_save_fn = "%s/azimuthalIntensityProfiles_%04d.%s" % (save_directory, frame, pdf) else: save_fn = "%s/v%04d_azimuthalIntensityProfiles_%04d.%s" % (save_directory, version, frame, png) pdf_save_fn = "%s/v%04d_azimuthalIntensityProfiles_%04d.%s" % (save_directory, version, frame, pdf) plot.savefig(save_fn, bbox_inches = 'tight', dpi = dpi) plot.savefig(pdf_save_fn, bbox_inches = 'tight', format = "pdf") if show: plot.show() plot.close(fig) # Close Figure (to avoid too many figures)
def add_to_plot(frame, fig, ax, size_name, num_frames, frame_i): # Convert size to number size = util.get_size(size_name) ### Data ### density1 = util.read_data(frame_range[0], 'dust', fargo_par, directory = "../taper10/%s-size" % size_name) / surface_density_zero density2 = util.read_data(frame_range[1], 'dust', fargo_par, directory = "../taper750/%s-size" % size_name) / surface_density_zero # Choose shift option if center: shift1 = az.get_azimuthal_peak(density1, fargo_par) threshold = util.get_threshold(size) shift2 = az.get_lookup_shift(frame_range[1], directory = "../taper750/%s-size" % size_name) else: shift1 = None; shift2 = None azimuthal_radii1, azimuthal_profiles1 = az.get_profiles(density1, fargo_par, args, shift = shift1) azimuthal_radii2, azimuthal_profiles2 = az.get_profiles(density2, fargo_par, args, shift = shift2) ### Plot ### # Profiles x = theta * (180.0 / np.pi) if num_profiles > 1: for i, (radius, azimuthal_profile) in enumerate(zip(azimuthal_radii1, azimuthal_profiles1)): plot.plot(x, azimuthal_profile, linewidth = linewidth, dashes = dashes[i], c = colors1[i], alpha = alpha, label = labels1[i]) else: i = 1 plot.plot(x, azimuthal_profiles1, linewidth = linewidth, dashes = dashes[i], c = colors1[i], alpha = alpha, label = labels1[i]) # Add a beak in the legend if num_profiles > 1: plot.plot([0.1, 0.1], [0.2, 0.2], c = 'white', label = "\t") if num_profiles > 1: for i, (radius, azimuthal_profile) in enumerate(zip(azimuthal_radii2, azimuthal_profiles2)): plot.plot(x, azimuthal_profile, linewidth = linewidth, dashes = dashes[i], c = colors2[i], alpha = alpha, label = labels2[i]) else: i = 1 plot.plot(x, azimuthal_profiles2, linewidth = linewidth, dashes = dashes[i], c = colors2[i], alpha = alpha, label = labels2[i]) # Plot analytic if num_profiles > 1: middle_i = (num_profiles - 1) / 2; radius = azimuthal_radii1[middle_i] # middle #center_density = azimuthal_profiles[middle_i][(len(azimuthal_profiles[middle_i]) - 1) / 2] max_density = np.max(azimuthal_profiles1[middle_i]) else: radius = azimuthal_radii1 max_density = np.max(azimuthal_profiles1) aspect_ratio = (r_a / dr_a) * (dtheta_a * np.pi / 180.0) # (r / dr) * d\theta S = util.get_stokes_number(size) / (diffusion_factor * viscosity / scale_height**2) # St / \alpha analytic = np.array([az.get_analytic_profile(angle, r_a, dr_a, dtheta_a, aspect_ratio, S) for angle in (x - 180.0)]) analytic = analytic / np.max(analytic) * max_density # Normalize and re-scale to max density # Mask outside vortex and plot masked_i = np.abs(x - 180.0) <= (dtheta_a / 2.0); masked_x = x[masked_i]; masked_y = analytic[masked_i] plot.plot(masked_x, masked_y, linewidth = linewidth, linestyle = "--", c = "k", label = r"$\mathrm{Analytic}$") # Mark Planet if shift1 is None: planet_loc1 = theta[0] else: if shift1 < -len(theta): shift1 += len(theta) planet_loc1 = theta[shift1] * (180.0 / np.pi) if shift2 is None: planet_loc2 = theta[0] else: if shift2 < -len(theta): shift2 += len(theta) planet_loc2 = theta[shift2] * (180.0 / np.pi) #plot.scatter(planet_loc1, 0, c = "r", s = 150, marker = "D", zorder = 100) # planet #plot.scatter(planet_loc2, 0, c = "b", s = 150, marker = "D", zorder = 100) # planet # Axes min_x = 0; max_x = 360 plot.xlim(min_x, max_x) angles = np.linspace(min_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[frame_i - 1]) # 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.xlabel(r"$\phi$ $\mathrm{(degrees)}$", fontsize = fontsize + 2) if frame_i == 1: plot.ylabel(r"$\Sigma$ / $\Sigma_\mathrm{0,}$ $_\mathrm{dust}$", fontsize = fontsize) # Legend #if frame_i == 2: # plot.legend(loc = "upper right", bbox_to_anchor = (1.34, 0.94)) # outside of plot plot.legend(loc = "upper left") # Extra Annotation #rc_line1 = r"$r_\mathrm{c,\ T=10} = %.02f \ r_\mathrm{p}$" % azimuthal_radii1[(num_profiles - 1) / 2] #rc_line2 = r"$r_\mathrm{c,\ T=1000} = %.02f \ r_\mathrm{p}$" % azimuthal_radii2[(num_profiles - 1) / 2] #plot.text(-170, 0.90 * plot.ylim()[-1], rc_line1, fontsize = fontsize, horizontalalignment = 'left') #plot.text(-170, 0.80 * plot.ylim()[-1], rc_line2, fontsize = fontsize, horizontalalignment = 'left') if frame_i == 2: center_x = 1.34 * plot.xlim()[-1] top_y = plot.ylim()[-1] line1 = "Radii" #plot.text(center_x, 0.95 * top_y, line1, fontsize = fontsize, horizontalalignment = 'center') # Title #title = "\n" + r"$t$ $=$ $%.1f$ " % (orbit) + "[$m_p(t)$ $=$ $%.2f$ $M_J$]" % (current_mass) size_label = util.get_size_label(size) stokes_number = util.get_stokes_number(size) title = r"%s$\mathrm{-size}$ $\mathrm{(St}_\mathrm{0}$ $=$ $%.03f \mathrm{)}$" % (size_label, stokes_number) plot.title("%s" % (title), fontsize = fontsize + 1, y = 1.015)
def make_plot(frame, show=False): # Set up figure fig = plot.figure(figsize=(7, 6), dpi=dpi) ### Data ### for i, beam_i in enumerate(beams[::-1]): arc_beam_i = beam_i / distance label_i = r"$%.02f^{\prime\prime} (%2d \mathrm{\ AU})$" % (arc_beam_i, beam_i) intensity_polar = util.read_data(frame, 'polar_intensity', fargo_par, id_number=id_number, directory="../beam%03d" % beam_i) if normalize: intensity_polar /= np.max(intensity_polar) azimuthal_radius, azimuthal_profile = az.get_profiles(intensity_polar, fargo_par, args, shift=None) if normalize: azimuthal_profile /= np.max(azimuthal_profile) x = theta * (180.0 / np.pi) plot.plot(x, azimuthal_profile, linewidth=linewidths[i], c=colors[i], alpha=alphas[i], linestyle=linestyles[i], label=label_i) # Mark Planet (get shift first) if taper_time > 99.9: shift = az.get_lookup_shift(frame, directory="../../../cm-size") else: dust_density = util.read_data(frame, 'dust', fargo_par, directory="../../../cm-size") shift = az.get_azimuthal_peak(dust_density, fargo_par) if shift is None: planet_loc = theta[0] else: if shift < -len(theta): shift += len(theta) planet_loc = theta[shift] * (180.0 / np.pi) plot.scatter(planet_loc, 0, c="k", s=150, marker="D", zorder=100) # planet # Axes min_x = 0 max_x = 360 plot.xlim(min_x, max_x) angles = np.linspace(min_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$ $\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) # Legend #plot.legend(loc = "upper right", bbox_to_anchor = (1.38, 0.94)) # outside of plot if annotate: pass else: plot.legend(loc="upper left") # Extra Annotation (Location, Legend Label) center_x = 1.38 * plot.xlim()[-1] top_y = plot.ylim()[-1] line = r"$\mathrm{Beam\ Diameters}$" #plot.text(center_x, 0.95 * top_y, line, fontsize = fontsize - 1, horizontalalignment = 'center') # Annotate Peak Offsets # if False: # this_frame = np.searchsorted(frames, frame) # offset1 = offsets1[this_frame]; offset2 = offsets2[this_frame]; offset3 = offsets3[this_frame]; offset4 = offsets4[this_frame] # line4 = "b = 40: %.1f" % (offset4) # line3 = "b = 30: %.1f" % (offset3) # line2 = "b = 20: %.1f" % (offset2) # line1 = "b = 10: %.1f" % (offset1) # start_y = 0.08 * plot.ylim()[-1]; linebreak = 0.08 * plot.ylim()[-1] # plot.text(180, start_y + 3.0 * linebreak, line4, fontsize = fontsize, horizontalalignment = 'center') # plot.text(180, start_y + 2.0 * linebreak, line3, fontsize = fontsize, horizontalalignment = 'center') # plot.text(180, start_y + 1.0 * linebreak, line2, fontsize = fontsize, horizontalalignment = 'center') # plot.text(180, start_y + 0.0 * linebreak, line1, fontsize = fontsize, horizontalalignment = 'center') if annotate: this_frame = np.searchsorted(frames, frame - 0.1) offset0 = offsets1[this_frame - 3] offset1 = offsets1[this_frame - 2] offset2 = offsets1[this_frame - 1] offset3 = offsets1[this_frame] offset4 = offsets1[this_frame + 1] offset5 = offsets1[this_frame + 2] line5 = "t = %d: %.1f (%.1f)" % (frame + 2, offset5, offset5 - offset4) line4 = "t = %d: %.1f (%.1f)" % (frame + 1, offset4, offset4 - offset3) line3 = "t = %d: %.1f (%.1f)" % (frame - 0, offset3, offset3 - offset2) line2 = "t = %d: %.1f (%.1f)" % (frame - 1, offset2, offset2 - offset1) line1 = "t = %d: %.1f (%.1f)" % (frame - 2, offset1, offset1 - offset0) start_y = 0.08 * plot.ylim()[-1] linebreak = 0.08 * plot.ylim()[-1] plot.text(180, start_y + 4.0 * linebreak, line1, fontsize=fontsize, horizontalalignment='center') plot.text(180, start_y + 3.0 * linebreak, line2, fontsize=fontsize, horizontalalignment='center') plot.text(180, start_y + 2.0 * linebreak, line3, fontsize=fontsize, horizontalalignment='center') plot.text(180, start_y + 1.0 * linebreak, line4, fontsize=fontsize, horizontalalignment='center') plot.text(180, start_y + 0.0 * linebreak, line5, fontsize=fontsize, horizontalalignment='center') # Save, Show, and Close plot.tight_layout() png = "png" pdf = "pdf" if version is None: save_fn = "%s/azimuthalIntensityProfiles_%04d.%s" % (save_directory, frame, png) pdf_save_fn = "%s/azimuthalIntensityProfiles_%04d.%s" % ( save_directory, frame, pdf) else: save_fn = "%s/v%04d_azimuthalIntensityProfiles_%04d.%s" % ( save_directory, version, frame, png) pdf_save_fn = "%s/v%04d_azimuthalIntensityProfiles_%04d.%s" % ( save_directory, version, frame, pdf) plot.savefig(save_fn, bbox_inches='tight', dpi=dpi) plot.savefig(pdf_save_fn, bbox_inches='tight', format="pdf") 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 dust_fargo_par = util.get_pickled_parameters( directory="../../../cm-size") ## shorten name? ######## Need to extract parameters, and add 'rad' and 'theta' ######## dust_rad = np.linspace(dust_fargo_par['Rmin'], dust_fargo_par['Rmax'], dust_fargo_par['Nrad']) dust_theta = np.linspace(0, 2 * np.pi, dust_fargo_par['Nsec']) dust_fargo_par['rad'] = dust_rad dust_fargo_par['theta'] = dust_theta gas_surface_density_zero = dust_fargo_par['Sigma0'] dust_density = util.read_data(frame, 'dust', dust_fargo_par, id_number=id_number, directory="../../../cm-size") # Shift gas density with center of dust density shift = az.get_lookup_shift(frame, directory="../../../cm-size") # 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(dust_theta): shift += len(dust_theta) planet_theta = dust_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) # Keep 0 < theta < 2 * 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 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 * planet_size), 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, num_sizes, frame_i): # Declare Subplot #ax = plot.subplot(1, num_frames, frame_i, sharex = prev_ax, sharey = prev_ax, aspect = "equal") # 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 dust_fargo_par = util.get_pickled_parameters(directory = "../../../cm-size") ## shorten name? ######## Need to extract parameters, and add 'rad' and 'theta' ######## dust_rad = np.linspace(dust_fargo_par['Rmin'], dust_fargo_par['Rmax'], dust_fargo_par['Nrad']) dust_theta = np.linspace(0, 2 * np.pi, dust_fargo_par['Nsec']) dust_fargo_par['rad'] = dust_rad; dust_fargo_par['theta'] = dust_theta gas_surface_density_zero = dust_fargo_par['Sigma0'] dust_density = util.read_data(frame, 'dust', dust_fargo_par, id_number = id_number, directory = "../../../cm-size") # Shift gas density with peak or lookup shift if taper_time < 100: shift = az.get_azimuthal_peak(dust_density, fargo_par) else: shift = az.get_lookup_shift(frame, directory = "../../../cm-size") # 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((-2 * arc_weight, -2 * 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(dust_theta): shift += len(dust_theta) planet_theta = dust_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) # Keep 0 < theta < 2 * 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 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 * planet_size), marker = "D", zorder = 100) # planet # Annotate Axes if arc: unit = "^{\prime\prime}" else: unit = "r_\mathrm{p}" ax.set_xlabel(r"$x$ [$%s$]" % unit, fontsize = fontsize) if frame_i == 1: ax.set_ylabel(r"$y$ [$%s$]" % unit, fontsize = fontsize) # 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) # Label 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)) # Title title = r"$t$ $=$ $%.1f$ [$m_p(t)$ $=$ $%.2f$ $M_J$]" % (orbit, current_mass) plot.title("%s" % (title), y = 1.015, fontsize = fontsize + 1) # Title left_x = -1.2 * box_size; line_y = 1.24 * box_size; linebreak = 0.2 * box_size right_x = 1.2 * box_size if frame_i == 1: line1 = r'$M_p = %d$ $M_J$' % planet_mass plot.text(left_x, line_y + 0.2 * linebreak, line1, horizontalalignment = 'left', fontsize = fontsize + 2) elif frame_i == 2: line2 = r'$\nu = 10^{%d}$' % round(np.log(viscosity) / np.log(10), 0) plot.text(right_x, line_y + 0.2 * linebreak, line2, horizontalalignment = 'right', fontsize = fontsize + 2) # 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) if frame_i == 2: cbar.set_label("Normalized Intensity", fontsize = fontsize, rotation = 270, labelpad = 25) #if frame_i != num_frames: # fig.delaxes(cax) # to balance out frames that don't have colorbar with the one that does return ax