The earth is 0.4 AU from the earth?

Trying to get apparent positions of things in the solar system, it seems like odd things happen when the object gets too close to the earth. Here’s the relevant cells from my notebook that shows if I get the position of the earth or moon, converting that to GCRS does some strange things. Other bodies (sun, jupiter, etc) look fine, but earth and moon are strange:

from astropy.coordinates import (SkyCoord, BarycentricTrueEcliptic, GCRS)
from astropy.time import Time
import astropy.units as u
from astropy.coordinates import get_body_barycentric, get_body
import numpy as np
import matplotlib.pylab as plt
%matplotlib inline

# set some times
mjd = np.arange(500) + 60980.0
times = Time(mjd, format="mjd")

for name in ["sun", "venus", "jupiter", "moon", "earth"]:
    body = get_body_barycentric(name, times)
    # convert to a SkyCoord
    body_sc = SkyCoord(body, representation_type='cartesian', obstime=times, frame=BarycentricTrueEcliptic)
    body_gc = body_sc.transform_to(GCRS)
    fig, ax = plt.subplots()
    ax.scatter(body_gc.ra, body_gc.dec, c=body_gc.distance.au)
    ax.set_xlabel("RA")
    ax.set_ylabel("dec")
    ax.set_title("%s, min=%f AU, max=%f AU" % (name, body_gc.distance.au.min(), body_gc.distance.au.max()))

get_body_barycentric() returns the vector to the body in ICRS, not in BarycenctricTrueEcliptic. If you replace BarycentricTrueEcliptic with ICRS in your code, you will get the following plot:

Incidentally, if it is important for your use case to have very accurate locations for non-Earth planetary bodies, you should set a JPL ephemeris instead of using Astropy’s built-in ephemeris. See Solar System Ephemerides — Astropy v7.0.1.

1 Like

Oh, I should add that if you want the apparent position of these solar system bodies, you will probably want to account for planetary aberration (i.e., the effect of light travel time). Instead of using get_body_barycentric(), you should use get_body(), which will calculate the apparent position and return the SkyCoord.

Perfect! That makes much more sense.