Example #1
0
		def plot(self,x):
			import matplotlib as mpl
			from mpl_toolkits.mplot3d import Axes3D
			import matplotlib.pyplot as plt
			from PyKEP import epoch, AU
			from PyKEP.sims_flanagan import sc_state
			from PyKEP.orbit_plots import plot_planet, plot_sf_leg
			
			start = epoch(x[0])
			end = epoch(x[0] + x[1])
			r,v = self.__earth.eph(start)
			v = [a+b for a,b in zip(v,x[3:6])]
			x0 = sc_state(r,v,self.__sc.mass)
			r,v = self.__mars.eph(end)
			xe = sc_state(r, v ,x[2])
			self.__leg.set(start,x0,x[-3 * self.__nseg:],end,xe)
			
			fig = plt.figure()
			ax = fig.gca(projection='3d')
			#The Sun
			ax.scatter([0],[0],[0], color='y')
			#The leg
			plot_sf_leg(ax, self.__leg, units=AU,N=10)
			#The planets
			plot_planet(ax, self.__earth, start, units=AU, legend = True,color=(0.8,0.8,1))
			plot_planet(ax, self.__mars, end, units=AU, legend = True,color=(0.8,0.8,1))
			plt.show()
Example #2
0
		def plot(self,x):
			import matplotlib as mpl
			from mpl_toolkits.mplot3d import Axes3D
			import matplotlib.pyplot as plt
			from PyKEP import epoch, AU, DAY2SEC
			from PyKEP.sims_flanagan import sc_state
			from PyKEP.orbit_plots import plot_planet, plot_sf_leg
			
			start = epoch(x[0])
			end = epoch(x[0] + x[1])
			
			r,v = self.__earth.eph(start)
			v = [a+b for a,b in zip(v,x[4:7])]
			x0 = sc_state(r,v,self.__sc.mass)
			
			r,v = self.__mars.eph(end)
			xe = sc_state(r, v ,x[3])
			self.__leg.set(start,x0,x[-3 * self.__nseg:],end,xe, x[2] * DAY2SEC)
			
			fig = plt.figure()
			axis = fig.gca(projection='3d')
			#The Sun
			axis.scatter([0],[0],[0], color='y')
			#The leg
			plot_sf_leg(self.__leg, units=AU,N=10, ax = axis)
			#The planets
			plot_planet(self.__earth, start, units=AU, legend = True,color=(0.8,0.8,1), ax = axis)
			plot_planet(self.__mars, end, units=AU, legend = True,color=(0.8,0.8,1), ax = axis)
			plt.show()
	def plot(self,x):
		import matplotlib as mpl
		from mpl_toolkits.mplot3d import Axes3D
		import matplotlib.pyplot as plt
		from PyKEP.orbit_plots import plot_planet, plot_sf_leg

		mpl.rcParams['legend.fontsize'] = 10
		fig = plt.figure()
		ax = fig.gca(projection='3d')
		ax.scatter(0,0,0, color='y')

		# 1 - We decode the chromosome extracting the time of flights
		T = list([0]*(self.__n_legs))
		for i in range(self.__n_legs):
			T[i] = x[2+i*8]
			
		#2 - We compute the epochs and ephemerides of the planetary encounters
		t_P = list([None] * (self.__n_legs+1))
		r_P = list([None] * (self.__n_legs+1))
		v_P = list([None] * (self.__n_legs+1))
		
		for i,planet in enumerate(self.seq):
			t_P[i+1] = epoch(self.tf - sum(T[i+1:]))
			r_P[i+1],v_P[i+1] = self.seq[i].eph(t_P[i+1])
			plot_planet(ax, self.seq[i], t_P[i+1], units=JR, legend = True,color='k')
			
		#And we insert a fake planet simulating the starting position
		t_P[0] = epoch(self.tf - sum(T))
		theta = x[0]
		phi = x[1]
		r = [cos(phi)*sin(theta), cos(phi)*cos(theta), sin(phi)] #phi close to zero is in the moon orbit plane injection
		r = [JR*1000*d for d in r]
		r_P[0] = r
		v_P[0] = x[4:7]
		
		#3 - We iterate through legs to compute mismatches and throttles constraints
		ceq = list()
		cineq = list()
		m0 = self.__sc.mass
		for i in range(self.__n_legs):

			if i!=0: #First Leg
				v = [a+b for a,b in zip(v_P[i],x[(4 + i * 8):(7 + i * 8)])]
			else:
				v = v_P[i]
			x0 = sc_state(r_P[i],v,m0)
			v = [a+b for a,b in zip(v_P[i+1],x[(7 + i * 8):(10 + i * 8)])]
			if (i==self.__n_legs-1): #Last leg
				v = [a+b for a,b in zip(v_P[i+1],self.vf)]
			xe = sc_state(r_P[i+1], v ,x[3+8*i])
			throttles = x[(8*self.__n_legs-1 + 3*sum(self.__n_seg[:i])):(8*self.__n_legs-1 + 3*sum(self.__n_seg[:i])+3*self.__n_seg[i])]
			self.__leg.set(t_P[i],x0,throttles,t_P[i+1],xe)
			plot_sf_leg(ax, self.__leg, units=JR,N=50)
			#update mass!
			m0 = x[3+8*i]
			ceq.extend(self.__leg.mismatch_constraints())
			cineq.extend(self.__leg.throttles_constraints())
			#raise Exception    
		plt.show()
		return ax
