Пример #1
0
    def animate(self):
        fig = plt.figure()
        self.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 = 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):
            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))
            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} \}$ - 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)
        plt.axis('off')

        fig.tight_layout()
        fig.subplots_adjust(top=0.9)
        plt.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).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.01) + 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/manifolds/spatial_manifolds_rotating_no_axes_' + orbit_type + '_' + str(
            c_level) + '.mp4'
        animation_function.save(file_name, writer=animation_writer)
Пример #2
0
    def plot_horizontal_to_axial_to_vertical(self):
        fig = plt.figure(figsize=self.figSize)
        ax1 = fig.add_subplot(2, 2, 1, projection='3d')
        ax2 = fig.add_subplot(2, 2, 2)
        ax3 = fig.add_subplot(2, 2, 3)
        ax4 = fig.add_subplot(2, 2, 4)

        horizontal_color = self.plottingColors['tripleLine'][2]
        axial_color = self.plottingColors['tripleLine'][0]
        vertical_color = self.plottingColors['tripleLine'][1]

        # Plot bifurcations
        line_width = 2
        plot_alpha = 1
        df = load_orbit('../../data/raw/orbits/L1_horizontal_' +
                        str(self.horizontalBifurcations[1]) + '.txt')
        l1, = ax1.plot(df['x'],
                       df['y'],
                       df['z'],
                       color=horizontal_color,
                       alpha=plot_alpha,
                       linewidth=1,
                       label='Horizontal Lyapunov')
        ax1.plot(df['x'],
                 df['y'],
                 df['z'],
                 color=horizontal_color,
                 alpha=plot_alpha,
                 linewidth=line_width)
        ax2.plot(df['x'],
                 df['y'],
                 color=horizontal_color,
                 alpha=plot_alpha,
                 linewidth=line_width)
        ax3.plot(df['y'],
                 df['z'],
                 color=horizontal_color,
                 alpha=plot_alpha,
                 linewidth=line_width)
        ax4.plot(df['x'],
                 df['z'],
                 color=horizontal_color,
                 alpha=plot_alpha,
                 linewidth=line_width)

        number_of_orbits = 10
        line_width = 1
        plot_alpha = 0.5
        for i in [
                int(i)
                for i in (np.linspace(100, self.axialMaxId, number_of_orbits))
        ]:
            df = load_orbit('../../data/raw/orbits/L1_axial_' + str(i) +
                            '.txt')
            l2, = ax1.plot(df['x'],
                           df['y'],
                           df['z'],
                           color=axial_color,
                           alpha=plot_alpha,
                           linewidth=line_width,
                           label='Axial')
            ax2.plot(df['x'],
                     df['y'],
                     color=axial_color,
                     alpha=plot_alpha,
                     linewidth=line_width)
            ax3.plot(df['y'],
                     df['z'],
                     color=axial_color,
                     alpha=plot_alpha,
                     linewidth=line_width)
            ax4.plot(df['x'],
                     df['z'],
                     color=axial_color,
                     alpha=plot_alpha,
                     linewidth=line_width)

        # Plot bifurcations
        line_width = 2
        plot_alpha = 1
        df = load_orbit('../../data/raw/orbits/L1_vertical_' +
                        str(self.verticalBifurcations[0]) + '.txt')
        l3, = ax1.plot(df['x'],
                       df['y'],
                       df['z'],
                       color=vertical_color,
                       alpha=plot_alpha,
                       linewidth=1,
                       label='Vertical Lyapunov')
        ax1.plot(df['x'],
                 df['y'],
                 df['z'],
                 color=vertical_color,
                 alpha=plot_alpha,
                 linewidth=line_width)
        ax2.plot(df['x'],
                 df['y'],
                 color=vertical_color,
                 alpha=plot_alpha,
                 linewidth=line_width)
        ax3.plot(df['y'],
                 df['z'],
                 color=vertical_color,
                 alpha=plot_alpha,
                 linewidth=line_width)
        ax4.plot(df['x'],
                 df['z'],
                 color=vertical_color,
                 alpha=plot_alpha,
                 linewidth=line_width)

        # Lagrange points and bodies
        lagrange_points_df = load_lagrange_points_location()
        lagrange_point_nrs = ['L1', 'L2']
        for lagrange_point_nr in lagrange_point_nrs:
            ax1.scatter(lagrange_points_df[lagrange_point_nr]['x'],
                        lagrange_points_df[lagrange_point_nr]['y'],
                        lagrange_points_df[lagrange_point_nr]['z'],
                        color='black',
                        marker='x')
            ax2.scatter(lagrange_points_df[lagrange_point_nr]['x'],
                        lagrange_points_df[lagrange_point_nr]['y'],
                        color='black',
                        marker='x')
            ax3.scatter(lagrange_points_df[lagrange_point_nr]['y'],
                        lagrange_points_df[lagrange_point_nr]['z'],
                        color='black',
                        marker='x')
            ax4.scatter(lagrange_points_df[lagrange_point_nr]['x'],
                        lagrange_points_df[lagrange_point_nr]['z'],
                        color='black',
                        marker='x')

        bodies_df = load_bodies_location()
        u = np.linspace(0, 2 * np.pi, 100)
        v = np.linspace(0, np.pi, 100)
        for body in ['Moon']:
            x = bodies_df[body]['r'] * np.outer(
                np.cos(u), np.sin(v)) + bodies_df[body]['x']
            y = bodies_df[body]['r'] * np.outer(np.sin(u), np.sin(v))
            z = bodies_df[body]['r'] * np.outer(np.ones(np.size(u)), np.cos(v))
            ax1.plot_surface(x, y, z, color='black')
            ax2.contourf(x, y, z, colors='black')
            ax3.contourf(y, z, x, colors='black')
            ax4.contourf(x, z, y, colors='black')

        ax1.set_xlabel('x [-]')
        ax1.set_ylabel('y [-]')
        ax1.set_zlabel('z [-]')
        ax1.grid(True, which='both', ls=':')

        ax2.set_xlabel('x [-]')
        ax2.set_ylabel('y [-]')
        ax2.grid(True, which='both', ls=':')

        ax3.set_xlabel('y [-]')
        ax3.set_ylabel('z [-]')
        ax3.grid(True, which='both', ls=':')

        ax4.set_xlabel('x [-]')
        ax4.set_ylabel('z [-]')
        ax4.grid(True, which='both', ls=':')

        plt.tight_layout()
        plt.subplots_adjust(top=0.9)
        ax1.legend(frameon=True, handles=[l1, l2, l3])
        plt.suptitle(
            '$L_1$ Bifurcation - Axial family connecting horizontal and vertical Lyapunov orbits',
            size=self.suptitleSize)
        if self.lowDPI:
            plt.savefig('../../data/figures/orbits/L1_bifurcation_axial.png',
                        transparent=True,
                        dpi=self.dpi)
        else:
            plt.savefig('../../data/figures/orbits/L1_bifurcation_axial.pdf',
                        transparent=True)
        plt.close()
        pass
