i'm trying to calculate sunrises and sunsets using pyephem, but the algorithm never seems to converge for polar regions?
observe the sample code below. it iterates through an entire year in 10-minute increments asking for the next sunrise and sunset. pyephem always returns with an AlwaysUpError or NeverUpError, but surely the sun must rise and set at least once during the year?
import ephem
from datetime import datetime, timedelta
obs = ephem.Observer()
obs.lat = '89:30'
obs.long = '0'
start = datetime(2011, 1, 1)
end = datetime(2012, 1, 1)
step = timedelta(minutes=10)
sun = ephem.Sun()
timestamp = start
while timestamp < end:
obs.date = timestamp
try:
print obs.next_rising(sun)
except (ephem.AlwaysUpError, ephem.NeverUpError):
pass
try:
print obs.next_setting(sun)
except (ephem.AlwaysUpError, ephem.NeverUpError):
pass
try:
print obs.previous_rising(sun)
except (ephem.AlwaysUpError, ephem.NeverUpError):
pass
try:
print obs.previous_setting(sun)
except (ephem.AlwaysUpError, ephem.NeverUpError):
pass
timestamp += step
either i'm using the api incorrectly, there's a bug in pyephem, or i'm misunderstanding something fundamental. any help?