Example #4
0
        def plot(self, x):
            import matplotlib as mpl
            from mpl_toolkits.mplot3d import Axes3D
            import matplotlib.pyplot as plt
            from PyKEP import epoch, AU
            from PyKEP.sims_flanagan import sc_state
            from PyKEP.orbit_plots import plot_planet, plot_sf_leg

            # Making sure the leg corresponds to the requested chromosome
            self._compute_constraints_impl(x)
            start = epoch(x[0])
            end = epoch(x[0] + x[1])

            # Plotting commands
            fig = plt.figure()
            axis = fig.gca(projection='3d')
            # The Sun
            axis.scatter([0], [0], [0], color='y')
            # The leg
            plot_sf_leg(self.__leg, units=AU, N=10, ax=axis)
            # The planets
            plot_planet(
                self.__earth, start, units=AU, legend=True, color=(0.8, 0.8, 1), ax = axis)
            plot_planet(
                self.__mars, end, units=AU, legend=True, color=(0.8, 0.8, 1), ax = axis)
            plt.show()
Example #5
0
        def plot(self, x):
            import matplotlib as mpl
            from mpl_toolkits.mplot3d import Axes3D
            import matplotlib.pyplot as plt
            from PyKEP import epoch, AU
            from PyKEP.sims_flanagan import sc_state
            from PyKEP.orbit_plots import plot_planet, plot_sf_leg

            t_E = epoch(x[0])
            t_V = epoch(x[0] + x[1])
            t_M = epoch(x[0] + x[1] + x[9])
            rE, vE = self.__earth.eph(t_E)
            rV, vV = self.__venus.eph(t_V)
            rM, vM = self.__mercury.eph(t_M)

            #First Leg
            v = [a + b for a, b in zip(vE, x[3:6])]
            x0 = sc_state(rE, v, self.__sc.mass)
            v = [a + b for a, b in zip(vV, x[6:9])]
            xe = sc_state(rV, v, x[2])
            self.__leg1.set(
                t_E, x0,
                x[-3 * (self.__nseg1 + self.__nseg2):-self.__nseg2 * 3], t_V,
                xe)

            #Second leg
            v = [a + b for a, b in zip(vV, x[11:14])]
            x0 = sc_state(rV, v, x[2])
            v = [a + b for a, b in zip(vM, x[14:17])]
            xe = sc_state(rM, v, x[10])
            self.__leg2.set(t_E, x0, x[(-3 * self.__nseg2):], t_V, xe)

            fig = plt.figure()
            axis = fig.gca(projection='3d')

            #The Sun
            axis.scatter([0], [0], [0], color='y')
            #The legs
            plot_sf_leg(self.__leg1, units=AU, N=10, ax=axis)
            plot_sf_leg(self.__leg2, units=AU, N=10, ax=axis)
            #The planets
            plot_planet(self.__earth,
                        t_E,
                        units=AU,
                        legend=True,
                        color=(0.7, 0.7, 1),
                        ax=axis)
            plot_planet(self.__venus,
                        t_V,
                        units=AU,
                        legend=True,
                        color=(0.7, 0.7, 1),
                        ax=axis)
            plot_planet(self.__mercury,
                        t_M,
                        units=AU,
                        legend=True,
                        color=(0.7, 0.7, 1),
                        ax=axis)
            plt.show()
