-
Calculate Julian Day (JD):
-
Adjustment for Months January and February:
If the month is January or February (month <= 2), subtract 1 from the year and add 12 to the month:
[
\text{if } month \leq 2: \quad year = year - 1, \quad month = month + 12
]
-
Intermediate Variables:
[
A = \left\lfloor \dfrac{year}{100} \right\rfloor
]
[
B = 2 - A + \left\lfloor \dfrac{A}{4} \right\rfloor
]
-
Julian Day Calculation:
[
JD = \left\lfloor 365.25 \times (year + 4716) \right\rfloor + \left\lfloor 30.6001 \times (month + 1) \right\rfloor + day + B - 1524.5
]
Calculates the Julian Day, a continuous count of days since the beginning of the Julian Period.
-
Calculate Julian Century (JC):
[
JC = \dfrac{JD - 2451545.0}{36525.0}
]
Represents the number of Julian centuries since J2000.0.
-
Calculate Geometric Mean Longitude of the Sun (L_0):
[
L_0 = 280.46646 + JC \times (36000.76983 + JC \times 0.0003032) \mod 360
]
The mean longitude of the sun, adjusted within a 0° to 360° range.
-
Calculate Geometric Mean Anomaly of the Sun (M):
[
M = 357.52911 + JC \times (35999.05029 - 0.0001537 \times JC)
]
The angular distance of the sun from its perihelion position.
-
Calculate Eccentricity of Earth's Orbit (e):
[
e = 0.016708634 - JC \times (0.000042037 + 0.0000001267 \times JC)
]
Measures the deviation of Earth's orbit from a perfect circle.
-
Calculate Sun's Equation of the Center (C):
[
\begin{align*}
C = & \sin(M) \times \left(1.914602 - JC \times (0.004817 + 0.000014 \times JC)\right) \
& + \sin(2 \times M) \times \left(0.019993 - 0.000101 \times JC\right) \
& + \sin(3 \times M) \times 0.000289
\end{align*}
]
Corrects the mean anomaly to account for the elliptical shape of Earth's orbit.
-
Calculate Sun's True Longitude (\text{true\_long}):
[
\text{true_long} = L_0 + C
]
Represents the sun's true geometric longitude.
-
Calculate Sun's Apparent Longitude (\lambda_{\text{sun}}):
-
Calculate Omega (\omega):
[
\omega = 125.04 - 1934.136 \times JC
]
-
Apparent Longitude:
[
\lambda_{\text{sun}} = \text{true_long} - 0.00569 - 0.00478 \times \sin(\omega)
]
Corrects the true longitude for the effects of nutation and aberration.
-
Calculate Mean Obliquity of the Ecliptic (\epsilon_0):
The mean tilt of Earth's axis relative to its orbital plane.
-
Calculate Corrected Obliquity (\epsilon):
[
\epsilon = \epsilon_0 + 0.00256 \times \cos(\omega)
]
Adjusts the mean obliquity for nutation.
-
Calculate Sun's Declination (\sin(\delta) and \cos(\delta)):
[
\sin(\delta) = \sin(\epsilon) \times \sin(\lambda_{\text{sun}})
]
[
\cos(\delta) = \cos\left(\arcsin\left(\sin(\delta)\right)\right)
]
Determines the sun's angle north or south of the celestial equator.
-
Calculate Equation of Time (EoT):
-
Intermediate Variable (y):
[
y = \tan\left(\dfrac{\epsilon}{2}\right)^2
]
-
Equation of Time:
[
\begin{align*}
EoT = & 4 \times \left[ y \times \sin(2 \times L_0) - 2 \times e \times \sin(M) \right. \
& + 4 \times e \times y \times \sin(M) \times \cos(2 \times L_0) \
& - 0.5 \times y^2 \times \sin(4 \times L_0) - 1.25 \times e^2 \times \sin(2 \times M) \Bigg]
\end{align*}
]
Accounts for the irregularity of solar time due to Earth's elliptical orbit and axial tilt.
-
Calculate Hour Angle (\cos(h_a) and h_a):
-
Calculate Cosine of Hour Angle:
[
\cos(h_a) = \dfrac{\cos(90.833^\circ) - (\cos(\text{latitude}) \times \sin(\delta))}{\sin(\text{latitude}) \times \cos(\delta)}
]
-
Handle Polar Day or Night:
If (|\cos(h_a)| > 1), the sun does not rise or set on this date at this location.
-
Calculate Hour Angle:
[
h_a = \arccos(\cos(h_a))
]
Determines the time difference from solar noon to sunrise or sunset.
-
Calculate Solar Noon (\text{solar\_noon}):
[
\text{solar_noon} = \dfrac{720 - 4 \times \text{longitude} - EoT + \text{timezone_offset} \times 60}{1440}
]
The time of day, in fractional days, when the sun is at its highest point.
-
Calculate Sunrise and Sunset Times (\text{sunrise\_time} and \text{sunset\_time}):
Calculates the times of sunrise and sunset in fractional days.
-
Convert Times to Decimal Hours (\text{sunrise} and \text{sunset}):
[
\text{sunrise} = (\text{sunrise_time} \times 24) \mod 24
]
[
\text{sunset} = (\text{sunset_time} \times 24) \mod 24
]
Converts the fractional day times to decimal hours adjusted to the local timezone.
By following the outlined steps and formulas, the function calculates the sun's apparent position in the sky and adjusts for the observer's timezone. It handles special cases, such as polar day or night, by returning None when the sun does not rise or set.
This method provides a high-precision calculation suitable for most practical purposes, reflecting astronomical phenomena affecting the sun's observed trajectory from Earth.