Moon Phase Calculator
计算任何日期的当前月相、照度百分比和农历周期信息。
关于此工具
月相计算器帮您发现任何日期(过去、现在或未来)的当前月相、照明百分比和详细的月球周期信息。理解月球在其29.5天周期内的外观和位置对天文爱好者、遵循农历的园丁、规划夜间摄影的摄影师以及对我们天然卫星行为感到好奇的任何人都很有价值。
只需使用日历选择器输入任何日期,工具即刻显示月相名称、月盘的照明百分比、当前周期内的天数以及下一个满月或新月的日期。您可以探索您生日那天的月球外观,检查即将到来的天文事件的观测条件,或追踪月球周期如何影响植树或捕鱼等活动。
此计算器使用天文算法来计算月球位置,精度很高,非常适合教育项目、创意规划和随意的观星活动。请记住,照明百分比仅是近似值;实际可见性取决于您的位置、当地天气和夜间时间。
常见问题
代码实现
import math
from datetime import date, datetime
def calculate_moon_phase(year: int, month: int, day: int) -> dict:
"""
Calculate moon phase using the Conway algorithm.
Returns phase name, illumination percentage, and age in days.
"""
# Julian date calculation
if month <= 2:
year -= 1
month += 12
A = int(year / 100)
B = 2 - A + int(A / 4)
julian = int(365.25 * (year + 4716)) + int(30.6001 * (month + 1)) + day + B - 1524.5
# Days since known new moon (Jan 6, 2000)
known_new_moon = 2451549.5
lunation = 29.53058868
age = (julian - known_new_moon) % lunation
illumination = (1 - math.cos(2 * math.pi * age / lunation)) / 2
# Phase name
phases = [
(0.03, "New Moon"), (0.22, "Waxing Crescent"), (0.28, "First Quarter"),
(0.47, "Waxing Gibbous"), (0.53, "Full Moon"), (0.72, "Waning Gibbous"),
(0.78, "Last Quarter"), (0.97, "Waning Crescent"), (1.00, "New Moon")
]
fraction = age / lunation
phase_name = next(name for threshold, name in phases if fraction <= threshold)
return {
"age_days": round(age, 2),
"illumination_pct": round(illumination * 100, 1),
"phase": phase_name,
"fraction": round(fraction, 4)
}
result = calculate_moon_phase(2024, 1, 15)
print(f"Phase: {result['phase']}")
print(f"Age: {result['age_days']} days")
print(f"Illumination: {result['illumination_pct']}%")Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.