Example #6
0
	def plot(self,x):
		"""	
		Plots the trajectory represented by the decision vector x
		
		Example::
		
		  prob.plot(x)
		"""
		import matplotlib as mpl
		from mpl_toolkits.mplot3d import Axes3D
		import matplotlib.pyplot as plt
		from PyKEP import epoch, AU
		from PyKEP.sims_flanagan import sc_state
		from PyKEP.orbit_plots import plot_planet, plot_sf_leg
		
		fig = plt.figure()
		ax = fig.gca(projection='3d')

		#Plotting the Sun ........
		ax.scatter([0],[0],[0], color='y')
		
		#Plotting the legs .......
		
		# 1 - We decode the chromosome extracting the time of flights
		T = list([0]*(self.__n_legs))
		for i in range(self.__n_legs):
			T[i] = x[1+i*8]
			
		#2 - We compute the epochs and ephemerides of the planetary encounters
		t_P = list([None] * (self.__n_legs+1))
		r_P = list([None] * (self.__n_legs+1))
		v_P = list([None] * (self.__n_legs+1))
		
		for i,planet in enumerate(self.seq):
			t_P[i] = epoch(x[0] + sum(T[0:i]))
			r_P[i],v_P[i] = self.seq[i].eph(t_P[i])
		
		#3 - We iterate through legs to compute mismatches and throttles constraints
		ceq = list()
		cineq = list()
		m0 = self.__sc.mass
		for i in range(self.__n_legs):
			#First Leg
			v = [a+b for a,b in zip(v_P[i],x[(3 + i * 8):(6 + i * 8)])]
			x0 = sc_state(r_P[i],v,m0)
			v = [a+b for a,b in zip(v_P[i+1],x[(6 + i * 8):(11 + i * 8)])]
			xe = sc_state(r_P[i+1], v ,x[2 + i * 8])
			throttles = x[(1 +8 * self.__n_legs + 3*sum(self.__n_seg[:i])):(1 +8 * self.__n_legs + 3*sum(self.__n_seg[:i])+3*self.__n_seg[i])]
			self.__leg.set(t_P[i],x0,throttles,t_P[i+1],xe)
			#update mass!
			m0 = x[2+8*i]
			plot_sf_leg(ax, self.__leg, units=AU,N=10)
			
		#Plotting planets
		for i,planet in enumerate(self.seq):
			plot_planet(ax, planet, t_P[i], units=AU, legend = True,color=(0.7,0.7,1))

		plt.show()
