使用 PyEphem 计算黎明和日落时间

发布于 2024-08-29 01:03:22 字数 138 浏览 9 评论 0原文

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

Is it possible to calculate Dawn, Dusk, and sunset times using PyEphem? I've used PyEphem to produce day and night time, but I didn't find anything on sunset/dusk/dawn

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

淑女气质 2024-09-05 01:03:22

以下脚本将使用 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 网站上查看答案。

请注意,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

请注意,我们必须减去 3 小时才能将它们转换为 ADT 时区。

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

The following script will calculate sunrise, sunset, and twilight times using PyEphem. The comments should be adequate to explain what each part is doing.

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

Relocating the horizon accounts for light refracting around the curvature of the Earth. PyEphem has the capability to calculate this more exactly given a temperature and pressure, but the U.S. Naval Astronomical Almanac prefers to ignore the atmosphere and simply relocate the horizon. I refer to the USNAA here because it's an authoritative source against which these sorts of calculations can be checked. You can also check answers on NOAA's website.

Note that PyEphem takes and returns values in UTC time. This means that you have to convert your local time to UTC and then convert UTC back to local time to find the answers you're probably looking for. On the date I wrote this answer Fredericton, Canada, in the ADT timezone was 3 hours behind UTC.

For kicks, I've also thrown in a calculation of solar noon. Note that this is an additional hour off from what you'd expect - that's a side-effect of our using daylight savings time.

All this returns:

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

Note that we'd have to subtract 3 hours to convert them to the ADT timezone.

This PyEphem documentation page contains much of the above, though I've tried to both clarify points I found confusing and include the important parts of that link here on StackOverflow.

甜心 2024-09-05 01:03:22

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

For dawn amd dusk, see pyephem documentation regarding twilight
In a nutshell, dawn and dusk express the time when the center of the Sun is at a particular angle below the horizon; the angle used for this calculation varies for the definition of the "civilian", navigation (nautical) and astronomical twilights which use 6, 12 and 18 degrees respectively.

In opposition the sunrise corresponds to the time when the edge of the Sun appears (or disappears, for sunset) just above/below the horizon (0 degree). Hence everybody, civilians, sailors and astronomy enthusiasts alike get the same rise/set times. (see Naval Observatory risings and settings in pyephem documentation).

To summarize, once one has properly parametrized an pyephem.Observer (setting its lat, long, date, time, pressure (? for altitude?), etc.), the various twilight times (dawn, dusk) and the sunrise and sunset times are obtained from the
Observer.previous_rising() and Observer.next_setting() methods,
  whereby
  the first argument is ephem.Sun() and
  the use_center= argument needs to be set to True for twilight calculations, and
  the horizon is either 0 (or 0:34 if you account for refraction of the atmosphere) or -6, -12 or -18.

北笙凉宸 2024-09-05 01:03:22

您可以尝试将 horizo​​n 参数设置低于地平线根据黄昏/黎明的不同定义。

You could try to set the horizon parameter below the horizon according to the different definitions of dusk/dawn.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文