[time-nuts] Sunrise, solar noon, sunset and the Equation of Time
listertim at gmail.com
Wed Aug 31 22:33:29 EDT 2016
On Tue, Aug 30, 2016 at 10:07 PM, Mark Sims <holrum at hotmail.com> wrote:
> I recently added code to Lady Heather to precisely calculate the sun position, sunrise/solar noon/sunset times and the Equation of Time... Egad, what a deep, dark rabbit hole that leads one down. And woe be unto thee that trusts any of the online calculators. Results can be over 10 minutes off and nobody gives times down to the second. Oh, and there's a half dozen different types of sunrise/sunset to consider.
> The gold standard for those calculation is NREL's Solar Position Algorithm. It's awesome. It's also awesomely complex. Like 1300 lines of code and several thousand double precision operations and 300+ trig functions per result. It also has a rather wonky license agreement. (and if your time zone is not Greenwich is can report the sunrise or sunset time for the previous/next day)
> I finally settled on Grena's Algorithm 5 for sun position. It only around 100 lines long uses less than 20 trig function calls to calculate the sun position and produces results comparable to SPA for the years 2010 .. 2110.
> Getting sunrise/sunset/solar noon from solar position is a bit more complicated. I do binary searches and interpolations to find when the sun crosses the magic thresholds to within a second... it takes about 300 lines of code and 60 sun position evaluations. Lady Heather can now play sound files at sunrise, solar noon, sunset... your basic GPS disciplined rooster and church bells.
> And, for the sundial crowd, tomorrow is the day the Equation of Time crosses 0.0 seconds so get out and set your sundials...
Funnily enough I spent yesterday and today wrestling with the same
sort of code. I would recommend JPL HORIZONS for double-checking of
results - I would trust it with my spaceprobe's (if I had one) life...
You can set the time span (in UTC or TT) and then set it to output the
apparent azimuth & elevation at 1 second intervals for any body from
anywhere. There are little 'r', 't', 's' markers after the date to
indicate rise, transit and set.
You can use the local hour angle to give an approximate time within a
day for the rise, transit, and set and then use that as base to
interpolate for the horizon crossing. Chapter 13 of Meeus's
Astronomical Algorithms (a good book but like most books, predating
the major upheaval/revolution of the IAU 2000/2006 changes in
reference systems) has more information on this approach. A word of
caution; the suggested interpolation procedure, which was designed for
reading lines from an almanac, for the right ascension and declination
at +/-1 day *does not* work for the Moon which moves too quickly.
Better to have routine that returns RA,Dec for a given TDB time and
use that directly.
(I would also say that variations in air pressure, humidity and
temperature will alter the atmospheric refraction and therefore the
actual rise and set times by up to approx. 20-30 seconds. Unless Lady
Heather is going to interface to weather stations also, it's probably
not worth trying to kill yourself to get better accuracy better than a
More information about the time-nuts