Example #7
0
    def plot(self, x, ax=None):
        """
        ax = prob.plot(x, ax=None)

        - x: encoded trajectory
        - ax: matplotlib axis where to plot. If None figure and axis will be created
        - [out] ax: matplotlib axis where to plot

        Plots the trajectory represented by a decision vector x on the 3d axis ax

        Example::

          ax = prob.plot(x)
        """
        import matplotlib as mpl
        from mpl_toolkits.mplot3d import Axes3D
        import matplotlib.pyplot as plt
        from PyKEP import epoch, AU
        from PyKEP.sims_flanagan import sc_state
        from PyKEP.orbit_plots import plot_planet, plot_sf_leg

        # Creating the axis if necessary
        if ax is None:
            mpl.rcParams['legend.fontsize'] = 10
            fig = plt.figure()
            axis = fig.gca(projection='3d')
        else:
            axis = ax

        # Plotting the Sun ........
        axis.scatter([0], [0], [0], color='y')

        # Computing the legs
        self._compute_constraints_impl(x)

        # Plotting the legs
        for leg in self.__legs:
            plot_sf_leg(leg, units=AU, N=10, ax=axis)

        # Plotting the PyKEP.planets both at departure and arrival dates
        for i in range(self.__num_legs):
            idx = i * self.__dim_leg
            plot_planet(self.__seq[i],
                        epoch(x[idx]),
                        units=AU,
                        legend=True,
                        color=(0.7, 0.7, 1),
                        s=30,
                        ax=axis)
            plot_planet(self.__seq[i + 1],
                        epoch(x[idx] + x[idx + 1]),
                        units=AU,
                        legend=False,
                        color=(0.7, 0.7, 1),
                        s=30,
                        ax=axis)
        plt.show()
        return axis
Example #8
0
    def plot(self, x, ax=None):
        """
        ax = prob.plot(x, ax=None)

        - x: encoded trajectory
        - ax: matplotlib axis where to plot. If None figure and axis will be created
        - [out] ax: matplotlib axis where to plot

        Plots the trajectory represented by a decision vector x on the 3d axis ax

        Example::

          ax = prob.plot(x)
        """
        import matplotlib as mpl
        from mpl_toolkits.mplot3d import Axes3D
        import matplotlib.pyplot as plt
        from PyKEP import epoch, AU
        from PyKEP.sims_flanagan import sc_state
        from PyKEP.orbit_plots import plot_planet, plot_sf_leg

        # Creating the axis if necessary
        if ax is None:
            mpl.rcParams['legend.fontsize'] = 10
            fig = plt.figure()
            axis = fig.gca(projection='3d')
        else:
            axis = ax

        # Plotting the Sun ........
        axis.scatter([0], [0], [0], color='y')

        # Computing the legs
        self._compute_constraints_impl(x)

        # Plotting the legs
        for leg in self.__legs:
            plot_sf_leg(leg, units=AU, N=10, ax=axis)

        # Plotting the PyKEP.planets both at departure and arrival dates
        for i in range(self.__num_legs):
            idx = i * self.__dim_leg
            plot_planet(self.__seq[i], epoch(x[idx]), units=AU, legend=True, color=(0.7, 0.7, 1), s=30, ax=axis)
            plot_planet(self.__seq[i + 1], epoch(x[idx] + x[idx + 1]), units=AU, legend=False, color=(0.7, 0.7, 1), s=30, ax=axis)
        plt.show()
        return axis
Example #9
0
        def plot(self, x):
            import matplotlib as mpl
            from mpl_toolkits.mplot3d import Axes3D
            import matplotlib.pyplot as plt
            from PyKEP import epoch, AU
            from PyKEP.sims_flanagan import sc_state
            from PyKEP.orbit_plots import plot_planet, plot_sf_leg

            t_E = epoch(x[0])
            t_V = epoch(x[0] + x[1])
            t_M = epoch(x[0] + x[1] + x[9])
            rE, vE = self.__earth.eph(t_E)
            rV, vV = self.__venus.eph(t_V)
            rM, vM = self.__mercury.eph(t_M)

            # First Leg
            v = [a + b for a, b in zip(vE, x[3:6])]
            x0 = sc_state(rE, v, self.__sc.mass)
            v = [a + b for a, b in zip(vV, x[6:9])]
            xe = sc_state(rV, v, x[2])
            self.__leg1.set(
                t_E, x0, x[-3 * (self.__nseg1 + self.__nseg2):-self.__nseg2 * 3], t_V, xe)

            # Second leg
            v = [a + b for a, b in zip(vV, x[11:14])]
            x0 = sc_state(rV, v, x[2])
            v = [a + b for a, b in zip(vM, x[14:17])]
            xe = sc_state(rM, v, x[10])
            self.__leg2.set(t_E, x0, x[(-3 * self.__nseg2):], t_V, xe)

            fig = plt.figure()
            axis = fig.gca(projection='3d')

            # The Sun
            axis.scatter([0], [0], [0], color='y')
            # The legs
            plot_sf_leg(self.__leg1, units=AU, N=10, ax=axis)
            plot_sf_leg(self.__leg2, units=AU, N=10, ax=axis)
            # The planets
            plot_planet(
                self.__earth, t_E, units=AU, legend=True, color=(0.7, 0.7, 1), ax = axis)
            plot_planet(
                self.__venus, t_V, units=AU, legend=True, color=(0.7, 0.7, 1), ax = axis)
            plot_planet(
                self.__mercury, t_M, units=AU, legend=True, color=(0.7, 0.7, 1), ax = axis)
            plt.show()
