[Python-modules-commits] [python-pysolar] 04/10: Rewrote some of the polynomial fits to use lambda functions.

Wolfgang Borgert debacle at moszumanska.debian.org
Fri Oct 3 23:36:03 UTC 2014


This is an automated email from the git hooks/post-receive script.

debacle pushed a commit to annotated tag 0.2.1
in repository python-pysolar.

commit 25370971bbddefa298d6cee71023990e0a9efdfd
Author: Brandon Stafford <brandon at farb.(none)>
Date:   Mon Mar 3 10:00:41 2008 -0500

    Rewrote some of the polynomial fits to use lambda functions.
---
 poly.py  | 18 ++++++++++++++++++
 solar.py | 27 +++++++--------------------
 2 files changed, 25 insertions(+), 20 deletions(-)

diff --git a/poly.py b/poly.py
new file mode 100644
index 0000000..d92c075
--- /dev/null
+++ b/poly.py
@@ -0,0 +1,18 @@
+#!/usr/bin/python
+
+coeff_list = [
+		('ArgumentOfLatitudeOfMoon', (93.27191, 483202.017538, -0.0036825, 327270.0)),
+		('LongitudeOfAscendingNode', (125.04452, -1934.136261, 0.0020708, 450000.0)),
+		('MeanElongationOfMoon', (297.85036, 445267.111480, -0.0019142, 189474.0)),
+		('MeanAnomalyOfMoon', (134.96298, 477198.867398, 0.0086972, 56250.0)),
+		('MeanAnomalyOfSun', (357.52772, 35999.050340, -0.0001603, -300000.0))
+	]
+
+def buildPolyFit((a, b, c, d)):
+	return (lambda x: a + b * x + c * x ** 2 + (x ** 3) / d)
+
+def buildPolyDict():
+	d = {}
+	polys = [(name, buildPolyFit(coeffs)) for (name, coeffs) in coeff_list]
+	d = dict(polys)
+	return d
diff --git a/solar.py b/solar.py
index e2ff6de..3cf4c89 100644
--- a/solar.py
+++ b/solar.py
@@ -23,6 +23,7 @@ import math
 import datetime
 import constants
 import sys
+import poly
 
 #if __name__ == "__main__":
 def SolarTest():
@@ -74,9 +75,6 @@ def GetApparentSiderealTime(julian_day, jme, nutation):
 def GetApparentSunLongitude(geocentric_longitude, nutation, ab_correction):
 	return geocentric_longitude + nutation['longitude'] + ab_correction
 
-def GetArgumentOfLatitudeOfMoon(jce):
-	return 93.27191 + 483202.017538 * jce - 0.0036825 * jce ** 2 + jce ** 3 / 327270.0
-
 def GetAzimuth(latitude_deg, longitude_deg, utc_datetime):
 # expect -50 degrees for solar.GetAzimuth(42.364908,-71.112828,datetime.datetime(2007, 2, 18, 20, 18, 0, 0))
 	day = GetDayOfYear(utc_datetime)
@@ -197,21 +195,9 @@ def GetJulianEphemerisDay(julian_day, delta_seconds):
 def GetJulianEphemerisMillenium(julian_ephemeris_century):
 	return (julian_ephemeris_century / 10.0)
 
-def GetLongitudeOfAscendingNode(jce):
-	return 125.04452 - (1934.136261 * jce) + (0.0020708 * jce ** 2) + (jce ** 3 / 450000.0)
-
 def GetLocalHourAngle(apparent_sidereal_time, longitude, geocentric_sun_right_ascension):
 	return (apparent_sidereal_time + longitude - geocentric_sun_right_ascension) % 360
 
-def GetMeanElongationOfMoon(jce):
-	return 297.85036 + (445267.111480 * jce) - (0.0019142 * jce ** 2) + (jce ** 3 / 189474.0)
-
-def GetMeanAnomalyOfMoon(jce):
-	return 134.96298 + (477198.867398 * jce) + (0.0086972 * jce ** 2) + (jce ** 3 / 56250.0)
-
-def GetMeanAnomalyOfSun(jce):
-	return 357.52772 + (35999.050340 * jce) - (0.0001603 * jce ** 2) - (jce ** 3 / 300000.0)
-
 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)
@@ -221,12 +207,13 @@ def GetMeanSiderealTime(julian_day):
 def GetNutationAberrationXY(jce, i):
 	y = constants.aberration_sin_terms
 	x = []
+	p = poly.buildPolyDict()
 	# order of 5 x.append lines below is important
-	x.append(GetMeanElongationOfMoon(jce))
-	x.append(GetMeanAnomalyOfSun(jce))
-	x.append(GetMeanAnomalyOfMoon(jce))
-	x.append(GetArgumentOfLatitudeOfMoon(jce))
-	x.append(GetLongitudeOfAscendingNode(jce))
+	x.append(p['MeanElongationOfMoon'](jce))
+	x.append(p['MeanAnomalyOfSun'](jce))
+	x.append(p['MeanAnomalyOfMoon'](jce))
+	x.append(p['ArgumentOfLatitudeOfMoon'](jce))
+	x.append(p['LongitudeOfAscendingNode'](jce))
 	sigmaxy = 0.0
 	for j in range(len(x)):
 		sigmaxy += x[j] * y[i][j]

-- 
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