0

根据 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

现在,我还想根据太阳高度/方位角对一天中的早上/中午/晚上阶段进行分类。我想出了以下内容。

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()

我需要帮助以了解如何进一步进行,因为我没有有关天文计算的相关背景知识。谢谢

4

1 回答 1

0

根据Brandon评论,我使用天顶角的余弦来获得阳光强度,然后将阳光强度与天顶角组合在一起,形成一天中单调递增的函数。

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']

可以调整限制以更改中午所需的持续时间等。

于 2020-03-17T08:57:33.697 回答