Example #10
0
    def plot(self, x):
        # Making sure the leg corresponds to the requested chromosome
        self._compute_constraints_impl(x)
        start = epoch(x[0])
        end   = epoch(x[0] + x[1])

        # Plotting commands
        fig = plt.figure()
        axis = fig.gca(projection='3d')
        # The Sun
        axis.scatter([0], [0], [0], color='y')
        # The leg
        plot_sf_leg(self.leg, units=AU, N=10, ax=axis)
        # The planets
        plot_planet(
            self.earth, start, units=AU, legend=True, color=(0.8, 0.8, 1), ax = axis)
        plot_planet(
            self.mars, end, units=AU, legend=True, color=(0.8, 0.8, 1), ax = axis)
        plt.show()
Example #11
0
    def plot(self, x):
        import matplotlib as mpl
        from mpl_toolkits.mplot3d import Axes3D
        import matplotlib.pyplot as plt
        from PyKEP import epoch, AU
        from PyKEP.sims_flanagan import sc_state
        from PyKEP.orbit_plots import plot_planet, plot_sf_leg

        # Creating the axis ........
        fig = plt.figure()
        axis = fig.gca(projection='3d')

        # Plotting the Sun ........
        axis.scatter([0], [0], [0], color='y')

        # Computing the legs
        self._compute_constraints_impl(x)

        # Plotting the legs
        for leg in self.__legs:
            plot_sf_leg(leg, units=AU, N=10, ax=axis)

        # Plotting the PyKEP.planets both at departure and arrival dates
        for i in range(self.__num_legs):
            idx = i * self.__dim_leg
            plot_planet(self.__seq[i],
                        epoch(x[idx]),
                        units=AU,
                        legend=True,
                        color=(0.7, 0.7, 1),
                        s=30,
                        ax=axis)
            plot_planet(self.__seq[i + 1],
                        epoch(x[idx] + x[idx + 1]),
                        units=AU,
                        legend=False,
                        color=(0.7, 0.7, 1),
                        s=30,
                        ax=axis)
        plt.show()
        return axis
Example #12
0
def _pl2pl_fixed_time_plot(self, x):
    from PyGMO import problem, algorithm, population
    from PyKEP import sims_flanagan, AU
    from PyKEP.orbit_plots import plot_planet, plot_sf_leg
    from PyKEP import phasing
    import matplotlib.pyplot as plt
    import matplotlib as mpl
    from mpl_toolkits.mplot3d import Axes3D

    fig = plt.figure()
    ax = fig.gca(projection='3d')

    ax.scatter(0, 0, 0, color='y')
    ast1, ast2 = self.get_sequence()
    leg = self.get_leg()
    t_i = self.get_t0()
    t_f = self.get_t1()

    # Get initial sc state
    sc = leg.get_spacecraft()
    r, v = ast1.eph(t_i)
    xi = sims_flanagan.sc_state(r, v, sc.mass)

    # Get final sc state
    r, v = ast2.eph(t_f)
    xf = sims_flanagan.sc_state(r, v, x[0])

    # Update leg with final sc state and throttles
    leg.set(t_i, xi, x[1:], t_f, xf)

    # Plot asteroid orbits
    plot_planet(ast1, t0=t_i, color=(0.8, 0.6, 0.4), legend=True, units=AU, ax=ax)
    plot_planet(ast2, t0=t_f, color=(0.8, 0.6, 0.8), legend=True, units=AU, ax=ax)

    # Plot Sims-Flanagan leg
    plot_sf_leg(leg, units=AU, N=50, ax=ax)

    return ax
