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
| Name | Symbol | Units | Description |
|---|---|---|---|
| Date | — | date | Calendar date for which sunrise/sunset is calculated |
| Latitude | degrees | Observer’s geographic latitude (positive north, negative south) | |
| Longitude | degrees | Observer’s geographic longitude (positive east, negative west) | |
| Altitude | meters | Observer’s elevation above mean sea level | |
| Standard UTC Offset | hours | Time zone offset from UTC (e.g., -5 for US Eastern Standard Time) |
Outputs
| Name | Symbol | Units | Description |
|---|---|---|---|
| Sunrise Time (UTC) | datetime | UTC datetime of sunrise | |
| Sunset Time (UTC) | datetime | UTC 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: where 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:- Atmospheric (~34 arcminutes = 0.567°)
- Solar disk radius (~16 arcminutes = 0.267°)
- Altitude-dependent correction (geometric horizon depression)
Step 3: Hour Angle at Sunrise/Sunset
The at which the sun crosses the corrected horizon is computed using the spherical trigonometry relationship: If the argument of arccos is outside the range [-1, 1], then:- : the sun never sets (polar day)
- : the sun never rises (polar night)
Step 4: Solar Time of Sunrise and Sunset
Convert the hour angle to . The hour angle is in radians, so convert to hours: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.
- is the equation of time correction from above (in minutes)
- converts longitude to minutes ( minutes per degree, with positive east)
- converts the UTC offset from hours to minutes
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: 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: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.