esa / pykep

PyKEP is a scientific library providing basic tools for research in interplanetary trajectory design.
http://esa.github.io/pykep/
GNU General Public License v3.0
340 stars 96 forks source link

Load the SPICE Kernel files to compute the ephemerides #58

Closed EPiress closed 7 years ago

EPiress commented 7 years ago

Hi,

So I am new to PYKEP, and I have been trying to compute some high precision ephemerides, from SPICE Kernels. My code is really simple, as I just want to get the ephemerides, before anything else. This is what I have so far:

from PyKEP import *

planet = planet.spice('EARTH', 'SUN', 'ECLIPJ2000', 'NONE', MU_SUN, MU_EARTH, EARTH_RADIUS, EARTH_RADIUS * 1.05)

r,v=planet.eph(epoch(5700,"mjd2000"))

And this is what I get:

Toolkit version: N0065

SPICE(NOLOADEDFILES) --

At least one SPK file needs to be loaded by SPKLEF before beginning a search.

A traceback follows. The name of the highest level module is first. spkezr_c --> SPKEZR --> SPKEZ --> SPKGEO --> SPKSFS

============================================================================ Traceback (most recent call last): File "/Users/eduardopires/PycharmProjects/01Pykep/test.py", line 7, in r,v=planet.eph(epoch(5700,"mjd2000")) RuntimeError: SPICE cannot compute the ephemerides, have you loaded all needed Kernel files?

Now I know I have to load the Kernels, but which Kernel should I load? And how do I actually load it?

Thanks in advance, EPiress

darioizzo commented 7 years ago

You need to load the Kernels that contain the data you then want to query. So it really depends on what eph you want to compute.

The c++ or python function to call is called load_spice_kernel. If you compiled PyKEP with SPICE you should find it in the main namespace.

Let me know if you manage ....

EPiress commented 7 years ago

Hey Dario,

Thank you for your fast answer. I have just re-compiled PyKEP, to make sure I included SPICE. But I can not find the function load_spice_kernel on Python! One more thing, on the example

planet = planet.spice('EARTH', 'SUN', 'ECLIPJ2000', 'NONE', MU_SUN, MU_EARTH, EARTH_RADIUS, EARTH_RADIUS * 1.05)

which Kernel do I have to load? It would be great for me if you could show me an example of how to load the kernels.

Thanks again, EPiress

darioizzo commented 7 years ago

Here is an output from my system:

In [1]: import PyKEP as pk

In [2]: pk.util.load_spice_kernel? Docstring: PyKEP.util.load_spice_kernel(file_name)

Loads the SPICE kernel specified by the filename into memory.

.. note::

The kernel must be in memory before its used, for example, when computing a planets.spice ephemerides

Example::

util.load_spice_kernel('de432s.bsp') Type: function

Do you not get the same?

On Fri, 17 Mar 2017 at 11:32 EPiress notifications@github.com wrote:

Hey Dario,

Thank you for your fast answer. I have just re-compiled PyKEP, to make sure I included SPICE. But I can not find the function load_spice_kernel on Python! One more thing, on the example

planet = planet.spice('EARTH', 'SUN', 'ECLIPJ2000', 'NONE', MU_SUN, MU_EARTH, EARTH_RADIUS, EARTH_RADIUS * 1.05)

which Kernel do I have to load? It would be great for me if you could show me an example of how to load the kernels.

Thanks again, EPiress

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/esa/pykep/issues/58#issuecomment-287320167, or mute the thread https://github.com/notifications/unsubscribe-auth/ADLEb9Zccx7b-mWYjmRi5PDhTCQhTTaGks5rmmEpgaJpZM4MfrQk .

EPiress commented 7 years ago

Dario,

This is what I get:

import PyKEP as pk pk.util.load_spice_kernel <Boost.Python.function object at 0x7f924b62d350>

What is wrong here?

darioizzo commented 7 years ago

nothing, you are just not calling the function and python tells you its a function.

darioizzo commented 7 years ago

in my example by adding a question mark at the end I print the help

EPiress commented 7 years ago

This is what I get, when I add the question mark:

File "", line 1 pk.util.load_spice_kernel? ^ SyntaxError: invalid syntax

darioizzo commented 7 years ago

that is probably because you are in python shell and not an ipython shell?

darioizzo commented 7 years ago
import PyKEP as pk
pk.util.load_spice_kernel('de432s.bsp')

you do not need to read the help in any case .... the above will work if you have the file ...

darioizzo commented 7 years ago

I suggest you to use an ipython shell though ..... it will make your life easier

EPiress commented 7 years ago

Ok, so I was able to load a Kernel!

from PyKEP import util.load_spice_kernel('mar097.bsp') planet = planet.spice('EARTH', 'SUN', 'ECLIPJ2000', 'NONE', MU_SUN, MU_EARTH, EARTH_RADIUS, EARTH_RADIUS 1.05) r,v=planet.eph(epoch(5700,"mjd2000"))

Do I have to have the Kernel in the same directory as the python file? And in this specific case, I am able to get results, even though the kernels are for mars, and I want to compute the eph for the earth. So how do I choose the "correct" Kernel?

darioizzo commented 7 years ago

Probably the kernel of mars contains also the earth. If you get a result it means the info is there, otherwise there would be an error. The kernel can be anywhere but you need to give then the full path or add the folder to the python path ...

darioizzo commented 7 years ago

Let me know when I can close this .... also you can chat on the gitter pykep channel next time instead of opening a ticket: https://gitter.im/esa/pykep

EPiress commented 7 years ago

Ok, thanks a lot!

darioizzo commented 7 years ago

One last think, do not call the variable planet, call it something else, like earth otherwise you will shadow the whole module called planet