# Path: skyfield/api.py
# N = E = +1.0
# S = W = -1.0
# 
# Path: skyfield/api.py
# N = E = +1.0
# S = W = -1.0
# 
# Path: skyfield/constants.py
# AU_KM = 149597870.700
# 
# AU_M = 149597870700             # per IAU 2012 Resolution B2
# 
# Path: skyfield/sgp4lib.py
# def TEME_to_ITRF(jd_ut1, rTEME, vTEME, xp=0.0, yp=0.0, fraction_ut1=0.0):
#     """Deprecated: use the TEME and ITRS frame objects instead."""
#     theta, theta_dot = theta_GMST1982(jd_ut1, fraction_ut1)
#     angular_velocity = multiply.outer(_zero_zero_minus_one, theta_dot)
# 
#     R = rot_z(-theta)
# 
#     if len(rTEME.shape) == 1:
#         rPEF = (R).dot(rTEME)
#         vPEF = (R).dot(vTEME) + _cross(angular_velocity, rPEF)
#     else:
#         rPEF = mxv(R, rTEME)
#         vPEF = mxv(R, vTEME) + _cross(angular_velocity, rPEF)
# 
#     if xp == 0.0 and yp == 0.0:
#         rITRF = rPEF
#         vITRF = vPEF
#     else:
#         W = (rot_x(yp)).dot(rot_y(xp))
#         rITRF = (W).dot(rPEF)
#         vITRF = (W).dot(vPEF)
#     return rITRF, vITRF
# 
# Path: skyfield/timelib.py
# def julian_date(year, month=1, day=1, hour=0, minute=0, second=0.0):
#     """Given a proleptic Gregorian calendar date and time, build a Julian date.
# 
#     The difference between a “Julian day” and a “Julian date” is that
#     the “day” is the integer part, while the “date” includes a fraction
#     indicating the time.
# 
#     """
#     return julian_day(year, month, day) - 0.5 + (
#         second + minute * 60.0 + hour * 3600.0) / DAY_S
# 
# Path: skyfield/constants.py
# DEG2RAD = 0.017453292519943296


from numpy import array
from skyfield import api
from skyfield.api import EarthSatellite, load
from skyfield.constants import AU_KM, AU_M
from skyfield.sgp4lib import TEME_to_ITRF
from skyfield.timelib import julian_date
from ..constants import DEG2RAD
    t = ts.tdb(2018, 7, [4, 5])
    p = s.at(t)
    assert abs(p.position.au - hp).max() < two_meters
    assert abs(p.velocity.au_per_d - hv).max() < three_km_per_hour

# The following tests are based on the text of
# http://www.celestrak.com/publications/AIAA/2006-6753/AIAA-2006-6753-Rev2.pdf

appendix_c_example = """\
TEME EXAMPLE
1 00005U 58002B   00179.78495062  .00000023  00000-0  28098-4 0  4753
2 00005  34.2682 348.7242 1859667 331.7664  19.3264 10.82419157413667
"""


arcminute = DEG2RAD / 60.0
arcsecond = arcminute / 60.0
seconds_per_day = 86400.0

# Note that the following test is based specifically on Revision 2 of
# "Revisiting Spacetrack Report #3" AIAA 2006-6753 (earlier versions of
# the PDF use different numbers):
#
# http://ww.celestrak.com/publications/AIAA/2006-6753/AIAA-2006-6753-Rev2.pdf

def test_appendix_c_conversion_from_TEME_to_ITRF():
    rTEME = array([5094.18016210, 6127.64465950, 6380.34453270])
    vTEME = array([-4.746131487, 0.785818041, 5.531931288])
    vTEME = vTEME * 24.0 * 60.0 * 60.0  # km/s to km/day


# Path: skyfield/api.py
# N = E = +1.0
# S = W = -1.0
# 
# Path: skyfield/api.py
# N = E = +1.0
# S = W = -1.0
# 
# Path: skyfield/constants.py
# AU_KM = 149597870.700
# 
# AU_M = 149597870700             # per IAU 2012 Resolution B2
# 
# Path: skyfield/sgp4lib.py
# def TEME_to_ITRF(jd_ut1, rTEME, vTEME, xp=0.0, yp=0.0, fraction_ut1=0.0):
#     """Deprecated: use the TEME and ITRS frame objects instead."""
#     theta, theta_dot = theta_GMST1982(jd_ut1, fraction_ut1)
#     angular_velocity = multiply.outer(_zero_zero_minus_one, theta_dot)
# 
#     R = rot_z(-theta)
# 
#     if len(rTEME.shape) == 1:
#         rPEF = (R).dot(rTEME)
#         vPEF = (R).dot(vTEME) + _cross(angular_velocity, rPEF)
#     else:
#         rPEF = mxv(R, rTEME)
#         vPEF = mxv(R, vTEME) + _cross(angular_velocity, rPEF)
# 
#     if xp == 0.0 and yp == 0.0:
#         rITRF = rPEF
#         vITRF = vPEF
#     else:
#         W = (rot_x(yp)).dot(rot_y(xp))
#         rITRF = (W).dot(rPEF)
#         vITRF = (W).dot(vPEF)
#     return rITRF, vITRF
# 
# Path: skyfield/timelib.py
# def julian_date(year, month=1, day=1, hour=0, minute=0, second=0.0):
#     """Given a proleptic Gregorian calendar date and time, build a Julian date.
# 
#     The difference between a “Julian day” and a “Julian date” is that
#     the “day” is the integer part, while the “date” includes a fraction
#     indicating the time.
# 
#     """
#     return julian_day(year, month, day) - 0.5 + (
#         second + minute * 60.0 + hour * 3600.0) / DAY_S
# 
# Path: skyfield/constants.py
# DEG2RAD = 0.017453292519943296


# Path: skyfield/tests/test_earth_satellites.py
from numpy import array
from skyfield import api
from skyfield.api import EarthSatellite, load
from skyfield.constants import AU_KM, AU_M
from skyfield.sgp4lib import TEME_to_ITRF
from skyfield.timelib import julian_date
from ..constants import DEG2RAD

    t = ts.tdb(2018, 7, [4, 5])
    p = s.at(t)
    assert abs(p.position.au - hp).max() < two_meters
    assert abs(p.velocity.au_per_d - hv).max() < three_km_per_hour

# The following tests are based on the text of
# http://www.celestrak.com/publications/AIAA/2006-6753/AIAA-2006-6753-Rev2.pdf

appendix_c_example = """\
TEME EXAMPLE
1 00005U 58002B   00179.78495062  .00000023  00000-0  28098-4 0  4753
2 00005  34.2682 348.7242 1859667 331.7664  19.3264 10.82419157413667
"""


arcminute = DEG2RAD / 60.0
arcsecond = arcminute / 60.0
seconds_per_day = 86400.0

# Note that the following test is based specifically on Revision 2 of
# "Revisiting Spacetrack Report #3" AIAA 2006-6753 (earlier versions of
# the PDF use different numbers):
#
# http://ww.celestrak.com/publications/AIAA/2006-6753/AIAA-2006-6753-Rev2.pdf

def test_appendix_c_conversion_from_TEME_to_ITRF():
    rTEME = array([5094.18016210, 6127.64465950, 6380.34453270])
    vTEME = array([-4.746131487, 0.785818041, 5.531931288])
    vTEME = vTEME * 24.0 * 60.0 * 60.0  # km/s to km/day


    jd_utc = julian_date(2004, 4, 6, 7, 51, 28.386)