Beispiel #1
0
def get_orbital_data(tle_data, time_data, label="Satellite"):
    ts = load.timescale()
    satellite = EarthSatellite(tle_data["line_1"], tle_data["line_2"], label,
                               ts)
    time_instant = ts.utc(
        time_data["year"],
        time_data["month"],
        time_data["day"],
        time_data["hour"],
        time_data["min"],
        time_data["sec"],
    )
    geocentric = satellite.at(time_instant)
    subpoint = geocentric.subpoint()
    elements = osculating_elements_of(geocentric)
    result = {
        "description": str(satellite),
        "lat": float(subpoint.latitude.degrees),
        "lng": float(subpoint.longitude.degrees),
        "alt": float(subpoint.elevation.km),
        "sunlit": satellite.at(time_instant).is_sunlit(JPL_EPH),
        "gcrs_vector": geocentric.position.km,
        "elements": elements
    }
    return result
Beispiel #2
0
def test_equatorial_km_d(ts):
    """Tests against data from Horizons in km and days, with equatorial reference plane
    """
    geocentric_pos = (moon - earth).at(ts.tdb(2015, 3, 2, 2))
    calc_data = horizons_array(osculating_elements_of(geocentric_pos))
    horizons_data = array([
        5.569337304355707E-02, 3.628019705296879E+05, 1.832507608006020E+01,
        3.570946187642240E+02, 3.318968921151215E+02, 2457072.329517839011,
        1.320459197700415E+01, 1.486020417866582E+02, 1.517384963232830E+02,
        3.841993269696947E+05, 4.055966834097015E+05, 2.726324301628867E+01
    ])
    epsilon = array([
        1e-10, 1e-4, 1e-7, 1e-6, 1e-6, 1e-8, 1e-9, 1e-6, 1e-7, 1e-4, 1e-4, 1e-8
    ])
    compare(calc_data, horizons_data, epsilon)
    def getOrbitalElements(self):
        """Get orbital and dynamic elements"""

        pv_list = self.getPV()
        elements = osculating_elements_of(pv_list[0])

        # line 2 of new TLEs
        self.inclination = elements.inclination.degrees
        self.raan = elements.longitude_of_ascending_node
        self.eccentricity = elements.eccentricity
        self.aop = elements.argument_of_periapsis
        self.ma = elements.mean_anomaly
        self.mm = elements.mean_motion_per_day
        return [self.inclination, self.raan, self.eccentricity, \
                self.aop, self.ma, self.mm]
Beispiel #4
0
def test_extreme_ellipse(ts):
    """Tests against data from Horizons for an orbit with eccentricity just less than 1
    """
    geocentric_pos = (io - sun).at(ts.tdb(2015, 3, 2, 17, 26))
    calc_data = horizons_array(osculating_elements_of(geocentric_pos),
                               units='km_s')
    horizons_data = array([
        9.993434925710607E-01, 1.163126430217223E+08, 2.164979337400508E+01,
        7.503612948248414E+00, 3.571949928607168E+02, 2456680.438054572791,
        2.798965463884538E-10, 9.764838165348996E-03, 1.351769989470609E+02,
        1.771688146920545E+11, 3.542213167410872E+11, 1.286189503390209E+12
    ])
    epsilon = array([
        1e-10, 1e-1, 1e-8, 1e-8, 1e-7, 1e-8, 1e-16, 1e-8, 1e-7, 1e5, 1e5, 1e6
    ])
    compare(calc_data, horizons_data, epsilon)
Beispiel #5
0
def test_slightly_hyperbolic(ts):
    """Tests against data from Horizons for an orbit with eccentricity just over 1
    """
    geocentric_pos = (io - sun).at(ts.tdb(2015, 3, 2, 17, 27))
    calc_data = horizons_array(osculating_elements_of(geocentric_pos),
                               units='km_s')
    horizons_data = array([
        1.000249165282725E+00, 1.176022222580809E+08, 2.167088597088522E+01,
        7.441033056578390E+00, 3.575776020085432E+02, 2456680.266815741546,
        6.437043762782399E-11, 2.246667771669457E-03, 1.348525808471548E+02,
        -4.719847844449893E+11
    ])
    epsilon = array(
        [1e-11, 1e-2, 1e-11, 1e-11, 1e-9, 1e-8, 1e-17, 1e-10, 1e-9, 1e4])
    compare(calc_data[:-2], horizons_data, epsilon)
    assert (calc_data[-2:] == array([inf, inf])).all()
