Example #1
0
def true_anomaly(t, P, e):
    """
    Calculate the true annomoly for a given time, period, eccentricity.

    :param t: time (BJD_TDB)
    :type t: float

    :param P: period [days]
    :type P: float

    :param e: eccentricity
    :type e: float


    :return: True Annomoly
    
    """

    # f in Murray and Dermott p. 27
    tp = 0
    t = np.array([t])
    m = 2. * np.pi * (((t - tp) / P) - np.floor((t - tp) / P))
    e1 = kepler(m, np.array([e]))
    n1 = 1.0 + e
    n2 = 1.0 - e
    nu = 2.0 * np.arctan((n1 / n2)**0.5 * np.tan(e1 / 2.e0))
    if nu < 0:
        nu += 2 * np.pi
    return nu
Example #2
0
def kepel_statvec(kepel):

	np.set_printoptions(precision=4)

	EARTH_GRAVITY = 3.9860064e+14 #Earth's gravitational constant (m^3/s^2)

	a   = kepel[0] # Semi-major axis
	exc = kepel[1] # Eccentricity
	c1  = math.sqrt(1.0 - exc**2)

	# Rotation matrix
	orb2iner = (rotmaz(-kepel[3]).dot(rotmax(-kepel[2]))).dot(rotmaz(-kepel[4]))
	#print('orb2iner :\n{0}'.format(orb2iner))

	# Kepler's equation
	E = kepler(kepel[5], exc)

	sE = math.sin(E)
	cE = math.cos(E)
	c3 = (math.sqrt(EARTH_GRAVITY/a))/(1.0 - exc*cE)

	#print('sE : {0}'.format(sE))
	#print('cE : {0}'.format(cE))
	#print('c3 : {0:5E}'.format(c3))

	# State vector
	aux1 = np.array([ a*(cE - exc), a*c1*sE, 0])
	aux2 = np.array([-c3*sE, c1*c3*cE, 0])
	T1 = aux1.dot(orb2iner.T)
	T2 = aux2.dot(orb2iner.T)

	stat_vec = np.hstack((T1, T2))
	return stat_vec
Example #3
0
 def flow(self, delta_time, SaveFlow = False):
     if self.eom == 'keplerian':
         from kepler import kepler
         from auxiliary import E2f, E2M, coe2rv
         #  create a list of the necessary orbital parameters
         #+ for ephemeris() and order them in the default order
         ephemeris_list = [self.e, self.n, self.E]
         ephemeris_list = kepler(ephemeris_list, delta_time)
         #  update other relevant orbital parameters
         self.epoch += delta_time
         self.E = ephemeris_list[2]
         self.f = E2f(self.e, self.E)
         self.M = E2M(self.e, self.E)
         #  update coe list
         self.coe[5] = self.f
         #  update the r, v vectors
         self.r, self.v = coe2rv(self.coe, self.Mu)
     elif self.eom == 'P2B':
         from utilities import rv2ic
         from flow import P2B
         ic = rv2ic(self.r[0:2], self.v[0:2], self.Mu, STM = False)
         flow = P2B(ic, [0, delta_time])
         self.epoch += delta_time
         self.r[0:2] = flow['y'][-1][0:2]
         self.v[0:2] = flow['y'][-1][2:4]
     elif self.eom == 'P2B_varEqns':
         from utilities import rv2ic
         from flow import P2B
         ic = rv2ic(self.r[0:2], self.v[0:2], self.Mu, STM = True)
         flow = P2B(ic, [0, delta_time], eom = 'P2BP_varEqns')
         self.epoch += delta_time
         self.r[0:2] = flow['y'][-1][0:2]
         self.v[0:2] = flow['y'][-1][2:4]
         self.STM = flow['y'][-1][5:]
     elif self.eom == 'S2B':
         from utilities import rv2ic
         from flow import S2B
         ic = rv2ic(self.r, self.v, self.Mu, STM = False)
         flow = S2B(ic, [0, delta_time])
         self.epoch += delta_time
         self.r = flow['y'][-1][0:3]
         self.v = flow['y'][-1][3:6]
     elif self.eom == 'S2B_varEqns':
         from utilities import rv2ic
         from flow import S2B
         ic = rv2ic(self.r, self.v, self.Mu, STM = True)
         flow = S2B(ic, [0, delta_time], tstep = delta_time/1E3, \
                    eom = 'S2BP_varEqns')
         self.epoch += delta_time
         self.r = flow['y'][-1][0:3]
         self.v = flow['y'][-1][3:6]
         self.STM = flow['y'][-1][6:]
     #  save the r, v and t history when not using 'keplerian'
     if self.eom != 'keplerian':
         n = len(self.r)
         from utilities import extract_elements
         extract_elements(flow['y'], 0, n - 1, self.r_history)
         extract_elements(flow['y'], n, 2*n - 1, self.v_history)
         self.t_history = flow['x']
         if SaveFlow: self.theflow = flow
