Skip to main content

Summary

The Sunrise and Sunset Determination algorithm computes the times of sunrise and sunset for a given geographic location and date using a simplified solar geometry approach. PlantPredict uses an approximation method based on NOAA solar calculations that includes atmospheric , solar disk size, and altitude-dependent corrections. These sunrise and sunset times are used downstream to adjust weather timestamps near sunrise/sunset for more accurate solar position calculations, and for horizon shading computations.

Inputs

NameSymbolUnitsDescription
DatedateCalendar date for which sunrise/sunset is calculated
Latitudeφ\varphidegreesObserver’s geographic latitude (positive north, negative south)
Longitudeλ\lambdadegreesObserver’s geographic longitude (positive east, negative west)
AltitudehhmetersObserver’s elevation above mean sea level
Standard UTC OffsetUTCoff\text{UTC}_{\text{off}}hoursTime zone offset from UTC (e.g., -5 for US Eastern Standard Time)

Outputs

NameSymbolUnitsDescription
Sunrise Time (UTC)trise,UTCt_{\text{rise,UTC}}datetimeUTC datetime of sunrise
Sunset Time (UTC)tset,UTCt_{\text{set,UTC}}datetimeUTC datetime of sunset

Detailed Description

PlantPredict implements a simplified sunrise/sunset algorithm that uses an approximate solar formula and includes corrections for atmospheric refraction, solar disk size, and observer altitude.

Step 1: Approximate Solar Declination

The solar declination is computed using a simplified sinusoidal approximation: δ=23.44×sin(2π(284+n)365.25)\delta = 23.44^\circ \times \sin\left(\frac{2\pi (284 + n)}{365.25}\right) where nn is the day of year extracted from the input date (1 = January 1, 365/366 = December 31). This formula, based on the NOAA Solar Calculator, approximates the sun’s declination throughout the year, with maximum positive declination (23.44°) occurring near the summer solstice (around day 172) and maximum negative declination (−23.44°) near the winter solstice (around day 355).

Step 2: Horizon Angle with Corrections

The at which sunrise/sunset occurs is computed to account for:
  1. Atmospheric (~34 arcminutes = 0.567°)
  2. Solar disk radius (~16 arcminutes = 0.267°)
  3. Altitude-dependent correction (geometric horizon depression)
The combined horizon correction zenith angle is: θhorizon=90.833+0.0347max(h,0)\theta_{\text{horizon}} = 90.833^\circ + 0.0347 \sqrt{\max(h, 0)} where 0.0347h0.0347 \sqrt{h} accounts for the geometric horizon depression due to Earth’s curvature—at higher elevations, the horizon appears lower because Earth curves away beneath the observer; if h<0h < 0 it is set to zero.

Step 3: Hour Angle at Sunrise/Sunset

The H0H_0 at which the sun crosses the corrected horizon is computed using the spherical trigonometry relationship: cos(H0)=cos(θhorizon)sin(φ)sin(δ)cos(φ)cos(δ)\cos(H_0) = \frac{\cos(\theta_{\text{horizon}}) - \sin(\varphi) \sin(\delta)}{\cos(\varphi) \cos(\delta)} If the argument of arccos is outside the range [-1, 1], then:
  • cos(H0)<1\cos(H_0) < -1: the sun never sets (polar day)
  • cos(H0)>1\cos(H_0) > 1: the sun never rises (polar night)
The polar cases are handled in Step 6. Otherwise: H0=arccos(cos(θhorizon)cos(δ)cos(φ)tan(δ)tan(φ))H_0 = \arccos\left(\frac{\cos(\theta_{\text{horizon}})}{\cos(\delta) \cos(\varphi)} - \tan(\delta) \tan(\varphi)\right)

Step 4: Solar Time of Sunrise and Sunset

Convert the hour angle to . The hour angle is in radians, so convert to hours: trise,solar=12H0×180π×(360/24hr)=12(1H0π)t_{\text{rise,solar}} = 12 - \frac{H_0 \times 180^\circ}{\pi \times (360^\circ / 24\text{hr})} = 12 \left(1 - \frac{H_0}{\pi}\right) tset,solar=12+H0×180π×(360/24hr)=12(1+H0π)t_{\text{set,solar}} = 12 + \frac{H_0 \times 180^\circ}{\pi \times (360^\circ / 24\text{hr})} = 12 \left(1 + \frac{H_0}{\pi}\right)

