brandon-rhodes / python-jplephem

Python version of NASA DE4xx ephemerides, the basis for the Astronomical Alamanac
MIT License
110 stars 29 forks source link

data type 1 SPK kernel #14

Open migueldvb opened 8 years ago

migueldvb commented 8 years ago

I have downloaded an SPK kernel of data type 1 form JPL horizons http://ssd.jpl.nasa.gov/x/spk.html in binary and ascii format. The kernel can be loaded using jplephem.spk.SPK but I get an error when I compute the position of an object.

In [22]: kernel[10,1000012].compute(2457400)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/home/mdevalbo/.local/lib/python3.5/site-packages/jplephem/spk.py in generate(self, tdb, tdb2)
    151         try:
--> 152             initial_epoch, interval_length, coefficients = self._data
    153         except AttributeError:

AttributeError: 'Segment' object has no attribute '_data'

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-22-5dbf5fd43a50> in <module>()
----> 1 kernel[10,1000012].compute(2457400)

/home/mdevalbo/.local/lib/python3.5/site-packages/jplephem/spk.py in compute(self, tdb, tdb2)
    104     def compute(self, tdb, tdb2=0.0):
    105         """Compute the component values for the time `tdb` plus `tdb2`."""
--> 106         for position in self.generate(tdb, tdb2):
    107             return position
    108 

/home/mdevalbo/.local/lib/python3.5/site-packages/jplephem/spk.py in generate(self, tdb, tdb2)
    152             initial_epoch, interval_length, coefficients = self._data
    153         except AttributeError:
--> 154             self._data = self._load()
    155             initial_epoch, interval_length, coefficients = self._data
    156 

/home/mdevalbo/.local/lib/python3.5/site-packages/jplephem/spk.py in _load(self)
    120             component_count = 6
    121         else:
--> 122             raise ValueError('only SPK data types 2 and 3 are supported')
    123 
    124         init, intlen, rsize, n = self.daf.map_array(self.end_i - 3, self.end_i)

ValueError: only SPK data types 2 and 3 are supported

Is there any way to get an SPK kernel from Horizons that is supported by jplephem?

brandon-rhodes commented 8 years ago

I had not seen that online form before! I do not see a knob for the kind of SPK file returned. Here is what I can find about that format:

http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/req/spk.html#Type 1: Modified Difference Arrays

Alas, it does not state how to turn the numbers into positions, but instead refers to a document:

JPL Internal Memorandum on Modified Difference Array polynomials

I cannot find a copy of it online. I wonder if the SPICE source code would include a routine we could examine in order to learn the steps? Or do we know anyone at the JPL who could share the memorandum with us? :)

migueldvb commented 8 years ago

I think that the SPK kernel generator form was introduce to complement the old method of requesting SPK files for minor bodies using telnet. It is very hard to find though.

I just checked that I can read the files with data type 1 generated with the webform using spiceypy that is a wrapper around the cspice library, so it should be possible to find the source code. If I can figure out something else I will add it to this ticket.

whiskie14142 commented 8 years ago

I wrote a module named spk_type01.py, and it computes position and velocity from SPK data (data type = 1) provided by JPL, through web form and/or telnet. If you wish to try it, please check the attached file. The file contains spk_type01.py, two test programs (test_type01.py, and test_type01b.py), two SPK data files (Ryugu-HC.bsp, and Ceres_Vesta.bsp), three reference data files (*.csv), and one sample output of test_type01.py. I tested them on Anaconda3, so I don't know they works on Python 2.11 or not, sorry. spk_type01.zip

whiskie14142 commented 8 years ago

I changed name of the module to 'spktype01', and uploaded to PyPI and GitHub as follows:

PyPI - https://pypi.python.org/pypi/spktype01/0.1.0 GitHub - https://github.com/whiskie14142/spktype01

brandon-rhodes commented 8 years ago

Thanks — I'll take a look at it when I get the chance! (Or, of course, any of the rest of you are free to try figuring out how to hook it up to Skyfield.)

whiskie14142 commented 7 years ago

I got a mail from a man who used jplephem and spktype01. He used them to visualize the orbit of the spacecraft Juno. They work fine, it seems. http://space.stackexchange.com/a/19263/12102