我正在尝试使用pyephem计算日出和日落,但该算法似乎从未收敛于极地地区?

遵守下面的示例代码。它以10分钟为增量迭代整年,要求下一次日出和日落。 pyephem总是以AlwaysUpError或NeverUpError返回,但是确定一年中太阳必须升起并落下至少一次吗?

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


我不是正确使用了api,pyephem中有一个错误,还是我误解了一些基本知识。有什么帮助吗?

最佳答案

我怀疑某种不适当的缓存。考虑:

import ephem
atlanta = ephem.Observer()
atlanta.pressure = 0
atlanta.horizon = '-0:34'
atlanta.lat, atlanta.lon = '89:30', '0'
atlanta.date = '2011/03/18 12:00'
print atlanta.previous_rising(ephem.Sun())
print atlanta.next_setting(ephem.Sun())
atlanta.date = '2011/03/19 12:00'
print atlanta.previous_rising(ephem.Sun())
print atlanta.next_setting(ephem.Sun())
atlanta.date = '2011/03/20 12:00'
print atlanta.previous_rising(ephem.Sun())
# print atlanta.next_setting(ephem.Sun())
atlanta.date = '2011/09/24 12:00'
# print atlanta.previous_rising(ephem.Sun())
print atlanta.next_setting(ephem.Sun())
atlanta.date = '2011/09/25 12:00'
print atlanta.previous_rising(ephem.Sun())
print atlanta.next_setting(ephem.Sun())
atlanta.date = '2011/09/26 12:00'
print atlanta.previous_rising(ephem.Sun())
print atlanta.next_setting(ephem.Sun())


产生:

2011/3/18 07:49:34
2011/3/18 17:44:50
2011/3/19 05:04:49
2011/3/19 21:49:23
2011/3/20 01:26:02
2011/9/24 19:59:09
2011/9/25 04:57:21
2011/9/25 17:14:10
2011/9/26 08:37:25
2011/9/26 14:03:20


符合分钟的USNO结果:

https://raw.github.com/barrycarter/bcapps/master/db/srss-895.txt

另请参阅我在链接问题中的相关抱怨抱怨。

关于pyephem - pyephem:无法计算极地地区的日出/时间,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6365182/

10-09 20:53