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 中存在错误,要么我误解了一些基本的东西。有什么帮助吗?

4

3 回答 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

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

于 2013-02-02T04:45:10.580 回答
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 分钟)。

于 2013-02-02T04:54:51.043 回答
0

我发现使用start参数 toobs.next_rising()等会产生更好的结果。然而,它有时似乎仍然错过了某些过境点;它发现的上升并不总是与相应的组合配对。

于 2011-06-25T22:41:10.117 回答