Example #13
0
    def plot(self, x, ax=None):
        """
        ax = prob.plot(x, ax=None)

        - x: encoded trajectory
        - ax: matplotlib axis where to plot. If None figure and axis will be created
        - [out] ax: matplotlib axis where to plot

        Plots the trajectory represented by a decision vector x on the 3d axis ax

        Example::

          ax = prob.plot(x)
        """
        import matplotlib as mpl
        from mpl_toolkits.mplot3d import Axes3D
        import matplotlib.pyplot as plt
        from PyKEP import epoch, AU
        from PyKEP.sims_flanagan import sc_state
        from PyKEP.orbit_plots import plot_planet, plot_sf_leg

        # Creating the axis if necessary
        if ax is None:
            mpl.rcParams['legend.fontsize'] = 10
            fig = plt.figure()
            axis = fig.gca(projection='3d')
        else:
            axis = ax

        # Plotting the Sun ........
        axis.scatter([0], [0], [0], color='y')

        # Plotting the legs .......
        # 1 - We decode the chromosome extracting the time of flights
        T = list([0] * (self.__n_legs))
        for i in range(self.__n_legs):
            T[i] = x[1 + i * 8]

        # 2 - We compute the epochs and ephemerides of the planetary encounters
        t_P = list([None] * (self.__n_legs + 1))
        r_P = list([None] * (self.__n_legs + 1))
        v_P = list([None] * (self.__n_legs + 1))

        for i, planet in enumerate(self.seq):
            t_P[i] = epoch(x[0] + sum(T[0:i]))
            r_P[i], v_P[i] = self.seq[i].eph(t_P[i])

        # 3 - We iterate through legs to compute mismatches and throttles constraints
        ceq = list()
        cineq = list()
        m0 = self.__sc.mass
        for i in range(self.__n_legs):
            # First Leg
            v = [a + b for a, b in zip(v_P[i], x[(3 + i * 8):(6 + i * 8)])]
            x0 = sc_state(r_P[i], v, m0)
            v = [
                a + b for a, b in zip(v_P[i + 1], x[(6 + i * 8):(11 + i * 8)])
            ]
            xe = sc_state(r_P[i + 1], v, x[2 + i * 8])
            throttles = x[(1 + 8 * self.__n_legs + 3 * sum(self.__n_seg[:i])):(
                1 + 8 * self.__n_legs + 3 * sum(self.__n_seg[:i]) +
                3 * self.__n_seg[i])]
            self.__leg.set(t_P[i], x0, throttles, t_P[i + 1], xe)
            # update mass!
            m0 = x[2 + 8 * i]
            plot_sf_leg(self.__leg, units=AU, N=10, ax=axis)

        # Plotting planets
        for i, planet in enumerate(self.seq):
            plot_planet(planet,
                        t_P[i],
                        units=AU,
                        legend=True,
                        color=(0.7, 0.7, 1),
                        ax=axis)

        plt.show()
        return axis
