使用 PyEphem 计算黎明和日落时间
是否可以使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
以下脚本将使用 PyEphem 计算日出、日落和黄昏时间。注释应该足以解释每个部分的作用。
重新定位地平线可以解释地球曲率周围的光折射。 PyEphem 能够在给定温度和压力的情况下更准确地计算这一点,但美国海军天文年鉴更喜欢忽略大气层并简单地重新定位地平线。我在这里提到 USNAA,因为它是可以检查此类计算的权威来源。您还可以在NOAA 网站上查看答案。
请注意,PyEphem 以 UTC 时间获取并返回值。这意味着您必须将本地时间转换为 UTC,然后将 UTC 转换回本地时间才能找到您可能正在寻找的答案。在我写此答案的日期,加拿大弗雷德里克顿的 ADT 时区 比 UTC 晚 3 小时。
为了好玩,我还计算了太阳正午的时间。请注意,这比您预期的时间多了一个小时 - 这是我们使用夏令时的副作用。
所有这些都会返回:
请注意,我们必须减去 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.
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:
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.
对于黎明和黄昏,请参阅有关 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 theObserver.previous_rising()
andObserver.next_setting()
methods,whereby
the first argument is
ephem.Sun()
andthe
use_center=
argument needs to be set toTrue
for twilight calculations, andthe horizon is either 0 (or 0:34 if you account for refraction of the atmosphere) or -6, -12 or -18.
您可以尝试将
horizon
参数设置低于地平线根据黄昏/黎明的不同定义。You could try to set the
horizon
parameter below the horizon according to the different definitions of dusk/dawn.