pyephem:无法计算极地地区的日出/日落时间

3
我正在尝试使用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存在bug,或者我对某些基本概念有所误解。需要帮助。


当我运行你的脚本时,输出了许多行代码。我想知道你的操作系统或环境与我的有何不同,以至于你的复制脚本什么也没有返回?请告诉我们你使用的操作系统版本、Python版本和PyEphem版本,这样我们可以进行比较。谢谢! - Brandon Rhodes
3个回答

1
我怀疑存在某种不当的缓存。考虑以下内容:
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

请参考我在链接问题中提出的相关抱怨。


1
我刚刚运行了你的程序并得到了这个输出(管道传递到“sort | uniq -c”):
260 2011/3/17 11:32:31
469 2011/3/17 13:42:56
184 2011/3/18 07:25:56
350 2011/3/18 18:13:15
191 2011/3/19 04:41:42
346 2011/9/24 20:25:13
337 2011/9/25 04:27:45
214 2011/9/25 17:36:10
166 2011/9/26 08:00:59
254 2011/9/26 14:37:06

你确定缩进是正确的吗?这是我的原始代码:

https://raw.github.com/barrycarter/bcapps/master/playground4.py

输出结果与我之前给出的答案不符,但我们使用的是不同的时间点(-34分钟与-50分钟)。


当我运行你的代码时,我也得到了很多输出行,这意味着如果你询问它们发生在哪一天,极地地区的日出和日落确实会被检测到。 - Brandon Rhodes

0

我发现使用obs.next_rising()start参数等可以获得更好的结果。然而,它有时仍然会错过某些交叉点;它找到的上升点并不总是与相应的下降点成对出现。


你能提供一个遗漏了交叉点的代码片段作为例子,这样我们就可以更详细地研究它吗?谢谢! - Brandon Rhodes

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接