def orbital_to_inertial_matrix(kepel):

    np.set_printoptions(precision=4)

    exc = kepel[1]  # Eccentricity
    c1 = math.sqrt(1.0 - exc**2)

    # Rotation matrix from perigee to inertial
    orb2iner = (rotmaz(-kepel[3]).dot(rotmax(-kepel[2]))).dot(
        rotmaz(-kepel[4]))

    #print("exc : {0:.4}".format(exc))
    #print("c1  : {0:.4}".format(c1))
    #print("orb2iner : \n{0}".format(orb2iner))

    # Kepler's equation
    E = kepler(kepel[5], exc)  #Excentric anomaly
    sE = math.sin(E)
    cE = math.cos(E)
    r_ov_a = 1.0 - exc * cE
    cf = (cE - exc) / r_ov_a  # cosine of the true anomaly
    sf = c1 * sE / r_ov_a  # sine of the true anomaly

    #print("r_ov_a : {0}".format(r_ov_a))
    #print("cf : {0:.4}".format(cf))
    #print("sf  : {0:.4}".format(sf))

    rmx_i_o = np.array([[cf, sf, 0], [sf, cf, 0], [0, 0, 1]])

    rmx_i_o = orb2iner.dot(rmx_i_o)
    #print('rmx_i_o : {0}'.format(rmx_i_o))

    return rmx_i_o
Example #5
0
 def test_example_2_4_Keplers_Problem(self):
     r_ijk = np.matrix((1131.340, -2282.343, 6672.423)).T
     v_ijk = np.matrix((-5.64305, 4.30333, 2.42879)).T
     del_t = 40.0
     
     del_t_sec = del_t*60.0
     
     (actual_pos, actual_vel) = kepler.kepler(r_ijk, v_ijk, del_t_sec)
     expected_pos = np.matrix((-4219.7527, 4363.0292, -3958.7666)).T
     expected_vel = np.matrix((3.689866, -1.916735, -6.112511)).T
     self.assertAlmostEqual(actual_pos.item(0), expected_pos.item(0), places=3)
     self.assertAlmostEqual(actual_pos.item(1), expected_pos.item(1), places=3)
     self.assertAlmostEqual(actual_pos.item(2), expected_pos.item(2), places=3)
     self.assertAlmostEqual(actual_vel.item(0), expected_vel.item(0), places=5)
     self.assertAlmostEqual(actual_vel.item(1), expected_vel.item(1), places=5)
     self.assertAlmostEqual(actual_vel.item(2), expected_vel.item(2), places=5)
Example #6
0
    def locate_body_spice(self,JD, mu, AU):

        try:
            import spiceypy as spice
        except:
            print("PySpice not available")
            
        try:
            state,time = spice.spkez(self.SPICEID,(JD-2400000.5-51544.5)*86400.0,"eclipJ2000","NONE",10)
            r = state[0:3]
            v = state[3:6]
        except:
            print(sys.exc_info()[0])
            #call Ryne's Kepler solver
            r, v = kepler(self.SMA * AU, self.ECC, self.INC, self.RAAN, self.AOP, self.MA, self.ReferenceEpoch, JD, mu)

        return r, v
Example #7
0
    def compute_fiducial_model(
        self,
        times: np.ndarray,
        *,
        semiamp: np.ndarray,
        period: np.ndarray,
        phase: np.ndarray,
        ecc: Optional[np.ndarray] = None,
        omega: Optional[np.ndarray] = None,
    ) -> np.ndarray:
        mean_anom = 2 * np.pi * times / period[None, :] + phase[None, :]

        if ecc is None:
            assert omega is None
            return semiamp * np.cos(mean_anom)

        assert omega is not None
        cosw = np.cos(omega)
        sinw = np.sin(omega)
        _, cosf, sinf = kepler.kepler(mean_anom,
                                      ecc[None, :] + np.zeros_like(mean_anom))
        return semiamp * (cosw[None, :] *
                          (ecc[None, :] + cosf) - sinw[None, :] * sinf)
Example #8
0
 def locate_body(self, JD, mu, AU):
     #call Ryne's Kepler solver
     r, v = kepler(self.SMA * AU, self.ECC, self.INC, self.RAAN, self.AOP, self.MA, self.ReferenceEpoch, JD, mu)
    
     return r, v
Example #9
0
 def locate_body(self, JD, mu, AU):
     #call Ryne's Kepler solver
     r, v = kepler(self.SMA * AU, self.ECC, self.INC, self.RAAN, self.AOP, self.MA, self.ReferenceEpoch, JD, mu)
     return r, v