Пример #3
0
eigenvectors_S = pd.read_table(
    '../../data/verification/ver_halo_1_W_S_plus.txt',
    delim_whitespace=True,
    header=None).filter(list(range(6)))
eigenvectors_U = pd.read_table(
    '../../data/verification/ver_halo_1_W_U_plus.txt',
    delim_whitespace=True,
    header=None).filter(list(range(6)))
eigenvectors_S.columns = ['x', 'y', 'z', 'xdot', 'ydot', 'zdot']
eigenvectors_U.columns = ['x', 'y', 'z', 'xdot', 'ydot', 'zdot']
eigenvectors_indices = [np.floor(i * len(orbit) / 20) for i in range(20)]

plt.figure(figsize=(30, 40))
plt.plot(orbit['x'], orbit['y'], color='blue', linewidth=4)
plt.scatter((load_lagrange_points_location()['L2']['x'] - 1) * 384400e-4,
            load_lagrange_points_location()['L2']['y'] * 384400e-4,
            color='grey',
            s=100)
plt.scatter(0, 0, color='grey', s=1000)

v_U = [0.46173686071464, -0.12104697597009]
v_S = [0.048496125209463, 0.38642078136333]

for idx, eigenvectors_index in enumerate(eigenvectors_indices):

    x_S = [
        orbit.xs(eigenvectors_index)['x'] - 1 * eigenvectors_S.xs(idx)['x'],
        orbit.xs(eigenvectors_index)['x'] + 1 * eigenvectors_S.xs(idx)['x']
    ]
    y_S = [
Пример #4
0
    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:
            # 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[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(
            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 = 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.04) + 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_zoom_' + self.orbitType + '_' + str(
            self.cLevel) + '.mp4'
        self.animation_function.save(self.file_name,
                                     writer=self.animation_writer)
        pass
ax1.set_zlim([-0.15, 0.15])
ax1.set_xlabel('x')
ax1.set_ylabel('y')
ax1.set_zlabel('z')
ax1.set_title('3D view', size=20)

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']
    z_body = bodies[body]['r'] * np.cos(theta) + bodies[body]['z']
    ax1.plot_surface(x_body, y_body, z_body, color='black')