Example #14
0
    def plot(self, x, ax=None):
        """
        ax = prob.plot(x, ax=None)

        - x: encoded trajectory
        - ax: matplotlib axis where to plot. If None figure and axis will be created
        - [out] ax: matplotlib axis where to plot

        Plots the trajectory represented by a decision vector x on the 3d axis ax

        Example::

          ax = prob.plot(x)
        """
        import matplotlib as mpl
        from mpl_toolkits.mplot3d import Axes3D
        import matplotlib.pyplot as plt
        from PyKEP import epoch, AU
        from PyKEP.sims_flanagan import sc_state
        from PyKEP.orbit_plots import plot_planet, plot_sf_leg

        # Creating the axis if necessary
        if ax is None:
            mpl.rcParams['legend.fontsize'] = 10
            fig = plt.figure()
            axis = fig.gca(projection='3d')
        else:
            axis = ax

        # Plotting the Sun ........
        axis.scatter([0], [0], [0], color='y')

        # Plotting the legs .......
        # 1 - We decode the chromosome extracting the time of flights
        T = list([0] * (self.__n_legs))
        for i in range(self.__n_legs):
            T[i] = x[1 + i * 8]

        # 2 - We compute the epochs and ephemerides of the planetary encounters
        t_P = list([None] * (self.__n_legs + 1))
        r_P = list([None] * (self.__n_legs + 1))
        v_P = list([None] * (self.__n_legs + 1))

        for i, planet in enumerate(self.seq):
            t_P[i] = epoch(x[0] + sum(T[0:i]))
            r_P[i], v_P[i] = self.seq[i].eph(t_P[i])

        # 3 - We iterate through legs to compute mismatches and throttles constraints
        ceq = list()
        cineq = list()
        m0 = self.__sc.mass
        for i in range(self.__n_legs):
            # First Leg
            v = [a + b for a, b in zip(v_P[i], x[(3 + i * 8):(6 + i * 8)])]
            x0 = sc_state(r_P[i], v, m0)
            v = [a + b for a, b in zip(v_P[i + 1], x[(6 + i * 8):(11 + i * 8)])]
            xe = sc_state(r_P[i + 1], v, x[2 + i * 8])
            throttles = x[(1 + 8 * self.__n_legs + 3 * sum(self.__n_seg[:i])):(1 + 8 * self.__n_legs + 3 * sum(self.__n_seg[:i]) + 3 * self.__n_seg[i])]
            self.__leg.set(t_P[i], x0, throttles, t_P[i + 1], xe)
            # update mass!
            m0 = x[2 + 8 * i]
            plot_sf_leg(self.__leg, units=AU, N=10, ax=axis)

        # Plotting planets
        for i, planet in enumerate(self.seq):
            plot_planet(planet, t_P[i], units=AU, legend=True, color=(0.7, 0.7, 1), ax = axis)

        plt.show()
        return axis
Example #15
0
    def plot(self, x):
        """	
		Plots the trajectory represented by the decision vector x
		
		Example::
		
		  prob.plot(x)
		"""
        import matplotlib as mpl
        from mpl_toolkits.mplot3d import Axes3D
        import matplotlib.pyplot as plt
        from PyKEP import epoch, AU
        from PyKEP.sims_flanagan import sc_state
        from PyKEP.orbit_plots import plot_planet, plot_sf_leg

        fig = plt.figure()
        ax = fig.gca(projection='3d')

        #Plotting the Sun ........
        ax.scatter([0], [0], [0], color='y')

        #Plotting the legs .......

        # 1 - We decode the chromosome extracting the time of flights
        T = list([0] * (self.__n_legs))
        for i in range(self.__n_legs):
            T[i] = x[1 + i * 8]

        #2 - We compute the epochs and ephemerides of the planetary encounters
        t_P = list([None] * (self.__n_legs + 1))
        r_P = list([None] * (self.__n_legs + 1))
        v_P = list([None] * (self.__n_legs + 1))

        for i, planet in enumerate(self.seq):
            t_P[i] = epoch(x[0] + sum(T[0:i]))
            r_P[i], v_P[i] = self.seq[i].eph(t_P[i])

        #3 - We iterate through legs to compute mismatches and throttles constraints
        ceq = list()
        cineq = list()
        m0 = self.__sc.mass
        for i in range(self.__n_legs):
            #First Leg
            v = [a + b for a, b in zip(v_P[i], x[(3 + i * 8):(6 + i * 8)])]
            x0 = sc_state(r_P[i], v, m0)
            v = [
                a + b for a, b in zip(v_P[i + 1], x[(6 + i * 8):(11 + i * 8)])
            ]
            xe = sc_state(r_P[i + 1], v, x[2 + i * 8])
            throttles = x[(1 + 8 * self.__n_legs + 3 * sum(self.__n_seg[:i])):(
                1 + 8 * self.__n_legs + 3 * sum(self.__n_seg[:i]) +
                3 * self.__n_seg[i])]
            self.__leg.set(t_P[i], x0, throttles, t_P[i + 1], xe)
            #update mass!
            m0 = x[2 + 8 * i]
            plot_sf_leg(ax, self.__leg, units=AU, N=10)

        #Plotting planets
        for i, planet in enumerate(self.seq):
            plot_planet(ax,
                        planet,
                        t_P[i],
                        units=AU,
                        legend=True,
                        color=(0.7, 0.7, 1))

        plt.show()
