예제 #1
0
    def test_cart_kep_loop(self):

        orb_init = n.array([self.a, 0.2, 23.0, 136.0, 44.0, 10.0],
                           dtype=n.float)

        x = dpt.kep2cart(orb_init, m=self.m, M_cent=self.M_e, radians=False)
        x_ref = x.copy()
        for ind in range(200):
            o = dpt.cart2kep(x, m=self.m, M_cent=self.M_e, radians=False)
            x = dpt.kep2cart(o, m=self.m, M_cent=self.M_e, radians=False)

        nt.assert_array_almost_equal(x, x_ref, decimal=6)
예제 #2
0
    def test_kep2cart_Omega_inc(self):
        self.orb_init[1] = 0.8
        self.orb_init[2] = 45.0
        self.orb_init[3] = 90.0
        self.orb_init[4] = 90.0

        nu = n.degrees(n.array([0.0], dtype=n.float))
        res = nu.size

        o = n.empty((6, res), dtype=n.float)
        for i in range(res):
            o[:5, i] = self.orb_init
            o[5, i] = nu[i]

        x = dpt.kep2cart(o, m=self.m, M_cent=self.M_e, radians=False)

        #rotates counterclockwise in orbital plane
        r = n.sqrt(n.sum(x[:3, :]**2, axis=0))

        nt.assert_almost_equal(
            r[0] / self.R_e,
            (1.0 - self.orb_init[1]) * self.orb_init[0] / self.R_e,
            decimal=3,
        )

        #check quadrant of periapsis
        assert x[2, 0] > 0.0 and x[0, 0] < 0.0 and n.abs(
            x[1, 0] / self.R_e) < 1e-3
예제 #3
0
    def test_kep2cart_omega_inc(self):
        self.orb_init[1] = 0.8
        self.orb_init[2] = 90.0
        self.orb_init[3] = 90.0

        nu = n.degrees(n.array([0.0], dtype=n.float))
        res = nu.size

        o = n.empty((6, res), dtype=n.float)
        for i in range(res):
            o[:5, i] = self.orb_init
            o[5, i] = nu[i]

        x = dpt.kep2cart(o, m=self.m, M_cent=self.M_e, radians=False)

        #rotates counterclockwise in orbital plane
        r = n.sqrt(n.sum(x[:3, :]**2, axis=0))

        nt.assert_almost_equal(
            r[0] / self.R_e,
            (1.0 - self.orb_init[1]) * self.orb_init[0] / self.R_e,
            decimal=3,
        )

        #check periapsis lies on +z axis
        nt.assert_almost_equal(
            x[2, 0] / self.R_e,
            n.linalg.norm(x[:, 0]) / self.R_e,
            decimal=3,
        )
예제 #4
0
    def test_orbit_inverse_error_kep(self):
        mjd0 = dpt.jd_to_mjd(2457126.2729)

        orb_init_list = self._gen_orbits(1000)

        prop = PropagatorKepler(
                in_frame='EME',
                out_frame='EME',
        )

        t = n.array([0.0])
        
        for kep in orb_init_list:
            state_ref = dpt.kep2cart(kep, m=self.init_data['m'], M_cent=M_earth, radians=False)

            state = prop.get_orbit(
                t=t, mjd0=mjd0,
                a=kep[0], e=kep[1], inc=kep[2],
                raan=kep[4], aop=kep[3], mu0=dpt.true2mean(kep[5], kep[1], radians=False),
                m=self.init_data['m'],
                radians=False,
            )

            state_diff1 = n.abs(state_ref - state[:,0])

            nt.assert_array_less(state_diff1[:3], n.full((3,), 1e-5, dtype=state_diff1.dtype))
            nt.assert_array_less(state_diff1[3:], n.full((3,), 1e-7, dtype=state_diff1.dtype))
예제 #5
0
    def get_orbit(self,t,a,e,inc,raan,aop,mu0,mjd0, **kwargs):
        '''
        **Implementation:**
    
        Units are in meters and degrees.

        Keyword arguments are:

        **Uses:**
            * 
        
        See :func:`propagator_base.PropagatorBase.get_orbit`.
        '''

        m = kwargs.setdefault('m', 0.0)

        orb = np.array([a,e,inc,aop,raan,dpt.mean2true(mu0,e, radians = False)], dtype=np.float)
        
        if self._inframe_to_heliocentric:
            M_cent = self.planets_mass[self._earth_ind - 1]
        else:
            M_cent = self.m_sun

        x, y, z, vx, vy, vz = dpt.kep2cart(
            orb,
            m=m,
            M_cent=M_cent,
            radians=False,
        )

        return self.get_orbit_cart(t, x, y, z, vx, vy, vz, mjd0, **kwargs)
예제 #6
0
    def test_orbit_inverse_error_cart(self):
        mjd0 = dpt.jd_to_mjd(2457126.2729)

        orb_init_list = self._gen_orbits(1000)

        prop = PropagatorKepler(
                in_frame='TEME',
                out_frame='TEME',
        )

        t = n.array([0.0])
        orbs_done = 0
        for kep in orb_init_list:
            state_ref = dpt.kep2cart(kep, m=self.init_data['m'], M_cent=M_earth, radians=False)

            state = prop.get_orbit_cart(
                t=t, mjd0=mjd0,
                x=state_ref[0], y=state_ref[1], z=state_ref[2],
                vx=state_ref[3], vy=state_ref[4], vz=state_ref[5],
                m=self.init_data['m'],
            )

            state_diff1 = n.abs(state_ref - state[:,0])
            if n.linalg.norm(state_diff1[:3]) > 1e-5:
                print(kep)
                print(orbs_done)
            nt.assert_array_less(state_diff1[:3], n.full((3,), 1e-5, dtype=state_diff1.dtype))
            nt.assert_array_less(state_diff1[3:], n.full((3,), 1e-7, dtype=state_diff1.dtype))
            orbs_done += 1
예제 #7
0
    def test_orbit_kep_cart_correspondance(self):
        mjd0 = dpt.jd_to_mjd(2457126.2729)

        orb_init_list = self._gen_orbits(100)

        prop = PropagatorKepler(
                in_frame='EME',
                out_frame='EME',
        )

        t = n.linspace(0, 12*3600, num=100, dtype=n.float)
        
        for kep in orb_init_list:
            state_ref = dpt.kep2cart(kep, m=self.init_data['m'], M_cent=M_earth, radians=False)

            state_kep = prop.get_orbit(
                t=t, mjd0=mjd0,
                a=kep[0], e=kep[1], inc=kep[2],
                raan=kep[4], aop=kep[3], mu0=dpt.true2mean(kep[5], kep[1], radians=False),
                m=self.init_data['m'], 
                radians=False,
            )
            state_cart = prop.get_orbit_cart(
                t=t, mjd0=mjd0,
                x=state_ref[0], y=state_ref[1], z=state_ref[2],
                vx=state_ref[3], vy=state_ref[4], vz=state_ref[5],
                m=self.init_data['m'],
            )

            state_diff1 = n.abs(state_kep - state_cart)

            nt.assert_array_less(state_diff1[:3,:], n.full((3,t.size), 1e-5, dtype=state_diff1.dtype))
            nt.assert_array_less(state_diff1[3:,:], n.full((3,t.size), 1e-7, dtype=state_diff1.dtype))
