def plot_manifolds(self): color_palette_green = sns.dark_palette('green', n_colors=self.numberOfOrbitsPerManifold) color_palette_red = sns.dark_palette('red', n_colors=self.numberOfOrbitsPerManifold) fig = plt.figure() ax = fig.gca() for i in range(self.numberOfOrbitsPerManifold): plt.plot(self.WS.xs(i)['x'], self.WS.xs(i)['y'], color=color_palette_green[i]) plt.plot(self.WU.xs(i)['x'], self.WU.xs(i)['y'], color=color_palette_red[i]) C = 3.15 x_range = np.arange(0.7, 1.3, 0.001) y_range = np.arange(-0.3, 0.3, 0.001) X, Y = np.meshgrid(x_range, y_range) Z = cr3bp_velocity(X, Y, C) if Z.min() < 0: plt.contourf(X, Y, Z, [Z.min(), 0], colors='black', alpha=0.2) if self.U_section == (2 or 3): ax.axvline(1 - self.massParameter, color='black') bodies_df = load_bodies_location() u = np.linspace(0, 2 * np.pi, 100) v = np.linspace(0, np.pi, 100) x = bodies_df['Moon']['r'] * np.outer(np.cos(u), np.sin(v)) + bodies_df['Moon']['x'] y = bodies_df['Moon']['r'] * np.outer(np.sin(u), np.sin(v)) z = bodies_df['Moon']['r'] * np.outer(np.ones(np.size(u)), np.cos(v)) plt.scatter(x, y, color='black') pass
def __init__(self, config, orbit_type): self.orbit = [] self.config = config self.orbitType = orbit_type self.massParameter = 0.0121505810173 self.figSize = (20, 20) self.titleSize = 20 self.suptitleSize = 30 orbit_ids = [] for orbit_id in list(self.config[self.orbitType].keys()): ls = orbit_id.split('_') if orbit_type == 'near_vertical': orbit_ids.append(int(ls[2])) if orbit_type == 'halo': orbit_ids.append(int(ls[1])) orbit_ids = [ self.orbitType + '_' + str(idx) for idx in sorted(orbit_ids) ] for orbit_id in orbit_ids: self.orbit.append( load_orbit('../data/raw/' + orbit_id + '_final_orbit.txt')) self.lagrangePoints = load_lagrange_points_location() self.bodies = load_bodies_location() sns.set_style("whitegrid") pass
def plot_2d_shooting_conditions(self): fig = plt.figure(figsize=self.figSize) ax = fig.gca() orbit_types = ['horizontal', 'vertical', 'halo'] lagrange_point_nrs = [1, 2] x = [] z = [] ydot = [] c = [] for idx, orbit_type in enumerate(orbit_types): for lagrange_point_nr in lagrange_point_nrs: initial_conditions_file_path = '../../data/raw/orbits/L' + str( lagrange_point_nr) + '_' + orbit_type + '_initial_conditions.txt' initial_conditions_incl_m_df = load_initial_conditions_incl_M(initial_conditions_file_path) plot_label = orbit_type.capitalize() if plot_label == 'Horizontal' or plot_label == 'Vertical': plot_label += ' Lyapunov' x.extend(list(initial_conditions_incl_m_df[2].values)) z.extend(list(initial_conditions_incl_m_df[4].values)) c.extend(list(initial_conditions_incl_m_df[0].values)) sc = ax.scatter(x, z, c=c, cmap='viridis', s=20) cb = plt.colorbar(sc) cb.set_label('$C \enskip [-]$') lagrange_points_df = load_lagrange_points_location() lagrange_point_nrs = ['L1', 'L2'] # Lagrange points and bodies for lagrange_point_nr in lagrange_point_nrs: ax.scatter(lagrange_points_df[lagrange_point_nr]['x'], lagrange_points_df[lagrange_point_nr]['z'], color='black', marker='x') bodies_df = load_bodies_location() u = np.linspace(0, 2 * np.pi, 100) v = np.linspace(0, np.pi, 100) for body in bodies_df: x = bodies_df[body]['r'] * np.outer(np.cos(u), np.sin(v)) + bodies_df[body]['x'] y = bodies_df[body]['r'] * np.outer(np.sin(u), np.sin(v)) z = bodies_df[body]['r'] * np.outer(np.ones(np.size(u)), np.cos(v)) ax.contourf(x, z, y, colors='black') ax.legend(frameon=True, loc='upper right') ax.set_xlabel('x [-]') ax.set_ylabel('z [-]') ax.grid(True, which='both', ls=':') fig.tight_layout() fig.subplots_adjust(top=0.9) plt.suptitle('$L_1, L_2$ - Shooting conditions for H-L, halo, and V-L', size=self.suptitleSize) if self.lowDPI: fig.savefig('../../data/figures/orbits/orbit_shooting_conditions_2d.png', transparent=True, dpi=self.dpi) else: fig.savefig('../../data/figures/orbits/orbit_shooting_conditions_2d.pdf', transparent=True) pass
def plot_3d_shooting_conditions(self): fig = plt.figure(figsize=self.figSize) ax = fig.gca(projection='3d') orbit_types = ['horizontal', 'vertical', 'halo'] lagrange_point_nrs = [1, 2] lines = [] linewidth = 2 for lagrange_point_nr in lagrange_point_nrs: for idx, orbit_type in enumerate(orbit_types): initial_conditions_file_path = '../../data/raw/orbits/L' + str( lagrange_point_nr) + '_' + orbit_type + '_initial_conditions.txt' initial_conditions_incl_m_df = load_initial_conditions_incl_M(initial_conditions_file_path) plot_label = orbit_type.capitalize() if plot_label == 'Horizontal' or plot_label == 'Vertical': plot_label += ' Lyapunov' line, = ax.plot(initial_conditions_incl_m_df[2].values, initial_conditions_incl_m_df[6].values, initial_conditions_incl_m_df[4].values, label=plot_label, linewidth=linewidth, color=self.plottingColors['tripleLine'][idx]) lines.append(line) lagrange_points_df = load_lagrange_points_location() lagrange_point_nrs = ['L1', 'L2'] # Lagrange points and bodies for lagrange_point_nr in lagrange_point_nrs: ax.scatter(lagrange_points_df[lagrange_point_nr]['x'], lagrange_points_df[lagrange_point_nr]['z'], color='black', marker='x') bodies_df = load_bodies_location() u = np.linspace(0, 2 * np.pi, 100) v = np.linspace(0, np.pi, 100) for body in bodies_df: x = bodies_df[body]['r'] * np.outer(np.cos(u), np.sin(v)) + bodies_df[body]['x'] y = bodies_df[body]['r'] * np.outer(np.sin(u), np.sin(v)) z = bodies_df[body]['r'] * np.outer(np.ones(np.size(u)), np.cos(v)) ax.plot_surface(x, y, z, color='black') # print(ax.elev) # print(ax.azim) # ax.view_init(20, -75) plt.plot(ax.get_xlim(), [0, 0], 'black', linewidth=0.5) ax.legend(frameon=True, loc='upper right', handles=lines[:3]) ax.set_xlabel('x [-]') ax.set_ylabel('$\dot{y}$ [-]') ax.set_zlabel('z [-]') ax.grid(True, which='both', ls=':') fig.tight_layout() fig.subplots_adjust(top=0.9) plt.suptitle('$L_1, L_2$ - Shooting conditions', size=self.suptitleSize) fig.savefig('../../data/figures/orbits/orbit_shooting_conditions_3d.pdf', transparent=True) pass
def plot_manifolds(self): # Plot: subplots fig = plt.figure(figsize=self.figSize) ax = fig.gca() lagrange_points_df = load_lagrange_points_location() lagrange_point_nrs = ['L1', 'L2'] # Lagrange points and bodies for lagrange_point_nr in lagrange_point_nrs: ax.scatter(lagrange_points_df[lagrange_point_nr]['x'], lagrange_points_df[lagrange_point_nr]['y'], color='black', marker='x') u = np.linspace(0, 2 * np.pi, 100) v = np.linspace(0, np.pi, 100) bodies_df = load_bodies_location() for body in bodies_df: x = bodies_df[body]['r'] * np.outer(np.cos(u), np.sin(v)) + bodies_df[body]['x'] y = bodies_df[body]['r'] * np.outer(np.sin(u), np.sin(v)) z = bodies_df[body]['r'] * np.outer(np.ones(np.size(u)), np.cos(v)) ax.contourf(x, y, z, colors='black') # Determine color for plot plot_alpha = 1 line_width = 1 for manifold_orbit_number in range(self.numberOfOrbitsPerManifold): ax.plot(self.W_S_plus.xs(manifold_orbit_number)['x'], self.W_S_plus.xs(manifold_orbit_number)['y'], color=self.colorPaletteStable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax.plot(self.W_S_min.xs(manifold_orbit_number)['x'], self.W_S_min.xs(manifold_orbit_number)['y'], color=self.colorPaletteStable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax.plot(self.W_U_plus.xs(manifold_orbit_number)['x'], self.W_U_plus.xs(manifold_orbit_number)['y'], color=self.colorPaletteUnstable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax.plot(self.W_U_min.xs(manifold_orbit_number)['x'], self.W_U_min.xs(manifold_orbit_number)['y'], color=self.colorPaletteUnstable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax.set_xlabel('x [-]') ax.set_ylabel('y [-]') ax.grid(True, which='both', ls=':') fig.tight_layout() fig.subplots_adjust(top=0.9) plt.suptitle('$L_' + str(self.lagrangePointNr) + '$ ' + self.orbitTypeForTitle + ' $\{ \mathcal{W}^{S \pm}, \mathcal{W}^{U \pm} \}$ - Spatial overview', size=self.suptitleSize) plt.savefig('../../data/figures/manifolds/refined_for_c/L' + str(self.lagrangePointNr) + '_' + self.orbitType + '_' + str(self.orbitId) + '_manifold.pdf', transparent=True) plt.close() pass
def plot_manifolds(self): # Plot: subplots if self.orbitType == 'horizontal': figsize = (self.figSize[0], self.figSize[1] / 2) fig = plt.figure(figsize=figsize) ax00 = fig.add_subplot(2, 3, 1, projection='3d') ax01 = fig.add_subplot(2, 3, 2, projection='3d') ax02 = fig.add_subplot(2, 3, 3, projection='3d') ax10 = fig.add_subplot(2, 3, 4) ax11 = fig.add_subplot(2, 3, 5) ax12 = fig.add_subplot(2, 3, 6) else: figsize = self.figSize fig = plt.figure(figsize=figsize) ax00 = fig.add_subplot(4, 3, 1, projection='3d') ax01 = fig.add_subplot(4, 3, 2, projection='3d') ax02 = fig.add_subplot(4, 3, 3, projection='3d') ax10 = fig.add_subplot(4, 3, 4) ax11 = fig.add_subplot(4, 3, 5) ax12 = fig.add_subplot(4, 3, 6) ax20 = fig.add_subplot(4, 3, 7) ax21 = fig.add_subplot(4, 3, 8) ax22 = fig.add_subplot(4, 3, 9) ax30 = fig.add_subplot(4, 3, 10) ax31 = fig.add_subplot(4, 3, 11) ax32 = fig.add_subplot(4, 3, 12) lagrange_points_df = load_lagrange_points_location() lagrange_point_nrs = ['L1', 'L2'] # Lagrange points and bodies for lagrange_point_nr in lagrange_point_nrs: ax00.scatter(lagrange_points_df[lagrange_point_nr]['x'], lagrange_points_df[lagrange_point_nr]['y'], lagrange_points_df[lagrange_point_nr]['z'], color='black', marker='x') ax01.scatter(lagrange_points_df[lagrange_point_nr]['x'], lagrange_points_df[lagrange_point_nr]['y'], lagrange_points_df[lagrange_point_nr]['z'], color='black', marker='x') ax02.scatter(lagrange_points_df[lagrange_point_nr]['x'], lagrange_points_df[lagrange_point_nr]['y'], lagrange_points_df[lagrange_point_nr]['z'], color='black', marker='x') ax10.scatter(lagrange_points_df[lagrange_point_nr]['x'], lagrange_points_df[lagrange_point_nr]['y'], color='black', marker='x') ax11.scatter(lagrange_points_df[lagrange_point_nr]['x'], lagrange_points_df[lagrange_point_nr]['y'], color='black', marker='x') ax12.scatter(lagrange_points_df[lagrange_point_nr]['x'], lagrange_points_df[lagrange_point_nr]['y'], color='black', marker='x') if self.orbitType != 'horizontal': ax20.scatter(lagrange_points_df[lagrange_point_nr]['x'], lagrange_points_df[lagrange_point_nr]['z'], color='black', marker='x') ax21.scatter(lagrange_points_df[lagrange_point_nr]['x'], lagrange_points_df[lagrange_point_nr]['z'], color='black', marker='x') ax22.scatter(lagrange_points_df[lagrange_point_nr]['x'], lagrange_points_df[lagrange_point_nr]['z'], color='black', marker='x') ax30.scatter(lagrange_points_df[lagrange_point_nr]['y'], lagrange_points_df[lagrange_point_nr]['z'], color='black', marker='x') ax31.scatter(lagrange_points_df[lagrange_point_nr]['y'], lagrange_points_df[lagrange_point_nr]['z'], color='black', marker='x') ax32.scatter(lagrange_points_df[lagrange_point_nr]['y'], lagrange_points_df[lagrange_point_nr]['z'], color='black', marker='x') u = np.linspace(0, 2 * np.pi, 100) v = np.linspace(0, np.pi, 100) bodies_df = load_bodies_location() for body in bodies_df: x = bodies_df[body]['r'] * np.outer( np.cos(u), np.sin(v)) + bodies_df[body]['x'] y = bodies_df[body]['r'] * np.outer(np.sin(u), np.sin(v)) z = bodies_df[body]['r'] * np.outer(np.ones(np.size(u)), np.cos(v)) ax00.plot_surface(x, y, z, color='black') ax01.plot_surface(x, y, z, color='black') ax02.plot_surface(x, y, z, color='black') ax10.contourf(x, y, z, colors='black') ax11.contourf(x, y, z, colors='black') ax12.contourf(x, y, z, colors='black') if self.orbitType != 'horizontal': ax20.contourf(x, z, y, colors='black') ax21.contourf(x, z, y, colors='black') ax22.contourf(x, z, y, colors='black') ax30.contourf(y, z, x, colors='black') ax31.contourf(y, z, x, colors='black') ax32.contourf(y, z, x, colors='black') # Determine color for plot plot_alpha = 1 line_width = 0.5 for manifold_orbit_number in range(self.numberOfOrbitsPerManifold): ax00.plot(self.W_S_plus[0].xs(manifold_orbit_number)['x'], self.W_S_plus[0].xs(manifold_orbit_number)['y'], self.W_S_plus[0].xs(manifold_orbit_number)['z'], color=self.colorPaletteStable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax01.plot(self.W_S_plus[1].xs(manifold_orbit_number)['x'], self.W_S_plus[1].xs(manifold_orbit_number)['y'], self.W_S_plus[1].xs(manifold_orbit_number)['z'], color=self.colorPaletteStable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax02.plot(self.W_S_plus[2].xs(manifold_orbit_number)['x'], self.W_S_plus[2].xs(manifold_orbit_number)['y'], self.W_S_plus[2].xs(manifold_orbit_number)['z'], color=self.colorPaletteStable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax10.plot(self.W_S_plus[0].xs(manifold_orbit_number)['x'], self.W_S_plus[0].xs(manifold_orbit_number)['y'], color=self.colorPaletteStable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax11.plot(self.W_S_plus[1].xs(manifold_orbit_number)['x'], self.W_S_plus[1].xs(manifold_orbit_number)['y'], color=self.colorPaletteStable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax12.plot(self.W_S_plus[2].xs(manifold_orbit_number)['x'], self.W_S_plus[2].xs(manifold_orbit_number)['y'], color=self.colorPaletteStable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) if self.orbitType != 'horizontal': ax20.plot(self.W_S_plus[0].xs(manifold_orbit_number)['x'], self.W_S_plus[0].xs(manifold_orbit_number)['z'], color=self.colorPaletteStable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax21.plot(self.W_S_plus[1].xs(manifold_orbit_number)['x'], self.W_S_plus[1].xs(manifold_orbit_number)['z'], color=self.colorPaletteStable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax22.plot(self.W_S_plus[2].xs(manifold_orbit_number)['x'], self.W_S_plus[2].xs(manifold_orbit_number)['z'], color=self.colorPaletteStable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax30.plot(self.W_S_plus[0].xs(manifold_orbit_number)['y'], self.W_S_plus[0].xs(manifold_orbit_number)['z'], color=self.colorPaletteStable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax31.plot(self.W_S_plus[1].xs(manifold_orbit_number)['y'], self.W_S_plus[1].xs(manifold_orbit_number)['z'], color=self.colorPaletteStable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax32.plot(self.W_S_plus[2].xs(manifold_orbit_number)['y'], self.W_S_plus[2].xs(manifold_orbit_number)['z'], color=self.colorPaletteStable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax00.plot(self.W_S_min[0].xs(manifold_orbit_number)['x'], self.W_S_min[0].xs(manifold_orbit_number)['y'], self.W_S_min[0].xs(manifold_orbit_number)['z'], color=self.colorPaletteStable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax01.plot(self.W_S_min[1].xs(manifold_orbit_number)['x'], self.W_S_min[1].xs(manifold_orbit_number)['y'], self.W_S_min[1].xs(manifold_orbit_number)['z'], color=self.colorPaletteStable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax02.plot(self.W_S_min[2].xs(manifold_orbit_number)['x'], self.W_S_min[2].xs(manifold_orbit_number)['y'], self.W_S_min[2].xs(manifold_orbit_number)['z'], color=self.colorPaletteStable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax10.plot(self.W_S_min[0].xs(manifold_orbit_number)['x'], self.W_S_min[0].xs(manifold_orbit_number)['y'], color=self.colorPaletteStable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax11.plot(self.W_S_min[1].xs(manifold_orbit_number)['x'], self.W_S_min[1].xs(manifold_orbit_number)['y'], color=self.colorPaletteStable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax12.plot(self.W_S_min[2].xs(manifold_orbit_number)['x'], self.W_S_min[2].xs(manifold_orbit_number)['y'], color=self.colorPaletteStable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) if self.orbitType != 'horizontal': ax20.plot(self.W_S_min[0].xs(manifold_orbit_number)['x'], self.W_S_min[0].xs(manifold_orbit_number)['z'], color=self.colorPaletteStable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax21.plot(self.W_S_min[1].xs(manifold_orbit_number)['x'], self.W_S_min[1].xs(manifold_orbit_number)['z'], color=self.colorPaletteStable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax22.plot(self.W_S_min[2].xs(manifold_orbit_number)['x'], self.W_S_min[2].xs(manifold_orbit_number)['z'], color=self.colorPaletteStable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax30.plot(self.W_S_min[0].xs(manifold_orbit_number)['y'], self.W_S_min[0].xs(manifold_orbit_number)['z'], color=self.colorPaletteStable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax31.plot(self.W_S_min[1].xs(manifold_orbit_number)['y'], self.W_S_min[1].xs(manifold_orbit_number)['z'], color=self.colorPaletteStable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax32.plot(self.W_S_min[2].xs(manifold_orbit_number)['y'], self.W_S_min[2].xs(manifold_orbit_number)['z'], color=self.colorPaletteStable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax00.plot(self.W_U_plus[0].xs(manifold_orbit_number)['x'], self.W_U_plus[0].xs(manifold_orbit_number)['y'], self.W_U_plus[0].xs(manifold_orbit_number)['z'], color=self.colorPaletteUnstable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax01.plot(self.W_U_plus[1].xs(manifold_orbit_number)['x'], self.W_U_plus[1].xs(manifold_orbit_number)['y'], self.W_U_plus[1].xs(manifold_orbit_number)['z'], color=self.colorPaletteUnstable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax02.plot(self.W_U_plus[2].xs(manifold_orbit_number)['x'], self.W_U_plus[2].xs(manifold_orbit_number)['y'], self.W_U_plus[2].xs(manifold_orbit_number)['z'], color=self.colorPaletteUnstable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax10.plot(self.W_U_plus[0].xs(manifold_orbit_number)['x'], self.W_U_plus[0].xs(manifold_orbit_number)['y'], color=self.colorPaletteUnstable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax11.plot(self.W_U_plus[1].xs(manifold_orbit_number)['x'], self.W_U_plus[1].xs(manifold_orbit_number)['y'], color=self.colorPaletteUnstable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax12.plot(self.W_U_plus[2].xs(manifold_orbit_number)['x'], self.W_U_plus[2].xs(manifold_orbit_number)['y'], color=self.colorPaletteUnstable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) if self.orbitType != 'horizontal': ax20.plot( self.W_U_plus[0].xs(manifold_orbit_number)['x'], self.W_U_plus[0].xs(manifold_orbit_number)['z'], color=self.colorPaletteUnstable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax21.plot( self.W_U_plus[1].xs(manifold_orbit_number)['x'], self.W_U_plus[1].xs(manifold_orbit_number)['z'], color=self.colorPaletteUnstable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax22.plot( self.W_U_plus[2].xs(manifold_orbit_number)['x'], self.W_U_plus[2].xs(manifold_orbit_number)['z'], color=self.colorPaletteUnstable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax30.plot( self.W_U_plus[0].xs(manifold_orbit_number)['y'], self.W_U_plus[0].xs(manifold_orbit_number)['z'], color=self.colorPaletteUnstable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax31.plot( self.W_U_plus[1].xs(manifold_orbit_number)['y'], self.W_U_plus[1].xs(manifold_orbit_number)['z'], color=self.colorPaletteUnstable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax32.plot( self.W_U_plus[2].xs(manifold_orbit_number)['y'], self.W_U_plus[2].xs(manifold_orbit_number)['z'], color=self.colorPaletteUnstable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax00.plot(self.W_U_min[0].xs(manifold_orbit_number)['x'], self.W_U_min[0].xs(manifold_orbit_number)['y'], self.W_U_min[0].xs(manifold_orbit_number)['z'], color=self.colorPaletteUnstable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax01.plot(self.W_U_min[1].xs(manifold_orbit_number)['x'], self.W_U_min[1].xs(manifold_orbit_number)['y'], self.W_U_min[1].xs(manifold_orbit_number)['z'], color=self.colorPaletteUnstable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax02.plot(self.W_U_min[2].xs(manifold_orbit_number)['x'], self.W_U_min[2].xs(manifold_orbit_number)['y'], self.W_U_min[2].xs(manifold_orbit_number)['z'], color=self.colorPaletteUnstable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax10.plot(self.W_U_min[0].xs(manifold_orbit_number)['x'], self.W_U_min[0].xs(manifold_orbit_number)['y'], color=self.colorPaletteUnstable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax11.plot(self.W_U_min[1].xs(manifold_orbit_number)['x'], self.W_U_min[1].xs(manifold_orbit_number)['y'], color=self.colorPaletteUnstable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax12.plot(self.W_U_min[2].xs(manifold_orbit_number)['x'], self.W_U_min[2].xs(manifold_orbit_number)['y'], color=self.colorPaletteUnstable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) if self.orbitType != 'horizontal': ax20.plot( self.W_U_min[0].xs(manifold_orbit_number)['x'], self.W_U_min[0].xs(manifold_orbit_number)['z'], color=self.colorPaletteUnstable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax21.plot( self.W_U_min[1].xs(manifold_orbit_number)['x'], self.W_U_min[1].xs(manifold_orbit_number)['z'], color=self.colorPaletteUnstable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax22.plot( self.W_U_min[2].xs(manifold_orbit_number)['x'], self.W_U_min[2].xs(manifold_orbit_number)['z'], color=self.colorPaletteUnstable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax30.plot( self.W_U_min[0].xs(manifold_orbit_number)['y'], self.W_U_min[0].xs(manifold_orbit_number)['z'], color=self.colorPaletteUnstable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax31.plot( self.W_U_min[1].xs(manifold_orbit_number)['y'], self.W_U_min[1].xs(manifold_orbit_number)['z'], color=self.colorPaletteUnstable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) ax32.plot( self.W_U_min[2].xs(manifold_orbit_number)['y'], self.W_U_min[2].xs(manifold_orbit_number)['z'], color=self.colorPaletteUnstable[manifold_orbit_number], alpha=plot_alpha, linewidth=line_width) plot_alpha = 1 line_width = 2 ax00.plot(self.orbitDf[0]['x'], self.orbitDf[0]['y'], self.orbitDf[0]['z'], color=self.plottingColors['orbit'], alpha=plot_alpha, linewidth=line_width) ax01.plot(self.orbitDf[1]['x'], self.orbitDf[1]['y'], self.orbitDf[1]['z'], color=self.plottingColors['orbit'], alpha=plot_alpha, linewidth=line_width) ax02.plot(self.orbitDf[2]['x'], self.orbitDf[2]['y'], self.orbitDf[2]['z'], color=self.plottingColors['orbit'], alpha=plot_alpha, linewidth=line_width) ax10.plot(self.orbitDf[0]['x'], self.orbitDf[0]['y'], color=self.plottingColors['orbit'], alpha=plot_alpha, linewidth=line_width) ax11.plot(self.orbitDf[1]['x'], self.orbitDf[1]['y'], color=self.plottingColors['orbit'], alpha=plot_alpha, linewidth=line_width) ax12.plot(self.orbitDf[2]['x'], self.orbitDf[2]['y'], color=self.plottingColors['orbit'], alpha=plot_alpha, linewidth=line_width) if self.orbitType != 'horizontal': ax20.plot(self.orbitDf[0]['x'], self.orbitDf[0]['z'], color=self.plottingColors['orbit'], alpha=plot_alpha, linewidth=line_width) ax21.plot(self.orbitDf[1]['x'], self.orbitDf[1]['z'], color=self.plottingColors['orbit'], alpha=plot_alpha, linewidth=line_width) ax22.plot(self.orbitDf[2]['x'], self.orbitDf[2]['z'], color=self.plottingColors['orbit'], alpha=plot_alpha, linewidth=line_width) ax30.plot(self.orbitDf[0]['y'], self.orbitDf[0]['z'], color=self.plottingColors['orbit'], alpha=plot_alpha, linewidth=line_width) ax31.plot(self.orbitDf[1]['y'], self.orbitDf[1]['z'], color=self.plottingColors['orbit'], alpha=plot_alpha, linewidth=line_width) ax32.plot(self.orbitDf[2]['y'], self.orbitDf[2]['z'], color=self.plottingColors['orbit'], alpha=plot_alpha, linewidth=line_width) ax00.set_xlabel('x [-]') ax00.set_ylabel('y [-]') ax00.set_zlabel('z [-]') ax00.grid(True, which='both', ls=':') ax00.view_init(30, -120) ax00.set_title('C = ' + str(self.C[0])) ax01.set_xlabel('x [-]') ax01.set_ylabel('y [-]') ax01.set_zlabel('z [-]') ax01.grid(True, which='both', ls=':') ax01.view_init(30, -120) ax01.set_title('C = ' + str(self.C[1])) ax02.set_xlabel('x [-]') ax02.set_ylabel('y [-]') ax02.set_zlabel('z [-]') if self.orbitType == 'horizontal': ax00.set_zlim([-0.4, 0.4]) ax01.set_zlim([-0.4, 0.4]) ax02.set_zlim([-0.4, 0.4]) ax02.grid(True, which='both', ls=':') ax02.view_init(30, -120) ax02.set_title('C = ' + str(self.C[2])) xlim = [ min(ax00.get_xlim()[0], ax01.get_xlim()[0], ax02.get_xlim()[0]), max(ax00.get_xlim()[1], ax01.get_xlim()[1], ax02.get_xlim()[1]) ] ylim = [ min(ax00.get_ylim()[0], ax01.get_ylim()[0], ax02.get_ylim()[0]), max(ax00.get_ylim()[1], ax01.get_ylim()[1], ax02.get_ylim()[1]) ] zlim = [ min(ax00.get_zlim()[0], ax01.get_zlim()[0], ax02.get_zlim()[0]), max(ax00.get_zlim()[1], ax01.get_zlim()[1], ax02.get_zlim()[1]) ] ax00.set_xlim(xlim) ax01.set_xlim(xlim) ax02.set_xlim(xlim) ax00.set_ylim(ylim) ax01.set_ylim(ylim) ax02.set_ylim(ylim) ax00.set_zlim(zlim) ax01.set_zlim(zlim) ax02.set_zlim(zlim) ax10.set_xlabel('x [-]') ax11.set_xlabel('x [-]') ax12.set_xlabel('x [-]') ax10.set_ylabel('y [-]') xlim = [ min(ax10.get_xlim()[0], ax11.get_xlim()[0], ax12.get_xlim()[0]), max(ax10.get_xlim()[1], ax11.get_xlim()[1], ax12.get_xlim()[1]) ] ylim = [ min(ax10.get_ylim()[0], ax11.get_ylim()[0], ax12.get_ylim()[0]), max(ax10.get_ylim()[1], ax11.get_ylim()[1], ax12.get_ylim()[1]) ] ax10.set_xlim(xlim) ax11.set_xlim(xlim) ax12.set_xlim(xlim) ax10.set_ylim(ylim) ax11.set_ylim(ylim) ax12.set_ylim(ylim) ax10.grid(True, which='both', ls=':') ax11.grid(True, which='both', ls=':') ax12.grid(True, which='both', ls=':') # Plot zero velocity surface x_range = np.arange(-6.0, 4.0, 0.001) y_range = np.arange(-3.0, 3.0, 0.001) x_mesh, y_mesh = np.meshgrid(x_range, y_range) z_mesh0 = cr3bp_velocity(x_mesh, y_mesh, 3.15) z_mesh1 = cr3bp_velocity(x_mesh, y_mesh, 3.1) z_mesh2 = cr3bp_velocity(x_mesh, y_mesh, 3.05) if z_mesh0.min() < 0: ax10.contourf(x_mesh, y_mesh, z_mesh0, list(np.linspace(z_mesh0.min(), 0, 10)), cmap='gist_gray_r', alpha=0.5) if z_mesh1.min() < 0: ax11.contourf(x_mesh, y_mesh, z_mesh1, list(np.linspace(z_mesh1.min(), 0, 10)), cmap='gist_gray_r', alpha=0.5) if z_mesh2.min() < 0: ax12.contourf(x_mesh, y_mesh, z_mesh2, list(np.linspace(z_mesh2.min(), 0, 10)), cmap='gist_gray_r', alpha=0.5) if self.orbitType != 'horizontal': ax20.set_xlabel('x [-]') ax21.set_xlabel('x [-]') ax22.set_xlabel('x [-]') ax20.set_ylabel('z [-]') xlim = [ min(ax20.get_xlim()[0], ax21.get_xlim()[0], ax22.get_xlim()[0]), max(ax20.get_xlim()[1], ax21.get_xlim()[1], ax22.get_xlim()[1]) ] ylim = [ min(ax20.get_ylim()[0], ax21.get_ylim()[0], ax22.get_ylim()[0]), max(ax20.get_ylim()[1], ax21.get_ylim()[1], ax22.get_ylim()[1]) ] ax20.set_xlim(xlim) ax21.set_xlim(xlim) ax22.set_xlim(xlim) ax20.set_ylim(ylim) ax21.set_ylim(ylim) ax22.set_ylim(ylim) ax20.grid(True, which='both', ls=':') ax21.grid(True, which='both', ls=':') ax22.grid(True, which='both', ls=':') ax30.set_xlabel('y [-]') ax31.set_xlabel('y [-]') ax32.set_xlabel('y [-]') ax30.set_ylabel('z [-]') xlim = [ min(ax30.get_xlim()[0], ax31.get_xlim()[0], ax32.get_xlim()[0]), max(ax30.get_xlim()[1], ax31.get_xlim()[1], ax32.get_xlim()[1]) ] ylim = [ min(ax30.get_ylim()[0], ax31.get_ylim()[0], ax32.get_ylim()[0]), max(ax30.get_ylim()[1], ax31.get_ylim()[1], ax32.get_ylim()[1]) ] ax30.set_xlim(xlim) ax31.set_xlim(xlim) ax32.set_xlim(xlim) ax30.set_ylim(ylim) ax31.set_ylim(ylim) ax32.set_ylim(ylim) ax30.grid(True, which='both', ls=':') ax31.grid(True, which='both', ls=':') ax32.grid(True, which='both', ls=':') fig.tight_layout() if self.orbitType == 'horizontal': fig.subplots_adjust(top=0.9) else: fig.subplots_adjust(top=0.95) plt.suptitle( '$L_' + str(self.lagrangePointNr) + '$ ' + self.orbitTypeForTitle + ' $\{ \mathcal{W}^{S \pm}, \mathcal{W}^{U \pm} \}$ - Spatial comparison', size=self.suptitleSize) fig.savefig('../../data/figures/manifolds/refined_for_c/L' + str(self.lagrangePointNr) + '_' + self.orbitType + '_manifold_comparison.pdf', transparent=True) # fig.savefig('/Users/koen/Documents/Courses/AE5810 Thesis Space/Meetings/0901/L' + str(self.lagrangePointNr) + '_' + self.orbitType + '_' + str(self.orbitId) + '_manifold_subplots.png') plt.close() pass
def animate(self): fig = plt.figure() self.ax = fig.gca() self.lines = [ plt.plot([], [], color=self.orbitColor, alpha=self.orbitAlpha, marker='o', markevery=[-1])[0] for idx in range(6) ] # Text object to display absolute normalized time of trajectories within the manifolds self.timeText = self.ax.text2D(0.05, 0.95, s='$\|t\| \\approx 0$', transform=self.ax.transAxes, size=self.timeTextSize) # Plot zero velocity surface x_range = np.arange(-5, 5, 0.001) y_range = np.arange(-5, 5, 0.001) x_mesh, y_mesh = np.meshgrid(x_range, y_range) z_mesh = cr3bp_velocity(x_mesh, y_mesh, self.cLevel) # self.ax.plot_surface(x_mesh, y_mesh, -z_mesh, alpha=0.1, linewidth=0, # cmap=matplotlib.colors.ListedColormap(sns.color_palette("Blues", n_colors=100)), # vmin=self.zLim[0], vmax=-z_mesh.min(), rstride=50, cstride=50) self.ax.plot_surface(x_mesh, y_mesh, -z_mesh, alpha=0.2, linewidth=0, color='black') self.ax.plot_wireframe(x_mesh, y_mesh, -z_mesh, alpha=1, linewidth=0.5, color='black', rstride=50, cstride=50) # Plot both primaries u = np.linspace(0, 2 * np.pi, 100) v = np.linspace(0, np.pi, 100) bodies_df = load_bodies_location() for body in bodies_df: x = self.orbitalBodiesEnlargementFactor * bodies_df[body][ 'r'] * np.outer(np.cos(u), np.sin(v)) + bodies_df[body]['x'] y = self.orbitalBodiesEnlargementFactor * bodies_df[body][ 'r'] * np.outer(np.sin(u), np.sin(v)) z = self.orbitalBodiesEnlargementFactor * bodies_df[body][ 'r'] * np.outer(np.ones(np.size(u)), np.cos(v)) self.ax.plot_surface(x, y, z, color='black', zorder=3) # Plot Lagrange points 1 and 2 lagrange_points_df = load_lagrange_points_location() lagrange_point_nrs = ['L1', 'L2'] for lagrange_point_nr in lagrange_point_nrs: self.ax.scatter3D(lagrange_points_df[lagrange_point_nr]['x'], lagrange_points_df[lagrange_point_nr]['y'], lagrange_points_df[lagrange_point_nr]['z'], color='black', marker='x', s=self.lagrangePointMarkerSize, zorder=1) title = 'Rotating reference frame - Spatial overview at C = ' + str( self.cLevel) self.ax.set_xlim3d(self.xLim) self.ax.set_ylim3d(self.yLim) self.ax.set_zlim3d(self.zLim) fig.tight_layout() fig.subplots_adjust(top=0.9) plt.suptitle(title, size=self.suptitleSize) # self.ax.elev = 60 self.initialElevation = self.ax.elev self.initialAzimuth = self.ax.azim self.ax.set_aspect('equal') # plt.show() plt.axis('off') # Determine the maximum value of t t_max = 1 print('Maximum value for t = ' + str(t_max) + ', animation t: = ') # Introduce a new time-vector for linearly spaced time throughout the animation # self.t = np.linspace(0, t_max, np.round(t_max / 0.05) + 1) self.t = np.linspace(0, t_max, np.round(t_max / 0.005) + 1) animation_function = animation.FuncAnimation( fig, self.update_lines, init_func=self.initiate_lines, frames=len(self.t), interval=1, blit=True) empty_writer_object = animation.writers['ffmpeg'] animation_writer = empty_writer_object( fps=30, metadata=dict(artist='Koen Langemeijer')) file_name = '../../../data/animations/reference_frame/spatial_rotating_reference_frame_' + str( self.cLevel) + '.mp4' animation_function.save(file_name, writer=animation_writer)
def animate(self): print( '\nProducing a HorizontalLyapunovBifurcationToAxialAnimation at L' + str(self.librationPointNr) + '\n') fig = plt.figure() ax = fig.add_subplot(111, projection='3d') self.lines = [ plt.plot([], [], color=self.orbitColor, alpha=self.orbitAlpha)[0] ] # Text object to display absolute normalized time of trajectories within the manifolds self.jacobiEnergyText = ax.text2D( 0.05, 0.05, s='Horizontal Lyapunov family \n $C \\approx$ {:.4f}'.format( round(self.jacobiEnergyHorizontalLyapunov[0], 4)), transform=ax.transAxes, size=self.timeTextSize) # Plot the first orbit orbit_df = load_orbit('../../../data/raw/orbits/L' + str(self.librationPointNr) + '_horizontal_' + str(0) + '.txt') plt.plot(orbit_df['x'], orbit_df['y'], orbit_df['z'], color='orange', alpha=self.orbitAlpha, linewidth=self.orbitLinewidth) # Plot the Moon u = np.linspace(0, 2 * np.pi, 100) v = np.linspace(0, np.pi, 100) bodies_df = load_bodies_location() x = bodies_df['Moon']['r'] * np.outer( np.cos(u), np.sin(v)) + bodies_df['Moon']['x'] y = bodies_df['Moon']['r'] * np.outer(np.sin(u), np.sin(v)) z = bodies_df['Moon']['r'] * np.outer(np.ones(np.size(u)), np.cos(v)) ax.plot_surface(x, y, z, color='black') # Plot Lagrange points 1 and 2 lagrange_points_df = load_lagrange_points_location() lagrange_point_nrs = ['L1', 'L2'] for lagrange_point_nr in lagrange_point_nrs: ax.scatter3D(lagrange_points_df[lagrange_point_nr]['x'], lagrange_points_df[lagrange_point_nr]['y'], lagrange_points_df[lagrange_point_nr]['z'], color='black', marker='x', s=self.lagrangePointMarkerSize) title = 'Bifurcation from horizontal Lyapunov to axial and vertical Lyapunov families at $L_' + str( self.librationPointNr) + '$' ax.set_xlim3d(self.xLim) ax.set_ylim3d(self.yLim) ax.set_zlim3d(self.zLim) ax.set_xlabel('x [-]') ax.set_ylabel('y [-]') ax.set_zlabel('z [-]') plt.show() ax.grid(True, which='both', ls=':') fig.tight_layout() fig.subplots_adjust(top=0.9) plt.suptitle(title, size=self.suptitleSize) # Fix overlap between labels and ticks ax.xaxis._axinfo['label']['space_factor'] = 2.0 ax.yaxis._axinfo['label']['space_factor'] = 2.0 ax.zaxis._axinfo['label']['space_factor'] = 2.0 # ax.elev = 10 # ax.azim = -80 # Determine number of frames number_of_frames = int( self.orbitIdBifurcationsFromHorizontalLyapunov[1] + 1 + self.numberOfAxialOrbits + len(self.verticalLyapunovIndices)) print('Number of frames equals ' + str(number_of_frames)) animation_function = animation.FuncAnimation( fig, self.update_lines, init_func=self.initiate_lines, frames=number_of_frames, interval=1, blit=True) empty_writer_object = animation.writers['ffmpeg'] animation_writer = empty_writer_object( fps=30, metadata=dict(artist='Koen Langemeijer')) file_name = '../../../data/animations/bifurcations/L' + str( self.librationPointNr ) + '_horizontal_lyapunov_bifurcation_to_axial_family.mp4' animation_function.save(file_name, writer=animation_writer)
def plot_saddle(self): fig = plt.figure(figsize=self.figSize) ax = fig.add_subplot(111, projection='3d') # azim=150 # elev=25 # print(ax.azim) # ax.view_init(elev=elev, azim=azim) ax.view_init(elev=25, azim=17) # Plot zero velocity surface # x_range = np.arange(self.xlim[0], self.xlim[1], 0.01) # y_range = np.arange(self.ylim[0], self.ylim[1], 0.01) x_range = np.arange(self.crange[0], self.crange[1], 0.01) y_range = np.arange(self.crange[0], self.crange[1], 0.01) x_mesh, y_mesh = np.meshgrid(x_range, y_range) z_mesh = cr3bp_velocity(x_mesh, y_mesh, self.cLevel) self.zlim = [-0.5, -min([min(i) for i in z_mesh])] print(z_mesh) threshold_z = 0.3 for idx1, row in enumerate(z_mesh): for idx2, item in enumerate(row): if item > threshold_z: z_mesh[idx1][idx2] = threshold_z # print(max([max(i) for i in z_mesh])) # print(min([min(i) for i in z_mesh])) if z_mesh.min() < 0: # plt.contour(x_mesh, y_mesh, z_mesh, [z_mesh.min(), 0], colors='black', alpha=0.3) # ax.contour(x_mesh, y_mesh, z_mesh, list(np.linspace(z_mesh.min(), 0, 10)), cmap='gist_gray_r', # alpha=0.5) ax.plot_surface(x_mesh, y_mesh, -z_mesh, alpha=1, linewidth=0, cmap='viridis', zorder=-1, vmin=self.zlim[0], vmax=self.zlim[1], rstride=1, cstride=1) # ax.plot_wireframe(x_mesh, y_mesh, -z_mesh, alpha=1, linewidth=0.05, color='black', rstride=1, cstride=1) pass # Lagrange points and bodies lagrange_points_df = load_lagrange_points_location() lagrange_point_nrs = ['L1', 'L2'] for idx, lagrange_point_nr in enumerate(lagrange_point_nrs): ax.scatter(lagrange_points_df[lagrange_point_nr]['x'], lagrange_points_df[lagrange_point_nr]['y'], lagrange_points_df[lagrange_point_nr]['z'], color='black', marker='x', zorder=idx) u = np.linspace(0, 2 * np.pi, 100) v = np.linspace(0, np.pi, 100) bodies_df = load_bodies_location() for idx, body in enumerate(bodies_df): x = bodies_df[body]['r'] * np.outer( np.cos(u), np.sin(v)) + bodies_df[body]['x'] y = bodies_df[body]['r'] * np.outer(np.sin(u), np.sin(v)) z = bodies_df[body]['r'] * np.outer(np.ones(np.size(u)), np.cos(v)) ax.plot_surface(x, y, z, color='black', zorder=2 + idx) ax.plot([-self.massParameter, 1 - self.massParameter], [0, 0], color='black') ax.set_xlim(self.xlim) ax.set_ylim(self.ylim) ax.set_zlim(self.zlim) # ax.set_title(str(azim)) plt.axis('off') plt.show() pass
def plot(self): colors = sns.color_palette("Blues", n_colors=6) # Plot: 3d overview fig = plt.figure(figsize=(7 * (1 + np.sqrt(5)) / 2, 7)) ax = fig.gca(projection='3d') # Plot both primaries u = np.linspace(0, 2 * np.pi, 100) v = np.linspace(0, np.pi, 100) bodies_df = load_bodies_location() for body in bodies_df: x = bodies_df[body]['r'] * np.outer( np.cos(u), np.sin(v)) + bodies_df[body]['x'] y = bodies_df[body]['r'] * np.outer(np.sin(u), np.sin(v)) z = bodies_df[body]['r'] * np.outer(np.ones(np.size(u)), np.cos(v)) ax.plot_surface(x, y, z, color='black') # Plot Lagrange points 1 and 2 lagrange_points_df = load_lagrange_points_location() lagrange_point_nrs = ['L1', 'L2'] for lagrange_point_nr in lagrange_point_nrs: ax.scatter3D(lagrange_points_df[lagrange_point_nr]['x'], lagrange_points_df[lagrange_point_nr]['y'], lagrange_points_df[lagrange_point_nr]['z'], color='black', marker='x', s=50) # ax.annotate('Moon', xy=(-0.002,0.004), # xytext=(-0.002, 0.04), fontsize=20, ha = 'center', va = 'top', # arrowprops=dict(arrowstyle = '->', connectionstyle = 'arc3,rad=0'), # ) # ax.annotate('$L_1$', xy=(-0.023, 0.012), # xytext=(-0.023, 0.04), fontsize=20, ha='center', va='top', # arrowprops=dict(arrowstyle='->', connectionstyle='arc3,rad=0'), # ) # ax.annotate('$L_2$', xy=(0.023, -0.004), # xytext=(0.023, 0.04), fontsize=20, ha='center', va='top', # arrowprops=dict(arrowstyle='->', connectionstyle='arc3,rad=0'), # ) # params = {'legend.fontsize': 16} # plt.rcParams.update(params) C = 3.1 # x_range = np.arange(0.7, 1.3, 0.001) # y_range = np.arange(-0.3, 0.3, 0.001) x_range = np.arange(0.8, 1.2, 0.001) y_range = np.arange(-0.2, 0.2, 0.001) X, Y = np.meshgrid(x_range, y_range) Z = cr3bp_velocity(X, Y, C) if Z.min() < 0: plt.contourf(X, Y, Z, 0, colors='black', alpha=0.05, zorder=1000) linewidth = 2 df = load_orbit('../../data/raw_equal_energy/horizontal_L1_577.txt') ax.plot(df['x'], df['y'], df['z'], color=sns.color_palette("viridis", 3)[0], alpha=0.75, linestyle='-', label='Horizontal Lyapunov', linewidth=linewidth) df = load_orbit('../../data/raw_equal_energy/halo_L1_799.txt') ax.plot(df['x'], df['y'], df['z'], color=sns.color_palette("viridis", 3)[2], alpha=0.75, linestyle='-', label='Halo', linewidth=linewidth) df = load_orbit('../../data/raw_equal_energy/vertical_L1_1163.txt') ax.plot(df['x'], df['y'], df['z'], color=sns.color_palette("viridis", 3)[1], alpha=0.75, linestyle='-', label='Vertical Lyapunov', linewidth=linewidth) ax.legend(frameon=True, loc='lower right') df = load_orbit('../../data/raw_equal_energy/horizontal_L2_760.txt') ax.plot(df['x'], df['y'], df['z'], color=sns.color_palette("viridis", 3)[0], alpha=0.75, linestyle='-', linewidth=linewidth) df = load_orbit('../../data/raw_equal_energy/vertical_L2_1299.txt') ax.plot(df['x'], df['y'], df['z'], color=sns.color_palette("viridis", 3)[1], alpha=0.75, linestyle='-', linewidth=linewidth) df = load_orbit('../../data/raw_equal_energy/halo_L2_651.txt') ax.plot(df['x'], df['y'], df['z'], color=sns.color_palette("viridis", 3)[2], alpha=0.75, linestyle='-', linewidth=linewidth) ax.set_xlabel('x [-]') ax.set_ylabel('y [-]') ax.set_zlabel('z [-]') ax.grid(True, which='both', ls=':') # ax.view_init(25, -60) ax.view_init(20, -60) # ax.set_xlim([0.7, 1.3]) # ax.set_ylim([-0.3, 0.3]) # ax.set_zlim([-0.3, 0.3]) ax.set_xlim([0.8, 1.2]) ax.set_ylim([-0.2, 0.2]) ax.set_zlim([-0.2, 0.2]) plt.tight_layout() # plt.show() # fig.savefig('../../../data/figures/family_of_equal_energy.png') if self.lowDPI: fig.savefig('../../data/figures/new_family_of_equal_energy.png', transparent=True, dpi=self.dpi) else: fig.savefig('../../data/figures/new_family_of_equal_energy.pdf', transparent=True) # tikz_save('../../../data/figures/family_of_equal_energy.tex') plt.close() pass
def plot_image_trajectories_with_angle(self, theta): line_width_near_heteroclinic = 2 print('Theta:') # for theta in self.thetaRangeList: print(theta) df_s = load_manifold_refactored('../../data/raw/poincare_sections/' + str(self.numberOfOrbitsPerManifold) + '/L2_' + self.orbitType + '_W_S_min_3.1_' + str(int(theta)) + '_full.txt') df_u = load_manifold_refactored('../../data/raw/poincare_sections/' + str(self.numberOfOrbitsPerManifold) + '/L1_' + self.orbitType + '_W_U_plus_3.1_' + str(int(theta)) + '_full.txt') fig = plt.figure(figsize=self.figSize) ax0 = fig.add_subplot(111, projection='3d') plot_alpha = 1 # Plot near-heteroclinic connection index_near_heteroclinic_s = int( self.minimumImpulse.loc[theta]['taus'] * self.numberOfOrbitsPerManifold) index_near_heteroclinic_u = int( self.minimumImpulse.loc[theta]['tauu'] * self.numberOfOrbitsPerManifold) portrait_s = [] portrait_u = [] for i in range(0, 5000, 10): portrait_s.append(df_s.xs(i).head(1)) portrait_u.append(df_u.xs(i).tail(1)) pass portrait_s = pd.concat(portrait_s) portrait_u = pd.concat(portrait_u) plt.plot(portrait_s['x'], portrait_s['y'], portrait_s['z'], color='g', linewidth=0.5) plt.plot(portrait_u['x'], portrait_u['y'], portrait_u['z'], color='r', linewidth=0.5) # for i in range(0, 5000, 10): # ax0.scatter(df_s.xs(i).head(1)['x'], df_s.xs(i).head(1)['y'], # df_s.xs(i).head(1)['z'], color='g', s=0.1) # ax0.scatter(df_u.xs(i).tail(1)['x'], df_u.xs(i).tail(1)['y'], # df_u.xs(i).tail(1)['z'], color='r', s=0.1) # (T1) ax0.plot(df_s.xs(index_near_heteroclinic_s)['x'], df_s.xs(index_near_heteroclinic_s)['y'], df_s.xs(index_near_heteroclinic_s)['z'], color='g', alpha=plot_alpha, linewidth=line_width_near_heteroclinic) ax0.plot(df_u.xs(index_near_heteroclinic_u)['x'], df_u.xs(index_near_heteroclinic_u)['y'], df_u.xs(index_near_heteroclinic_u)['z'], color='r', alpha=plot_alpha, linewidth=line_width_near_heteroclinic) # # (T4) # ax0.plot(df_s.xs(index_near_heteroclinic_s)['x'], -df_s.xs(index_near_heteroclinic_s)['y'], df_s.xs(index_near_heteroclinic_s)['z'], color='r', alpha=plot_alpha, linewidth=line_width_near_heteroclinic) # ax0.plot(df_u.xs(index_near_heteroclinic_u)['x'], -df_u.xs(index_near_heteroclinic_u)['y'], df_u.xs(index_near_heteroclinic_u)['z'], color='g', alpha=plot_alpha, linewidth=line_width_near_heteroclinic) # # # (T3) # ax0.plot(df_s.xs(index_near_heteroclinic_s)['x'], df_s.xs(index_near_heteroclinic_s)['y'], # -df_s.xs(index_near_heteroclinic_s)['z'], color='g', alpha=plot_alpha, # linewidth=line_width_near_heteroclinic) # ax0.plot(df_u.xs(index_near_heteroclinic_u)['x'], df_u.xs(index_near_heteroclinic_u)['y'], # -df_u.xs(index_near_heteroclinic_u)['z'], color='r', alpha=plot_alpha, # linewidth=line_width_near_heteroclinic) # # (T2) # ax0.plot(df_s.xs(index_near_heteroclinic_s)['x'], -df_s.xs(index_near_heteroclinic_s)['y'], # -df_s.xs(index_near_heteroclinic_s)['z'], color='r', alpha=plot_alpha, # linewidth=line_width_near_heteroclinic) # ax0.plot(df_u.xs(index_near_heteroclinic_u)['x'], -df_u.xs(index_near_heteroclinic_u)['y'], # -df_u.xs(index_near_heteroclinic_u)['z'], color='g', alpha=plot_alpha, # linewidth=line_width_near_heteroclinic) bodies_df = load_bodies_location() u = np.linspace(0, 2 * np.pi, 100) v = np.linspace(0, np.pi, 100) # for body in ['Moon']: for body in ['Earth', 'Moon']: x = bodies_df[body]['r'] * np.outer( np.cos(u), np.sin(v)) + bodies_df[body]['x'] y = bodies_df[body]['r'] * np.outer(np.sin(u), np.sin(v)) z = bodies_df[body]['r'] * np.outer(np.ones(np.size(u)), np.cos(v)) ax0.plot_surface(x, y, z, color='black') # Lagrange points and bodies lagrange_points_df = load_lagrange_points_location() lagrange_point_nrs = ['L1', 'L2'] for lagrange_point_nr in lagrange_point_nrs: ax0.scatter(lagrange_points_df[lagrange_point_nr]['x'], lagrange_points_df[lagrange_point_nr]['y'], lagrange_points_df[lagrange_point_nr]['z'], color='black', marker='x') # Create cubic bounding box to simulate equal aspect ratio max_range = np.array([ max(df_s['x'].max(), df_u['x'].max()) - min(df_s['x'].min(), df_u['x'].min()), max(df_s['y'].max(), df_u['y'].max()) - min(df_s['y'].min(), df_u['y'].min()), max(df_s['z'].max(), df_u['z'].max()) - min(df_s['z'].min(), df_u['z'].min()) ]).max() Xb = 0.3 * max_range * np.mgrid[-1:2:2, -1:2:2, -1:2:2][0].flatten( ) + 0.2 * (max(df_s['x'].max(), df_u['x'].max()) + min(df_s['x'].min(), df_u['x'].min())) Yb = 0.3 * max_range * np.mgrid[-1:2:2, -1:2:2, -1:2:2][1].flatten( ) + 0.5 * (max(df_s['y'].max(), df_u['y'].max()) + min(df_s['y'].min(), df_u['y'].min())) Zb = 0.3 * max_range * np.mgrid[-1:2:2, -1:2:2, -1:2:2][2].flatten( ) + 0.5 * (max(df_s['z'].max(), df_u['z'].max()) + min(df_s['z'].min(), df_u['z'].min())) # Comment or uncomment following both lines to test the fake bounding box: if self.orbitType != 'halo': for xb, yb, zb in zip(Xb, Yb, Zb): ax0.plot([xb], [yb], [zb], 'w') arc_length = 0.2 surface_alpha = 0.1 surface_color = 'black' x_range = np.arange(1 - self.massParameter - arc_length * 0.75, 1 - self.massParameter, 0.001) z_range = np.arange(-arc_length * 0.75, arc_length * 0.75, 0.001) x_mesh, z_mesh = np.meshgrid(x_range, z_range) y_mesh = -abs(x_mesh - (1 - self.massParameter)) / np.tan(35 * np.pi / 180) # Plot poincare plane ax0.plot_surface(x_mesh, y_mesh, z_mesh, alpha=surface_alpha, color=surface_color) ax0.plot_wireframe(x_mesh, y_mesh, z_mesh, color=surface_color, rstride=500, cstride=500, linewidth=1) # Plot line at angle plt.plot( [1 - self.massParameter, np.min(x_mesh)], [0, np.min(y_mesh)], [0, 0], color='k', linestyle=':', linewidth=1) # Plot line orthogonal to collinear points plt.plot([1 - self.massParameter, 1 - self.massParameter], [0, np.min(y_mesh)], [0, 0], color='k', linestyle=':', linewidth=1) # Plot line from primary to L2 plt.plot([-self.massParameter, lagrange_points_df['L2']['x']], [0, 0], [0, 0], color='k', linestyle=':', linewidth=1) # Indicate connection on plane ax0.scatter(df_u.xs(index_near_heteroclinic_u).tail(1)['x'], df_u.xs(index_near_heteroclinic_u).tail(1)['y'], df_u.xs(index_near_heteroclinic_u).tail(1)['z'], s=20, linewidth=line_width_near_heteroclinic, facecolors='none', edgecolors='r') # Set viewpoint ax0.set_xlim(lagrange_points_df['L1']['x'], lagrange_points_df['L2']['x']) ax0.set_ylim(-0.15, 0.05) ax0.set_zlim(-0.1, 0.1) print(ax0.azim) print(ax0.elev) # ax0.view_init(elev=15, azim=220) # Single line ax0.view_init(elev=5, azim=220) # View from Earth # ax0.view_init(elev=5, azim=340) # View from outside plt.tight_layout() fig.subplots_adjust(right=1.1) plt.axis('off') # plt.show() plt.savefig('../../data/figures/cover_page_angle.pdf', transparent=True) plt.close() pass
def plot_image_trajectories(self, theta): line_width_near_heteroclinic = 3 print('Theta:') # for theta in self.thetaRangeList: print(theta) df_s = load_manifold_refactored('../../data/raw/poincare_sections/' + str(self.numberOfOrbitsPerManifold) + '/L2_' + self.orbitType + '_W_S_min_3.1_' + str(int(theta)) + '_full.txt') df_u = load_manifold_refactored('../../data/raw/poincare_sections/' + str(self.numberOfOrbitsPerManifold) + '/L1_' + self.orbitType + '_W_U_plus_3.1_' + str(int(theta)) + '_full.txt') print(df_s) fig = plt.figure(figsize=self.figSize) ax0 = fig.add_subplot(111, projection='3d') plot_alpha = 1 # Plot near-heteroclinic connection index_near_heteroclinic_s = int( self.minimumImpulse.loc[theta]['taus'] * self.numberOfOrbitsPerManifold) index_near_heteroclinic_u = int( self.minimumImpulse.loc[theta]['tauu'] * self.numberOfOrbitsPerManifold) # for i in range(0, 5000, 50): # ax0.plot(df_s.xs(i)['x'], df_s.xs(i)['y'], # df_s.xs(i)['z'], color='g', alpha=plot_alpha, # linewidth=0.5) # ax0.plot(df_u.xs(i)['x'], df_u.xs(i)['y'], # df_u.xs(i)['z'], color='r', alpha=plot_alpha, # linewidth=0.5) # (T1) ax0.plot(df_s.xs(index_near_heteroclinic_s)['x'], df_s.xs(index_near_heteroclinic_s)['y'], df_s.xs(index_near_heteroclinic_s)['z'], color='g', alpha=plot_alpha, linewidth=line_width_near_heteroclinic) ax0.plot(df_u.xs(index_near_heteroclinic_u)['x'], df_u.xs(index_near_heteroclinic_u)['y'], df_u.xs(index_near_heteroclinic_u)['z'], color='r', alpha=plot_alpha, linewidth=line_width_near_heteroclinic) # # (T4) # ax0.plot(df_s.xs(index_near_heteroclinic_s)['x'], -df_s.xs(index_near_heteroclinic_s)['y'], df_s.xs(index_near_heteroclinic_s)['z'], color='r', alpha=plot_alpha, linewidth=line_width_near_heteroclinic) # ax0.plot(df_u.xs(index_near_heteroclinic_u)['x'], -df_u.xs(index_near_heteroclinic_u)['y'], df_u.xs(index_near_heteroclinic_u)['z'], color='g', alpha=plot_alpha, linewidth=line_width_near_heteroclinic) # # # (T3) # ax0.plot(df_s.xs(index_near_heteroclinic_s)['x'], df_s.xs(index_near_heteroclinic_s)['y'], # -df_s.xs(index_near_heteroclinic_s)['z'], color='g', alpha=plot_alpha, # linewidth=line_width_near_heteroclinic) # ax0.plot(df_u.xs(index_near_heteroclinic_u)['x'], df_u.xs(index_near_heteroclinic_u)['y'], # -df_u.xs(index_near_heteroclinic_u)['z'], color='r', alpha=plot_alpha, # linewidth=line_width_near_heteroclinic) # # (T2) # ax0.plot(df_s.xs(index_near_heteroclinic_s)['x'], -df_s.xs(index_near_heteroclinic_s)['y'], # -df_s.xs(index_near_heteroclinic_s)['z'], color='r', alpha=plot_alpha, # linewidth=line_width_near_heteroclinic) # ax0.plot(df_u.xs(index_near_heteroclinic_u)['x'], -df_u.xs(index_near_heteroclinic_u)['y'], # -df_u.xs(index_near_heteroclinic_u)['z'], color='g', alpha=plot_alpha, # linewidth=line_width_near_heteroclinic) bodies_df = load_bodies_location() u = np.linspace(0, 2 * np.pi, 100) v = np.linspace(0, np.pi, 100) # for body in ['Earth', 'Moon']: for body in ['Moon']: x = bodies_df[body]['r'] * np.outer( np.cos(u), np.sin(v)) + bodies_df[body]['x'] y = bodies_df[body]['r'] * np.outer(np.sin(u), np.sin(v)) z = bodies_df[body]['r'] * np.outer(np.ones(np.size(u)), np.cos(v)) ax0.plot_surface(x, y, z, color='black') # Lagrange points and bodies lagrange_points_df = load_lagrange_points_location() lagrange_point_nrs = ['L1', 'L2'] for lagrange_point_nr in lagrange_point_nrs: ax0.scatter(lagrange_points_df[lagrange_point_nr]['x'], lagrange_points_df[lagrange_point_nr]['y'], lagrange_points_df[lagrange_point_nr]['z'], color='black', marker='x') # Create cubic bounding box to simulate equal aspect ratio max_range = np.array([ max(df_s['x'].max(), df_u['x'].max()) - min(df_s['x'].min(), df_u['x'].min()), max(df_s['y'].max(), df_u['y'].max()) - min(df_s['y'].min(), df_u['y'].min()), max(df_s['z'].max(), df_u['z'].max()) - min(df_s['z'].min(), df_u['z'].min()) ]).max() Xb = 0.3 * max_range * np.mgrid[-1:2:2, -1:2:2, -1:2:2][0].flatten( ) + 0.2 * (max(df_s['x'].max(), df_u['x'].max()) + min(df_s['x'].min(), df_u['x'].min())) Yb = 0.3 * max_range * np.mgrid[-1:2:2, -1:2:2, -1:2:2][1].flatten( ) + 0.5 * (max(df_s['y'].max(), df_u['y'].max()) + min(df_s['y'].min(), df_u['y'].min())) Zb = 0.3 * max_range * np.mgrid[-1:2:2, -1:2:2, -1:2:2][2].flatten( ) + 0.5 * (max(df_s['z'].max(), df_u['z'].max()) + min(df_s['z'].min(), df_u['z'].min())) # Comment or uncomment following both lines to test the fake bounding box: if self.orbitType != 'halo': for xb, yb, zb in zip(Xb, Yb, Zb): ax0.plot([xb], [yb], [zb], 'w') # azim=150 # elev=25 print(ax0.azim) print(ax0.elev) ax0.view_init(elev=15, azim=220) # Single line # ax0.view_init(elev=20, azim=240) # Manifold lines plt.tight_layout() plt.axis('off') # plt.show() plt.savefig('../../data/figures/cover_page.pdf', transparent=True) plt.close() pass
def animate(self): fig = plt.figure() self.ax = fig.add_subplot(111, projection='3d') self.horizontalLyapunov = [ load_orbit('../../../data/raw/orbits/L' + str(1) + '_horizontal_' + str(self.orbitIds['horizontal'][1][self.cLevel]) + '_100.txt'), load_orbit('../../../data/raw/orbits/L' + str(2) + '_horizontal_' + str(self.orbitIds['horizontal'][2][self.cLevel]) + '_100.txt') ] self.verticalLyapunov = [ load_orbit('../../../data/raw/orbits/L' + str(1) + '_vertical_' + str(self.orbitIds['vertical'][1][self.cLevel]) + '_100.txt'), load_orbit('../../../data/raw/orbits/L' + str(2) + '_vertical_' + str(self.orbitIds['vertical'][2][self.cLevel]) + '_100.txt') ] self.halo = [ load_orbit('../../../data/raw/orbits/L' + str(1) + '_halo_' + str(self.orbitIds['halo'][1][self.cLevel]) + '_100.txt'), load_orbit('../../../data/raw/orbits/L' + str(2) + '_halo_' + str(self.orbitIds['halo'][2][self.cLevel]) + '_100.txt') ] self.lines = [ plt.plot([], [], color=self.orbitColor, alpha=self.orbitAlpha, marker='o', markevery=[-1])[0] for idx in range(6) ] # Text object to display absolute normalized time of trajectories within the manifolds self.timeText = self.ax.text2D(0.05, 0.05, s='$\|t\| \\approx 0$', transform=self.ax.transAxes, size=self.timeTextSize) # Plot zero velocity surface x_range = np.arange(self.xLim[0], self.xLim[1], 0.001) y_range = np.arange(self.yLim[0], self.yLim[1], 0.001) x_mesh, y_mesh = np.meshgrid(x_range, y_range) z_mesh = cr3bp_velocity(x_mesh, y_mesh, c_level) if z_mesh.min() < 0: plt.contour(x_mesh, y_mesh, z_mesh, [z_mesh.min(), 0], colors='black', alpha=0.3) # Plot both orbits for k in range(2): plt.plot(self.horizontalLyapunov[k]['x'], self.horizontalLyapunov[k]['y'], self.horizontalLyapunov[k]['z'], color=self.orbitColor, alpha=self.orbitAlpha, linewidth=self.orbitLinewidth, linestyle=':') plt.plot(self.verticalLyapunov[k]['x'], self.verticalLyapunov[k]['y'], self.verticalLyapunov[k]['z'], color=self.orbitColor, alpha=self.orbitAlpha, linewidth=self.orbitLinewidth, linestyle=':') plt.plot(self.halo[k]['x'], self.halo[k]['y'], self.halo[k]['z'], color=self.orbitColor, alpha=self.orbitAlpha, linewidth=self.orbitLinewidth, linestyle=':') # Plot both primaries u = np.linspace(0, 2 * np.pi, 100) v = np.linspace(0, np.pi, 100) bodies_df = load_bodies_location() for body in bodies_df: x = bodies_df[body]['r'] * np.outer( np.cos(u), np.sin(v)) + bodies_df[body]['x'] y = bodies_df[body]['r'] * np.outer(np.sin(u), np.sin(v)) z = bodies_df[body]['r'] * np.outer(np.ones(np.size(u)), np.cos(v)) self.ax.plot_surface(x, y, z, color='black') # Plot Lagrange points 1 and 2 lagrange_points_df = load_lagrange_points_location() lagrange_point_nrs = ['L1', 'L2'] for lagrange_point_nr in lagrange_point_nrs: self.ax.scatter3D(lagrange_points_df[lagrange_point_nr]['x'], lagrange_points_df[lagrange_point_nr]['y'], lagrange_points_df[lagrange_point_nr]['z'], color='black', marker='x', s=self.lagrangePointMarkerSize) title = 'Types of periodic libration point motion - Rotating spatial overview at C = ' + str( c_level) self.ax.set_xlim3d(self.xLim) self.ax.set_ylim3d(self.yLim) self.ax.set_zlim3d(self.zLim) self.ax.set_xlabel('x [-]') self.ax.set_ylabel('y [-]') self.ax.set_zlabel('z [-]') self.ax.grid(True, which='both', ls=':') fig.tight_layout() fig.subplots_adjust(top=0.9) plt.suptitle(title, size=self.suptitleSize) # Fix overlap between labels and ticks self.ax.xaxis._axinfo['label']['space_factor'] = 2.0 self.ax.yaxis._axinfo['label']['space_factor'] = 2.0 self.ax.zaxis._axinfo['label']['space_factor'] = 2.0 self.initialElevation = self.ax.elev self.initialAzimuth = self.ax.azim # Determine the maximum value of t t_max = 0 for lagrange_point_idx in [0, 1]: t_max = max( t_max, self.horizontalLyapunov[lagrange_point_idx].tail(1) ['time'].values[0]) t_max = max( t_max, self.verticalLyapunov[lagrange_point_idx].tail(1) ['time'].values[0]) t_max = max( t_max, self.halo[lagrange_point_idx].tail(1)['time'].values[0]) print('Maximum value for t = ' + str(t_max) + ', animation t: = ') # Introduce a new time-vector for linearly spaced time throughout the animation self.t = np.linspace(0, t_max, np.round(t_max / 0.005) + 1) animation_function = animation.FuncAnimation( fig, self.update_lines, init_func=self.initiate_lines, frames=len(self.t), interval=1, blit=True) empty_writer_object = animation.writers['ffmpeg'] animation_writer = empty_writer_object( fps=30, metadata=dict(artist='Koen Langemeijer')) file_name = '../../../data/animations/orbits/spatial_orbits_rotating_' + str( c_level) + '.mp4' animation_function.save(file_name, writer=animation_writer)
def plot_image_trajectories(self): line_width_near_heteroclinic = 1.5 print('Theta:') for theta in self.thetaRangeList: print(theta) df_s = load_manifold_refactored( '../../data/raw/poincare_sections/' + str(self.numberOfOrbitsPerManifold) + '/L2_' + self.orbitType + '_W_S_min_3.1_' + str(int(theta)) + '_full.txt') df_u = load_manifold_refactored( '../../data/raw/poincare_sections/' + str(self.numberOfOrbitsPerManifold) + '/L1_' + self.orbitType + '_W_U_plus_3.1_' + str(int(theta)) + '_full.txt') fig = plt.figure(figsize=self.figSize) ax0 = fig.add_subplot(111, projection='3d') if self.numberOfOrbitsPerManifold > 100: # Plot at max 100 lines range_step_size = int(self.numberOfOrbitsPerManifold / 100) else: range_step_size = 1 plot_alpha = 1 line_width = 0.5 # Plot near-heteroclinic connection try: index_near_heteroclinic_s = int( self.minimumImpulse.loc[theta]['tau1'] * self.numberOfOrbitsPerManifold) index_near_heteroclinic_u = int( self.minimumImpulse.loc[theta]['tau2'] * self.numberOfOrbitsPerManifold) # (T1) ax0.plot(df_s.xs(index_near_heteroclinic_s)['x'], df_s.xs(index_near_heteroclinic_s)['y'], df_s.xs(index_near_heteroclinic_s)['z'], color='g', alpha=plot_alpha, linewidth=line_width_near_heteroclinic) ax0.plot(df_u.xs(index_near_heteroclinic_u)['x'], df_u.xs(index_near_heteroclinic_u)['y'], df_u.xs(index_near_heteroclinic_u)['z'], color='r', alpha=plot_alpha, linewidth=line_width_near_heteroclinic) # (T4) ax0.plot(df_s.xs(index_near_heteroclinic_s)['x'], -df_s.xs(index_near_heteroclinic_s)['y'], df_s.xs(index_near_heteroclinic_s)['z'], color='r', alpha=plot_alpha, linewidth=line_width_near_heteroclinic) ax0.plot(df_u.xs(index_near_heteroclinic_u)['x'], -df_u.xs(index_near_heteroclinic_u)['y'], df_u.xs(index_near_heteroclinic_u)['z'], color='g', alpha=plot_alpha, linewidth=line_width_near_heteroclinic) if orbit_type != 'horizontal': # (T3) ax0.plot(df_s.xs(index_near_heteroclinic_s)['x'], df_s.xs(index_near_heteroclinic_s)['y'], -df_s.xs(index_near_heteroclinic_s)['z'], color='g', alpha=plot_alpha, linewidth=line_width_near_heteroclinic) ax0.plot(df_u.xs(index_near_heteroclinic_u)['x'], df_u.xs(index_near_heteroclinic_u)['y'], -df_u.xs(index_near_heteroclinic_u)['z'], color='r', alpha=plot_alpha, linewidth=line_width_near_heteroclinic) # (T2) ax0.plot(df_s.xs(index_near_heteroclinic_s)['x'], -df_s.xs(index_near_heteroclinic_s)['y'], -df_s.xs(index_near_heteroclinic_s)['z'], color='r', alpha=plot_alpha, linewidth=line_width_near_heteroclinic) ax0.plot(df_u.xs(index_near_heteroclinic_u)['x'], -df_u.xs(index_near_heteroclinic_u)['y'], -df_u.xs(index_near_heteroclinic_u)['z'], color='g', alpha=plot_alpha, linewidth=line_width_near_heteroclinic) pass connection_text = '$min(\Delta r) \quad \\forall \enskip \Delta V < 0.5$ \n' + \ '$\Delta V = \enskip $' + str(np.round(self.minimumImpulse.loc[theta]['dv'], 1)) + '\n' + \ '$\Delta r = \enskip $' + str(np.round(self.minimumImpulse.loc[theta]['dr'], 1)) ax0.text2D(0.0, 0.8, s=connection_text, horizontalalignment='left', verticalalignment='bottom', transform=ax0.transAxes, bbox=dict(boxstyle="round", fc="w")) except KeyError: pass bodies_df = load_bodies_location() u = np.linspace(0, 2 * np.pi, 100) v = np.linspace(0, np.pi, 100) x = bodies_df['Moon']['r'] * np.outer( np.cos(u), np.sin(v)) + bodies_df['Moon']['x'] y = bodies_df['Moon']['r'] * np.outer(np.sin(u), np.sin(v)) z = bodies_df['Moon']['r'] * np.outer(np.ones(np.size(u)), np.cos(v)) ax0.plot_surface(x, y, z, color='black') # Create cubic bounding box to simulate equal aspect ratio max_range = np.array([ max(df_s['x'].max(), df_u['x'].max()) - min(df_s['x'].min(), df_u['x'].min()), max(df_s['y'].max(), df_u['y'].max()) - min(df_s['y'].min(), df_u['y'].min()), max(df_s['z'].max(), df_u['z'].max()) - min(df_s['z'].min(), df_u['z'].min()) ]).max() Xb = 0.5 * max_range * np.mgrid[-1:2:2, -1:2:2, -1:2:2][0].flatten( ) + 0.5 * (max(df_s['x'].max(), df_u['x'].max()) + min(df_s['x'].min(), df_u['x'].min())) Yb = 0.5 * max_range * np.mgrid[-1:2:2, -1:2:2, -1:2:2][1].flatten( ) + 0.5 * (max(df_s['y'].max(), df_u['y'].max()) + min(df_s['y'].min(), df_u['y'].min())) Zb = 0.5 * max_range * np.mgrid[-1:2:2, -1:2:2, -1:2:2][2].flatten( ) + 0.5 * (max(df_s['z'].max(), df_u['z'].max()) + min(df_s['z'].min(), df_u['z'].min())) # Comment or uncomment following both lines to test the fake bounding box: for xb, yb, zb in zip(Xb, Yb, Zb): ax0.plot([xb], [yb], [zb], 'w') ax0.set_xlabel('x [-]') ax0.set_ylabel('y [-]') ax0.set_zlabel('z [-]') ax0.grid(True, which='both', ls=':') fig.tight_layout() fig.subplots_adjust(top=0.9) plt.suptitle( self.orbitTypeForTitle + ' near-heteroclinic cycle $\mathcal{W}^{U+} \cup \mathcal{W}^{S-}$ (C = 3.1, $\\theta$ = ' + str(theta) + '$^\circ$)', size=self.suptitleSize) # plt.show() plt.savefig('../../data/figures/poincare_sections/' + str(self.numberOfOrbitsPerManifold) + '/' + self.orbitType + '_3.1_heteroclinic_cycle_' + str(theta) + '.pdf', transparent=True) plt.close() pass
def plot_family(self): c_normalized = [(value - min(self.C)) / (max(self.C) - min(self.C)) for value in self.C] colors = matplotlib.colors.ListedColormap( sns.color_palette("viridis_r"))(c_normalized) # colors = matplotlib.colors.ListedColormap(sns.dark_palette("blue", reverse=True))(c_normalized) sm = plt.cm.ScalarMappable(cmap=matplotlib.colors.ListedColormap( sns.color_palette("viridis", len(self.C))), norm=plt.Normalize(vmin=min(self.C), vmax=max(self.C))) # sm = plt.cm.ScalarMappable(cmap=sns.dark_palette("blue", as_cmap=True, reverse=True), norm=plt.Normalize(vmin=min(self.C), vmax=max(self.C))) # clean the array of the scalar mappable sm._A = [] # Plot 1: 3d overview fig1 = plt.figure(figsize=self.figSize) ax1 = fig1.gca() # Plot 2: subplots if self.orbitType == 'horizontal': fig2 = plt.figure(figsize=(self.figSize[0], self.figSize[1] / 2)) ax2 = fig2.add_subplot(1, 2, 1, projection='3d') ax5 = fig2.add_subplot(1, 2, 2) else: fig2 = plt.figure(figsize=self.figSize) ax2 = fig2.add_subplot(2, 2, 1, projection='3d') ax3 = fig2.add_subplot(2, 2, 4) ax4 = fig2.add_subplot(2, 2, 3) ax5 = fig2.add_subplot(2, 2, 2) lagrange_points_df = load_lagrange_points_location() lagrange_point_nrs = ['L1', 'L2'] # Lagrange points and bodies for lagrange_point_nr in lagrange_point_nrs: ax1.scatter(lagrange_points_df[lagrange_point_nr]['x'], lagrange_points_df[lagrange_point_nr]['y'], color='black', marker='x') ax2.scatter(lagrange_points_df[lagrange_point_nr]['x'], lagrange_points_df[lagrange_point_nr]['y'], lagrange_points_df[lagrange_point_nr]['z'], color='black', marker='x') ax5.scatter(lagrange_points_df[lagrange_point_nr]['x'], lagrange_points_df[lagrange_point_nr]['y'], color='black', marker='x') if self.orbitType != 'horizontal': ax3.scatter(lagrange_points_df[lagrange_point_nr]['x'], lagrange_points_df[lagrange_point_nr]['z'], color='black', marker='x') ax4.scatter(lagrange_points_df[lagrange_point_nr]['y'], lagrange_points_df[lagrange_point_nr]['z'], color='black', marker='x') bodies_df = load_bodies_location() u = np.linspace(0, 2 * np.pi, 100) v = np.linspace(0, np.pi, 100) x = bodies_df['Moon']['r'] * np.outer( np.cos(u), np.sin(v)) + bodies_df['Moon']['x'] y = bodies_df['Moon']['r'] * np.outer(np.sin(u), np.sin(v)) z = bodies_df['Moon']['r'] * np.outer(np.ones(np.size(u)), np.cos(v)) ax1.contourf(x, y, z, colors='black') ax2.plot_surface(x, y, z, color='black') ax5.contourf(x, y, z, colors='black') if self.orbitType != 'horizontal': ax3.contourf(x, z, y, colors='black') ax4.contourf(y, z, x, colors='black') # Determine color for plot # colorOrderOfLinearInstability = ['whitesmoke', 'silver', 'dimgrey'] plot_alpha = 1 line_width = 0.5 # Plot every 100th member, including the ultimate member of the family spacing_factor = 100 orbitIdsPlot = list(range(0, len(self.C) - 1, spacing_factor)) if orbitIdsPlot[-1] != len(self.C) - 1: orbitIdsPlot.append(len(self.C) - 1) # Plot orbits for i in orbitIdsPlot: # plot_color = colorOrderOfLinearInstability[self.orderOfLinearInstability[i]] nan_correction = sum( [1 for nan in self.indexNanEntries if nan < i]) plot_color = colors[self.plotColorIndexBasedOnC[i - nan_correction]] df = load_orbit('../../data/raw/orbits/extended/L' + str(self.lagrangePointNr) + '_' + self.orbitType + '_' + str(i) + '.txt') ax1.plot(df['x'], df['y'], color=plot_color, alpha=plot_alpha, linewidth=line_width) ax2.plot(df['x'], df['y'], df['z'], color=plot_color, alpha=plot_alpha, linewidth=line_width) ax5.plot(df['x'], df['y'], color=plot_color, alpha=plot_alpha, linewidth=line_width) if self.orbitType != 'horizontal': ax3.plot(df['x'], df['z'], color=plot_color, alpha=plot_alpha, linewidth=line_width) ax4.plot(df['y'], df['z'], color=plot_color, alpha=plot_alpha, linewidth=line_width) # # Plot the bifurcations # for i in self.orbitIdBifurcations: # # plot_color = 'b' # nan_correction = sum([1 for nan in self.indexNanEntries if nan < i]) # plot_color = colors[self.plotColorIndexBasedOnC[i - nan_correction]] # df = load_orbit('../../data/raw/orbits/extended/L' + str(self.lagrangePointNr) + '_' + self.orbitType + '_' + str(i) + '.txt') # ax1.plot(df['x'], df['y'], color=plot_color, linewidth=3) # ax2.plot(df['x'], df['y'], df['z'], color=plot_color, linewidth=3) # ax5.plot(df['x'], df['y'], color=plot_color, linewidth=3) # if self.orbitType != 'horizontal': # ax3.plot(df['x'], df['z'], color=plot_color, linewidth=3) # ax4.plot(df['y'], df['z'], color=plot_color, linewidth=3) ax1.set_xlabel('x [-]') ax1.set_ylabel('y [-]') ax1.grid(True, which='both', ls=':') ax2.set_xlabel('x [-]') ax2.set_ylabel('y [-]') ax2.set_zlabel('z [-]') ax2.set_zlim([-1.2, 1.2]) ax2.grid(True, which='both', ls=':') ax2.view_init(30, -120) if self.orbitType != 'horizontal': ax3.set_xlabel('x [-]') ax3.set_ylabel('z [-]') ax3.set_ylim([-1.2, 1.2]) ax3.grid(True, which='both', ls=':') ax4.set_xlabel('y [-]') ax4.set_ylabel('z [-]') ax4.set_ylim([-1.2, 1.2]) ax4.grid(True, which='both', ls=':') ax5.set_xlabel('x [-]') ax5.set_ylabel('y [-]') ax5.grid(True, which='both', ls=':') fig2.tight_layout() if self.orbitType == 'horizontal': fig2.subplots_adjust(top=0.8) else: fig2.subplots_adjust(top=0.9) if self.orbitType != 'horizontal': cax, kw = matplotlib.colorbar.make_axes([ax2, ax3, ax4, ax5]) else: cax, kw = matplotlib.colorbar.make_axes([ax2, ax5]) cbar = plt.colorbar(sm, cax=cax, label='C [-]', **kw) plt.suptitle('$L_' + str(self.lagrangePointNr) + '$ ' + self.orbitTypeForTitle + ' - Orthographic projection', size=self.suptitleSize) fig1.suptitle('$L_' + str(self.lagrangePointNr) + '$ ' + self.orbitTypeForTitle + ': family', size=self.suptitleSize) fig2.savefig('../../data/figures/orbits/extended/L' + str(self.lagrangePointNr) + '_' + self.orbitType + '_family_subplots.pdf', transparent=True) plt.close(fig2) plt.close() pass
def plot_manifolds(self): line_width_near_heteroclinic = 2 color_near_heteroclinic = 'k' print('Theta:') for theta in self.thetaRangeList: print(theta) df_s = load_manifold_refactored( '../../data/raw/poincare_sections/' + str(self.numberOfOrbitsPerManifold) + '/L2_' + self.orbitType + '_W_S_min_3.1_' + str(int(theta)) + '_full.txt') df_u = load_manifold_refactored( '../../data/raw/poincare_sections/' + str(self.numberOfOrbitsPerManifold) + '/L1_' + self.orbitType + '_W_U_plus_3.1_' + str(int(theta)) + '_full.txt') fig = plt.figure(figsize=self.figSize) ax0 = fig.add_subplot(2, 2, 1, projection='3d') ax1 = fig.add_subplot(2, 2, 2) ax3 = fig.add_subplot(2, 2, 3) ax2 = fig.add_subplot(2, 2, 4) # ax0.set_aspect('equal') # ax1.set_aspect('equal') # ax2.set_aspect('equal') # ax3.set_aspect('equal') if self.numberOfOrbitsPerManifold > 100: # Plot at max 100 lines range_step_size = int(self.numberOfOrbitsPerManifold / 100) else: range_step_size = 1 plot_alpha = 1 line_width = 0.5 for i in range(0, self.numberOfOrbitsPerManifold, range_step_size): # Plot manifolds ax0.plot(df_u.xs(i)['x'], df_u.xs(i)['y'], df_u.xs(i)['z'], color=self.colorPaletteUnstable[i], alpha=plot_alpha, linewidth=line_width) ax0.plot(df_s.xs(i)['x'], df_s.xs(i)['y'], df_s.xs(i)['z'], color=self.colorPaletteStable[i], alpha=plot_alpha, linewidth=line_width) ax1.plot(df_s.xs(i)['x'], df_s.xs(i)['y'], color=self.colorPaletteStable[i], alpha=plot_alpha, linewidth=line_width) ax1.plot(df_u.xs(i)['x'], df_u.xs(i)['y'], color=self.colorPaletteUnstable[i], alpha=plot_alpha, linewidth=line_width) ax2.plot(df_s.xs(i)['x'], df_s.xs(i)['z'], color=self.colorPaletteStable[i], alpha=plot_alpha, linewidth=line_width) ax2.plot(df_u.xs(i)['x'], df_u.xs(i)['z'], color=self.colorPaletteUnstable[i], alpha=plot_alpha, linewidth=line_width) ax3.plot(df_s.xs(i)['y'], df_s.xs(i)['z'], color=self.colorPaletteStable[i], alpha=plot_alpha, linewidth=line_width) ax3.plot(df_u.xs(i)['y'], df_u.xs(i)['z'], color=self.colorPaletteUnstable[i], alpha=plot_alpha, linewidth=line_width) # Plot near-heteroclinic connection try: index_near_heteroclinic_s = int( self.minimumImpulse.loc[theta]['tau1'] * self.numberOfOrbitsPerManifold) index_near_heteroclinic_u = int( self.minimumImpulse.loc[theta]['tau2'] * self.numberOfOrbitsPerManifold) ax0.plot(df_s.xs(index_near_heteroclinic_s)['x'], df_s.xs(index_near_heteroclinic_s)['y'], df_s.xs(index_near_heteroclinic_s)['z'], color=color_near_heteroclinic, alpha=plot_alpha, linewidth=line_width_near_heteroclinic) ax0.plot(df_u.xs(index_near_heteroclinic_u)['x'], df_u.xs(index_near_heteroclinic_u)['y'], df_u.xs(index_near_heteroclinic_u)['z'], color=color_near_heteroclinic, alpha=plot_alpha, linewidth=line_width_near_heteroclinic) ax1.plot(df_s.xs(index_near_heteroclinic_s)['x'], df_s.xs(index_near_heteroclinic_s)['y'], color=color_near_heteroclinic, alpha=plot_alpha, linewidth=line_width_near_heteroclinic) ax1.plot(df_u.xs(index_near_heteroclinic_u)['x'], df_u.xs(index_near_heteroclinic_u)['y'], color=color_near_heteroclinic, alpha=plot_alpha, linewidth=line_width_near_heteroclinic) ax2.plot(df_s.xs(index_near_heteroclinic_s)['x'], df_s.xs(index_near_heteroclinic_s)['z'], color=color_near_heteroclinic, alpha=plot_alpha, linewidth=line_width_near_heteroclinic) ax2.plot(df_u.xs(index_near_heteroclinic_u)['x'], df_u.xs(index_near_heteroclinic_u)['z'], color=color_near_heteroclinic, alpha=plot_alpha, linewidth=line_width_near_heteroclinic) ax3.plot(df_s.xs(index_near_heteroclinic_s)['y'], df_s.xs(index_near_heteroclinic_s)['z'], color=color_near_heteroclinic, alpha=plot_alpha, linewidth=line_width_near_heteroclinic) ax3.plot(df_u.xs(index_near_heteroclinic_u)['y'], df_u.xs(index_near_heteroclinic_u)['z'], color=color_near_heteroclinic, alpha=plot_alpha, linewidth=line_width_near_heteroclinic) connection_text = '$\Delta \mathbf{V} = $' + str(np.round(self.minimumImpulse.loc[theta]['dv'], 1)) + 'm/s \n' + \ '$\Delta \mathbf{r} = $' + str(np.round(self.minimumImpulse.loc[theta]['dr'], 1)) + 'km' ax1.text(0.975, 0.075, connection_text, horizontalalignment='right', verticalalignment='bottom', transform=ax1.transAxes, bbox={ 'facecolor': 'navy', 'alpha': 0.1, 'pad': 3 }) except KeyError: pass bodies_df = load_bodies_location() u = np.linspace(0, 2 * np.pi, 100) v = np.linspace(0, np.pi, 100) x = bodies_df['Moon']['r'] * np.outer( np.cos(u), np.sin(v)) + bodies_df['Moon']['x'] y = bodies_df['Moon']['r'] * np.outer(np.sin(u), np.sin(v)) z = bodies_df['Moon']['r'] * np.outer(np.ones(np.size(u)), np.cos(v)) ax0.plot_surface(x, y, z, color='black') ax1.contourf(x, y, z, colors='black') ax2.contourf(x, z, y, colors='black') # ax3.contourf(y, z, x, colors='black') # Create cubic bounding box to simulate equal aspect ratio max_range = np.array([ max(df_s['x'].max(), df_u['x'].max()) - min(df_s['x'].min(), df_u['x'].min()), max(df_s['y'].max(), df_u['y'].max()) - min(df_s['y'].min(), df_u['y'].min()), max(df_s['z'].max(), df_u['z'].max()) - min(df_s['z'].min(), df_u['z'].min()) ]).max() Xb = 0.5 * max_range * np.mgrid[-1:2:2, -1:2:2, -1:2:2][0].flatten( ) + 0.5 * (max(df_s['x'].max(), df_u['x'].max()) + min(df_s['x'].min(), df_u['x'].min())) Yb = 0.5 * max_range * np.mgrid[-1:2:2, -1:2:2, -1:2:2][1].flatten( ) + 0.5 * (max(df_s['y'].max(), df_u['y'].max()) + min(df_s['y'].min(), df_u['y'].min())) Zb = 0.5 * max_range * np.mgrid[-1:2:2, -1:2:2, -1:2:2][2].flatten( ) + 0.5 * (max(df_s['z'].max(), df_u['z'].max()) + min(df_s['z'].min(), df_u['z'].min())) # Comment or uncomment following both lines to test the fake bounding box: for xb, yb, zb in zip(Xb, Yb, Zb): ax0.plot([xb], [yb], [zb], 'w') ax0.set_xlabel('x [-]') ax0.set_ylabel('y [-]') ax0.set_zlabel('z [-]') ax1.set_xlabel('x [-]') ax1.set_ylabel('y [-]') ax2.set_xlabel('x [-]') ax2.set_ylabel('z [-]') ax3.set_xlabel('y [-]') ax3.set_ylabel('z [-]') ax0.grid(True, which='both', ls=':') ax1.grid(True, which='both', ls=':') ax2.grid(True, which='both', ls=':') ax3.grid(True, which='both', ls=':') fig.tight_layout() fig.subplots_adjust(top=0.9) plt.suptitle( 'Near-heteroclinic connection for $min(\Delta r) \enskip \\forall \Delta V < 0.5$ (at $\mathcal{W}^{U+} \cup \mathcal{W}^{S-}$, C = 3.1, $\\theta$ = ' + str(theta) + '$^\circ$)', size=self.suptitleSize) # plt.show() plt.savefig('../../data/figures/poincare_sections/' + str(self.numberOfOrbitsPerManifold) + '/' + self.orbitType + '_3.1_heteroclinic_connection_' + str(theta) + '.pdf') plt.close() pass
def plot_result(self): color_palette_green = sns.dark_palette( 'green', n_colors=self.numberOfOrbitsPerManifold) color_palette_red = sns.dark_palette( 'red', n_colors=self.numberOfOrbitsPerManifold) plt.figure(figsize=(5 * (1 + np.sqrt(5)) / 2, 5)) gs = gridspec.GridSpec(2, 2) ax1 = plt.subplot(gs[0, :]) ax2 = plt.subplot(gs[1, 0]) ax3 = plt.subplot(gs[1, 1]) # Subplot 1: manifolds for i in range(self.numberOfOrbitsPerManifold): ax1.plot(self.WS.xs(i)['x'], self.WS.xs(i)['y'], color=color_palette_green[i], alpha=0.5) ax1.plot(self.WU.xs(i)['x'], self.WU.xs(i)['y'], color=color_palette_red[i], alpha=0.5) x_range = np.arange(ax1.get_xlim()[0], ax1.get_xlim()[1], 0.001) y_range = np.arange(ax1.get_ylim()[0] * 1.2, ax1.get_ylim()[1] * 1.2, 0.001) X, Y = np.meshgrid(x_range, y_range) Z = cr3bp_velocity(X, Y, self.C[0]) if Z.min() < 0: ax1.contourf(X, Y, Z, [Z.min(), 0], colors='black', alpha=0.2) if self.U_section == 2: # ax1.axvline(1 - self.massParameter, color='black') ax1.plot([1 - self.massParameter, 1 - self.massParameter], [-0.11, 0.01], color='black', linewidth=3) ax1.text(s='$\sum_2$', x=(1 - 0.5 * self.massParameter), y=0.01) bodies_df = load_bodies_location() u = np.linspace(0, 2 * np.pi, 100) v = np.linspace(0, np.pi, 100) x = bodies_df['Moon']['r'] * np.outer( np.cos(u), np.sin(v)) + bodies_df['Moon']['x'] y = bodies_df['Moon']['r'] * np.outer(np.sin(u), np.sin(v)) z = bodies_df['Moon']['r'] * np.outer(np.ones(np.size(u)), np.cos(v)) # ax1.scatter(x, y, color='black', s=1) ax1.contourf(x, y, z, [z.min(), 0], colors='black') ax1.grid(True, which='both', ls=':') ax1.set_title('$C_1 = ' + str(self.C[0]) + ', C_2 = ' + str(self.C[1]) + '$') ax1.set_aspect('equal', adjustable='box') # Subplot 2: poincare v_max = 2 if self.U_section in set([2, 3]): variable_axis = 'y' elif self.U_section in set([3, 4]): variable_axis = 'x' ax2.plot( self.poincareWS[abs(self.poincareWS[variable_axis + 'dot']) < v_max][variable_axis].values, self.poincareWS[abs(self.poincareWS[variable_axis + 'dot']) < v_max][variable_axis + 'dot'].values, color='g') ax2.plot( self.poincareWU[abs(self.poincareWU[variable_axis + 'dot']) < v_max][variable_axis].values, self.poincareWU[abs(self.poincareWU[variable_axis + 'dot']) < v_max][variable_axis + 'dot'].values, color='r') # Find entry of lowest difference in derivative of variable_axis (which is the variable with maximum spread in phase plane) s = set( np.round(self.poincareWS[variable_axis + 'dot'], self.roundOrderConnection)) intersections = list( s.intersection( np.round(self.poincareWU[variable_axis + 'dot'], self.roundOrderConnection))) poincare_w_s_in_v = self.poincareWS[np.round( self.poincareWS[variable_axis + 'dot'], self.roundOrderConnection).isin(intersections)] poincare_w_u_in_v = self.poincareWU[np.round( self.poincareWU[variable_axis + 'dot'], self.roundOrderConnection).isin(intersections)] # Use tuples to bind pairs of position and velocity subset = poincare_w_s_in_v[[variable_axis, variable_axis + 'dot']] tuples_w_s_in_v = [ tuple(np.round(x, self.roundOrderConnection)) for x in subset.values ] subset = poincare_w_u_in_v[[variable_axis, variable_axis + 'dot']] tuples_w_u_in_v = [ tuple(np.round(x, self.roundOrderConnection)) for x in subset.values ] s = set(tuples_w_s_in_v) intersections = list(s.intersection(tuples_w_u_in_v)) for intersection in intersections: poincare_temp = poincare_w_s_in_v[np.round( poincare_w_s_in_v[variable_axis], self.roundOrderConnection) == intersection[0]] poincare_temp = poincare_temp[np.round( poincare_temp[variable_axis + 'dot'], self.roundOrderConnection) == intersection[1]] idx_s = int(poincare_temp.index.values) poincare_temp = poincare_w_u_in_v[np.round( poincare_w_u_in_v[variable_axis], self.roundOrderConnection) == intersection[0]] poincare_temp = poincare_temp[np.round( poincare_temp[variable_axis + 'dot'], self.roundOrderConnection) == intersection[1]] idx_u = int(poincare_temp.index.values) ax2.scatter(self.poincareWS[variable_axis][idx_s], self.poincareWS[variable_axis + 'dot'][idx_s], color='black') ax2.scatter(self.poincareWU[variable_axis][idx_u], self.poincareWU[variable_axis + 'dot'][idx_u], color='black') ax1.plot(self.WS.xs(idx_s)['x'], self.WS.xs(idx_s)['y'], color='black') ax1.plot(self.WU.xs(idx_u)['x'], self.WU.xs(idx_u)['y'], color='black') ax2.set_xlabel('$' + variable_axis + '$') ax2.set_ylabel('$\dot{' + variable_axis + '}$') ax2.set_ylim([-1.5, 1.5]) ax2.grid(True, which='both', ls=':') title = '$\sum_' + str(self.U_section) + '$' ax2.set_title(title) # Subplot 3: x error # ax3.axhline(abs(self.poincareWS['y'][46] - self.poincareWU['y'][65])) # ax3.axhline(abs(self.poincareWS['y'][37] - self.poincareWU['y'][77])) # ax3.axhline(abs(self.poincareWS['ydot'][46] - self.poincareWU['ydot'][65])) # ax3.axhline(abs(self.poincareWS['ydot'][37] - self.poincareWU['ydot'][77])) if self.U_section == (2 or 3): ax3.semilogy(abs((1 - self.massParameter) - self.poincareWS['x'].values), color='g') ax3.semilogy(abs((1 - self.massParameter) - self.poincareWU['x'].values), color='r') ax3.set_ylabel('$\| x - (1-\mu) \|$') elif self.U_section == (1 or 4): ax3.semilogy(abs(self.poincareWS['y'].values), color='g') ax3.semilogy(abs(self.poincareWU['y'].values), color='r') ax3.set_ylabel('$\| y \|$') ax3.set_xlabel('orbitId [-]') ax3.grid(True, which='both', ls=':') plt.tight_layout() # plt.savefig('../../data/figures/heteroclinic_connection.pdf') # plt.savefig('../../data/figures/homoclinic_connection.pdf') pass
def animate(self): self.W_S_plus = [ load_manifold_refactored( '../../../data/raw/manifolds/refined_for_c/L' + str(1) + '_' + self.orbitType + '_' + str(self.orbitIds[0]) + '_W_S_plus.txt'), load_manifold_refactored( '../../../data/raw/manifolds/refined_for_c/L' + str(2) + '_' + self.orbitType + '_' + str(self.orbitIds[1]) + '_W_S_plus.txt') ] self.W_S_min = [ load_manifold_refactored( '../../../data/raw/manifolds/refined_for_c/L' + str(1) + '_' + self.orbitType + '_' + str(self.orbitIds[0]) + '_W_S_min.txt'), load_manifold_refactored( '../../../data/raw/manifolds/refined_for_c/L' + str(2) + '_' + self.orbitType + '_' + str(self.orbitIds[1]) + '_W_S_min.txt') ] self.W_U_plus = [ load_manifold_refactored( '../../../data/raw/manifolds/refined_for_c/L' + str(1) + '_' + self.orbitType + '_' + str(self.orbitIds[0]) + '_W_U_plus.txt'), load_manifold_refactored( '../../../data/raw/manifolds/refined_for_c/L' + str(2) + '_' + self.orbitType + '_' + str(self.orbitIds[1]) + '_W_U_plus.txt') ] self.W_U_min = [ load_manifold_refactored( '../../../data/raw/manifolds/refined_for_c/L' + str(1) + '_' + self.orbitType + '_' + str(self.orbitIds[0]) + '_W_U_min.txt'), load_manifold_refactored( '../../../data/raw/manifolds/refined_for_c/L' + str(2) + '_' + self.orbitType + '_' + str(self.orbitIds[1]) + '_W_U_min.txt') ] self.numberOfOrbitsPerManifold = len( set(self.W_S_plus[0].index.get_level_values(0))) color_palette_green = sns.dark_palette( 'green', n_colors=self.numberOfOrbitsPerManifold) color_palette_red = sns.dark_palette( 'red', n_colors=self.numberOfOrbitsPerManifold) self.lines = [ self.ax.plot([], [], color=color_palette_red[idx], alpha=self.orbitAlpha)[0] for idx in range(self.numberOfOrbitsPerManifold) ] self.lines.extend([ self.ax.plot([], [], color=color_palette_green[idx], alpha=self.orbitAlpha)[0] for idx in range(self.numberOfOrbitsPerManifold) ]) self.lines.extend([ self.ax.plot([], [], color=color_palette_red[idx], alpha=self.orbitAlpha)[0] for idx in range(self.numberOfOrbitsPerManifold) ]) self.lines.extend([ self.ax.plot([], [], color=color_palette_green[idx], alpha=self.orbitAlpha)[0] for idx in range(self.numberOfOrbitsPerManifold) ]) self.lines.extend([ self.ax.plot([], [], color=color_palette_red[idx], alpha=self.orbitAlpha)[0] for idx in range(self.numberOfOrbitsPerManifold) ]) self.lines.extend([ self.ax.plot([], [], color=color_palette_green[idx], alpha=self.orbitAlpha)[0] for idx in range(self.numberOfOrbitsPerManifold) ]) self.lines.extend([ self.ax.plot([], [], color=color_palette_green[idx], alpha=self.orbitAlpha)[0] for idx in range(self.numberOfOrbitsPerManifold) ]) self.lines.extend([ self.ax.plot([], [], color=color_palette_red[idx], alpha=self.orbitAlpha)[0] for idx in range(self.numberOfOrbitsPerManifold) ]) # Text object to display absolute normalized time of trajectories within the manifolds self.timeText = self.ax.text2D(0.05, 0.05, s='$\|t\| \\approx 0$', transform=self.ax.transAxes, size=self.timeTextSize) # Plot zero velocity surface x_range = np.arange(self.xLim[0], self.xLim[1], 0.001) y_range = np.arange(self.yLim[0], self.yLim[1], 0.001) x_mesh, y_mesh = np.meshgrid(x_range, y_range) z_mesh = cr3bp_velocity(x_mesh, y_mesh, self.cLevel) if z_mesh.min() < 0: self.ax.contour(x_mesh, y_mesh, z_mesh, [z_mesh.min(), 0], colors='black', alpha=0.3) # Plot both orbits for k in range(2): orbit_df = load_orbit('../../../data/raw/orbits/refined_for_c/L' + str(k + 1) + '_' + self.orbitType + '_' + str(self.orbitIds[k]) + '.txt') self.ax.plot(orbit_df['x'], orbit_df['y'], orbit_df['z'], color=self.orbitColor, alpha=self.orbitAlpha, linewidth=self.orbitLinewidth) # Plot both primaries u = np.linspace(0, 2 * np.pi, 100) v = np.linspace(0, np.pi, 100) bodies_df = load_bodies_location() for body in bodies_df: x = bodies_df[body]['r'] * np.outer( np.cos(u), np.sin(v)) + bodies_df[body]['x'] y = bodies_df[body]['r'] * np.outer(np.sin(u), np.sin(v)) z = bodies_df[body]['r'] * np.outer(np.ones(np.size(u)), np.cos(v)) self.ax.plot_surface(x, y, z, color='black') # Plot Lagrange points 1 and 2 lagrange_points_df = load_lagrange_points_location() lagrange_point_nrs = ['L1', 'L2'] for lagrange_point_nr in lagrange_point_nrs: self.ax.scatter3D(lagrange_points_df[lagrange_point_nr]['x'], lagrange_points_df[lagrange_point_nr]['y'], lagrange_points_df[lagrange_point_nr]['z'], color='black', marker='x', s=self.lagrangePointMarkerSize) title = self.orbitTypeForTitle + ' $\{ \mathcal{W}^{S \pm}, \mathcal{W}^{U \pm} \}$ - Orthographic projection (C = ' + str( c_level) + ')' # self.ax.set_xlim3d(self.xLim) # self.ax.set_ylim3d(self.yLim) # self.ax.set_zlim3d(self.zLim) self.ax.set_xlim(self.xLim) self.ax.set_ylim(self.yLim) self.ax.set_zlim(self.zLim) self.ax.axis('off') # fig.tight_layout() self.fig.subplots_adjust(top=0.9) self.fig.suptitle(title, size=self.suptitleSize) self.initialElevation = self.ax.elev self.initialAzimuth = self.ax.azim # Determine the maximum value of t t_max = 0 for lagrange_point_idx in [0, 1]: for index in range(self.numberOfOrbitsPerManifold): t_max = max( t_max, abs(self.W_S_plus[lagrange_point_idx].xs(index).head( 1).index.values[0])) t_max = max( t_max, abs(self.W_S_min[lagrange_point_idx].xs(index).head( 1).index.values[0])) t_max = max( t_max, abs(self.W_U_plus[lagrange_point_idx].xs(index).tail( 1).index.values[0])) t_max = max( t_max, abs(self.W_U_min[lagrange_point_idx].xs(index).tail( 1).index.values[0])) print('Maximum value for t = ' + str(t_max) + ', animation t: = ') # Introduce a new time-vector for linearly spaced time throughout the animation self.t = np.linspace(0, t_max, np.round(t_max / 0.01) + 1) self.animation_function = animation.FuncAnimation( self.fig, self.update_lines, init_func=self.initiate_lines, frames=len(self.t), interval=1, blit=True) self.empty_writer_object = animation.writers['ffmpeg'] self.animation_writer = self.empty_writer_object( fps=30, metadata=dict(artist='Koen Langemeijer')) self.file_name = '../../../data/animations/manifolds/spatial_manifolds_rotating_no_axes_' + self.orbitType + '_' + str( self.cLevel) + '.mp4' self.animation_function.save(self.file_name, writer=self.animation_writer)
def animate(self): color_palette_green = sns.dark_palette( 'green', n_colors=self.numberOfOrbitsPerManifold) color_palette_red = sns.dark_palette( 'red', n_colors=self.numberOfOrbitsPerManifold) self.lines = [ self.ax.plot([], [], color='red', linewidth=self.orbitLinewidth, alpha=self.orbitAlpha)[0], self.ax.plot([], [], color='green', linewidth=self.orbitLinewidth, alpha=self.orbitAlpha)[0] ] # Text object to display absolute normalized time of trajectories within the manifolds self.timeText = self.ax.text2D(0.05, 0.05, s='$\|t\| \\approx 0$', transform=self.ax.transAxes, size=self.timeTextSize) # Plot zero velocity surface x_range = np.arange(self.xLim[0], self.xLim[1], 0.001) y_range = np.arange(self.yLim[0], self.yLim[1], 0.001) x_mesh, y_mesh = np.meshgrid(x_range, y_range) z_mesh = cr3bp_velocity(x_mesh, y_mesh, self.cLevel) if z_mesh.min() < 0: # plt.contour(x_mesh, y_mesh, z_mesh, [z_mesh.min(), 0], colors='black', alpha=0.3) self.ax.contour(x_mesh, y_mesh, z_mesh, list(np.linspace(z_mesh.min(), 0, 10)), cmap='gist_gray_r', alpha=0.5) # Plot both orbits for k in range(2): orbit_df = load_orbit( '../../../data/raw/orbits/refined_for_c/L' + str(k + 1) + '_' + self.orbitType + '_' + str(self.orbitIds[self.orbitType][k + 1][self.cLevel]) + '.txt') self.ax.plot(orbit_df['x'], orbit_df['y'], orbit_df['z'], color=self.orbitColor, alpha=self.orbitAlpha, linewidth=2, linestyle=':') # Plot both primaries u = np.linspace(0, 2 * np.pi, 100) v = np.linspace(0, np.pi, 100) bodies_df = load_bodies_location() for body in bodies_df: x = bodies_df[body]['r'] * np.outer( np.cos(u), np.sin(v)) + bodies_df[body]['x'] y = bodies_df[body]['r'] * np.outer(np.sin(u), np.sin(v)) z = bodies_df[body]['r'] * np.outer(np.ones(np.size(u)), np.cos(v)) self.ax.plot_surface(x, y, z, color='black') # Plot Lagrange points 1 and 2 lagrange_points_df = load_lagrange_points_location() lagrange_point_nrs = ['L1', 'L2'] for lagrange_point_nr in lagrange_point_nrs: self.ax.scatter3D(lagrange_points_df[lagrange_point_nr]['x'], lagrange_points_df[lagrange_point_nr]['y'], lagrange_points_df[lagrange_point_nr]['z'], color='black', marker='x', s=self.lagrangePointMarkerSize) title = self.orbitTypeForTitle + ' $\{ \mathcal{W}^{S \pm}, \mathcal{W}^{U \pm} \}$ - Orthographic projection (C = ' + str( self.cLevel) + ')' self.ax.set_xlim(self.xLim) self.ax.set_ylim(self.yLim) self.ax.set_zlim(self.zLim) self.ax.set_xlabel('x [-]') self.ax.set_ylabel('y [-]') self.ax.set_zlabel('z [-]') self.ax.grid(True, which='both', ls=':') # self.fig.tight_layout() self.fig.subplots_adjust(top=0.9) self.fig.suptitle(title, size=self.suptitleSize) # Fix overlap between labels and ticks self.ax.xaxis._axinfo['label']['space_factor'] = 6.0 self.ax.yaxis._axinfo['label']['space_factor'] = 6.0 self.ax.zaxis._axinfo['label']['space_factor'] = 6.0 # Determine the maximum value of t t_max = max(abs(self.W_U_plus.index)) + max(abs(self.W_S_min.index)) print('Maximum value for unstable = ' + str(max(abs(self.W_U_plus.index)))) print('Maximum value for stable = ' + str(max(abs(self.W_S_min.index)))) print('Maximum value for t = ' + str(t_max) + ', animation t: = ') # Introduce a new time-vector for linearly spaced time throughout the animation self.t = np.linspace(0, t_max, 150) self.animation_function = animation.FuncAnimation( self.fig, self.update_lines, init_func=self.initiate_lines, frames=len(self.t), interval=1, blit=True) self.empty_writer_object = animation.writers['ffmpeg'] self.animation_writer = self.empty_writer_object( fps=30, metadata=dict(artist='Koen Langemeijer')) self.file_name = '../../../data/animations/natural_connections/spatial_heteroclinic_' + self.orbitType + '_' + str( int(self.theta)) + '.mp4' self.animation_function.save(self.file_name, writer=self.animation_writer)
def animate(self): fig = plt.figure() ax = fig.add_subplot(111, projection='3d') self.W_S_plus = [load_manifold('../../../data/raw/manifolds/L' + str(1) + '_' + self.orbitType + '_' + str(self.orbitIds[0]) + '_W_S_plus.txt'), load_manifold('../../../data/raw/manifolds/L' + str(2) + '_' + self.orbitType + '_' + str(self.orbitIds[1]) + '_W_S_plus.txt')] self.W_S_min = [load_manifold('../../../data/raw/manifolds/L' + str(1) + '_' + self.orbitType + '_' + str(self.orbitIds[0]) + '_W_S_min.txt'), load_manifold('../../../data/raw/manifolds/L' + str(2) + '_' + self.orbitType + '_' + str(self.orbitIds[1]) + '_W_S_min.txt')] self.W_U_plus = [load_manifold('../../../data/raw/manifolds/L' + str(1) + '_' + self.orbitType + '_' + str(self.orbitIds[0]) + '_W_U_plus.txt'), load_manifold('../../../data/raw/manifolds/L' + str(2) + '_' + self.orbitType + '_' + str(self.orbitIds[1]) + '_W_U_plus.txt')] self.W_U_min = [load_manifold('../../../data/raw/manifolds/L' + str(1) + '_' + self.orbitType + '_' + str(self.orbitIds[0]) + '_W_U_min.txt'), load_manifold('../../../data/raw/manifolds/L' + str(2) + '_' + self.orbitType + '_' + str(self.orbitIds[1]) + '_W_U_min.txt')] self.numberOfOrbitsPerManifold = len(set(self.W_S_plus[0].index.get_level_values(0))) color_palette_green = sns.dark_palette('green', n_colors=self.numberOfOrbitsPerManifold) color_palette_red = sns.dark_palette('red', n_colors=self.numberOfOrbitsPerManifold) self.lines = [plt.plot([], [], color=color_palette_red[idx], alpha=self.orbitAlpha)[0] for idx in range(self.numberOfOrbitsPerManifold)] self.lines.extend([plt.plot([], [], color=color_palette_green[idx], alpha=self.orbitAlpha)[0] for idx in range(self.numberOfOrbitsPerManifold)]) self.lines.extend([plt.plot([], [], color=color_palette_red[idx], alpha=self.orbitAlpha)[0] for idx in range(self.numberOfOrbitsPerManifold)]) self.lines.extend([plt.plot([], [], color=color_palette_green[idx], alpha=self.orbitAlpha)[0] for idx in range(self.numberOfOrbitsPerManifold)]) self.lines.extend([plt.plot([], [], color=color_palette_red[idx], alpha=self.orbitAlpha)[0] for idx in range(self.numberOfOrbitsPerManifold)]) self.lines.extend([plt.plot([], [], color=color_palette_green[idx], alpha=self.orbitAlpha)[0] for idx in range(self.numberOfOrbitsPerManifold)]) self.lines.extend([plt.plot([], [], color=color_palette_green[idx], alpha=self.orbitAlpha)[0] for idx in range(self.numberOfOrbitsPerManifold)]) self.lines.extend([plt.plot([], [], color=color_palette_red[idx], alpha=self.orbitAlpha)[0] for idx in range(self.numberOfOrbitsPerManifold)]) # Text object to display absolute normalized time of trajectories within the manifolds self.timeText = ax.text2D(0.05, 0.05, s='$\|t\| \\approx 0$', transform=ax.transAxes, size=self.timeTextSize) # Plot zero velocity surface x_range = np.arange(self.xLim[0], self.xLim[1], 0.001) y_range = np.arange(self.yLim[0], self.yLim[1], 0.001) x_mesh, y_mesh = np.meshgrid(x_range, y_range) z_mesh = cr3bp_velocity(x_mesh, y_mesh, c_level) if z_mesh.min() < 0: plt.contour(x_mesh, y_mesh, z_mesh, [z_mesh.min(), 0], colors='black', alpha=0.3) # Plot both orbits for k in range(2): orbit_df = load_orbit('../../../data/raw/orbits/L' + str(k+1) + '_' + self.orbitType + '_' + str(self.orbitIds[k]) + '.txt') plt.plot(orbit_df['x'], orbit_df['y'], orbit_df['z'], color=self.orbitColor, alpha=self.orbitAlpha, linewidth=self.orbitLinewidth) # Plot both primaries u = np.linspace(0, 2 * np.pi, 100) v = np.linspace(0, np.pi, 100) bodies_df = load_bodies_location() for body in bodies_df: x = bodies_df[body]['r'] * np.outer(np.cos(u), np.sin(v)) + bodies_df[body]['x'] y = bodies_df[body]['r'] * np.outer(np.sin(u), np.sin(v)) z = bodies_df[body]['r'] * np.outer(np.ones(np.size(u)), np.cos(v)) ax.plot_surface(x, y, z, color='black') # Plot Lagrange points 1 and 2 lagrange_points_df = load_lagrange_points_location() lagrange_point_nrs = ['L1', 'L2'] for lagrange_point_nr in lagrange_point_nrs: ax.scatter3D(lagrange_points_df[lagrange_point_nr]['x'], lagrange_points_df[lagrange_point_nr]['y'], lagrange_points_df[lagrange_point_nr]['z'], color='black', marker='x', s=self.lagrangePointMarkerSize) title = self.orbitTypeForTitle + ' $\{ \mathcal{W}^{S \pm}, \mathcal{W}^{U \pm} \}$ - Spatial overview at C = ' + str(c_level) ax.set_xlim3d(self.xLim) ax.set_ylim3d(self.yLim) ax.set_zlim3d(self.zLim) ax.set_xlabel('x [-]') ax.set_ylabel('y [-]') ax.set_zlabel('z [-]') ax.grid(True, which='both', ls=':') fig.tight_layout() fig.subplots_adjust(top=0.9) plt.suptitle(title, size=self.suptitleSize) # Fix overlap between labels and ticks ax.xaxis._axinfo['label']['space_factor'] = 6.0 ax.yaxis._axinfo['label']['space_factor'] = 6.0 ax.zaxis._axinfo['label']['space_factor'] = 6.0 # Determine the maximum value of t t_max = 0 for lagrange_point_idx in [0, 1]: for index in range(self.numberOfOrbitsPerManifold): t_max = max(t_max, abs(self.W_S_plus[lagrange_point_idx].xs(index).tail(1).index.values[0])) t_max = max(t_max, abs(self.W_S_min[lagrange_point_idx].xs(index).tail(1).index.values[0])) t_max = max(t_max, abs(self.W_U_plus[lagrange_point_idx].xs(index).tail(1).index.values[0])) t_max = max(t_max, abs(self.W_U_min[lagrange_point_idx].xs(index).tail(1).index.values[0])) print('Maximum value for t = ' + str(t_max) + ', animation t: = ') # Introduce a new time-vector for linearly spaced time throughout the animation self.t = np.linspace(0, t_max, np.round(t_max / 0.04) + 1) animation_function = animation.FuncAnimation(fig, self.update_lines, init_func=self.initiate_lines, frames=len(self.t), interval=1, blit=True) # # # Determine the maximum number of frames # number_of_frames = 0 # for lagrange_point_idx in [0, 1]: # for index in range(self.numberOfOrbitsPerManifold): # number_of_frames = max(number_of_frames, len(self.W_S_plus[lagrange_point_idx].xs(index)['x'])) # number_of_frames = max(number_of_frames, len(self.W_S_min[lagrange_point_idx].xs(index)['x'])) # number_of_frames = max(number_of_frames, len(self.W_U_plus[lagrange_point_idx].xs(index)['x'])) # number_of_frames = max(number_of_frames, len(self.W_U_min[lagrange_point_idx].xs(index)['x'])) # # animation_function = animation.FuncAnimation(fig, self.update_lines, init_func=self.initiate_lines, # frames=int(number_of_frames), interval=1, blit=True) empty_writer_object = animation.writers['ffmpeg'] animation_writer = empty_writer_object(fps=30, metadata=dict(artist='Koen Langemeijer')) file_name = '../../../data/animations/manifolds/spatial_manifolds_' + orbit_type + '_' + str(c_level) + '.mp4' animation_function.save(file_name, writer=animation_writer)
def plot_horizontal_to_halo(self): fig = plt.figure(figsize=self.figSize) ax1 = fig.add_subplot(2, 2, 1, projection='3d') ax2 = fig.add_subplot(2, 2, 2) ax3 = fig.add_subplot(2, 2, 3) ax4 = fig.add_subplot(2, 2, 4) horizontal_color = self.plottingColors['tripleLine'][2] halo_color = self.plottingColors['tripleLine'][0] # Plot bifurcations line_width = 2 plot_alpha = 1 df = load_orbit('../../data/raw/orbits/L1_horizontal_' + str(self.horizontalBifurcations[0]) + '.txt') l1, = ax1.plot(df['x'], df['y'], df['z'], color=horizontal_color, alpha=plot_alpha, linewidth=1, label='Horizontal Lyapunov') ax1.plot(df['x'], df['y'], df['z'], color=horizontal_color, alpha=plot_alpha, linewidth=line_width) ax2.plot(df['x'], df['y'], color=horizontal_color, alpha=plot_alpha, linewidth=line_width) ax3.plot(df['y'], df['z'], color=horizontal_color, alpha=plot_alpha, linewidth=line_width) ax4.plot(df['x'], df['z'], color=horizontal_color, alpha=plot_alpha, linewidth=line_width) number_of_orbits = 10 line_width = 1 plot_alpha = 0.5 for i in [ int(i) for i in (np.linspace(1, self.haloMaxId, number_of_orbits)) ]: df = load_orbit('../../data/raw/orbits/L1_halo_' + str(i) + '.txt') l2, = ax1.plot(df['x'], df['y'], df['z'], color=halo_color, alpha=plot_alpha, linewidth=line_width, label='Halo') ax2.plot(df['x'], df['y'], color=halo_color, alpha=plot_alpha, linewidth=line_width) ax3.plot(df['y'], df['z'], color=halo_color, alpha=plot_alpha, linewidth=line_width) ax4.plot(df['x'], df['z'], color=halo_color, alpha=plot_alpha, linewidth=line_width) # Lagrange points and bodies lagrange_points_df = load_lagrange_points_location() lagrange_point_nrs = ['L1', 'L2'] for lagrange_point_nr in lagrange_point_nrs: ax1.scatter(lagrange_points_df[lagrange_point_nr]['x'], lagrange_points_df[lagrange_point_nr]['y'], lagrange_points_df[lagrange_point_nr]['z'], color='black', marker='x') ax2.scatter(lagrange_points_df[lagrange_point_nr]['x'], lagrange_points_df[lagrange_point_nr]['y'], color='black', marker='x') ax3.scatter(lagrange_points_df[lagrange_point_nr]['y'], lagrange_points_df[lagrange_point_nr]['z'], color='black', marker='x') ax4.scatter(lagrange_points_df[lagrange_point_nr]['x'], lagrange_points_df[lagrange_point_nr]['z'], color='black', marker='x') bodies_df = load_bodies_location() u = np.linspace(0, 2 * np.pi, 100) v = np.linspace(0, np.pi, 100) for body in ['Moon']: x = bodies_df[body]['r'] * np.outer( np.cos(u), np.sin(v)) + bodies_df[body]['x'] y = bodies_df[body]['r'] * np.outer(np.sin(u), np.sin(v)) z = bodies_df[body]['r'] * np.outer(np.ones(np.size(u)), np.cos(v)) ax1.plot_surface(x, y, z, color='black') ax2.contourf(x, y, z, colors='black') ax3.contourf(y, z, x, colors='black') ax4.contourf(x, z, y, colors='black') ax1.set_xlabel('x [-]') ax1.set_ylabel('y [-]') ax1.set_zlabel('z [-]') ax1.grid(True, which='both', ls=':') ax2.set_xlabel('x [-]') ax2.set_ylabel('y [-]') ax2.grid(True, which='both', ls=':') ax3.set_xlabel('y [-]') ax3.set_ylabel('z [-]') ax3.grid(True, which='both', ls=':') ax4.set_xlabel('x [-]') ax4.set_ylabel('z [-]') ax4.grid(True, which='both', ls=':') plt.tight_layout() plt.subplots_adjust(top=0.9) ax1.legend(frameon=True, handles=[l1, l2]) plt.suptitle( '$L_1$ Bifurcation - Halo family connecting to horizontal Lyapunov orbits', size=self.suptitleSize) plt.savefig('../../data/figures/orbits/L1_bifurcation_halo.pdf', transparent=True) plt.close() pass
C = float(config[orbit_type][orbit_name]['C']) x_range = np.arange(0.5, 1.5, 0.001) y_range = np.arange(-0.5, 0.5, 0.001) X, Y = np.meshgrid(x_range, y_range) Z = cr3bp_velocity(X, Y, C) if Z.min() < 0: plt.contourf(X, Y, Z, [Z.min(), 0], colors='black', alpha=0.05) title = 'C = ' + str(round(C, 3)) + \ ', T = ' + str(round(float(config[orbit_type][orbit_name]['T']), 3)) plt.title(title, size=30) phi = np.linspace(0, 2 * np.pi, 100) theta = np.linspace(0, np.pi, 100) bodies = load_bodies_location() for body in bodies: x_body = bodies[body]['r'] * np.outer( np.cos(phi), np.sin(theta)) + bodies[body]['x'] y_body = bodies[body]['r'] * np.outer( np.sin(phi), np.sin(theta)) + bodies[body]['y'] plt.plot(x_body, y_body, color='black') lagrange_points = load_lagrange_points_location() for lagrange_point in ['L1', 'L2']: ax.scatter(lagrange_points[lagrange_point]['x'], lagrange_points[lagrange_point]['y'], color='grey', marker='d', alpha=0.75) ax.text(lagrange_points[lagrange_point]['x'],
def plot_result(self): color_palette_green = sns.dark_palette('green', n_colors=self.numberOfOrbitsPerManifold) color_palette_red = sns.dark_palette('red', n_colors=self.numberOfOrbitsPerManifold) C = 3.15 x_range = np.arange(0.8, 1.2, 0.001) y_range = np.arange(-0.15, 0.15, 0.001) X, Y = np.meshgrid(x_range, y_range) Z = cr3bp_velocity(X, Y, C) plt.figure(figsize=(5*(1+np.sqrt(5))/2, 5)) gs = gridspec.GridSpec(2, 2) ax1 = plt.subplot(gs[0, :]) ax2 = plt.subplot(gs[1, 0]) ax3 = plt.subplot(gs[1, 1]) # Subplot 1: manifolds for i in range(self.numberOfOrbitsPerManifold): ax1.plot(self.WS.xs(i)['x'], self.WS.xs(i)['y'], color=color_palette_green[i], alpha=0.5) ax1.plot(self.WU.xs(i)['x'], self.WU.xs(i)['y'], color=color_palette_red[i], alpha=0.5) ax1.plot(self.WS.xs(46)['x'], self.WS.xs(46)['y'], color='black') ax1.plot(self.WS.xs(37)['x'], self.WS.xs(37)['y'], color='black') ax1.plot(self.WU.xs(65)['x'], self.WU.xs(65)['y'], color='black') ax1.plot(self.WU.xs(77)['x'], self.WU.xs(77)['y'], color='black') if Z.min() < 0: ax1.contourf(X, Y, Z, [Z.min(), 0], colors='black', alpha=0.2) if self.U_section == 2: # ax1.axvline(1 - self.massParameter, color='black') ax1.plot([1 - self.massParameter, 1 - self.massParameter], [-0.11, 0.01], color='black', linewidth=3) ax1.text(s='$\sum_2$', x=(1-0.5*self.massParameter), y=0.01) bodies_df = load_bodies_location() u = np.linspace(0, 2 * np.pi, 100) v = np.linspace(0, np.pi, 100) x = bodies_df['Moon']['r'] * np.outer(np.cos(u), np.sin(v)) + bodies_df['Moon']['x'] y = bodies_df['Moon']['r'] * np.outer(np.sin(u), np.sin(v)) z = bodies_df['Moon']['r'] * np.outer(np.ones(np.size(u)), np.cos(v)) # ax1.scatter(x, y, color='black', s=1) ax1.contourf(x, y, z, [z.min(), 0], colors='black') ax1.grid(True, which='both', ls=':') # Subplot 2: poincare v_max = 2 ax2.plot(self.poincareWS[abs(self.poincareWS['ydot']) < v_max]['y'].values, self.poincareWS[abs(self.poincareWS['ydot']) < v_max]['ydot'].values, color='g') ax2.plot(self.poincareWU[abs(self.poincareWU['ydot']) < v_max]['y'].values, self.poincareWU[abs(self.poincareWU['ydot']) < v_max]['ydot'].values, color='r') ax2.scatter(self.poincareWS['y'][46], self.poincareWS['ydot'][46], color='black') ax2.scatter(self.poincareWU['y'][65], self.poincareWU['ydot'][65], color='black') ax2.scatter(self.poincareWS['y'][37], self.poincareWS['ydot'][37], color='black') ax2.scatter(self.poincareWU['y'][77], self.poincareWU['ydot'][77], color='black') # y_1 y_2 # WS 46 41 # WU 65 83 # x_intersection = -0.0491777 # print(self.poincareWS[self.poincareWS['y'] == x_intersection + abs(self.poincareWS['y'] - x_intersection).min()]) # print(self.poincareWS[self.poincareWS['y'] == x_intersection - abs(self.poincareWS['y'] - x_intersection).min()]) # print(self.poincareWU[self.poincareWU['y'] == x_intersection + abs(self.poincareWU['y'] - x_intersection).min()]) # print(self.poincareWU[self.poincareWU['y'] == x_intersection - abs(self.poincareWU['y'] - x_intersection).min()]) ax2.set_xlabel('$y$') ax2.set_ylabel('$\dot{y}$') ax2.set_ylim([-1.5, 1.5]) ax2.grid(True, which='both', ls=':') title = '$\sum_' + str(self.U_section) + '$' ax2.set_title(title) # Subplot 3: x error ax3.axhline(abs(self.poincareWS['y'][46] - self.poincareWU['y'][65])) ax3.axhline(abs(self.poincareWS['y'][37] - self.poincareWU['y'][77])) ax3.axhline(abs(self.poincareWS['ydot'][46] - self.poincareWU['ydot'][65])) ax3.axhline(abs(self.poincareWS['ydot'][37] - self.poincareWU['ydot'][77])) ax3.semilogy((1 - self.massParameter) - self.poincareWS['x'].values) ax3.set_ylabel('$\| x - (1-\mu) \|$') ax3.set_xlabel('orbitId [-]') ax3.grid(True, which='both', ls=':') plt.tight_layout() # plt.savefig('../../data/figures/heteroclinic_connection.pdf') pass