Getting ephemerides for a CelestialBody always returns Earth's ephemerides

Hi!

I’ve written some code to get the PVCoordinates of a planet at a given time. This works great for Earth but, for some reason, returns Earth’s position regardless of what body I ask for. I’ve loaded a more complete lnxp1550.430 file into my orekit-data folder which I can confirm is being read, so I don’t think that’s the issue, but it shouldn’t matter anyway since I’m not querying for dates very far into the future.

Here’s a simplified version of the code I’m running, made a bit more verbose in places for clarity:

int secondsInDay = 24 * 60 * 60;

// convert Julian Date (2024-Apr-09) to TDB time
Double julianDate = 2460409.5;
int julianDay = julianDate.intValue();
double seconds = (julianDate - julianDay) * secondsInDay;
AbsoluteDate absDate = AbsoluteDate.createJDDate(julianDay, seconds, TimeScalesFactory.getTDB());

// Get Frame
Frame eclipticFrame = FramesFactory.getEcliptic(IERSConventions.IERS_2010);

// Initialise Ephemerides Loader
JPLEphemeridesLoader ephemeridesLoader = new JPLEphemeridesLoader(DEFAULT_DE_SUPPORTED_NAMES, JPLEphemeridesLoader.EphemerisType.SOLAR_SYSTEM_BARYCENTER);

// Get 3 bodies
CelestialBody venus = ephemeridesLoader.loadCelestialBody(CelestialBodyFactory.VENUS);
CelestialBody earth = ephemeridesLoader.loadCelestialBody(CelestialBodyFactory.EARTH);
CelestialBody mars = ephemeridesLoader.loadCelestialBody(CelestialBodyFactory.MARS);

// Get their positions
Vector3D venusPosition = venus.getPVCoordinates(absDate, eclipticFrame).getPosition();
Vector3D earthPosition = earth.getPVCoordinates(absDate, eclipticFrame).getPosition();
Vector3D marsPosition = mars.getPVCoordinates(absDate, eclipticFrame).getPosition();

The issue when I run this code is that all bodies have the same position, and the position matches the JPL Horizons data for Earth at that time! It’s like Orekit can’t find the CelestialBody and then silently falls back to Earth, or something.

Would love to find out what I’m doing wrong here.

Thanks a million!

Hello @decmurphy,

Out of pure interest I tried to debug the code snippet and got the same result as you.

I put a breakpoint after the definition of the Celestial bodies first; All of the attraction coeffients (gm parameter of each celestial body instance) were the same and equal to the Sun’s attraction coefficient. I thought this might not be normal, because the definition of a Celestial body with the default loader (i.e. CelestialBodyFactory.getEarth()) gave the correct attraction coefficient for Earth (or any other body’s), and not the Sun’s Barycenter.

The reason why the attraction coefficient of all bodies is equal to the Sun’s Barycenter coefficient is because you have defined the EphemerisType as SOLAR_BARYCENTER, and the call of the function loadCelestialBody is actually computing the attraction coefficient (gm) of the ephemeris corresponding to the solar barycenter and using that to define the gm for every Celestial Body wished to be loaded (getLoadedGravitationalCoefficient(generateType), in the defintion of loadCelestialBody function)

It is not clear to me if this is the true intention of the function, or if this is unwanted.

If this is intended, then you might need to create one loader per celestial body and then load again the body by calling the function loadCelestialBody(JPLEphemeridesLoader.EphemerisType.VENUS). Please see the code snippet below. This way, you get the body created with the same attraction coefficient as if you would call CelestialBodyFactory.getVenus().

Just replace the instantiation of the JPL loader and body creation with the following snippet, only for Venus, and similar for other bodies.

  // Initialise Ephemerides Loader
  JPLEphemeridesLoader venusEphemeridesLoader = new JPLEphemeridesLoader(
  		JPLEphemeridesLoader.DEFAULT_DE_SUPPORTED_NAMES,
  		JPLEphemeridesLoader.EphemerisType.VENUS);

  CelestialBody venus = venusEphemeridesLoader.loadCelestialBody("VENUS");

  // Get their positions
  Vector3D venusPosition = venus.getPVCoordinates(absDate, eclipticFrame).getPosition();