Step 5: Convert Local Solar Time to Local Standard Time

This step converts to and involves two corrections: 1. Equation of Time Correction This first correction is to account for the fact that the sun does not move at a constant rate across the sky. Consequently, the interval between consecutive solar noons is not exactly 24 hours and varies slightly from day to day (by up to ±30 seconds). These differences accumulate throughout the year. The (EoT) corrects for this variation, which arises from two effects:
  • Earth’s elliptical orbit: Earth moves faster near perihelion (January) and slower near aphelion (July), per Kepler’s second law
  • Earth’s axial tilt: The sun moves along the ecliptic (tilted 23.44°), but time is measured based on the sun’s east-west motion projected onto the celestial equator. This projection causes the apparent rate to vary: slower at the equinoxes, faster at the solstices.
These effects combine to produce a correction ranging from approximately −14 to +16 minutes depending on the time of year. PlantPredict uses a second-order Fourier series approximation of the equation of time, following Spencer (1971). First, compute the γ\gamma (in radians) from the day of year nn and the solar time to be corrected tsolart_{\text{solar}}: γ=2π365.24(n1+tsolar24)\gamma = \frac{2\pi}{365.24} \left(n - 1 + \frac{t_{\text{solar}}}{24}\right) The equation of time correction (in minutes) is: EoT=229.18×(0.000075+0.001868cos(γ)0.032077sin(γ)0.014615cos(2γ)0.040849sin(2γ))\begin{aligned} \text{EoT} &= 229.18 \times \Big( 0.000075 + 0.001868 \cos(\gamma) - 0.032077 \sin(\gamma) \\ &\quad - 0.014615 \cos(2\gamma) - 0.040849 \sin(2\gamma) \Big) \end{aligned} 2. Time Offset from UTC and Longitude Correction An additional correction is required to account for the longitude and the offset from UTC. The combined time offset (in minutes) from local solar time to local standard time is: TimeOffset=EoT+4λ60×UTCoff\text{TimeOffset} = \text{EoT} + 4\lambda - 60 \times \text{UTC}_{\text{off}} where:
  • EoT\text{EoT} is the equation of time correction from above (in minutes)
  • 4λ4\lambda converts longitude to minutes (60×24/360=460 \times 24 / 360 = 4 minutes per degree, with positive east)
  • 60×UTCoff60 \times \text{UTC}_{\text{off}} converts the UTC offset from hours to minutes
The local solar time is then converted to the local standard time tlocalt_{\text{local}}, in hours: trise,local=trise,solarTimeOffset60t_{\text{rise,local}} = t_{\text{rise,solar}} - \frac{\text{TimeOffset}}{60} tset,local=tset,solarTimeOffset60t_{\text{set,local}} = t_{\text{set,solar}} - \frac{\text{TimeOffset}}{60}

Step 6: Handle Polar Conditions

If the cosine term in Step 3 returned a value outside the range [-1, 1] (sun never crosses the horizon), the code sets: trise,local=0.0,tset,local=24.0t_{\text{rise,local}} = 0.0, \quad t_{\text{set,local}} = 24.0 This simplification does not distinguish between polar day and polar night—both result in a full 24-hour “day.” However, the calculated sunrise and sunset times are only used to adjust timestamps for intervals that straddle sunrise or sunset, and for horizon shading calculations. In polar conditions, no intervals straddle the 0:00/24:00 boundaries, so the sunrise/sunset-specific adjustments simply don’t apply.

Step 7: Convert to UTC DateTime

Add the local times (in decimal hours) to the date, then convert to UTC: trise,UTC=Date+trise,local hours+UTCofft_{\text{rise,UTC}} = \text{Date} + t_{\text{rise,local}} \text{ hours} + \text{UTC}_{\text{off}} tset,UTC=Date+tset,local hours+UTCofft_{\text{set,UTC}} = \text{Date} + t_{\text{set,local}} \text{ hours} + \text{UTC}_{\text{off}}

References

  • NOAA Solar Calculator. NOAA Earth System Research Laboratory, Global Monitoring Division. https://gml.noaa.gov/grad/solcalc/
  • Duffie, J. A., & Beckman, W. A. (2013). Solar Engineering of Thermal Processes (4th ed.). John Wiley & Sons.
  • Spencer, J. W. (1971). Fourier series representation of the position of the Sun. Search, 2(5), 172.