Beispiel #6
0
def test_equatorial_au_d(ts):
    """Tests against data from Horizons in au and days, with equatorial reference plane
    """
    geocentric_pos = (moon - earth).at(ts.tdb(2015, 3, 2, 2))
    calc_data = horizons_array(osculating_elements_of(geocentric_pos),
                               units='au_d')
    horizons_data = array([
        5.569337304355707E-02, 2.425181380136368E-03, 1.832507608006020E+01,
        3.570946187642240E+02, 3.318968921151215E+02, 2457072.329517839011,
        1.320459197700415E+01, 1.486020417866582E+02, 1.517384963232830E+02,
        2.568213873445825E-03, 2.711246366755283E-03, 2.726324301628867E+01
    ])
    epsilon = array([
        1e-10, 1e-12, 1e-7, 1e-6, 1e-6, 1e-8, 1e-9, 1e-6, 1e-7, 1e-13, 1e-12,
        1e-8
    ])
    compare(calc_data, horizons_data, epsilon)
Beispiel #7
0
def test_ecliptic_km_d(ts):
    """Tests against data from Horizons in km and days, with ecliptic reference plane
    """
    geocentric_pos = (moon - earth).at(ts.tdb(2015, 3, 2, 2))
    calc_data = horizons_array(osculating_elements_of(geocentric_pos,
                                                      ECLIPTIC),
                               units='km_d')
    horizons_data = array([
        5.569337304355707E-02, 3.628019705296879E+05, 5.216521657765558E+00,
        1.900948892867905E+02, 1.390846818575352E+02, 2457072.329517839011,
        1.320459197700415E+01, 1.486020417866582E+02, 1.517384963232830E+02,
        3.841993269696947E+05, 4.055966834097015E+05, 2.726324301628867E+01
    ])
    epsilon = array([
        1e-10, 1e-4, 1e-8, 1e-6, 1e-6, 1e-8, 1e-9, 1e-6, 1e-7, 1e-4, 1e-4, 1e-8
    ])
    compare(calc_data, horizons_data, epsilon)
Beispiel #8
0
def test_ecliptic_au_d(ts):
    """Tests against data from Horizons in au and days, with ecliptic reference plane
    """
    geocentric_pos = (moon - earth).at(ts.tdb(2015, 3, 2, 2))
    elem = osculating_elements_of(geocentric_pos, ECLIPTIC)
    calc_data = horizons_array(elem, units='au_d')
    horizons_data = array([
        5.569337304355707E-02, 2.425181380136368E-03, 5.216521657765558E+00,
        1.900948892867905E+02, 1.390846818575352E+02, 2457072.329517839011,
        1.320459197700415E+01, 1.486020417866582E+02, 1.517384963232830E+02,
        2.568213873445825E-03, 2.711246366755283E-03, 2.726324301628867E+01
    ])
    epsilon = array([
        1e-10, 1e-12, 1e-8, 1e-6, 1e-6, 1e-8, 1e-9, 1e-6, 1e-7, 1e-13, 1e-12,
        1e-8
    ])
    compare(calc_data, horizons_data, epsilon)
def test_slightly_hyperbolic(ts):
    """Tests against data from Horizons for an orbit with eccentricity just over 1
    """
    geocentric_pos = (io - sun).at(ts.tdb(2015, 3, 2, 17, 27))
    calc_data = horizons_array(osculating_elements_of(geocentric_pos), units='km_s')
    horizons_data = array([1.000249165282725E+00,
                           1.176022222580809E+08,
                           2.167088597088522E+01,
                           7.441033056578390E+00,
                           3.575776020085432E+02,
                           2456680.266815741546,
                           6.437043762782399E-11,
                           2.246667771669457E-03,
                           1.348525808471548E+02,
                           -4.719847844449893E+11])
    epsilon = array([1e-11, 1e-2, 1e-11, 1e-11, 1e-9, 1e-8, 1e-17, 1e-10, 1e-9, 1e4])
    compare(calc_data[:-2], horizons_data, epsilon)
    assert (calc_data[-2:] == array([inf, inf])).all()
