[Python-modules-commits] [python-pysolar] 01/18: Broke code out into smaller files. Updated copyright date. Added few comments.
Wolfgang Borgert
debacle at moszumanska.debian.org
Fri Oct 3 23:36:06 UTC 2014
This is an automated email from the git hooks/post-receive script.
debacle pushed a commit to annotated tag 0.3.0
in repository python-pysolar.
commit af56db14eab6e2f69bcac9b25e163eb5c9723706
Author: Brandon Stafford <brandon at farb.(none)>
Date: Sat Mar 8 20:06:06 2008 -0500
Broke code out into smaller files. Updated copyright date. Added few comments.
---
constants.py | 2 +-
julian.py | 52 +++++++++++++++++++++++++++++++++++++++++++++++
poly.py | 19 +++++++++++++++++
radiation.py | 41 +++++++++++++++++++++++++++++++++++++
solar.py | 66 +++++++++++-------------------------------------------------
testsolar.py | 13 ++++++------
6 files changed, 132 insertions(+), 61 deletions(-)
diff --git a/constants.py b/constants.py
index f0856c4..c4e5df1 100644
--- a/constants.py
+++ b/constants.py
@@ -2,7 +2,7 @@
# Constants for calculating the position of the sun relative to the earth
-# Copyright 2007 Brandon Stafford
+# Copyright 2008 Brandon Stafford
#
# This file is part of Pysolar.
#
diff --git a/julian.py b/julian.py
new file mode 100644
index 0000000..ffa1745
--- /dev/null
+++ b/julian.py
@@ -0,0 +1,52 @@
+#!/usr/bin/python
+
+# Julian calendar calculations for calculating the position of the sun relative to the earth
+
+# Copyright 2008 Brandon Stafford
+#
+# This file is part of Pysolar.
+#
+# Pysolar is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# Pysolar is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with Pysolar. If not, see <http://www.gnu.org/licenses/>.
+
+import math
+
+def GetJulianCentury(julian_day):
+ return (julian_day - 2451545.0) / 36525.0
+
+def GetJulianDay(utc_datetime): # based on NREL/TP-560-34302 by Andreas and Reda
+ # does not accept years before 0 because of bounds check on Python's datetime.year field
+ year = utc_datetime.year
+ month = utc_datetime.month
+ if(month <= 2): # shift to accomodate leap years?
+ year = year - 1
+ month = month + 12
+ day = utc_datetime.day + (((utc_datetime.hour * 3600.0) + (utc_datetime.minute * 60.0) + utc_datetime.second) / 86400.0)
+ gregorian_offset = 2 - math.floor(year / 100) + math.floor(math.floor(year / 100) / 4)
+ julian_day = math.floor(365.25*(year + 4716)) + math.floor(30.6001 *(month + 1)) + day - 1524.5
+ if (julian_day <= 2299160):
+ return julian_day # before October 5, 1852
+ else:
+ return julian_day + gregorian_offset # after October 5, 1852
+
+def GetJulianEphemerisCentury(julian_ephemeris_day):
+ return (julian_ephemeris_day - 2451545.0) / 36525.0
+
+def GetJulianEphemerisDay(julian_day, delta_seconds):
+ """delta_seconds is value referred to by astronomers as Delta-T, defined as the difference between
+ Dynamical Time (TD) and Universal Time (UT). In 2007, it's around 65 seconds.
+ A list of values for Delta-T can be found here: ftp://maia.usno.navy.mil/ser7/deltat.data"""
+ return julian_day + (delta_seconds / 86400.0)
+
+def GetJulianEphemerisMillenium(julian_ephemeris_century):
+ return (julian_ephemeris_century / 10.0)
diff --git a/poly.py b/poly.py
index b90a286..5f2d732 100644
--- a/poly.py
+++ b/poly.py
@@ -1,5 +1,24 @@
#!/usr/bin/python
+# Library for calculating location of the sun
+
+# Copyright 2008 Brandon Stafford
+#
+# This file is part of Pysolar.
+#
+# Pysolar is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# Pysolar is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with Pysolar. If not, see <http://www.gnu.org/licenses/>.
+
coeff_list = [
('ArgumentOfLatitudeOfMoon', (93.27191, 483202.017538, -0.0036825, 327270.0)),
('LongitudeOfAscendingNode', (125.04452, -1934.136261, 0.0020708, 450000.0)),
diff --git a/radiation.py b/radiation.py
new file mode 100644
index 0000000..2232db4
--- /dev/null
+++ b/radiation.py
@@ -0,0 +1,41 @@
+#!/usr/bin/python
+
+# Functions for calculating the solar radiation hitting the earth
+
+# Copyright 2008 Brandon Stafford
+#
+# This file is part of Pysolar.
+#
+# Pysolar is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# Pysolar is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with Pysolar. If not, see <http://www.gnu.org/licenses/>.
+
+def GetAirMassRatio(altitude_deg):
+ # from Masters, p. 412
+ # warning: pukes on input of zero
+ return (1/math.sin(math.radians(altitude_deg)))
+
+def GetApparentExtraterrestrialFlux(day):
+ # from Masters, p. 412
+ return 1160 + (75 * math.sin((360/365) * (day - 275)))
+
+def GetOpticalDepth(day):
+ # from Masters, p. 412
+ return 0.174 + (0.035 * math.sin((360/365) * (day - 100)))
+
+def GetRadiationDirect(utc_datetime, altitude_deg):
+ # from Masters, p. 412
+ day = GetDayOfYear(utc_datetime)
+ flux = GetApparentExtraterrestrialFlux(day)
+ optical_depth = GetOpticalDepth(day)
+ air_mass_ratio = GetAirMassRatio(altitude_deg)
+ return flux * math.exp(-1 * optical_depth * air_mass_ratio)
diff --git a/solar.py b/solar.py
index 33154ba..dd4968f 100644
--- a/solar.py
+++ b/solar.py
@@ -22,7 +22,9 @@
import math
import datetime
import constants
+import julian
import poly
+import radiation
#if __name__ == "__main__":
def SolarTest():
@@ -34,7 +36,7 @@ def SolarTest():
timestamp = d.ctime()
altitude_deg = GetAltitude(latitude_deg, longitude_deg, d)
azimuth_deg = GetAzimuth(latitude_deg, longitude_deg, d)
- power = GetRadiationDirect(d, altitude_deg)
+ power = radiation.GetRadiationDirect(d, altitude_deg)
if (altitude_deg > 0):
print timestamp, "UTC", altitude_deg, azimuth_deg, power
d = d + thirty_minutes
@@ -46,11 +48,6 @@ def EquationOfTime(day):
def GetAberrationCorrection(r): # r is earth radius vector [astronomical units]
return -20.4898/(3600.0 * r)
-def GetAirMassRatio(altitude_deg):
- # from Masters, p. 412
- # warning: pukes on input of zero
- return (1/math.sin(math.radians(altitude_deg)))
-
def GetAltitude(latitude_deg, longitude_deg, utc_datetime):
# expect 19 degrees for solar.GetAltitude(42.364908,-71.112828,datetime.datetime(2007, 2, 18, 20, 13, 1, 130320))
@@ -64,10 +61,6 @@ def GetAltitude(latitude_deg, longitude_deg, utc_datetime):
second_term = math.sin(latitude_rad) * math.sin(declination_rad)
return math.degrees(math.asin(first_term + second_term))
-def GetApparentExtraterrestrialFlux(day):
- # from Masters, p. 412
- return 1160 + (75 * math.sin((360/365) * (day - 275)))
-
def GetApparentSiderealTime(julian_day, jme, nutation):
return GetMeanSiderealTime(julian_day) + nutation['longitude'] * math.cos(GetTrueEclipticObliquity(jme, nutation))
@@ -115,6 +108,8 @@ def GetFlattenedLatitude(latitude):
latitude_rad = math.radians(latitude)
return math.degrees(math.atan(0.99664719 * math.tan(latitude_rad)))
+# Geocentric functions calculate angles relative to the center of the earth.
+
def GetGeocentricLatitude(jme):
return -1 * GetHeliocentricLatitude(jme)
@@ -142,6 +137,8 @@ def GetGeocentricSunRightAscension(apparent_sun_longitude, true_ecliptic_obliqui
alpha = math.atan2((a - b), c)
return math.degrees(alpha) % 360
+# Heliocentric functions calculate angles relative to the center of the sun.
+
def GetHeliocentricLatitude(jme):
b0 = GetCoefficient(jme, constants.B0)
b1 = GetCoefficient(jme, constants.B1)
@@ -169,42 +166,12 @@ def GetIncidenceAngle(topocentric_zenith_angle, slope, slope_orientation, topoce
taa_rad = math.radians(topocentric_azimuth_angle)
return math.degrees(math.acos(math.cos(tza_rad) * math.cos(slope_rad) + math.sin(slope_rad) * math.sin(tza_rad) * math.cos(taa_rad - math.pi - so_rad)))
-def GetJulianCentury(julian_day):
- return (julian_day - 2451545.0) / 36525.0
-
-def GetJulianDay(utc_datetime): # based on NREL/TP-560-34302 by Andreas and Reda
- # does not accept years before 0 because of bounds check on Python's datetime.year field
- year = utc_datetime.year
- month = utc_datetime.month
- if(month <= 2): # shift to accomodate leap years?
- year = year - 1
- month = month + 12
- day = utc_datetime.day + (((utc_datetime.hour * 3600.0) + (utc_datetime.minute * 60.0) + utc_datetime.second) / 86400.0)
- gregorian_offset = 2 - math.floor(year / 100) + math.floor(math.floor(year / 100) / 4)
- julian_day = math.floor(365.25*(year + 4716)) + math.floor(30.6001 *(month + 1)) + day - 1524.5
- if (julian_day <= 2299160):
- return julian_day # before October 5, 1852
- else:
- return julian_day + gregorian_offset # after October 5, 1852
-
-def GetJulianEphemerisCentury(julian_ephemeris_day):
- return (julian_ephemeris_day - 2451545.0) / 36525.0
-
-def GetJulianEphemerisDay(julian_day, delta_seconds):
- """delta_seconds is value referred to by astronomers as Delta-T, defined as the difference between
- Dynamical Time (TD) and Universal Time (UT). In 2007, it's around 65 seconds.
- A list of values for Delta-T can be found here: ftp://maia.usno.navy.mil/ser7/deltat.data"""
- return julian_day + (delta_seconds / 86400.0)
-
-def GetJulianEphemerisMillenium(julian_ephemeris_century):
- return (julian_ephemeris_century / 10.0)
-
def GetLocalHourAngle(apparent_sidereal_time, longitude, geocentric_sun_right_ascension):
return (apparent_sidereal_time + longitude - geocentric_sun_right_ascension) % 360
def GetMeanSiderealTime(julian_day):
# This function doesn't agree with Andreas and Reda as well as it should. Works to ~5 sig figs in current unit test
- jc = GetJulianCentury(julian_day)
+ jc = julian.GetJulianCentury(julian_day)
sidereal_time = 280.46061837 + (360.98564736629 * (julian_day - 2451545.0)) + (0.000387933 * jc ** 2) - (jc ** 3 / 38710000)
return sidereal_time % 360
@@ -225,7 +192,7 @@ def GetNutationAberrationXY(jce, i):
def GetNutation(jde):
abcd = constants.nutation_coefficients
- jce = GetJulianEphemerisCentury(jde)
+ jce = julian.GetJulianEphemerisCentury(jde)
nutation_long = []
nutation_oblique = []
@@ -239,10 +206,6 @@ def GetNutation(jde):
return nutation
-def GetOpticalDepth(day):
- # from Masters, p. 412
- return 0.174 + (0.035 * math.sin((360/365) * (day - 100)))
-
def GetParallaxSunRightAscension(projected_radial_distance, equatorial_horizontal_parallax, local_hour_angle, geocentric_sun_declination, projected_axial_distance):
prd = projected_radial_distance
ehp_rad = math.radians(equatorial_horizontal_parallax)
@@ -263,14 +226,6 @@ def GetProjectedAxialDistance(elevation, latitude):
flattened_latitude_rad = math.radians(GetFlattenedLatitude(latitude))
latitude_rad = math.radians(latitude)
return 0.99664719 * math.sin(flattened_latitude_rad) + (elevation * math.sin(latitude_rad) / constants.earth_radius)
-
-def GetRadiationDirect(utc_datetime, altitude_deg):
- # from Masters, p. 412
- day = GetDayOfYear(utc_datetime)
- flux = GetApparentExtraterrestrialFlux(day)
- optical_depth = GetOpticalDepth(day)
- air_mass_ratio = GetAirMassRatio(altitude_deg)
- return flux * math.exp(-1 * optical_depth * air_mass_ratio)
def GetRadiusVector(jme):
r0 = GetCoefficient(jme, constants.R0)
@@ -292,7 +247,10 @@ def GetSolarTime(longitude_deg, utc_datetime):
day = GetDayOfYear(utc_datetime)
return (((utc_datetime.hour * 60) + utc_datetime.minute + (4 * longitude_deg) + EquationOfTime(day))/60)
+# Topocentric functions calculate angles relative to a location on the surface of the earth.
+
def GetTopocentricAzimuthAngle(topocentric_local_hour_angle, latitude, topocentric_sun_declination):
+ """Measured eastward from north"""
tlha_rad = math.radians(topocentric_local_hour_angle)
latitude_rad = math.radians(latitude)
tsd_rad = math.radians(topocentric_sun_declination)
diff --git a/testsolar.py b/testsolar.py
index c719e20..e4db0de 100644
--- a/testsolar.py
+++ b/testsolar.py
@@ -21,6 +21,7 @@
import solar
import constants
+import julian
import datetime
import unittest
@@ -35,11 +36,11 @@ class testSolar(unittest.TestCase):
self.temperature = 11.0 # degrees Celsius
self.slope = 30.0 # degrees
self.slope_orientation = -10.0 # degrees east from south
- self.jd = solar.GetJulianDay(self.d)
- self.jc = solar.GetJulianCentury(self.jd)
- self.jde = solar.GetJulianEphemerisDay(self.jd, 67.0) #65.284)
- self.jce = solar.GetJulianEphemerisCentury(self.jde)
- self.jme = solar.GetJulianEphemerisMillenium(self.jce)
+ self.jd = julian.GetJulianDay(self.d)
+ self.jc = julian.GetJulianCentury(self.jd)
+ self.jde = julian.GetJulianEphemerisDay(self.jd, 67.0)
+ self.jce = julian.GetJulianEphemerisCentury(self.jde)
+ self.jme = julian.GetJulianEphemerisMillenium(self.jce)
self.geocentric_longitude = solar.GetGeocentricLongitude(self.jme)
self.geocentric_latitude = solar.GetGeocentricLatitude(self.jme)
self.nutation = solar.GetNutation(self.jde)
@@ -62,7 +63,7 @@ class testSolar(unittest.TestCase):
self.topocentric_zenith_angle = solar.GetTopocentricZenithAngle(self.latitude, self.topocentric_sun_declination, self.topocentric_local_hour_angle, self.pressure, self.temperature)
self.topocentric_azimuth_angle = solar.GetTopocentricAzimuthAngle(self.topocentric_local_hour_angle, self.latitude, self.topocentric_sun_declination)
self.incidence_angle = solar.GetIncidenceAngle(self.topocentric_zenith_angle, self.slope, self.slope_orientation, self.topocentric_azimuth_angle)
-
+
def testGetJulianDay(self):
self.assertAlmostEqual(2452930.312847, self.jd, 6) # value from Reda and Andreas (2005)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-pysolar.git
More information about the Python-modules-commits
mailing list