def make_plot(frame, show = False): # Set up figure fig = plot.figure(figsize = (12, 10), dpi = dpi) gs = gridspec.GridSpec(2, 2) size_str = "" for i, size_i in enumerate(sizes): ax = fig.add_subplot(gs[i]) ax = add_to_plot(frame, fig, ax, size_i, len(frame_range), i + 1) size_str += "size_i_" size_str = size_str[:-1] # Trim last '_' #### Finish Plot #### # Title 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) if orbit >= taper_time: frame_title = r"$t$ $=$ $%.1f$" % (orbit) fig.suptitle(frame_title, y = 1.0, verticalalignment = "bottom", bbox = dict(facecolor = 'none', edgecolor = 'black', linewidth = 1.5, pad = 7.0), fontsize = fontsize + 4) else: frame_title = "\n" + r"$t$ $=$ $%.1f$" % (orbit) + "\n" + "[$m_p(t)$ $=$ $%.2f$ $M_J$]" % (current_mass) fig.suptitle(frame_title, y = 1.0, verticalalignment = "bottom", bbox = dict(facecolor = 'none', edgecolor = 'black', linewidth = 1.5, pad = 20.0), fontsize = fontsize + 4) # Save and Close plot.tight_layout() # Save, Show, and Close png = "png"; pdf = "pdf" if version is None: save_fn = "%s/densityMap_%04d.%s" % (save_directory, frame, png) pdf_save_fn = "%s/densityMap_%04d.%s" % (save_directory, frame, pdf) else: save_fn = "%s/v%04d_densityMap_%04d.%s" % (save_directory, version, frame, png) pdf_save_fn = "%s/v%04d_densityMap_%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") # pdf will not work 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_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 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 ### 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, num_frames, frame_i): # Convert size to number size_name = "cm" size = util.get_size(size_name) # Taper if frame_i == 1: taper_time = 10 else: taper_time = 1000 ### Data ### middle_profiles = [ get_middle_profile(directory_i) for directory_i in directories ] # # 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_azimuthal_center(dust_density, dust_fargo_par, threshold = 10.0 * gas_surface_density_zero / 100.0) ### 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 # if shift is None: # planet_loc = theta[0] # else: # if shift < -len(dust_theta): # shift += len(dust_theta) # planet_loc = dust_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 = 180 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) if frame_i == 1: plot.ylabel(r"$I$ / $I_\mathrm{max}$", fontsize=fontsize) # Legend if frame_i == 2: plot.legend(loc="upper right", bbox_to_anchor=(1.34, 0.94)) # outside of plot # Extra Annotation 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') if frame_i == 2: 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') # Label #taper_title = r"$T_\mathrm{growth} = %d$" % taper_time #plot.text(0.95 * plot.xlim()[-1], 0.885 * plot.ylim()[-1], taper_title, fontsize = fontsize, color = 'black', horizontalalignment = 'right', bbox=dict(facecolor = 'white', edgecolor = 'black', pad = 10.0)) # Title #title = "\n" + r"$t$ $=$ $%.1f$ " % (orbit) + "[$m_p(t)$ $=$ $%.2f$ $M_J$]" % (current_mass) #plot.title("%s" % (title), fontsize = fontsize + 1) # Return to previous directory os.chdir(cwd)
def add_to_plot(frame, fig, ax, num_frames, frame_i): # Convert size to number size_name = "cm" size = util.get_size(size_name) ### Data ### density = util.read_data( frame, 'dust', fargo_par, directory="../%s-size" % size_name) / surface_density_zero # Choose shift option if center: # Center vortex if fargo_par["MassTaper"] < 10.1: shift = az.get_azimuthal_peak(density, fargo_par) else: threshold = util.get_threshold(size) shift = az.get_azimuthal_center(density, fargo_par, threshold=threshold) else: shift = None azimuthal_radii, azimuthal_profiles = az.get_profiles(density, fargo_par, args, shift=shift) ### 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], alpha=alpha, label=labels[i]) # Analytic middle_i = (num_profiles - 1) / 2 radius = azimuthal_radii[middle_i] # middle #center_density = azimuthal_profiles[middle_i][(len(azimuthal_profiles[middle_i]) - 1) / 2] max_density = np.max(azimuthal_profiles[middle_i]) 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 ]) analytic = analytic / np.max( analytic) * max_density # Normalize and re-scale to max density # Mask outside vortex and plot masked_i = np.abs(x) <= (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") # Mark 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 # 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[frame_i - 1]) # Input if frame_i <= 2: # Remove unless bottom ax.set_xticklabels([]) # 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) if frame_i > 2: plot.xlabel(r"$\phi - \phi_\mathrm{center}$ $\mathrm{(degrees)}$", fontsize=fontsize + 2) if frame_i % 2 == 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 # Extra Annotation rc_line = r"$r_\mathrm{c} = %.02f$" % azimuthal_radii[(num_profiles - 1) / 2] plot.text(-170, 0.85 * plot.ylim()[-1], rc_line, fontsize=fontsize, horizontalalignment='left') if frame_i % 2 == 0: center_x = 1.38 * plot.xlim()[-1] top_y = plot.ylim()[-1] if frame_i == 2: line = "Radii" elif frame_i == 4: line = "Analytic" plot.text(center_x, 0.95 * top_y, line, fontsize=fontsize, horizontalalignment='center') plot.text(center_x, 0.95 * top_y, line, fontsize=fontsize, horizontalalignment='center') if frame_i == 4: half_width = 0.12 * plot.xlim()[-1] analytic_legend_y0 = 0.85 * top_y analytic_legend_x = [ 1.005 * center_x - half_width, 1.005 * center_x + half_width ] analytic_legend_y = [analytic_legend_y0, analytic_legend_y0] plot.plot(analytic_legend_x, analytic_legend_y, linewidth=linewidth, c='k', linestyle="--", clip_on=False) # Title title = "\n" + r"$t$ $=$ $%.1f$ " % ( orbit) + "[$m_p(t)$ $=$ $%.2f$ $M_J$]" % (current_mass) plot.title("%s" % (title), fontsize=fontsize + 1)
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 add_to_plot(frame, fig, ax, num_frames, frame_i): # Convert size to number size_name = "cm" size = util.get_size(size_name) ### 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) # 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_azimuthal_center(dust_density, dust_fargo_par, threshold=10.0 * gas_surface_density_zero / 100.0) ### 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], alpha=alpha, label=labels[i]) # Mark Planet if shift is None: planet_loc = theta[0] else: if shift < -len(dust_theta): shift += len(dust_theta) planet_loc = dust_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 if frame_i <= 2: # Remove unless bottom ax.set_xticklabels([]) # 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) if frame_i > 2: plot.xlabel(r"$\phi - \phi_\mathrm{center}$ $\mathrm{(degrees)}$", fontsize=fontsize + 2) if frame_i % 2 == 1: plot.ylabel(r"$I$ / $I_\mathrm{0}$", fontsize=fontsize) # Legend if frame_i == 2: plot.legend(loc="upper right", bbox_to_anchor=(1.34, 0.94)) # outside of plot # Extra Annotation rc_line = r"$r_\mathrm{c} = %.02f$" % azimuthal_radii[(num_profiles - 1) / 2] plot.text(-170, 0.85 * plot.ylim()[-1], rc_line, fontsize=fontsize, horizontalalignment='left') if frame_i == 2: 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, horizontalalignment='center') plot.text(center_x, 0.95 * top_y, 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)
def add_to_plot(frame, fig, 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="../taper1000/%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_azimuthal_center(density2, fargo_par, threshold=threshold) 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) - 180.0 middle_i = (num_profiles - 1) / 2 middle_profile1 = azimuthal_profiles1[middle_i] plot.plot(x, middle_profile1, linewidth=linewidth, dashes=dashes[frame_i], c=colors[0], alpha=alpha, label=labels[frame_i]) # Add a break in the legend plot.plot([0.1, 0.1], [0.2, 0.2], c='white', label="\t") middle_profile2 = azimuthal_profiles2[middle_i] plot.plot(x, middle_profile2, linewidth=linewidth, dashes=dashes[frame_i], c=colors[1], alpha=1.0, label=labels[frame_i]) # 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) - 180.0 if shift2 is None: planet_loc2 = theta[0] else: if shift2 < -len(theta): shift2 += len(theta) planet_loc2 = theta[shift2] * (180.0 / np.pi) - 180.0 #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 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) 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 # 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)