How to use the sgp4.api.Satrec function in sgp4

To help you get started, we’ve selected a few sgp4 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github consensys-space / trusat-orbit / tests / test_profile.py View on Github external
baseline = Timer(lambda: tsp.find_rms_inline_scalar(satnew, rd, ll, odata)).timeit(number=num)
    print("find_rms_inline_scalar:      {:.6f} {:.2f}x".format( *tac(baseline, Timer(lambda: tsp.find_rms_inline_scalar(satnew, rd, ll, odata)).timeit(number = num)) ))
    print("find_rms:                    {:.6f} {:.2f}x".format( *tac(baseline, Timer(lambda: find_rms(satnew, rd, ll, odata)).timeit(number = num)) ))
    print("find_rms_old:                {:.6f} {:.2f}x".format( *tac(baseline, Timer(lambda: tsp.find_rms_old(satold, rd, ll, odata)).timeit(number = num)) ))
    print("find_rmspy:                  {:.6f} {:.2f}x".format( *tac(baseline, Timer(lambda: tsp.find_rmspy(satold, rd, ll, odata)).timeit(number = num)) ))
else:
    print("find_rms:                    {:.6f}".format( Timer(lambda: find_rms(satnew, rd, ll, odata)).timeit(number = num)) )

print()
find_rms_inline_baseline = baseline

tsince = (60 + satnew.jdsatepoch) * 1440.0 # time since epoch in minutes
(jd, fr) = divmod(satnew.jdsatepoch,1)
satnew.sgp4(jd, fr)

satrec3 = Satrec()
satrec3_jdsatepoch  = 2451723.28495062
satrec3.sgp4init(WGS72, 'i', satnum, satrec3_jdsatepoch-2433281.5, bstar, 
                ndot, nddot, ecco, argpo, inclo, mo, no_kozai, nodeo)

print("Single element SGP4")
baseline = Timer(lambda: satrec3.sgp4(jd,fr)).timeit(number = num)
print("sgp4_cpp(1):                 {:.6f} {:.2f}x".format( *tac(baseline, Timer(lambda: satrec3.sgp4(jd,fr)).timeit(number = num)) ))
print("sgp4_py:                     {:.6f} {:.2f}x".format( *tac(baseline, Timer(lambda: sgp4(satold, tsince)).timeit(number = num)) ))
print()

print("Vector element SGP4 vs scalar loop of same #")
sats = []
sats.append(satnew)
a = SatrecArray(sats)

for j in range(len(odata)):
github brandon-rhodes / python-sgp4 / sgp4 / tests.py View on Github external
def test_satrec_initialized_with_sgp4init_in_afspc_mode():
    sat = Satrec()
    sat.sgp4init(
        WGS72,
        'a',
        VANGUARD_ATTRS['satnum'],
        VANGUARD_EPOCH,
        *sgp4init_args(VANGUARD_ATTRS)
    )
    assertEqual(sat.operationmode, 'a')
github consensys-space / trusat-orbit / tests / test_profile.py View on Github external
bmax = 1.1*b
bmin = 0.9*b
bstep = (bmax-bmin)/20.0

satnum   = 5
bstar    = 2.8098e-05
ndot     = 6.96919666594958e-13
nddot    = 0.0
ecco     = 0.1859667
argpo    = 5.790416027488515
inclo    = 0.5980929187319208
mo       = 0.3373093125574321
no_kozai = 0.04722944544077857
nodeo    = 6.08638547138321

sat2 = Satrec()
sat2_jdsatepoch  = 2451723.28495062

sat2.sgp4init(WGS72, 'i', satnum, sat2_jdsatepoch, bstar, ndot, nddot,
              ecco, argpo, inclo, mo, no_kozai, nodeo)


# Vectorized Python-SGP4 array initialization
jd = np.linspace(2451723, 2451723+900, 100)
fr = np.zeros((jd.shape[0],))
rv_template = np.zeros((1, len(jd), 3), dtype='double')

print()
np_zeros_template = np.zeros((1,10,3), dtype='double')
np_empty_template = np.empty((1,10,3), dtype='double')

def tac(baseline, time):
github brandon-rhodes / python-sgp4 / sgp4 / tests.py View on Github external
def test_all_three_gravity_models_with_sgp4init():
    # Gravity models specified with sgp4init() should also change the
    # positions generated.

    sat = Satrec()
    args = sgp4init_args(VANGUARD_ATTRS)

    sat.sgp4init(WGS72OLD, 'i', VANGUARD_ATTRS['satnum'], VANGUARD_EPOCH, *args)
    assert_wgs72old(sat)

    sat.sgp4init(WGS72, 'i', VANGUARD_ATTRS['satnum'], VANGUARD_EPOCH, *args)
    assert_wgs72(sat)

    sat.sgp4init(WGS84, 'i', VANGUARD_ATTRS['satnum'], VANGUARD_EPOCH, *args)
    assert_wgs84(sat)
