Skip to content

Commit a41dc95

Browse files
committed
cleanups
1 parent ab0040d commit a41dc95

File tree

4 files changed

+25
-46
lines changed

4 files changed

+25
-46
lines changed

laika/astro_dog.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import DefaultDict
55
from collections.abc import Iterable
66

7-
from .constants import SECS_IN_DAY, SECS_IN_HR
7+
from .constants import SECS_IN_DAY
88
from .helpers import ConstellationId, get_constellation, get_closest, get_el_az, TimeRangeHolder
99
from .ephemeris import Ephemeris, EphemerisType, GLONASSEphemeris, GPSEphemeris, PolyEphemeris, parse_sp3_orbits, parse_rinex_nav_msg_gps, \
1010
parse_rinex_nav_msg_glonass
@@ -216,20 +216,9 @@ def download_parse_orbit(self, gps_time: GPSTime, skip_before_epoch=None) -> dic
216216
files = [self.fetch_count(f.result()) for f in futures if f.result()] if futures else []
217217
ephems = parse_sp3_orbits(files, self.valid_const, skip_before_epoch)
218218
return ephems
219-
#{k: ephems_us.get(k, []) for k in set(list([]) + list(ephems_us.keys()))}
220-
221-
def download_parse_prediction_orbit(self, gps_time: GPSTime):
222-
assert EphemerisType.ULTRA_RAPID_ORBIT in self.valid_ephem_types
223-
skip_until_epoch = gps_time - 2 * SECS_IN_HR
224-
225-
result = [self.fetch_count(download_orbits_gps(t, self.cache_dir, self.valid_ephem_types)) for t in [gps_time - SECS_IN_DAY, gps_time]]
226-
return parse_sp3_orbits(result, self.valid_const, skip_until_epoch=skip_until_epoch)
227219

228220
def get_orbit_data(self, time: GPSTime, only_predictions=False):
229-
if only_predictions:
230-
ephems_sp3 = self.download_parse_prediction_orbit(time)
231-
else:
232-
ephems_sp3 = self.download_parse_orbit(time)
221+
ephems_sp3 = self.download_parse_orbit(time)
233222
if sum([len(v) for v in ephems_sp3.values()]) < 5:
234223
raise RuntimeError(f'No orbit data found. For Time {time.as_datetime()} constellations {self.valid_const} valid ephem types {self.valid_ephem_types}')
235224
self.add_ephem_fetched_time(ephems_sp3, self.orbit_fetched_times)

laika/downloader.py

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@
2727
# mirror of sftp://gdc.cddis.eosdis.nasa.gov/gnss/data/hourly
2828
CDDIS_HOURLY_BASE_URL = os.getenv("CDDIS_HOURLY_BASE_URL", "https://raw.githubusercontent.com/commaai/gnss-data-hourly/master")
2929

30-
# mirror of ftp://ftp.glonass-iac.ru
31-
GLONAS_IAC_BASE_URL = os.getenv("GLONAS_IAC_BASE_URL", "https://raw.githubusercontent.com/commaai/gnss-data-alt/master")
32-
33-
# no mirror
34-
IGN_BASE_URL = os.getenv("IGN_BASE_URL", "ftp://igs.ign.fr/pub")
35-
3630

3731
class DownloadFailed(Exception):
3832
pass
@@ -325,36 +319,33 @@ def download_nav(time: GPSTime, cache_dir, constellation: ConstellationId):
325319
def download_orbits_gps(time, cache_dir, ephem_types):
326320
url_bases = (
327321
mirror_url(CDDIS_BASE_URL, '/gnss/products/'),
328-
mirror_url(IGN_BASE_URL, '/igs/products/'),
322+
mirror_url(CDDIS_BASE_URL, '/glonass/products/'),
329323
)
330324

