question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Once the TLE data has been loaded, is there a way to retreive the TLEs for use in sgp4?

See original GitHub issue

What is the procedure to extract the individual TLEs using Skyfield for input into sgp4? I’ve been able to get Skyfield to load the data from Celestrack, but I’m having difficulty extracting the individual TLEs. The code I’m using follows.

from skyfield.api import Topos, load

import numpy    as np
import spiceypy

from datetime import datetime, timedelta
from sgp4.earth_gravity import wgs84
from sgp4.io import twoline2rv

# --------------------------------------------------------------------------
# --------------------------------------------------------------------------

stations_url = 'https://celestrak.com/satcat/tle.php?INTDES=1987%2D060'
TLEs = load.tle_file(stations_url)
print('Loaded', len(TLEs), 'satellites')

# --------------------------------------------------------------------------
# --------------------------------------------------------------------------

satnum_list = open('COSMOS_1867_Coolant_IDs.dat', 'r')

# --------------------------------------------------------------------------
# --------------------------------------------------------------------------

for satnum in satnum_list:
     by_number = {sat.model.satnum: sat for sat in TLEs}
     sat = by_number[int(satnum)]
     print(sat, sat.epoch.utc_jpl())

# --------------------------------------------------------------------------
# --------------------------------------------------------------------------

for line1, line2, line3 in TLEs:
     print(line1)
     print(line2)
     print(line3)

The resulting output follows.


================================================================================
July 23, 2020 at 04:12:30
~/COSMOS_1867_Coolant/skyfield_satcat.py
--------------------------------------------------------------------------------
Loaded 41 satellites
EarthSatellite 'COSMOS 1867' number=18187 epoch=2020-07-22T12:55:48Z A.D. 2020-Jul-22 12:55:47.6259 UT
EarthSatellite 'COSMOS 1867 COOLANT' number=39637 epoch=2020-07-22T08:19:57Z A.D. 2020-Jul-22 08:19:56.8039 UT
EarthSatellite 'COSMOS 1867 COOLANT' number=39638 epoch=2020-07-22T20:59:31Z A.D. 2020-Jul-22 20:59:30.9281 UT
EarthSatellite 'COSMOS 1867 COOLANT' number=39639 epoch=2020-07-22T08:42:26Z A.D. 2020-Jul-22 08:42:26.1680 UT
EarthSatellite 'COSMOS 1867 COOLANT' number=39640 epoch=2020-07-22T12:45:25Z A.D. 2020-Jul-22 12:45:24.5385 UT
EarthSatellite 'COSMOS 1867 COOLANT' number=39641 epoch=2020-07-22T12:43:18Z A.D. 2020-Jul-22 12:43:17.5486 UT
EarthSatellite 'COSMOS 1867 COOLANT' number=39642 epoch=2020-07-22T17:18:51Z A.D. 2020-Jul-22 17:18:51.3386 UT
EarthSatellite 'COSMOS 1867 COOLANT' number=39643 epoch=2020-07-22T20:35:18Z A.D. 2020-Jul-22 20:35:18.2633 UT
EarthSatellite 'COSMOS 1867 COOLANT' number=39644 epoch=2020-07-22T17:04:00Z A.D. 2020-Jul-22 17:03:59.8202 UT
EarthSatellite 'COSMOS 1867 COOLANT' number=39645 epoch=2020-07-19T00:04:25Z A.D. 2020-Jul-19 00:04:25.1339 UT
EarthSatellite 'COSMOS 1867 COOLANT' number=39646 epoch=2020-07-22T21:03:13Z A.D. 2020-Jul-22 21:03:13.4600 UT
EarthSatellite 'COSMOS 1867 COOLANT' number=39647 epoch=2020-07-22T21:15:30Z A.D. 2020-Jul-22 21:15:30.3345 UT
EarthSatellite 'COSMOS 1867 COOLANT' number=39654 epoch=2020-07-21T12:44:35Z A.D. 2020-Jul-21 12:44:35.1626 UT
EarthSatellite 'COSMOS 1867 COOLANT' number=39655 epoch=2020-07-22T16:57:59Z A.D. 2020-Jul-22 16:57:59.3948 UT
EarthSatellite 'COSMOS 1867 COOLANT' number=39656 epoch=2020-07-22T20:48:43Z A.D. 2020-Jul-22 20:48:42.5583 UT
EarthSatellite 'COSMOS 1867 COOLANT' number=39657 epoch=2020-07-22T20:46:58Z A.D. 2020-Jul-22 20:46:58.4187 UT
EarthSatellite 'COSMOS 1867 COOLANT' number=39658 epoch=2020-07-22T18:29:34Z A.D. 2020-Jul-22 18:29:34.4875 UT
EarthSatellite 'COSMOS 1867 COOLANT' number=39659 epoch=2020-07-22T12:50:08Z A.D. 2020-Jul-22 12:50:08.4135 UT
EarthSatellite 'COSMOS 1867 COOLANT' number=39660 epoch=2020-07-22T18:33:18Z A.D. 2020-Jul-22 18:33:17.5421 UT
EarthSatellite 'COSMOS 1867 COOLANT' number=39661 epoch=2020-07-22T06:30:46Z A.D. 2020-Jul-22 06:30:45.6794 UT
EarthSatellite 'COSMOS 1867 COOLANT' number=39662 epoch=2020-07-22T20:55:29Z A.D. 2020-Jul-22 20:55:29.0073 UT
EarthSatellite 'COSMOS 1867 COOLANT' number=39663 epoch=2020-07-22T20:58:05Z A.D. 2020-Jul-22 20:58:04.9852 UT
EarthSatellite 'COSMOS 1867 COOLANT' number=39664 epoch=2020-07-22T20:49:17Z A.D. 2020-Jul-22 20:49:16.6665 UT
EarthSatellite 'COSMOS 1867 COOLANT' number=39665 epoch=2020-07-22T18:40:48Z A.D. 2020-Jul-22 18:40:47.9401 UT
EarthSatellite 'COSMOS 1867 COOLANT' number=39666 epoch=2020-07-22T20:52:46Z A.D. 2020-Jul-22 20:52:46.0957 UT
EarthSatellite 'COSMOS 1867 COOLANT' number=39667 epoch=2020-07-22T20:52:14Z A.D. 2020-Jul-22 20:52:13.7787 UT
EarthSatellite 'COSMOS 1867 COOLANT' number=39668 epoch=2020-07-22T20:51:23Z A.D. 2020-Jul-22 20:51:22.8277 UT
EarthSatellite 'COSMOS 1867 COOLANT' number=39669 epoch=2020-07-22T20:37:41Z A.D. 2020-Jul-22 20:37:41.3461 UT
EarthSatellite 'COSMOS 1867 COOLANT' number=39670 epoch=2020-07-21T12:35:15Z A.D. 2020-Jul-21 12:35:14.5778 UT
EarthSatellite 'COSMOS 1867 COOLANT' number=39671 epoch=2020-07-22T21:01:29Z A.D. 2020-Jul-22 21:01:29.4136 UT
EarthSatellite 'COSMOS 1867 COOLANT' number=39672 epoch=2020-07-22T20:54:19Z A.D. 2020-Jul-22 20:54:18.9265 UT
EarthSatellite 'COSMOS 1867 COOLANT' number=39673 epoch=2020-07-22T17:58:06Z A.D. 2020-Jul-22 17:58:06.4911 UT
EarthSatellite 'COSMOS 1867 COOLANT' number=39674 epoch=2020-07-22T12:49:37Z A.D. 2020-Jul-22 12:49:37.0381 UT
EarthSatellite 'COSMOS 1867 COOLANT' number=39675 epoch=2020-07-22T12:05:24Z A.D. 2020-Jul-22 12:05:23.8488 UT
EarthSatellite 'COSMOS 1867 COOLANT' number=39676 epoch=2020-07-22T16:56:17Z A.D. 2020-Jul-22 16:56:17.1776 UT
EarthSatellite 'COSMOS 1867 COOLANT' number=39677 epoch=2020-07-21T12:52:38Z A.D. 2020-Jul-21 12:52:37.5710 UT
EarthSatellite 'COSMOS 1867 COOLANT' number=43324 epoch=2020-07-22T18:01:40Z A.D. 2020-Jul-22 18:01:40.0045 UT
EarthSatellite 'COSMOS 1867 COOLANT' number=43325 epoch=2020-07-22T12:59:41Z A.D. 2020-Jul-22 12:59:40.6951 UT
EarthSatellite 'COSMOS 1867 COOLANT' number=43326 epoch=2020-07-22T18:21:59Z A.D. 2020-Jul-22 18:21:59.3790 UT
EarthSatellite 'COSMOS 1867 COOLANT' number=43327 epoch=2020-07-21T15:25:15Z A.D. 2020-Jul-21 15:25:14.7752 UT
EarthSatellite 'COSMOS 1867 COOLANT' number=43328 epoch=2020-07-22T00:16:23Z A.D. 2020-Jul-22 00:16:23.1361 UT
Traceback (most recent call last):
  File "/Users/user/COSMOS_1867_Coolant/skyfield_satcat.py", line 42, in <module>
    for line1, line2, line3 in TLEs:
