Debian Codegraph @

PKG-INFO

raw
1 Metadata-Version: 2.1
2 Name: sgp4
3 Version: 2.22
4 Summary: Track Earth satellites given TLE data, using up-to-date 2020 SGP4 routines.
5 Home-page: https://github.com/brandon-rhodes/python-sgp4
6 Author: Brandon Rhodes
7 Author-email: [email protected]
8 License: MIT
9 Classifier: Development Status :: 5 - Production/Stable
10 Classifier: Intended Audience :: Science/Research
11 Classifier: License :: OSI Approved :: MIT License
12 Classifier: Programming Language :: Python :: 2
13 Classifier: Programming Language :: Python :: 2.6
14 Classifier: Programming Language :: Python :: 2.7
15 Classifier: Programming Language :: Python :: 3
16 Classifier: Programming Language :: Python :: 3.3
17 Classifier: Programming Language :: Python :: 3.4
18 Classifier: Programming Language :: Python :: 3.5
19 Classifier: Programming Language :: Python :: 3.6
20 Classifier: Programming Language :: Python :: 3.7
21 Classifier: Programming Language :: Python :: 3.8
22 Classifier: Programming Language :: Python :: 3.9
23 Classifier: Topic :: Scientific/Engineering :: Astronomy
24 License-File: LICENSE
25
26
27 This package compiles the official C++ code from `Revisiting Spacetrack
28 Report #3 <https://celestrak.org/publications/AIAA/2006-6753/>`_ (AIAA
29 2006-6753) and uses it to compute the positions of satellites in Earth
30 orbit. Orbital elements can be read from either a legacy TLE file or
31 from a modern OMM element set, both of which you can fetch from a site
32 like `CelesTrak <https://celestrak.com/>`_.
33
34 If your machine can’t install or compile the C++ code, then this package
35 falls back to using a slower pure-Python implementation of SGP4. Tests
36 make sure that its positions **agree to within 0.1 mm** with the
37 standard version of the algorithm — an error far less than the
38 1–3 km/day by which satellites themselves deviate from the ideal orbits
39 described in TLE files.
40
41 An accelerated routine is available that, given a series of times and of
42 satellites, computes a whole array of output positions using a fast C++
43 loop. See the “Array Acceleration” section below.
44
45 Note that the SGP4 propagator returns raw *x,y,z* Cartesian coordinates
46 in a “True Equator Mean Equinox” (TEME) reference frame that’s centered
47 on the Earth but does not rotate with it — an “Earth centered inertial”
48 (ECI) reference frame. The SGP4 propagator itself does not implement
49 the math to convert these positions into more official ECI frames like
50 J2000 or the ICRS, nor into any Earth-centered Earth-fixed (ECEF) frames
51 like the ITRS, nor into latitudes and longitudes through an Earth
52 ellipsoid like WGS84. For conversions into these other coordinate
53 frames, look for a comprehensive astronomy library, like the `Skyfield
54 <https://rhodesmill.org/skyfield/>`_ library that is built atop this one
55 (see the `section on Earth satellites
56 <https://rhodesmill.org/skyfield/earth-satellites.html>`_ in its
57 documentation).
58
59 Usage
60 -----
61
62 You will probably first want to to check whether your machine has
63 successfully installed the fast SGP4 C++ code, or is using the slow
64 Python version (in which case this value will be false):
65
66 >>> from sgp4.api import accelerated
67 >>> print(accelerated)
68 True
69
70 This library uses the same function names as the official C++ code, to
71 help users who are already familiar with SGP4 in other languages. Here
72 is how to compute the x,y,z position and velocity for the International
73 Space Station at 12:50:19 on 29 June 2000:
74
75 >>> from sgp4.api import Satrec
76 >>>
77 >>> s = '1 25544U 98067A 19343.69339541 .00001764 00000-0 38792-4 0 9991'
78 >>> t = '2 25544 51.6439 211.2001 0007417 17.6667 85.6398 15.50103472202482'
79 >>> satellite = Satrec.twoline2rv(s, t)
80 >>>
81 >>> jd, fr = 2458827, 0.362605
82 >>> e, r, v = satellite.sgp4(jd, fr)
83 >>> e
84 0
85 >>> print(r) # True Equator Mean Equinox position (km)
86 (-6102.44..., -986.33..., -2820.31...)
87 >>> print(v) # True Equator Mean Equinox velocity (km/s)
88 (-1.45..., -5.52..., 5.10...)
89
90 As input, you can provide either:
91
92 * A simple floating-point Julian Date for ``jd`` and the value 0.0 for
93 ``fr``, if you are happy with the precision of a 64-bit floating point
94 number. Note that modern Julian Dates are greater than 2,450,000
95 which means that nearly half of the precision of a 64-bit float will
96 be consumed by the whole part that specifies the day. The remaining
97 digits will provide a precision for the fraction of around 20.1 µs.
98 This should be no problem for the accuracy of your result — satellite
99 positions usually off by a few kilometers anyway, far less than a
100 satellite moves in 20.1 µs — but if you run a solver that dives down
101 into the microseconds while searching for a rising or setting time,
102 the solver might be bothered by the 20.1 µs plateau between each jump
103 in the satellite’s position.
104
105 * Or, you can provide a coarse date ``jd`` plus a very precise fraction
106 ``fr`` that supplies the rest of the value. The Julian Date for which
107 the satellite position is computed is the sum of the two values. One
108 common practice is to provide the whole number as ``jd`` and the
109 fraction as ``fr``; another is to have ``jd`` carry the fraction 0.5
110 since UTC midnight occurs halfway through each Julian Date. Either
111 way, splitting the value allows a solver to run all the way down into
112 the nanoseconds and still see SGP4 respond smoothly to tiny date
113 adjustments with tiny changes in the resulting satellite position.
114
115 Here is how to intrepret the results:
116
117 * ``e`` will be a non-zero error code if the satellite position could
118 not be computed for the given date. You can ``from sgp4.api import
119 SGP4_ERRORS`` to access a dictionary mapping error codes to error
120 messages explaining what each code means.
121
122 * ``r`` measures the satellite position in **kilometers** from the
123 center of the earth in the idiosyncratic True Equator Mean Equinox
124 coordinate frame used by SGP4.
125
126 * ``v`` velocity is the rate at which the position is changing,
127 expressed in **kilometers per second**.
128
129 If your application does not natively handle Julian dates, you can
130 compute ``jd`` and ``fr`` from calendar dates using ``jday()``.
131
132 >>> from sgp4.api import jday
133 >>> jd, fr = jday(2019, 12, 9, 12, 0, 0)
134 >>> jd
135 2458826.5
136 >>> fr
137 0.5
138
139 Double-checking your TLE lines
140 ------------------------------
141
142 Because TLE is an old punch-card fixed-width format, it’s very sensitive
143 to whether exactly the right number of spaces are positioned in exactly
144 the right columns. If you suspect that your satellite elements aren’t
145 getting loaded correctly, try calling the slow pure-Python version of
146 ``twoline2rv()``, which performs extra checks that the fast C++ doesn’t:
147
148 >>> from sgp4.earth_gravity import wgs72
149 >>> from sgp4.io import twoline2rv
150 >>> assert twoline2rv(s, t, wgs72)
151
152 Any TLE formatting errors will be raised as a ``ValueError``.
153
154 Using OMM elements instead of TLE
155 ---------------------------------
156
157 The industry is migrating away from the original TLE format, because it
158 will soon run out of satellite numbers.
159
160 * Some TLE files now use a new “Alpha-5” convention that expands the
161 range of satellite numbers by using an initial letter; for example,
162 “E8493” means satellite 148493. This library supports the Alpha-5
163 convention and should return the correct integer in Python.
164
165 * Some authorities are now distributing satellite elements in an “OMM”
166 Orbit Mean Elements Message format that replaces the TLE format. You
167 can learn about OMM in Dr. T.S. Kelso’s `“A New Way to Obtain GP Data”
168 <https://celestrak.com/NORAD/documentation/gp-data-formats.php>`_ at
169 the CelesTrak site.
170
171 You can already try out experimental support for OMM:
172
173 >>> from sgp4 import omm
174
175 Reading OMM data takes two steps, because OMM supports several different
176 text formats. First, parse the input text to recover the field names
177 and values that it stores; second, build a Python satellite object from
178 those field values. For example, to load OMM from XML:
179
180 >>> with open('sample_omm.xml') as f:
181 ... fields = next(omm.parse_xml(f))
182 >>> sat = Satrec()
183 >>> omm.initialize(sat, fields)
184
185 Or, to load OMM from CSV:
186
187 >>> with open('sample_omm.csv') as f:
188 ... fields = next(omm.parse_csv(f))
189 >>> sat = Satrec()
190 >>> omm.initialize(sat, fields)
191
192 Either way, the satellite object should wind up properly initialized and
193 ready to start producing positions.
194
195 If you are interested in saving satellite parameters using the new OMM
196 format, then read the section on “Export” below.
197
198 Epoch
199 -----
200
201 Over a given satellite’s lifetime, dozens or hundreds of different TLE
202 records will be produced as its orbit evolves. Each TLE record
203 specifies the “epoch date” for which it is most accurate. Typically a
204 TLE is only useful for a couple of weeks to either side of its epoch
205 date, beyond which its predictions become unreliable.
206
207 Satellite objects natively provide their epoch as a two-digit year and
208 then a fractional number of days into the year:
209
210 >>> satellite.epochyr
211 19
212 >>> satellite.epochdays
213 343.69339541
214
215 Because Sputnik was launched in 1957, satellite element sets will never
216 refer to an earlier year, so years 57 through 99 mean 1957–1999 while 0
217 through 56 mean 2000–2056. The TLE format will presumably be obsolete
218 in 2057 and have to be upgraded to 4-digit years.
219
220 To turn the number of days and its fraction into a calendar date and
221 time, use the ``days2mdhms()`` function.
222
223 >>> from sgp4.api import days2mdhms
224 >>> month, day, hour, minute, second = days2mdhms(19, 343.69339541)
225 >>> month
226 12
227 >>> day
228 9
229 >>> hour
230 16
231 >>> minute
232 38
233 >>> second
234 29.363424
235
236 The SGP4 library also translates those two numbers into a Julian date
237 and fractional Julian date, since Julian dates are more commonly used in
238 astronomy.
239
240 >>> satellite.jdsatepoch
241 2458826.5
242 >>> satellite.jdsatepochF
243 0.69339541
244
245 Finally, a convenience function is available in the library if you need
246 the epoch date and time as Python ``datetime``.
247
248 >>> from sgp4.conveniences import sat_epoch_datetime
249 >>> sat_epoch_datetime(satellite)
250 datetime.datetime(2019, 12, 9, 16, 38, 29, 363423, tzinfo=UTC)
251
252 Array Acceleration
253 ------------------
254
255 To avoid the expense of running a Python loop when you have many dates
256 and times for which you want a position, you can pass your Julian dates
257 as arrays. The array routine is only faster if your machine has
258 successfully installed or compiled the SGP4 C++ code, so you might want
259 to check first:
260
261 >>> from sgp4.api import accelerated
262 >>> print(accelerated)
263 True
264
265 To call the array routine, make NumPy arrays for ``jd`` and ``fr`` that
266 are the same length:
267
268 >>> import numpy as np
269 >>> np.set_printoptions(precision=2)
270
271 >>> jd = np.array((2458826, 2458826, 2458826, 2458826))
272 >>> fr = np.array((0.0001, 0.0002, 0.0003, 0.0004))
273
274 >>> e, r, v = satellite.sgp4_array(jd, fr)
275
276 >>> print(e)
277 [0 0 0 0]
278 >>> print(r)
279 [[-3431.31 2620.15 -5252.97]
280 [-3478.86 2575.14 -5243.87]
281 [-3526.09 2529.89 -5234.28]
282 [-3572.98 2484.41 -5224.19]]
283 >>> print(v)
284 [[-5.52 -5.19 1.02]
285 [-5.49 -5.22 1.08]
286 [-5.45 -5.25 1.14]
287 [-5.41 -5.28 1.2 ]]
288
289 To avoid the expense of Python loops when you have many satellites and
290 dates, build a ``SatrecArray`` from several individual satellites. Its
291 ``sgp4()`` method will expect both ``jd`` and ``fr`` to be NumPy arrays,
292 so if you only have one date, be sure to provide NumPy arrays of length
293 one. Here is a sample computation for 2 satellites and 4 dates:
294
295 >>> u = '1 20580U 90037B 19342.88042116 .00000361 00000-0 11007-4 0 9996'
296 >>> w = '2 20580 28.4682 146.6676 0002639 185.9222 322.7238 15.09309432427086'
297 >>> satellite2 = Satrec.twoline2rv(u, w)
298
299 >>> from sgp4.api import SatrecArray
300 >>> a = SatrecArray([satellite, satellite2])
301 >>> e, r, v = a.sgp4(jd, fr)
302
303 >>> np.set_printoptions(precision=2)
304 >>> print(e)
305 [[0 0 0 0]
306 [0 0 0 0]]
307 >>> print(r)
308 [[[-3431.31 2620.15 -5252.97]
309 [-3478.86 2575.14 -5243.87]
310 [-3526.09 2529.89 -5234.28]
311 [-3572.98 2484.41 -5224.19]]
312 <BLANKLINE>
313 [[ 5781.85 2564. -2798.22]
314 [ 5749.36 2618.59 -2814.63]
315 [ 5716.35 2672.94 -2830.78]
316 [ 5682.83 2727.05 -2846.68]]]
317 >>> print(v)
318 [[[-5.52 -5.19 1.02]
319 [-5.49 -5.22 1.08]
320 [-5.45 -5.25 1.14]
321 [-5.41 -5.28 1.2 ]]
322 <BLANKLINE>
323 [[-3.73 6.33 -1.91]
324 [-3.79 6.3 -1.88]
325 [-3.85 6.28 -1.85]
326 [-3.91 6.25 -1.83]]]
327
328 Export
329 ------
330
331 If you have a ``Satrec`` you want to share with friends or persist to a
332 file, there’s an export routine that will turn it back into a TLE:
333
334 >>> from sgp4 import exporter
335 >>> line1, line2 = exporter.export_tle(satellite)
336 >>> line1
337 '1 25544U 98067A 19343.69339541 .00001764 00000-0 38792-4 0 9991'
338 >>> line2
339 '2 25544 51.6439 211.2001 0007417 17.6667 85.6398 15.50103472202482'
340
341 Happily, these are exactly the two TLE lines that we used to create this
342 satellite object:
343
344 >>> (s == line1) and (t == line2)
345 True
346
347 Another export routine is available that produces the fields defined by
348 the new OMM format (see the “OMM” section above):
349
350 >>> from pprint import pprint
351 >>> fields = exporter.export_omm(satellite, 'ISS (ZARYA)')
352 >>> pprint(fields)
353 {'ARG_OF_PERICENTER': 17.6667,
354 'BSTAR': 3.8792e-05,
355 'CENTER_NAME': 'EARTH',
356 'CLASSIFICATION_TYPE': 'U',
357 'ECCENTRICITY': 0.0007417,
358 'ELEMENT_SET_NO': 999,
359 'EPHEMERIS_TYPE': 0,
360 'EPOCH': '2019-12-09T16:38:29.363423',
361 'INCLINATION': 51.6439,
362 'MEAN_ANOMALY': 85.6398,
363 'MEAN_ELEMENT_THEORY': 'SGP4',
364 'MEAN_MOTION': 15.501034720000002,
365 'MEAN_MOTION_DDOT': 0.0,
366 'MEAN_MOTION_DOT': 1.764e-05,
367 'NORAD_CAT_ID': 25544,
368 'OBJECT_ID': '1998-067A',
369 'OBJECT_NAME': 'ISS (ZARYA)',
370 'RA_OF_ASC_NODE': 211.2001,
371 'REF_FRAME': 'TEME',
372 'REV_AT_EPOCH': 20248,
373 'TIME_SYSTEM': 'UTC'}
374
375 Gravity
376 -------
377
378 The SGP4 algorithm operates atop a set of constants specifying how
379 strong the Earth’s gravity is. The most recent official paper on SGP4
380 (see below) specifies that “We use WGS-72 as the default value”, so this
381 Python module uses the same default. But in case you want to use either
382 the old legacy version of the WGS-72 constants, or else the non-standard
383 but more modern WGS-84 constants, the ``twoline2rv()`` constructor takes
384 an optional argument:
385
386 >>> from sgp4.api import WGS72OLD, WGS72, WGS84
387 >>> satellite3 = Satrec.twoline2rv(s, t, WGS84)
388
389 You will in general get less accurate results if you choose WGS-84.
390 Even though it reflects more recent and accurate measures of the Earth,
391 satellite TLEs across the industry are most likely generated with WGS-72
392 as their basis. The positions you generate will better agree with the
393 real positions of each satellite if you use the same underlying gravity
394 constants as were used to generate the TLE.
395
396 Providing your own elements
397 ---------------------------
398
399 If instead of parsing a TLE you want to specify orbital elements
400 directly, you can pass them as floating point numbers to a satellite
401 object’s ``sgp4init()`` method. For example, here’s how to build the
402 same International Space Station orbit that we loaded from a TLE in the
403 first code example above:
404
405 >>> satellite2 = Satrec()
406 >>> satellite2.sgp4init(
407 ... WGS72, # gravity model
408 ... 'i', # 'a' = old AFSPC mode, 'i' = improved mode
409 ... 25544, # satnum: Satellite number
410 ... 25545.69339541, # epoch: days since 1949 December 31 00:00 UT
411 ... 3.8792e-05, # bstar: drag coefficient (1/earth radii)
412 ... 0.0, # ndot: ballistic coefficient (radians/minute^2)
413 ... 0.0, # nddot: mean motion 2nd derivative (radians/minute^3)
414 ... 0.0007417, # ecco: eccentricity
415 ... 0.3083420829620822, # argpo: argument of perigee (radians)
416 ... 0.9013560935706996, # inclo: inclination (radians)
417 ... 1.4946964807494398, # mo: mean anomaly (radians)
418 ... 0.06763602333248933, # no_kozai: mean motion (radians/minute)
419 ... 3.686137125541276, # nodeo: R.A. of ascending node (radians)
420 ... )
421
422 These numbers don’t look the same as the numbers in the TLE, because the
423 underlying ``sgp4init()`` routine uses different units: radians rather
424 than degrees. But this is the same orbit and will produce the same
425 positions.
426
427 Note that ``ndot`` and ``nddot`` are ignored by the SGP4 propagator, so
428 you can leave them ``0.0`` without any effect on the resulting satellite
429 positions. But they do at least get saved to the satellite object, and
430 written out if you write the parameters to a TLE or OMM file (see the
431 “Export” section, above).
432
433 To compute the “epoch” argument, take the epoch’s Julian date and
434 subtract 2433281.5 days.
435
436 While the underlying ``sgp4init()`` routine leaves the attributes
437 ``epochyr``, ``epochdays``, ``jdsatepoch``, and ``jdsatepochF`` unset,
438 this library goes ahead and sets them anyway for you, using the epoch
439 you provided.
440
441 See the next section for the complete list of attributes that are
442 available from the satellite record once it has been initialized.
443
444 Attributes
445 ----------
446
447 There are several dozen ``Satrec`` attributes that expose data from the
448 underlying C++ SGP4 record. They fall into the following categories.
449
450 *Identification*
451
452 These are copied directly from the TLE record but aren’t used by the
453 propagation math.
454
455 | ``satnum_str`` — Satellite number, as a 5-character string.
456 | ``satnum`` — Satellite number, converted to an integer.
457 | ``classification`` — ``'U'``, ``'C'``, or ``'S'``
458 indicating the element set is Unclassified, Classified, or Secret.
459 | ``ephtype`` — Integer “ephemeris type”, used internally by space
460 agencies to mark element sets that are not ready for publication;
461 this field should always be ``0`` in published TLEs.
462 | ``elnum`` — Element set number.
463 | ``revnum`` — Satellite’s revolution number at the moment of the epoch,
464 presumably counting from 1 following launch.
465
466 *Orbital Elements*
467
468 These are the orbital parameters, copied verbatim from the text of the
469 TLE record. They describe the orbit at the moment of the TLE’s epoch
470 and so remain constant even as the satellite record is used over and
471 over again to propagate positions for different times.
472
473 | ``epochyr`` — Epoch date: the last two digits of the year.
474 | ``epochdays`` — Epoch date: the number of days into the year,
475 including a decimal fraction for the UTC time of day.
476 | ``ndot`` — First time derivative of the mean motion
477 (loaded from the TLE, but otherwise ignored).
478 | ``nddot`` — Second time derivative of the mean motion
479 (loaded from the TLE, but otherwise ignored).
480 | ``bstar`` — Ballistic drag coefficient B* (1/earth radii).
481 | ``inclo`` — Inclination (radians).
482 | ``nodeo`` — Right ascension of ascending node (radians).
483 | ``ecco`` — Eccentricity.
484 | ``argpo`` — Argument of perigee (radians).
485 | ``mo`` — Mean anomaly (radians).
486 | ``no_kozai`` — Mean motion (radians/minute).
487 | ``no`` — Alias for ``no_kozai``, for compatibility with old code.
488
489 You can also access the epoch as a Julian date:
490
491 | ``jdsatepoch`` — Whole part of the epoch’s Julian date.
492 | ``jdsatepochF`` — Fractional part of the epoch’s Julian date.
493
494 *Computed Orbit Properties*
495
496 These are computed when the satellite is first loaded,
497 as a convenience for callers who might be interested in them.
498 They aren’t used by the SGP4 propagator itself.
499
500 | ``a`` — Semi-major axis (earth radii).
501 | ``altp`` — Altitude of the satellite at perigee
502 (earth radii, assuming a spherical Earth).
503 | ``alta`` — Altitude of the satellite at apogee
504 (earth radii, assuming a spherical Earth).
505 | ``argpdot`` — Rate at which the argument of perigee is changing
506 (radians/minute).
507 | ``gsto`` — Greenwich Sidereal Time at the satellite’s epoch (radians).
508 | ``mdot`` — Rate at which the mean anomaly is changing (radians/minute)
509 | ``nodedot`` — Rate at which the right ascension of the ascending node
510 is changing (radians/minute).
511
512 *Propagator Mode*
513
514 | ``operationmode`` — A single character that directs SGP4
515 to either operate in its modern ``'i'`` improved mode
516 or in its legacy ``'a'`` AFSPC mode.
517 | ``method`` — A single character, chosen automatically
518 when the orbital elements were loaded, that indicates whether SGP4
519 has chosen to use its built-in ``'n'`` Near Earth
520 or ``'d'`` Deep Space mode for this satellite.
521
522 *Result of Most Recent Propagation*
523
524 | ``t`` —
525 The time you gave when you most recently asked SGP4
526 to compute this satellite’s position,
527 measured in minutes before (negative) or after (positive)
528 the satellite’s epoch.
529 | ``error`` —
530 Error code produced by the most recent SGP4 propagation
531 you performed with this element set.
532
533 The possible ``error`` codes are:
534
535 0. No error.
536 1. Mean eccentricity is outside the range 0 ≤ e < 1.
537 2. Mean motion has fallen below zero.
538 3. Perturbed eccentricity is outside the range 0 ≤ e ≤ 1.
539 4. Length of the orbit’s semi-latus rectum has fallen below zero.
540 5. (No longer used.)
541 6. Orbit has decayed: the computed position is underground.
542 (The position is still returned, in case the vector is helpful
543 to software that might be searching for the moment of re-entry.)
544
545 *Mean Elements From Most Recent Propagation*
546
547 Partway through each propagation, the SGP4 routine saves a set of
548 “singly averaged mean elements” that describe the orbit’s shape at the
549 moment for which a position is being computed. They are averaged with
550 respect to the mean anomaly and include the effects of secular gravity,
551 atmospheric drag, and — in Deep Space mode — of those pertubations from
552 the Sun and Moon that SGP4 averages over an entire revolution of each of
553 those bodies. They omit both the shorter-term and longer-term periodic
554 pertubations from the Sun and Moon that SGP4 applies right before
555 computing each position.
556
557 | ``am`` — Average semi-major axis (earth radii).
558 | ``em`` — Average eccentricity.
559 | ``im`` — Average inclination (radians).
560 | ``Om`` — Average right ascension of ascending node (radians).
561 | ``om`` — Average argument of perigee (radians).
562 | ``mm`` — Average mean anomaly (radians).
563 | ``nm`` — Average mean motion (radians/minute).
564
565 *Gravity Model Parameters*
566
567 When the satellite record is initialized, your choice of gravity model
568 results in a slate of eight constants being copied in:
569
570 | ``tumin`` — Minutes in one “time unit”.
571 | ``xke`` — The reciprocal of ``tumin``.
572 | ``mu`` — Earth’s gravitational parameter (km³/s²).
573 | ``radiusearthkm`` — Radius of the earth (km).
574 | ``j2``, ``j3``, ``j4`` — Un-normalized zonal harmonic values J₂, J₃, and J₄.
575 | ``j3oj2`` — The ratio J₃/J₂.
576
577 Printing satellite attributes
578 -----------------------------
579
580 If you want to print out a satellite, this library provides a convenient
581 “attribute dump” routine that takes a satellite and generates lines that
582 list its attributes::
583
584 from sys import stdout
585 from sgp4.conveniences import dump_satrec
586
587 stdout.writelines(dump_satrec(satellite))
588
589 If you want to compare two satellites, then simply pass a second
590 argument; the second satellite’s attributes will be printed in a second
591 column next to those of the first. ::
592
593 stdout.writelines(dump_satrec(satellite, satellite2))
594
595 Validation against the official algorithm
596 -----------------------------------------
597
598 This implementation passes all of the automated tests in the August 2010
599 release of the reference implementation of SGP4 by Vallado et al., who
600 originally published their revision of SGP4 in 2006:
601
602 Vallado, David A., Paul Crawford, Richard Hujsak, and T.S. Kelso,
603 “Revisiting Spacetrack Report #3,” presented at the AIAA/AAS
604 Astrodynamics Specialist Conference, Keystone, CO, 2006 August
605 21–24.
606
607 If you would like to review the paper, it is `available online
608 <https://www.celestrak.com/publications/AIAA/2006-6753/>`_. You can
609 always download the latest version of their code for comparison against
610 this Python module (or other implementations) at `AIAA-2006-6753.zip
611 <https://www.celestrak.com/publications/AIAA/2006-6753/AIAA-2006-6753.zip>`_.
612
613 For developers
614 --------------
615
616 Developers can check out this full project from GitHub:
617
618 https://github.com/brandon-rhodes/python-sgp4
619
620 To run its unit tests, install Python 2, Python 3, and the ``tox``
621 testing tool. The tests runing in Python 2 will exercise the fallback
622 pure-Python version of the routines, while Python 3 exercises the fast
623 new C++ accelerated code::
624
625 cd python-sgp4
626 tox
627
628 Legacy API
629 ----------
630
631 Before this library pivoted to wrapping Vallado's official C++ code and
632 was operating in pure Python only, it had a slightly quirkier API, which
633 is still supported for compatibility with older clients. You can learn
634 about it by reading the documentation from version 1.4 or earlier:
635
636 https://pypi.org/project/sgp4/1.4/
637
638 Changelog
639 ---------
640
641 2023-04-27 — 2.22
642
643 * Added a ``satnum_str`` attribute, exposing the fact that the C++ now
644 stores the satellite number as a string; and check that ``satnum`` is
645 never greater than 339999.
646
647 * Fixed the units of the ``nddot`` attribute when the value is loaded
648 from an OMM record. (Since the TLE computation itself ignores this
649 attribute, this did not affect any satellite positions.)
650
651 * Enhanced the fallback Python version of ``twoline2rv()`` to verify
652 that TLE lines are ASCII, and added documentation using it to
653 double-check TLEs that might suffer from non-ASCII characters.
654
655 * If the user doesn’t set a satellite’s ``classification``, it now
656 defaults to ``'U'`` for ‘unclassified’.
657
658 2022-04-06 — 2.21
659
660 * Added ``dump_satrec()`` to the ``sgp4.conveniences`` module.
661
662 * Fixed the ``Satrec`` attribute ``.error``, which was previously
663 building a nonsense integer from the wrong data in memory.
664
665 * Removed ``.whichconst`` from Python ``Satrec``, to help users avoid
666 writing code that will break when the C++ extension is available.
667
668 2021-07-01 — 2.20
669
670 * Taught ``sgp4init()`` to round both ``epochdays`` and ``jdsatepochF``
671 to the same 8 decimal places used for the date fraction in a TLE, if
672 the user-supplied ``epoch`` itself has 8 or fewer digits behind the
673 decimal point. This should make it easier to build satellites that
674 round-trip to TLE format with perfect accuracy.
675
676 * Fixed how ``export_tle()`` formats the BSTAR field when its value, if
677 written in scientific notation, has a positive exponent.
678
679 * Fixed the ``epochyr`` assigned by ``sgp4init()`` so years before 2000
680 have two digits instead of three (for example, so that 1980 produces
681 an ``epochyr`` of 80 instead of 980).
682
683 2021-04-22 — 2.19
684
685 * Extended the documentation on the Python Package Index and in the
686 module docstring so it lists every ``Satrec`` attribute that this
687 library exposes; even the more obscure ones might be useful to folks
688 working to analyze satellite orbits.
689
690 2021-03-08 — 2.18
691
692 * If a TLE satellite number lacks the required 5 digits,
693 ``twoline2rv()`` now gives the underlying C++ library a little help so
694 it can still parse the classification and international designator
695 correctly.
696
697 * The ``Satrec`` attributes ``jdsatepoch``, ``jdsatepochF``,
698 ``epochyr``, and ``epochdays`` are now writeable, so users can adjust
699 their values manually — which should make up for the fact that the
700 ``sgp4init()`` method can’t set them with full floating point
701 precision.
702
703 | 2021-02-17 — 2.17 — Fixed where in the output array the ``sgp4_array()`` method writes NaN values when an SGP4 propagation fails.
704 | 2021-02-12 — 2.16 — Fixed ``days2mdhms()`` rounding to always match TLE epoch.
705 | 2021-01-08 — 2.15 — Fixed parsing of the ``satnum`` TLE field in the Python fallback code, when the field has a leading space; added OMM export routine.
706 | 2020-12-16 — 2.14 — New data formats: added OMM message support for both XML and CSV, and added support for the new Alpha-5 extension to TLE files.
707 | 2020-10-14 — 2.13 — Enhanced ``sgp4init()`` with custom code that also sets the ``epochdays`` and ``epochyr`` satellite attributes.
708 | 2020-05-28 — 2.12 — Moved the decision of whether to set the locale during ``twoline2rv()`` from import time to runtime, for users who change locales after their application is up and running.
709 | 2020-05-24 — 2.11 — Fixed a regression in how dates are split into hours, minutes, and seconds that would sometimes produce a time whose second=60, crashing the pure-Python version of the library.
710 | 2020-05-22 — 2.10 — Switch the locale temporarily to ``C`` during the C++ accelerated ``twoline2rv()``, since it does not protect its ``sscanf()`` calls from locales that, like German, expect comma decimal points instead of the period decimal points always used in a TLE.
711 | 2020-05-21 — 2.9 — Added ``sat_epoch_datetime()``, expanded documentation around converting a satellite epoch to a date and time, and started rounding the epoch to exactly the digits provided in the TLE; and removed the ``Satrec.epoch`` attribute from Python fallback code to better match the C++ version.
712 | 2020-05-07 — 2.8 — New function ``jday_datetime()`` is now available in the ``sgp4.conveniences`` module, thanks to Egemen Imre.
713 | 2020-04-24 — 2.7 — New method ``sgp4init()`` (thank you, Chris Lewicki!) is available.
714 | 2020-04-20 — 2.6 — New routine ``export_tle()`` (thank you, Egemen Imre!) is available. Improved how the accelerated C++ backend parses the ``intldesg`` string and the ``revnum`` integer.
715 | 2020-03-22 — 2.5 — Gave the new accelerated ``twoline2rv()`` an optional argument that lets the user choose a non-standard set of gravity constants.
716 | 2020-02-25 — 2.4 — Improved the ``jday()`` docstring; made the old legacy Python resilient if the day of the month is out-of-range (past the end of the month) in a TLE; and Mark Rutten fixed the C++ so it compiles on Windows!
717 | 2020-02-04 — 2.3 — Removed experimental code that caused performance problems for users with Numba installed.
718 | 2020-02-02 — 2.2 — A second release on Palindrome Day: fix the Satrec ``.epochyr`` attribute so it behaves the same way in Python as it does in the official C library, where it is only the last 2 digits of the year; and make ``.no`` available in the Python fallback case as well.
719 | 2020-02-02 — 2.1 — Add vectorized array method to Satrec object; add ``.no`` attribute to new Satrec object to support old code that has not migrated to the new name ``.no_kozai``; gave Python wrapper classes ``__slots__`` to avoid the expense of a per-object attribute dictionary.
720 | 2020-01-30 — 2.0 — Rewrite API to use genuine Vallado C++ code on those systems where it can be compiled; add accelerated vectorized array interface; make ``gstime()`` a public function; clarify format error message.
721 | 2015-01-15 — 1.4 — Display detailed help when TLE input does not match format.
722 | 2014-06-26 — 1.3 — Return ``(NaN,NaN,NaN)`` vectors on error and set ``.error_message``
723 | 2013-11-29 — 1.2 — Made ``epochyr`` 4 digits; add ``datetime`` for ``.epoch``
724 | 2012-11-22 — 1.1 — Python 3 compatibility; more documentation
725 | 2012-08-27 — 1.0 — Initial release
726