获取基于太阳的一天中的阶段 altitude/azimuth
Get phase of day based on solar altitude/azimuth
根据 skyfield 在线文档,我能够计算出一天中的给定时间是 day 还是 night。
import skyfield.api
import skyfield.almanac
ts = skyfield.api.load.timescale()
ephemeris = skyfield.api.load('de421.bsp')
observer = skyfield.api.Topos(latitude_degrees=LAT, longitude_degrees=LON)
is_day_or_night = skyfield.almanac.sunrise_sunset(ephemeris, observer)
day_or_night = is_day_or_night(ts.utc(merged_df.index.to_pydatetime()))
s = pd.Series(data=['Day' if is_day else 'Night' for is_day in day_or_night],
index = merged_df.index, dtype='category')
merged_df['Day or Night'] = s
现在,我还想根据太阳能 altitude/azimuth 对一天的 morning/noon/evening 阶段进行分类。我想到了以下内容。
earth, sun = ephemeris['earth'], ephemeris['sun']
observer = earth + skyfield.api.Topos(latitude_degrees=LAT,
longitude_degrees=LON)
astrometric = observer.at(ts.utc(merged_df.index.to_pydatetime())).observe(sun)
alt, az, d = astrometric.apparent().altaz()
由于我没有天文计算的相关背景知识,因此我需要帮助以了解如何进一步进行。
谢谢
根据Brandon's ,我使用天顶角的余弦值来获取阳光强度,然后将阳光强度与天顶角一起破解,形成一天中单调递增的函数。
temp = pd.DataFrame({'zenith': 90 - alt.degrees,
'Day or Night': day_or_night},
index=merged_df.index)
temp['cos zenith'] = np.cos(np.deg2rad(temp['zenith']))
temp['feature'] = temp['cos zenith'].diff(periods=-1)*temp['zenith']
temp['Day Phase'] = None
temp.loc[temp['Day or Night'] == False, 'Day Phase'] = 'Night'
temp.loc[(temp['feature'] > -np.inf) & (temp['feature'] <= -0.035), 'Day Phase'] = 'Morning'
temp.loc[(temp['feature'] > -0.035) & (temp['feature'] <= 0.035), 'Day Phase'] = 'Noon'
temp.loc[(temp['feature'] > 0.035) & (temp['feature'] <= np.inf), 'Day Phase'] = 'Evening'
merged_df['Phase of Day'] = temp['Day Phase']
可以调整限制以更改中午等所需的持续时间
根据 skyfield 在线文档,我能够计算出一天中的给定时间是 day 还是 night。
import skyfield.api
import skyfield.almanac
ts = skyfield.api.load.timescale()
ephemeris = skyfield.api.load('de421.bsp')
observer = skyfield.api.Topos(latitude_degrees=LAT, longitude_degrees=LON)
is_day_or_night = skyfield.almanac.sunrise_sunset(ephemeris, observer)
day_or_night = is_day_or_night(ts.utc(merged_df.index.to_pydatetime()))
s = pd.Series(data=['Day' if is_day else 'Night' for is_day in day_or_night],
index = merged_df.index, dtype='category')
merged_df['Day or Night'] = s
现在,我还想根据太阳能 altitude/azimuth 对一天的 morning/noon/evening 阶段进行分类。我想到了以下内容。
earth, sun = ephemeris['earth'], ephemeris['sun']
observer = earth + skyfield.api.Topos(latitude_degrees=LAT,
longitude_degrees=LON)
astrometric = observer.at(ts.utc(merged_df.index.to_pydatetime())).observe(sun)
alt, az, d = astrometric.apparent().altaz()
由于我没有天文计算的相关背景知识,因此我需要帮助以了解如何进一步进行。 谢谢
根据Brandon's
temp = pd.DataFrame({'zenith': 90 - alt.degrees,
'Day or Night': day_or_night},
index=merged_df.index)
temp['cos zenith'] = np.cos(np.deg2rad(temp['zenith']))
temp['feature'] = temp['cos zenith'].diff(periods=-1)*temp['zenith']
temp['Day Phase'] = None
temp.loc[temp['Day or Night'] == False, 'Day Phase'] = 'Night'
temp.loc[(temp['feature'] > -np.inf) & (temp['feature'] <= -0.035), 'Day Phase'] = 'Morning'
temp.loc[(temp['feature'] > -0.035) & (temp['feature'] <= 0.035), 'Day Phase'] = 'Noon'
temp.loc[(temp['feature'] > 0.035) & (temp['feature'] <= np.inf), 'Day Phase'] = 'Evening'
merged_df['Phase of Day'] = temp['Day Phase']
可以调整限制以更改中午等所需的持续时间