def test_extreme_ellipse(ts):
    """Tests against data from Horizons for an orbit with eccentricity just less than 1
    """
    geocentric_pos = (io - sun).at(ts.tdb(2015, 3, 2, 17, 26))
    calc_data = horizons_array(osculating_elements_of(geocentric_pos), units='km_s')
    horizons_data = array([9.993434925710607E-01,
                           1.163126430217223E+08,
                           2.164979337400508E+01,
                           7.503612948248414E+00,
                           3.571949928607168E+02,
                           2456680.438054572791,
                           2.798965463884538E-10,
                           9.764838165348996E-03,
                           1.351769989470609E+02,
                           1.771688146920545E+11,
                           3.542213167410872E+11,
                           1.286189503390209E+12])
    epsilon = array([1e-10, 1e-1, 1e-8, 1e-8, 1e-7, 1e-8, 1e-16, 1e-8, 1e-7, 1e5, 1e5, 1e6])
    compare(calc_data, horizons_data, epsilon)
def test_ecliptic_km_s(ts):
    """Tests against data from Horizons in km and seconds, with ecliptic reference plane
    """
    geocentric_pos = (moon - earth).at(ts.tdb(2015, 3, 2, 2))
    calc_data = horizons_array(osculating_elements_of(geocentric_pos, ECLIPTIC), units='km_s')
    horizons_data = array([5.569337304355707E-02,
                           3.628019705296879E+05,
                           5.216521657765558E+00,
                           1.900948892867905E+02,
                           1.390846818575352E+02,
                           2457072.329517839011,
                           1.528309256597703E-04,
                           1.486020417866582E+02,
                           1.517384963232830E+02,
                           3.841993269696947E+05,
                           4.055966834097015E+05,
                           2.355544196607342E+06])
    epsilon = array([1e-10, 1e-4, 1e-8, 1e-6, 1e-6, 1e-8, 1e-14, 1e-6, 1e-7, 1e-4, 1e-4, 1e-3])
    compare(calc_data, horizons_data, epsilon)
def test_equatorial_au_d(ts):
    """Tests against data from Horizons in au and days, with equatorial reference plane
    """
    geocentric_pos = (moon - earth).at(ts.tdb(2015, 3, 2, 2))
    calc_data = horizons_array(osculating_elements_of(geocentric_pos), units='au_d')
    horizons_data = array([5.569337304355707E-02,
                           2.425181380136368E-03,
                           1.832507608006020E+01,
                           3.570946187642240E+02,
                           3.318968921151215E+02,
                           2457072.329517839011,
                           1.320459197700415E+01,
                           1.486020417866582E+02,
                           1.517384963232830E+02,
                           2.568213873445825E-03,
                           2.711246366755283E-03,
                           2.726324301628867E+01])
    epsilon = array([1e-10, 1e-12, 1e-7, 1e-6, 1e-6, 1e-8, 1e-9, 1e-6, 1e-7, 1e-13, 1e-12, 1e-8])
    compare(calc_data, horizons_data, epsilon)
def test_equatorial_km_s(ts):
    """Tests against data from Horizons in km and seconds, with equatorial reference plane
    """
    geocentric_pos = (moon - earth).at(ts.tdb(2015, 3, 2, 2))
    calc_data = horizons_array(osculating_elements_of(geocentric_pos), units='km_s')
    horizons_data = array([5.569337304355707E-02,
                           3.628019705296879E+05,
                           1.832507608006020E+01,
                           3.570946187642240E+02,
                           3.318968921151215E+02,
                           2457072.329517839011,
                           1.528309256597703E-04,
                           1.486020417866582E+02,
                           1.517384963232830E+02,
                           3.841993269696947E+05,
                           4.055966834097015E+05,
                           2.355544196607342E+06])
    epsilon = array([1e-10, 1e-4, 1e-7, 1e-6, 1e-6, 1e-8, 1e-14, 1e-6, 1e-7, 1e-4, 1e-4, 1e-3])
    compare(calc_data, horizons_data, epsilon)
