我有一个函数,返回给定位置的日出、日落、太阳正午和黄昏时间。此函数使用pyephem,由于它已被弃用,我想我应该重新编写该函数以使用skyfield。但是,skyfield没有函数.previous_rising
、.next_setting
或{
skyfield确实有一个函数^{
from datetime import datetime, timedelta
from skyfield import api, almanac
import pytz
ts = api.load.timescale()
planets = api.load('de421.bsp')
sun, earth = planets['sun'], planets['earth']
lat, lon = '44.59028 N', '104.71528 W' # UFO Mooring Site
tzn, elv = 'US/Mountain', 1559
tz = pytz.timezone(tzn)
loc = api.Topos(lat, lon, elevation_m=elv)
earth_loc = earth + loc
def civil_twil(time):
"returns true/false if sun is above -6 degrees"
alt, az, dis = earth_loc.at(time).observe(sun).apparent().altaz()
return alt > -6
t0 = ts.utc(datetime.now(tz))
t1 = ts.utc(tz.normalize(datetime.now(tz) + timedelta(1)))
civil_dawn = almanac.find_discrete(t0, t1, civil_twil)
但这只是给了我一个错误,即函数缺少“rough_period”属性,而且文档中没有提到可能是什么。我会猜测它可能只对almanac类中定义的函数有效;但同样,它没有提到。在
《暮光之城》,我怎么能找到?在
文档中有一个example,用find_离散函数来查找日出和日落的值。有关此函数,请参阅almanac.py中的源代码。这里唯一的问题是,它只计算当太阳的顶部显然与地平线平齐的时候。在下面的示例中,我将
sunrise_sunset
函数改为daylength
函数。这样,您就可以给daylength
函数指定所需的角度。在这将打印以下结果:
第一个列表显示发现变化的时间,第二个列表显示}当太阳落山时。在
True
如果太阳升起(或黄昏开始),而{在您的例子中缺少的
rough_period
应该是一个浮点数,它表示每天发生的次数。太阳每天升起和落下一次,所以这个函数中的事件一天发生两次。这意味着rough_period
是0.5
。例如,当你想计算月相时,rough_period
可以设置为7.0
(满月轨道为27.3天,每相位为6.825天)。请参阅almanac.py源代码中有关季节或月亮阶段计算的其他示例。在相关问题 更多 >
编程相关推荐