Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update horizons.py for current JPL Horizons telnet interface #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 35 additions & 4 deletions tests/horizons.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
#!/usr/bin/env python
"""
Retrieve a SPICE SPK file for the given comet or asteroid from JPL Horizons, as described at
http://ssd.jpl.nasa.gov/?horizons_doc

For example, to retrieve an SPK for comet 67P:

$ python horizons.py 900647
('900647_pexpect.xfr', -1, ['Horizons lookup status=0, URL=ftp://ssd.jpl.nasa.gov/pub/ssd/wld24158.15', '### Retrieved SPK (URL=ftp://ssd.jpl.nasa.gov/pub/ssd/wld24158.15) as 900647_pexpect.xfr', '### Retrieved SPICEID -1; status=SUCCESS'])

Bugs:
The returned SPICEID is -1, not the actual "Target SPK ID" from the .xfr file.

It should return something like this:

('900647_pexpect.xfr', 1000012, ['Horizons lookup status=0, URL=ftp://ssd.jpl.nasa.gov/pub/ssd/wld11001.15', '### Retrieved SPK (URL=ftp://ssd.jpl.nasa.gov/pub/ssd/wld11001.15) as 900647_pexpect.xfr', '### Retrieved SPICEID 1000012; status=SUCCESS'])

"""

import re
import os
Expand All @@ -23,7 +40,7 @@ def horizons(target):

if rtn == 2: return rtn,pe.before

sl( target+nl )
sl( target )
rtn = ex( ['\[S]PK', pexpect.TIMEOUT], timeout=3)
if rtn > 0: return rtn,pe.before

Expand All @@ -32,10 +49,19 @@ def horizons(target):
if rtn > 0: return rtn,pe.before

sl( '[email protected]'+nl )
rtn = ex( ['Confirm e-mail.*YES, NO,', pexpect.TIMEOUT], timeout=3)
if rtn > 0: return rtn,pe.before

sl( 'YES')

# It appears that this question is no longer asked.
"""
rtn = ex( ['text transfer.*YES, NO,', pexpect.TIMEOUT], timeout=3)
if rtn > 0: return rtn,pe.before

sl( 'NO' )
"""

rtn = ex( ['START', pexpect.TIMEOUT], timeout=3)
if rtn > 0: return rtn,pe.before

Expand Down Expand Up @@ -79,7 +105,7 @@ def brief(fn):
return int(pe.before),'SUCCESS'

def gomain(target):
fn = '_'.join( re.split('[^-a-zA-Z0-9]',target) )+'_pexpect.bsp'
fn = '_'.join( re.split('[^-a-zA-Z0-9]',target) )+'_pexpect.xfr'
spiceId = 0
msgs = ['Horizons lookup FAILED'
,'SPK retrieval not attempted'
Expand All @@ -96,10 +122,15 @@ def gomain(target):
msgs[0] = 'Horizons lookup status=%d, URL=%s' % (r,url,)

msgs[1] = 'SPK retrieval FAILED'
msgs[1] = '### Retrieved SPK (URL=%s) as %s' % (url, urllib.urlretrieve(url,fn)[0],)
urlret = urllib.urlretrieve(url,fn)
msgs[1] = '### Retrieved SPK (URL=%s) as %s' % (url, urlret[0])

msgs[2] = 'SPICE Body ID FAILED'
spiceId,status = brief(fn)
# spiceId,status = brief(fn)
# Horizons seems to now retrieve ASCII files rather than binary BSP files, and brief doesn't work on those.
# For now just assume success, and pretend it is really a BSP file, and return 'NA' rather than the actual SPICEID.
# We could just use a regular expression to search for this sort of text: Target SPK ID : 1000012
spiceId,status = (-1, 'SUCCESS')
msgs[2] = '### Retrieved SPICEID %d; status=%s' % (spiceId,status,)

except:
Expand Down