Beispiel #1
0
def solution(infile='./data/RV2.txt', outfile='./data/RV2_solution.txt'):
    """Generate the solution that students should be able to match

    """
    mu = constants.earth.mu

    output_string = ''
    with open(infile, 'r') as f:
        line = f.readline().split()
        while line:
            r_in = np.array([float(i) for i in line[0:3]])
            v_in = np.array([float(i) for i in line[3:6]])
            dt = float(line[6])

            # convert to coe
            p, a, ecc, inc, raan, arg_p, nu, _, _, _, _ = kepler.rv2coe(
                r_in, v_in, mu)

            # propagate forward
            E_f, M_f, nu_f = kepler.tof_delta_t(p, ecc, mu, nu, dt)

            # compute elements at future time
            prop_string = kepler.orbit_el(p, ecc, inc, raan, arg_p, nu_f, mu)

            output_string += prop_string

            line = f.readline().split()

    with open(outfile, 'w') as f:
        f.write(output_string)
def example_one():
    re = constants.earth.radius
    r = np.array([1.6772 * re, -1.6772 * re,
                  2.3719 * re])  # position in ECI in kilometers
    v = np.array([3.1544, 2.4987, 0.4658])  # velocity in ECI in km/sec

    a, ecc, inc, raan, argp, nu = kepler.rv2coe(r, v)
Beispiel #3
0
class TestEllipticalOribtProperties():
    # test case from RV2COE Astro 321, MAE3145
    r = np.array([8840.0, 646, 5455])
    v = np.array([-0.695, 5.25, -1.65])

    r_mag_true = 10407.6866
    v_mag_true = 5.5469

    r_per_true = 6260.5311
    r_apo_true = 11134.4744
    energy_true = -22.9147
    period_true = 2.2423
    sma_true = 8697.5027
    ecc_true = 0.2802
    inc_true = 33.9987
    raan_true = 250.0287
    arg_p_true = 255.5372
    nu_true = 214.8548
    
    mu = constants.earth.mu

    p, a, ecc, inc, raan, arg_p, nu, _, _, _, _ = kepler.rv2coe(r, v, mu) 
    ( a, h, period, sme, fpa, r_per, r_apo, r_ijk, v_ijk,
     r_pqw, v_pqw, r_lvlh, v_lvlh, r, v, v_circ, v_esc,
     E, M, n ) = kepler.elp_orbit_el(p,ecc,inc,raan,arg_p,nu,mu)
    def test_r_mag(self):
        np.testing.assert_allclose(np.linalg.norm(self.r_ijk), self.r_mag_true, rtol=1e-4)

    def test_v_mag(self):
        np.testing.assert_allclose(np.linalg.norm(self.v_ijk), self.v_mag_true, rtol=1e-4)

    def test_r_per(self):
        np.testing.assert_allclose(self.r_per, self.r_per_true, rtol=1e-4)

    def test_r_apo(self):
        np.testing.assert_allclose(self.r_apo, self.r_apo_true, rtol=1e-4)

    def test_energy(self):
        np.testing.assert_allclose(self.sme, self.energy_true, rtol=1e-4)

    def test_period(self):
        np.testing.assert_allclose(self.period*constants.sec2hr, self.period_true, rtol=1e-4)

    def test_sma(self):
        np.testing.assert_allclose(self.a, self.sma_true, rtol=1e-4)

    def test_ecc(self):
        np.testing.assert_allclose(self.ecc, self.ecc_true, rtol=1e-4)

    def test_inc(self):
        np.testing.assert_allclose(self.inc*constants.rad2deg, self.inc_true, rtol=1e-4)

    def test_raan(self):
        np.testing.assert_allclose(self.raan*constants.rad2deg, self.raan_true, rtol=1e-4)

    def test_arg_p(self):
        np.testing.assert_allclose(self.arg_p*constants.rad2deg, self.arg_p_true, rtol=1e-4)