예제 #8
0
    def _gen_cart(self, p):
        orb = n.array([
            self.init_data['a'],
            self.init_data['e'],
            self.init_data['inc'],
            self.init_data['aop'],
            self.init_data['raan'],
            dpt.mean2true(self.init_data['mu0'],
                          self.init_data['e'],
                          radians=False),
        ])
        cart = dpt.kep2cart(orb,
                            m=self.init_data['m'],
                            M_cent=p.M_earth,
                            radians=False)

        self.init_data_cart = {
            'x': cart[0],
            'y': cart[1],
            'z': cart[2],
            'vx': cart[3],
            'vy': cart[4],
            'vz': cart[5],
            'mjd0': 57125.7729,
            'C_D': 2.3,
            'C_R': 1.0,
            'm': 8000,
            'A': 1.0,
        }
예제 #9
0
    def test_TEME_to_TLE_cases(self):
        import propagator_sgp4

        R_E = 6353.0e3
        mjd0 = dpt.jd_to_mjd(2457126.2729)
        a = R_E*2.0
        orb_init_list = []

        orb_range = n.array([a, 0.9, 180, 360, 360, 360], dtype=n.float)
        orb_offset = n.array([R_E*1.1, 0, 0.0, 0.0, 0.0, 0.0], dtype=n.float)
        test_n = 5000
        while len(orb_init_list) < test_n:
            orb = n.random.rand(6)
            orb = orb_offset + orb*orb_range
            if orb[0]*(1.0 - orb[1]) > R_E+200e3:
                orb_init_list.append(orb)

        orb_init_list.append(n.array([R_E*1.2, 0, 0.0, 0.0, 0.0, 0.0], dtype=n.float))
        orb_init_list.append(n.array([R_E*1.2, 0, 0.0, 0.0, 0.0, 270], dtype=n.float))
        orb_init_list.append(n.array([R_E*1.2, 1e-9, 0.0, 0.0, 0.0, 0.0], dtype=n.float))
        orb_init_list.append(n.array([R_E*1.2, 0.1, 0.0, 0.0, 0.0, 0.0], dtype=n.float))
        orb_init_list.append(n.array([R_E*1.2, 0.1, 75.0, 0.0, 0.0, 0.0], dtype=n.float))
        orb_init_list.append(n.array([R_E*1.2, 0.1, 0.0, 120.0, 0.0, 0.0], dtype=n.float))
        orb_init_list.append(n.array([R_E*1.2, 0.1, 0.0, 0.0, 35.0, 0.0], dtype=n.float))
        orb_init_list.append(n.array([R_E*1.2, 0.1, 75.0, 120.0, 0.0, 0.0], dtype=n.float))
        orb_init_list.append(n.array([R_E*1.2, 0.1, 75.0, 0.0, 35.0, 0.0], dtype=n.float))
        orb_init_list.append(n.array([R_E*1.2, 0.1, 75.0, 120.0, 35.0, 0.0], dtype=n.float))
        
        fail_inds = []
        errs = n.empty((len(orb_init_list),2), dtype=n.float)
        for ind, kep in enumerate(orb_init_list):

            M_earth = propagator_sgp4.SGP4.GM*1e9/consts.G

            state_TEME = dpt.kep2cart(kep, m=0.0, M_cent=M_earth, radians=False)*1e-3

            mean_elements = tle.TEME_to_TLE(state_TEME, mjd0=mjd0, kepler=False)

            state = propagator_sgp4.sgp4_propagation(mjd0, mean_elements, B=0, dt=0.0)

            state_diff = n.abs(state - state_TEME)*1e3
            er_r = n.linalg.norm(state_diff[:3])
            er_v = n.linalg.norm(state_diff[3:])
            errs[ind,0] = er_r
            errs[ind,1] = er_v
            try:
                self.assertLess(er_r, 10.0)
                self.assertLess(er_v, 1.0)
            except AssertionError as err:
                fail_inds.append(ind)

        if len(fail_inds) > 0:
            print('FAIL / TOTAL: {} / {}'.format(len(fail_inds), len(orb_init_list)))

        self.assertLess(n.median(errs[:,0]), 1e-2)
        self.assertLess(n.median(errs[:,1]), 1e-4)

        assert len(fail_inds) < float(test_n)/100.
예제 #10
0
 def get_states(self, M_cent = propagator_sgp4.M_earth):
     '''Use the orbital parameters and get the state.'''
     orbs = self.get_all_orbits(order_angs = True).T
     orbs[:,5] = dpt.mean2true(orbs[:,5], orbs[:,1], radians=False)
     if 'm' in self.header:
         mv = self.objs['m']
     else:
         mv = np.zeros(len(self), dtype=self._default_dtype)
     states = dpt.kep2cart(orbs, m=mv, M_cent=M_cent, radians=False).T
     return states
예제 #11
0
    def get_orbit(self, t, a, e, inc, raan, aop, mu0, mjd0, **kwargs):
        '''
        **Implementation:**
    
        All state-vector units are in meters.

        Keyword arguments contain only mass :code:`m` in kg and is not required.

        They also contain a option to give angles in radians or degrees. By default input is assumed to be degrees.

        **Frame:**

        The input frame is always the same as the output frame.
    
        :param float m: Mass of the object in kg.
        :param bool radians: If true, all angles are assumed to be in radians.
        '''

        radians = kwargs.setdefault('radians', False)
        m = kwargs.setdefault('m', 0.0)

        if radians:
            one_lap = np.pi*2.0
        else:
            one_lap = 360.0

        gravitational_param = consts.G*(M_earth + m)

        mean_motion = np.sqrt(gravitational_param/(a**3.0))/(np.pi*2.0)

        t = self._make_numpy(t)

        mean_anomalies = mu0 + t*mean_motion*one_lap
        mean_anomalies = np.remainder(mean_anomalies, one_lap)

        true_anomalies = dpt.mean2true(mean_anomalies, e, radians=radians)

        orb0 = np.array([a, e, inc, aop, raan], dtype=np.float64)
        orb0.shape = (5,1)

        orbs = np.empty((6, len(t)), dtype=np.float64)
        orbs[:5, :] = np.repeat(orb0, len(t), axis=1)
        orbs[5, :] = true_anomalies

        states_raw = dpt.kep2cart(orbs, m=m, M_cent=M_earth, radians=radians)

        if self.in_frame != self.out_frame:
            states = frame_conversion(states_raw, t/(3600.0*24.0) + mjd0, self.orekit_in_frame, self.orekit_out_frame)
        else:
            states = states_raw
        
        return states
