跳到内容
🛠️ToolsShed

Golden Hour Calculator

根据您的位置和日期查找黄金时段和蓝调时段摄影窗口。

关于此工具

黄金时刻是日出后不久和日落前不久太阳低悬的短暂时段,柔和温暖的光线将万物笼罩其中;而蓝色时刻则是日出前和日落后更深的暮光时分,天空被均匀而清冷的蓝色调填满。这两个时段都深受摄影师珍视,因为它们能拍出正午强光无法企及的柔美且富有氛围的影像。本计算器运用天文公式,精确推算出任意日期和地点这些时段的开始与结束时刻。

使用时只需输入日期和所在位置,工具便会显示日出和日落前后黄金时刻与蓝色时刻的起止时间。它专为希望将拍摄精确规划到分钟、并在光线最佳时抵达现场的摄影师、视频创作者和旅行者而设计。

请记住,这些时刻会随季节和纬度明显变化,因此请务必针对你的确切日期查询数据,而不要依赖粗略估计。所有计算均在你的浏览器本地完成,位置数据绝不会离开你的设备。

常见问题

代码实现

import math
from datetime import datetime, timedelta, timezone

def sun_times(lat: float, lon: float, date: datetime) -> dict:
    """Calculate sunrise, sunset and golden hour times."""
    # Day of year
    N = date.timetuple().tm_yday

    # Mean longitude and anomaly
    L = (280.460 + 0.9856474 * N) % 360
    g = math.radians((357.528 + 0.9856003 * N) % 360)

    # Ecliptic longitude
    lam = math.radians(L + 1.915 * math.sin(g) + 0.020 * math.sin(2 * g))

    # Declination
    decl = math.asin(math.sin(math.radians(23.439)) * math.sin(lam))

    # Hour angle for sunrise/sunset (sun altitude = -0.833°)
    cos_ha = (math.sin(math.radians(-0.833)) - math.sin(math.radians(lat)) * math.sin(decl)) /              (math.cos(math.radians(lat)) * math.cos(decl))

    if abs(cos_ha) > 1:
        return {"error": "Midnight sun or polar night"}

    ha = math.degrees(math.acos(cos_ha))

    # Equation of time correction (simplified)
    B = math.radians(360 / 365 * (N - 81))
    eot = 9.87 * math.sin(2 * B) - 7.53 * math.cos(B) - 1.5 * math.sin(B)

    # Solar noon in minutes from midnight UTC
    solar_noon = 720 - 4 * lon - eot

    sunrise_min = solar_noon - 4 * ha
    sunset_min  = solar_noon + 4 * ha

    # Golden hour bounds: sun at 6° above horizon
    cos_gh = (math.sin(math.radians(6)) - math.sin(math.radians(lat)) * math.sin(decl)) /              (math.cos(math.radians(lat)) * math.cos(decl))
    gh_ha = math.degrees(math.acos(max(-1, min(1, cos_gh))))

    golden_end_morn = solar_noon - 4 * gh_ha
    golden_start_eve = solar_noon + 4 * gh_ha

    def mins_to_str(m):
        h, mn = divmod(int(m), 60)
        return f"{h:02d}:{mn:02d}"

    return {
        "sunrise": mins_to_str(sunrise_min),
        "golden_hour_morning_end": mins_to_str(golden_end_morn),
        "solar_noon": mins_to_str(solar_noon),
        "golden_hour_evening_start": mins_to_str(golden_start_eve),
        "sunset": mins_to_str(sunset_min),
    }

# New York City
result = sun_times(40.7128, -74.0060, datetime(2024, 6, 21))
for k, v in result.items():
    print(f"{k}: {v}")

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.