I am trying to calculate sunrises and sunsets using pyephem, but the algorithm never converges for polar regions?
follow the code example below. it repeats itself after a whole year with a 10-minute step, asking for the next dawn and sunset. pyephem always returns with AlwaysUpError or NeverUpError, but surely the sun should 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 use the api incorrectly, there is an error in pyephem, or I misunderstand something fundamental. any help?
source
share