If you want to match NOAA, you'll have to consult Jean Meeus' Astronomical Algorithms (mostly Chapter 15). And it's complicated! Martin Beckett is correct, you have to define the sunset. Typically this is the apparent rise or set of upper limb of the sun, which makes your "standard" altitide -5/6 degrees (not zero). And you can't calculate the sunrise or sunset directly with NOAA's accuracy. You'll have to create a governing set of equations for apparent right ascension and declination for the day in question and then interpolate the apparent right ascension and declination over time to find the exact rising and setting times at the standard altitude.
Hope this helps. I spent about a month digesting AA and re-writing all our solar code when I came across the same thing, and it still took over a year to sort out some of the corner cases where my code broke. So it will take some time to figure out. I'm not aware of any public code examples of this algorithm and don't have any to share at this moment, but I'm happy to help you through some headaches if I can.
For accuracy in the 5min range you have to consider 'which' sunset. Do you want the time the bottom of the sun touches the horizon or the time the top of the sun passes below the horizon?
It takes 2mins for the sun to cross the horizon. Below the 1min level you also need to take into account atmospheric refraction.
日出/日落的定义可能有所不同。 例如,在 ephem 中,“上升和下降被定义为当身体上肢接触地平线(即当身体的 alt 加半径等于 0 时)" [PyEphem 快速参考]。
#!/usr/bin/env python
import datetime
import ephem # to install, run `pip install pyephem`
o = ephem.Observer()
o.lat, o.long, o.date = '34:3', '-118:15', datetime.datetime.utcnow()
sun = ephem.Sun(o)
print "Los Angeles"
print "sunrise:", o.next_rising(sun), "UTC"
print "sunset:",o.next_setting(sun), "UTC"
输出
Los Angeles, CA
sunrise: 2010/3/30 13:42:43 UTC
sunset: 2010/3/30 02:11:50 UTC
如果它是开源库,那么您可以修复它,而不是创建一个带有新错误的新库。
Definitions of what constitutes sunrise/sunset can vary. For example, in ephem "rising and setting are defined as the moments when the upper limb of the body touches the horizon (that is, when the body’s alt plus radius equals zero)" [PyEphem Quick Reference].
#!/usr/bin/env python
import datetime
import ephem # to install, run `pip install pyephem`
o = ephem.Observer()
o.lat, o.long, o.date = '34:3', '-118:15', datetime.datetime.utcnow()
sun = ephem.Sun(o)
print "Los Angeles"
print "sunrise:", o.next_rising(sun), "UTC"
print "sunset:",o.next_setting(sun), "UTC"
Output
Los Angeles, CA
sunrise: 2010/3/30 13:42:43 UTC
sunset: 2010/3/30 02:11:50 UTC
If it is open-source library then you could fix it instead of creating a new one with new bugs.
include Math
# degrees to radians = PI/180
to_r = PI/180.0
#radians to degrees = 180/PI
to_d = 180.0/PI
puts "Day, Declination, EofT"
# test a celestial year worth of values.
for jday in 1..366
et = -7.633 * sin(jday * (2 * PI)/365.24) + 9.65 * sin((jday - 78) * 180/92 * to_r)
a_sin = sin(23.433 * to_r) * sin((2 * PI/366) * (jday - 81))
declination = asin(a_sin) * to_d
puts "#{jday}, #{declination}, #{et}"
end
然后对于上面的等式:
# center disk and refraction factor have been considered.
cos_omega = sin(-0.83 * to_r) - tan(latitude * to_r) * tan(declination * to_r)
semi_diurnal_arc = acos(cos_omega)
include Math
# degrees to radians = PI/180
to_r = PI/180.0
#radians to degrees = 180/PI
to_d = 180.0/PI
puts "Day, Declination, EofT"
# test a celestial year worth of values.
for jday in 1..366
et = -7.633 * sin(jday * (2 * PI)/365.24) + 9.65 * sin((jday - 78) * 180/92 * to_r)
a_sin = sin(23.433 * to_r) * sin((2 * PI/366) * (jday - 81))
declination = asin(a_sin) * to_d
puts "#{jday}, #{declination}, #{et}"
end
Then for the above equation:
# center disk and refraction factor have been considered.
cos_omega = sin(-0.83 * to_r) - tan(latitude * to_r) * tan(declination * to_r)
semi_diurnal_arc = acos(cos_omega)
I did see some interesting things on this NOAA page under the Technical Definitions and Computational Details heading, but I'm sure you've read that already.
As a side note (it doesn't answer your question directly), is there a reason you can't pull the NOAA data and use it as a lookup table instead of calculating it? Storage tends to be relatively cheap these days.
发布评论
评论(8)
您可以考虑阅读维基百科关于日出方程的文章。 主要段落给出了方程:
cos(ωo) = -tan(φ) * tan(δ)
其中:
You may consider reading Wikipedia's article on sunrise equations. The lead paragraph gives the equation:
cos(ωo) = -tan(φ) * tan(δ)
where:
如果你想与 NOAA 匹配,你必须查阅 Jean Meeus 的天文算法(主要是第 15 章)。 而且很复杂! 马丁·贝克特是对的,你必须定义日落。 通常,这是太阳上肢的明显升起或落下,这使得您的“标准”海拔高度为 -5/6 度(不是零)。 而且你无法直接以 NOAA 的精度计算日出或日落。 您必须为相关日期的视赤经和赤纬创建一组控制方程,然后对一段时间内的视赤经和赤纬进行插值,以找到标准高度下准确的上升和落下时间。
希望这可以帮助。 当我遇到同样的事情时,我花了大约一个月的时间来消化AA并重写我们所有的太阳能代码,并且仍然花了一年多的时间来整理我的代码出现问题的一些极端情况。 所以需要一些时间来弄清楚。 我不知道该算法的任何公共代码示例,目前也没有任何可分享的,但如果可以的话,我很乐意帮助您解决一些令人头痛的问题。
If you want to match NOAA, you'll have to consult Jean Meeus' Astronomical Algorithms (mostly Chapter 15). And it's complicated! Martin Beckett is correct, you have to define the sunset. Typically this is the apparent rise or set of upper limb of the sun, which makes your "standard" altitide -5/6 degrees (not zero). And you can't calculate the sunrise or sunset directly with NOAA's accuracy. You'll have to create a governing set of equations for apparent right ascension and declination for the day in question and then interpolate the apparent right ascension and declination over time to find the exact rising and setting times at the standard altitude.
Hope this helps. I spent about a month digesting AA and re-writing all our solar code when I came across the same thing, and it still took over a year to sort out some of the corner cases where my code broke. So it will take some time to figure out. I'm not aware of any public code examples of this algorithm and don't have any to share at this moment, but I'm happy to help you through some headaches if I can.
为了确保 5 分钟范围内的准确性,您必须考虑“哪个”日落。
您想要太阳底部触及地平线的时间还是太阳顶部经过地平线以下的时间?
太阳穿过地平线需要 2 分钟。
低于 1 分钟水平时,您还需要考虑大气折射。
For accuracy in the 5min range you have to consider 'which' sunset.
Do you want the time the bottom of the sun touches the horizon or the time the top of the sun passes below the horizon?
It takes 2mins for the sun to cross the horizon.
Below the 1min level you also need to take into account atmospheric refraction.
日出/日落的定义可能有所不同。 例如,在
ephem
中,“上升和下降被定义为当身体上肢接触地平线(即当身体的 alt 加半径等于 0 时)" [PyEphem 快速参考]。输出
如果它是开源库,那么您可以修复它,而不是创建一个带有新错误的新库。
Definitions of what constitutes sunrise/sunset can vary. For example, in
ephem
"rising and setting are defined as the moments when the upper limb of the body touches the horizon (that is, when the body’s alt plus radius equals zero)" [PyEphem Quick Reference].Output
If it is open-source library then you could fix it instead of creating a new one with new bugs.
看看这本书:
“用计算器进行实用天文学(平装本)”作者:Peter Duffett-Smith。
虽然很旧了,但仍在印刷中......
链接
Have a look at this book:
"Practical Astronomy with your Calculator (Paperback)" by Peter Duffett-Smith.
It is quite old but still in print...
link
我在 Ruby 中为时间方程写了这个。
然后对于上面的等式:
有一个完整的网站致力于此,位于 http://www.analemma.com/
In Ruby I wrote this for equation of time.
Then for the above equation:
There is a whole website devoted to this at http://www.analemma.com/
您可能想查看有关计算太阳位置的早期条目。 具体来说,我指出的 Solpos 程序支持日出/日落。
You might want to look at an earlier entry on calculating the position of the sun. Specifically, the Solpos program that I pointed to has support for sunrise/sunset.
我确实在这个NOAA页面的技术定义下看到了一些有趣的东西和计算细节标题,但我相信您已经阅读过。
SO问题的答案“太阳给定的一天中的时间,以及纬度/经度”,上面的内容实际上可能就是您所需要的。
作为旁注(它不会直接回答您的问题),您是否有理由无法提取 NOAA 数据并将其用作查找表而不是计算它? 如今,存储往往相对便宜。
I did see some interesting things on this NOAA page under the Technical Definitions and Computational Details heading, but I'm sure you've read that already.
The answer to the SO question "Position of the sun given time of day, and lat/long" and the above may actually be all you need.
As a side note (it doesn't answer your question directly), is there a reason you can't pull the NOAA data and use it as a lookup table instead of calculating it? Storage tends to be relatively cheap these days.