Skip to content

Commit e3eb552

Browse files
committed
update kernel download mechanisms; new NAIF filenames
1 parent 37cbbe4 commit e3eb552

File tree

4 files changed

+62
-58
lines changed

4 files changed

+62
-58
lines changed

grss/debias/get_debiasing_data.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
11
"""Download the debiasing data files from the JPL Solar System Dynamics Group's FTP server"""
22
import os
3+
import requests
4+
5+
def check_and_download(url, local_path, note):
6+
try:
7+
response = requests.head(url, timeout=30, allow_redirects=True)
8+
if response.status_code == 200:
9+
print(f'Downloading {note}...')
10+
response = requests.get(url, timeout=30)
11+
with open(local_path, 'wb') as f:
12+
f.write(response.content)
13+
else:
14+
msg = f'File {url} ({note}) does not exist on server. Code: {response.status_code}'
15+
raise FileNotFoundError(msg)
16+
except requests.RequestException as e:
17+
raise ConnectionError(f'Error checking/downloading {note}') from e
318

419
cwd = os.path.dirname(os.path.abspath(__file__))
520

6-
FTP_SITE = 'ftp://ssd.jpl.nasa.gov/pub/ssd/debias'
21+
FTP_SITE = 'https://ssd.jpl.nasa.gov/ftp/ssd/debias'
722
# get debiasing data files from the JPL Solar System Dynamics Group's FTP server
823
# if lowres_data.tgz or lowres_data/ already exist, do not download
924
if not os.path.exists(f'{cwd}/lowres_data.tgz') and not os.path.exists(f'{cwd}/lowres_data/'):
10-
FTP_FILE = 'debias_2018.tgz'
11-
cmd = f'curl --connect-timeout 30 --show-error -o {cwd}/lowres_data.tgz {FTP_SITE}/{FTP_FILE}'
12-
print('Downloading low-resolution debiasing data...')
13-
os.system(cmd)
25+
check_and_download(f'{FTP_SITE}/debias_2018.tgz',
26+
f'{cwd}/lowres_data.tgz', 'low-resolution debiasing data')
1427
if not os.path.exists(f'{cwd}/hires_data.tgz') and not os.path.exists(f'{cwd}/hires_data/'):
15-
FTP_FILE = 'debias_hires2018.tgz'
16-
cmd = f'curl --connect-timeout 30 --show-error -o {cwd}/hires_data.tgz {FTP_SITE}/{FTP_FILE}'
17-
print('Downloading high-resolution debiasing data...')
18-
os.system(cmd)
28+
check_and_download(f'{FTP_SITE}/debias_hires2018.tgz',
29+
f'{cwd}/hires_data.tgz', 'high-resolution debiasing data')
1930

2031
# extract the data files
2132
# create the directories if they don't exist, delete the files if they do

grss/kernels/get_kernels.py

