Ric*_*ard 25
以下脚本将使用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
Run Code Online (Sandbox Code Playgroud)
重新定位地平线可以解释围绕地球曲率的光折射.考虑到温度和压力,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
Run Code Online (Sandbox Code Playgroud)
请注意,我们必须减去3个小时才能将它们转换为ADT时区.
这个 PyEphem文档页面包含了上面的大部分内容,虽然我试图澄清我发现令人困惑的点,并在StackOverflow中包含该链接的重要部分.
mjv*_*mjv 14
对于黎明黄昏AMD,看到关于暮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 .