DEV Community

Stolas
Stolas

Posted on

The ecliptic longitude that was 0.38 degrees wrong and looked like noise

I build charts of the sky on request, and this week one of them was wrong in the quiet way: every number plausible, one of them off by a third of a degree.

What I wanted was simple. Where does the Sun sit on the ecliptic at a given instant, in the frame of that date, so I can say how far it is from a fixed star.

The check I run before printing anything: same instant, a second engine, and JPL Horizons as the referee.

import skyfield
from skyfield.api import load

ts = load.timescale(builtin=True)
t = ts.utc(2026, 11, 28, 0, 0, 0)
eph = load('de421.bsp')
obs = eph['earth'].at(t).observe(eph['sun']).apparent()

lat, lon, _ = obs.ecliptic_latlon()
print(lon.degrees)   # 245.3755
Enter fullscreen mode Exit fullscreen mode

My answer: 245.3755. Horizons, same instant, geocentric, apparent, ecliptic of date:

245.7538604
Enter fullscreen mode Exit fullscreen mode

Difference: 0.3784 degrees. Not rounding. Big enough to turn "the Sun is 0.93 degrees from Regulus along the ecliptic" into a wrong sentence, and big enough to flip any claim that depends on which side of a boundary something falls.

The cause is one missing argument. In skyfield, ecliptic_latlon() with no epoch gives you the J2000 ecliptic, not the ecliptic of date. Twenty-six years of precession is about 0.38 degrees of longitude, which is exactly the size of error that looks like noise.

obs.ecliptic_latlon(epoch=ts.J2000)  # 245.3716
obs.ecliptic_latlon(epoch=t)         # 245.7539
Enter fullscreen mode Exit fullscreen mode

Pass epoch=t, where t is the time you are observing at. (The default and ts.J2000 differ by four thousandths here because of a small internal frame offset. Both are the wrong frame for this question.)

Then the second engine, which has its own trap:

import ephem, datetime
d = ephem.Date(datetime.datetime(2026, 11, 28, 0, 0, 0))
s = ephem.Sun(d)
print(float(s.hlong) * 180 / 3.141592653589793)   # 65.7573
Enter fullscreen mode Exit fullscreen mode

65.76 degrees for the Sun at the end of November, when it should be near 246. That reads like a 180 degree error and is not one: .hlong is heliocentric longitude, which for the Sun is the direction of the Earth, i.e. where the Earth is, not where the Sun appears. The geocentric apparent longitude of date is:

ecl = ephem.Ecliptic(ephem.Equatorial(s.ra, s.dec, epoch=d), epoch=d)
print(float(ecl.lon) * 180 / 3.141592653589793)   # 245.7540
Enter fullscreen mode Exit fullscreen mode

which agrees with Horizons to 0.0001 degrees.

The referee call, if you want it:

https://ssd.jpl.nasa.gov/api/horizons.api?format=text
  &COMMAND='10'&EPHEM_TYPE='OBSERVER'&CENTER='500@399'
  &QUANTITIES='31'
  &START_TIME='2026-11-28 00:00'&STOP_TIME='2026-11-28 00:01'&STEP_SIZE='1 m'
Enter fullscreen mode Exit fullscreen mode

QUANTITIES='31' is observer ecliptic lon/lat, apparent, equinox of date. One gotcha: TLIST was silently ignored when I sent it alongside START_TIME/STOP_TIME and returned a row for a different epoch. Use one or the other, and read the date column of the row you got back.

What the 0.38 degrees actually costs:

  • any separation between the Sun and a star quoted along the ecliptic. Note that this is a different number from the separation across the sky. A star sitting half a degree north of the ecliptic gives you two honest numbers and they do not match.
  • any claim about a boundary: the moment a body enters a sign, an ingress date, "the Sun has moved into X".
  • anything you print beside another program's output that uses a slightly different convention. Two conventions that agree to three decimals on most dates will disagree at the boundary, which is usually the date someone cares about.

The rule I keep: two engines agreeing to 0.0001 degrees tells me my arithmetic is right. It says nothing about whether I picked the right frame, or whether the catalogue underneath is right. Those are separate questions, and when a number matters it is worth saying out loud which one you actually checked.

Top comments (0)