def __init__(self, orbit_type, lagrange_point_nr, orbit_id, c_level): self.orbitType = orbit_type self.orbitId = orbit_id self.cLevel = c_level self.orbitTypeForTitle = orbit_type.capitalize() if (self.orbitTypeForTitle == 'Horizontal') or (self.orbitTypeForTitle == 'Vertical'): self.orbitTypeForTitle += ' Lyapunov' self.lagrangePointNr = lagrange_point_nr EARTH_GRAVITATIONAL_PARAMETER = 3.986004418E14 SUN_GRAVITATIONAL_PARAMETER = 1.32712440018e20 MOON_GRAVITATIONAL_PARAMETER = SUN_GRAVITATIONAL_PARAMETER / (328900.56 * (1.0 + 81.30059)) self.massParameter = MOON_GRAVITATIONAL_PARAMETER / (MOON_GRAVITATIONAL_PARAMETER + EARTH_GRAVITATIONAL_PARAMETER) self.eigenvectorDf_S = pd.read_table('../../data/raw/manifolds/refined_for_c/L' + str(lagrange_point_nr) + '_' + orbit_type + '_' + str(orbit_id) + '_W_S_plus_eigenvector.txt', delim_whitespace=True, header=None).filter(list(range(6))) self.eigenvectorDf_U = pd.read_table('../../data/raw/manifolds/refined_for_c/L' + str(lagrange_point_nr) + '_' + orbit_type + '_' + str(orbit_id) + '_W_U_plus_eigenvector.txt', delim_whitespace=True, header=None).filter(list(range(6))) self.eigenvectorLocationDf_S = pd.read_table('../../data/raw/manifolds/refined_for_c/L' + str(lagrange_point_nr) + '_' + orbit_type + '_' + str(orbit_id) + '_W_S_plus_eigenvector_location.txt', delim_whitespace=True, header=None).filter(list(range(6))) self.eigenvectorLocationDf_U = pd.read_table('../../data/raw/manifolds/refined_for_c/L' + str(lagrange_point_nr) + '_' + orbit_type + '_' + str(orbit_id) + '_W_U_plus_eigenvector_location.txt', delim_whitespace=True, header=None).filter(list(range(6))) self.W_S_plus = load_manifold_refactored('../../data/raw/manifolds/refined_for_c/L' + str(lagrange_point_nr) + '_' + orbit_type + '_' + str(orbit_id) + '_W_S_plus.txt') self.W_S_min = load_manifold_refactored('../../data/raw/manifolds/refined_for_c/L' + str(lagrange_point_nr) + '_' + orbit_type + '_' + str(orbit_id) + '_W_S_min.txt') self.W_U_plus = load_manifold_refactored('../../data/raw/manifolds/refined_for_c/L' + str(lagrange_point_nr) + '_' + orbit_type + '_' + str(orbit_id) + '_W_U_plus.txt') self.W_U_min = load_manifold_refactored('../../data/raw/manifolds/refined_for_c/L' + str(lagrange_point_nr) + '_' + orbit_type + '_' + str(orbit_id) + '_W_U_min.txt') self.orbitDf = load_orbit('../../data/raw/orbits/refined_for_c/L' + str(lagrange_point_nr) + '_' + orbit_type + '_' + str(orbit_id) + '.txt') self.numberOfOrbitsPerManifold = len(set(self.W_S_plus.index.get_level_values(0))) self.figSize = (7 * (1 + np.sqrt(5)) / 2, 7) blues = sns.color_palette('Blues', 100) greens = sns.color_palette('BuGn', 100) self.colorPaletteStable = sns.dark_palette('green', n_colors=self.numberOfOrbitsPerManifold) self.colorPaletteUnstable = sns.dark_palette('red', n_colors=self.numberOfOrbitsPerManifold) n_colors = 3 n_colors_l = 6 self.plottingColors = {'lambda1': sns.color_palette("viridis", n_colors_l)[0], 'lambda2': sns.color_palette("viridis", n_colors_l)[2], 'lambda3': sns.color_palette("viridis", n_colors_l)[4], 'lambda4': sns.color_palette("viridis", n_colors_l)[5], 'lambda5': sns.color_palette("viridis", n_colors_l)[3], 'lambda6': sns.color_palette("viridis", n_colors_l)[1], 'singleLine': sns.color_palette("viridis", n_colors)[0], 'doubleLine': [sns.color_palette("viridis", n_colors)[n_colors - 1], sns.color_palette("viridis", n_colors)[0]], 'tripleLine': [sns.color_palette("viridis", n_colors)[n_colors - 1], sns.color_palette("viridis", n_colors)[int((n_colors - 1) / 2)], sns.color_palette("viridis", n_colors)[0]], 'W_S_plus': self.colorPaletteStable[int(0.9*self.numberOfOrbitsPerManifold)], 'W_S_min': self.colorPaletteStable[int(0.4*self.numberOfOrbitsPerManifold)], 'W_U_plus': self.colorPaletteUnstable[int(0.9*self.numberOfOrbitsPerManifold)], 'W_U_min': self.colorPaletteUnstable[int(0.4*self.numberOfOrbitsPerManifold)], 'limit': 'black', 'orbit': 'navy'} self.suptitleSize = 20 pass
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 __init__(self, orbit_type, lagrange_point_nr, orbit_id_per_c): print('=======================') print(str(orbit_type) + ' in L' + str(lagrange_point_nr)) print('=======================') self.orbitType = orbit_type self.orbitIdPerC = orbit_id_per_c self.orbitTypeForTitle = orbit_type.capitalize() if (self.orbitTypeForTitle == 'Horizontal') or (self.orbitTypeForTitle == 'Vertical'): self.orbitTypeForTitle += ' Lyapunov' self.lagrangePointNr = lagrange_point_nr EARTH_GRAVITATIONAL_PARAMETER = 3.986004418E14 SUN_GRAVITATIONAL_PARAMETER = 1.32712440018e20 MOON_GRAVITATIONAL_PARAMETER = SUN_GRAVITATIONAL_PARAMETER / ( 328900.56 * (1.0 + 81.30059)) self.massParameter = MOON_GRAVITATIONAL_PARAMETER / ( MOON_GRAVITATIONAL_PARAMETER + EARTH_GRAVITATIONAL_PARAMETER) 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) self.C = [] self.orbitDf = [] self.W_S_plus = [] self.W_S_min = [] self.W_U_plus = [] self.W_U_min = [] for c_level in reversed(sorted(orbit_id_per_c)): orbit_id = orbit_id_per_c[c_level] # self.C.append(initial_conditions_incl_m_df.iloc[orbit_id][0]) self.orbitDf.append( load_orbit('../../data/raw/orbits/refined_for_c/L' + str(lagrange_point_nr) + '_' + orbit_type + '_' + str(orbit_id) + '.txt')) self.C.append( computeJacobiEnergy(self.orbitDf[-1].iloc[0]['x'], self.orbitDf[-1].iloc[0]['y'], self.orbitDf[-1].iloc[0]['z'], self.orbitDf[-1].iloc[0]['xdot'], self.orbitDf[-1].iloc[0]['ydot'], self.orbitDf[-1].iloc[0]['zdot'])) self.W_S_plus.append( load_manifold_refactored( '../../data/raw/manifolds/refined_for_c/L' + str(lagrange_point_nr) + '_' + orbit_type + '_' + str(orbit_id) + '_W_S_plus.txt')) self.W_S_min.append( load_manifold_refactored( '../../data/raw/manifolds/refined_for_c/L' + str(lagrange_point_nr) + '_' + orbit_type + '_' + str(orbit_id) + '_W_S_min.txt')) self.W_U_plus.append( load_manifold_refactored( '../../data/raw/manifolds/refined_for_c/L' + str(lagrange_point_nr) + '_' + orbit_type + '_' + str(orbit_id) + '_W_U_plus.txt')) self.W_U_min.append( load_manifold_refactored( '../../data/raw/manifolds/refined_for_c/L' + str(lagrange_point_nr) + '_' + orbit_type + '_' + str(orbit_id) + '_W_U_min.txt')) self.numberOfOrbitsPerManifold = len( set(self.W_S_plus[0].index.get_level_values(0))) self.figSize = (7 * (1 + np.sqrt(5)) / 2, 7 * 2) blues = sns.color_palette('Blues', 100) greens = sns.color_palette('BuGn', 100) self.colorPaletteStable = sns.dark_palette( 'green', n_colors=self.numberOfOrbitsPerManifold) self.colorPaletteUnstable = sns.dark_palette( 'red', n_colors=self.numberOfOrbitsPerManifold) self.plottingColors = { 'lambda1': blues[40], 'lambda2': greens[50], 'lambda3': blues[90], 'lambda4': blues[90], 'lambda5': greens[70], 'lambda6': blues[60], 'singleLine': blues[80], 'doubleLine': [greens[50], blues[80]], 'tripleLine': [blues[40], greens[50], blues[80]], 'W_S_plus': self.colorPaletteStable[90], 'W_S_min': self.colorPaletteStable[40], 'W_U_plus': self.colorPaletteUnstable[90], 'W_U_min': self.colorPaletteUnstable[40], 'limit': 'black', 'orbit': 'navy' } self.suptitleSize = 20 pass
def plot_portrait_L1_to_L2(self): fig, axarr = plt.subplots(1, 2, figsize=(self.figSize[0], self.figSize[1] / 2), sharex=True, sharey=True) for idx, c_level in enumerate([3.1, 3.15]): w_u_plus = load_manifold_refactored( '../../data/raw/manifolds/refined_for_c/L1_horizontal_' + str(orbit_ids['horizontal'][1][c_level]) + '_W_U_plus.txt') w_s_min = load_manifold_refactored( '../../data/raw/manifolds/refined_for_c/L2_horizontal_' + str(orbit_ids['horizontal'][2][c_level]) + '_W_S_min.txt') ls_u = [] ls_s = [] for i in range(self.numberOfOrbitsPerManifold): if abs( w_u_plus.xs(i).tail(1)['x'].get_values()[0] - (1 - self.massParameter)) > 1e-11: pass else: ls_u.append(w_u_plus.xs(i).tail(1)) if abs( w_s_min.xs(i).head(1)['x'].get_values()[0] - (1 - self.massParameter)) > 1e-11: pass else: ls_s.append(w_s_min.xs(i).head(1)) # Add start as endpoint for loop plot if abs( w_u_plus.xs(0).tail(1)['x'].get_values()[0] - (1 - self.massParameter)) > 1e-11: pass else: ls_u.append(w_u_plus.xs(0).tail(1)) if abs( w_s_min.xs(0).head(1)['x'].get_values()[0] - (1 - self.massParameter)) > 1e-11: pass else: ls_s.append(w_s_min.xs(0).head(1)) w_u_plus_poincare = pd.concat(ls_u) w_s_min_poincare = pd.concat(ls_s) l1, = axarr[idx].plot(w_u_plus_poincare['y'], w_u_plus_poincare['ydot'], c='r', label='$\mathcal{W}^{U+}$') l2, = axarr[idx].plot(w_s_min_poincare['y'], w_s_min_poincare['ydot'], c='g', label='$\mathcal{W}^{S-}$') axarr[idx].set_title('$C$ = ' + str(c_level)) axarr[0].set_ylim([-1, 1]) axarr[1].set_xlim([-0.175, -0.0025]) axarr[0].set_xlabel('$y$ [-]') axarr[1].set_xlabel('$y$ [-]') axarr[0].set_ylabel('$\dot{y}$ [-]') axarr[0].grid(True, which='both', ls=':') axarr[1].grid(True, which='both', ls=':') axarr[1].legend(frameon=True, loc='center left', bbox_to_anchor=(1, 0.5), handles=[l1, l2]) fig.tight_layout() fig.subplots_adjust(top=0.8, right=0.9) plt.suptitle('Planar Poincaré phase portrait at $\mathbf{U}_2$', size=self.suptitleSize) # plt.show() plt.savefig( '../../data/figures/poincare_sections/planar_poincare_phase_portrait_l1_to_l2.pdf', transparent=True) plt.close() 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} \}$ - Orthografic projection (C = ' + str( c_level) + ')' 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=':') # 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'] = 4.0 self.ax.yaxis._axinfo['label']['space_factor'] = 4.0 self.ax.zaxis._axinfo['label']['space_factor'] = 4.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]: 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_' + self.orbitType + '_' + str( self.cLevel) + '.mp4' self.animation_function.save(self.file_name, writer=self.animation_writer)
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_overview(self): lagrange_points = [1, 2] orbit_types = ['horizontal', 'halo', 'vertical'] c_levels = [3.05, 3.1, 3.15] orbit_ids = { 'horizontal': { 1: { 3.05: 808, 3.1: 577, 3.15: 330 }, 2: { 3.05: 1066, 3.1: 760, 3.15: 373 } }, 'halo': { 1: { 3.05: 1235, 3.1: 836, 3.15: 358 }, 2: { 3.05: 1093, 3.1: 651, 3.15: 0 } }, 'vertical': { 1: { 3.05: 1664, 3.1: 1159, 3.15: 600 }, 2: { 3.05: 1878, 3.1: 1275, 3.15: 513 } } } resultsplus = { 'horizontal': { 1: { 3.05: [], 3.1: [], 3.15: [] }, 2: { 3.05: [], 3.1: [], 3.15: [] } }, 'halo': { 1: { 3.05: [], 3.1: [], 3.15: [] }, 2: { 3.05: [], 3.1: [], 3.15: [] } }, 'vertical': { 1: { 3.05: [], 3.1: [], 3.15: [] }, 2: { 3.05: [], 3.1: [], 3.15: [] } } } resultsmin = { 'horizontal': { 1: { 3.05: [], 3.1: [], 3.15: [] }, 2: { 3.05: [], 3.1: [], 3.15: [] } }, 'halo': { 1: { 3.05: [], 3.1: [], 3.15: [] }, 2: { 3.05: [], 3.1: [], 3.15: [] } }, 'vertical': { 1: { 3.05: [], 3.1: [], 3.15: [] }, 2: { 3.05: [], 3.1: [], 3.15: [] } } } linestyles = {1: '-', 2: '--'} fig, axarr = plt.subplots(1, 2, figsize=self.figSize, sharex=True, sharey=True) # fig, axarr = plt.subplots(1, 2, figsize=(self.figSize[0], self.figSize[1]/2), sharex=True, sharey=True) for lagrange_point in lagrange_points: for idx, orbit_type in enumerate(orbit_types): orbit_type_for_label = orbit_type.capitalize() if (orbit_type_for_label == 'Horizontal') or (orbit_type_for_label == 'Vertical'): orbit_type_for_label += ' Lyapunov' label = '$L_' + str( lagrange_point) + '$ ' + orbit_type_for_label for c_level in c_levels: df = load_manifold_refactored( '../../data/raw/manifolds/refined_for_c/L' + str(lagrange_point) + '_' + orbit_type + '_' + str(orbit_ids[orbit_type][lagrange_point][c_level]) + '_W_U_plus.txt') resultsplus[orbit_type][lagrange_point][c_level] = [ df.xs(i).index.get_level_values(0)[-1] for i in range(100) ] df = load_manifold_refactored( '../../data/raw/manifolds/refined_for_c/L' + str(lagrange_point) + '_' + orbit_type + '_' + str(orbit_ids[orbit_type][lagrange_point][c_level]) + '_W_U_min.txt') resultsmin[orbit_type][lagrange_point][c_level] = [ df.xs(i).index.get_level_values(0)[-1] for i in range(100) ] plot_data_plus = [ np.mean( resultsplus[orbit_type][lagrange_point][c_levels[0]]), np.mean( resultsplus[orbit_type][lagrange_point][c_levels[1]]), np.mean( resultsplus[orbit_type][lagrange_point][c_levels[2]]) ] plot_data_min = [ np.mean( resultsmin[orbit_type][lagrange_point][c_levels[0]]), np.mean( resultsmin[orbit_type][lagrange_point][c_levels[1]]), np.mean( resultsmin[orbit_type][lagrange_point][c_levels[2]]) ] axarr[0].plot(c_levels, plot_data_plus, linestyle=linestyles[lagrange_point], c=self.plottingColors['tripleLine'][idx]) axarr[1].plot(c_levels, plot_data_min, label=label, linestyle=linestyles[lagrange_point], c=self.plottingColors['tripleLine'][idx]) axarr[1].legend(frameon=True, loc='center left', bbox_to_anchor=(1.0, 0.5)) for i in range(2): axarr[i].set_xlabel('$C$ [-]') axarr[i].set_ylabel('$|T|$ [-]') axarr[i].grid(True, which='both', ls=':') axarr[0].set_xlim([3.05, 3.15]) axarr[0].set_title('Mean total integration period $\{\mathcal{W}^+\}$') axarr[1].set_title('Mean total integration period $\{\mathcal{W}^-\}$') fig.tight_layout() fig.subplots_adjust(top=0.8, right=0.8) fig.suptitle('Families overview - Orbital energy and time to unwind', size=self.suptitleSize) # plt.show() if self.lowDPI: plt.savefig( '../../data/figures/manifolds/refined_for_c/overview_families_orbital_energy_unwind.png', transparent=True, dpi=self.dpi) else: plt.savefig( '../../data/figures/manifolds/refined_for_c/overview_families_orbital_energy_unwind.pdf', transparent=True) pass
def __init__(self, orbit_type, theta, number_of_orbits_per_manifold, orbit_ids): self.suptitleSize = 44 self.timeTextSize = 33 self.xLim = [0.7, 1.3] self.yLim = [-0.3, 0.3] self.zLim = self.yLim self.orbitAlpha = 0.8 self.orbitLinewidth = 3 self.orbitColor = 'navy' self.orbitType = orbit_type self.theta = theta self.orbitIds = orbit_ids self.lines = [] self.W_S_plus = [] self.W_S_min = [] self.W_U_plus = [] self.W_U_min = [] self.t = [] self.numberOfOrbitsPerManifold = number_of_orbits_per_manifold self.lagrangePointMarkerSize = 100 self.timeText = '' # Will become a plt.text-object self.cLevel = 3.1 self.orbitTypeForTitle = orbit_type.capitalize() if (self.orbitTypeForTitle == 'Horizontal') or (self.orbitTypeForTitle == 'Vertical'): self.orbitTypeForTitle += ' Lyapunov' print(self.orbitTypeForTitle + ' at theta = ' + str(theta)) self.fig = plt.figure() self.ax = self.fig.add_subplot(111, projection='3d') self.fig.tight_layout() df = pd.read_table('../../../data/raw/poincare_sections/' + str(self.numberOfOrbitsPerManifold) + '/' + self.orbitType + '_3.1_minimum_impulse_connections.txt', delim_whitespace=True, header=None).filter(list(range(17))) df.columns = [ 'theta', 'taus', 'ts', 'xs', 'ys', 'zs', 'xdots', 'ydots', 'zdots', 'tauu', 'tu', 'xu', 'yu', 'zu', 'xdotu', 'ydotu', 'zdotu' ] df['dr'] = np.sqrt((df['xs'] - df['xu'])**2 + (df['ys'] - df['yu'])**2 + (df['zs'] - df['zu'])**2) df['dv'] = np.sqrt((df['xdots'] - df['xdotu'])**2 + (df['ydots'] - df['ydotu'])**2 + (df['zdots'] - df['zdotu'])**2) self.minimumImpulse = df.set_index('theta') index_near_heteroclinic_s = int( self.minimumImpulse.loc[theta]['taus'] * self.numberOfOrbitsPerManifold) index_near_heteroclinic_u = int( self.minimumImpulse.loc[theta]['tauu'] * self.numberOfOrbitsPerManifold) self.W_S_min = load_manifold_refactored( '../../../data/raw/poincare_sections/' + str(self.numberOfOrbitsPerManifold) + '/L2_' + self.orbitType + '_W_S_min_3.1_' + str(int(theta)) + '_full.txt').xs(index_near_heteroclinic_s) self.W_U_plus = load_manifold_refactored( '../../../data/raw/poincare_sections/' + str(self.numberOfOrbitsPerManifold) + '/L1_' + self.orbitType + '_W_U_plus_3.1_' + str(int(theta)) + '_full.txt').xs(index_near_heteroclinic_u) self.firstTimeStable = True 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