Example #16
0
    def plot(self, x):
        import matplotlib as mpl
        from mpl_toolkits.mplot3d import Axes3D
        import matplotlib.pyplot as plt
        from PyKEP.orbit_plots import plot_planet, plot_sf_leg

        mpl.rcParams['legend.fontsize'] = 10
        fig = plt.figure()
        ax = fig.gca(projection='3d')
        ax.scatter(0, 0, 0, color='y')

        # 1 - We decode the chromosome extracting the time of flights
        T = list([0] * (self.__n_legs))
        for i in range(self.__n_legs):
            T[i] = x[2 + i * 8]

        #2 - We compute the epochs and ephemerides of the planetary encounters
        t_P = list([None] * (self.__n_legs + 1))
        r_P = list([None] * (self.__n_legs + 1))
        v_P = list([None] * (self.__n_legs + 1))

        for i, planet in enumerate(self.seq):
            t_P[i + 1] = epoch(self.tf - sum(T[i + 1:]))
            r_P[i + 1], v_P[i + 1] = self.seq[i].eph(t_P[i + 1])
            plot_planet(ax,
                        self.seq[i],
                        t_P[i + 1],
                        units=JR,
                        legend=True,
                        color='k')

        #And we insert a fake planet simulating the starting position
        t_P[0] = epoch(self.tf - sum(T))
        theta = x[0]
        phi = x[1]
        r = [cos(phi) * sin(theta),
             cos(phi) * cos(theta),
             sin(phi)]  #phi close to zero is in the moon orbit plane injection
        r = [JR * 1000 * d for d in r]
        r_P[0] = r
        v_P[0] = x[4:7]

        #3 - We iterate through legs to compute mismatches and throttles constraints
        ceq = list()
        cineq = list()
        m0 = self.__sc.mass
        for i in range(self.__n_legs):

            if i != 0:  #First Leg
                v = [a + b for a, b in zip(v_P[i], x[(4 + i * 8):(7 + i * 8)])]
            else:
                v = v_P[i]
            x0 = sc_state(r_P[i], v, m0)
            v = [
                a + b for a, b in zip(v_P[i + 1], x[(7 + i * 8):(10 + i * 8)])
            ]
            if (i == self.__n_legs - 1):  #Last leg
                v = [a + b for a, b in zip(v_P[i + 1], self.vf)]
            xe = sc_state(r_P[i + 1], v, x[3 + 8 * i])
            throttles = x[(8 * self.__n_legs - 1 + 3 * sum(self.__n_seg[:i])):(
                8 * self.__n_legs - 1 + 3 * sum(self.__n_seg[:i]) +
                3 * self.__n_seg[i])]
            self.__leg.set(t_P[i], x0, throttles, t_P[i + 1], xe)
            plot_sf_leg(ax, self.__leg, units=JR, N=50)
            #update mass!
            m0 = x[3 + 8 * i]
            ceq.extend(self.__leg.mismatch_constraints())
            cineq.extend(self.__leg.throttles_constraints())
            #raise Exception
        plt.show()
        return ax