def __init__(self, w_s, w_u, u_section):
        self.WS = load_manifold('../../data/raw/' + w_s + '.txt')
        self.WU = load_manifold('../../data/raw/' + w_u + '.txt')
        self.numberOfOrbitsPerManifold = len(set(self.WS.index.get_level_values(0)))
        self.U_section = u_section

        # Select last entry of manifolds
        ls_s = []
        ls_u = []

        for i in range(100):
            ls_s.append(self.WS.xs(i).tail(1))
            ls_u.append(self.WU.xs(i).tail(1))

        self.poincareWS = pd.concat(ls_s).reset_index(drop=True)
        self.poincareWU = pd.concat(ls_u).reset_index(drop=True)

        self.figSize = (40, 40)
        self.titleSize = 20
        self.suptitleSize = 30

        EARTH_GRAVITATIONAL_PARAMETER = 3.986004418E14
        SUN_GRAVITATIONAL_PARAMETER = 1.32712440018e20
        MOON_GRAVITATIONAL_PARAMETER = SUN_GRAVITATIONAL_PARAMETER / (328900.56 * (1.0 + 81.30059))
        self.massParameter = MOON_GRAVITATIONAL_PARAMETER / (MOON_GRAVITATIONAL_PARAMETER + EARTH_GRAVITATIONAL_PARAMETER)
        pass
예제 #2
0
    def __init__(self, w_s, w_u, u_section, round_order_connection):

        # orbit_idx = []
        # for l_point, orbit_type in [(l_point_1, orbit_type_1), (l_point_2, orbit_type_2)]
        #     df = load_initial_conditions_incl_M('../../data/raw/' + l_point + '_' + orbit_type + '_initial_conditions.txt')
        #     orbit_idx.append(df[abs(df[0] - C) == (abs(df[0] - C)).min()].index)

        l_point, orbit_type, orbit_id, w, s, sign = w_s.split('_')
        self.C = [
            load_initial_conditions_incl_M('../../data/raw/' + l_point + '_' +
                                           orbit_type +
                                           '_initial_conditions.txt').xs(
                                               int(orbit_id))[0]
        ]
        l_point, orbit_type, orbit_id, w, s, sign = w_u.split('_')
        self.C.append(
            load_initial_conditions_incl_M('../../data/raw/' + l_point + '_' +
                                           orbit_type +
                                           '_initial_conditions.txt').xs(
                                               int(orbit_id))[0])

        self.WS = load_manifold('../../data/raw/' + w_s + '.txt')
        self.WU = load_manifold('../../data/raw/' + w_u + '.txt')
        self.numberOfOrbitsPerManifold = len(
            set(self.WS.index.get_level_values(0)))
        self.U_section = u_section
        self.roundOrderConnection = round_order_connection
        # Select last entry of manifolds
        ls_s = []
        ls_u = []

        for i in range(len(set(self.WS.index.get_level_values(0)))):
            ls_s.append(self.WS.xs(i).tail(1))
            ls_u.append(self.WU.xs(i).tail(1))

        self.poincareWS = pd.concat(ls_s).reset_index(drop=True)
        self.poincareWU = pd.concat(ls_u).reset_index(drop=True)

        self.figSize = (40, 40)
        self.titleSize = 20
        self.suptitleSize = 30

        EARTH_GRAVITATIONAL_PARAMETER = 3.986004418E14
        SUN_GRAVITATIONAL_PARAMETER = 1.32712440018e20
        MOON_GRAVITATIONAL_PARAMETER = SUN_GRAVITATIONAL_PARAMETER / (
            328900.56 * (1.0 + 81.30059))
        self.massParameter = MOON_GRAVITATIONAL_PARAMETER / (
            MOON_GRAVITATIONAL_PARAMETER + EARTH_GRAVITATIONAL_PARAMETER)
        pass