예제 #12
0
    def test_kep2cart_ecc(self):
        self.orb_init[1] = 0.8

        nu = n.degrees(
            n.array([0, n.pi * 0.5, 1.5 * n.pi, n.pi], dtype=n.float))
        res = nu.size

        o = n.empty((6, res), dtype=n.float)
        for i in range(res):
            o[:5, i] = self.orb_init
            o[5, i] = nu[i]

        x = dpt.kep2cart(o, m=self.m, M_cent=self.M_e, radians=False)

        r = n.sqrt(n.sum(x[:3, :]**2, axis=0))
        v = n.sqrt(n.sum(x[3:, :]**2, axis=0))

        #test true anomaly = 0 is periapsis
        assert n.all(r[0] < r[1:]), 'nu=0 is not periapsis'
        assert n.all(r[3] > r[:3]), 'nu=pi is not apoapsis'

        assert x[0, 0] > 0.0, 'periapsis NOT to +x'
        assert x[0, 3] < 0.0, 'apoapsis NOT to +x'

        #test velocity, fast at peri slow at apo
        assert n.all(v[0] > v[1:]), 'periapsis vel not fastest'
        assert n.all(v[3] < v[:3]), 'apoapsis vel not slowest'

        #test velocity is perp at peri and apo
        nt.assert_almost_equal(x[3, 0] * 1e-3, 0.0, decimal=3)
        nt.assert_almost_equal(x[3, 3] * 1e-3, 0.0, decimal=3)

        #test ellipse oriented along x
        nt.assert_almost_equal(x[1, 0] / self.R_e, 0.0, decimal=3)
        nt.assert_almost_equal(x[1, 3] / self.R_e, 0.0, decimal=3)

        #test orbital motion counter-clockwise
        assert x[1, 1] > 0.0, 'orbital motion is not counter-clockwise'
        assert x[1, 2] < 0.0, 'orbital motion is not counter-clockwise'

        #test periapsis distance and apoapsis distance
        nt.assert_almost_equal(
            r[0] / self.R_e,
            (1.0 - self.orb_init[1]) * self.orb_init[0] / self.R_e,
            decimal=3,
        )
        nt.assert_almost_equal(
            r[3] / self.R_e,
            (1.0 + self.orb_init[1]) * self.orb_init[0] / self.R_e,
            decimal=3,
        )
예제 #13
0
    def test_kep2cart_inc(self):
        self.orb_init[2] = 45.0

        nu = n.degrees(n.array([n.pi * 0.5], dtype=n.float))
        res = nu.size

        o = n.empty((6, res), dtype=n.float)
        for i in range(res):
            o[:5, i] = self.orb_init
            o[5, i] = nu[i]

        x = dpt.kep2cart(o, m=self.m, M_cent=self.M_e, radians=False)

        assert x[2, 0] > 0.0 and x[1, 0] > 0.0, '+y inclines towards +z'
