Skip to content

Commit

Permalink
Merge pull request #8 from GlobalFishingWatch/bugfix/PIPELINE-2278
Browse files Browse the repository at this point in the history
Logging when there is a RuntimeError and expose the TLE
  • Loading branch information
smpiano authored Oct 24, 2024
2 parents 5a311cb + 5a728e3 commit 8a28f8b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
42 changes: 25 additions & 17 deletions pipe_satellite_data/utils/locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import time
import udatetime
import ujson as json
import logging


EPOCH = udatetime.utcfromtimestamp(0)
Expand Down Expand Up @@ -77,7 +78,10 @@ def fetch_TLE(st_auth, norad_ids, dt):
for tles_list_by_norad in norad_dict.values():
first_tle=[tles_list_by_norad[0]]
for tle in first_tle:
yield tle
if int(tle["DECAYED"]) not in [1, 2]: # https://www.space-track.org/documentation#api-basicSpaceDataDecay
yield tle
else:
logging.info(f'>>> TLE already DECAYED: {tle["NORAD_CAT_ID"]}')



Expand All @@ -103,19 +107,23 @@ def satellite_locations(tles, dt):
end_ts = start_ts + SECONDS_IN_DAY

for tle in tles:
tle_lines = [str(tle['TLE_LINE%s' % i]) for i in range(3)]
orbit = ephem.readtle(*tle_lines)

for ts in range(start_ts, end_ts):
orbit.compute(datetime.utcfromtimestamp(ts).strftime("%Y/%m/%d %H:%M:%S"))
lon = ephem.degrees(orbit.sublong) * 180 / 3.1416
lat = ephem.degrees(orbit.sublat) * 180 / 3.1416
elevation = orbit.elevation

yield dict(
norad_id=tle['NORAD_CAT_ID'],
lat=lat,
lon=lon,
timestamp=ts,
altitude=elevation
)
try:
tle_lines = [str(tle['TLE_LINE%s' % i]) for i in range(3)]
orbit = ephem.readtle(*tle_lines)

for ts in range(start_ts, end_ts):
orbit.compute(datetime.utcfromtimestamp(ts).strftime("%Y/%m/%d %H:%M:%S"))
lon = ephem.degrees(orbit.sublong) * 180 / 3.1416
lat = ephem.degrees(orbit.sublat) * 180 / 3.1416
elevation = orbit.elevation

yield dict(
norad_id=tle['NORAD_CAT_ID'],
lat=lat,
lon=lon,
timestamp=ts,
altitude=elevation
)
except RuntimeError as e:
logging.error(e, f'Error found in TLE: {tle}.\nCheck satellite status: https://www.n2yo.com/satellite/?s={tle["NORAD_CAT_ID"]}')
raise e
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='pipe-satellite-data',
version='3.1.0',
version='3.1.1',
packages=find_packages(exclude=['test*.*', 'tests'])
)

0 comments on commit 8a28f8b

Please sign in to comment.