# Path: spyce/physics.py
# def _(tabulated, uncertainty=None, computed=None):
# G = _(6.67384e-11, 80e-16)     # gravitational constant (N.(m/kg)^2)
# N_A = _(6.02214129e23, 27e15, A_r_e*M_u/m_e)  # Avogadro constant (1/mol)
# R = _(8.3144621, 75e-7)                       # molar gas constant (J/mol/K)
# T_P = _(1.416833e32, 85e26, m_P * c**2 / k_B)        # Planck temperature (K)
# T0 = _(288.15)   # standard temperature (K)
# 
# Path: spyce/coordinates.py
# class CelestialCoordinates:
#     """Celestial coordinates of a point or a direction
# 
#     Celestial coordinates are spherical coordinates. The referential is thus
#     given by an origin, a fundamental plane and a primary direction.
# 
#     * ecliptic coordinates: planet center, ecliptic, vernal equinox
#     * equatorial coordinates: planet center, celestial equator, vernal equinox
# 
#     Note that the vernal equinox, the celestial equator and the ecliptic are
#     respectively the northward equinox, the equatorial plane and the orbital
#     plane *of the Earth*. It does mean that the direction of the north pole of
#     Mars is given within a referential centered on Mars, oriented with Earth.
#     """
# 
#     # the obliquity of the ecliptic is Earth's obliquity (tilt); that is, the
#     # angle between the celestial equator (Earth's equatorial plane) and the
#     # ecliptic (Earth's orbital plane)
#     obliquity_of_the_ecliptic = 0.40910517666747087
# 
#     def __init__(self, right_ascension, declination, ecliptic_longitude,
#                  ecliptic_latitude, distance):
#         """Use from_equatorial() or from_ecliptic()"""
#         self.right_ascension = right_ascension
#         self.declination = declination
#         self.ecliptic_longitude = ecliptic_longitude
#         self.ecliptic_latitude = ecliptic_latitude
#         self.distance = distance
# 
#     @classmethod
#     def from_equatorial(cls, right_ascension, declination, distance=math.inf):
#         """Locate an object from its equatorial coordinates (see class doc)
# 
#         If distance is omitted, it is assumed to be infinite; the coordinates
#         then refer either to a point infinitely far away, or to a direction.
#         """
#         e = cls.obliquity_of_the_ecliptic
#         ecliptic_longitude = math.atan(
#             (
#                 math.sin(right_ascension) * math.cos(e) +
#                 math.tan(declination) * math.sin(e)
#             )
#             / math.cos(right_ascension)
#         )
#         ecliptic_latitude = math.asin(
#             math.sin(declination) * math.cos(e) -
#             math.cos(declination) * math.sin(e) * math.sin(right_ascension)
#         )
#         return cls(right_ascension, declination, ecliptic_longitude,
#                    ecliptic_latitude, distance)
# 
#     @classmethod
#     def from_ecliptic(cls, ecliptic_longitude, ecliptic_latitude,
#                       distance=math.inf):
#         """Locate an object from its ecliptic coordinates (see class doc)
# 
#         If distance is omitted, it is assumed to be infinite; the coordinates
#         then refer either to a point infinitely far away, or to a direction.
#         """
#         e = cls.obliquity_of_the_ecliptic
#         right_ascension = math.atan(
#             (
#                 math.sin(ecliptic_longitude) * math.cos(e) -
#                 math.tan(ecliptic_latitude) * math.sin(e)
#             ) / math.cos(ecliptic_longitude)
#         )
#         declination = math.asin(
#             math.sin(ecliptic_latitude) * math.cos(e) +
#             math.cos(ecliptic_latitude) * math.sin(e) *
#             math.sin(ecliptic_longitude)
#         )
#         return cls(right_ascension, declination, ecliptic_longitude,
#                    ecliptic_latitude, distance)


