summaryrefslogtreecommitdiffstats
path: root/src/solar.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/solar.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/solar.py b/src/solar.py
index 041d427..24370c1 100644
--- a/src/solar.py
+++ b/src/solar.py
@@ -98,6 +98,7 @@ def julian_day_to_epoch(t):
'''
return (t - 2440587.5) * 86400.0
+
def epoch_to_julian_day(t):
'''
Converts a POSIX time timestamp to a Julian Day timestamp
@@ -107,6 +108,7 @@ def epoch_to_julian_day(t):
'''
return t / 86400.0 + 2440587.5
+
def julian_day_to_julian_centuries(t):
'''
Converts a Julian Day timestamp to a Julian Centuries timestamp
@@ -116,6 +118,7 @@ def julian_day_to_julian_centuries(t):
'''
return (t - 2451545.0) / 36525.0
+
def julian_centuries_to_julian_day(t):
'''
Converts a Julian Centuries timestamp to a Julian Day timestamp
@@ -125,6 +128,7 @@ def julian_centuries_to_julian_day(t):
'''
return t * 36525.0 + 2451545.0
+
def epoch_to_julian_centuries(t):
'''
Converts a POSIX time timestamp to a Julian Centuries timestamp
@@ -134,6 +138,7 @@ def epoch_to_julian_centuries(t):
'''
return julian_day_to_julian_centuries(epoch_to_julian_day(t))
+
def julian_centuries_to_epoch(t):
'''
Converts a Julian Centuries timestamp to a POSIX time timestamp
@@ -143,6 +148,7 @@ def julian_centuries_to_epoch(t):
'''
return julian_day_to_epoch(julian_centuries_to_julian_day(t))
+
def epoch():
'''
Get current POSIX time
@@ -151,6 +157,7 @@ def epoch():
'''
return time.time()
+
def julian_day():
'''
Get current Julian Day time
@@ -159,6 +166,7 @@ def julian_day():
'''
return epoch_to_julian_day(epoch())
+
def julian_centuries():
'''
Get current Julian Centuries time (100 Julian days since J2000)
@@ -167,6 +175,7 @@ def julian_centuries():
'''
return epoch_to_julian_centuries(epoch())
+
def radians(deg):
'''
Convert an angle from degrees to radians
@@ -176,6 +185,7 @@ def radians(deg):
'''
return deg * math.pi / 180
+
def degrees(rad):
'''
Convert an angle from radians to degrees
@@ -185,6 +195,7 @@ def degrees(rad):
'''
return rad * 180 / math.pi
+
def sun_geometric_mean_longitude(t):
'''
Calculates the Sun's geometric mean longitude
@@ -194,6 +205,7 @@ def sun_geometric_mean_longitude(t):
'''
return radians((0.0003032 * t ** 2 + 36000.76983 * t + 280.46646) % 360)
+
def sun_geometric_mean_anomaly(t):
'''
Calculates the Sun's geometric mean anomaly
@@ -203,6 +215,7 @@ def sun_geometric_mean_anomaly(t):
'''
return radians(-0.0001537 * t ** 2 + 35999.05029 * t + 357.52911)
+
def earth_orbit_eccentricity(t):
'''
Calculates the Earth's orbit eccentricity
@@ -212,6 +225,7 @@ def earth_orbit_eccentricity(t):
'''
return -0.0000001267 * t ** 2 - 0.000042037 * t + 0.016708634
+
def sun_equation_of_centre(t):
'''
Calculates the Sun's equation of the centre, the difference between
@@ -226,6 +240,7 @@ def sun_equation_of_centre(t):
rc += math.sin(3 * a) * 0.000289
return radians(rc)
+
def sun_real_longitude(t):
'''
Calculates the Sun's real longitudinal position
@@ -236,6 +251,7 @@ def sun_real_longitude(t):
rc = sun_geometric_mean_longitude(t)
return rc + sun_equation_of_centre(t)
+
def sun_apparent_longitude(t):
'''
Calculates the Sun's apparent longitudinal position
@@ -247,6 +263,7 @@ def sun_apparent_longitude(t):
rc -= 0.00478 * math.sin(radians(-1934.136 * t + 125.04))
return radians(rc)
+
def mean_ecliptic_obliquity(t):
'''
Calculates the mean ecliptic obliquity of the Sun's apparent motion without variation correction
@@ -259,6 +276,7 @@ def mean_ecliptic_obliquity(t):
rc = 23 + rc / 60
return radians(rc)
+
def corrected_mean_ecliptic_obliquity(t):
'''
Calculates the mean ecliptic obliquity of the Sun's apparent motion with variation correction
@@ -271,6 +289,7 @@ def corrected_mean_ecliptic_obliquity(t):
rc += degrees(mean_ecliptic_obliquity(t))
return radians(rc)
+
def solar_declination(t):
'''
Calculates the Sun's declination
@@ -282,6 +301,7 @@ def solar_declination(t):
rc *= math.sin(sun_apparent_longitude(t))
return math.asin(rc)
+
def equation_of_time(t):
'''
Calculates the equation of time, the discrepancy between apparent and mean solar time
@@ -300,6 +320,7 @@ def equation_of_time(t):
rc -= 1.25 * e ** 2 * math.sin(2 * m)
return 4 * degrees(rc)
+
def hour_angle_from_elevation(latitude, declination, elevation):
'''
Calculates the solar hour angle from the Sun's elevation
@@ -317,6 +338,7 @@ def hour_angle_from_elevation(latitude, declination, elevation):
rc = math.acos(rc)
return -rc if (rc < 0) == (elevation < 0) else rc;
+
def elevation_from_hour_angle(latitude, declination, hour_angle):
'''
Calculates the Sun's elevation from the solar hour angle
@@ -331,6 +353,7 @@ def elevation_from_hour_angle(latitude, declination, hour_angle):
rc += math.sin(radians(latitude)) * math.sin(declination)
return math.asin(rc)
+
def time_of_solar_noon(t, longitude):
'''
Calculates the time of the closest solar noon
@@ -345,6 +368,7 @@ def time_of_solar_noon(t, longitude):
rc = 720 - 4 * longitude - equation_of_time(rc)
return rc
+
def time_of_solar_elevation(t, noon, latitude, longitude, elevation):
'''
Calculates the time the Sun has a specified apparent elevation at a geographical position
@@ -367,6 +391,7 @@ def time_of_solar_elevation(t, noon, latitude, longitude, elevation):
rc = 720 - 4 * (longitude + degrees(rc)) - et
return rc
+
def solar_elevation_from_time(t, latitude, longitude):
'''
Calculates the Suns elevation as apparent from a geographical position
@@ -383,6 +408,7 @@ def solar_elevation_from_time(t, latitude, longitude):
rc = radians(rc / 4 - longitude)
return elevation_from_hour_angle(latitude, solar_declination(t), rc)
+
def solar_elevation(latitude, longitude, t = None):
'''
Calculates the Suns elevation as apparent from a geographical position