Track earth satellite TLE orbits using up-to-date 2010 version of SGP4
Project description
This Python package computes the position and velocity of an earth-orbiting satellite, given the satellite’s TLE orbital elements from a source like Celestrak. It implements the most recent version of SGP4, and is regularly run against the SGP4 test suite to make sure that its satellite position predictions agree to within 0.1 mm with the predictions of the standard distribution of the algorithm. This error is far less than the 1–3 km/day by which satellites themselves deviate from the ideal orbits described in TLE files.
If your platform supports it, this package compiles the verbatim source code from the official C++ version of SGP4. You can call the routine directly, or through an array API that loops over arrays of satellites and arrays of times with machine code instead of Python.
Otherwise, a slower but reliable Python implementation of SGP4 is used instead.
Note that this package produces raw Earth-centered Earth-fixed coordinates. It does not implement all the steps necessary to convert satellite positions into geographic coordinates. For that, look for a comprehensive astronomy library that is built atop this one, like the Skyfield library:
http://rhodesmill.org/skyfield/earth-satellites.html
To run the test suite for this module, clone its repository from GitHub:
https://github.com/brandon-rhodes/python-sgp4
Then invoke the tests using the Python Standard Library:
python -m unittest discover sgp4
The C++ function names have been retained, since users may already be familiar with this library in other languages. Here is how to compute the x,y,z position and velocity for Vanguard 1 at 12:50:19 on 29 June 2000:
>>> from sgp4.api import Satrec >>> >>> s = '1 25544U 98067A 19343.69339541 .00001764 00000-0 38792-4 0 9991' >>> t = '2 25544 51.6439 211.2001 0007417 17.6667 85.6398 15.50103472202482' >>> satellite = Satrec.twoline2rv(s, t) >>> >>> jd, fr = 2458827, 0.362605 >>> e, r, v = satellite.sgp4(jd, fr) >>> e 0 >>> print(r) (-6102.44..., -986.33..., -2820.31...) >>> print(v) (-1.45..., -5.52..., 5.10...)
Here is how to intrepret the results:
e will be a non-zero error code if the satellite position could not be computed for the given date. You can from sgp4.api import SGP4_ERRORS to access a dictionary mapping error codes to error messages explaining what each code means.
r measures the satellite position in kilometers from the center of the earth in the idiosyncratic True Equator Mean Equinox coordinate frame used by SGP4.
v velocity is the rate at which the position is changing, expressed in kilometers per second.
If your application does not natively handle Julian dates, you can compute jd and fr from calendar dates using jday().
>>> from sgp4.api import jday >>> jd, fr = jday(2019, 12, 9, 12, 0, 0) >>> jd 2458826.5 >>> fr 0.5
To avoid the expense of Python loops when you have many dates, you can pass them as arrays to another method that understands NumPy:
>>> import numpy as np >>> np.set_printoptions(precision=2)
>>> jd = np.array((2458826, 2458826, 2458826, 2458826)) >>> fr = np.array((0.0001, 0.0002, 0.0003, 0.0004))
>>> e, r, v = satellite.sgp4_array(jd, fr)
>>> print(e) [0 0 0 0] >>> print(r) [[-3431.31 2620.15 -5252.97] [-3478.86 2575.14 -5243.87] [-3526.09 2529.89 -5234.28] [-3572.98 2484.41 -5224.19]] >>> print(v) [[-5.52 -5.19 1.02] [-5.49 -5.22 1.08] [-5.45 -5.25 1.14] [-5.41 -5.28 1.2 ]]
To avoid the expense of Python loops when you have many satellites and dates, build a SatrecArray from several individual satellites. Its sgp4() method will expect both jd and fr to be NumPy arrays, so if you only have one date, be sure to provide NumPy arrays of length one. Here is a sample computation for 2 satellites and 4 dates:
>>> s = '1 20580U 90037B 19342.88042116 .00000361 00000-0 11007-4 0 9996' >>> t = '2 20580 28.4682 146.6676 0002639 185.9222 322.7238 15.09309432427086' >>> satellite2 = Satrec.twoline2rv(s, t)
>>> from sgp4.api import SatrecArray >>> a = SatrecArray([satellite, satellite2]) >>> e, r, v = a.sgp4(jd, fr)
>>> np.set_printoptions(precision=2) >>> print(e) [[0 0 0 0] [0 0 0 0]] >>> print(r) [[[-3431.31 2620.15 -5252.97] [-3478.86 2575.14 -5243.87] [-3526.09 2529.89 -5234.28] [-3572.98 2484.41 -5224.19]] <BLANKLINE> [[ 5781.85 2564. -2798.22] [ 5749.36 2618.59 -2814.63] [ 5716.35 2672.94 -2830.78] [ 5682.83 2727.05 -2846.68]]] >>> print(v) [[[-5.52 -5.19 1.02] [-5.49 -5.22 1.08] [-5.45 -5.25 1.14] [-5.41 -5.28 1.2 ]] <BLANKLINE> [[-3.73 6.33 -1.91] [-3.79 6.3 -1.88] [-3.85 6.28 -1.85] [-3.91 6.25 -1.83]]]
The attributes of a Satrec object carry the data loaded from the TLE entry. Most of this class’s hundred-plus attributes are intermediate values of interest only to the propagation algorithm itself. Here are the attributes set by sgp4.io.twoline2rv() in which users are likely to be interested:
- satnum
Unique satellite number given in the TLE file.
- epochyr
Full four-digit year of this element set’s epoch moment.
- epochdays
Fractional days into the year of the epoch moment.
- jdsatepoch
Julian date of the epoch (computed from epochyr and epochdays).
- ndot
First time derivative of the mean motion (ignored by SGP4).
- nddot
Second time derivative of the mean motion (ignored by SGP4).
- bstar
Ballistic drag coefficient B* in inverse earth radii.
- inclo
Inclination in radians.
- nodeo
Right ascension of ascending node in radians.
- ecco
Eccentricity.
- argpo
Argument of perigee in radians.
- mo
Mean anomaly in radians.
- no_kozai
Mean motion in radians per minute.
Look at the class’s documentation for details.
This implementation passes all of the automated tests in the August 2010 release of the reference implementation of SGP4 by Vallado et al., who originally published their revision of SGP4 in 2006:
Vallado, David A., Paul Crawford, Richard Hujsak, and T.S. Kelso, “Revisiting Spacetrack Report #3,” presented at the AIAA/AAS Astrodynamics Specialist Conference, Keystone, CO, 2006 August 21–24.
If you would like to review the paper, it is available online. You can always download the latest version of their code for comparison against this Python module (or other implementations) at AIAA-2006-6753.zip.
Legacy API
Before this library pivoted to wrapping Vallado’s official C++ code and was operating in pure Python only, it had a slightly quirkier API, which is still supported for compatibility with older clients. You can learn about it by reading the documentation from version 1.4 or earlier:
Changelog
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for sgp4-2.3-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42961de4c80a65f0437d684dfd18db22273e8eef7cb362dd4dec12f104d49ea2 |
|
MD5 | 3a03357b1898f1ccc3aa3696c96e57e4 |
|
BLAKE2b-256 | cae517588785f5a2cc5b0d5219f63dd5c17d463240afa5fe3f084208fcd050c9 |
Hashes for sgp4-2.3-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 098eee7227704d8c9a720f4086572835d40dc6382d3bffd15ec1e51e24e21fff |
|
MD5 | acbab4da77943a67ef4dca79e5cf6e5c |
|
BLAKE2b-256 | 09b085239b901f7650ef7d0c76450ca7f9d622609e9a26a7e05145b8916e687c |
Hashes for sgp4-2.3-cp38-cp38-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | af4db701bb6ceb62efb0a275201d6afc83109ea8607d8c80476bd9830bb846e9 |
|
MD5 | bd1b14d9e78e8cc980a2e1e53bfa9607 |
|
BLAKE2b-256 | 2ea7e78b79bc8cafeacd2431d540739bf066bd391300c5f6db2fd87448e00cc5 |
Hashes for sgp4-2.3-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | be8ba420bb95b5c5a46e06ac7cb2a6a0c4b55910e7c6ad136006b8024ea49285 |
|
MD5 | 08cfa84c60461f331f4def00c4b0346c |
|
BLAKE2b-256 | 507b50516c704054af00a548ce56bb0ed7a05b46dbc518e5332a0cb1a455d4d8 |
Hashes for sgp4-2.3-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 644d29c1aa756a035ac9b2f57f8bf6a9548be8f8bd5015178760abed6d12a9d5 |
|
MD5 | 9969c1764c2667d2e7c883f1ad0bed03 |
|
BLAKE2b-256 | 467356f87c8996a5ee5dd3d7492cb030be9987b693fdea6ac18d6f06c8ca0a37 |
Hashes for sgp4-2.3-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2e2c25fb04f63c0ff87943c7b9fb78292d77880460d86546d5ccb5bd175c03c |
|
MD5 | c0319a7783f2ea61ce7bcf27b6495c9e |
|
BLAKE2b-256 | a847feb6a2d0d1f2fe4f9266778873be3125de06a29f548d9da8ee6e71db0c9e |
Hashes for sgp4-2.3-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b4e845be370d7b8d55d83849dd55612153c5cbdcd142d5f2baa4e30bfe3ca66 |
|
MD5 | 18d3d36c22a260c6dad43bef48e67a6c |
|
BLAKE2b-256 | 065fb9290d2407e1bbe5bab2a262d29e7cc590e355f7bf0f443f475915fe2736 |
Hashes for sgp4-2.3-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb2a9a9c96e5045100b90d37cb937aa5ea982a011c8314568e002b2bcf16f6e5 |
|
MD5 | 4ac78dbfc6a33afc53eec58c9a80f893 |
|
BLAKE2b-256 | 0a5b422c681b2bfc31c5088a9b909a8e7a78da325fce7a901703559a5bb1c22e |
Hashes for sgp4-2.3-cp37-cp37m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2960999e167cb3ded9857ea511467fd1e9a4ac7c75b4ecd2e1ffc758baf80038 |
|
MD5 | bc143b1778df220c509fb0435888725d |
|
BLAKE2b-256 | 7f342ae85864322c0e440d273eab911aab843843fc6f455c10378a521859d280 |
Hashes for sgp4-2.3-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e2df598f1f9cdc1a2aa74c45f95e5b913c6df0edce62292cb4e4ca5c3b9b582e |
|
MD5 | f3b4e9e03aec24d4111abbf34bb51732 |
|
BLAKE2b-256 | e57701593e71bda988b94402169e01f548b2ee1818ad5592bde20ecd538e967e |
Hashes for sgp4-2.3-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7edde5606942e8d72e74d8792835db24f783d59e3b44cf6ba28ade4651ff513d |
|
MD5 | 2699359f8f3f5a21fd3983d4eae0fb0a |
|
BLAKE2b-256 | 327a79d2b341e6ead08a9d355a7b465297d21782df8b1b6bb3b84aca9767dd6f |
Hashes for sgp4-2.3-cp37-cp37m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8056ed80c546a1fb14db4ff42c6dc53e909ef20051a8245d291d7cc679d403e8 |
|
MD5 | 2f9017f71cc855a55bdf124810836170 |
|
BLAKE2b-256 | 823e6554efea143aa45ce8f958c82b57014a27c0130d37c4e2d4ced5ff5fdb92 |
Hashes for sgp4-2.3-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 406cdb4ea2273856797ff2f7df1b9da897cbfebd3262bc00b946da27f5b11100 |
|
MD5 | 58396f7de6ecd136291f49b365819a75 |
|
BLAKE2b-256 | f9465ab3aeba503b1e62f4e4ca2861b00823d99182e5cfa919b03f8eb46d2e4a |
Hashes for sgp4-2.3-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 504912688f7bce4130131a8a3cb1b6b216f8a97f79eb71427ca30ed5760fef03 |
|
MD5 | b7b8b96a72fc1ad7058cb118d292edf2 |
|
BLAKE2b-256 | 22278b29e3f2c26dc9023d6219794c6effb5e06218d6f3c4abd05c32f37f89bc |
Hashes for sgp4-2.3-cp36-cp36m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7abfde5a9fbfc844876e0baf33aa36c1cf986fce12a8588062e3095ab23e9da |
|
MD5 | 597f1722a0c44b3ae87087bf02fe4df1 |
|
BLAKE2b-256 | 274d715282567e4a1207aecce2229e62aa5b2c298ecbc6be124e2a61d70cc3e2 |
Hashes for sgp4-2.3-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2fded15ecc78b69878299196eafde3d1ac4f6fc70ddb7a2b160a4834562f5ff2 |
|
MD5 | 7e344901ce9b7b17a08dd0e46bb8b134 |
|
BLAKE2b-256 | 0827fa1655f519780e01a0c5054ffb0339edec1b896485a9a6f7807e5bce0acd |
Hashes for sgp4-2.3-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d7d4f73bfa3d90aeeaaf96452b2c7465b2e3a2e63c265b98ed84b5dc48af9980 |
|
MD5 | 1b7f150ac0414756ae4cb671b1bf4be9 |
|
BLAKE2b-256 | c80f9f71c421895f1bbc5f70d52d27abf27196aa29edded847ea801c8b23350c |
Hashes for sgp4-2.3-cp36-cp36m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02a26a7c267fd310b7d3563f37029cb2456a1262538c31dc1c637c7cd6c6ccf4 |
|
MD5 | 93569280413bd053dcfda50bb831effe |
|
BLAKE2b-256 | 2d381620198eb1e9280f8644b330cb4ab4cdf554e1ce6fe7260739ae296bf02e |
Hashes for sgp4-2.3-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dfb541838e7ead5267c2598401cefbb10507d920d6d34980ccd4606e306d9416 |
|
MD5 | 6a409ec770bd0698d3a2fcd5bfe2b21e |
|
BLAKE2b-256 | 43b9bae7aabd08af2202db777821545584afdd7222d2c0350b3b162b6d7cef1a |
Hashes for sgp4-2.3-cp35-cp35m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 346c0aa9cd3abe92a7d3ed987bf32614bb396f6e8bf6eb5728afa48719970a9a |
|
MD5 | e0c35eb7ce8f70b849fdc38a9240aeb3 |
|
BLAKE2b-256 | 48f76190fb59da37fa5c92a91e82d51d8ac40501250bbfef237aec60e310414a |
Hashes for sgp4-2.3-cp35-cp35m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f43a9f32e50159cc45ef3c519f18a77f22a48b05d57be1ab1ce0c9c8b7c508a1 |
|
MD5 | 666441d81a993de7ec67d9223343b5b5 |
|
BLAKE2b-256 | 3b0834ce4c46f3c495b1cf3bc17bc880f259de4025254161ff3eff9446df8015 |
Hashes for sgp4-2.3-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fbeaa49e994647cc2af9615fd4325ed41d7d6a88a89461156595501b38e06bb6 |
|
MD5 | 91fa612a9556a99c77901d47f9c6193c |
|
BLAKE2b-256 | 02877a0225d5af6d7357ff143635b4b746eda82cf4277613129ad14043e245d2 |
Hashes for sgp4-2.3-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c2319da0e6c196f00fc2db8672fb19eb4342eff6a6ec32a101c6c96492b39b3 |
|
MD5 | 687d97241e72b3e909174ea556c1e14b |
|
BLAKE2b-256 | 377ebfcb82ad66b97d55be3859cef52977b5603cca9d8488e8898eb37a870ff0 |
Hashes for sgp4-2.3-cp35-cp35m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 36b636d1b01a682ba01eb89fd72ab4399d49eda9ed5d15c9300c4315c314accd |
|
MD5 | 5716941a6768452679c13dd06f4c3c47 |
|
BLAKE2b-256 | b208bcb6b28499b4ae74542595667eb2c404a70e128adb72fd5464000c70aca3 |