From af3fb8fead849b289df593d44bcfbf1e39d281f8 Mon Sep 17 00:00:00 2001 From: Neal McBurnett Date: Sat, 22 Nov 2014 18:35:09 -0700 Subject: [PATCH 1/4] Update horizons.py for current JPL Horizons telnet interface - new prompts, sends in ASCII transfer format. Add documentation. --- tests/horizons.py | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/tests/horizons.py b/tests/horizons.py index 8a61774..6b65beb 100755 --- a/tests/horizons.py +++ b/tests/horizons.py @@ -1,4 +1,13 @@ #!/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.bsp', 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.bsp', '### Retrieved SPICEID 1000012; status=SUCCESS']) +""" import re import os @@ -23,7 +32,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 @@ -32,10 +41,19 @@ def horizons(target): if rtn > 0: return rtn,pe.before sl( 'pexpect@python.org'+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 @@ -79,7 +97,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' @@ -96,10 +114,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: From 37099775c14eee58de188a5bdfc62e976bf755dd Mon Sep 17 00:00:00 2001 From: Neal McBurnett Date: Sun, 23 Nov 2014 10:47:10 -0700 Subject: [PATCH 2/4] horizons.py: Fix documentation to match the code: now gets a .xfr file --- tests/horizons.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/horizons.py b/tests/horizons.py index 6b65beb..a8e957d 100755 --- a/tests/horizons.py +++ b/tests/horizons.py @@ -6,7 +6,7 @@ For example, to retrieve an SPK for comet 67P: $ python horizons.py 900647 -('900647_pexpect.bsp', 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.bsp', '### Retrieved SPICEID 1000012; status=SUCCESS']) +('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 From 8c6453fc99cd0c03391e8a70df36452c7456a273 Mon Sep 17 00:00:00 2001 From: Neal McBurnett Date: Sun, 23 Nov 2014 10:54:07 -0700 Subject: [PATCH 3/4] horizons.py: Note that SPICEID is no longer figured out properly --- tests/horizons.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/horizons.py b/tests/horizons.py index a8e957d..ca921fd 100755 --- a/tests/horizons.py +++ b/tests/horizons.py @@ -6,7 +6,11 @@ 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']) ('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']) + +Bugs: +The returned SPICEID is -1, not the actual "Target SPK ID" from the .xfr file. """ import re From 2b7a30224ec831f9bdae3b900567dcf80add7010 Mon Sep 17 00:00:00 2001 From: Neal McBurnett Date: Sun, 23 Nov 2014 11:16:00 -0700 Subject: [PATCH 4/4] Fix documentation, so example of what output should like follows info about the bug. --- tests/horizons.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/horizons.py b/tests/horizons.py index ca921fd..bcb5990 100755 --- a/tests/horizons.py +++ b/tests/horizons.py @@ -7,10 +7,14 @@ $ 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']) -('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']) 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