代码之家  ›  专栏  ›  技术社区  ›  dassouki

用pyephem计算黎明和日落时间

  •  16
  • dassouki  · 技术社区  · 15 年前

    是否可以使用 PyEphem ?我曾用毕弗制造白天和夜晚的时间,但在日落/黄昏/黎明时我什么也没有发现。

    3 回复  |  直到 7 年前
        1
  •  14
  •   mjv    15 年前

    为了 晨昏 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。

        2
  •  24
  •   Richard    11 年前

    下面的脚本将使用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 比联合技术公司晚了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中包含了该链接的重要部分。

        3
  •  4
  •   Michael Kuhn    15 年前

    你可以试着设置 horizon 参数 below the horizon 根据黄昏/黎明的不同定义。