Beispiel #4
0
class Testrv2coeRV1():
    a_true = 8697.5027
    ecc_true = 0.2802
    p_true = a_true * ( 1 - ecc_true**2)
    inc_true = np.deg2rad(33.9987)
    raan_true = np.deg2rad(250.0287)
    arg_p_true = np.deg2rad(255.5372)
    nu_true = np.deg2rad(214.8548)
    mu = 398600.5

    r = np.array([8840, 646, 5455])
    v = np.array([-0.6950, 5.250, -1.65])

    p, a, ecc, inc, raan, arg_p, nu, m, arglat, truelon, lonper = kepler.rv2coe(r, v, mu)

    def test_p(self):
        np.testing.assert_allclose(self.p, self.p_true, rtol=1e-1)
    
    def test_a(self):
        np.testing.assert_allclose(self.a, self.p_true / (1 - self.ecc_true**2))

    def test_ecc(self):
        np.testing.assert_allclose(self.ecc, self.ecc_true, rtol=1e-4)
    
    def test_inc(self):
        np.testing.assert_allclose(self.inc, self.inc_true, rtol=1e-4)

    def test_raan(self):
        np.testing.assert_allclose(self.raan, self.raan_true)

    def test_arg_p(self):
        np.testing.assert_allclose(self.arg_p, self.arg_p_true, rtol=1e-4)
    
    def test_nu(self):
        np.testing.assert_allclose(self.nu, self.nu_true, rtol=1e-4)

    def test_m(self):
        E_true, M_true = kepler.nu2anom(self.nu, self.ecc)
        np.testing.assert_allclose(self.m, M_true)

    def test_arglat(self):
        # argument of latitude isn't used for this case so it goes to zero
        # np.testing.assert_allclose(self.arglat, self.nu_true + self.arg_p_true)
        pass

    def test_truelon(self):
        # not used for inclined orbits - only special ones
        # np.testing.assert_allclose(self.truelon, self.nu_true + self.raan_true + self.arg_p_true)
        pass

    def test_lonper(self):
        # not really used for inclined orbits
        # np.testing.assert_allclose(self.lonper, self.arg_p_true + self.raan_true)
        pass
Beispiel #5
0
def test_rv2coe_project_example_one():
    r = np.array([8840, 646, 5455])
    v = np.array([-0.695, 5.25, -1.65])

    a, ecc, inc, raan, argp, nu = kepler.rv2coe(r, v)

    # expected values
    a_exp = 8697.5027
    ecc_exp = 0.2802

    np.testing.assert_allclose(a, a_exp)
    np.testing.assert_allclose(ecc, ecc_exp, rtol=1e-4)
Beispiel #6
0
class Testrv2coeEquatorialCircularHalf():

    p_true = 6378.137 # km
    ecc_true = 0.0
    inc_true = 0.0
    raan_true = 0.0
    arg_p_true = 0.0
    nu_true = np.pi
    mu = 398600.5 # km^3 /sec^2

    R_ijk_true = np.array([-p_true, 0,0])
    V_ijk_true = np.sqrt(mu/p_true) * np.array([0,-1,0])
    
    p, a, ecc, inc, raan, arg_p, nu, m, arglat, truelon, lonper = kepler.rv2coe(R_ijk_true, V_ijk_true, mu)
    
    def test_p(self):
        np.testing.assert_allclose(self.p, self.p_true)
    
    def test_a(self):
        np.testing.assert_allclose(self.a, self.p_true / (1 - self.ecc_true**2))

    def test_ecc(self):
        np.testing.assert_allclose(self.ecc, self.ecc_true)
    
    def test_inc(self):
        np.testing.assert_allclose(self.inc, self.inc_true)

    def test_raan(self):
        np.testing.assert_allclose(self.raan, self.raan_true)

    def test_arg_p(self):
        np.testing.assert_allclose(self.arg_p, self.arg_p_true)
    
    def test_nu(self):
        np.testing.assert_allclose(self.nu, self.nu_true)

    def test_m(self):
        E_true, M_true = kepler.nu2anom(self.nu, self.ecc)
        np.testing.assert_allclose(self.m, M_true)

    def test_arglat(self):
        # argument of latitude isn't used for this case so it goes to zero
        # np.testing.assert_allclose(self.arglat, self.nu_true + self.arg_p_true)
        pass

    def test_truelon(self):
        np.testing.assert_allclose(self.truelon, self.nu_true + self.raan_true + self.arg_p_true)

    def test_lonper(self):
        np.testing.assert_allclose(self.lonper, self.arg_p_true + self.raan_true)
