使用PyEphem计算黎明和日落时间

是否可以使用PyEphem计算黎明,黄昏和日落时间?我用PyEphem来制作白天和黑夜时间,但是我没有在日落/黄昏/黎明时找到任何东西     
已邀请:
黎明和黄昏,请参阅有关黄昏的pyephem文档 简而言之,黎明和黄昏表示太阳中心在地平线以下的特定角度的时间;用于此计算的角度因“民用”,导航(航海)和天文双重的定义而异,分别使用6度,12度和18度。 相反,日出对应于太阳的边缘在地平线上方/下方(0度)出现(或消失,为日落)的时间。因此,每个人,平民,水手和天文爱好者都会获得相同的上升/设定时间。 (参见海军天文台在pyephem文件中的上升和设置)。 总而言之,一旦一个人正确地参数化了
pyephem.Observer
(设置其纬度,长度,日期,时间,压力(高度?)等),就可以获得各种黄昏时间(黎明,黄昏)以及日出和日落时间。来自  
Observer.previous_rising()
Observer.next_setting()
方法,    因此    第一个参数是
ephem.Sun()
和    对于黄昏计算,需要将
use_center=
参数设置为
True
   地平线是0(如果考虑到大气的折射,则为0:34)或-6,-12或-18。     
以下脚本将使用PyEphem计算日出,日落和黄昏时间。评论应该足以解释每个部分正在做什么。
import ephem

#Make an observer
fred      = ephem.Observer()

#PyEphem takes and returns only UTC times. 15:00 is noon in Fredericton
fred.date = "2013-09-04 15:00:00"

#Location of Fredericton, Canada
fred.lon  = str(-66.666667) #Note that lon should be in string format
fred.lat  = str(45.95)      #Note that lat should be in string format

#Elevation of Fredericton, Canada, in metres
fred.elev = 20

#To get U.S. Naval Astronomical Almanac values, use these settings
fred.pressure= 0
fred.horizon = '-0:34'

sunrise=fred.previous_rising(ephem.Sun()) #Sunrise
noon   =fred.next_transit   (ephem.Sun(), start=sunrise) #Solar noon
sunset =fred.next_setting   (ephem.Sun()) #Sunset

#We relocate the horizon to get twilight times
fred.horizon = '-6' #-6=civil twilight, -12=nautical, -18=astronomical
beg_twilight=fred.previous_rising(ephem.Sun(), use_center=True) #Begin civil twilight
end_twilight=fred.next_setting   (ephem.Sun(), use_center=True) #End civil twilight
重新定位地平线可以解释围绕地球曲率的光折射。考虑到温度和压力,PyEphem有能力更精确地计算,但是美国海军天文年历更喜欢忽略大气并简单地重新定位地平线。我在这里指的是USNAA,因为它是一个权威来源,可以检查这些类型的计算。您还可以在NOAA的网站上查看答案。 请注意,PyEphem接收并返回UTC时间的值。这意味着您必须将本地时间转换为UTC,然后将UTC转换回本地时间以找到您可能正在寻找的答案。在我写这个答案的那天,加拿大的弗雷德里克顿在ADT时区落后于UTC 3小时。 对于踢球,我也投入了太阳正午的计算。请注意,这比您期望的还要多一小时 - 这是我们使用夏令时的副作用。 所有这些都返回:
begin civil twilight: 2013/9/4 09:20:46
sunrise:              2013/9/4 09:51:25
noon:                 2013/9/4 16:25:33
sunset:               2013/9/4 22:58:49
end civil twilight:   2013/9/4 23:29:22
请注意,我们必须减去3个小时才能将它们转换为ADT时区。 这个PyEphem文档页面包含了上面的大部分内容,虽然我试图澄清我发现令人困惑的点,并在StackOverflow中包含该链接的重要部分。     
您可以尝试根据黄昏/黎明的不同定义将
horizon
参数设置在地平线以下。     

要回复问题请先登录注册