def make_plot(show = False): fig = plot.figure(figsize = (7, 5), dpi = dpi) ax = fig.add_subplot(111) # Plot x = frame_range y = np.array(extents) plot.plot(x, y, linewidth = linewidth) # Axes angles = np.linspace(0, 360, 7) plot.yticks(angles) plot.ylim(0, 360) # Annotate Axes plot.xlabel(r"$t \mathrm{\ (planet orbits)}$", fontsize = fontsize + 2) plot.ylabel(r"$\phi_\mathrm{extent}$ $\mathrm{(degrees)}$", fontsize = fontsize + 2) # Title size_label = util.get_size_label(size) title = r"Azimuthal Extents (%s)" % (size_label) plot.title("%s" % (title), fontsize = fontsize + 3) # Save, Show, and Close size_name = util.get_size_name(size) if version is None: save_fn = "%s/extentsBySize_%s.png" % (save_directory, size_name) else: save_fn = "%s/v%04d_extentsBySize_%s.png" % (save_directory, version, size_name) 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(show = False): # Set up figure fig = plot.figure(figsize = (7, 6), dpi = dpi) ax = fig.add_subplot(111) ### Line Plot ### reference = np.array(center_arrays["hcm"]) for i, size_name in enumerate(size_names): x = frame_range y = angle_difference(np.array(center_arrays[size_name]), reference) plot.plot(x, y, c = colors[i], linewidth = linewidth, label = util.get_size_label(sizes[i])) # Annotate Axes plot.xlabel("Time (planet orbits)", fontsize = fontsize) plot.ylabel(r"$\phi$", fontsize = fontsize) plot.title("Vortex Centers") plot.legend(loc = "upper right", bbox_to_anchor = (1.28, 1.0)) # outside of plot # Axes plot.xlim(frame_range[0], frame_range[-1]) if max_y is not None: plot.ylim(-max_y, max_y) # Save, Show, and Close save_fn = "vortexCenters.png" plot.savefig(save_fn, bbox_inches = 'tight') if show: plot.show() plot.close(fig) # Close Figure (to avoid too many figures)
def make_plot(show = False): # Set up figure fig = plot.figure(figsize = (12, 6), dpi = dpi) gs = gridspec.GridSpec(1, 2) frame_str = "" for i, frame_i in enumerate(frame_range): ax = fig.add_subplot(gs[i]) ax = add_to_plot(frame_i, fig, ax, len(frame_range), i + 1) frame_str += "%04d-" % frame_i frame_str = frame_str[:-1] # Trim last '_' #### Finish Plot #### size = 1.0 # cm-size only (in the future, make this a parameter?) size_label = util.get_size_label(size) stokes_number = util.get_stokes_number(size) title = r"$\mathrm{1\ cm-size}$ $\mathrm{(St}_\mathrm{0}$ $=$ $%.03f \mathrm{)}$" % (stokes_number) fig.suptitle(title, y = 0.97, verticalalignment = "bottom", bbox = dict(facecolor = 'none', edgecolor = 'black', linewidth = 1.5, pad = 7.0), fontsize = fontsize + 4) # Save and Close plot.tight_layout() # Save, Show, and Close if version is None: save_fn = "%s/densityMapEvolution_%s.png" % (save_directory, frame_str) else: save_fn = "%s/v%04d_densityMapEvolution_%s.png" % (save_directory, version, frame_str) 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(show=False): # Set up figure fig = plot.figure(figsize=(7, 6), dpi=dpi) frame_str = "" sizes = ["cm", "mm"] # <<<====== Make this a parameter for i, (size_i, frame_i) in enumerate(zip(sizes, frame_range)): add_to_plot(frame_i, fig, size_i, len(frame_range), i) frame_str += "%04d-" % frame_i frame_str = frame_str[:-1] # Trim last '_' #### Finish Plot #### size = 1.0 # cm-size only (in the future, make this a parameter?) size_label = util.get_size_label(size) stokes_number = util.get_stokes_number(size) #title = r"$\mathrm{1\ cm-size}$ $\mathrm{(St}_\mathrm{0}$ $=$ $%.03f \mathrm{)}$" % (stokes_number) #fig.suptitle(title, y = 0.97, verticalalignment = "bottom", bbox = dict(facecolor = 'none', edgecolor = 'black', linewidth = 1.5, pad = 7.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/azimuthalDensityOnePanelComparison_%s.%s" % ( save_directory, frame_str, png) pdf_save_fn = "%s/azimuthalDensityOnePanelComparison_%s.%s" % ( save_directory, frame_str, pdf) else: save_fn = "%s/v%04d_azimuthalDensityOnePanelComparison_%s.%s" % ( save_directory, version, frame_str, png) save_fn = "%s/v%04d_azimuthalDensityOnePanelComparison_%s.%s" % ( save_directory, version, frame_str, 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)
r_min = fargo_par["Rmin"] r_max = fargo_par["Rmax"] jupiter_mass = 1e-3 planet_mass = fargo_par["PlanetMass"] / jupiter_mass surface_density_zero = fargo_par["Sigma0"] / 100 disk_mass = 2 * np.pi * surface_density_zero * ( r_max - r_min ) / jupiter_mass # M_{disk} = (2 \pi) * \Sigma_0 * r_p * (r_out - r_in) scale_height = fargo_par["AspectRatio"] viscosity = fargo_par["Viscosity"] taper = fargo_par["MassTaper"] size = fargo_par["PSIZE"] size_label = util.get_size_label(size) ### Get Input Parameters ### # Frames frame_range = util.get_frame_range(args.frames) # Number of Cores num_cores = args.num_cores # Files save_directory = args.save_directory if not os.path.isdir(save_directory): os.mkdir( save_directory) # make save directory if it does not already exist
def add_to_plot(i, grain): # Identify Subplot number = i + 1 ax = plot.subplot(3, 1, number) # Data if merge > 0: num_merged_cores = merge gas_density = util.read_merged_data(frame, num_merged_cores, num_rad, num_theta) if i > 0: density = util.read_merged_data(frame, num_merged_cores, num_rad, num_theta, fluid='dust%d' % i) elif mpi: field = "dens" gas_density = Fields("./", 'gas', frame).get_field(field).reshape( num_rad, num_theta) if i > 0: density = Fields("./", 'dust%d' % i, frame).get_field(field).reshape( num_rad, num_theta) else: gas_density = fromfile("gasdens%d.dat" % frame).reshape( num_rad, num_theta) if i > 0: density = fromfile("dust%ddens%d.dat" % (i, frame)).reshape( num_rad, num_theta) normalized_gas_density = gas_density / surface_density_zero if i > 0: normalized_density = density / dust_surface_density_zero if center: if i > 0: 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 = theta * (180.0 / np.pi) y = rad if i == 0: cmap = 'viridis' result = ax.pcolormesh(x, y, normalized_gas_density, cmap=cmap) cbar = fig.colorbar(result) result.set_clim(0, cmaxGas) else: cmap = args.cmap result = ax.pcolormesh(x, y, normalized_density, cmap=cmap) cbar = fig.colorbar(result) result.set_clim(0, cmax[i - 1]) if number == 1: cbar.set_label(r"$\Sigma$ / $\Sigma_\mathrm{0,}$ $_\mathrm{gas}$", fontsize=fontsize, rotation=270, labelpad=25) elif number == 3: cbar.set_label(r"$\Sigma$ / $\Sigma_\mathrm{0,}$ $_\mathrm{dust}$", fontsize=fontsize, rotation=270, labelpad=25) if use_contours and i > 0: levels = np.linspace(low_contour, high_contour, num_levels) colors = generate_colors(num_levels) plot.contour(x, y, normalized_gas_density, levels=levels, origin='upper', linewidths=1, colors=colors) # Axes plot.xlim(0, 360) plot.ylim(y_min, y_max) angles = np.linspace(0, 360, 7) plot.xticks(angles) 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=6) # 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] if number == 3: plot.xlabel(r"$\phi$ $\mathrm{(degrees)}$", fontsize=fontsize) if number == 1 or number == 3: plot.ylabel(r"Radius [$r_\mathrm{p}$]", fontsize=fontsize) if number == 1: plot.title( r"$t = %d$ $\mathrm{orbits}}$ [$m_\mathrm{p}(t)\ =\ %.2f$ $M_\mathrm{J}$]" % (orbit, current_mass), bbox=dict(facecolor='w', edgecolor='k', pad=10.0), y=1.08, fontsize=fontsize + 1) # Label left_x = plot.xlim()[0] right_x = plot.xlim()[-1] range_x = right_x - left_x margin_x = 0.05 * range_x bottom_y = plot.ylim()[0] top_y = plot.ylim()[-1] range_y = top_y - bottom_y margin_y = 0.15 * range_y if number == 1: # Gas title = r"$\mathrm{Gas\ Density}$" #plot.text(left_x + margin_x, top_y - margin_y, title, fontsize = fontsize, color = 'black', horizontalalignment = 'left', bbox=dict(facecolor = 'white', edgecolor = 'black', pad = 10.0)) else: # Dust this_size = util.get_size(grain) size_label = util.get_size_label(this_size) stokes_number = util.get_stokes_number(this_size) title = r"%s$\mathrm{-size}$" % size_label stokes = r"$\mathrm{St}_\mathrm{0}$ $=$ $%.03f$" % stokes_number #plot.text(left_x + margin_x, top_y - margin_y, title, fontsize = fontsize, color = 'white', horizontalalignment = 'left', bbox=dict(facecolor = 'black', edgecolor = 'white', pad = 10.0)) #plot.text(right_x - margin_x, top_y - margin_y, stokes, fontsize = fontsize, color = 'white', horizontalalignment = 'right', bbox=dict(facecolor = 'black', edgecolor = 'white', pad = 10.0)) # Text line_y = top_y + 0.31 * range_y linebreak = 0.16 * range_y left_start_x = left_x - 3.0 * margin_x right_end_x = right_x + 4.0 * margin_x if number == 1: line1 = r'$M_p = %d$ $M_J$' % planet_mass line2 = r'$\nu = 10^{%d}$' % round( np.log(viscosity) / np.log(10), 0) plot.text(left_start_x, line_y + linebreak, line1, horizontalalignment='left', fontsize=fontsize + 1) plot.text(left_start_x, line_y, line2, horizontalalignment='left', fontsize=fontsize + 1) line3 = r'$T_\mathrm{growth} = %d$ $\rm{orbits}$' % taper_time line4 = r"$N_\mathrm{r} \times \ N_\mathrm{\phi} = %d \times \ %d$" % ( num_rad, num_theta) plot.text(right_end_x, line_y + linebreak, line3, horizontalalignment='right', fontsize=fontsize + 1) plot.text(right_end_x, line_y, line4, horizontalalignment='right', fontsize=fontsize + 1)
def add_to_plot(frame, fig, ax, size_name, num_sizes, frame_i): # Convert size to number size = util.get_size(size_name) # Declare Subplot #ax = plot.subplot(1, num_frames, frame_i, sharex = prev_ax, sharey = prev_ax, aspect = "equal") # Data this_fargo_par = fargo_par.copy() this_fargo_par["PSIZE"] = size if size_name == "um": # Gas case is separate! density = util.read_data(frame, 'dust', fargo_par, directory = "../cm-size") gas_density = util.read_data(frame, 'gas', fargo_par, directory = "../cm-size") else: density = util.read_data(frame, 'dust', this_fargo_par, directory = "../%s-size" % size_name) if center: if taper_time < 10.1: shift = az.get_azimuthal_peak(density, fargo_par) else: if size_name == "um": threshold = util.get_threshold(1.0) # get cm-size threshold instead else: threshold = util.get_threshold(size) shift = az.get_azimuthal_center(density, fargo_par, threshold = threshold * surface_density_zero) # Shift! (Handle gas case separately) if size_name == "um": density = np.roll(gas_density, shift) / 100.0 else: density = np.roll(density, shift) normalized_density = density / surface_density_zero # Convert gas density to cartesian _, _, xs_grid, ys_grid, normalized_density = sq.polar_to_cartesian(normalized_density, rad, theta) ### Plot ### if size_name == "um": colormap = "viridis" else: colormap = cmap result = plot.pcolormesh(xs_grid, ys_grid, np.transpose(normalized_density), cmap = colormap) if size_name == "um": result.set_clim(0, 1.5) else: result.set_clim(clim[0], clim[1]) # Get rid of interior circle = plot.Circle((0, 0), min(rad), color = "black") ax.add_artist(circle) # Add planet orbit planet_orbit = plot.Circle((0, 0), 1, 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) # 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, planet_y, c = "white", s = int(70 * planet_size), marker = "D", zorder = 100) # planet # Annotate Axes if frame_i > 2: ax.set_xlabel(r"$x$ [$r_\mathrm{p}$]", fontsize = fontsize) if frame_i % 2 == 1: ax.set_ylabel(r"$y$ [$r_\mathrm{p}$]", fontsize = fontsize) # Axes box_size = 2.5 ax.set_xlim(-box_size, box_size) ax.set_ylim(-box_size, box_size) ax.set_aspect('equal') if frame_i > 1: 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 size_label = util.get_size_label(size) stokes_number = util.get_stokes_number(size) title = r"%s$\mathrm{-size}$" % size_label stokes = r"$\mathrm{St}_\mathrm{0}$ $=$ $%.03f$" % stokes_number if size_name == "um": title = r"$\mathrm{Gas\ Density}$" plot.text(-0.9 * box_size, 2, title, fontsize = fontsize, color = 'black', horizontalalignment = 'left', bbox=dict(facecolor = 'white', edgecolor = 'black', pad = 10.0)) else: plot.text(-0.9 * box_size, 2, title, fontsize = fontsize, color = 'white', horizontalalignment = 'left', bbox=dict(facecolor = 'black', edgecolor = 'white', pad = 10.0)) plot.text(0.9 * box_size, 2, stokes, fontsize = fontsize, color = 'white', horizontalalignment = 'right') #ax.set_title(title) frame_title = r"$t$ $=$ $%.1f$ [$m_p(t)$ $=$ $%.2f$ $M_J$]" % (orbit, current_mass) # Title left_x = -0.8 * box_size; line_y = 1.1 * box_size; linebreak = 0.2 * box_size right_x = 1.3 * box_size if frame_i == 1: line1 = r'$M_p = %d$ $M_J$' % planet_mass line2 = r'$\nu = 10^{%d}$' % round(np.log(viscosity) / np.log(10), 0) plot.text(left_x, line_y + linebreak, line1, horizontalalignment = 'left', fontsize = fontsize + 2) plot.text(left_x, line_y, line2, horizontalalignment = 'left', fontsize = fontsize + 2) if orbit < taper_time: # Add this white line to keep supertitle in the save frame plot.text(left_x, line_y + 2.0 * linebreak, line1, color = "white", horizontalalignment = 'left', fontsize = fontsize + 2) elif frame_i == 2 : line3 = r'$T_\mathrm{growth} = %d$ $\rm{orbits}$' % taper_time plot.text(right_x, line_y + 0.5 * linebreak, line3, horizontalalignment = 'right', fontsize = fontsize + 2) #if frame_i != 1: # # Remove unless 1st frame # ax.set_yticklabels([]) # 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 == 1: cbar.set_label(r"$\Sigma$ / $\Sigma_\mathrm{0,}$ $_\mathrm{gas}$", fontsize = fontsize, rotation = 270, labelpad = 25) else: cbar.set_label(r"$\Sigma$ / $\Sigma_\mathrm{0,}$ $_\mathrm{dust}$", 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
def make_plot(show=False): fig = plot.figure(figsize=(7, 6), dpi=dpi) ax = fig.add_subplot(111) # Plot for i, size in enumerate(sizes): size_label = util.get_size_label(size) x = frame_range y = np.array(extents[i]) kernel = 5 smooth_y = util.smooth(y, kernel) plot.plot(x, y, c=colors[i], linewidth=linewidth, alpha=alpha) plot.plot(x, smooth_y, c=colors[i], linewidth=linewidth, label=size_label) # Comparisons if compare: comparisons = comparison_dictionary[threshold] for i, extent_i in enumerate(comparisons[::-1]): plot.scatter(x[0], extent_i, c=colors[i], s=100, marker="H", zorder=5) # Left Marker plot.scatter(x[-1], extent_i, c=colors[i], s=100, marker="H", zorder=99, clip_on=False) # Right Marker plot.plot([x[0], x[-1]], [extent_i, extent_i], linestyle="--", c=colors[i], zorder=2) # Dashed line ine # Axes plot.xlim(x[0], x[-1]) angles = np.linspace(0, 360, 7) plot.yticks(angles) plot.ylim(0, 360) # Annotate Axes plot.xlabel(r"$t \mathrm{\ (planet\ orbits)}$", fontsize=fontsize + 2) plot.ylabel(r"$\Delta \phi$ $\mathrm{(degrees)}$", fontsize=fontsize + 2) #plot.legend(loc = "upper right", bbox_to_anchor = (1.28, 1.0)) # outside of plot plot.legend(loc="upper left") # outside of plot # Title title = r"$\mathrm{Azimuthal\ Extents}$" plot.title("%s" % (title), y=1.01, fontsize=fontsize + 3) # Save, Show, and Close if version is None: save_fn = "%s/extentsBySize.png" % (save_directory) else: save_fn = "%s/v%04d_extentsBySize.png" % (save_directory, version) 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(i, grain): # Grain Size this_size = util.get_size(grain) # Identify Subplot number = i + 1 ax = plot.subplot(3, 1, number) # Parameters this_fargo_par = fargo_par.copy() this_fargo_par["PSIZE"] = this_size ### Data ### gas_density = (fromfile( "../%s-size/gasdens%d.dat" % (grain, frame)).reshape( num_rad, num_theta)) / (100.0 * surface_density_zero) dust_density = (fromfile("../%s-size/gasddens%d.dat" % (grain, frame)).reshape(num_rad, num_theta)) normalized_density = dust_density / (surface_density_zero) # Store cm dust if number == 1: cm_dust_density = dust_density # Shift if center is "off": shift_c = 0 elif center.startswith("cm"): normalized_density, shift_c = shift_density( normalized_density, this_fargo_par, option=center[3:], reference_density=cm_dust_density, frame=frame, grain=grain) else: normalized_density, shift_c = shift_density(normalized_density, this_fargo_par, option=center, frame=frame, grain=grain) gas_density = np.roll(gas_density, shift_c) ### Plot ### x = theta * (180.0 / np.pi) y = rad if number == 1: result = plot.pcolormesh(x, y, gas_density, cmap="viridis") else: result = plot.pcolormesh(x, y, normalized_density, cmap=cmap) cbar = fig.colorbar(result) if number == 1: result.set_clim(0, cmaxGas) else: result.set_clim(0, cmax[i - 1]) if number == 1: cbar.set_label(r"$\Sigma$ / $\Sigma_\mathrm{0,}$ $_\mathrm{gas}$", fontsize=fontsize, rotation=270, labelpad=25) elif number == 3: cbar.set_label(r"$\Sigma$ / $\Sigma_\mathrm{0,}$ $_\mathrm{dust}$", fontsize=fontsize, rotation=270, labelpad=25) if use_contours and number > 1: levels = np.linspace(low_contour, high_contour, num_levels) colors = generate_colors(num_levels) plot.contour(x, y, gas_density, levels=levels, origin='upper', linewidths=1, colors=colors) # Axes plot.xlim(0, 360) plot.ylim(y_min, y_max) angles = np.linspace(0, 360, 7) plot.xticks(angles) 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=6) # Annotate Axes time = fargo_par["Ninterm"] * fargo_par["DT"] orbit = (time / (2 * np.pi)) * frame if orbit >= taper: current_mass = planet_mass else: current_mass = np.power( np.sin((np.pi / 2) * (1.0 * orbit / taper)), 2) * planet_mass if number == 3: plot.xlabel(r"$\phi$ $\mathrm{(degrees)}$", fontsize=fontsize) if number == 1 or number == 3: plot.ylabel(r"Radius [$r_\mathrm{p}$]", fontsize=fontsize) if number == 1: plot.title( r"$t = %d$ $\mathrm{orbits}}$ [$m_\mathrm{p}(t)\ =\ %.2f$ $M_\mathrm{J}$]" % (orbit, current_mass), bbox=dict(facecolor='w', edgecolor='k', pad=10.0), y=1.08, fontsize=fontsize + 2) # Label left_x = plot.xlim()[0] right_x = plot.xlim()[-1] range_x = right_x - left_x margin_x = 0.05 * range_x bottom_y = plot.ylim()[0] top_y = plot.ylim()[-1] range_y = top_y - bottom_y margin_y = 0.15 * range_y if number == 1: # Gas title = r"$\mathrm{Gas\ Density}$" plot.text(left_x + margin_x, top_y - margin_y, title, fontsize=fontsize, color='black', horizontalalignment='left', bbox=dict(facecolor='white', edgecolor='black', pad=10.0)) else: # Dust size_label = util.get_size_label(this_size) stokes_number = util.get_stokes_number(this_size) title = r"%s$\mathrm{-size}$" % size_label stokes = r"$\mathrm{St}_\mathrm{0}$ $=$ $%.03f$" % stokes_number plot.text(left_x + margin_x, top_y - margin_y, title, fontsize=fontsize, color='white', horizontalalignment='left', bbox=dict(facecolor='black', edgecolor='white', pad=10.0)) plot.text(right_x - margin_x, top_y - margin_y, stokes, fontsize=fontsize, color='white', horizontalalignment='right', bbox=dict(facecolor='black', edgecolor='white', pad=10.0)) # Text line_y = top_y + 0.31 * range_y linebreak = 0.16 * range_y left_start_x = left_x - 3.0 * margin_x right_end_x = right_x + 4.0 * margin_x if number == 1: line1 = r'$M_p = %d$ $M_J$' % planet_mass line2 = r'$\nu = 10^{%d}$' % round( np.log(viscosity) / np.log(10), 0) plot.text(left_start_x, line_y + linebreak, line1, horizontalalignment='left', fontsize=fontsize + 1) plot.text(left_start_x, line_y, line2, horizontalalignment='left', fontsize=fontsize + 1) line3 = r'$T_\mathrm{growth} = %d$ $\rm{orbits}$' % taper line4 = r"$N_\mathrm{r} \times \ N_\mathrm{\phi} = %d \times \ %d$" % ( num_rad, num_theta) plot.text(right_end_x, line_y + linebreak, line3, horizontalalignment='right', fontsize=fontsize + 1) plot.text(right_end_x, line_y, line4, horizontalalignment='right', fontsize=fontsize + 1)
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 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)
def make_plot(frame, shift, azimuthal_radii, azimuthal_profiles, show=False): # Set up figure fig = plot.figure(figsize=(7, 6), dpi=dpi) ax = fig.add_subplot(111) ### Plot ### 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="%.3f" % radius) # 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") # planet # Axes plot.xlim(-180, 180) angles = np.linspace(-180, 180, 7) plot.xticks(angles) if max_y is not None: plot.ylim(0, max_y) else: plot.ylim(0, plot.ylim()[-1]) # Annotate Axes time = fargo_par["Ninterm"] * fargo_par["DT"] orbit = (time / (2 * np.pi)) * frame plot.xlabel(r"$\phi - \phi_\mathrm{center}$ $\mathrm{(degrees)}$", fontsize=fontsize + 2) #plot.ylabel("Azimuthal Dust Density", fontsize = fontsize) plot.ylabel(r"$\Sigma$ / $\Sigma_\mathrm{0,}$ $_\mathrm{dust}$", fontsize=fontsize) 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) #title = r"(t = %.1f orbits)" % (orbit) plot.title("%s" % (title), y=1.01, fontsize=fontsize + 1) # Annotate Parameters line_x = -165.0 line_y = 0.91 linebreak = 0.07 center_x = 1.30 * plot.xlim()[-1] top_y = plot.ylim()[-1] #left1 = r"$M_p = %d$ $M_{Jup}$" % (planet_mass) #left2 = r"$\nu = 10^{%d}$" % (np.log10(viscosity)) #plot.text(line_x, line_y * plot.ylim()[-1], left1, horizontalalignment = 'left', fontsize = fontsize) #plot.text(line_x, (line_y - linebreak) * plot.ylim()[-1], left2, horizontalalignment = 'left', fontsize = fontsize) #right1 = r"$T_{growth} = %d$ $\rm{orbits}$" % (taper) #right2 = r"$s$ = %s" % (size_label) #plot.text(360 - line_x, line_y * plot.ylim()[-1], right1, horizontalalignment = 'right', fontsize = fontsize) #plot.text(360 - line_x, (line_y - linebreak) * plot.ylim()[-1], right2, horizontalalignment = 'right', fontsize = fontsize) left1 = r"$t = %.1f$" % (orbit) plot.text(line_x, line_y * plot.ylim()[-1], left1, horizontalalignment='left', fontsize=fontsize) plot.text(center_x, 0.95 * top_y, "Radii", fontsize=fontsize - 1, horizontalalignment='center') plot.legend(loc="upper right", bbox_to_anchor=(1.28, 0.94)) # outside of plot # Save, Show, and Close if version is None: save_fn = "%s/azimuthalDensityProfiles_%04d.png" % (save_directory, frame) else: save_fn = "%s/v%04d_azimuthalDensityProfiles_%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)