github consensys-space / trusat-orbit / tests / test_profile.py View on Github external
from array import array
import numpy as np

from sgp4.propagation import sgp4, sgp4init
from sgp4.api import Satrec, SatrecArray, SGP4_ERRORS, WGS72
from sgp4.earth_gravity import wgs72
from sgp4.io import twoline2rv

from trusat.satfit import Date

line0 = 'SL-16 R/B'
line1 = '1 22285U 92093B   19314.09990558 -.00000000  00000-0  24310-4 0  9990'
line2 = '2 22285  71.0198 174.7928 0006190 244.6688 115.3794 14.15033886386443'

satold = twoline2rv(line1,line2,wgs72)
satnew = Satrec.twoline2rv(line1,line2)

test_tuple           = (0.1, 0.2, 0.3)
test_list            = [0.1, 0.2, 0.3]
test_vec   = array('d',[0.1, 0.2, 0.3])
test_vec2  = array('d',[0.3, 0.2, 0.1])
rtn_vec    = array('d',[0, 0, 0])

test_vec_np = np.array([0.1,0.2,0.3],dtype=np.double)
rtn_vec_np  = np.zeros(3,dtype=np.double)
r = 0.0

b = 0.000012345
bmax = 1.1*b
bmin = 0.9*b
bstep = (bmax-bmin)/20.0
github brandon-rhodes / python-sgp4 / sgp4 / tests.py View on Github external
def test_correct_epochyr():
    # Make sure that the non-standard four-digit epochyr I switched
    # to in the Python version of SGP4 is reverted back to the
    # official behavior when that code is used behind Satrec.
    sat = Satrec.twoline2rv(LINE1, LINE2)
    assertEqual(sat.epochyr, 0)
github brandon-rhodes / python-sgp4 / sgp4 / tests.py View on Github external
def test_satrec_built_with_twoline2rv():
    sat = Satrec.twoline2rv(LINE1, LINE2)
    verify_vanguard_1(sat)
    assertEqual(sat.epochdays, VANGUARD_EPOCHDAYS)
github aerospaceresearch / orbitdeterminator / orbitdeterminator / doppler_determination / orbdet / utils / utils_aux.py View on Github external
def get_6_oe_from_tle(tle):
    """ Get six orbital elements from given TLE.
    This function is used in the process of generating possible orbital configurations.

    Args:
        tle (list[str]): Two-line element set
    Returns:
        oe (np.ndarray): Array containing eccentricity, semi-major axis, inclination, 
                            right ascension of the ascending node, argument of perigee and mean anomaly
    """
    
    sat = Satrec.twoline2rv(tle[0], tle[1])

    # Orbitral elements
    oe = np.array([sat.ecco,   # Eccentricity
                sat.a,         # Semi-major axis
                sat.inclo,     # Inclination
                sat.nodeo,     # Right ascension of the ascending node
                sat.argpo,     # Argument of perigee
                sat.mo])       # Mean anomaly

    return oe
github bwinkel / cysgp4 / cysgp4 / helpers.py View on Github external
eci_pos = np.empty(tles.shape + (3,), dtype=np.float64)
    eci_vel = np.empty(tles.shape + (3,), dtype=np.float64)

    for u_tle in unique_tles:

        # doesn't work, as array doesn't know tle_strings method
        # mask = u_tle == tles
        mask = np.array(
            [u_tle == t for t in tles.flat], dtype=np.bool
            ).reshape(tles.shape)

        mjd = mjds[mask]

        line1, line2 = u_tle.tle_strings()[1:]

        sat = Satrec.twoline2rv(line1, line2)
        _f, _i = np.modf(mjd)
        err_code, pos, vel = sat.sgp4_array(_i + 2400000.5, _f)

        if np.any(err_code):
            raise ValueError(
                'Satellite propagation error', err_code,
                '({})'.format(SGP4_ERRORS[err_code])
                )

        eci_pos[mask] = pos
        eci_vel[mask] = vel

    return eci_pos, eci_vel
github skyfielders / python-skyfield / skyfield / sgp4lib.py View on Github external
def __init__(self, line1, line2, name=None, ts=None):
        if ts is None:
            ts = self.ts
            if ts is None:
                ts = EarthSatellite.ts = _build_builtin_timescale()

        self.name = None if name is None else name.strip()
        satrec = Satrec.twoline2rv(line1, line2)
        self.model = satrec

        two_digit_year = satrec.epochyr
        if two_digit_year < 57:
            year = two_digit_year + 2000
        else:
            year = two_digit_year + 1900

        self.epoch = ts.utc(year, 1, satrec.epochdays)

        self._setup(satrec)