def test_ecliptic_au_d(ts):
    """Tests against data from Horizons in au and days, with ecliptic reference plane
    """
    geocentric_pos = (moon - earth).at(ts.tdb(2015, 3, 2, 2))
    elem = osculating_elements_of(geocentric_pos, ECLIPTIC)
    calc_data = horizons_array(elem, units='au_d')
    horizons_data = array([5.569337304355707E-02,
                           2.425181380136368E-03,
                           5.216521657765558E+00,
                           1.900948892867905E+02,
                           1.390846818575352E+02,
                           2457072.329517839011,
                           1.320459197700415E+01,
                           1.486020417866582E+02,
                           1.517384963232830E+02,
                           2.568213873445825E-03,
                           2.711246366755283E-03,
                           2.726324301628867E+01])
    epsilon = array([1e-10, 1e-12, 1e-8, 1e-6, 1e-6, 1e-8, 1e-9, 1e-6, 1e-7, 1e-13, 1e-12, 1e-8])
    compare(calc_data, horizons_data, epsilon)
Beispiel #15
0
def test_periapsis_time(ts):
    """This tests the moment when the eccentricity of Io orbiting the sun
    transitions from just below 1 to just above 1. Periapsis time is
    calculated using M/n, and both M and n go to 0 as e goes to 1.
    Periapsis time of Io around the sun should change linearly over a very
    small time interval interval (a fraction of one second) during this
    transition, but instead periapsis time deviated from linear within .005s
    of e=1.

    One source of the deviation was the fact that M was being remapped to
    -pi to pi when e>1. Using M without remapping reduced the deviation when
    e>1. The second thing that reduced the deviation was widening the
    tolerance for the use of the parabolic periapsis time equation.

    This test makes sure these fixes don't regress by checking that the
    periapsis times don't deviate from linear by more than 1e-5 days within
    .005s of e=1.
    """
    t = ts.tdb(jd=linspace(2457084.226893796, 2457084.226893912, 500))

    elem = osculating_elements_of((io - sun).at(t))
    Tp = elem.periapsis_time.tdb
    line = -240.61044176706827 * t.tdb + 593656801.6052344
    compare(Tp, line, 1e-5)
def test_periapsis_time(ts):
    """This tests the moment when the eccentricity of Io orbiting the sun
    transitions from just below 1 to just above 1. Periapsis time is
    calculated using M/n, and both M and n go to 0 as e goes to 1.
    Periapsis time of Io around the sun should change linearly over a very
    small time interval interval (a fraction of one second) during this
    transition, but instead periapsis time deviated from linear within .005s
    of e=1.

    One source of the deviation was the fact that M was being remapped to
    -pi to pi when e>1. Using M without remapping reduced the deviation when
    e>1. The second thing that reduced the deviation was widening the
    tolerance for the use of the parabolic periapsis time equation.

    This test makes sure these fixes don't regress by checking that the
    periapsis times don't deviate from linear by more than 1e-5 days within
    .005s of e=1.
    """
    t = ts.tdb(jd=linspace(2457084.226893796, 2457084.226893912, 500))

    elem = osculating_elements_of((io - sun).at(t))
    Tp = elem.periapsis_time.tdb
    line = -240.61044176706827*t.tdb + 593656801.6052344
    compare(Tp, line, 1e-5)
def test_repr(ts):
    elements = osculating_elements_of((moon-earth).at(ts.utc(2015, 3, 2, 12)))
    assert repr(elements) == '<Elements 1 sets>'
Beispiel #18
0
def _sidereal_period(secondary, primary):
    elements = osculating_elements_of((secondary - primary).at(ts.utc(2017)))
    return elements.period_in_days