Lines changed: 40 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,23 @@
22
GRSS GitHub repository and the NAIF FTP server"""
33
import os
44
import time
5+
import requests
6+
7+
def check_and_download(url, local_path, note, force=False):
8+
if os.path.exists(local_path) and not force:
9+
return
10+
try:
11+
response = requests.head(url, timeout=30, allow_redirects=True)
12+
if response.status_code == 200:
13+
print(f'Downloading {note}...')
14+
response = requests.get(url, timeout=30)
15+
with open(local_path, 'wb') as f:
16+
f.write(response.content)
17+
else:
18+
msg = f'File {url} ({note}) does not exist on server. Code: {response.status_code}'
19+
raise FileNotFoundError(msg)
20+
except requests.RequestException as e:
21+
raise ConnectionError(f'Error checking/downloading {note}') from e
522

623
# get the path to the directory containing this script
724
script_dir = os.path.dirname(os.path.realpath(__file__))
@@ -11,61 +28,37 @@
1128

1229
# get the spice kernels if they are not already present
1330
# de430 planets + de431 big16
14-
mb430_exists = os.path.exists(f'{script_dir}/de430.bsp')
15-
sb431_exists = os.path.exists(f'{script_dir}/sb431-n16s.bsp')
16-
if (not mb430_exists or not sb431_exists):
17-
print('Downloading DE430/431 planet and big16 asteroid kernels...')
18-
os.system((f'curl --connect-timeout 30 --show-error -o {script_dir}/de430.bsp '
19-
f'{NAIF_SITE}/spk/planets/de430.bsp'))
20-
os.system((f'curl --connect-timeout 30 --show-error -o {script_dir}/sb431-n16s.bsp '
21-
f'{SSD_SITE}/xfr/sb431-n16s.bsp'))
22-
# de440 planets + de441 big16
23-
mb440_exists = os.path.exists(f'{script_dir}/de440.bsp')
24-
sb441s_exists = os.path.exists(f'{script_dir}/sb441-n16s.bsp')
25-
mb441_exists = os.path.exists(f'{script_dir}/de441.bsp')
26-
sb441_exists = os.path.exists(f'{script_dir}/sb441-n16.bsp')
27-
if (not mb440_exists or not mb441_exists or not sb441s_exists or not sb441_exists):
28-
print('Downloading DE440/441 planet and big16 asteroid kernels...')
29-
os.system((f'curl --connect-timeout 30 --show-error -o {script_dir}/de440.bsp '
30-
f'{SSD_SITE}/eph/planets/bsp/de440.bsp'))
31-
os.system((f'curl --connect-timeout 30 --show-error -o {script_dir}/sb441-n16s.bsp '
32-
f'{SSD_SITE}/xfr/sb441-n16s.bsp'))
33-
os.system((f'curl --connect-timeout 30 --show-error -o {script_dir}/de441.bsp '
34-
f'{SSD_SITE}/eph/planets/bsp/de441.bsp'))
35-
os.system((f'curl --connect-timeout 30 --show-error -o {script_dir}/sb441-n16.bsp '
36-
f'{SSD_SITE}/eph/small_bodies/asteroids_de441/sb441-n16.bsp'))
31+
check_and_download(f'{NAIF_SITE}/spk/planets/de430.bsp',
32+
f'{script_dir}/de430.bsp', 'DE430 planet kernel')
33+
check_and_download(f'{SSD_SITE}/xfr/sb431-n16s.bsp',
34+
f'{script_dir}/sb431-n16s.bsp', 'DE431 big16 asteroid kernel')
35+
# de440/441 planets + de441 big16
36+
check_and_download(f'{SSD_SITE}/eph/planets/bsp/de440.bsp',
37+
f'{script_dir}/de440.bsp', 'DE440 planet kernel')
38+
check_and_download(f'{SSD_SITE}/xfr/sb441-n16s.bsp',
39+
f'{script_dir}/sb441-n16s.bsp', 'short-term DE441 big16 asteroid kernel')
40+
check_and_download(f'{SSD_SITE}/eph/planets/bsp/de441.bsp',
41+
f'{script_dir}/de441.bsp', 'DE441 planet kernel')
42+
check_and_download(f'{SSD_SITE}/eph/small_bodies/asteroids_de441/sb441-n16.bsp',
43+
f'{script_dir}/sb441-n16.bsp', 'long-term DE441 big16 asteroid kernel')
3744

38-
# get the earth orientation binary spice kernels and their comments if they are not already present
3945
# latest earth pck
4046
latest_earth_pck_exists = os.path.exists(f'{script_dir}/earth_latest.bpc')
4147
latest_earth_pck_old = (latest_earth_pck_exists and
4248
time.time() - os.path.getmtime(f'{script_dir}/earth_latest.bpc')
4349
> 86400)
4450
if not latest_earth_pck_exists or latest_earth_pck_old:
45-
print('Downloading latest Earth binary PCK...')
46-
os.system((f'curl --connect-timeout 30 --show-error -o {script_dir}/earth_latest.bpc '
47-
f'{NAIF_SITE}/pck/earth_latest_high_prec.bpc'))
51+
check_and_download(f'{NAIF_SITE}/pck/earth_latest_high_prec.bpc',
52+
f'{script_dir}/earth_latest.bpc', 'latest Earth binary PCK', force=True)
4853
# historical earth pck
49-
historical_earth_pck_exists = os.path.exists(f'{script_dir}/earth_historic.bpc')
50-
if not historical_earth_pck_exists:
51-
print('Downloading historic Earth binary PCK...')
52-
os.system((f'curl --connect-timeout 30 --show-error -o {script_dir}/earth_historic.bpc '
53-
f'{NAIF_SITE}/pck/earth_620120_240827.bpc'))
54+
check_and_download(f'{NAIF_SITE}/pck/earth_620120_250826.bpc',
55+
f'{script_dir}/earth_historic.bpc', 'historic Earth binary PCK')
5456
# predicted earth pck
55-
predicted_earth_pck_exists = os.path.exists(f'{script_dir}/earth_predict.bpc')
56-
if not predicted_earth_pck_exists:
57-
print('Downloading predicted Earth binary PCK...')
58-
os.system((f'curl --connect-timeout 30 --show-error -o {script_dir}/earth_predict.bpc '
59-
f'{NAIF_SITE}/pck/earth_200101_990827_predict.bpc'))
57+
check_and_download(f'{NAIF_SITE}/pck/earth_2025_250826_2125_predict.bpc',
58+
f'{script_dir}/earth_predict.bpc', 'predicted Earth binary PCK')
6059
# moon pck
61-
moon_pa_de440_exists = os.path.exists(f'{script_dir}/moon_pa_de440.bpc')
62-
if not moon_pa_de440_exists:
63-
print('Downloading Moon PCK for DE440...')
64-
os.system((f'curl --connect-timeout 30 --show-error -o {script_dir}/moon_pa_de440.bpc '
65-
f'{NAIF_SITE}/pck/moon_pa_de440_200625.bpc'))
60+
check_and_download(f'{NAIF_SITE}/pck/moon_pa_de440_200625.bpc',
61+
f'{script_dir}/moon_pa_de440.bpc', 'Moon PCK for DE440')
6662
# generic frame kernels
67-
generic_frame_kernel_exists = os.path.exists(f'{script_dir}/pck00011.tpc')
68-
if not generic_frame_kernel_exists:
69-
print('Downloading generic frame kernel...')
70-
os.system((f'curl --connect-timeout 30 --show-error -o {script_dir}/pck00011.tpc '
71-
f'{NAIF_SITE}/pck/pck00011.tpc'))
63+
check_and_download(f'{NAIF_SITE}/pck/pck00011.tpc',
64+
f'{script_dir}/pck00011.tpc', 'generic frame kernel')

grss/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def initialize():
7272
"""
7373
internet = _connected_to_internet()
7474
if not internet:
75-
print("Please connect to the internet to download/update the necessary data files.")
75+
print("Internet connection is required to download/update the necessary data files.")
7676
return None
7777
# run the get_debiasing_data.py script
7878
os.system(f'python {grss_path}/debias/get_debiasing_data.py')

grss/version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.5.1
1+
4.5.2

0 commit comments

Comments
 (0)