Beispiel #7
0
class Testrv2coePolarCircular():

    p_true = 6378.137 # km
    ecc_true = 0.0
    inc_true = np.pi / 2
    raan_true = 0.0
    arg_p_true = 0.0
    nu_true = 0.0
    mu = 398600.5 # km^3 /sec^2

    R_ijk_true = np.array([6378.137,0,0])
    V_ijk_true = np.sqrt(mu/p_true) * np.array([0,0,1])
    
    p, a, ecc, inc, raan, arg_p, nu, m, arglat, truelon, lonper = kepler.rv2coe(R_ijk_true, V_ijk_true, mu)
    
    def test_p(self):
        np.testing.assert_allclose(self.p, self.p_true)
    
    def test_a(self):
        np.testing.assert_allclose(self.a, self.p_true / (1 - self.ecc_true**2))

    def test_ecc(self):
        np.testing.assert_allclose(self.ecc, self.ecc_true)
    
    def test_inc(self):
        np.testing.assert_allclose(self.inc, self.inc_true)

    def test_raan(self):
        np.testing.assert_allclose(self.raan, self.raan_true)

    def test_arg_p(self):
        np.testing.assert_allclose(self.arg_p, self.arg_p_true)
    
    def test_nu(self):
        np.testing.assert_allclose(self.nu, self.nu_true)

    def test_m(self):
        E_true, M_true = kepler.nu2anom(self.nu, self.ecc)
        np.testing.assert_allclose(self.m, M_true)

    def test_arglat(self):
        np.testing.assert_allclose(self.arglat, self.nu_true + self.arg_p_true)

    def test_truelon(self):
        np.testing.assert_allclose(self.truelon, self.nu_true + self.raan_true + self.arg_p_true)

    def test_lonper(self):
        np.testing.assert_allclose(self.lonper, self.arg_p_true + self.raan_true)
Beispiel #8
0
class Testrv2coeCurtis():
    """Using example 4.7 from Curtis
    """
    p_true = 80000**2/398600
    ecc_true = 1.4
    inc_true = np.deg2rad(30)
    raan_true = np.deg2rad(40)
    arg_p_true = np.deg2rad(60)
    nu_true = np.deg2rad(30)
    mu = 398600 # km^3 /sec^2

    R_ijk_true = np.array([-4040, 4815, 3629])
    V_ijk_true = np.array([-10.39, -4.772, 1.744]) 
    
    p, a, ecc, inc, raan, arg_p, nu, m, _, _, _= kepler.rv2coe(R_ijk_true, V_ijk_true, mu)
    
    rtol = 1e-3

    def test_p(self):
        np.testing.assert_allclose(self.p, self.p_true, rtol=self.rtol)
    
    def test_a(self):
        np.testing.assert_allclose(np.absolute(self.a), self.p_true / (self.ecc_true**2 - 1), rtol=1e2)

    def test_ecc(self):
        np.testing.assert_allclose(self.ecc, self.ecc_true, rtol=1e-1)
    
    def test_inc(self):
        np.testing.assert_allclose(self.inc, self.inc_true, rtol=self.rtol)

    def test_raan(self):
        np.testing.assert_allclose(self.raan, self.raan_true, rtol=self.rtol)

    def test_arg_p(self):
        np.testing.assert_allclose(self.arg_p, self.arg_p_true, rtol=self.rtol)
    
    def test_nu(self):
        np.testing.assert_allclose(self.nu, self.nu_true, rtol=self.rtol)

    def test_m(self):
        E_true, M_true = kepler.nu2anom(self.nu, self.ecc)
        np.testing.assert_allclose(self.m, M_true, rtol=self.rtol)
Beispiel #9
0
class Testrv2coeVallado():

    p_true = 1.73527 * constants.earth.radius # km
    ecc_true = 0.83285
    inc_true = np.deg2rad(87.87)
    raan_true = np.deg2rad(227.89)
    arg_p_true = np.deg2rad(53.38)
    nu_true = np.deg2rad(92.335)
    mu = 398600.5 # km^3 /sec^2

    R_ijk_true = np.array([6524.834, 6862.875, 6448.296])
    V_ijk_true = np.array([4.901320, 5.533756, -1.976341]) 
    
    p, a, ecc, inc, raan, arg_p, nu, m, _, _, _= kepler.rv2coe(R_ijk_true, V_ijk_true, mu)
    
    rtol = 1e-3

    def test_p(self):
        np.testing.assert_allclose(self.p, self.p_true, rtol=self.rtol)
    
    def test_a(self):
        np.testing.assert_allclose(self.a, self.p_true / (1 - self.ecc_true**2), rtol=self.rtol)

    def test_ecc(self):
        np.testing.assert_allclose(self.ecc, self.ecc_true, rtol=self.rtol)
    
    def test_inc(self):
        np.testing.assert_allclose(self.inc, self.inc_true, rtol=self.rtol)

    def test_raan(self):
        np.testing.assert_allclose(self.raan, self.raan_true, rtol=self.rtol)

    def test_arg_p(self):
        np.testing.assert_allclose(self.arg_p, self.arg_p_true, rtol=self.rtol)
    
    def test_nu(self):
        np.testing.assert_allclose(self.nu, self.nu_true, rtol=self.rtol)

    def test_m(self):
        E_true, M_true = kepler.nu2anom(self.nu, self.ecc)
        np.testing.assert_allclose(self.m, M_true, rtol=self.rtol)