TypeError: cannot unpack non-iterable EarthSatellite object

Please advise.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
craigimcommented, Oct 1, 2020

Never mind. Just found from sgp4.exporter import export_tle.

0reactions
craigimcommented, Oct 1, 2020

I actually have a use case for this, though it’s probably obscure enough that it may not be worth it to add.

I’m running skyfield on an air-gapped computer and want to store TLEs in a simple database rather than a big text file. I’d like to use the fact that skyfield already parses the epoch date and can handle both 2 and 3 line entries, and then insert the two lines into the database. Then, if I want a particular TLE, I can search on the NORAD ID and epoch date and then return the two lines to build my skyfield EarthSatellite object. Essentially, if possible, under model (or similar), I’d like to see two fields line1 and line2 that are just copies of the inputs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Loading OMM and TLE satellite data - poliastro
Propagate the TLE or OMM using the SGP4 algorithm, which produces cartesian elements (position and velocity) in the True Equator Mean Equinox (TEME)...
Read more >
python-sgp4/__init__.py at master - GitHub
"""Track Earth satellites given TLE data, using up-to-date 2020 SGP4 routines. ... available from the satellite record once it has been initialized.
Read more >
Earth Satellites — Skyfield documentation - Rhodes Mill
If your program already has the two lines of TLE data for a satellite and doesn't need Skyfield to download and parse a...
Read more >
How to generate TLE file? - Space Exploration Stack Exchange
Do not make FAKE TLEs! Step 1: Read this answer. Step 2: Review all of the links in the answer. I'll repeat them...
Read more >
ImportTLEFile (Satellites) - Agi
The ImportTLEFile Connect command imports satellites from a TLE file into ... STK creates a constellation (if it doesn't already exist) and places...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found