325+
folder_path = "%i/" % time.week
326+
filenames = []
327+
331328
if time.week < 2238:
329+
assert EphemerisType.FINAL_ORBIT in ephem_types, "Only final orbits are available before 2238"
332330
compression = '.Z'
333-
ephem_strs = {
334-
EphemerisType.FINAL_ORBIT: ['igs{wwww}{dow}.sp3'.format(wwww=time.week, dow=time.dow)],
335-
EphemerisType.RAPID_ORBIT: ['igr{wwww}{dow}.sp3'.format(wwww=time.week, dow=time.dow)],
336-
EphemerisType.ULTRA_RAPID_ORBIT: ['igu{wwww}{dow}_{hh}.sp3'.format(wwww=time.week, dow=time.dow, hh=hour) for hour in ['18', '12', '06', '00']]
337-
}
331+
filenames.extend(['igs{wwww}{dow}.sp3'.format(wwww=time.week, dow=time.dow)])
338332
else:
339333
# TODO deal with version number
340334
compression = '.gz'
341335
ephem_strs = {
342-
EphemerisType.FINAL_ORBIT: ['IGS0OPSFIN_{yyyy}{doy:03d}0000_01D_15M_ORB.SP3'.format(yyyy=time.year, doy=time.doy)],
343-
EphemerisType.RAPID_ORBIT: ['IGS0OPSRAP_{yyyy}{doy:03d}0000_01D_15M_ORB.SP3'.format(yyyy=time.year, doy=time.doy)],
344-
EphemerisType.ULTRA_RAPID_ORBIT: ['IGS0OPSULT_{yyyy}{doy:03d}{hh}00_02D_15M_ORB.SP3'.format(yyyy=time.year, doy=time.doy, hh=hour) \
336+
EphemerisType.FINAL_ORBIT: ['COD0OPSFIN_{yyyy}{doy:03d}0000_01D_05M_ORB.SP3'.format(yyyy=time.year, doy=time.doy)],
337+
EphemerisType.RAPID_ORBIT: ['COD0OPSRAP_{yyyy}{doy:03d}0000_01D_05M_ORB.SP3'.format(yyyy=time.year, doy=time.doy)],
338+
EphemerisType.ULTRA_RAPID_ORBIT: ['COD0OPSULT_{yyyy}{doy:03d}{hh}00_02D_05M_ORB.SP3'.format(yyyy=time.year, doy=time.doy, hh=hour) \
345339
for hour in ['18', '12', '06', '00']],
346340
}
347341

348-
folder_path = "%i/" % time.week
349-
filenames = []
350-
351-
# Download filenames in order of quality. Final -> Rapid -> Ultra-Rapid(newest first)
352-
if EphemerisType.FINAL_ORBIT in ephem_types and GPSTime.from_datetime(datetime.utcnow()) - time > 3 * SECS_IN_WEEK:
353-
filenames.extend(ephem_strs[EphemerisType.FINAL_ORBIT])
354-
if EphemerisType.RAPID_ORBIT in ephem_types and GPSTime.from_datetime(datetime.utcnow()) - time > 3 * SECS_IN_DAY:
355-
filenames.extend(ephem_strs[EphemerisType.RAPID_ORBIT])
356-
if EphemerisType.ULTRA_RAPID_ORBIT in ephem_types:
357-
filenames.extend(ephem_strs[EphemerisType.ULTRA_RAPID_ORBIT])
342+
# Download filenames in order of quality. Final -> Rapid -> Ultra-Rapid(newest first)
343+
if EphemerisType.FINAL_ORBIT in ephem_types and GPSTime.from_datetime(datetime.utcnow()) - time > 3 * SECS_IN_WEEK:
344+
filenames.extend(ephem_strs[EphemerisType.FINAL_ORBIT])
345+
if EphemerisType.RAPID_ORBIT in ephem_types and GPSTime.from_datetime(datetime.utcnow()) - time > 3 * SECS_IN_DAY:
346+
filenames.extend(ephem_strs[EphemerisType.RAPID_ORBIT])
347+
if EphemerisType.ULTRA_RAPID_ORBIT in ephem_types:
348+
filenames.extend(ephem_strs[EphemerisType.ULTRA_RAPID_ORBIT])
358349

359350
folder_file_names = [(folder_path, filename) for filename in filenames]
360351
ret = download_and_cache_file_return_first_success(url_bases, folder_file_names, cache_dir+'cddis_products/', compression=compression)
@@ -388,7 +379,6 @@ def download_dcb(time, cache_dir):
388379
folder_paths = []
389380
url_bases = (
390381
mirror_url(CDDIS_BASE_URL, '/gnss/products/bias/'),
391-
mirror_url(IGN_BASE_URL, '/igs/products/mgex/dcb/'),
392382
)
393383
# seem to be a lot of data missing, so try many days
394384
for time_step in [time - i * SECS_IN_DAY for i in range(14)]:

tests/test_ephemerides.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def test_nav_vs_orbit_old(self):
3333
dog_nav = AstroDog(valid_ephem_types=EphemerisType.NAV)
3434
for gps_time in gps_times:
3535
for svId in svIds:
36+
print(svId, gps_time)
3637
sat_info_nav = dog_nav.get_sat_info(svId, gps_time)
3738
assert sat_info_nav is not None
3839
sat_info_orbit = dog_orbit.get_sat_info(svId, gps_time)

tests/test_prediction_orbits.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,19 @@
1010
class TestPredictionOrbits(unittest.TestCase):
1111

1212
def test_gps(self):
13-
available_date = GPSTime.from_datetime(datetime(2020, 5, 1, 12))
13+
available_date = GPSTime.from_datetime(datetime.now())
1414
dog = AstroDog(valid_const=(ConstellationId.GPS,), valid_ephem_types=EphemerisType.ULTRA_RAPID_ORBIT)
15-
dog.get_orbit_data(available_date, only_predictions=True)
15+
dog.get_orbit_data(available_date)
1616
self.assertGreater(len(dog.orbits.keys()), 0)
1717
self.assertTrue(available_date in dog.orbit_fetched_times)
1818

19-
def test_gps_and_glonass_2022(self):
20-
# Test GPS and GLONASS separately from the first date that GLONASS Ultra-Rapid prediction orbits were available
21-
available_date = GPSTime.from_datetime(datetime(2022, 1, 29, 11, 31))
19+
def test_glonass(self):
20+
available_date = GPSTime.from_datetime(datetime.now())
2221
for t in range(0, 24, 3):
2322
check_date = available_date + t * SECS_IN_HR
24-
for const in [ConstellationId.GPS, ConstellationId.GLONASS]:
23+
for const in [ConstellationId.GLONASS]:
2524
dog = AstroDog(valid_const=(const,), valid_ephem_types=EphemerisType.ULTRA_RAPID_ORBIT)
26-
dog.get_orbit_data(check_date, only_predictions=True)
25+
dog.get_orbit_data(check_date)
2726
self.assertGreater(len(dog.orbits.keys()), 0)
2827
self.assertTrue(check_date in dog.orbit_fetched_times)
2928

0 commit comments

Comments
 (0)