Beispiel #10
0
etTwo = spice.str2et('Sep 15, 2005')

times = np.linspace(etOne, etTwo, 5000)
state = np.zeros((len(times), 6))
for ii, et in enumerate(times):
    state[ii, :], _ = spice.spkezr('Cassini', et, 'J2000', 'None',
                                   'SATURN BARYCENTER')

initial_state = state[0, :]
# comppute position/velocity in the orbital plane
print('Cassini pos: {} km'.format(initial_state[0:3]))
print('Cassini vel: {} km/sec'.format(initial_state[3:6]))

# compute some orbital elements of the vehicle
mu = constants.saturn.mu
p, a, ecc, inc, raan, arg_p, nu, m, arglat, truelon, lonper = kepler.rv2coe(
    initial_state[0:3], initial_state[3:6], mu)
kepler.orbit_el(p, ecc, inc, raan, arg_p, nu, mu, print_flag=True)

# students should generate a plot of the orbit (conic equation)
pos_inertial, sat_inertial, pos_pqw, sat_pqw = kepler.conic_orbit(
    p, ecc, inc, raan, arg_p, nu, nu)
rsaturn = constants.saturn.radius
pqw_fig, pqw_ax = plt.subplots()
pqw_ax.plot(pos_pqw[:, 0] / rsaturn, pos_pqw[:, 1] / rsaturn)
pqw_ax.plot(sat_pqw[0] / rsaturn, sat_pqw[1] / rsaturn, 'bo', markersize=10)
pqw_ax.plot(0, 0, 'bo', markersize=20)
pqw_ax.set_xlabel(r'$\hat p (r_{\saturn})$')
pqw_ax.set_ylabel(r'$\hat q (r_{\saturn})$')
pqw_ax.set_title(r'Cassini Orbit in Perifocal Reference Frame')
pqw_ax.grid()
def example_two():
    r = np.array([6524.834, 6862.875,
                  6448.296])  # position in ECI in kilometers
    v = np.array([4.901327, 5.53376, -1.976341])  # velocity in ECI in km/sec

    kepler.rv2coe(r, v)
Beispiel #12
0
import numpy as np
from astro import kepler, constants

mu = constants.earth.mu
r = np.array([0, -26560, 0])
v = np.array([2.5, 0, 2.5])

p, a, ecc, inc, raan, arg_p, nu, m, arglat, truelon, lonper = kepler.rv2coe(
    r, v, mu)

string = kepler.orbit_el(p, ecc, inc, raan, arg_p, nu, mu, False)

