0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Skyfield で今日の月齢を計算してみた

Posted at

はじめに

月齢をPython(Skyfield)で計算してみました。
月齢は日付から直接決まるものではなく
太陽と月の位置関係(角度)を
日数に換算したものです。

月齢の正体:太陽と月の「角度差」

月齢は
太陽と月の黄経(こうけい、ecliptic longitude)の差で決まります。

位相 太陽−月の角度
新月
上弦 90°
満月 180°
下弦 270°
1周期 360°

この 360° が
約 29.53 日(朔望月) に対応します。

Pythonで計算してみます(Skyfield使用)

1. ライブラリと天体暦の読み込み

from skyfield.api import load

eph = load('de421.bsp')   # JPLの天体暦データ
ts = load.timescale()

2. 今日の日時

t = ts.now()

3. 太陽と月の位置を取得

sun = eph['sun']
moon = eph['moon']
earth = eph['earth']

s = earth.at(t).observe(sun).apparent()
m = earth.at(t).observe(moon).apparent()

4. 黄経(ecliptic longitude)を取得

_, sun_lon, _ = s.ecliptic_latlon()
_, moon_lon, _ = m.ecliptic_latlon()

sun_lon.degrees:太陽の黄経(度)
moon_lon.degrees:月の黄経(度)

5. 位相角(0〜360°)を計算

phase_angle = (moon_lon.degrees - sun_lon.degrees) % 360

% 360 で
角度が0〜360° に収まります。

6. 角度 → 月齢(日)

moon_age = phase_angle / 360 * 29.53

7. 結果表示

print(f"位相角: {phase_angle:.2f}°")
print(f"今日の月齢: {moon_age:.2f}")

補足:便利関数との違い

Skyfield には

from skyfield import almanac
almanac.moon_phase(eph, t)

という便利関数がありますが
学習目的として
角度から計算しました。

この計算を使って作ったアプリ

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?