Пример #1
0
        def extrapo_intern_fct(i_ref, coef, until):
            ##
            ## backward :
            ## i_ref , coef = 0,-1
            ##
            ## forward :
            ## i_ref , coef = -1,1
            ##
            ## CORRDS ARE GIVEN IN ECI HERE !!!
            ##
            orbit_back = TwoBodyOrbit("orbit",
                                      mu=3.9860044188e14)  # create an instance
            orbit_back.setOrbCart(Tsec[i_ref], P[i_ref],
                                  V[i_ref])  # define the orbit

            if until:
                t_rang_strt, t_rang_end = list(sorted([Tutc[i_ref], until]))
                Range = conv.dt_range(t_rang_strt, t_rang_end, 0, step)
                n_step_intern = len(Range) - 1
            else:
                n_step_intern = n_step

            for t in np.arange(step, n_step_intern * step + 1, step):
                Pout, Vout = orbit_back.posvelatt(coef * t)
                epoc = Tgps[i_ref] + coef * dt.timedelta(seconds=int(t))
                DFline_new = DFline_dummy.copy()
                DFline_new[["x", "y", "z"]] = Pout
                DFline_new["epoch"] = pd.Timestamp(epoc)

                NewEpoch_stk.append(DFline_new)

            return Pout, Vout
Пример #2
0
 def points(self, jd, ndata):
     sunpos, sunvel = common.SPKposvel(10, jd)
     tpos, tvel = self.posvel(jd)
     tpos -= sunpos
     tvel -= sunvel
     orbit = TwoBodyOrbit(self.name, 'Sun', common.solarmu)
     orbit.setOrbCart(0.0, tpos, tvel)
     xs, ys, zs, ts = orbit.points(ndata)
     xs += sunpos[0]
     ys += sunpos[1]
     zs += sunpos[2]
     ts /= common.secofday
     return xs, ys, zs, ts
Пример #3
0
def extrapolate_orbit_kepler(P, V, t, t0, mu=3.9860044188e14):
    orbit = TwoBodyOrbit("", mu=mu)  # create an instance
    orbit.setOrbCart(t0, P, V)  # define the orbit
    Pout, Vout = orbit.posvelatt(t)  # get position and velocity at t1
    kepl = orbit.elmKepl()  # get classical orbital elements

    return Pout, Vout, kepl
Пример #4
0
import numpy as np
import tkinter
from pytwobodyorbit import TwoBodyOrbit
from pytwobodyorbit import lambert
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import matplotlib

# Standard gravitational parameter for the Sun
# With this parameter, lenght should be in meters,
# and time should be in seconds
sunmu = 1.32712440041e20

# Create instance of TwoBodyOrbit
orbit = TwoBodyOrbit('object', mu=sunmu)

# Seconds of a day
secofday = 86400.0

# prepare plotting
matplotlib.rcParams['toolbar'] = 'none'
plt.ion()  # set pyplot to the interactive mode
fig = plt.figure(figsize=(11, 11))
ax = fig.gca(projection='3d', aspect='equal')
ax.set_clip_on(True)
ax.set_xlim(-3.0e11, 3.0e11)
ax.set_ylim(-3.0e11, 3.0e11)
ax.set_zlim(-3.0e11, 3.0e11)
ax.set_xlabel('X')
ax.set_ylabel('Y')
 def __init__(self, pname):
     self.orbit = TwoBodyOrbit(pname, 'Sun', common.solarmu)
     return
