2014-11-02 53 views
2

看起來像pyephem應該能夠給我你的標準的人類名稱,我們在月球週期中給定日期 - 「第一季度, 「」滿「,」打蠟月牙「,」漸漸萎縮「等。與Pyephem相關的月相人類可讀名字

我說得對嗎?

有沒有人知道一個標準的解決方案呢?

+0

您可以嘗試[this](https://stackoverflow.com/a/2526835/2629998)一段代碼。 – 2014-11-02 17:29:37

回答

2

這是我對自己問題的快速和骯髒的解決方案。它假定observer與系統時區處於同一時區,但這足夠滿足我的目的。

仍然感到驚訝pyhehem沒有比這更精緻的東西,但也許有一個天文理由,我不夠聰明理解。

import ephem 

def human_moon(observer): 
    target_date_utc = observer.date 
    target_date_local = ephem.localtime(target_date_utc).date() 
    next_full = ephem.localtime(ephem.next_full_moon(target_date_utc)).date() 
    next_new = ephem.localtime(ephem.next_new_moon(target_date_utc)).date() 
    next_last_quarter = ephem.localtime(ephem.next_last_quarter_moon(target_date_utc)).date() 
    next_first_quarter = ephem.localtime(ephem.next_first_quarter_moon(target_date_utc)).date() 
    previous_full = ephem.localtime(ephem.previous_full_moon(target_date_utc)).date() 
    previous_new = ephem.localtime(ephem.previous_new_moon(target_date_utc)).date() 
    previous_last_quarter = ephem.localtime(ephem.previous_last_quarter_moon(target_date_utc)).date() 
    previous_first_quarter = ephem.localtime(ephem.previous_first_quarter_moon(target_date_utc)).date() 
    if target_date_local in (next_full, previous_full): 
     return 'Full' 
    elif target_date_local in (next_new, previous_new): 
     return 'New' 
    elif target_date_local in (next_first_quarter, previous_first_quarter): 
     return 'First Quarter' 
    elif target_date_local in (next_last_quarter, previous_last_quarter): 
     return 'Last Full Quarter' 
    elif previous_new < next_first_quarter < next_full < next_last_quarter < next_new: 
     return 'Waxing Crescent' 
    elif previous_first_quarter < next_full < next_last_quarter < next_new < next_first_quarter: 
     return 'Waxing Gibbous' 
    elif previous_full < next_last_quarter < next_new < next_first_quarter < next_full: 
     return 'Waning Gibbous' 
    elif previous_last_quarter < next_new < next_first_quarter < next_full < next_last_quarter: 
     return 'Waning Crescent' 
3

除了月亮完全滿的時候,還沒有像「滿月」這樣的術語的標準定義。這意味着,從技術上講,月亮完全滿的時候只有一個確切的無限小時刻,因此任何你可以問PyEphem的真實時刻都將在完美時刻之前或之後。

所以,除非你能找到一個標準的定義,以秒爲單位的「寬」在滿月的時刻,那麼你詢問的任何給定秒的實際階段將是打蠟或減少。你可以諮詢USNO定義的所有細節:

http://aa.usno.navy.mil/faq/docs/moon_phases.php

由於標準有說,在黃道經度的差異是如何確定的階段,你可以嘗試這樣的事:

import ephem 
tau = 2.0 * ephem.pi 

sun = ephem.Sun() 
moon = ephem.Moon() 
names = ['Waxing Crescent', 'Waxing Gibbous', 
     'Waning Gibbous', 'Waning Crescent'] 

for n in range(1, 31): 
    s = '2014/%d/11' % n 
    sun.compute(s) 
    moon.compute(s) 

    sunlon = ephem.Ecliptic(sun).lon 
    moonlon = ephem.Ecliptic(moon).lon 

    angle = (moonlon - sunlon) % tau 
    quarter = int(angle * 4.0 // tau) 
    print n, names[quarter] 
+1

啊哈,好! 儘管如此,那個「確切的無限小時刻」 - 無論是全新月亮還是季度月亮 - 都是我真正需要的,pyephem確實會給我。爲了我的目的,發生無限小時刻的滿月的日期是滿月的日期。 – hanksims 2014-11-04 20:40:35