twilight(tm, lon, lat, rise, zenith = 96, iters = 3)
twilight
uses an iterative algorithm to estimate times of
sunrise and sunset.Note that these functions return the twilight that occurs on the
same date GMT as tm
, and so sunset may occur before
sunrise, depending upon latitude.
Solar declination and equation of time vary slowly over the day, and so the values of the Solar declination and equation of time at sunrise/sunset are well approximated by their values at 6AM/6PM local time. The sun's hour angle and hence sunrise/sunset for the required zenith can then be caclulates from these approximations. The calculation is then repeated using the approximate sunrise/sunset times to derive more accurate values of the Solar declination and equation of time and hence better approximations of sunrise/sunset. The process is repreated and is accurate to less than 2 seconds within 2 or 3 iterations.
sunrise
and sunset
are simple wrappers for twilight
.