class TwoBodyPred:
    """class for two body prediction
    """
    def __init__(self, pname):
        self.orbit = TwoBodyOrbit(pname, 'Sun', common.solarmu)
        return

    def fix_state(self, jd, ppos, pvel):
        self.jd = jd
        self.sunpos, self.sunvel = common.SPKposvel(10, self.jd)
        jdsec = self.jd * common.secofday
        self.ppos = ppos
        self.pvel = pvel
        pos = self.ppos - self.sunpos
        vel = self.pvel - self.sunvel
        self.orbit.setOrbCart(jdsec, pos, vel)
        return
        
    def set_pred_dv(self, dv, phi, elv):
        relv = math.radians(elv)
        rphi = math.radians(phi)
        ldv = np.array([
            dv * np.cos(relv) * np.cos(rphi),
            dv * np.cos(relv) * np.sin(rphi),
            dv * np.sin(relv)
            ])
        self.pred_vel = self.pvel + \
            common.ldv2ecldv(ldv, self.ppos, self.pvel, \
            self.sunpos, self.sunvel)
        jdsec = self.jd * common.secofday
        pos = self.ppos - self.sunpos
        vel = self.pred_vel - self.sunvel
        self.orbit.setOrbCart(jdsec, pos, vel)
        return
        
    def points(self, ndata):
        xs, ys, zs, times = self.orbit.points(ndata)
        return xs + self.sunpos[0], ys + self.sunpos[1], zs + self.sunpos[2], \
            times / common.secofday
        
    def posvelatt(self, jd):
        jdsec = jd * common.secofday
        pos, vel =self.orbit.posvelatt(jdsec)
        
        # sunpos, sunvel at jd
        spos, svel = common.SPKposvel(10, jd)
        return pos + spos, vel + svel
        
    def fta(self, jd, tepos):
        # compute fixed time arrival guidance
        # jd : date of arrival
        # tepos position of target at jd (barycenter origin)
        dsec = (jd - self.jd) * common.secofday
        ipos = self.ppos - self.sunpos
        
        # sun position at end
        esunpos, esunvel = common.SPKposvel(10, jd)
        
        tpos = tepos - esunpos
        ivel, tvel = lambert(ipos, tpos, dsec, common.solarmu, ccw=True)
        iprobe_vel = self.pvel - self.sunvel
        delta_v = ivel - iprobe_vel
        
        localdv = common.eclv2lv(delta_v, self.ppos, self.pvel, self.sunpos, 
                                 self.sunvel)
        return common.rect2polar(localdv)
        
    def ftavel(self, jd, tepos):
        # compute fixed time arrival guidance
        # jd : date of arrival
        # tepos position of target at jd (barycenter origin)
        dsec = (jd - self.jd) * common.secofday
        ipos = self.ppos - self.sunpos
        
        # sun position and velocity at end
        esunpos, esunvel = common.SPKposvel(10, jd)
        
        tpos = tepos - esunpos
        ivel, tvel = lambert(ipos, tpos, dsec, common.solarmu, ccw=True)
        iprobe_vel = self.pvel - self.sunvel
        delta_v = ivel - iprobe_vel
        localdv = common.eclv2lv(delta_v, self.ppos, self.pvel, self.sunpos, 
                                 self.sunvel)
        dv, phi, elv = common.rect2polar(localdv)
        
        bc_ivel = ivel + self.sunvel
        bc_tvel = tvel + esunvel

        # returns intial velocity and terminal velocity (SSB origin)
        return dv, phi, elv, bc_ivel, bc_tvel
        
    def vta(self, jd, tpos, tvel):
        print('vta function is under construction')
        return
        
    def elmKepl(self):
        kepl = self.orbit.elmKepl()
        kepl['epoch'] /= common.secofday    # convert to 'JD(day)'
        kepl['T'] /= common.secofday        # convert to 'JD(day)'
        if kepl['e'] < 1.0:
            kepl['n'] *= common.secofday    # convert to 'deg/day'
            kepl['P'] /= common.secofday    # convert to 'days'
        return kepl
#Apophis coordinates, plus calculation of the other anomalies.
a = 0.9222654975186300 * au.value  #in metres
e = 0.1910573105
i = 3.33132242244163  #All in DEGREES
asc_node = 204.45996801109067
a_of_p = 126.39643948747843
mean_anomaly = 61.41677858002747

eccentric_anomaly = mean_to_eccentric(m.radians(mean_anomaly), e)  #in radians

true_anomaly_r = 2 * m.atan(
    ((1 + e) / (1 - e))**.5 * m.tan(eccentric_anomaly / 2))
true_anomaly = m.degrees(true_anomaly_r)
'''Conversion 1: TwoBodyOrbit package'''
a_km = a / 1000
initial_conditions = TwoBodyOrbit("Apophis", mu=GM_sun.value)
initial_conditions.setOrbKepl(epoch_JD, a, e, i, asc_node, a_of_p,
                              mean_anomaly)
conversion_1 = initial_conditions.posvelatt(epoch_JD)[0]
print("Conversion 1:", conversion_1)
'''Conversion 2: spiceypy (based on NASA SPICE)'''

#Converts elements to radians and km, as required in spiceypy
i_r = m.radians(i)
asc_node_r = m.radians(asc_node)
a_of_p_r = m.radians(a_of_p)
mean_anomaly_r = m.radians(mean_anomaly)

r_p = a_km * (1 - e)
GM_sun_km = GM_sun.value / 10**9