Skip to content
This repository was archived by the owner on Dec 22, 2020. It is now read-only.

Proposal: SGP4 Propagator

Frazer McLean edited this page Sep 8, 2016 · 1 revision

A hypothetical SGP4 propagator that conforms to a Propagator interface.

from copy import copy

from sgp4.io import twoline2rv
from sgp4.propagation import sgp4

from .base import Propagator
from ..bodies import earth, wgs72
from ..somewhere import State


class SGP4(Propagator):
    """Adapter class for sgp4 module, which uses the C++ API"""
    def __init__(self, tle, gravity_model=wgs72):
        if gravity_model._sgp4_constants is None:
            raise TypeError(
                'gravity_model._sgp4_constants must be an sgp4.earth_gravity.'
                'EarthGravity instance for use with the sgp4 module.')

        self.tle = tle
        self.gravity_model = gravity_model
        self._satellite = twoline2rv(
            tle.line1, tle.line2, gravity_model._sgp4_constants)

    def propagate_to(self, time):
        minutes = (time.jd - self._satellite.jdsatepoch) * 1440
        r, v = sgp4(self._satellite, minutes)

        body = earth

        # If we're using a different ellipsoid than `earth`, create a
        # new CelestialBody with our ellipsoid.
        if body.ellipsoid is not earth.ellipsoid:
            body = copy(earth)
            body._ellipsoid = self.gravity_model

        return State(r, v, body=body)
Clone this wiki locally