예제 #3
0
    def __init__(self, w_s, w_u):
        self.stableManifold = load_manifold('../../data/raw/manifolds/' + w_s + '.txt')
        self.unstableManifold = load_manifold('../../data/raw/manifolds/' + w_u + '.txt')
        self.numberOfOrbitsPerManifold = len(set(self.stableManifold.index.get_level_values(0)))

        # Assemble states at Poincaré section (end of file)
        ls_s = []
        ls_u = []

        # plt.figure()
        ls_dx = []
        ls_dy = []
        ls_dz = []
        ls_dxdot = []
        ls_dydot = []
        ls_dzdot = []

        for i in range(self.numberOfOrbitsPerManifold):
                for j in range(self.numberOfOrbitsPerManifold):
                    # ls_s.append(self.stableManifold.xs(i).tail(1))
                    # ls_u.append(self.unstableManifold.xs(i).tail(1))

                    ls_dx.append(self.stableManifold.xs(i).tail(1)['x'].values-self.unstableManifold.xs(j).tail(1)['x'].values)
                    ls_dy.append(self.stableManifold.xs(i).tail(1)['y'].values - self.unstableManifold.xs(j).tail(1)['y'].values)
                    ls_dz.append(self.stableManifold.xs(i).tail(1)['z'].values - self.unstableManifold.xs(j).tail(1)['z'].values)

                    ls_dxdot.append(self.stableManifold.xs(i).tail(1)['xdot'].values - self.unstableManifold.xs(j).tail(1)['xdot'].values)
                    ls_dydot.append(self.stableManifold.xs(i).tail(1)['ydot'].values - self.unstableManifold.xs(j).tail(1)['ydot'].values)
                    ls_dzdot.append(self.stableManifold.xs(i).tail(1)['zdot'].values - self.unstableManifold.xs(j).tail(1)['zdot'].values)

        f, axarr = plt.subplots(2)
        axarr[0].scatter(list(range(len(ls_dx))), ls_dx)
        axarr[0].scatter(list(range(len(ls_dx))), ls_dy)
        axarr[0].scatter(list(range(len(ls_dx))), ls_dz)
        axarr[1].scatter(list(range(len(ls_dx))), ls_dxdot)
        axarr[1].scatter(list(range(len(ls_dx))), ls_dydot)
        axarr[1].scatter(list(range(len(ls_dx))), ls_dzdot)

        axarr[0].set_ylim([-0.01, 0.01])
        axarr[1].set_ylim([-0.01, 0.01])
        plt.show()

        EARTH_GRAVITATIONAL_PARAMETER = 3.986004418E14
        SUN_GRAVITATIONAL_PARAMETER = 1.32712440018e20
        MOON_GRAVITATIONAL_PARAMETER = SUN_GRAVITATIONAL_PARAMETER / (328900.56 * (1.0 + 81.30059))
        self.massParameter = MOON_GRAVITATIONAL_PARAMETER / (MOON_GRAVITATIONAL_PARAMETER + EARTH_GRAVITATIONAL_PARAMETER)
        pass
    def __init__(self, config, orbit_type):
        self.orbit = []
        self.manifold_S_plus, self.manifold_S_min, self.manifold_U_plus, self.manifold_U_min = [], [], [], []
        self.config = config
        self.orbitType = orbit_type
        self.massParameter = 0.0121505810173
        self.numberOfManifolds = 100
        self.figSize = (40, 40)
        self.titleSize = 20
        self.suptitleSize = 30

        orbit_ids = []
        for orbit_id in list(self.config[self.orbitType].keys()):
            ls = orbit_id.split('_')
            if orbit_type == 'near_vertical':
                orbit_ids.append(int(ls[2]))
            if orbit_type == 'halo':
                orbit_ids.append(int(ls[1]))
        orbit_ids = [
            self.orbitType + '_' + str(idx) for idx in sorted(orbit_ids)
        ]

        for orbit_id in orbit_ids:
            self.orbit.append(
                load_orbit('../data/raw/' + orbit_id + '_final_orbit.txt'))
            self.manifold_S_plus.append(
                load_manifold('../data/raw/' + orbit_id + '_W_S_plus.txt'))
            self.manifold_S_min.append(
                load_manifold('../data/raw/' + orbit_id + '_W_S_min.txt'))
            self.manifold_U_plus.append(
                load_manifold('../data/raw/' + orbit_id + '_W_U_plus.txt'))
            self.manifold_U_min.append(
                load_manifold('../data/raw/' + orbit_id + '_W_U_min.txt'))

        self.lagrangePoints = load_lagrange_points_location()
        self.bodies = load_bodies_location()

        sns.set_style("whitegrid")
        pass
예제 #5
0
            for idx in range(numberOfOrbitsPerManifolds)
        ]
        lines.extend([
            plt.plot([], [], color=color_palette_green[idx])[0]
            for idx in range(numberOfOrbitsPerManifolds)
        ])
        lines.extend([
            plt.plot([], [], color=color_palette_red[idx])[0]
            for idx in range(numberOfOrbitsPerManifolds)
        ])
        lines.extend([
            plt.plot([], [], color=color_palette_red[idx])[0]
            for idx in range(numberOfOrbitsPerManifolds)
        ])

        manifold_S_plus = load_manifold('../data/raw/' + orbit_name +
                                        '_W_S_plus.txt')
        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)
    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)