print(string)
Beispiel #13
0
def solution(meas_file='./data/COMFIX_tle_measurement.txt',
             outfile='./data/COMFIX_tle_solution.txt'):
    # read in the measurement data
    fout = open(outfile, 'w')

    with open(meas_file, 'r') as f:
        l0 = f.readline().split()
        l0 = [float(x) for x in l0]
        while l0:
            l1 = f.readline().split()
            l1 = [float(x) for x in l1]
            latgd, lon, alt, jd = np.deg2rad(l0[0]), np.deg2rad(
                l0[1]), l0[2] / 1e3, l0[3]
            satnum, rho, az, el, drho, daz, dele = l1[0], l1[1], np.deg2rad(
                l1[2]), np.deg2rad(l1[3]), l1[4], np.deg2rad(
                    l1[5]), np.deg2rad(l1[6])

            # GST, LST
            gst, lst = time.gstlst(jd, lon)
            # find satellite vector in SEZ
            rho_sez, drho_sez = geodetic.rhoazel2sez(rho, az, el, drho, daz,
                                                     dele)
            R_eci2ecef = geodetic.eci2ecef(jd)
            R_ecef2eci = geodetic.ecef2eci(jd)
            R_sez2ecef = transform.dcm_sez2ecef(latgd, lon, alt)

            # find  site vector in ECEF/ECI
            site_ecef = geodetic.lla2ecef(latgd, lon, alt)
            site_eci = R_ecef2eci.dot(site_ecef)

            # transform satellite vector from SEZ to ECI
            rho_ecef = R_sez2ecef.dot(rho_sez)
            rho_eci = R_ecef2eci.dot(rho_ecef)

            drho_ecef = R_sez2ecef.dot(drho_sez)
            drho_eci = R_ecef2eci.dot(drho_ecef)

            pos_eci = site_eci + rho_eci
            vel_eci = drho_eci + np.cross(
                np.array([0, 0, constants.earth.omega]), pos_eci)
            # find orbital elements
            p, a, ecc, inc, raan, arg_p, nu, _, _, _, _ = kepler.rv2coe(
                pos_eci, vel_eci, constants.earth.mu)

            # compute orbit properties
            prop_string = kepler.orbit_el(p, ecc, inc, raan, arg_p, nu,
                                          constants.earth.mu)

            l0 = f.readline().split()
            l0 = [float(x) for x in l0]
            # output to text file
            fout.write(
                '#################### COMFIX SATELLITE {:g} ####################################\n\n'
                .format(satnum))
            fout.write(
                '------------------------ INPUT DATA -------------------------------------------\n\n'
            )
            fout.write('LAT (deg)    LON (deg)     ALT (m)       JD\n')
            fout.write(
                '{:<9.4f}    {:<9.4f}     {:<9.4f}      {:<16.6f}\n\n'.format(
                    np.rad2deg(latgd), np.rad2deg(lon), alt * 1e3, jd))
            fout.write(
                'RHO (km)     AZ (deg)    EL (deg)   DRHO (km/s)   DAZ (deg/s)   DEL (deg/s)\n'
            )
            fout.write(
                '{:<9.4f}     {:<6.4f}    {:<6.4f}     {:<6.4f}     {:<6.4f}        {:<6.4f}\n'
                .format(rho, np.rad2deg(az), np.rad2deg(el), drho,
                        np.rad2deg(daz), np.rad2deg(dele)))

            fout.write(
                '------------------------- WORKING DATA ----------------------------------------\n\n'
            )
            fout.write('LAT (rad)    LON (rad)     ALT (m)       JD\n')
            fout.write(
                '{:<9.4f}    {:<9.4f}     {:<9.4f}      {:<16.6f}\n\n'.format(
                    latgd, lon, alt, jd))
            fout.write(
                'RHO (km)     AZ (rad)    EL (rad)   DRHO (km/s)   DAZ (rad/s)   DEL (rad/s)\n'
            )
            fout.write(
                '{:<9.4f}     {:<6.4f}    {:<6.4f}     {:<6.4f}     {:<6.4f}        {:<6.4f}\n\n'
                .format(rho, az, el, drho, daz, dele))
            fout.write('GST  = {:16.9f} rad = {:16.9f} deg\n'.format(
                gst, np.rad2deg(gst)))
            fout.write('LST  = {:16.9f} rad = {:16.9f} deg\n\n'.format(
                lst, np.rad2deg(lst)))

            fout.write(
                '---------------------------- VECTORS ------------------------------------------\n'
            )
            fout.write(
                '{:9s} = {:13.4f} S {:13.4f} E {:13.4f} Z MAG = {:7.4f} km\n'.
                format('rho_sez', rho_sez[0], rho_sez[1], rho_sez[2],
                       np.linalg.norm(rho_sez)))
            fout.write(
                '{:9s} = {:13.4f} I {:13.4f} J {:13.4f} K MAG = {:7.4f} km\n'.
                format('rho_ecef', rho_ecef[0], rho_ecef[1], rho_ecef[2],
                       np.linalg.norm(rho_ecef)))
            fout.write(
                '{:9s} = {:13.4f} I {:13.4f} J {:13.4f} K MAG = {:7.4f} km\n'.
                format('rho_eci', rho_eci[0], rho_eci[1], rho_eci[2],
                       np.linalg.norm(rho_eci)))
            fout.write(
                '{:9s} = {:13.4f} S {:13.4f} E {:13.4f} Z MAG = {:7.4f} km/s\n'
                .format('drho_sez', drho_sez[0], drho_sez[1], drho_sez[2],
                        np.linalg.norm(drho_sez)))
            fout.write(
                '{:9s} = {:13.4f} I {:13.4f} J {:13.4f} K MAG = {:7.4f} km/s\n'
                .format('drho_ecef', drho_ecef[0], drho_ecef[1], drho_ecef[2],
                        np.linalg.norm(drho_ecef)))
            fout.write(
                '{:9s} = {:13.4f} I {:13.4f} J {:13.4f} K MAG = {:7.4f} km/s\n'
                .format('drho_eci', drho_eci[0], drho_eci[1], drho_eci[2],
                        np.linalg.norm(drho_eci)))
            fout.write(
                '{:9s} = {:13.4f} I {:13.4f} J {:13.4f} K MAG = {:7.4f} km\n'.
                format('site_ecef', site_ecef[0], site_ecef[1], site_ecef[2],
                       np.linalg.norm(site_ecef)))
            fout.write(
                '{:9s} = {:13.4f} I {:13.4f} J {:13.4f} K MAG = {:7.4f} km\n'.
                format('site_eci', site_eci[0], site_eci[1], site_eci[2],
                       np.linalg.norm(site_eci)))
            fout.write(
                '{:9s} = {:13.4f} I {:13.4f} J {:13.4f} K MAG = {:7.4f} km\n'.
                format('pos_eci', pos_eci[0], pos_eci[1], pos_eci[2],
                       np.linalg.norm(pos_eci)))
            fout.write(
                '{:9s} = {:13.4f} I {:13.4f} J {:13.4f} K MAG = {:7.4f} km/s\n'
                .format('vel_eci', vel_eci[0], vel_eci[1], vel_eci[2],
                        np.linalg.norm(vel_eci)))

            fout.write(prop_string + '\n')
    fout.close()
