# Path: beyond/dates/date.py
# class Timescale(Node):
# class Date:
# class DateRange:
#     class DateConverter(mdates.DateConverter):
#     def __repr__(self):  # pragma: no cover
#     def __str__(self):
#     def _scale_ut1_minus_utc(self, mjd, eop):
#     def _scale_tai_minus_utc(self, mjd, eop):
#     def _scale_tt_minus_tai(self, mjd, eop):
#     def _scale_tai_minus_gps(self, mjd, eop):
#     def _scale_tdb_minus_tt(self, mjd, eop):
#     def offset(self, mjd, new_scale, eop):
# def get_scale(name):
#     def __init__(self, *args, scale=DEFAULT_SCALE, **kwargs):
#     def __getstate__(self):  # pragma: no cover
#     def __setstate__(self, state):  # pragma: no cover
#     def __setattr__(self, *args):  # pragma: no cover
#     def __delattr__(self, *args):  # pragma: no cover
#     def __add__(self, other):
#     def __sub__(self, other):
#     def __gt__(self, other):
#     def __ge__(self, other):
#     def __lt__(self, other):
#     def __le__(self, other):
#     def __eq__(self, other):
#     def __repr__(self):  # pragma: no cover
#     def __str__(self):  # pragma: no cover
#     def __format__(self, fmt):  # pragma: no cover
#     def __hash__(self):
#     def _convert_dt(cls, dt):
#     def _convert_to_scale(self):
#     def d(self):
#     def s(self):
#     def datetime(self):
#     def _datetime(self):
#     def strptime(cls, data, format, scale=DEFAULT_SCALE):  # pragma: no cover
#     def now(cls, scale=DEFAULT_SCALE):
#     def strftime(self, fmt):  # pragma: no cover
#     def change_scale(self, new_scale):
#     def _julian_century(cls, jd):
#     def julian_century(self):
#     def jd(self):
#     def _mjd(self):
#     def mjd(self):
#     def range(cls, *args, **kwargs):
#     def __init__(self, start, stop, step, *, inclusive=False):
#     def dur(self):
#     def _sign(cls, x):
#     def __iter__(self):
#     def __contains__(self, date):
#     def __len__(self):
#         def _conv(v):
#         def convert(values, unit, axis):
# UT1 = Timescale("UT1")  # Universal Time
# GPS = Timescale("GPS")  # GPS Time
# TDB = Timescale("TDB")  # Barycentric Dynamical Time
# UTC = Timescale("UTC")  # Coordinated Universal Time
# TAI = Timescale("TAI")  # International Atomic Time
# TT = Timescale("TT")  # Terrestrial Time
#     MJD_T0 = datetime(1858, 11, 17)
#     JD_MJD = 2400000.5
#     J2000 = 2451545.0
#     REF_SCALE = "TAI"
#     DEFAULT_SCALE = "UTC"
# 
# Path: beyond/utils/ltan.py
# def _mean_sun_raan(date):
# def _true_sun_raan(date):
# def orb2ltan(orb, type="mean"):  # pragma: no cover
# def raan2ltan(date, raan, type="mean"):
# def ltan2raan(date, ltan, type="mean"):
# 
# Path: beyond/env/solarsystem.py
# def get_body(name):
# def get_frame(name):
#     def propagate(cls, date):
#     def propagate(cls, date):
#     def _propagate(cls, date):
#         def cos(angle):
#         def sin(angle):
#     def _propagate(cls, date):
# class EarthPropagator(AnalyticalPropagator):
# class _DiffPropagator(AnalyticalPropagator):
# class MoonPropagator(_DiffPropagator):
# class SunPropagator(_DiffPropagator):
#     FRAME = "EME2000"
#     FRAME = "EME2000"
#     FRAME = "MOD"
#         M = np.radians(357.5291092 + 35999.05034 * t_ut1)


from beyond.dates import Date, timedelta
from beyond.utils import ltan
from beyond.env import solarsystem


eps = 1e-14


def test_ltan2raan(common_env):

    date = Date(2020, 1, 29, 18, 27)

    assert abs(ltan.ltan2raan(date, 22.5 * 3600) - 1.8496591694176407) < eps
    assert abs(ltan.ltan2raan(date, 22.5 * 3600, "true") - 1.901700132311372) < eps


def test_raan2ltan(common_env, iss_tle):

    orb = iss_tle.orbit().copy(frame="EME2000", form="keplerian")


