pyephem:无法计算极地地区的日出/设定值

时间:2011-06-15 22:26:53

标签: pyephem

我正在尝试使用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中有一个错误,或者我误解了一些基本的东西。有什么帮助吗?

3 个答案:

答案 0 :(得分: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

另见链接问题中我的相关whiny抱怨。

答案 1 :(得分: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分钟vs -50分钟)。

答案 2 :(得分:0)

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