def test_multiple_times(ts):
    """Tests creation of an OsculatingElements object with multiple sets of elements
    """
    time = ts.utc(2015, 3, 2, [12, 13, 14, 15])
    elements = osculating_elements_of((moon-earth).at(time))
    check_types(elements, len(time))
def test_single_time(ts):
    """Tests creation of an OsculatingElements object with a single set of elements
    """
    elements = osculating_elements_of((moon-earth).at(ts.utc(2015, 3, 2, 12)))
    check_types(elements, 1)
Beispiel #21
0
def get_orbits(request):
    planets = load('de422.bsp')

    ts = load.timescale(builtin=True)
    t = ts.now()

    with closing(planets):
        planet_data = []
        planet_keys = [
            'SUN', 'MERCURY BARYCENTER', 'VENUS BARYCENTER',
            'EARTH BARYCENTER', 'MARS BARYCENTER', 'JUPITER BARYCENTER',
            'SATURN BARYCENTER', 'URANUS BARYCENTER', 'NEPTUNE BARYCENTER',
            'PLUTO BARYCENTER'
        ]
        planet_arr = [
            'sun', 'mercury', 'venus', 'earth', 'mars', 'jupiter', 'saturn',
            'uranus', 'neptune', 'pluto'
        ]

        planet_scale = [10, 0.38, 0.95, 1, 0.53, 11.2, 9.45, 4, 3.88, 5]

        for planet in planet_keys:
            planet_ephemeris = planets[planet].at(t)
            position = planet_ephemeris.position

            pos_x = position.au[0]
            pos_y = position.au[1]
            pos_z = position.au[2]
            position = {}
            position2 = {}
            rotation = {}
            axes = {}

            if (planet != 'SUN'):
                sun = planets['SUN'].at(t)
                position = (planets[planet] - planets['sun']).at(t)
                elements = osculating_elements_of(position)
                axes = {
                    "semi-major-axis": elements.semi_major_axis.au,
                    "semi-minor-axis": elements.semi_minor_axis.au
                }

                rotation = {
                    "x": 0,
                    "y": 0,
                    "z": 0,
                    "loa": elements.longitude_of_ascending_node.radians,
                    "per": elements.argument_of_periapsis.radians,
                    "inc": elements.inclination.radians
                }
                distance = (elements.semi_major_axis.au -
                            elements.periapsis_distance.au)

                position = {"x": -distance, "y": 0, "z": 0}
                position2 = {
                    "x": sun.position.au[0],
                    "y": sun.position.au[1],
                    "z": sun.position.au[2]
                }

            planet_data.append({
                "name": planet_arr[planet_keys.index(planet)],
                "scale": planet_scale[planet_keys.index(planet)],
                "x": pos_x,
                "y": pos_y,
                "z": pos_z,
                "position": position,
                "position2": position2,
                "rotation": rotation,
                "axes": axes
            })

        return JsonResponse(planet_data, safe=False)
Beispiel #22
0
from skyfield.api import load
from skyfield.elementslib import osculating_elements_of

ts = load.timescale()
t = ts.utc(2018, 4, 22, range(0, 25))

planets = load('de421.bsp')
earth = planets['earth']
moon = planets['moon']

position = (moon - earth).at(t)
elements = osculating_elements_of(position)

a = '321'
Beispiel #23
0
def test_multiple_times(ts):
    """Tests creation of an OsculatingElements object with multiple sets of elements
    """
    time = ts.utc(2015, 3, 2, [12, 13, 14, 15])
    elements = osculating_elements_of((moon - earth).at(time))
    check_types(elements, len(time))
Beispiel #24
0
def test_single_time(ts):
    """Tests creation of an OsculatingElements object with a single set of elements
    """
    elements = osculating_elements_of((moon - earth).at(ts.utc(2015, 3, 2,
                                                               12)))
    check_types(elements, 1)
Beispiel #25
0
def test_repr(ts):
    elements = osculating_elements_of((moon - earth).at(ts.utc(2015, 3, 2,
                                                               12)))
    assert repr(elements) == '<Elements 1 sets>'