Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Earth to Jupiter distance with Skyfield

I'm trying to use Skyfield to plot the distance in au from Earth to solar system planets as a function of time. This is super simple and is even given in the front page of the package homepage. However while this works perfectly well for mercury, venus and mars, it doesn't work for other planets. I'm not familiar with JPL ephemeris files but it seems that for example Jupiter has no key entry in the file de421.bsp which would explain the issue.

Here is a minimal example (the one from the homepage):

from skyfield.api import load, now

planets = load('de421.bsp')
earth, planet = planets['earth'], planets['jupiter']

jd = now()
position = earth.at(jd).observe(planet)
ra, dec, distance = position.radec()

print(distance)

The error is the below. Note that if you replace 'jupiter' by 'mars' in the code above, it doesn't crash.

---->  earth, planet = planets['earth'], planets['jupiter']
KeyError: "kernel 'de421.bsp' is missing 'JUPITER' - the targets it supports are:
SOLAR SYSTEM BARYCENTER, MERCURY BARYCENTER, VENUS BARYCENTER, EARTH BARYCENTER, 
MARS BARYCENTER, JUPITER BARYCENTER, SATURN BARYCENTER, URANUS BARYCENTER, 
NEPTUNE BARYCENTER, PLUTO BARYCENTER, SUN, MERCURY, VENUS, MOON, EARTH, MARS"

Am I using the ephemeris file in the wrong way (wrong barycenter ?) or is this just a limitation of the de421.bsp file ? I read the description of the ephemeris file on the Skyfield website (here) but not sure I fully understood it.

Any suggestion of how to perform this simple calculation of Earth-Jupiter distance with Skyfield ?

Thanks !

like image 590
Fabio Avatar asked Jan 19 '16 10:01

Fabio


1 Answers

Like the error says, you need to use JUPITER BARYCENTER instead of jupiter.

like image 172
BlueMoon93 Avatar answered Sep 19 '22 14:09

BlueMoon93