【问题标题】:Calculating dawn and sunset times using PyEphem使用 PyEphem 计算黎明和日落时间
【发布时间】:2011-02-07 21:36:42
【问题描述】:

是否可以使用PyEphem 计算黎明、黄昏和日落时间?我已经使用 PyEphem 生成白天和黑夜时间,但在日落/黄昏/黎明时我没有找到任何东西

【问题讨论】:

    标签: python astronomy pyephem


    【解决方案1】:

    以下脚本将使用 PyEphem 计算日出、日落和黄昏时间。 cmets 应该足以解释每个部分在做什么。

    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 时区。

    ThisPyEphem 文档页面包含上述大部分内容,尽管我试图澄清我发现令人困惑的点并在 StackOverflow 上包含该链接的重要部分。

    【讨论】:

      【解决方案2】:

      对于黎明和黄昏,请参阅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。

      【讨论】:

        【解决方案3】:

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2015-01-17
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多