def center_vortex(density, frame, reference_density=None): """ Step 2: center the vortex so that the peak is at 180 degrees """ if taper_time < 1.1: for i, size in enumerate(sizes): shift_i = az.get_azimuthal_peak(density[:, :, i], fargo_par) density[:, :, i] = np.roll(density[:, :, i], shift_i, axis=1) return density elif taper_time > 1.1: for i, size_name in enumerate(size_names): if center == "lookup": pass #shift_i = az.get_lookup_shift(frame, directory = "../%s-size" % size_name) elif center == "threshold": threshold = util.get_threshold(size) * surface_density_zero shift_i = az.get_azimuthal_center(density[:, :, i], fargo_par, threshold=threshold) elif center == "away": shift_i = az.shift_away_from_minimum(reference_density, fargo_par) else: print "invalid centering option" density[:, :, i] = np.roll(density[:, :, i], shift_i, axis=1) return density
def 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 _extract_tree(self, X, y, depth=0): if (self.max_depth is None or depth > self.max_depth) and len(np.unique(y)) > 1: # Extract 1 shapelet, using the specified `extractor` map_dict = {} for j, c in enumerate(np.unique(y)): map_dict[c] = j y_mapped = np.vectorize(map_dict.get)(y) shapelet = self.extractor.extract( X, y_mapped, min_len=self.min_len, max_len=self.max_len, nr_shapelets=1, metric=self.metric )[0] # Get the best threshold distance for this shapelet L = [] X_left, y_left, X_right, y_right = [], [], [], [] for k in range(len(X)): D = X[k, :] dist = util.sdist(shapelet, D) L.append((dist, y[k])) threshold = util.get_threshold(L) # Create a new internal node node = ShapeletTree(right=None, left=None, shapelet=shapelet, threshold=threshold, class_probabilities=self._calc_probs(y)) # Partition the data X_left, y_left, X_right, y_right = [], [], [], [] for ts, label in zip(X, y): if util.sdist(shapelet, ts) <= threshold: X_left.append(ts) y_left.append(label) else: X_right.append(ts) y_right.append(label) X_left = np.array(X_left) y_left = np.array(y_left) X_right = np.array(X_right) y_right = np.array(y_right) # Recursive call to create the left and right child of the internal node if len(X_left) >= self.min_samples_split: node.left = self._extract_tree(X_left, y_left, depth=depth+1) else: node.left = ShapeletTree(right=None, left=None, shapelet=None, threshold=None, class_probabilities=self._calc_probs(y_left)) if len(X_right) >= self.min_samples_split: node.right = self._extract_tree(X_right, y_right, depth=depth+1) else: node.right = ShapeletTree(right=None, left=None, shapelet=None, threshold=None, class_probabilities=self._calc_probs(y_right)) return node else: return ShapeletTree(right=None, left=None, shapelet=None, threshold=None, class_probabilities=self._calc_probs(y))
def get_center(density, fargo_par, size): """ return theta for vortex center (in degrees) """ ######## Get Parameters ######### theta = fargo_par["theta"] ########### Method ############## threshold = util.get_threshold(size) shift_c = az.get_azimuthal_center(density, fargo_par, threshold = threshold) theta_c = theta[shift_c] * (180.0 / np.pi) return theta_c
def make_plot(frame, show=False): # Set up figure fig = plot.figure(figsize=(7, 6), dpi=dpi) ax = fig.add_subplot(111) # 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: threshold = util.get_threshold(size) shift_c = az.get_azimuthal_center(dust_density, fargo_par, threshold=threshold * surface_density_zero / 100.0) 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) 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 plot.xlim(x_min, x_max) plot.ylim(0, 360) angles = np.linspace(0, 360, 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) plot.ylabel(r"$\phi$", fontsize=fontsize) #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{Jup}$]" % ( orbit, current_mass) plot.title("%s" % (title2), y=1.015, fontsize=fontsize + 1) plot.text(x_mid, y_text * plot.ylim()[-1], 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{Jup}$" % (int(planet_mass)) text_visc = r"$\alpha_\mathrm{disk} = 3 \times 10^{%d}$" % ( int(np.log(viscosity) / np.log(10)) + 2) #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)) plot.text(-0.84 * x_range / 2.0 + x_mid, y_text * plot.ylim()[-1], text_mass, fontsize=fontsize, color='black', horizontalalignment='right') plot.text(0.84 * x_range / 2.0 + x_mid, y_text * plot.ylim()[-1], text_visc, fontsize=fontsize, color='black', horizontalalignment='left') # Label colorbar 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=25) # Save, Show, and Close if version is None: save_fn = "%s/vorticityMap_%04d.png" % (save_directory, frame) else: save_fn = "%s/v%04d_vorticityMap_%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)
save_directory) # make save directory if it does not already exist # Plot Parameters (variable) show = args.show max_y = args.max_y num_scale_heights = args.num_scale_heights rad = np.linspace(r_min, r_max, num_rad) theta = np.linspace(0, 2 * np.pi, num_theta) version = args.version center = args.center threshold = args.threshold if threshold is None: threshold = util.get_threshold(size) # Plot Parameters (constant) fontsize = args.fontsize labelsize = args.labelsize linewidth = args.linewidth alpha = args.alpha dpi = args.dpi rc['xtick.labelsize'] = labelsize rc['ytick.labelsize'] = labelsize ############################################################################### ### Add new parameters to dictionary ### fargo_par["rad"] = rad
def make_plot(frame, show=False): # Set up figure fig = plot.figure(figsize=(7, 6), dpi=dpi) ax = fig.add_subplot(111) # Data gas_density = (fromfile("gasdens%d.dat" % frame).reshape( num_rad, num_theta)) dust_density = (fromfile("gasddens%d.dat" % frame).reshape( num_rad, num_theta)) radial_velocity = (fromfile("gasdvrad%d.dat" % frame).reshape( num_rad, num_theta)) azimuthal_velocity = (fromfile("gasdvtheta%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: threshold = util.get_threshold(size) * 1.5 shift_c = az.get_azimuthal_center(dust_density, fargo_par, threshold=threshold * surface_density_zero) radial_velocity = np.roll(radial_velocity, shift_c) azimuthal_velocity = np.roll(azimuthal_velocity, shift_c) # Calculate Limiting Velocity d_rad = np.diff(rad) d_theta = np.diff(theta) dv_rad = np.diff(radial_velocity, axis=1) print np.max(dv_rad) dv_theta = np.diff(rad[:, None] * azimuthal_velocity, axis=0) print np.max(dv_theta) r_maxes = np.max(dv_rad, axis=1) t_maxes = np.max(dv_theta, axis=1) for (r_i, r_max_i, t_max_i) in zip(rad[1:], r_maxes, t_maxes): print r_i, r_max_i, t_max_i #limiting_velocity_grid = [np.max([dv_rad, dv_theta], axis = 0)] limiting_velocity_grid = dv_rad ### Plot ### x = rad y = theta * (180.0 / np.pi) result = ax.pcolormesh(x, y, np.transpose(limiting_velocity_grid), cmap=cmap) 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(gas_density / gas_surface_density_zero), levels=levels, origin='upper', linewidths=1, colors=colors) # Axes plot.xlim(x_min, x_max) plot.ylim(0, 360) angles = np.linspace(0, 360, 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) plot.ylabel(r"$\phi$", fontsize=fontsize) #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{Jup}$]" % ( orbit, current_mass) plot.title("%s" % (title2), y=1.015, fontsize=fontsize + 1) plot.text(x_mid, y_text * plot.ylim()[-1], 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{Jup}$" % (int(planet_mass)) text_visc = r"$\alpha_\mathrm{disk} = 3 \times 10^{%d}$" % ( int(np.log(viscosity) / np.log(10)) + 2) #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)) plot.text(-0.84 * x_range / 2.0 + x_mid, y_text * plot.ylim()[-1], text_mass, fontsize=fontsize, color='black', horizontalalignment='right') plot.text(0.84 * x_range / 2.0 + x_mid, y_text * plot.ylim()[-1], text_visc, fontsize=fontsize, color='black', horizontalalignment='left') # Save, Show, and Close if version is None: save_fn = "%s/limitingVelocity_%04d.png" % (save_directory, frame) else: save_fn = "%s/v%04d_limitingVelocity_%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)
def add_to_plot(frame, ax, size, num_sizes, frame_i): print frame, num_frames, frame_i # 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 density = util.read_data(frame, 'dust', this_fargo_par, id_number=id_number, directory="../%s-size" % size) if center: if taper < 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 * surface_density_zero) density = np.roll(density, shift_c) 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 == "um": cmap = "viridis" result = plot.pcolormesh(xs_grid, ys_grid, np.transpose(normalized_density), cmap=cmap) 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(gas_theta): shift += len(gas_theta) planet_theta = gas_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 ax.set_xlabel(r"$x$ [$r_p$]", fontsize=fontsize) if frame_i == 1: ax.set_ylabel(r"$y$ [$r_p$]", fontsize=fontsize) title = "Dust (%s-size) Density" % size if size == "um": title = "Gas Density" ax.set_title(title) frame_title = r"$t$ $=$ $%.1f$ [$m_p(t)$ $=$ $%.2f$ $M_J$]" % ( orbit, current_mass) # 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: # 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) 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, frame_title
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 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) ax = fig.add_subplot(111) # Data field = "dens" density = Fields("./", 'gas', frame).get_field(field).reshape(num_rad, num_theta) normalized_density = density / surface_density_zero field = "dens" density = Fields("./", 'dust%d' % dust_number, frame).get_field(field).reshape(num_rad, num_theta) normalized_density = density / dust_surface_density_zero field = "vx" # radial radial_velocity = Fields("./", 'dust%d' % dust_number, frame).get_field(field).reshape( num_rad, num_theta) field = "vy" # azimuthal azimuthal_velocity = Fields("./", 'dust%d' % dust_number, frame).get_field(field).reshape( num_rad, num_theta) if center: if taper_time < 10.1: shift_c = az.get_azimuthal_peak(dust_density, fargo_par) else: threshold = util.get_threshold(size) * 1.5 shift_c = az.get_azimuthal_center(dust_density, fargo_par, threshold=threshold * surface_density_zero) radial_velocity = np.roll(radial_velocity, shift_c) azimuthal_velocity = np.roll(azimuthal_velocity, shift_c) # Calculate CFL Timestep keplerian_velocity = rad * (np.power( rad, -1.5) - 1) # in rotating frame, v_k = r * (r^-1.5 - r_p^-1.5) azimuthal_velocity -= keplerian_velocity[:, None] delta_r = rad[1] - rad[0] r_delta_theta = (rad * (theta[1] - theta[0]))[:, None] cfl = np.abs(radial_velocity) / (delta_r) + np.abs(azimuthal_velocity) / ( r_delta_theta) cfl_max = 0.4 delta_t = cfl_max / cfl critical_location = np.unravel_index(np.argmin(delta_t), np.shape(delta_t)) critical_location = (rad[critical_location[0]], theta[critical_location[1]] ) # convert to rad and theta # Print Overall Min print np.min(delta_t), critical_location # Print min at each radius minima = np.min(delta_t, axis=0) for i, (rad_i, min_i) in enumerate(zip(rad, minima)): if i % 4 == 0: print rad_i, min_i ### Plot ### x = rad y = theta * (180.0 / np.pi) result = ax.pcolormesh(x, y, np.transpose(azimuthal_velocity), cmap=cmap) 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(gas_density / gas_surface_density_zero), levels=levels, origin='upper', linewidths=1, colors=colors) # Axes plot.xlim(x_min, x_max) plot.ylim(0, 360) angles = np.linspace(0, 360, 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) plot.ylabel(r"$\phi$", fontsize=fontsize) #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{Jup}$]" % ( orbit, current_mass) plot.title("%s" % (title2), y=1.015, fontsize=fontsize + 1) plot.text(x_mid, y_text * plot.ylim()[-1], 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{Jup}$" % (int(planet_mass)) text_visc = r"$\alpha_\mathrm{disk} = 3 \times 10^{%d}$" % ( int(np.log(viscosity) / np.log(10)) + 2) #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)) plot.text(-0.84 * x_range / 2.0 + x_mid, y_text * plot.ylim()[-1], text_mass, fontsize=fontsize, color='black', horizontalalignment='right') plot.text(0.84 * x_range / 2.0 + x_mid, y_text * plot.ylim()[-1], text_visc, fontsize=fontsize, color='black', horizontalalignment='left') # Save, Show, and Close if version is None: save_fn = "%s/cflTimestep_%04d.png" % (save_directory, frame) else: save_fn = "%s/v%04d_cflTimestep_%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)
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, 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 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, show = False): # Set up figure fig = plot.figure(figsize = (14, 6), dpi = dpi) # Data gas_density = util.read_data(frame, 'gas', fargo_par) / surface_density_zero dust_density = util.read_data(frame, 'dust', fargo_par) / dust_surface_density_zero # Shift gas density with center of dust density threshold = util.get_threshold(size) shift = az.get_azimuthal_center(dust_density, fargo_par, threshold = threshold) gas_density = np.roll(gas_density, shift) dust_density = np.roll(dust_density, shift) # 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) # Convert density to cartesian _, _, xs_grid, ys_grid, gas_density = sq.polar_to_cartesian(gas_density, rad, theta) _, _, _, _, dust_density = sq.polar_to_cartesian(dust_density, rad, theta) ############################## Left Panel ################################# plot.subplot(1, 2, 1, aspect = 'equal') ### Plot ### result = plot.pcolormesh(xs_grid, ys_grid, np.transpose(gas_density), cmap = "viridis") cbar = fig.colorbar(result) result.set_clim(gas_clim[0], gas_clim[1]) # Get rid of interior circle = plot.Circle((0, 0), min(rad), color = "black") fig.gca().add_artist(circle) # Add planet orbit planet_orbit = plot.Circle((0, 0), 1, color = "white", fill = False, alpha = 0.8, linestyle = "dashed", zorder = 50) fig.gca().add_artist(planet_orbit) # Label star and planet time = fargo_par["Ninterm"] * fargo_par["DT"] orbit = (time / (2 * np.pi)) * frame orbit = 550 + (time / (2 * np.pi)) * (frame - 550) 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 # Use Fixed Mass current_mass = np.power(np.sin((np.pi / 2) * (550.0 / 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 plot.xlabel("x", fontsize = fontsize) plot.ylabel("y", fontsize = fontsize) plot.title("Gas Density Map (t = %.1f)" % (orbit), fontsize = fontsize + 1) # Axes box_size = 2.5 plot.xlim(-box_size, box_size) plot.ylim(-box_size, box_size) ############################# Right Panel ################################# plot.subplot(1, 2, 2, aspect = 'equal') ### Plot ### result = plot.pcolormesh(xs_grid, ys_grid, np.transpose(dust_density), cmap = cmap) cbar = fig.colorbar(result) result.set_clim(dust_clim[0], dust_clim[1]) # Get rid of interior circle = plot.Circle((0, 0), min(rad), color = "black") fig.gca().add_artist(circle) # Add planet orbit planet_orbit = plot.Circle((0, 0), 1, color = "white", fill = False, alpha = 0.8, linestyle = "dashed", zorder = 50) fig.gca().add_artist(planet_orbit) # Label star and planet 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 plot.xlabel("x", fontsize = fontsize) plot.ylabel("y", fontsize = fontsize) plot.title("Dust Density Map (t = %.1f)" % (orbit), fontsize = fontsize + 1) # Axes box_size = 2.5 plot.xlim(-box_size, box_size) plot.ylim(-box_size, box_size) ################################# End ##################################### # Save, Show, and Close if version is None: save_fn = "%s/bothDensityMaps_%04d.png" % (save_directory, frame) else: save_fn = "%s/v%04d_bothDensityMaps_%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)