# Path: beyond/dates/date.py
# class Timescale(Node):
# class Date:
# class DateRange:
#     class DateConverter(mdates.DateConverter):
#     def __repr__(self):  # pragma: no cover
#     def __str__(self):
#     def _scale_ut1_minus_utc(self, mjd, eop):
#     def _scale_tai_minus_utc(self, mjd, eop):
#     def _scale_tt_minus_tai(self, mjd, eop):
#     def _scale_tai_minus_gps(self, mjd, eop):
#     def _scale_tdb_minus_tt(self, mjd, eop):
#     def offset(self, mjd, new_scale, eop):
# def get_scale(name):
#     def __init__(self, *args, scale=DEFAULT_SCALE, **kwargs):
#     def __getstate__(self):  # pragma: no cover
#     def __setstate__(self, state):  # pragma: no cover
#     def __setattr__(self, *args):  # pragma: no cover
#     def __delattr__(self, *args):  # pragma: no cover
#     def __add__(self, other):
#     def __sub__(self, other):
#     def __gt__(self, other):
#     def __ge__(self, other):
#     def __lt__(self, other):
#     def __le__(self, other):
#     def __eq__(self, other):
#     def __repr__(self):  # pragma: no cover
#     def __str__(self):  # pragma: no cover
#     def __format__(self, fmt):  # pragma: no cover
#     def __hash__(self):
#     def _convert_dt(cls, dt):
#     def _convert_to_scale(self):
#     def d(self):
#     def s(self):
#     def datetime(self):
#     def _datetime(self):
#     def strptime(cls, data, format, scale=DEFAULT_SCALE):  # pragma: no cover
#     def now(cls, scale=DEFAULT_SCALE):
#     def strftime(self, fmt):  # pragma: no cover
#     def change_scale(self, new_scale):
#     def _julian_century(cls, jd):
#     def julian_century(self):
#     def jd(self):
#     def _mjd(self):
#     def mjd(self):
#     def range(cls, *args, **kwargs):
#     def __init__(self, start, stop, step, *, inclusive=False):
#     def dur(self):
#     def _sign(cls, x):
#     def __iter__(self):
#     def __contains__(self, date):
#     def __len__(self):
#         def _conv(v):
#         def convert(values, unit, axis):
# UT1 = Timescale("UT1")  # Universal Time
# GPS = Timescale("GPS")  # GPS Time
# TDB = Timescale("TDB")  # Barycentric Dynamical Time
# UTC = Timescale("UTC")  # Coordinated Universal Time
# TAI = Timescale("TAI")  # International Atomic Time
# TT = Timescale("TT")  # Terrestrial Time
#     MJD_T0 = datetime(1858, 11, 17)
#     JD_MJD = 2400000.5
#     J2000 = 2451545.0
#     REF_SCALE = "TAI"
#     DEFAULT_SCALE = "UTC"
# 
# Path: beyond/utils/ltan.py
# def _mean_sun_raan(date):
# def _true_sun_raan(date):
# def orb2ltan(orb, type="mean"):  # pragma: no cover
# def raan2ltan(date, raan, type="mean"):
# def ltan2raan(date, ltan, type="mean"):
# 
# Path: beyond/env/solarsystem.py
# def get_body(name):
# def get_frame(name):
#     def propagate(cls, date):
#     def propagate(cls, date):
#     def _propagate(cls, date):
#         def cos(angle):
#         def sin(angle):
#     def _propagate(cls, date):
# class EarthPropagator(AnalyticalPropagator):
# class _DiffPropagator(AnalyticalPropagator):
# class MoonPropagator(_DiffPropagator):
# class SunPropagator(_DiffPropagator):
#     FRAME = "EME2000"
#     FRAME = "EME2000"
#     FRAME = "MOD"
#         M = np.radians(357.5291092 + 35999.05034 * t_ut1)


# Path: tests/utils/test_ltan.py
from beyond.dates import Date, timedelta
from beyond.utils import ltan
from beyond.env import solarsystem



eps = 1e-14


def test_ltan2raan(common_env):

    date = Date(2020, 1, 29, 18, 27)

    assert abs(ltan.ltan2raan(date, 22.5 * 3600) - 1.8496591694176407) < eps
    assert abs(ltan.ltan2raan(date, 22.5 * 3600, "true") - 1.901700132311372) < eps


def test_raan2ltan(common_env, iss_tle):

    orb = iss_tle.orbit().copy(frame="EME2000", form="keplerian")


    assert abs(ltan.raan2ltan(orb.date, orb.raan) / 3600 - 0.903570175768742) < eps