import json
import re
from math import acos, asin, cos, pi, radians, sin
from urllib.request import urlopen
from spyce.physics import au
from spyce.coordinates import CelestialCoordinates
    # extract data from table
    lines = html.split('\n')
    lines = [re.split(r'\s{2,}', line) for line in lines[16:]]

    epoch = tt_to_j2000(2000, 1, 1, 12)

    for i in range(0, len(lines) - 1, 2):
        name = lines[i][0]
        elements = lines[i][1:]
        changes = lines[i + 1][1:]

        if name == 'EM Bary':
            name = 'Earth'

        # see aprx_pos_planets.md
        t = epoch / 86400 / 36525
        elements = [
            float(x0) + float(dx) * t
            for x0, dx in zip(elements, changes)
        ]

        (semi_major_axis, eccentricity, inclination, mean_longitude,
            longitude_of_periapsis, longitude_of_ascending_node) = elements

        mean_anomaly = mean_longitude - longitude_of_periapsis
        argument_of_periapsis = longitude_of_periapsis - longitude_of_ascending_node

        body = bodies.setdefault(name, {})
        body['orbit'] = {
            'primary': 'Sun',

# Path: spyce/physics.py
# def _(tabulated, uncertainty=None, computed=None):
# G = _(6.67384e-11, 80e-16)     # gravitational constant (N.(m/kg)^2)
# N_A = _(6.02214129e23, 27e15, A_r_e*M_u/m_e)  # Avogadro constant (1/mol)
# R = _(8.3144621, 75e-7)                       # molar gas constant (J/mol/K)
# T_P = _(1.416833e32, 85e26, m_P * c**2 / k_B)        # Planck temperature (K)
# T0 = _(288.15)   # standard temperature (K)
# 
# Path: spyce/coordinates.py
# class CelestialCoordinates:
#     """Celestial coordinates of a point or a direction
# 
#     Celestial coordinates are spherical coordinates. The referential is thus
#     given by an origin, a fundamental plane and a primary direction.
# 
#     * ecliptic coordinates: planet center, ecliptic, vernal equinox
#     * equatorial coordinates: planet center, celestial equator, vernal equinox
# 
#     Note that the vernal equinox, the celestial equator and the ecliptic are
#     respectively the northward equinox, the equatorial plane and the orbital
#     plane *of the Earth*. It does mean that the direction of the north pole of
#     Mars is given within a referential centered on Mars, oriented with Earth.
#     """
# 
#     # the obliquity of the ecliptic is Earth's obliquity (tilt); that is, the
#     # angle between the celestial equator (Earth's equatorial plane) and the
#     # ecliptic (Earth's orbital plane)
#     obliquity_of_the_ecliptic = 0.40910517666747087
# 
#     def __init__(self, right_ascension, declination, ecliptic_longitude,
#                  ecliptic_latitude, distance):
#         """Use from_equatorial() or from_ecliptic()"""
#         self.right_ascension = right_ascension
#         self.declination = declination
#         self.ecliptic_longitude = ecliptic_longitude
#         self.ecliptic_latitude = ecliptic_latitude
#         self.distance = distance
# 
#     @classmethod
#     def from_equatorial(cls, right_ascension, declination, distance=math.inf):
#         """Locate an object from its equatorial coordinates (see class doc)
# 
#         If distance is omitted, it is assumed to be infinite; the coordinates
#         then refer either to a point infinitely far away, or to a direction.
#         """
#         e = cls.obliquity_of_the_ecliptic
#         ecliptic_longitude = math.atan(
#             (
#                 math.sin(right_ascension) * math.cos(e) +
#                 math.tan(declination) * math.sin(e)
#             )
#             / math.cos(right_ascension)
#         )
#         ecliptic_latitude = math.asin(
#             math.sin(declination) * math.cos(e) -
#             math.cos(declination) * math.sin(e) * math.sin(right_ascension)
#         )
#         return cls(right_ascension, declination, ecliptic_longitude,
#                    ecliptic_latitude, distance)
# 
#     @classmethod
#     def from_ecliptic(cls, ecliptic_longitude, ecliptic_latitude,
#                       distance=math.inf):
#         """Locate an object from its ecliptic coordinates (see class doc)
# 
#         If distance is omitted, it is assumed to be infinite; the coordinates
#         then refer either to a point infinitely far away, or to a direction.
#         """
#         e = cls.obliquity_of_the_ecliptic
#         right_ascension = math.atan(
#             (
#                 math.sin(ecliptic_longitude) * math.cos(e) -
#                 math.tan(ecliptic_latitude) * math.sin(e)
#             ) / math.cos(ecliptic_longitude)
#         )
#         declination = math.asin(
#             math.sin(ecliptic_latitude) * math.cos(e) +
#             math.cos(ecliptic_latitude) * math.sin(e) *
#             math.sin(ecliptic_longitude)
#         )
#         return cls(right_ascension, declination, ecliptic_longitude,
#                    ecliptic_latitude, distance)


# Path: get_nasa_data.py
import json
import re
from math import acos, asin, cos, pi, radians, sin
from urllib.request import urlopen
from spyce.physics import au
from spyce.coordinates import CelestialCoordinates

    # extract data from table
    lines = html.split('\n')
    lines = [re.split(r'\s{2,}', line) for line in lines[16:]]

    epoch = tt_to_j2000(2000, 1, 1, 12)

    for i in range(0, len(lines) - 1, 2):
        name = lines[i][0]
        elements = lines[i][1:]
        changes = lines[i + 1][1:]

        if name == 'EM Bary':
            name = 'Earth'

        # see aprx_pos_planets.md
        t = epoch / 86400 / 36525
        elements = [
            float(x0) + float(dx) * t
            for x0, dx in zip(elements, changes)
        ]

        (semi_major_axis, eccentricity, inclination, mean_longitude,
            longitude_of_periapsis, longitude_of_ascending_node) = elements

        mean_anomaly = mean_longitude - longitude_of_periapsis
        argument_of_periapsis = longitude_of_periapsis - longitude_of_ascending_node

        body = bodies.setdefault(name, {})
        body['orbit'] = {
            'primary': 'Sun',

            'semi_major_axis': semi_major_axis * au,