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 show_2d_subplots(self, axis_1, axis_2): nr_rows = int(np.ceil(np.sqrt(len(self.orbit)))) nr_columns = int(np.ceil(len(self.orbit) / nr_rows)) f, axarr = plt.subplots(nr_rows, nr_columns, sharex=True, sharey=True, figsize=self.figSize) for idx, orbit in enumerate(self.orbit): column = idx % nr_columns row = int((idx - idx % nr_columns) / nr_columns) # Orbit axarr[row, column].plot(orbit[axis_1], orbit[axis_2], color='darkblue') # Lagrange points and bodies for lagrange_point in self.lagrangePoints: axarr[row, column].scatter( self.lagrangePoints[lagrange_point][axis_1], self.lagrangePoints[lagrange_point][axis_2], color='grey') phi = np.linspace(0, 2 * np.pi, 100) theta = np.linspace(0, np.pi, 100) for body in self.bodies: x = self.bodies[body]['r'] * np.outer( np.cos(phi), np.sin(theta)) + self.bodies[body][axis_1] y = self.bodies[body]['r'] * np.outer( np.sin(phi), np.sin(theta)) + self.bodies[body][axis_2] axarr[row, column].plot(x, y, color='black') C = float(config[self.orbitType][self.orbitType + '_' + str(idx + 1)]['C']) if axis_1 == 'x' and axis_2 == 'y': x = np.arange(-2.0, 2.0, 0.1) y = np.arange(-2.0, 2.0, 0.1) X, Y = np.meshgrid(x, y) Z = cr3bp_velocity(X, Y, C) axarr[row, column].contourf(X, Y, Z, levels=[-1, 0], colors='grey') title = 'C = ' + str(round(C, 3)) + \ ', T = ' + str(round(float(config[self.orbitType][self.orbitType + '_' + str(idx + 1)]['T']), 3)) axarr[row, column].set_title(title, size=self.titleSize) # axarr[0, 0].set_aspect('equal') # axarr[0, 0].set_ylim(axarr[0, 0].get_zlim()) f.suptitle(self.orbitType + ' subplots 2D', size=self.suptitleSize) plt.savefig('../data/figures/orbit_' + self.orbitType + '_2d_' + axis_1 + '_' + axis_2 + '.png') pass
manifold_S_min = load_manifold('../data/raw/' + orbit_name + '_W_S_min.txt') manifold_U_plus = load_manifold('../data/raw/' + orbit_name + '_W_U_plus.txt') manifold_U_min = load_manifold('../data/raw/' + orbit_name + '_W_U_min.txt') plt.xlim(xlim) plt.ylim(ylim) time_text = ax.text(0.01, 0.01, s='', transform=ax.transAxes, size=22) 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']
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 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_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 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_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 animate(self): print( '\nProducing a HorizontalLyapunovBifurcationToAxialAnimation at L' + str(self.librationPointNr) + '\n') fig = plt.figure() self.ax = fig.add_subplot(111, projection='3d') if self.includeSurfaceHill: x_range = np.arange(self.xLim[0], self.xLim[1], 0.001) y_range = np.arange(self.yLim[0], self.yLim[1], 0.001) self.x_mesh, self.y_mesh = np.meshgrid(x_range, y_range) z_mesh = cr3bp_velocity(self.x_mesh, self.y_mesh, self.jacobiEnergyHorizontalLyapunov[0]) self.contour = self.ax.contour( self.x_mesh, self.y_mesh, z_mesh, list(np.linspace(z_mesh.min(), 0, 10)), cmap='gist_gray_r', alpha=0.5) self.lines = [ self.ax.plot([], [], color=self.orbitColors['horizontal'], alpha=self.orbitAlpha, linewidth=self.orbitLinewidth)[0] ] # Text object to display absolute normalized time of trajectories within the manifolds self.jacobiEnergyText = self.ax.text2D( 0.05, 0.05, s='Horizontal Lyapunov family \n $C \\approx$ {:.4f}'.format( round(self.jacobiEnergyHorizontalLyapunov[0], 4)), transform=self.ax.transAxes, size=self.timeTextSize) # Plot the first orbit orbit_df = load_orbit('../../../data/raw/orbits/L' + str(self.librationPointNr) + '_horizontal_' + str(0) + '.txt') self.ax.plot(orbit_df['x'], orbit_df['y'], orbit_df['z'], color=self.orbitColors['horizontal'], 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)) 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 = 'Bifurcation from horizontal Lyapunov to axial and vertical Lyapunov families at $L_' + str( self.librationPointNr) + '$' 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 [-]') plt.show() 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 # 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')) if self.includeSurfaceHill: file_name = '../../../data/animations/bifurcations/L' + str( self.librationPointNr ) + '_horizontal_lyapunov_bifurcation_to_axial_family_hill.mp4' else: 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 update_lines(self, i): if i % 10 == 0: print(i) index_for_vertical = 0 for j, line in enumerate(self.lines): if i <= self.orbitIdBifurcationsFromHorizontalLyapunov[1]: jacobi_energy = self.jacobiEnergyHorizontalLyapunov[i] self.jacobiEnergyText.set_text( 'Horizontal Lyapunov family \n $C \\approx$ {:.4f}'.format( round(jacobi_energy, 4))) orbit_df = load_orbit('../../../data/raw/orbits/L' + str(self.librationPointNr) + '_horizontal_' + str(i) + '.txt') elif self.orbitIdBifurcationsFromHorizontalLyapunov[ 1] < i <= self.orbitIdBifurcationsFromHorizontalLyapunov[ 1] + self.numberOfAxialOrbits: index_for_axial = i - self.orbitIdBifurcationsFromHorizontalLyapunov[ 1] - 1 jacobi_energy = self.jacobiEnergyAxial[index_for_axial] self.jacobiEnergyText.set_text( 'Axial family \n $C \\approx$ {:.4f}'.format( round(jacobi_energy, 4))) orbit_df = load_orbit('../../../data/raw/orbits/L' + str(self.librationPointNr) + '_axial_' + str(index_for_axial) + '.txt') line.set_color(self.orbitColors['halo']) else: index_for_vertical = self.verticalLyapunovIndices[ i - self.orbitIdBifurcationsFromHorizontalLyapunov[1] - self.numberOfAxialOrbits - 1] jacobi_energy = self.jacobiEnergyVerticalLyapunov[ index_for_vertical] self.jacobiEnergyText.set_text( 'Vertical Lyapunov family \n $C \\approx$ {:.4f}'.format( round(jacobi_energy, 4))) orbit_df = load_orbit('../../../data/raw/orbits/L' + str(self.librationPointNr) + '_vertical_' + str(index_for_vertical) + '.txt') line.set_color(self.orbitColors['vertical']) if i in self.orbitIdBifurcationsFromHorizontalLyapunov and i <= self.orbitIdBifurcationsFromHorizontalLyapunov[ 1]: self.ax.plot(orbit_df['x'], orbit_df['y'], orbit_df['z'], color=self.orbitColors['horizontal'], linewidth=self.bifurcationLinewidth) if index_for_vertical == self.orbitIdBifurcationsFromVerticalLyapunov[ 0]: self.ax.plot(orbit_df['x'], orbit_df['y'], orbit_df['z'], color=self.orbitColors['halo'], linewidth=self.bifurcationLinewidth) x = orbit_df['x'].tolist() y = orbit_df['y'].tolist() z = orbit_df['z'].tolist() line.set_data(x, y) line.set_3d_properties(z) pass if self.includeSurfaceHill: z_mesh = cr3bp_velocity(self.x_mesh, self.y_mesh, jacobi_energy) if self.setContourLastTime: for coll in self.contour.collections: self.ax.collections.remove(coll) if z_mesh.min() < 0: self.contour = self.ax.contour( self.x_mesh, self.y_mesh, z_mesh, list(np.linspace(z_mesh.min(), 0, 10)), cmap='gist_gray_r', alpha=0.5) self.setContourLastTime = True else: self.setContourLastTime = False if i % 100 == 0 and i != 0: if i <= self.orbitIdBifurcationsFromHorizontalLyapunov[1]: plt.plot(orbit_df['x'], orbit_df['y'], orbit_df['z'], color=self.orbitColors['horizontal'], linewidth=self.orbitLinewidth) elif self.orbitIdBifurcationsFromHorizontalLyapunov[ 1] < i <= self.orbitIdBifurcationsFromHorizontalLyapunov[ 1] + self.numberOfAxialOrbits: plt.plot(orbit_df['x'], orbit_df['y'], orbit_df['z'], color=self.orbitColors['halo'], linewidth=self.orbitLinewidth) else: plt.plot(orbit_df['x'], orbit_df['y'], orbit_df['z'], color=self.orbitColors['vertical'], linewidth=self.orbitLinewidth) return self.lines
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 show_2d_subplots(self, axis_1, axis_2): color_palette_green = sns.dark_palette('green', n_colors=self.numberOfManifolds) color_palette_red = sns.dark_palette('red', n_colors=self.numberOfManifolds) nr_rows = int(np.ceil(np.sqrt(len(self.orbit)))) nr_columns = int(np.ceil(len(self.orbit) / nr_rows)) f, axarr = plt.subplots(nr_rows, nr_columns, sharex=True, sharey=True, figsize=self.figSize) for idx, orbit in enumerate(self.orbit): column = idx % nr_columns row = int((idx - idx % nr_columns) / nr_columns) print('\n=== ' + str(idx) + ' ===') # Manifold for manifold_orbit_number in range(1, self.numberOfManifolds + 1): print(manifold_orbit_number) if idx == 37 and manifold_orbit_number > 48: print('chekc') continue axarr[row, column].plot( self.manifold_S_plus[idx].xs( manifold_orbit_number)[axis_1], self.manifold_S_plus[idx].xs( manifold_orbit_number)[axis_2], color=color_palette_green[manifold_orbit_number - 1]) axarr[row, column].plot( self.manifold_S_min[idx].xs(manifold_orbit_number)[axis_1], self.manifold_S_min[idx].xs(manifold_orbit_number)[axis_2], color=color_palette_green[manifold_orbit_number - 1]) axarr[row, column].plot( self.manifold_U_plus[idx].xs( manifold_orbit_number)[axis_1], self.manifold_U_plus[idx].xs( manifold_orbit_number)[axis_2], color=color_palette_red[manifold_orbit_number - 1]) axarr[row, column].plot( self.manifold_U_min[idx].xs(manifold_orbit_number)[axis_1], self.manifold_U_min[idx].xs(manifold_orbit_number)[axis_2], color=color_palette_red[manifold_orbit_number - 1]) # Orbit axarr[row, column].plot(orbit[axis_1], orbit[axis_2], color='darkblue') # Lagrange points and bodies for lagrange_point in self.lagrangePoints: axarr[row, column].scatter( self.lagrangePoints[lagrange_point][axis_1], self.lagrangePoints[lagrange_point][axis_2], color='grey') phi = np.linspace(0, 2 * np.pi, 100) theta = np.linspace(0, np.pi, 100) for body in self.bodies: x = self.bodies[body]['r'] * np.outer( np.cos(phi), np.sin(theta)) + self.bodies[body][axis_1] y = self.bodies[body]['r'] * np.outer( np.sin(phi), np.sin(theta)) + self.bodies[body][axis_2] axarr[row, column].plot(x, y, color='black') axarr[row, column].set_aspect('equal') C = float(config[self.orbitType][self.orbitType + '_' + str(idx + 1)]['C']) if axis_1 == 'x' and axis_2 == 'y': x = np.arange(-2.0, 2.0, 0.1) y = np.arange(-2.0, 2.0, 0.1) X, Y = np.meshgrid(x, y) Z = cr3bp_velocity(X, Y, C) axarr[row, column].contourf(X, Y, Z, levels=[-1, 0], colors='grey') title = 'C = ' + str(round(C, 3)) + \ ', T = ' + str(round(float(config[self.orbitType][self.orbitType + '_' + str(idx + 1)]['T']), 3)) axarr[row, column].set_title(title, size=self.titleSize) axarr[0, 0].set_aspect('equal') # axarr[0, 0].set_ylim(axarr[0, 0].get_zlim()) f.suptitle(self.orbitType + ' subplots 2D', size=self.suptitleSize) plt.savefig('../data/figures/manifold_' + self.orbitType + '_2d_' + axis_1 + '_' + axis_2 + '.png') pass
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 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