I am trying to compare the position of the Earth in heliocentric system given by Astropy, with that of JPL's Horizons. I find remarkable differences and I don't know what they may be due....
I want to do this way because my purpose is to convert from geographic coordinates to heliocentric one.
from astropy.coordinates import SkyCoord
from astropy.time import Time
from astropy import units as u
from astroquery.jplhorizons import Horizons
time = '2015-03-30T21:33:52.000'
JD = Time(time).jd
observing_time = Time(time, format='isot', scale='utc')
#ASTROPY
c = SkyCoord(x=0,y=0,z=0, unit='au', representation_type='cartesian', frame='gcrs', obstime=time)
cc = c.transform_to("heliocentriceclipticiau76")
print(cc.cartesian.x, cc.cartesian.y, cc.cartesian.z)
cc = c.transform_to("heliocentricmeanecliptic")
print(cc.cartesian.x, cc.cartesian.y, cc.cartesian.z)
cc = c.transform_to("heliocentrictrueecliptic")
print(cc.cartesian.x, cc.cartesian.y, cc.cartesian.z)
#JPL'S HORIZONS
obj = Horizons(id="Geocenter", location="@sun", epochs=JD, id_type='id').vectors()
print(obj['x'], obj['y'], obj['z'])
Possibly this is no longer of interest after 2 years but for the benefit of future users who may get bitten by this subtlety, here's the answer. There is a subtle difference in the timescales that JPL HORIZONS, and by extension the
astroquery.jplhorizonscode, expects when asking for state vectors vs ephemerides. As documented under theepochspart ofHorizonsClass(docs):So while AstroPy is assuming UTC (you would be better passing your
observing_timeTimeobject to theSkyCoordroutine's constructor so it would explicitly know what timescale it's in and be able to convert it), you are passing a Julian Date (JD) in the UTC timescale to HORIZONS which is expecting a time in the TDB timescale. At the time you have asked for, the difference TDB-UTC is ~67.184s (plus or minus 1-2 milliseconds for relativistic reasons we can ignore) so you are not asking for the position of the Earth at the same time via the two methods.If you change your call to
Horizonstoobj = Horizons(id="Geocenter", location="@sun", epochs=observing_time.tdb.jd, id_type='id').vectors(delta_T=True)instead thenepochswill get a correct JD in the TDB timescale corresponding to the same UTC instant. (I also included thedelta_T=Truein the call to.vectors()so you can see the exact value of TDB-UTC). With this change, the resulting HORIZONS position matches the Astropy one within ~2 km which is within the stated precision for the position of the Earth produced by the erfa.epv00 routine used internally by AstroPy.