Beispiel #14
0
beta = np.arctan2(mag_dv_outofplane, mag_dv_inplane)
phi = np.arctan2(dv_lvlh[0], dv_lvlh[1])
alpha = phi-np.absolute(fpa)

print('Beta (out of plane) : {} deg'.format(np.rad2deg(beta)))
print('Phi (angle from theta_hat) : {} deg'.format(np.rad2deg(phi)))
print('Alpha (angle from Vhat) : {} deg'.format(np.rad2deg(alpha)))

r_initial = r_inertial
v_initial = v_inertial

r_final = r_initial
v_final = dv_inertial+v_initial

# find orbital elements of new orbit
( p_n,a_n,ecc_n,inc_n,raan_n,arg_p_n,nu_n,_,_,_,_) = kepler.rv2coe(r_final,v_final, mu)

print('Final Orbit')
kepler.orbit_el(p_n,ecc_n,inc_n,raan_n,arg_p_n,nu_n,mu,'True')

# generate a plot of the orbit
state_mci1, state_pqw1, _, sat_mci1, _, _ = kepler.conic_orbit(p, ecc, inc, raan, arg_p, nu, nu, mu)
state_mci2, state_pqw2, _, sat_mci2,_, _ = kepler.conic_orbit(p_n, ecc_n, inc_n, raan_n, arg_p_n, nu_n, nu_n, mu)

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

ax.plot(state_mci1[:, 0],state_mci1[:, 1], state_mci1[:, 2], label='Initial')
ax.plot(state_mci2[:, 0],state_mci2[:, 1], state_mci2[:, 2], label='Final')
ax.plot([0, sat_mci1[0]], [0, sat_mci1[1]], [0, sat_mci1[2]], 'b.-', markersize=10)
ax.scatter(0, 0, 0,s=1000)
Beispiel #15
0
"""Problem 4 HW4 2017
"""

from astro import kepler, constants
import numpy as np
import matplotlib.pyplot as plt

re = constants.earth.radius
mu = constants.earth.mu

r = np.array([3 * re, 5 * re, 0])
v = np.array([-3.2, 2.0, 2.5])

p, a, ecc, inc, raan, arg_p, nu, _, _, _, _ = kepler.rv2coe(r, v, mu)

output = kepler.orbit_el(p, ecc, inc, raan, arg_p, nu, mu, True)

state_eci, state_pqw, state_lvlh, state_sat_eci, state_sat_pqw, state_sat_lvlh = kepler.conic_orbit(
    p, ecc, inc, raan, arg_p, nu, nu)

fig, ax = plt.subplots()
ax.plot(state_pqw[:, 0], state_pqw[:, 1])
ax.plot(re * np.cos(np.linspace(0, 2 * np.pi)),
        re * np.sin(np.linspace(0, 2 * np.pi)))
ax.plot([0, state_sat_pqw[0]], [0, state_sat_pqw[1]], 'b-', linewidth=3)
ax.plot(state_sat_pqw[0], state_sat_pqw[1], 'b.', markersize=20)
ax.set_xlabel(r'$\hat p$')
ax.set_ylabel(r'$\hat q$')
plt.axis('equal')
plt.show()