lagrange_points = load_lagrange_points_location()
for lagrange_point in ['L1', 'L2']:
    ax1.scatter3D(lagrange_points[lagrange_point]['x'],
                  lagrange_points[lagrange_point]['y'],
                  lagrange_points[lagrange_point]['z'], color='grey', marker='d', alpha=0.75)
    ax1.text(lagrange_points[lagrange_point]['x'],
             lagrange_points[lagrange_point]['y'],
             lagrange_points[lagrange_point]['z'], lagrange_point, size=16)


# Plot 2: 2D-view of orbit
if orbit_type == 'horizontal' or orbit_type == 'halo':
    line2 = ax2.plot(orbit[0]['x'].values, orbit[0]['y'].values, color='darkblue')
    ax2.set_xlabel('x')
    ax2.set_ylabel('y')
    def animate(self):
        fig = plt.figure()
        self.ax = fig.add_subplot(111, projection='3d')

        self.horizontalLyapunov = [
            load_orbit('../../../data/raw/orbits/refined_for_c/L' + str(1) +
                       '_horizontal_' +
                       str(self.orbitIds['horizontal'][1][self.cLevel]) +
                       '_100.txt'),
            load_orbit('../../../data/raw/orbits/refined_for_c/L' + str(2) +
                       '_horizontal_' +
                       str(self.orbitIds['horizontal'][2][self.cLevel]) +
                       '_100.txt')
        ]

        self.verticalLyapunov = [
            load_orbit('../../../data/raw/orbits/refined_for_c/L' + str(1) +
                       '_vertical_' +
                       str(self.orbitIds['vertical'][1][self.cLevel]) +
                       '_100.txt'),
            load_orbit('../../../data/raw/orbits/refined_for_c/L' + str(2) +
                       '_vertical_' +
                       str(self.orbitIds['vertical'][2][self.cLevel]) +
                       '_100.txt')
        ]

        self.halo = [
            load_orbit('../../../data/raw/orbits/refined_for_c/L' + str(1) +
                       '_halo_' + str(self.orbitIds['halo'][1][self.cLevel]) +
                       '_100.txt'),
            load_orbit('../../../data/raw/orbits/refined_for_c/L' + str(2) +
                       '_halo_' + str(self.orbitIds['halo'][2][self.cLevel]) +
                       '_100.txt')
        ]

        self.lines = [
            plt.plot([], [],
                     color=self.orbitColors['horizontal'],
                     linewidth=self.orbitLinewidth,
                     alpha=self.orbitAlpha,
                     marker='o',
                     markevery=[-1])[0],
            plt.plot([], [],
                     color=self.orbitColors['horizontal'],
                     linewidth=self.orbitLinewidth,
                     alpha=self.orbitAlpha,
                     marker='o',
                     markevery=[-1])[0],
            plt.plot([], [],
                     color=self.orbitColors['vertical'],
                     linewidth=self.orbitLinewidth,
                     alpha=self.orbitAlpha,
                     marker='o',
                     markevery=[-1])[0],
            plt.plot([], [],
                     color=self.orbitColors['vertical'],
                     linewidth=self.orbitLinewidth,
                     alpha=self.orbitAlpha,
                     marker='o',
                     markevery=[-1])[0],
            plt.plot([], [],
                     color=self.orbitColors['halo'],
                     linewidth=self.orbitLinewidth,
                     alpha=self.orbitAlpha,
                     marker='o',
                     markevery=[-1])[0],
            plt.plot([], [],
                     color=self.orbitColors['halo'],
                     linewidth=self.orbitLinewidth,
                     alpha=self.orbitAlpha,
                     marker='o',
                     markevery=[-1])[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):
            plt.plot(self.horizontalLyapunov[k]['x'],
                     self.horizontalLyapunov[k]['y'],
                     self.horizontalLyapunov[k]['z'],
                     color=self.orbitColors['horizontal'],
                     alpha=self.orbitAlpha,
                     linewidth=self.orbitLinewidth,
                     linestyle=':')
            plt.plot(self.verticalLyapunov[k]['x'],
                     self.verticalLyapunov[k]['y'],
                     self.verticalLyapunov[k]['z'],
                     color=self.orbitColors['vertical'],
                     alpha=self.orbitAlpha,
                     linewidth=self.orbitLinewidth,
                     linestyle=':')
            plt.plot(self.halo[k]['x'],
                     self.halo[k]['y'],
                     self.halo[k]['z'],
                     color=self.orbitColors['halo'],
                     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(
            self.cLevel) + '.mp4'
        animation_function.save(file_name, writer=animation_writer)
    def plot_family(self):
        c_normalized = [(value - min(self.C)) / (max(self.C) - min(self.C))
                        for value in self.C]
        colors = matplotlib.colors.ListedColormap(
            sns.color_palette("viridis_r"))(c_normalized)
        # colors = matplotlib.colors.ListedColormap(sns.dark_palette("blue", reverse=True))(c_normalized)

        sm = plt.cm.ScalarMappable(cmap=matplotlib.colors.ListedColormap(
            sns.color_palette("viridis", len(self.C))),
                                   norm=plt.Normalize(vmin=min(self.C),
                                                      vmax=max(self.C)))
        # sm = plt.cm.ScalarMappable(cmap=sns.dark_palette("blue", as_cmap=True, reverse=True), norm=plt.Normalize(vmin=min(self.C), vmax=max(self.C)))
        # clean the array of the scalar mappable
        sm._A = []

        # Plot 1: 3d overview
        fig1 = plt.figure(figsize=self.figSize)
        ax1 = fig1.gca()

        # Plot 2: subplots
        if self.orbitType == 'horizontal':
            fig2 = plt.figure(figsize=(self.figSize[0], self.figSize[1] / 2))
            ax2 = fig2.add_subplot(1, 2, 1, projection='3d')
            ax5 = fig2.add_subplot(1, 2, 2)
        else:
            fig2 = plt.figure(figsize=self.figSize)
            ax2 = fig2.add_subplot(2, 2, 1, projection='3d')
            ax3 = fig2.add_subplot(2, 2, 4)
            ax4 = fig2.add_subplot(2, 2, 3)
            ax5 = fig2.add_subplot(2, 2, 2)

        lagrange_points_df = load_lagrange_points_location()
        lagrange_point_nrs = ['L1', 'L2']
        # Lagrange points and bodies
        for lagrange_point_nr in lagrange_point_nrs:
            ax1.scatter(lagrange_points_df[lagrange_point_nr]['x'],
                        lagrange_points_df[lagrange_point_nr]['y'],
                        color='black',
                        marker='x')
            ax2.scatter(lagrange_points_df[lagrange_point_nr]['x'],
                        lagrange_points_df[lagrange_point_nr]['y'],
                        lagrange_points_df[lagrange_point_nr]['z'],
                        color='black',
                        marker='x')
            ax5.scatter(lagrange_points_df[lagrange_point_nr]['x'],
                        lagrange_points_df[lagrange_point_nr]['y'],
                        color='black',
                        marker='x')
            if self.orbitType != 'horizontal':
                ax3.scatter(lagrange_points_df[lagrange_point_nr]['x'],
                            lagrange_points_df[lagrange_point_nr]['z'],
                            color='black',
                            marker='x')
                ax4.scatter(lagrange_points_df[lagrange_point_nr]['y'],
                            lagrange_points_df[lagrange_point_nr]['z'],
                            color='black',
                            marker='x')

        bodies_df = load_bodies_location()
        u = np.linspace(0, 2 * np.pi, 100)
        v = np.linspace(0, np.pi, 100)
        x = bodies_df['Moon']['r'] * np.outer(
            np.cos(u), np.sin(v)) + bodies_df['Moon']['x']
        y = bodies_df['Moon']['r'] * np.outer(np.sin(u), np.sin(v))
        z = bodies_df['Moon']['r'] * np.outer(np.ones(np.size(u)), np.cos(v))

        ax1.contourf(x, y, z, colors='black')
        ax2.plot_surface(x, y, z, color='black')
        ax5.contourf(x, y, z, colors='black')
        if self.orbitType != 'horizontal':
            ax3.contourf(x, z, y, colors='black')
            ax4.contourf(y, z, x, colors='black')

        # Determine color for plot
        # colorOrderOfLinearInstability = ['whitesmoke', 'silver', 'dimgrey']
        plot_alpha = 1
        line_width = 0.5

        # Plot every 100th member, including the ultimate member of the family
        spacing_factor = 100

        orbitIdsPlot = list(range(0, len(self.C) - 1, spacing_factor))
        if orbitIdsPlot[-1] != len(self.C) - 1:
            orbitIdsPlot.append(len(self.C) - 1)

        # Plot orbits
        for i in orbitIdsPlot:
            # plot_color = colorOrderOfLinearInstability[self.orderOfLinearInstability[i]]
            nan_correction = sum(
                [1 for nan in self.indexNanEntries if nan < i])
            plot_color = colors[self.plotColorIndexBasedOnC[i -
                                                            nan_correction]]
            df = load_orbit('../../data/raw/orbits/extended/L' +
                            str(self.lagrangePointNr) + '_' + self.orbitType +
                            '_' + str(i) + '.txt')
            ax1.plot(df['x'],
                     df['y'],
                     color=plot_color,
                     alpha=plot_alpha,
                     linewidth=line_width)
            ax2.plot(df['x'],
                     df['y'],
                     df['z'],
                     color=plot_color,
                     alpha=plot_alpha,
                     linewidth=line_width)
            ax5.plot(df['x'],
                     df['y'],
                     color=plot_color,
                     alpha=plot_alpha,
                     linewidth=line_width)
            if self.orbitType != 'horizontal':
                ax3.plot(df['x'],
                         df['z'],
                         color=plot_color,
                         alpha=plot_alpha,
                         linewidth=line_width)
                ax4.plot(df['y'],
                         df['z'],
                         color=plot_color,
                         alpha=plot_alpha,
                         linewidth=line_width)

        # # Plot the bifurcations
        # for i in self.orbitIdBifurcations:
        #     # plot_color = 'b'
        #     nan_correction = sum([1 for nan in self.indexNanEntries if nan < i])
        #     plot_color = colors[self.plotColorIndexBasedOnC[i - nan_correction]]
        #     df = load_orbit('../../data/raw/orbits/extended/L' + str(self.lagrangePointNr) + '_' + self.orbitType + '_' + str(i) + '.txt')
        #     ax1.plot(df['x'], df['y'], color=plot_color, linewidth=3)
        #     ax2.plot(df['x'], df['y'], df['z'], color=plot_color, linewidth=3)
        #     ax5.plot(df['x'], df['y'], color=plot_color, linewidth=3)
        #     if self.orbitType != 'horizontal':
        #         ax3.plot(df['x'], df['z'], color=plot_color, linewidth=3)
        #         ax4.plot(df['y'], df['z'], color=plot_color, linewidth=3)

        ax1.set_xlabel('x [-]')
        ax1.set_ylabel('y [-]')
        ax1.grid(True, which='both', ls=':')

        ax2.set_xlabel('x [-]')
        ax2.set_ylabel('y [-]')
        ax2.set_zlabel('z [-]')
        ax2.set_zlim([-1.2, 1.2])
        ax2.grid(True, which='both', ls=':')
        ax2.view_init(30, -120)

        if self.orbitType != 'horizontal':
            ax3.set_xlabel('x [-]')
            ax3.set_ylabel('z [-]')
            ax3.set_ylim([-1.2, 1.2])
            ax3.grid(True, which='both', ls=':')

            ax4.set_xlabel('y [-]')
            ax4.set_ylabel('z [-]')
            ax4.set_ylim([-1.2, 1.2])
            ax4.grid(True, which='both', ls=':')

        ax5.set_xlabel('x [-]')
        ax5.set_ylabel('y [-]')
        ax5.grid(True, which='both', ls=':')

        fig2.tight_layout()
        if self.orbitType == 'horizontal':
            fig2.subplots_adjust(top=0.8)
        else:
            fig2.subplots_adjust(top=0.9)

        if self.orbitType != 'horizontal':
            cax, kw = matplotlib.colorbar.make_axes([ax2, ax3, ax4, ax5])
        else:
            cax, kw = matplotlib.colorbar.make_axes([ax2, ax5])
        cbar = plt.colorbar(sm, cax=cax, label='C [-]', **kw)

        plt.suptitle('$L_' + str(self.lagrangePointNr) + '$ ' +
                     self.orbitTypeForTitle + ' - Orthographic projection',
                     size=self.suptitleSize)

        fig1.suptitle('$L_' + str(self.lagrangePointNr) + '$ ' +
                      self.orbitTypeForTitle + ': family',
                      size=self.suptitleSize)

        fig2.savefig('../../data/figures/orbits/extended/L' +
                     str(self.lagrangePointNr) + '_' + self.orbitType +
                     '_family_subplots.pdf',
                     transparent=True)
        plt.close(fig2)

        plt.close()
        pass
    def animate(self):
        fig = plt.figure()
        self.ax = fig.add_subplot(111, projection='3d')
        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_2d_shooting_conditions(self):
        fig = plt.figure(figsize=self.figSize)
        ax = fig.gca()

        orbit_types = ['horizontal', 'vertical', 'halo']
        lagrange_point_nrs = [1, 2]

        x = []
        z = []
        ydot = []
        c = []
        for idx, orbit_type in enumerate(orbit_types):
            for lagrange_point_nr in lagrange_point_nrs:
                if orbit_type == 'vertical':
                    initial_conditions_file_path = '../../data/raw/orbits/extended/L' + str(
                        lagrange_point_nr) + '_' + orbit_type + '_initial_conditions.txt'
                else:
                    initial_conditions_file_path = '../../data/raw/orbits/L' + str(
                        lagrange_point_nr) + '_' + orbit_type + '_initial_conditions.txt'

                initial_conditions_incl_m_df = load_initial_conditions_incl_M(initial_conditions_file_path)

                plot_label = orbit_type.capitalize()
                if plot_label == 'Horizontal' or plot_label == 'Vertical':
                    plot_label += ' Lyapunov'

                x.extend(list(initial_conditions_incl_m_df[2].values))
                z.extend(list(initial_conditions_incl_m_df[4].values))
                c.extend(list(initial_conditions_incl_m_df[0].values))

        sc = ax.scatter(x, z, c=c, cmap='viridis', s=20)
        cb = plt.colorbar(sc)
        cb.set_label('$C \enskip [-]$')

        lagrange_points_df = load_lagrange_points_location()
        lagrange_point_nrs = ['L1', 'L2', 'L3']
        # Lagrange points and bodies
        for lagrange_point_nr in lagrange_point_nrs:
            ax.scatter(lagrange_points_df[lagrange_point_nr]['x'], lagrange_points_df[lagrange_point_nr]['z'], color='black', marker='x')

        bodies_df = load_bodies_location()
        u = np.linspace(0, 2 * np.pi, 100)
        v = np.linspace(0, np.pi, 100)
        for body in bodies_df:
            x = bodies_df[body]['r'] * np.outer(np.cos(u), np.sin(v)) + bodies_df[body]['x']
            y = bodies_df[body]['r'] * np.outer(np.sin(u), np.sin(v))
            z = bodies_df[body]['r'] * np.outer(np.ones(np.size(u)), np.cos(v))
            ax.contourf(x, z, y, colors='black')

        ax.legend(frameon=True, loc='upper right')
        ax.set_xlabel('x [-]')
        ax.set_ylabel('z [-]')
        ax.grid(True, which='both', ls=':')
        fig.tight_layout()
        fig.subplots_adjust(top=0.9)
        plt.suptitle('$L_1, L_2$ - Shooting conditions for H-L, halo, and V-L', size=self.suptitleSize)
        if self.lowDPI:
            fig.savefig('../../data/figures/orbits/extended/orbit_shooting_conditions_2d.png', transparent=True, dpi=self.dpi)
        else:
            fig.savefig('../../data/figures/orbits/extended/orbit_shooting_conditions_2d.pdf', transparent=True)
        pass
    def plot_2d_3d_shooting_conditions(self):
        fig = plt.figure(figsize=self.figSize)
        ax1 = fig.add_subplot(1, 2, 1, projection='3d')
        ax2 = fig.add_subplot(1, 2, 2)

        orbit_types = ['horizontal', 'vertical', 'halo']
        lagrange_point_nrs = [1, 2]

        x = []
        z = []
        c = []
        lines = []
        linewidth = 2
        for lagrange_point_nr in lagrange_point_nrs:
            for idx, orbit_type in enumerate(orbit_types):
                initial_conditions_file_path = '../../data/raw/orbits/L' + str(
                    lagrange_point_nr) + '_' + orbit_type + '_initial_conditions.txt'
                initial_conditions_incl_m_df = load_initial_conditions_incl_M(initial_conditions_file_path)

                plot_label = orbit_type.capitalize()
                if plot_label == 'Horizontal' or plot_label == 'Vertical':
                    plot_label += ' Lyapunov'

                line, = ax1.plot(initial_conditions_incl_m_df[2].values, initial_conditions_incl_m_df[6].values,
                                 initial_conditions_incl_m_df[4].values, label=plot_label, linewidth=linewidth,
                                 color=self.plottingColors['tripleLine'][idx])
                # ax2.plot(initial_conditions_incl_m_df[2].values, initial_conditions_incl_m_df[4].values,
                #          linewidth=linewidth, color=self.plottingColors['tripleLine'][idx])
                lines.append(line)
                x.extend(list(initial_conditions_incl_m_df[2].values))
                z.extend(list(initial_conditions_incl_m_df[4].values))
                c.extend(list(initial_conditions_incl_m_df[0].values))

        sc = ax2.scatter(x, z, c=c, cmap='viridis', s=10)
        cb = plt.colorbar(sc)
        cb.set_label('$C \enskip [-]$')

        # Lagrange points and bodies
        lagrange_points_df = load_lagrange_points_location()
        lagrange_point_nrs = ['L1', 'L2']
        for lagrange_point_nr in lagrange_point_nrs:
            ax1.scatter(lagrange_points_df[lagrange_point_nr]['x'], lagrange_points_df[lagrange_point_nr]['z'],
                        color='black', marker='x')
            ax2.scatter(lagrange_points_df[lagrange_point_nr]['x'], lagrange_points_df[lagrange_point_nr]['z'],
                        color='black', marker='x')

        bodies_df = load_bodies_location()
        u = np.linspace(0, 2 * np.pi, 100)
        v = np.linspace(0, np.pi, 100)
        for body in bodies_df:
            x = bodies_df[body]['r'] * np.outer(np.cos(u), np.sin(v)) + bodies_df[body]['x']
            y = bodies_df[body]['r'] * np.outer(np.sin(u), np.sin(v))
            z = bodies_df[body]['r'] * np.outer(np.ones(np.size(u)), np.cos(v))
            ax1.plot_surface(x, y, z, color='black')
            ax2.contourf(x, z, y, colors='black')

        # print(ax1.elev)
        # print(ax1.azim)
        # ax1.view_init(10, -40)
        # plt.plot(ax1.get_xlim(), [0, 0], 'black', linewidth=0.5)
        # plt.plot(ax2.get_xlim(), [0, 0], 'black', linewidth=0.5)
        ax1.legend(frameon=True, loc='upper right', handles=lines[:3])
        ax1.set_xlabel('x [-]')
        ax1.set_ylabel('$\dot{y}$ [-]')
        ax1.set_zlabel('z [-]')

        ax1.grid(True, which='both', ls=':')
        ax2.set_xlabel('x [-]')
        ax2.set_ylabel('z [-]')
        ax2.grid(True, which='both', ls=':')
        ax2.set_ylim([-0.4, 0.8])

        fig.tight_layout()
        fig.subplots_adjust(top=0.9)
        plt.suptitle('$L_1, L_2$ - Shooting conditions', size=self.suptitleSize)
        fig.savefig('../../data/figures/orbits/orbit_shooting_conditions_2d_3d.pdf', transparent=True)
        pass
Пример #11
0
    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
Пример #12
0
    def plot_image_trajectories(self, theta):
        line_width_near_heteroclinic = 3

        print('Theta:')
        # for theta in self.thetaRangeList:
        print(theta)

        df_s = load_manifold_refactored('../../data/raw/poincare_sections/' +
                                        str(self.numberOfOrbitsPerManifold) +
                                        '/L2_' + self.orbitType +
                                        '_W_S_min_3.1_' + str(int(theta)) +
                                        '_full.txt')
        df_u = load_manifold_refactored('../../data/raw/poincare_sections/' +
                                        str(self.numberOfOrbitsPerManifold) +
                                        '/L1_' + self.orbitType +
                                        '_W_U_plus_3.1_' + str(int(theta)) +
                                        '_full.txt')
        print(df_s)

        fig = plt.figure(figsize=self.figSize)
        ax0 = fig.add_subplot(111, projection='3d')

        plot_alpha = 1

        # Plot near-heteroclinic connection
        index_near_heteroclinic_s = int(
            self.minimumImpulse.loc[theta]['taus'] *
            self.numberOfOrbitsPerManifold)
        index_near_heteroclinic_u = int(
            self.minimumImpulse.loc[theta]['tauu'] *
            self.numberOfOrbitsPerManifold)

        # for i in range(0, 5000, 50):
        #     ax0.plot(df_s.xs(i)['x'], df_s.xs(i)['y'],
        #              df_s.xs(i)['z'], color='g', alpha=plot_alpha,
        #              linewidth=0.5)
        #     ax0.plot(df_u.xs(i)['x'], df_u.xs(i)['y'],
        #              df_u.xs(i)['z'], color='r', alpha=plot_alpha,
        #              linewidth=0.5)

        # (T1)
        ax0.plot(df_s.xs(index_near_heteroclinic_s)['x'],
                 df_s.xs(index_near_heteroclinic_s)['y'],
                 df_s.xs(index_near_heteroclinic_s)['z'],
                 color='g',
                 alpha=plot_alpha,
                 linewidth=line_width_near_heteroclinic)
        ax0.plot(df_u.xs(index_near_heteroclinic_u)['x'],
                 df_u.xs(index_near_heteroclinic_u)['y'],
                 df_u.xs(index_near_heteroclinic_u)['z'],
                 color='r',
                 alpha=plot_alpha,
                 linewidth=line_width_near_heteroclinic)

        # # (T4)
        # ax0.plot(df_s.xs(index_near_heteroclinic_s)['x'], -df_s.xs(index_near_heteroclinic_s)['y'], df_s.xs(index_near_heteroclinic_s)['z'], color='r', alpha=plot_alpha, linewidth=line_width_near_heteroclinic)
        # ax0.plot(df_u.xs(index_near_heteroclinic_u)['x'], -df_u.xs(index_near_heteroclinic_u)['y'], df_u.xs(index_near_heteroclinic_u)['z'], color='g', alpha=plot_alpha, linewidth=line_width_near_heteroclinic)
        #
        # # (T3)
        # ax0.plot(df_s.xs(index_near_heteroclinic_s)['x'], df_s.xs(index_near_heteroclinic_s)['y'],
        #          -df_s.xs(index_near_heteroclinic_s)['z'], color='g', alpha=plot_alpha,
        #          linewidth=line_width_near_heteroclinic)
        # ax0.plot(df_u.xs(index_near_heteroclinic_u)['x'], df_u.xs(index_near_heteroclinic_u)['y'],
        #          -df_u.xs(index_near_heteroclinic_u)['z'], color='r', alpha=plot_alpha,
        #          linewidth=line_width_near_heteroclinic)
        # # (T2)
        # ax0.plot(df_s.xs(index_near_heteroclinic_s)['x'], -df_s.xs(index_near_heteroclinic_s)['y'],
        #          -df_s.xs(index_near_heteroclinic_s)['z'], color='r', alpha=plot_alpha,
        #          linewidth=line_width_near_heteroclinic)
        # ax0.plot(df_u.xs(index_near_heteroclinic_u)['x'], -df_u.xs(index_near_heteroclinic_u)['y'],
        #          -df_u.xs(index_near_heteroclinic_u)['z'], color='g', alpha=plot_alpha,
        #          linewidth=line_width_near_heteroclinic)

        bodies_df = load_bodies_location()
        u = np.linspace(0, 2 * np.pi, 100)
        v = np.linspace(0, np.pi, 100)
        # for body in ['Earth', 'Moon']:
        for body in ['Moon']:
            x = bodies_df[body]['r'] * np.outer(
                np.cos(u), np.sin(v)) + bodies_df[body]['x']
            y = bodies_df[body]['r'] * np.outer(np.sin(u), np.sin(v))
            z = bodies_df[body]['r'] * np.outer(np.ones(np.size(u)), np.cos(v))
            ax0.plot_surface(x, y, z, color='black')

        # Lagrange points and bodies
        lagrange_points_df = load_lagrange_points_location()
        lagrange_point_nrs = ['L1', 'L2']
        for lagrange_point_nr in lagrange_point_nrs:
            ax0.scatter(lagrange_points_df[lagrange_point_nr]['x'],
                        lagrange_points_df[lagrange_point_nr]['y'],
                        lagrange_points_df[lagrange_point_nr]['z'],
                        color='black',
                        marker='x')

        # Create cubic bounding box to simulate equal aspect ratio
        max_range = np.array([
            max(df_s['x'].max(), df_u['x'].max()) -
            min(df_s['x'].min(), df_u['x'].min()),
            max(df_s['y'].max(), df_u['y'].max()) -
            min(df_s['y'].min(), df_u['y'].min()),
            max(df_s['z'].max(), df_u['z'].max()) -
            min(df_s['z'].min(), df_u['z'].min())
        ]).max()

        Xb = 0.3 * max_range * np.mgrid[-1:2:2, -1:2:2, -1:2:2][0].flatten(
        ) + 0.2 * (max(df_s['x'].max(), df_u['x'].max()) +
                   min(df_s['x'].min(), df_u['x'].min()))
        Yb = 0.3 * max_range * np.mgrid[-1:2:2, -1:2:2, -1:2:2][1].flatten(
        ) + 0.5 * (max(df_s['y'].max(), df_u['y'].max()) +
                   min(df_s['y'].min(), df_u['y'].min()))
        Zb = 0.3 * max_range * np.mgrid[-1:2:2, -1:2:2, -1:2:2][2].flatten(
        ) + 0.5 * (max(df_s['z'].max(), df_u['z'].max()) +
                   min(df_s['z'].min(), df_u['z'].min()))
        # Comment or uncomment following both lines to test the fake bounding box:
        if self.orbitType != 'halo':
            for xb, yb, zb in zip(Xb, Yb, Zb):
                ax0.plot([xb], [yb], [zb], 'w')

        # azim=150
        # elev=25
        print(ax0.azim)
        print(ax0.elev)
        ax0.view_init(elev=15, azim=220)  # Single line
        # ax0.view_init(elev=20, azim=240)  # Manifold lines
        plt.tight_layout()
        plt.axis('off')
        # plt.show()

        plt.savefig('../../data/figures/cover_page.pdf', transparent=True)
        plt.close()
        pass
    def 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')
        fig.savefig('../../data/figures/new_family_of_equal_energy.pdf',
                    transparent=True)
        # tikz_save('../../../data/figures/family_of_equal_energy.tex')
        plt.close()
        pass