예제 #14
0
def plot_orb_conv(orb_init, res=100):
    o = n.empty((6, res), dtype=n.float)
    nu = n.linspace(0, 360.0, num=res, dtype=n.float)

    for i in range(res):
        o[:5, i] = orb_init
        o[5, i] = nu[i]

    x_dpt = dpt.kep2cart(o, m=n.array([1.0]), M_cent=M_e, radians=False)

    fig = plt.figure(figsize=(15, 15))
    ax = fig.add_subplot(111, projection='3d')
    ax.view_init(15, 5)
    plothelp.draw_earth_grid(ax)

    max_range = orb_init[0] * 1.1

    ax.plot([0, max_range], [0, 0], [0, 0], "-k")
    ax.plot([0, max_range], [0, 0], [0, 0], "-k", label='+x')
    ax.plot([0, 0], [0, max_range], [0, 0], "-b", label='+y')
    ax.set_xlim(-max_range, max_range)
    ax.set_ylim(-max_range, max_range)
    ax.set_zlim(-max_range, max_range)
    ax.plot(x_dpt[0, :],
            x_dpt[1, :],
            x_dpt[2, :],
            ".k",
            alpha=0.5,
            label='Converted elements')
    ax.plot([x_dpt[0, 0]], [x_dpt[1, 0]], [x_dpt[2, 0]],
            "or",
            alpha=1,
            label='$\\nu = 0$')
    ax.plot([x_dpt[0, int(res // 4)]], [x_dpt[1, int(res // 4)]],
            [x_dpt[2, int(res // 4)]],
            "oy",
            alpha=1,
            label='$\\nu = 0.5\pi$')

    ax.legend()
    plt.title(
        "Kep -> cart: a={} km, e={}, inc={} deg, omega={} deg, Omega={} deg ".
        format(
            orb_init[0] * 1e-3,
            orb_init[1],
            orb_init[2],
            orb_init[3],
            orb_init[4],
        ))
예제 #15
0
파일: TLE_tools.py 프로젝트: zzwei1/SORTSpp
def _sgp4_elems2cart(kep, radians=True):
    '''Orbital elements to cartesian coordinates. Wrap DPT-function to use mean anomaly, km and reversed order on aoe and raan.
    
    Neglecting mass is sufficient for this calculation (the standard gravitational parameter is 24 orders larger then the change).
    '''
    _kep = kep.copy()
    _kep[0] *= 1e3
    tmp = _kep[4]
    _kep[4] = _kep[3]
    _kep[3] = tmp
    _kep[5] = dpt.mean2true(_kep[5], _kep[1], radians=radians)
    cart = dpt.kep2cart(kep,
                        m=0.0,
                        M_cent=propagator_sgp4.M_earth,
                        radians=radians)
    return cart
예제 #16
0
def get_orbit_cart(o):
    cart = dpt.kep2cart(o, m=1.0, M_cent=M_earth, radians=False)
    #print('{:.2f}, {:.2f}, {:.2f}, {:.2f}, {:.2f}, {:.2f}'.format(*cart.tolist()))
    ecef = prop.get_orbit_cart(
        t=0.0,
        x=cart[0],
        y=cart[1],
        z=cart[2],
        vx=cart[3],
        vy=cart[4],
        vz=cart[5],
        mjd0=dpt.jd_to_mjd(2457126.2729),
        C_D=2.3,
        A=1.0,
        m=1.0,
    )
    return ecef
예제 #17
0
def run_direct():

    prop = ReboundMOID(time_step=dt)

    init_orb = np.array([0.95 * AU / (1.0 - 0.6), 0.6, 78, 180.0, 0.0, 180.0])
    init_cart = dpt.kep2cart(init_orb, m=0.0, M_cent=dpt.M_sol, radians=False)

    fw = init_cart[3:] / np.linalg.norm(init_cart[3:])
    side = init_cart[:3] / np.linalg.norm(init_cart[:3])

    def model(v, theta):

        cart = init_cart.copy()

        pert_dir = np.cos(np.radians(theta)) * fw + np.cos(
            np.radians(theta)) * side
        pert = pert_dir * v

        cart[3:] = cart[3:] + pert
        return cart

    prop.states = np.empty((6, steps), dtype=np.float64)

    chain = np.zeros((1, params, prop.num), dtype=np.float64)

    for p in range(steps):
        theta = np.random.randn(1)[0] * 25.0
        v = np.random.rand(1)[0] * 200.0
        chain[0, 0, p] = theta
        chain[0, 1, p] = v
        prop.states[:, p] = model(v, theta)

    prop.t0 = 0.0

    t = np.arange(0, t_end * _year, dt, dtype=np.float64)

    out_results = [[None] * prop.num for ind in range(steps)]

    results = prop.propagate(t)

    with open(fname2, 'wb') as hf:
        pickle.dump([[results], chain], hf)
예제 #18
0
    def get_orbit(self, t, a, e, inc, raan, aop, mu0, mjd0, **kwargs):
        '''
        **Implementation:**
    
        All state-vector units are in meters.

        Keyword arguments contain only information needed for ballistic coefficient :code:`B` used by SGP4. Either :code:`B` or :code:`C_D`, :code:`A` and :code:`m` must be supplied.
        They also contain a option to give angles in radians or degrees. By default input is assumed to be degrees.

        **Frame:**

        The input frame is ECI (TEME) for orbital elements and Cartesian. The output frame is as standard ECEF (ITRF). But can be set to TEME.

        :param float B: Ballistic coefficient
        :param float C_D: Drag coefficient
        :param float A: Cross-sectional Area
        :param float m: Mass
        :param bool radians: If true, all angles are assumed to be in radians.
        '''
        if 'm' in kwargs:
            m = kwargs['m']
        else:
            m = 0.0

        if 'radians' in kwargs:
            radians = kwargs['radians']
        else:
            radians = False
        
        if not radians:
            inc = np.radians(inc)
            mu0 = np.radians(mu0)
            raan = np.radians(raan)
            aop = np.radians(aop)

        orb = np.array([a, e, inc, aop, raan, dpt.mean2true(mu0, e, radians=True)],dtype=np.float)

        state_c = dpt.kep2cart(orb, m=m, M_cent=M_earth, radians=True)

        return self.get_orbit_cart(t, x=state_c[0], y=state_c[1], z=state_c[2], vx=state_c[3], vy=state_c[4], vz=state_c[5], mjd0=mjd0, **kwargs)
예제 #19
0
    def test_kep2cart_circ(self):
        res = 100
        nu = n.linspace(0, 360.0, num=res, dtype=n.float)

        o = n.empty((6, res), dtype=n.float)
        for i in range(res):
            o[:5, i] = self.orb_init
            o[5, i] = nu[i]

        x = dpt.kep2cart(o, m=self.m, M_cent=self.M_e, radians=False)

        r0 = n.ones((res, ), dtype=n.float)
        r0 *= self.a / self.R_e
        r = n.sqrt(n.sum(x[:3, :]**2, axis=0)) / self.R_e

        nt.assert_array_almost_equal(r0, r, decimal=3)

        v0 = n.ones((res, ), dtype=n.float)
        v0 *= dpt.orbital_speed(
            self.a, self.a, scipy.constants.G * (self.m[0] + self.M_e)) * 1e-3
        v = n.sqrt(n.sum(x[3:, :]**2, axis=0)) * 1e-3

        nt.assert_array_almost_equal(v0, v, decimal=3)

        #check perpendicular vel to rad

        dot = n.sum(x[3:, :] * x[:3, :], axis=0)
        nt.assert_array_almost_equal(dot,
                                     n.zeros(dot.shape, dtype=n.float),
                                     decimal=3)

        #check 0 inc in xy
        nt.assert_array_almost_equal(x[2, :],
                                     n.zeros((res, ), dtype=n.float),
                                     decimal=3)
        nt.assert_array_almost_equal(x[5, :],
                                     n.zeros((res, ), dtype=n.float),
                                     decimal=3)
예제 #20
0
    def __init__(self,
                 a,
                 e,
                 i,
                 raan,
                 aop,
                 mu0,
                 d=0.01,
                 C_D=2.3,
                 A=1.0,
                 m=1.0,
                 mjd0=57125.7729,
                 oid=42,
                 M_cent=M_e,
                 C_R=1.0,
                 propagator=default_propagator,
                 propagator_options={},
                 **kwargs):

        self.kwargs = kwargs

        self.M_cent = M_cent

        orb = n.array(
            [a * 1e3, e, i, aop, raan,
             dpt.mean2true(mu0, e, radians=False)],
            dtype=n.float)
        state_c = dpt.kep2cart(orb, m=m, M_cent=self.M_cent,
                               radians=False) * 1e-3

        x = state_c[0]
        y = state_c[1]
        z = state_c[2]
        vx = state_c[3]
        vy = state_c[4]
        vz = state_c[5]

        self.state_cart = state_c * 1e3

        self.a = a
        self.e = e
        self.i = i
        self.oid = oid
        self.raan = raan
        self.aop = aop
        self.mu0 = mu0

        self.x = x
        self.y = y
        self.z = z
        self.vx = vx
        self.vy = vy
        self.vz = vz

        self.C_D = C_D
        self.C_R = C_R
        self.A = A
        self.m = m
        self.mjd0 = mjd0
        self._propagator = propagator
        self.propagator_options = propagator_options
        self.prop = propagator(**propagator_options)
        self.d = d
예제 #21
0
    def update(self, **kwargs):
        '''Updates the orbital elements and Cartesian state vector of the space object.

        Can update any of the related state parameters, all others will automatically update.

        Cannot update Keplerian and Cartesian elements simultaneously.

        :param float a: Semi-major axis in km
        :param float e: Eccentricity
        :param float i: Inclination in degrees
        :param float aop: Argument of perigee in degrees
        :param float raan: Right ascension of the ascending node in degrees
        :param float mu0: Mean anomaly in degrees
        :param float x: X position in km
        :param float y: Y position in km
        :param float z: Z position in km
        :param float vx: X-direction velocity in km/s
        :param float vy: Y-direction velocity in km/s
        :param float vz: Z-direction velocity in km/s
        '''

        kep = ['a', 'e', 'i', 'raan', 'aop', 'mu0']
        cart = ['x', 'y', 'z', 'vx', 'vy', 'vz']

        kep_orb = False
        cart_orb = False

        for key, val in kwargs.items():
            if key in kep:
                kep_orb = True
                setattr(self, key, val)

            elif key in cart:
                cart_orb = True
                setattr(self, key, val)

            else:
                raise TypeError('{} variable cannot be updated'.format(key))

        if kep_orb and cart_orb:
            raise TypeError(
                'Cannot update both Cartesian and Kepler elements at the same time'
            )

        if kep_orb:
            orb = n.array([
                self.a * 1e3, self.e, self.i, self.aop, self.raan,
                dpt.mean2true(self.mu0, self.e, radians=False)
            ],
                          dtype=n.float)
            state_c = dpt.kep2cart(
                orb, m=n.array([self.m
                                ]), M_cent=self.M_cent, radians=False) * 1e-3

        if cart_orb:
            state = n.array(
                [self.x, self.y, self.z, self.vx, self.vy, self.vz],
                dtype=n.float) * 1e3
            self.state_cart = state
            orb_c = dpt.cart2kep(state,
                                 m=self.m,
                                 M_cent=self.M_cent,
                                 radians=False)

        if kep_orb:
            self.x = state_c[0]
            self.y = state_c[1]
            self.z = state_c[2]
            self.vx = state_c[3]
            self.vy = state_c[4]
            self.vz = state_c[5]
            self.state_cart = state_c * 1e3

        if cart_orb:
            self.a = orb_c[0] * 1e-3
            self.e = orb_c[1]
            self.i = orb_c[2]
            self.raan = orb_c[4]
            self.aop = orb_c[3]
            self.mu0 = dpt.true2mean(orb_c[5], orb_c[1], radians=False)
예제 #22
0
                      mu0=dpt.true2mean(o[5], o[1], radians=False),
                      C_D=2.3,
                      A=1.0,
                      m=1.0,
                      diam=0.1)

#ecef needs earth rotation as a function of time
from keplerian_sgp4 import gmst
theta = gmst(obj.mjd0)
eart_rot = dpt.rot_mat_z(-theta)

x = obj.get_state(0.0)

M_e = 5.972e24

x_dpt = dpt.kep2cart(o, m=n.array([1.0]), M_cent=M_e, radians=False)
o_dpt = dpt.cart2kep(x, m=n.array([1.0]), M_cent=M_e, radians=False)

x_dpt[:3] = eart_rot.dot(x_dpt[:3])
x_dpt[3:] = eart_rot.dot(x_dpt[3:])

print('Initial Kepler:', o)
print('Initial Cart as from propagator:', x)
print('Converted Kepler:', o_dpt)
print('Converted Cart:', x_dpt)

#n.testing.assert_almost_equal(x/au,x_dpt/au, decimal=4)
#n.testing.assert_almost_equal(o,o_dpt, decimal=2)

nu = n.mod(n.linspace(0.0, 360.0, num=100) + 90.0, 360.0)
'''
cols = []
orbs_fail = []
fail_inds = []
fail_err = []
fail_errv = []

prop = PropagatorOrekit(
    in_frame='EME',
    out_frame='EME',
)

for ind, kep in enumerate(orb_init_list):

    t = np.array([0.0])

    state_ref = dpt.kep2cart(kep, m=1.0, M_cent=prop.M_earth, radians=False)
    '''
    state = prop.get_orbit(
            t=t, mjd0=mjd0,
            a=kep[0], e=kep[1], inc=kep[2],
            raan=kep[4], aop=kep[3], mu0=dpt.true2mean(kep[5], kep[1], radians=False),
            C_D=2.3, m=1.0, A=1.0, C_R=1.0,
            radians=False,
        )
    '''
    state = prop.get_orbit_cart(
        t=t,
        mjd0=mjd0,
        x=state_ref[0],
        y=state_ref[1],
        z=state_ref[2],
예제 #24
0
def run_moid():

    prop = ReboundMOID(time_step=dt)

    init_orb = np.array([0.95 * AU / (1.0 - 0.6), 0.6, 78, 180.0, 0.0, 180.0])
    init_cart = dpt.kep2cart(init_orb, m=0.0, M_cent=dpt.M_sol, radians=False)

    fw = init_cart[3:] / np.linalg.norm(init_cart[3:])
    side = init_cart[:3] / np.linalg.norm(init_cart[:3])

    def model(v, theta):

        cart = init_cart.copy()

        pert_dir = np.cos(np.radians(theta)) * fw + np.cos(
            np.radians(theta)) * side
        pert = pert_dir * v

        cart[3:] = cart[3:] + pert
        return cart

    init_p = 5

    prop.states = np.empty((6, init_p), dtype=np.float64)

    model_state = np.array([
        [0.0, 0.0],
        [100.0, 0.0],
        [0.0, 90.0],
        [0.0, 180.0],
        [100.0, 180.0],
    ]).T

    for p in range(init_p):
        prop.states[:, p] = model(*model_state[:, p].tolist())

    prop.t0 = 0.0

    if plot:
        global lin
        global dst
        for ind in range(steps):
            lin += ax.plot([], [], [], '-k', alpha=0.01)
        for ind in range(prop.num):
            dst += ax.plot([], [], [], '-r', alpha=0.7)

    step = np.array([[1.0, 0.1]], np.float64) * 10
    step = np.repeat(step.T, prop.num, axis=1)

    t = np.arange(0, t_end * _year, dt, dtype=np.float64)

    chain = np.zeros((steps, params, prop.num), dtype=np.float64)
    chain_prop = np.zeros((steps, 6, prop.num), dtype=np.float64)
    out_results = [[None] * prop.num for ind in range(steps)]
    accept = np.zeros((prop.num, 6), dtype=np.float64)
    tries = np.zeros((prop.num, 6), dtype=np.float64)

    logpost = np.zeros((prop.num, ), dtype=np.float64)
    logpost_try = np.zeros((prop.num, ), dtype=np.float64)

    results = prop.propagate(t)
    for p in range(prop.num):
        logpost[p] = -results[p]['MOID']

    for ind in tqdm(range(steps)):

        x_current = np.copy(model_state)
        prop_current = np.copy(prop.states)

        for p in range(prop.num):
            pi = int(np.floor(np.random.rand(1) * params))

            model_state[pi, p] += np.random.randn(1) * step[pi, p]

            prop.states[:, p] = model(*model_state[:, p].tolist())

        save_state = prop.states.copy()
        save_model_state = model_state.copy()
        results = prop.propagate(t, plot=True)

        for p in range(prop.num):
            logpost_try[p] = -results[p]['MOID']

            alpha = np.log(np.random.rand(1))

            if logpost_try[p] > logpost[p]:
                _accept = True
            elif (logpost_try[p] - alpha) > logpost[p]:
                _accept = True
            else:
                _accept = False

            tries[p, pi] += 1.0

            if _accept:
                logpost[p] = logpost_try[p]
                accept[p, pi] += 1.0
            else:
                model_state[:, p] = x_current[:, p]
                prop.states[:, p] = prop_current[:, p]

            #print('log post {:<5.2e} AU'.format(logpost_try[p]/AU))

            if ind % 100 == 0 and ind > 0:
                for dim in range(params):
                    ratio = accept[p, dim] / tries[p, dim]

                    #print('ratio {:<5.2f}'.format(ratio))
                    if ratio > 0.5:
                        step[dim, p] *= 2.0
                    elif ratio < 0.3:
                        step[dim, p] /= 2.0

                    accept[p, dim] = 0.0
                    tries[p, dim] = 0.0

            chain[ind, :, :] = save_model_state
            chain_prop[ind, :, :] = save_state
            out_results[ind][p] = results[p]

    with open(fname, 'wb') as hf:
        pickle.dump([out_results, chain, chain_prop], hf)
import numpy as n

from keplerian_sgp4 import sgp4_propagator as sgp_p
import dpt_tools as dpt

init_data = {
    'a': 7000,
    'e': 0.0,
    'inc': 90.0,
    'raan': 10,
    'aop': 10,
    'mu0': 40.0,
    'mjd0': 2457126.2729,
    'C_D': 2.3,
    'm': 8000,
    'A': 1.0,
}

self.t0 = n.array([0.0], dtype=n.float)

p = sgp_p()

ecefs = p.get_orbit(self.t, **self.init_data)
o = n.array(
    [7000e3, 0.0, 90.0, 10.0, 10.0,
     dpt.mean2true(40.0, 0.0, radians=False)])

x = dpt.kep2cart(o, m=init_data['m'], M_cent=5.98e24, radians=False)

print(x)
print(ecefs)
예제 #26
0
    def test_PropagatorSGP4_cart_kep_cases(self):

        R_E = 6353.0e3
        mjd0 = dpt.jd_to_mjd(2457126.2729)
        a = R_E*2.0
        orb_init_list = []

        orb_range = np.array([a, 0.9, 180, 360, 360, 360], dtype=np.float)
        orb_offset = np.array([R_E*1.1, 0, 0.0, 0.0, 0.0, 0.0], dtype=np.float)
        test_n = 100
        while len(orb_init_list) < test_n:
            orb = np.random.rand(6)
            orb = orb_offset + orb*orb_range
            if orb[0]*(1.0 - orb[1]) > R_E+200e3:
                orb_init_list.append(orb)

        orb_init_list.append(np.array([R_E*1.2, 0, 0.0, 0.0, 0.0, 0.0], dtype=np.float))
        orb_init_list.append(np.array([R_E*1.2, 0, 0.0, 0.0, 0.0, 270], dtype=np.float))
        orb_init_list.append(np.array([R_E*1.2, 1e-9, 0.0, 0.0, 0.0, 0.0], dtype=np.float))
        orb_init_list.append(np.array([R_E*1.2, 0.1, 0.0, 0.0, 0.0, 0.0], dtype=np.float))
        orb_init_list.append(np.array([R_E*1.2, 0.1, 75.0, 0.0, 0.0, 0.0], dtype=np.float))
        orb_init_list.append(np.array([R_E*1.2, 0.1, 0.0, 120.0, 0.0, 0.0], dtype=np.float))
        orb_init_list.append(np.array([R_E*1.2, 0.1, 0.0, 0.0, 35.0, 0.0], dtype=np.float))
        orb_init_list.append(np.array([R_E*1.2, 0.1, 75.0, 120.0, 0.0, 0.0], dtype=np.float))
        orb_init_list.append(np.array([R_E*1.2, 0.1, 75.0, 0.0, 35.0, 0.0], dtype=np.float))
        orb_init_list.append(np.array([R_E*1.2, 0.1, 75.0, 120.0, 35.0, 0.0], dtype=np.float))

        prop = propagator_sgp4.PropagatorSGP4(polar_motion=False)

        t = np.linspace(0, 12*3600, num=100, dtype=np.float)
        M_earth = propagator_sgp4.SGP4.GM*1e9/consts.G
        
        for kep in orb_init_list:
            state_TEME = dpt.kep2cart(kep, m=self.m, M_cent=M_earth, radians=False)

            ecefs_kep = prop.get_orbit(
                t=t, mjd0=mjd0,
                a=kep[0], e=kep[1], inc=kep[2],
                raan=kep[4], aop=kep[3], mu0=dpt.true2mean(kep[5], kep[1], radians=False),
                C_D=self.C_D, m=self.m, A=self.A,
                radians=False,
            )
            ecefs_cart = prop.get_orbit_cart(
                t=t, mjd0=mjd0,
                x=state_TEME[0], y=state_TEME[1], z=state_TEME[2],
                vx=state_TEME[3], vy=state_TEME[4], vz=state_TEME[5],
                C_D=self.C_D, m=self.m, A=self.A,
            )

            p = ecefs_kep[:3,:]*1e-3
            v = ecefs_kep[3:,:]*1e-3
            kep_TEME = propagator_sgp4.ecef2teme(t, p, v, mjd0=mjd0)*1e3

            p = ecefs_kep[:3,:]*1e-3
            v = ecefs_kep[3:,:]*1e-3
            cart_TEME = propagator_sgp4.ecef2teme(t, p, v, mjd0=mjd0)*1e3

            state_diff1 = np.abs(kep_TEME - cart_TEME)

            nt.assert_array_less(state_diff1[:3,:], np.full((3,t.size), 1e-5, dtype=state_diff1.dtype))
            nt.assert_array_less(state_diff1[3:,:], np.full((3,t.size), 1e-7, dtype=state_diff1.dtype))
예제 #27
0
def tryTest1():
    init_data = {
        'a': 7500e3,
        'e': 0,
        'inc': 90.0,
        'raan': 10,
        'aop': 10,
        'mu0': 40.0,
        'mjd0': 57125.7729,
        'C_D': 2.3,
        'C_R': 1.0,
        'm': 8000,
        'A': 1.0,
    }

    mjd0 = dpt.jd_to_mjd(2457126.2729)

    orb_init_list = _gen_orbits(100)

    prop = PropagatorOrekit(
        in_frame='EME',
        out_frame='EME',
    )

    t = np.linspace(0, 12 * 3600, num=100, dtype=np.float)

    for kep in orb_init_list:
        state_ref = dpt.kep2cart(kep,
                                 m=init_data['m'],
                                 M_cent=prop.M_earth,
                                 radians=False)

        state_kep = prop.get_orbit(
            t=t,
            mjd0=mjd0,
            a=kep[0],
            e=kep[1],
            inc=kep[2],
            raan=kep[4],
            aop=kep[3],
            mu0=dpt.true2mean(kep[5], kep[1], radians=False),
            C_D=init_data['C_D'],
            m=init_data['m'],
            A=init_data['A'],
            C_R=init_data['C_R'],
            radians=False,
        )
        state_cart = prop.get_orbit_cart(
            t=t,
            mjd0=mjd0,
            x=state_ref[0],
            y=state_ref[1],
            z=state_ref[2],
            vx=state_ref[3],
            vy=state_ref[4],
            vz=state_ref[5],
            C_D=init_data['C_D'],
            m=init_data['m'],
            A=init_data['A'],
            C_R=init_data['C_R'],
        )

        state_diff1 = np.abs(state_kep - state_cart)

        try:
            nt.assert_array_less(
                state_diff1[:3, :],
                np.full((3, t.size), 1e-5, dtype=state_diff1.dtype))
            nt.assert_array_less(
                state_diff1[3:, :],
                np.full((3, t.size), 1e-7, dtype=state_diff1.dtype))

        except:

            fig = plt.figure(figsize=(15, 15))
            ax = fig.add_subplot(211)
            ax.plot(t / 3600.0,
                    np.sqrt(np.sum(state_diff1[:3, :], axis=0)) * 1e-3)
            ax.set_xlabel('Time [h]')
            ax.set_ylabel('Position difference [km]')
            ax.set_title(
                'Propagation difference diameter simple vs advanced models')
            ax = fig.add_subplot(212)
            ax.plot(t / 3600.0,
                    np.sqrt(np.sum(state_diff1[3:, :], axis=0)) * 1e-3)
            ax.set_xlabel('Time [h]')

            fig = plt.figure(figsize=(15, 15))
            ax = fig.add_subplot(111, projection='3d')
            plothelp.draw_earth_grid(ax)
            ax.plot(state_kep[0, :],
                    state_kep[1, :],
                    state_kep[2, :],
                    "-",
                    alpha=0.5,
                    color="green",
                    label='KEP input')
            ax.plot(state_cart[0, :],
                    state_cart[1, :],
                    state_cart[2, :],
                    "-",
                    alpha=0.5,
                    color="red",
                    label='CART input')
            plt.legend()

            plt.show()
예제 #28
0
    def test_cart_kep_inverse(self):
        a = n.linspace(self.a, self.a + self.R_e, num=5, dtype=n.float64)
        e = n.linspace(0.0, 0.99, num=10, dtype=n.float64)
        inc = n.linspace(0.0, n.pi, num=10, dtype=n.float64)
        omega = n.linspace(0.0, 2.0 * n.pi, num=10, dtype=n.float64)
        Omega = omega.copy()
        nu = omega.copy()
        av, ev, incv, omegav, Omegav, nuv = n.meshgrid(a, e, inc, omega, Omega,
                                                       nu)

        ait = n.nditer(av)
        eit = n.nditer(ev)
        incit = n.nditer(incv)
        omegait = n.nditer(omegav)
        Omegait = n.nditer(Omegav)
        nuit = n.nditer(nuv)

        o = n.empty((6, av.size), dtype=n.float64)
        for ind in range(av.size):
            o[0, ind] = next(ait)
            o[1, ind] = next(eit)
            o[2, ind] = next(incit)
            o[3, ind] = next(omegait)
            o[4, ind] = next(Omegait)
            o[5, ind] = next(nuit)

        x = dpt.kep2cart(o, m=self.m, M_cent=self.M_e, radians=False)
        o_calc = dpt.cart2kep(x, m=self.m, M_cent=self.M_e, radians=False)
        x_calc = dpt.kep2cart(o_calc, m=self.m, M_cent=self.M_e, radians=False)

        for ind in range(av.size):
            try:
                nt.assert_array_almost_equal(x[:3, ind] / o[0, ind],
                                             x_calc[:3, ind] / o[0, ind],
                                             decimal=6)
                nt.assert_array_almost_equal(x[3:, ind] / o[0, ind],
                                             x_calc[3:, ind] / o[0, ind],
                                             decimal=6)
            except AssertionError:
                print(ind)
                print(x[:3, ind] - x_calc[:3, ind])
                print(o[:, ind])
                print(o_calc[:, ind])
                print(o_calc[:, ind] - o[:, ind])
                raise

        x = dpt.kep2cart(o, m=self.m, M_cent=self.M_e, radians=False)
        o_calc = dpt.cart2kep(x, m=self.m, M_cent=self.M_e, radians=False)

        o[3, o[1, :] < 1e-3] *= 0.0
        o[4, o[2, :] < 180e-3] *= 0.0

        for ind in range(av.size):
            test = n.isclose(o_calc[0, ind] / self.R_e,
                             o[0, ind] / self.R_e,
                             atol=1e-3)
            test = n.logical_and(
                test, n.isclose(o_calc[1, ind], o[1, ind], atol=1e-4))
            test_ang = n.logical_or(
                n.isclose(o_calc[2:, ind], o[2:, ind], atol=1e-7),
                n.isclose(n.mod(o_calc[2:, ind] + 180.0, 360.0),
                          n.mod(o[2:, ind] + 180.0, 360.0),
                          atol=1e-7),
            )
            test = n.logical_and(test, test_ang)
            if not n.all(test):
                print(ind)
                print(o[:, ind])
                print(o_calc[:, ind])
                print(o_calc[:, ind] - o[:, ind])
            assert n.all(test)
예제 #29
0
    def test_PropagatorSGP4_cart_kep_inverse_cases(self):

        R_E = 6353.0e3
        mjd0 = dpt.jd_to_mjd(2457126.2729)
        a = R_E*2.0
        orb_init_list = []

        orb_range = np.array([a, 0.9, 180, 360, 360, 360], dtype=np.float)
        orb_offset = np.array([R_E*1.1, 0, 0.0, 0.0, 0.0, 0.0], dtype=np.float)
        test_n = 5000
        while len(orb_init_list) < test_n:
            orb = np.random.rand(6)
            orb = orb_offset + orb*orb_range
            if orb[0]*(1.0 - orb[1]) > R_E+200e3:
                orb_init_list.append(orb)

        orb_init_list.append(np.array([R_E*1.2, 0, 0.0, 0.0, 0.0, 0.0], dtype=np.float))
        orb_init_list.append(np.array([R_E*1.2, 0, 0.0, 0.0, 0.0, 270], dtype=np.float))
        orb_init_list.append(np.array([R_E*1.2, 1e-9, 0.0, 0.0, 0.0, 0.0], dtype=np.float))
        orb_init_list.append(np.array([R_E*1.2, 0.1, 0.0, 0.0, 0.0, 0.0], dtype=np.float))
        orb_init_list.append(np.array([R_E*1.2, 0.1, 75.0, 0.0, 0.0, 0.0], dtype=np.float))
        orb_init_list.append(np.array([R_E*1.2, 0.1, 0.0, 120.0, 0.0, 0.0], dtype=np.float))
        orb_init_list.append(np.array([R_E*1.2, 0.1, 0.0, 0.0, 35.0, 0.0], dtype=np.float))
        orb_init_list.append(np.array([R_E*1.2, 0.1, 75.0, 120.0, 0.0, 0.0], dtype=np.float))
        orb_init_list.append(np.array([R_E*1.2, 0.1, 75.0, 0.0, 35.0, 0.0], dtype=np.float))
        orb_init_list.append(np.array([R_E*1.2, 0.1, 75.0, 120.0, 35.0, 0.0], dtype=np.float))

        prop = propagator_sgp4.PropagatorSGP4(polar_motion=False)

        t = np.array([0], dtype=np.float)
        M_earth = propagator_sgp4.SGP4.GM*1e9/consts.G

        fail_inds = []
        errs = np.empty((len(orb_init_list),2), dtype=np.float)
        for ind, kep in enumerate(orb_init_list):

            state_TEME = dpt.kep2cart(kep, m=self.m, M_cent=M_earth, radians=False)

            ecefs_kep = self.prop.get_orbit(
                t=t, mjd0=mjd0,
                a=kep[0], e=kep[1], inc=kep[2],
                raan=kep[4], aop=kep[3], mu0=dpt.true2mean(kep[5],kep[1],radians=False),
                C_D=self.C_D, m=self.m, A=self.A,
            )
            p = ecefs_kep[:3]*1e-3
            p.shape=(3,1)
            v = ecefs_kep[3:]*1e-3
            v.shape=(3,1)
            kep_TEME = propagator_sgp4.ecef2teme(np.array([0.0]), p, v, mjd0=mjd0)*1e3
            kep_TEME.shape = (6,)

            ecefs_cart = self.prop.get_orbit_cart(
                t=t, mjd0=mjd0,
                x=kep_TEME[0], y=kep_TEME[1], z=kep_TEME[2], 
                vx=kep_TEME[3], vy=kep_TEME[4], vz=kep_TEME[5], 
                C_D=self.C_D, m=self.m, A=self.A,
            )
            p = ecefs_cart[:3]*1e-3
            p.shape=(3,1)
            v = ecefs_cart[3:]*1e-3
            v.shape=(3,1)
            cart_TEME = propagator_sgp4.ecef2teme(np.array([0.0]), p, v, mjd0=mjd0)*1e3
            cart_TEME.shape = (6,)

            state_diff1 = np.abs(kep_TEME - state_TEME)
            try:
                nt.assert_array_less(state_diff1[:3], np.full((3,), 1e-2, dtype=state_diff1.dtype))
                nt.assert_array_less(state_diff1[3:], np.full((3,), 1e-5, dtype=state_diff1.dtype))
            except AssertionError as err:
                if ind not in fail_inds:
                    fail_inds.append(ind)

            state_diff2 = np.abs(cart_TEME - state_TEME)

            try:
                nt.assert_array_less(state_diff2[:3], np.full((3,), 1e-2, dtype=state_diff2.dtype))
                nt.assert_array_less(state_diff2[3:], np.full((3,), 1e-5, dtype=state_diff2.dtype))
            except AssertionError as err:
                if ind not in fail_inds:
                    fail_inds.append(ind)

            state_diff = np.abs(cart_TEME - kep_TEME)

            try:
                nt.assert_array_less(state_diff[:3], np.full((3,), 1e-2, dtype=state_diff.dtype))
                nt.assert_array_less(state_diff[3:], np.full((3,), 1e-5, dtype=state_diff.dtype))
            except AssertionError as err:
                if ind not in fail_inds:
                    fail_inds.append(ind)

            er_r = np.linalg.norm(state_diff1[:3])
            er_v = np.linalg.norm(state_diff1[3:])
            errs[ind,0] = er_r
            errs[ind,1] = er_v

        if len(fail_inds) > 0:
            print('FAIL / TOTAL: {} / {}'.format(len(fail_inds), len(orb_init_list)))

        assert np.median(errs[:,0]) < 1e-2
        assert np.median(errs[:,1]) < 1e-4

        assert len(fail_inds) < float(test_n)/100.
예제 #30
0
#orb_init_list.append(np.array([a, 0.2, 75.0, 0.0, 35.0, 0.0], dtype=np.float))
#orb_init_list.append(np.array([a, 0.2, 75.0, 120.0, 35.0, 0.0], dtype=np.float))

orbs_pass = []
orbs = []
mean_orbs = []
cols = []
orbs_fail = []
fail_inds = []
fail_err = []
fail_errv = []
for ind, kep in enumerate(orb_init_list):
    #print('{}/{} done'.format(ind, len(orb_init_list)))
    M_earth = propagator_sgp4.SGP4.GM * 1e9 / consts.G

    state_TEME = dpt.kep2cart(kep, m=0.0, M_cent=M_earth, radians=False) * 1e-3

    mean_elements = tle.TEME_to_TLE(state_TEME, mjd0=mjd0, kepler=False)
    mlst = mean_elements.tolist()
    mlst[0] *= 1e3
    mlst[4] = mean_elements[3]
    mlst[3] = mean_elements[4]
    mlst[5] = dpt.mean2true(mean_elements[5], mean_elements[1], radians=True)
    mean_orbs.append(mlst)
    state = propagator_sgp4.sgp4_propagation(mjd0, mean_elements, B=0, dt=0.0)

    state_diff = np.abs(state - state_TEME) * 1e3

    try:
        nt.assert_array_less(state_diff[:3],
                             np.full((3, ), 100, dtype=state_diff.dtype))