2010-04-14 27 views

回答

14

對於黎明AMD黃昏,見pyephem documentation regarding twilight
簡而言之,黎明和黃昏表達的時間時太陽的中心位於地平線以下的特定角度;用於此計算的角度因「平民」,導航(航海)和分別使用6度,12度和18度的天文暮色的定義而異。

在反對的日出邊緣太陽出現(或消失,日落)剛好高於/低於地平線(0度)時對應於時間。因此,每個人,平民,水手和天文愛好者都會得到相同的上升/固定時間。 (見Naval Observatory risings and settings in pyephem documentation)。

總之,一旦人們正確參數化的pyephem.Observer(設置它的緯度,經度,日期,時間,壓力(嗎?高度?)等),各種暮倍(黎明,黃昏)和日出和日落時間從
Observer.previous_rising()Observer.next_setting()方法獲得,
 由此  第一個參數爲ephem.Sun()
 的use_center=參數需要被設置到True爲暮計算,
 地平線是0(或0:34,如果你考慮大氣的折射)或-6,-12或-18。

4

根據dusk/dawn的不同定義,您可以嘗試設置horizon參數below the horizon

21

以下腳本將使用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's website上查看答案。

請注意,PyEphem需要並返回UTC時間的值。這意味着您必須將當地時間轉換爲UTC,然後將UTC轉換回當地時間以查找您可能要查找的答案。在我寫這個答案的日期中,加拿大弗雷德裏克頓在ADT timezone的時間比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時區。

This PyEphem文檔頁面包含了上面的大部分內容,儘管我試圖闡明兩點,我發現這些問題讓我感到困惑,並且在StackOverflow中包含了這個鏈接的重要部分。