Sunrise equation
The sunrise equation or sunset equation can be used to derive the time of sunrise or sunset for any solar declination and latitude in terms of local solar time when sunrise and sunset actually occur.
Formulation
It is formulated as:where:
Principles
The Earth rotates at an angular velocity of 15°/hour. Therefore, the expression, where is in degree, gives the interval of time in hours from sunrise to local solar noon or from local solar noon to sunset.The sign convention is typically that the observer latitude is 0 at the equator, positive for the Northern Hemisphere and negative for the Southern Hemisphere, and the solar declination is 0 at the vernal and autumnal equinoxes when the sun is exactly above the equator, positive during the Northern Hemisphere summer and negative during the Northern Hemisphere winter.
The expression above is always applicable for latitudes between the Arctic Circle and Antarctic Circle. North of the Arctic Circle or south of the Antarctic Circle, there is at least one day of the year with no sunrise or sunset. Formally, there is a sunrise or sunset when during the Northern Hemisphere summer, and when during the Northern Hemisphere winter. For locations outside these latitudes, it is either 24-hour daytime or 24-hour nighttime.
Expressions for the solar hour angle
In the equation given at the beginning, the cosine function on the left side gives results in the range , but the value of the expression on the right side is in the range. An applicable expression for in the format of Fortran 90 is as follows:where omegao is in degree, delta is in degree, phi is in degree, rpd is equal to, and dpr is equal to.
The above expression gives results in degree in the range. When, it means it is polar night, or 0-hour daylight; when, it means it is polar day, or 24-hour daylight.
Hemispheric relation
Suppose is a given latitude in Northern Hemisphere, and is the corresponding sunrise hour angle that has a negative value, and similarly, is the same latitude but in Southern Hemisphere, which means, and is the corresponding sunrise hour angle, then it is apparent thatwhich means
The above relation implies that on the same day, the lengths of daytime from sunrise to sunset at and sum to 24 hours if, and this also applies to regions where polar days and polar nights occur. This further suggests that the global average of length of daytime on any given day is 12 hours without considering the effect of atmospheric refraction.
Generalized equation
The equation above neglects the influence of atmospheric refraction and the non-zero angle subtended by the solar disc — i.e. the apparent diameter of the sun —. The times of the rising and the setting of the upper solar limb as given in astronomical almanacs correct for this by using the more general equationwith the altitude angle of the center of the solar disc set to about −0.83°.
The above general equation can be also used for any other solar altitude. The NOAA provides additional approximate expressions for refraction corrections at these other altitudes. There are also alternative formulations, such as a non-piecewise expression by G.G. Bennett used in the U.S. Naval Observatory's "Vector Astronomy Software".
Complete calculation on Earth
The generalized equation relies on a number of other variables which need to be calculated before it can itself be calculated. These equations have the solar-earth constants substituted with angular constants expressed in degrees.Calculate current Julian day
where:Mean solar time
where:Solar mean anomaly
where:Equation of the center
where:Ecliptic longitude
where:Solar transit
where:Declination of the Sun
where:Alternatively, the Sun's declination could be approximated as:
where:
Hour angle
This is the equation from above with corrections for atmospherical refraction and solar disc diameter.where:
For observations on a sea horizon needing an elevation-of-observer correction, add, or to the −0.833° in the numerator's sine term. This corrects for both apparent dip and terrestrial refraction. For example, for an observer at 10,000 feet, add or about −1.92° to −0.833°.
Calculate sunrise and sunset
where:Example of implementation in Python
- !/usr/bin/env python3
from datetime import datetime, timedelta, timezone, tzinfo
from math import acos, asin, ceil, cos, degrees, fmod, radians, sin, sqrt
from time import time
log = logging.getLogger
def _ts2human -> str:
return str
def j2ts -> float:
return * 86400
def ts2j -> float:
return ts / 86400.0 + 2440587.5
def _j2human -> str:
ts = j2ts
return f" = "
def _deg2human -> str:
x = int
num = f"∠°"
rad = f"∠rad"
human = f"∠°′″" # N.B. not correct for negative x
return f" = = "
def calc -> tuple | tuple:
log.debug
log.debug
log.debug
J_date = ts2j
log.debug
# Julian day
# TODO: ceil ?
n = ceil
log.debug
# Mean solar time
J_ = n + 0.0009 - l_w / 360.0
log.debug
# Solar mean anomaly
# M_degrees = 357.5291 + 0.98560028 * J_ # Same, but looks ugly
M_degrees = fmod
M_radians = radians
log.debug
# Equation of the center
C_degrees = 1.9148 * sin + 0.02 * sin + 0.0003 * sin
# The difference for final program result is few milliseconds
# https://www.astrouw.edu.pl/~jskowron/pracownia/praca/sunspot_answerbook_expl/expl-4.html
# e = 0.01671
# C_degrees = \
# degrees * e ** 3 + * sin \
# + degrees * e ** 4 + * sin \
# + degrees * sin \
# + degrees * e ** 4 - * sin \
# + degrees * sin \
# + degrees * sin
log.debug
# Ecliptic longitude
# L_degrees = M_degrees + C_degrees + 180.0 + 102.9372 # Same, but looks ugly
L_degrees = fmod
log.debug
Lambda_radians = radians
# Solar transit
J_transit = - 0.0069 * sin)
log.debug
# Declination of the Sun
sin_d = sin * sin
# cos_d = sqrt # exactly the same precision, but 1.5 times slower
cos_d = cos
# Hour angle
some_cos = /
try:
w0_radians = acos
except ValueError:
return None, None, some_cos > 0.0
w0_degrees = degrees # 0...180
log.debug
j_rise = J_transit - w0_degrees / 360
j_set = J_transit + w0_degrees / 360
log.debug
log.debug
log.debug
return j2ts, j2ts, None
def main:
logging.basicConfig
latitude = 33.00801
longitude = 35.08794
elevation = 0
print)
if __name__ "__main__":
main