def plot_initial_geometry(ni=0.0, mu=0.5): """ Visualizes the initial spaceraft conditions for the gtoc6 problem. Given a point on the initial spheres, \ it assumes a velocity (almost) pointing toward Jupiter. THIS IS ONLY A VISUALIZATION, the initial velocityshould not be taken as realistic. """ from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt from math import sin,cos,acos,pi from PyKEP.orbit_plots import plot_kepler, plot_planet from PyKEP import DAY2SEC, propagate_lagrangian, epoch from scipy.linalg import norm ep=epoch(0.0) days=300.0 r = [JR*1000*cos(ni)*cos(mu), JR*1000*cos(ni)*sin(mu),JR*1000*sin(ni)] VINF = 3400.0 v = [-d/norm(r)*3400 for d in r] v = [d+200 for d in v] fig = plt.figure() ax = fig.gca(projection='3d', aspect='equal') plot_planet(ax,io,color = 'r', units = JR, t0 = ep, legend=True) plot_planet(ax,europa,color = 'b', units = JR, t0 = ep, legend=True) plot_planet(ax,ganymede,color = 'k', units = JR, t0 = ep, legend=True) plot_planet(ax,callisto,color = 'y', units = JR, t0 = ep, legend=True) plot_kepler(ax,r,v,days*DAY2SEC,MU_JUPITER, N=200, units = JR, color = 'b') plt.plot([r[0]/JR],[r[1]/JR],[r[2]/JR],'o') plt.show()
def _mga_part_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.orbit_plots import plot_planet, plot_lambert, plot_kepler from PyKEP import epoch, propagate_lagrangian, lambert_problem, fb_prop, AU, MU_SUN, DAY2SEC from math import pi, acos, cos, sin from scipy.linalg import norm mpl.rcParams["legend.fontsize"] = 10 fig = plt.figure() ax = fig.gca(projection="3d", aspect="equal") ax.scatter(0, 0, 0, color="y") JR = 71492000.0 legs = len(x) / 4 seq = self.get_sequence() common_mu = seq[0].mu_central_body start_mjd2000 = self.t0.mjd2000 # 1 - we 'decode' the chromosome recording the various times of flight (days) in the list T T = x[3::4] # 2 - We compute the epochs and ephemerides of the planetary encounters t_P = list([None] * (legs + 1)) r_P = list([None] * (legs + 1)) v_P = list([None] * (legs + 1)) for i, planet in enumerate(seq): t_P[i] = epoch(start_mjd2000 + sum(T[:i])) r_P[i], v_P[i] = planet.eph(t_P[i]) plot_planet(ax, planet, t0=t_P[i], color=(0.8, 0.6, 0.8), legend=True, units=JR) v_end_l = [a + b for a, b in zip(v_P[0], self.vinf_in)] # 4 - And we iterate on the legs for i in xrange(0, legs): # Fly-by v_out = fb_prop(v_end_l, v_P[i], x[1 + 4 * i] * seq[i - 1].radius, x[4 * i], seq[i].mu_self) # s/c propagation before the DSM r, v = propagate_lagrangian(r_P[i], v_out, x[4 * i + 2] * T[i] * DAY2SEC, common_mu) plot_kepler( ax, r_P[i], v_out, x[4 * i + 2] * T[i] * DAY2SEC, common_mu, N=500, color="b", legend=False, units=JR ) # Lambert arc to reach Earth during (1-nu2)*T2 (second segment) dt = (1 - x[4 * i + 2]) * T[i] * DAY2SEC l = lambert_problem(r, r_P[i + 1], dt, common_mu, False, False) plot_lambert(ax, l, sol=0, color="r", legend=False, units=JR, N=500) v_end_l = l.get_v2()[0] v_beg_l = l.get_v1()[0] plt.show() return ax
def _mga_1dsm_tof_plot(self, x): """ Plots the trajectory represented by the decision vector x """ import matplotlib as mpl from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt from PyKEP.orbit_plots import plot_planet, plot_lambert, plot_kepler from PyKEP import epoch, propagate_lagrangian, lambert_problem, fb_prop, AU, MU_SUN, DAY2SEC from math import pi, acos, cos, sin from scipy.linalg import norm mpl.rcParams['legend.fontsize'] = 10 fig = plt.figure() ax = fig.gca(projection='3d') ax.scatter(0, 0, 0, color='y') seq = self.get_sequence() # 2 - We plot the first leg r_P0, v_P0 = seq[0].eph(epoch(x[0])) plot_planet(ax, seq[0], t0=epoch(x[0]), color=(0.8, 0.6, 0.8), legend=True, units=AU) r_P1, v_P1 = seq[1].eph(epoch(x[0] + x[5])) theta = 2 * pi * x[1] phi = acos(2 * x[2] - 1) - pi / 2 Vinfx = x[3] * cos(phi) * cos(theta) Vinfy = x[3] * cos(phi) * sin(theta) Vinfz = x[3] * sin(phi) v0 = [a + b for a, b in zip(v_P0, [Vinfx, Vinfy, Vinfz])] r, v = propagate_lagrangian(r_P0, v0, x[4] * x[5] * DAY2SEC, seq[0].mu_central_body) plot_kepler(ax, r_P0, v0, x[4] * x[5] * DAY2SEC, seq[0].mu_central_body, N=100, color='b', legend=False, units=AU) # Lambert arc to reach seq[1] dt = (1 - x[4]) * x[5] * DAY2SEC l = lambert_problem(r, r_P1, dt, seq[0].mu_central_body) plot_lambert(ax, l, sol=0, color='r', legend=False, units=AU) v_end_l = l.get_v2()[0] vinf_in = [a - b for a, b in zip(v_end_l, v_P1)] _part_plot(x[6:], AU, ax, seq[1:], x[0] + x[5], vinf_in) return ax
def _mga_1dsm_tof_plot(self, x): """ Plots the trajectory represented by the decision vector x """ import matplotlib as mpl from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt from PyKEP.orbit_plots import plot_planet, plot_lambert, plot_kepler from PyKEP import epoch, propagate_lagrangian, lambert_problem, fb_prop, AU, MU_SUN, DAY2SEC from math import pi, acos, cos, sin from scipy.linalg import norm mpl.rcParams['legend.fontsize'] = 10 fig = plt.figure() ax = fig.gca(projection='3d') ax.scatter(0, 0, 0, color='y') seq = self.get_sequence() # 2 - We plot the first leg r_P0, v_P0 = seq[0].eph(epoch(x[0])) plot_planet(ax, seq[0], t0=epoch(x[0]), color=( 0.8, 0.6, 0.8), legend=True, units = AU) r_P1, v_P1 = seq[1].eph(epoch(x[0] + x[5])) theta = 2 * pi * x[1] phi = acos(2 * x[2] - 1) - pi / 2 Vinfx = x[3] * cos(phi) * cos(theta) Vinfy = x[3] * cos(phi) * sin(theta) Vinfz = x[3] * sin(phi) v0 = [a + b for a, b in zip(v_P0, [Vinfx, Vinfy, Vinfz])] r, v = propagate_lagrangian( r_P0, v0, x[4] * x[5] * DAY2SEC, seq[0].mu_central_body) plot_kepler( ax, r_P0, v0, x[4] * x[5] * DAY2SEC, seq[0].mu_central_body, N=100, color='b', legend=False, units=AU) # Lambert arc to reach seq[1] dt = (1 - x[4]) * x[5] * DAY2SEC l = lambert_problem(r, r_P1, dt, seq[0].mu_central_body) plot_lambert(ax, l, sol=0, color='r', legend=False, units=AU) v_end_l = l.get_v2()[0] vinf_in = [a - b for a, b in zip(v_end_l, v_P1)] _part_plot(x[6:], AU, ax, seq[1:], x[0] + x[5], vinf_in) return ax
def _part_plot(x, units, ax, seq, start_mjd2000, vinf_in): """ Plots the trajectory represented by a decision vector x = [beta,rp,eta,T] * N associated to a sequence seq, a start_mjd2000 and an incoming vinf_in """ from PyKEP.orbit_plots import plot_planet, plot_lambert, plot_kepler from PyKEP import epoch, propagate_lagrangian, lambert_problem, fb_prop, AU, MU_SUN, DAY2SEC from math import pi, acos, cos, sin from scipy.linalg import norm legs = len(x) / 4 common_mu = seq[0].mu_central_body # 1 - we 'decode' the chromosome recording the various times of flight # (days) in the list T T = x[3::4] # 2 - We compute the epochs and ephemerides of the planetary encounters t_P = list([None] * (legs + 1)) r_P = list([None] * (legs + 1)) v_P = list([None] * (legs + 1)) for i, planet in enumerate(seq): t_P[i] = epoch(start_mjd2000 + sum(T[:i])) r_P[i], v_P[i] = planet.eph(t_P[i]) plot_planet(ax, planet, t0=t_P[i], color=(0.8, 0.6, 0.8), legend=True, units=units) v_end_l = [a + b for a, b in zip(v_P[0], vinf_in)] # 4 - And we iterate on the legs for i in range(0, legs): # Fly-by v_out = fb_prop(v_end_l, v_P[i], x[1 + 4 * i] * seq[i].radius, x[4 * i], seq[i].mu_self) # s/c propagation before the DSM r, v = propagate_lagrangian(r_P[i], v_out, x[4 * i + 2] * T[i] * DAY2SEC, common_mu) plot_kepler(ax, r_P[i], v_out, x[4 * i + 2] * T[i] * DAY2SEC, common_mu, N=500, color='b', legend=False, units=units) # Lambert arc to reach Earth during (1-nu2)*T2 (second segment) dt = (1 - x[4 * i + 2]) * T[i] * DAY2SEC l = lambert_problem(r, r_P[i + 1], dt, common_mu, False, False) plot_lambert(ax, l, sol=0, color='r', legend=False, units=units, N=500) v_end_l = l.get_v2()[0] v_beg_l = l.get_v1()[0]
def _part_plot(x, units, axis, seq, start_mjd2000, vinf_in): """ Plots the trajectory represented by a decision vector x = [beta,rp,eta,T] * N associated to a sequence seq, a start_mjd2000 and an incoming vinf_in """ from PyKEP.orbit_plots import plot_planet, plot_lambert, plot_kepler from PyKEP import epoch, propagate_lagrangian, lambert_problem, fb_prop, AU, MU_SUN, DAY2SEC from math import pi, acos, cos, sin from scipy.linalg import norm legs = len(x) // 4 common_mu = seq[0].mu_central_body # 1 - we 'decode' the chromosome recording the various times of flight # (days) in the list T T = x[3::4] # 2 - We compute the epochs and ephemerides of the planetary encounters t_P = list([None] * (legs + 1)) r_P = list([None] * (legs + 1)) v_P = list([None] * (legs + 1)) for i, planet in enumerate(seq): t_P[i] = epoch(start_mjd2000 + sum(T[:i])) r_P[i], v_P[i] = planet.eph(t_P[i]) plot_planet(planet, t0=t_P[i], color=( 0.8, 0.6, 0.8), legend=True, units = units, ax=axis) v_end_l = [a + b for a, b in zip(v_P[0], vinf_in)] # 4 - And we iterate on the legs for i in range(0, legs): # Fly-by v_out = fb_prop(v_end_l, v_P[i], x[1 + 4 * i] * seq[i].radius, x[4 * i], seq[i].mu_self) # s/c propagation before the DSM r, v = propagate_lagrangian( r_P[i], v_out, x[4 * i + 2] * T[i] * DAY2SEC, common_mu) plot_kepler(r_P[i], v_out, x[4 * i + 2] * T[i] * DAY2SEC, common_mu, N=500, color='b', legend=False, units=units, ax=axis) # Lambert arc to reach Earth during (1-nu2)*T2 (second segment) dt = (1 - x[4 * i + 2]) * T[i] * DAY2SEC l = lambert_problem(r, r_P[i + 1], dt, common_mu, False, False) plot_lambert( l, sol=0, color='r', legend=False, units=units, N=500, ax=axis) v_end_l = l.get_v2()[0] v_beg_l = l.get_v1()[0]
def plot_initial_geometry(ni=0.0, mu=0.5): """ Visualizes the initial spaceraft conditions for the gtoc6 problem. Given a point on the initial spheres, \ it assumes a velocity (almost) pointing toward Jupiter. THIS IS ONLY A VISUALIZATION, the initial velocityshould not be taken as realistic. """ from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt from math import sin, cos, acos, pi from PyKEP.orbit_plots import plot_kepler, plot_planet from PyKEP import DAY2SEC, propagate_lagrangian, epoch from scipy.linalg import norm ep = epoch(0.0) days = 300.0 r = [ JR * 1000 * cos(ni) * cos(mu), JR * 1000 * cos(ni) * sin(mu), JR * 1000 * sin(ni) ] VINF = 3400.0 v = [-d / norm(r) * 3400 for d in r] v = [d + 200 for d in v] fig = plt.figure() ax = fig.gca(projection='3d', aspect='equal') plot_planet(ax, io, color='r', units=JR, t0=ep, legend=True) plot_planet(ax, europa, color='b', units=JR, t0=ep, legend=True) plot_planet(ax, ganymede, color='k', units=JR, t0=ep, legend=True) plot_planet(ax, callisto, color='y', units=JR, t0=ep, legend=True) plot_kepler(ax, r, v, days * DAY2SEC, MU_JUPITER, N=200, units=JR, color='b') plt.plot([r[0] / JR], [r[1] / JR], [r[2] / JR], 'o') plt.show()
def _mga_incipit_plot_old(self, x, plot_leg_0=False): """ 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.orbit_plots import plot_planet, plot_lambert, plot_kepler from PyKEP import epoch, propagate_lagrangian, lambert_problem, fb_prop, AU, MU_SUN, DAY2SEC from math import pi, acos, cos, sin from scipy.linalg import norm mpl.rcParams['legend.fontsize'] = 10 fig = plt.figure() ax = fig.gca(projection='3d', aspect='equal') ax.scatter(0, 0, 0, color='y') JR = 71492000.0 legs = len(x) / 4 seq = self.get_sequence() common_mu = seq[0].mu_central_body # 1 - we 'decode' the chromosome recording the various times of flight # (days) in the list T T = x[3::4] # 2 - We compute the epochs and ephemerides of the planetary encounters t_P = list([None] * legs) r_P = list([None] * legs) v_P = list([None] * legs) DV = list([None] * legs) for i, planet in enumerate(seq): t_P[i] = epoch(x[0] + sum(T[:i + 1])) r_P[i], v_P[i] = planet.eph(t_P[i]) plot_planet(ax, planet, t0=t_P[i], color=( 0.8, 0.6, 0.8), legend=True, units = JR) # 3 - We start with the first leg: a lambert arc theta = 2 * pi * x[1] phi = acos(2 * x[2] - 1) - pi / 2 # phi close to zero is in the moon orbit plane injection r = [cos(phi) * sin(theta), cos(phi) * cos(theta), sin(phi)] r = [JR * 1000 * d for d in r] l = lambert_problem(r, r_P[0], T[0] * DAY2SEC, common_mu, False, False) if (plot_leg_0): plot_lambert(ax, l, sol=0, color='k', legend=False, units=JR, N=500) # Lambert arc to reach seq[1] v_end_l = l.get_v2()[0] v_beg_l = l.get_v1()[0] # 4 - And we proceed with each successive leg for i in range(1, legs): # Fly-by v_out = fb_prop(v_end_l, v_P[i - 1], x[1 + 4 * i] * seq[i - 1].radius, x[4 * i], seq[i - 1].mu_self) # s/c propagation before the DSM r, v = propagate_lagrangian( r_P[i - 1], v_out, x[4 * i + 2] * T[i] * DAY2SEC, common_mu) plot_kepler(ax, r_P[i - 1], v_out, x[4 * i + 2] * T[i] * DAY2SEC, common_mu, N=500, color='b', legend=False, units=JR) # Lambert arc to reach Earth during (1-nu2)*T2 (second segment) dt = (1 - x[4 * i + 2]) * T[i] * DAY2SEC l = lambert_problem(r, r_P[i], dt, common_mu, False, False) plot_lambert(ax, l, sol=0, color='r', legend=False, units=JR, N=500) v_end_l = l.get_v2()[0] v_beg_l = l.get_v1()[0] plt.show() return ax
def _mga_1dsm_tof_plot_old(self, x): """ Plots the trajectory represented by the decision vector x """ import matplotlib as mpl from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt from PyKEP.orbit_plots import plot_planet, plot_lambert, plot_kepler from PyKEP import epoch, propagate_lagrangian, lambert_problem, fb_prop, AU, MU_SUN, DAY2SEC from math import pi, acos, cos, sin from scipy.linalg import norm mpl.rcParams['legend.fontsize'] = 10 fig = plt.figure() ax = fig.gca(projection='3d') ax.scatter(0, 0, 0, color='y') seq = self.get_sequence() n = (len(seq) - 1) # 1 - we 'decode' the chromosome recording the various times of flight # (days) in the list T T = x[5::4] # 2 - We compute the epochs and ephemerides of the planetary encounters t_P = list([None] * (n + 1)) r_P = list([None] * (n + 1)) v_P = list([None] * (n + 1)) DV = list([None] * (n + 1)) for i, planet in enumerate(seq): t_P[i] = epoch(x[0] + sum(T[0:i])) r_P[i], v_P[i] = planet.eph(t_P[i]) plot_planet(ax, planet, t0=t_P[i], color=( 0.8, 0.6, 0.8), legend=True, units = AU) # 3 - We start with the first leg theta = 2 * pi * x[1] phi = acos(2 * x[2] - 1) - pi / 2 Vinfx = x[3] * cos(phi) * cos(theta) Vinfy = x[3] * cos(phi) * sin(theta) Vinfz = x[3] * sin(phi) v0 = [a + b for a, b in zip(v_P[0], [Vinfx, Vinfy, Vinfz])] r, v = propagate_lagrangian( r_P[0], v0, x[4] * T[0] * DAY2SEC, seq[0].mu_central_body) plot_kepler( ax, r_P[0], v0, x[4] * T[0] * DAY2SEC, seq[0].mu_central_body, N=100, color='b', legend=False, units=AU) # Lambert arc to reach seq[1] dt = (1 - x[4]) * T[0] * DAY2SEC l = lambert_problem(r, r_P[1], dt, seq[0].mu_central_body) plot_lambert(ax, l, sol=0, color='r', legend=False, units=AU) v_end_l = l.get_v2()[0] v_beg_l = l.get_v1()[0] # First DSM occuring at time nu1*T1 DV[0] = norm([a - b for a, b in zip(v_beg_l, v)]) # 4 - And we proceed with each successive leg for i in range(1, n): # Fly-by v_out = fb_prop(v_end_l, v_P[i], x[7 + (i - 1) * 4] * seq[i].radius, x[6 + (i - 1) * 4], seq[i].mu_self) # s/c propagation before the DSM r, v = propagate_lagrangian( r_P[i], v_out, x[8 + (i - 1) * 4] * T[i] * DAY2SEC, seq[0]. mu_central_body) plot_kepler(ax, r_P[i], v_out, x[8 + (i - 1) * 4] * T[i] * DAY2SEC, seq[0].mu_central_body, N=100, color='b', legend=False, units=AU) # Lambert arc to reach Earth during (1-nu2)*T2 (second segment) dt = (1 - x[8 + (i - 1) * 4]) * T[i] * DAY2SEC l = lambert_problem(r, r_P[i + 1], dt, seq[0].mu_central_body) plot_lambert(ax, l, sol=0, color='r', legend=False, units=AU) v_end_l = l.get_v2()[0] v_beg_l = l.get_v1()[0] # DSM occurring at time nu2*T2 DV[i] = norm([a - b for a, b in zip(v_beg_l, v)]) return ax
def _mga_part_plot_old(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.orbit_plots import plot_planet, plot_lambert, plot_kepler from PyKEP import epoch, propagate_lagrangian, lambert_problem, fb_prop, AU, MU_SUN, DAY2SEC from math import pi, acos, cos, sin from scipy.linalg import norm mpl.rcParams['legend.fontsize'] = 10 fig = plt.figure() ax = fig.gca(projection='3d', aspect='equal') ax.scatter(0, 0, 0, color='y') JR = 71492000.0 legs = len(x) / 4 seq = self.get_sequence() common_mu = seq[0].mu_central_body start_mjd2000 = self.t0.mjd2000 # 1 - we 'decode' the chromosome recording the various times of flight # (days) in the list T T = x[3::4] # 2 - We compute the epochs and ephemerides of the planetary encounters t_P = list([None] * (legs + 1)) r_P = list([None] * (legs + 1)) v_P = list([None] * (legs + 1)) for i, planet in enumerate(seq): t_P[i] = epoch(start_mjd2000 + sum(T[:i])) r_P[i], v_P[i] = planet.eph(t_P[i]) plot_planet(ax, planet, t0=t_P[i], color=(0.8, 0.6, 0.8), legend=True, units=JR) v_end_l = [a + b for a, b in zip(v_P[0], self.vinf_in)] # 4 - And we iterate on the legs for i in range(0, legs): # Fly-by v_out = fb_prop(v_end_l, v_P[i], x[1 + 4 * i] * seq[i - 1].radius, x[4 * i], seq[i].mu_self) # s/c propagation before the DSM r, v = propagate_lagrangian(r_P[i], v_out, x[4 * i + 2] * T[i] * DAY2SEC, common_mu) plot_kepler(ax, r_P[i], v_out, x[4 * i + 2] * T[i] * DAY2SEC, common_mu, N=500, color='b', legend=False, units=JR) # Lambert arc to reach Earth during (1-nu2)*T2 (second segment) dt = (1 - x[4 * i + 2]) * T[i] * DAY2SEC l = lambert_problem(r, r_P[i + 1], dt, common_mu, False, False) plot_lambert(ax, l, sol=0, color='r', legend=False, units=JR, N=500) v_end_l = l.get_v2()[0] v_beg_l = l.get_v1()[0] plt.show() return ax
def _mga_incipit_plot_old(self, x, plot_leg_0=False): """ 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.orbit_plots import plot_planet, plot_lambert, plot_kepler from PyKEP import epoch, propagate_lagrangian, lambert_problem, fb_prop, AU, MU_SUN, DAY2SEC from math import pi, acos, cos, sin from scipy.linalg import norm mpl.rcParams['legend.fontsize'] = 10 fig = plt.figure() ax = fig.gca(projection='3d', aspect='equal') ax.scatter(0, 0, 0, color='y') JR = 71492000.0 legs = len(x) / 4 seq = self.get_sequence() common_mu = seq[0].mu_central_body # 1 - we 'decode' the chromosome recording the various times of flight # (days) in the list T T = x[3::4] # 2 - We compute the epochs and ephemerides of the planetary encounters t_P = list([None] * legs) r_P = list([None] * legs) v_P = list([None] * legs) DV = list([None] * legs) for i, planet in enumerate(seq): t_P[i] = epoch(x[0] + sum(T[:i + 1])) r_P[i], v_P[i] = planet.eph(t_P[i]) plot_planet(ax, planet, t0=t_P[i], color=(0.8, 0.6, 0.8), legend=True, units=JR) # 3 - We start with the first leg: a lambert arc theta = 2 * pi * x[1] phi = acos(2 * x[2] - 1) - pi / 2 # phi close to zero is in the moon orbit plane injection r = [cos(phi) * sin(theta), cos(phi) * cos(theta), sin(phi)] r = [JR * 1000 * d for d in r] l = lambert_problem(r, r_P[0], T[0] * DAY2SEC, common_mu, False, False) if (plot_leg_0): plot_lambert(ax, l, sol=0, color='k', legend=False, units=JR, N=500) # Lambert arc to reach seq[1] v_end_l = l.get_v2()[0] v_beg_l = l.get_v1()[0] # 4 - And we proceed with each successive leg for i in range(1, legs): # Fly-by v_out = fb_prop(v_end_l, v_P[i - 1], x[1 + 4 * i] * seq[i - 1].radius, x[4 * i], seq[i - 1].mu_self) # s/c propagation before the DSM r, v = propagate_lagrangian(r_P[i - 1], v_out, x[4 * i + 2] * T[i] * DAY2SEC, common_mu) plot_kepler(ax, r_P[i - 1], v_out, x[4 * i + 2] * T[i] * DAY2SEC, common_mu, N=500, color='b', legend=False, units=JR) # Lambert arc to reach Earth during (1-nu2)*T2 (second segment) dt = (1 - x[4 * i + 2]) * T[i] * DAY2SEC l = lambert_problem(r, r_P[i], dt, common_mu, False, False) plot_lambert(ax, l, sol=0, color='r', legend=False, units=JR, N=500) v_end_l = l.get_v2()[0] v_beg_l = l.get_v1()[0] plt.show() return ax
def _mga_1dsm_tof_plot_old(self, x): """ Plots the trajectory represented by the decision vector x """ import matplotlib as mpl from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt from PyKEP.orbit_plots import plot_planet, plot_lambert, plot_kepler from PyKEP import epoch, propagate_lagrangian, lambert_problem, fb_prop, AU, MU_SUN, DAY2SEC from math import pi, acos, cos, sin from scipy.linalg import norm mpl.rcParams['legend.fontsize'] = 10 fig = plt.figure() ax = fig.gca(projection='3d') ax.scatter(0, 0, 0, color='y') seq = self.get_sequence() n = (len(seq) - 1) # 1 - we 'decode' the chromosome recording the various times of flight # (days) in the list T T = x[5::4] # 2 - We compute the epochs and ephemerides of the planetary encounters t_P = list([None] * (n + 1)) r_P = list([None] * (n + 1)) v_P = list([None] * (n + 1)) DV = list([None] * (n + 1)) for i, planet in enumerate(seq): t_P[i] = epoch(x[0] + sum(T[0:i])) r_P[i], v_P[i] = planet.eph(t_P[i]) plot_planet(ax, planet, t0=t_P[i], color=(0.8, 0.6, 0.8), legend=True, units=AU) # 3 - We start with the first leg theta = 2 * pi * x[1] phi = acos(2 * x[2] - 1) - pi / 2 Vinfx = x[3] * cos(phi) * cos(theta) Vinfy = x[3] * cos(phi) * sin(theta) Vinfz = x[3] * sin(phi) v0 = [a + b for a, b in zip(v_P[0], [Vinfx, Vinfy, Vinfz])] r, v = propagate_lagrangian(r_P[0], v0, x[4] * T[0] * DAY2SEC, seq[0].mu_central_body) plot_kepler(ax, r_P[0], v0, x[4] * T[0] * DAY2SEC, seq[0].mu_central_body, N=100, color='b', legend=False, units=AU) # Lambert arc to reach seq[1] dt = (1 - x[4]) * T[0] * DAY2SEC l = lambert_problem(r, r_P[1], dt, seq[0].mu_central_body) plot_lambert(ax, l, sol=0, color='r', legend=False, units=AU) v_end_l = l.get_v2()[0] v_beg_l = l.get_v1()[0] # First DSM occuring at time nu1*T1 DV[0] = norm([a - b for a, b in zip(v_beg_l, v)]) # 4 - And we proceed with each successive leg for i in range(1, n): # Fly-by v_out = fb_prop(v_end_l, v_P[i], x[7 + (i - 1) * 4] * seq[i].radius, x[6 + (i - 1) * 4], seq[i].mu_self) # s/c propagation before the DSM r, v = propagate_lagrangian(r_P[i], v_out, x[8 + (i - 1) * 4] * T[i] * DAY2SEC, seq[0].mu_central_body) plot_kepler(ax, r_P[i], v_out, x[8 + (i - 1) * 4] * T[i] * DAY2SEC, seq[0].mu_central_body, N=100, color='b', legend=False, units=AU) # Lambert arc to reach Earth during (1-nu2)*T2 (second segment) dt = (1 - x[8 + (i - 1) * 4]) * T[i] * DAY2SEC l = lambert_problem(r, r_P[i + 1], dt, seq[0].mu_central_body) plot_lambert(ax, l, sol=0, color='r', legend=False, units=AU) v_end_l = l.get_v2()[0] v_beg_l = l.get_v1()[0] # DSM occurring at time nu2*T2 DV[i] = norm([a - b for a, b in zip(v_beg_l, v)]) return ax
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.orbit_plots import plot_planet, plot_lambert, plot_kepler if ax is None: mpl.rcParams['legend.fontsize'] = 10 fig = plt.figure() axis = fig.gca(projection='3d') else: axis = ax axis.scatter(0, 0, 0, color='y') # 1 - we 'decode' the chromosome recording the various times of flight # (days) in the list T and the cartesian components of vinf T, Vinfx, Vinfy, Vinfz = self._decode_times_and_vinf(x) # 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)) DV = 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] = planet.eph(t_P[i]) plot_planet(planet, t0=t_P[i], color=(0.8, 0.6, 0.8), legend=True, units=AU, ax=axis) # 3 - We start with the first leg v0 = [a + b for a, b in zip(v_P[0], [Vinfx, Vinfy, Vinfz])] r, v = propagate_lagrangian(r_P[0], v0, x[5] * T[0] * DAY2SEC, self.common_mu) plot_kepler(r_P[0], v0, x[5] * T[0] * DAY2SEC, self.common_mu, N=100, color='b', legend=False, units=AU, ax=axis) # Lambert arc to reach seq[1] dt = (1 - x[5]) * T[0] * DAY2SEC l = lambert_problem(r, r_P[1], dt, self.common_mu, False, False) plot_lambert(l, sol=0, color='r', legend=False, units=AU, ax=axis) v_end_l = l.get_v2()[0] v_beg_l = l.get_v1()[0] # First DSM occuring at time nu1*T1 DV[0] = norm([a - b for a, b in zip(v_beg_l, v)]) # 4 - And we proceed with each successive leg for i in range(1, self.__n_legs): # Fly-by v_out = fb_prop(v_end_l, v_P[i], x[8 + (i - 1) * 4] * self.seq[i].radius, x[7 + (i - 1) * 4], self.seq[i].mu_self) # s/c propagation before the DSM r, v = propagate_lagrangian(r_P[i], v_out, x[9 + (i - 1) * 4] * T[i] * DAY2SEC, self.common_mu) plot_kepler(r_P[i], v_out, x[9 + (i - 1) * 4] * T[i] * DAY2SEC, self.common_mu, N=100, color='b', legend=False, units=AU, ax=axis) # Lambert arc to reach Earth during (1-nu2)*T2 (second segment) dt = (1 - x[9 + (i - 1) * 4]) * T[i] * DAY2SEC l = lambert_problem(r, r_P[i + 1], dt, self.common_mu, False, False) plot_lambert(l, sol=0, color='r', legend=False, units=AU, N=1000, ax=axis) v_end_l = l.get_v2()[0] v_beg_l = l.get_v1()[0] # DSM occuring at time nu2*T2 DV[i] = norm([a - b for a, b in zip(v_beg_l, v)]) plt.show() return axis
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.orbit_plots import plot_planet, plot_lambert, plot_kepler if ax is None: mpl.rcParams['legend.fontsize'] = 10 fig = plt.figure() axis = fig.gca(projection='3d') else: axis = ax axis.scatter(0, 0, 0, color='y') # 1 - we 'decode' the chromosome recording the various deep space # manouvres timing (days) in the list T T = list([0] * (self.N_max - 1)) for i in range(len(T)): T[i] = log(x[2 + 4 * i]) total = sum(T) T = [x[1] * time / total for time in T] # 2 - We compute the starting and ending position r_start, v_start = self.start.eph(epoch(x[0])) if self.phase_free: r_target, v_target = self.target.eph(epoch(x[-1])) else: r_target, v_target = self.target.eph(epoch(x[0] + x[1])) plot_planet(self.start, t0=epoch(x[0]), color=(0.8, 0.6, 0.8), legend=True, units = AU, ax=axis) plot_planet(self.target, t0=epoch(x[0] + x[1]), color=(0.8, 0.6, 0.8), legend=True, units = AU, ax=axis) # 3 - We loop across inner impulses rsc = r_start vsc = v_start for i, time in enumerate(T[:-1]): theta = 2 * pi * x[3 + 4 * i] phi = acos(2 * x[4 + 4 * i] - 1) - pi / 2 Vinfx = x[5 + 4 * i] * cos(phi) * cos(theta) Vinfy = x[5 + 4 * i] * cos(phi) * sin(theta) Vinfz = x[5 + 4 * i] * sin(phi) # We apply the (i+1)-th impulse vsc = [a + b for a, b in zip(vsc, [Vinfx, Vinfy, Vinfz])] plot_kepler(rsc, vsc, T[ i] * DAY2SEC, self.__common_mu, N=200, color='b', legend=False, units=AU, ax=axis) rsc, vsc = propagate_lagrangian( rsc, vsc, T[i] * DAY2SEC, self.__common_mu) cw = (ic2par(rsc, vsc, self.start.mu_central_body)[2] > pi / 2) # We now compute the remaining two final impulses # Lambert arc to reach seq[1] dt = T[-1] * DAY2SEC l = lambert_problem(rsc, r_target, dt, self.__common_mu, cw, False) plot_lambert( l, sol=0, color='r', legend=False, units=AU, ax=axis, N=200) plt.show() return axis
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.orbit_plots import plot_planet, plot_lambert, plot_kepler 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 recording the various times of flight (days) in the list T for convenience T = list([0]*(self.__n_legs)) for i in xrange(self.__n_legs): T[i] = (x[4+4*i]/sum(x[4::4]))*x[3] #2 - We compute the epochs and ephemerides of the planetary encounters t_P = list([None] * (self.__n_legs)) r_P = list([None] * (self.__n_legs)) v_P = list([None] * (self.__n_legs)) DV = list([None] * (self.__n_legs)) for i,planet in enumerate(self.seq): t_P[i] = epoch(x[0]+sum(T[:i+1])) r_P[i],v_P[i] = self.seq[i].eph(t_P[i]) plot_planet(ax, planet, t0=t_P[i], color=(0.8,0.6,0.8), legend=True, units = JR) #3 - We start with the first leg: a lambert arc theta = 2*pi*x[1] phi = acos(2*x[2]-1)-pi/2 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] l = lambert_problem(r,r_P[0],T[0]*DAY2SEC,self.common_mu, False, False) plot_lambert(ax,l, sol = 0, color='k', legend=False, units = JR, N=500) #Lambert arc to reach seq[1] v_end_l = l.get_v2()[0] v_beg_l = l.get_v1()[0] #First DSM occuring at the very beginning (will be cancelled by the optimizer) DV[0] = abs(norm(v_beg_l) - 3400) #4 - And we proceed with each successive leg for i in xrange(1,self.__n_legs): #Fly-by v_out = fb_prop(v_end_l,v_P[i-1],x[6+(i-1)*4]*self.seq[i-1].radius,x[5+(i-1)*4],self.seq[i-1].mu_self) #s/c propagation before the DSM r,v = propagate_lagrangian(r_P[i-1],v_out,x[4*i+3]*T[i]*DAY2SEC,self.common_mu) plot_kepler(ax,r_P[i-1],v_out,x[7+(i-1)*4]*T[i]*DAY2SEC,self.common_mu,N = 500, color='b', legend=False, units = JR) #Lambert arc to reach Earth during (1-nu2)*T2 (second segment) dt = (1-x[7+(i-1)*4])*T[i]*DAY2SEC l = lambert_problem(r,r_P[i],dt,self.common_mu, False, False) plot_lambert(ax,l, sol = 0, color='r', legend=False, units = JR, N=500) v_end_l = l.get_v2()[0] v_beg_l = l.get_v1()[0] #DSM occuring at time nu2*T2 DV[i] = norm([a-b for a,b in zip(v_beg_l,v)]) plt.show()
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.orbit_plots import plot_planet, plot_lambert, plot_kepler 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 recording the various times of flight (days) in the list T T = x[3::4] #2 - We compute the epochs and ephemerides of the planetary encounters t_P = list([None] * (self.__n_legs)) r_P = list([None] * (self.__n_legs)) v_P = list([None] * (self.__n_legs)) DV = list([None] * (self.__n_legs)) for i, planet in enumerate(self.seq): t_P[i] = epoch(x[0] + sum(T[:i + 1])) r_P[i], v_P[i] = self.seq[i].eph(t_P[i]) plot_planet(ax, planet, t0=t_P[i], color=(0.8, 0.6, 0.8), legend=True, units=JR) #3 - We start with the first leg: a lambert arc theta = 2 * pi * x[1] phi = acos(2 * x[2] - 1) - pi / 2 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] l = lambert_problem(r, r_P[0], T[0] * DAY2SEC, self.common_mu, False, False) plot_lambert(ax, l, sol=0, color='k', legend=False, units=JR, N=500) #Lambert arc to reach seq[1] v_end_l = l.get_v2()[0] v_beg_l = l.get_v1()[0] #First DSM occuring at the very beginning (will be cancelled by the optimizer) DV[0] = abs(norm(v_beg_l) - 3400) #4 - And we proceed with each successive leg for i in xrange(1, self.__n_legs): #Fly-by v_out = fb_prop(v_end_l, v_P[i - 1], x[1 + 4 * i] * self.seq[i - 1].radius, x[4 * i], self.seq[i - 1].mu_self) #s/c propagation before the DSM r, v = propagate_lagrangian(r_P[i - 1], v_out, x[4 * i + 2] * T[i] * DAY2SEC, self.common_mu) plot_kepler(ax, r_P[i - 1], v_out, x[4 * i + 2] * T[i] * DAY2SEC, self.common_mu, N=500, color='b', legend=False, units=JR) #Lambert arc to reach Earth during (1-nu2)*T2 (second segment) dt = (1 - x[4 * i + 2]) * T[i] * DAY2SEC l = lambert_problem(r, r_P[i], dt, self.common_mu, False, False) plot_lambert(ax, l, sol=0, color='r', legend=False, units=JR, N=500) v_end_l = l.get_v2()[0] v_beg_l = l.get_v1()[0] #DSM occuring at time nu2*T2 DV[i] = norm([a - b for a, b in zip(v_beg_l, v)]) plt.show() return ax
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.orbit_plots import plot_planet, plot_lambert, plot_kepler 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 recording the various times of flight (days) in the list T T = list([0] * (self.__n_legs)) #a[-i] = x[-1-(i-1)*4] for i in xrange(self.__n_legs - 1): j = i + 1 T[-j] = (x[5] - sum(T[-(j - 1):])) * x[-1 - (j - 1) * 4] T[0] = x[5] - sum(T) #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)) DV = 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] = planet.eph(t_P[i]) plot_planet(ax, planet, t0=t_P[i], color=(0.8, 0.6, 0.8), legend=True, units=AU) #3 - We start with the first leg theta = 2 * pi * x[1] phi = acos(2 * x[2] - 1) - pi / 2 Vinfx = x[3] * cos(phi) * cos(theta) Vinfy = x[3] * cos(phi) * sin(theta) Vinfz = x[3] * sin(phi) v0 = [a + b for a, b in zip(v_P[0], [Vinfx, Vinfy, Vinfz])] r, v = propagate_lagrangian(r_P[0], v0, x[4] * T[0] * DAY2SEC, self.common_mu) plot_kepler(ax, r_P[0], v0, x[4] * T[0] * DAY2SEC, self.common_mu, N=100, color='b', legend=False, units=AU) #Lambert arc to reach seq[1] dt = (1 - x[4]) * T[0] * DAY2SEC l = lambert_problem(r, r_P[1], dt, self.common_mu, False, False) plot_lambert(ax, l, sol=0, color='r', legend=False, units=AU) v_end_l = l.get_v2()[0] v_beg_l = l.get_v1()[0] #First DSM occuring at time nu1*T1 DV[0] = norm([a - b for a, b in zip(v_beg_l, v)]) #4 - And we proceed with each successive leg for i in range(1, self.__n_legs): #Fly-by v_out = fb_prop(v_end_l, v_P[i], x[7 + (i - 1) * 4] * self.seq[i].radius, x[6 + (i - 1) * 4], self.seq[i].mu_self) #s/c propagation before the DSM r, v = propagate_lagrangian(r_P[i], v_out, x[8 + (i - 1) * 4] * T[i] * DAY2SEC, self.common_mu) plot_kepler(ax, r_P[i], v_out, x[8 + (i - 1) * 4] * T[i] * DAY2SEC, self.common_mu, N=100, color='b', legend=False, units=AU) #Lambert arc to reach Earth during (1-nu2)*T2 (second segment) dt = (1 - x[8 + (i - 1) * 4]) * T[i] * DAY2SEC l = lambert_problem(r, r_P[i + 1], dt, self.common_mu, False, False) plot_lambert(ax, l, sol=0, color='r', legend=False, units=AU, N=1000) v_end_l = l.get_v2()[0] v_beg_l = l.get_v1()[0] #DSM occuring at time nu2*T2 DV[i] = norm([a - b for a, b in zip(v_beg_l, v)]) plt.show()
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.orbit_plots import plot_planet, plot_lambert, plot_kepler if ax is None: mpl.rcParams['legend.fontsize'] = 10 fig = plt.figure() axis = fig.gca(projection='3d') else: axis = ax axis.scatter(0, 0, 0, color='y') # 1 - we 'decode' the chromosome recording the various times of flight # (days) in the list T and the cartesian components of vinf T, Vinfx, Vinfy, Vinfz = self._decode_times_and_vinf(x) # 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)) DV = 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] = planet.eph(t_P[i]) plot_planet(planet, t0=t_P[i], color=(0.8, 0.6, 0.8), legend=True, units = AU, ax=axis) # 3 - We start with the first leg v0 = [a + b for a, b in zip(v_P[0], [Vinfx, Vinfy, Vinfz])] r, v = propagate_lagrangian(r_P[0], v0, x[5] * T[0] * DAY2SEC, self.common_mu) plot_kepler(r_P[0], v0, x[5] * T[0] * DAY2SEC, self.common_mu, N=100, color='b', legend=False, units=AU, ax=axis) # Lambert arc to reach seq[1] dt = (1 - x[5]) * T[0] * DAY2SEC l = lambert_problem(r, r_P[1], dt, self.common_mu, False, False) plot_lambert(l, sol=0, color='r', legend=False, units=AU, ax=axis) v_end_l = l.get_v2()[0] v_beg_l = l.get_v1()[0] # First DSM occuring at time nu1*T1 DV[0] = norm([a - b for a, b in zip(v_beg_l, v)]) # 4 - And we proceed with each successive leg for i in range(1, self.__n_legs): # Fly-by v_out = fb_prop(v_end_l, v_P[i], x[8 + (i - 1) * 4] * self.seq[i].radius, x[7 + (i - 1) * 4], self.seq[i].mu_self) # s/c propagation before the DSM r, v = propagate_lagrangian(r_P[i], v_out, x[9 + (i - 1) * 4] * T[i] * DAY2SEC, self.common_mu) plot_kepler(r_P[i], v_out, x[9 + (i - 1) * 4] * T[i] * DAY2SEC, self.common_mu, N=100, color='b', legend=False, units=AU, ax=axis) # Lambert arc to reach Earth during (1-nu2)*T2 (second segment) dt = (1 - x[9 + (i - 1) * 4]) * T[i] * DAY2SEC l = lambert_problem(r, r_P[i + 1], dt, self.common_mu, False, False) plot_lambert(l, sol=0, color='r', legend=False, units=AU, N=1000, ax=axis) v_end_l = l.get_v2()[0] v_beg_l = l.get_v1()[0] # DSM occuring at time nu2*T2 DV[i] = norm([a - b for a, b in zip(v_beg_l, v)]) plt.show() return axis
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.orbit_plots import plot_planet, plot_lambert, plot_kepler mpl.rcParams['legend.fontsize'] = 10 fig = plt.figure() axis = fig.gca(projection='3d') axis.scatter(0,0,0, color='y') #1 - we 'decode' the chromosome recording the various times of flight (days) in the list T T = list([0]*(self.__n_legs)) for i in range(0, self.__n_legs): T[i] = x[4+3*(self.__n_legs - 1) + i+1] #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)) DV = 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] = planet.eph(t_P[i]) plot_planet(planet, t0=t_P[i], color=(0.8,0.6,0.8), legend=True, units = AU, ax=axis) #3 - We start with the first leg theta = 2*pi*x[1] phi = acos(2*x[2]-1)-pi/2 Vinfx = x[3]*cos(phi)*cos(theta) Vinfy = x[3]*cos(phi)*sin(theta) Vinfz = x[3]*sin(phi) v0 = [a+b for a,b in zip(v_P[0],[Vinfx,Vinfy,Vinfz])] r,v = propagate_lagrangian(r_P[0],v0,x[4]*T[0]*DAY2SEC,self.common_mu) plot_kepler(r_P[0],v0,x[4]*T[0]*DAY2SEC,self.common_mu,N = 100, color='b', legend=False, units = AU, ax=axis) #Lambert arc to reach seq[1] dt = (1-x[4])*T[0]*DAY2SEC l = lambert_problem(r,r_P[1],dt,self.common_mu, False, False) plot_lambert(l, sol = 0, color='r', legend=False, units = AU, ax=axis) v_end_l = l.get_v2()[0] v_beg_l = l.get_v1()[0] #First DSM occurring at time nu1*T1 DV[0] = norm([a-b for a,b in zip(v_beg_l,v)]) #4 - And we proceed with each successive leg for i in range(1,self.__n_legs): #Fly-by v_out = fb_prop(v_end_l,v_P[i],x[6+(i-1)*3]*self.seq[i].radius,x[5+(i-1)*3],self.seq[i].mu_self) #s/c propagation before the DSM r,v = propagate_lagrangian(r_P[i],v_out,x[7+(i-1)*3]*T[i]*DAY2SEC,self.common_mu) plot_kepler(r_P[i],v_out,x[7+(i-1)*3]*T[i]*DAY2SEC,self.common_mu,N = 100, color='b', legend=False, units = AU, ax=axis) #Lambert arc to reach Earth during (1-nu2)*T2 (second segment) dt = (1-x[7+(i-1)*3])*T[i]*DAY2SEC l = lambert_problem(r,r_P[i+1],dt,self.common_mu, False, False) plot_lambert(l, sol = 0, color='r', legend=False, units = AU, N=1000, ax=axis) v_end_l = l.get_v2()[0] v_beg_l = l.get_v1()[0] #DSM occurring at time nu2*T2 DV[i] = norm([a-b for a,b in zip(v_beg_l,v)]) plt.show() return axis
v3 = np.array([-7557.86574,0,0]) r1a = math.sqrt(r1[0]**2+r1[1]**2+r1[2]**2) MU_EARTH = 3.986004418e14 dt = 3.1415926535* math.sqrt((r1a+100000)**3/MU_EARTH) # seconds l = lambert_problem(r1, r2, dt*.5, MU_EARTH) fig2 = plt.figure(2) axis2 = fig2.gca(projection='3d') axis2.scatter([0], [0], [0], color='y') plot_lambert(l, sol=0, ax=axis2, color='r') # plot_lambert(l, sol=1, ax=axis2, color='r') x0 = l.get_x()[0] plot_kepler(r1, v0, dt*2, MU_EARTH, N=600, units=1, color='b',legend=False, ax=axis2) plot_kepler(r2, v3, dt*2.2, MU_EARTH, N=600, units=1, color='b',legend=False, ax=axis2) axis2.set_ylim3d(-1.2*6378000,1.2*6378000) axis2.set_xlim3d(-1.2*6378000,1.2*6378000) plt.xlabel('X coordinate [m]') plt.ylabel('Y coordinate [m]') # plt.zlabel('Z coordinate [m]') # plt.ylabel('DV [m/s]') plt.title('Lambert transfers for 200km altitude increase with different time of flight') plt.show() # dt = 3*3.1415926535* math.sqrt((r1a+100000)**3/MU_EARTH) # seconds l = lambert_problem(r1, r2, dt*2.4, MU_EARTH) fig2 = plt.figure(2) axis2 = fig2.gca(projection='3d') axis2.scatter([0], [0], [0], color='y')
def AIO(self,x, doplot = True, doprint = True, rtrn_desc = True, dists_class = None): P = doprint plots_datas = list([None] * (self.__n)) PLDists = list([None] * (self.__n-1)) FBDates = list([None] * (self.__n-1)) #1 - we 'decode' the chromosome recording the various times of flight (days) in the list T T = list([0]*(self.__n)) #a[-i] = x[-1-(i-1)*4] for i in xrange(self.__n-1): j = i+1; T[-j] = (x[5] - sum(T[-(j-1):])) * x[-1-(j-1)*4] T[0] = x[5] - sum(T) #2 - We compute the epochs and ephemerides of the planetary encounters t_P = list([None] * (self.__n+1)) r_P = list([None] * (self.__n+1)) v_P = list([None] * (self.__n+1)) DV = list([None] * (self.__n+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 start with the first leg if P: print "First Leg: " + self.seq[0].name + " to " + self.seq[1].name theta = 2*pi*x[1] phi = acos(2*x[2]-1)-pi/2 Vinfx = x[3]*cos(phi)*cos(theta) Vinfy = x[3]*cos(phi)*sin(theta) Vinfz = x[3]*sin(phi) if P: print("Departure: " + str(t_P[0]) + " (" + str(t_P[0].mjd2000) + " mjd2000) \n" "Duration: " + str(T[0]) + " days\n" "VINF: " + str(x[3] / 1000) + " km/sec\n" "C3: " + str((x[3] / 1000)**2) + " km^2/s^2") v0 = [a+b for a,b in zip(v_P[0], [Vinfx,Vinfy,Vinfz])] r,v = propagate_lagrangian(r_P[0], v0, x[4]*T[0]*DAY2SEC, MU_SUN) if P: print "DSM after " + str(x[4]*T[0]) + " days" #Lambert arc to reach seq[1] dt = (1-x[4])*T[0]*DAY2SEC l = lambert_problem(r, r_P[1], dt, MU_SUN) v_end_l = l.get_v2()[0] v_beg_l = l.get_v1()[0] # Append data needed for potential plot generation plots_datas[0] = [v0, x[4]*T[0]*DAY2SEC, l] #First DSM occuring at time nu1*T1 DV[0] = norm([a-b for a,b in zip(v_beg_l,v)]) if P: print "DSM magnitude: " + str(DV[0]) + "m/s" #4 - And we proceed with each successive leg for i in range(1,self.__n): if P: print("\nleg no. " + str(i+1) + ": " + self.seq[i].name + " to " + self.seq[i+1].name + "\n" "Duration: " + str(T[i]) + "days") #Fly-by v_out = fb_prop(v_end_l, v_P[i], x[7+(i-1)*4]*self.seq[i].radius, x[6+(i-1)*4], self.seq[i].mu_self) PLDists[i-1] = (x[7+(i-1)*4] -1)*self.seq[i].radius/1000. FBDates[i-1] = t_P[i] if P: print("Fly-by epoch: " + str(t_P[i]) + " (" + str(t_P[i].mjd2000) + " mjd2000) \n" "Fly-by radius: " + str(x[7+(i-1)*4]) + " planetary radii\n" "Fly-by distance: " + str( (x[7+(i-1)*4] -1)*self.seq[i].radius/1000.) + " km") #s/c propagation before the DSM r,v = propagate_lagrangian(r_P[i], v_out, x[8+(i-1)*4]*T[i]*DAY2SEC, MU_SUN) if P: print "DSM after " + str(x[8+(i-1)*4]*T[i]) + " days" #Lambert arc to reach Earth during (1-nu2)*T2 (second segment) dt = (1-x[8+(i-1)*4])*T[i]*DAY2SEC l = lambert_problem(r, r_P[i+1], dt, MU_SUN) v_end_l = l.get_v2()[0] v_beg_l = l.get_v1()[0] # Append data needed for potential plot generation plots_datas[i] = [v_out, x[8+(i-1)*4]*T[i]*DAY2SEC, l] #DSM occuring at time nu2*T2 DV[i] = norm([a-b for a,b in zip(v_beg_l,v)]) if P: print "DSM magnitude: " + str(DV[i]) + "m/s" #Last Delta-v if P: print "\nArrival at " + self.seq[-1].name DV[-1] = norm([a-b for a,b in zip(v_end_l,v_P[-1])]) if P: print("Arrival Vinf: " + str(DV[-1]) + "m/s \n" "Total mission time: " + str(sum(T)/365.25) + " years (" + str(sum(T)) + " days) \n" "DSMs mag: " + str(sum(DV[:-1])) + "m/s \n" "Entry Vel: " + str(sqrt(2*(0.5*(DV[-1])**2 + 61933310.95))) + "m/s \n" "Entry epoch: " + str(epoch(t_P[0].mjd2000 + sum(T))) ) if doplot: import matplotlib as mpl from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt from PyKEP.orbit_plots import plot_planet, plot_lambert, plot_kepler mpl.rcParams['legend.fontsize'] = 10 fig = plt.figure(figsize=(8, 8), dpi=80) ax = fig.gca(projection='3d') ax.scatter(0,0,0, color='y') for i,planet in enumerate(self.seq): plot_planet(ax, planet, t0=t_P[i], color=(0.8,0.6,0.8), legend=True, units = AU) for i, tpl in enumerate(plots_datas): plot_kepler(ax, r_P[i], tpl[0], tpl[1], MU_SUN ,N = 100, color='b', legend=False, units = AU) plot_lambert(ax, tpl[2], sol = 0, color='r', legend=False, units = AU) fig.tight_layout() plt.show() if dists_class is not None: for i, tpl in enumerate(plots_datas): dists_class.positions_kepler(r_P[i], tpl[0], tpl[1], MU_SUN ,index = 2*i) dists_class.positions_lambert(tpl[2], sol = 0, index = 2*(i+.5)) dists_class.set_launch_epoch(t_P[0].mjd2000) return dists_class if rtrn_desc: import numpy as np from math import atan2 desc = dict() for i in range(len(x)): desc[i] = x[i] theta = 2*pi*x[1] phi = acos(2*x[2]-1)-pi/2 axtl = 23.43929*DEG2RAD # Earth axial tlit mactran = np.matrix([ [1, 0, 0], [0, cos(axtl), -sin(axtl)], [0, sin(axtl), cos(axtl)] ]) # Macierz przejscia z helio do ECI macdegs = np.matrix([ [cos(phi)*cos(theta)], [cos(phi)*sin(theta)], [sin(phi)] ]) aaa = mactran.dot(macdegs) theta_earth = atan2(aaa[1,0], aaa[0,0]) # Rektascensja asym phi_earth = asin(aaa[2,0]) # Deklinacja asym desc['RA'] = 360+RAD2DEG*theta_earth desc['DEC'] = phi_earth*RAD2DEG desc['Ldate'] = str(t_P[0]) desc['C3'] = (x[3] / 1000)**2 desc['dVmag'] = sum(DV[:-1]) desc['VinfRE'] = DV[-1] desc['VRE'] = (DV[-1]**2 + 2*61933310.95)**.5 desc['REDate'] = str(epoch(t_P[0].mjd2000 + sum(T))) for i in range(1,self.__n): desc[self.seq[i].name[0].capitalize()+'Dist'] = PLDists[i-1] desc[self.seq[i].name[0].capitalize()+'FBDate'] = str(FBDates[i-1]) return desc
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.orbit_plots import plot_planet, plot_lambert, plot_kepler if ax is None: mpl.rcParams['legend.fontsize'] = 10 fig = plt.figure() axis = fig.gca(projection='3d') else: axis = ax axis.scatter(0, 0, 0, color='y') # 1 - we 'decode' the chromosome recording the various deep space # manouvres timing (days) in the list T T = list([0] * (self.N_max - 1)) for i in range(len(T)): T[i] = log(x[2 + 4 * i]) total = sum(T) T = [x[1] * time / total for time in T] # 2 - We compute the starting and ending position r_start, v_start = self.start.eph(epoch(x[0])) if self.phase_free: r_target, v_target = self.target.eph(epoch(x[-1])) else: r_target, v_target = self.target.eph(epoch(x[0] + x[1])) plot_planet(self.start, t0=epoch(x[0]), color=(0.8, 0.6, 0.8), legend=True, units=AU, ax=axis) plot_planet(self.target, t0=epoch(x[0] + x[1]), color=(0.8, 0.6, 0.8), legend=True, units=AU, ax=axis) # 3 - We loop across inner impulses rsc = r_start vsc = v_start for i, time in enumerate(T[:-1]): theta = 2 * pi * x[3 + 4 * i] phi = acos(2 * x[4 + 4 * i] - 1) - pi / 2 Vinfx = x[5 + 4 * i] * cos(phi) * cos(theta) Vinfy = x[5 + 4 * i] * cos(phi) * sin(theta) Vinfz = x[5 + 4 * i] * sin(phi) # We apply the (i+1)-th impulse vsc = [a + b for a, b in zip(vsc, [Vinfx, Vinfy, Vinfz])] plot_kepler(rsc, vsc, T[i] * DAY2SEC, self.__common_mu, N=200, color='b', legend=False, units=AU, ax=axis) rsc, vsc = propagate_lagrangian(rsc, vsc, T[i] * DAY2SEC, self.__common_mu) cw = (ic2par(rsc, vsc, self.start.mu_central_body)[2] > pi / 2) # We now compute the remaining two final impulses # Lambert arc to reach seq[1] dt = T[-1] * DAY2SEC l = lambert_problem(rsc, r_target, dt, self.__common_mu, cw, False) plot_lambert(l, sol=0, color='r', legend=False, units=AU, ax=axis, N=200) plt.show() return axis