[Python-modules-commits] [python-pysolar] 01/06: Merged poly.py into constants.py. Added some docstrings.
Wolfgang Borgert
debacle at moszumanska.debian.org
Fri Oct 3 23:36:33 UTC 2014
This is an automated email from the git hooks/post-receive script.
debacle pushed a commit to annotated tag 0.4.3
in repository python-pysolar.
commit f46a86e3ce333eac3e27eb1028b7802df95147ee
Author: Brandon Stafford <brandon at loess.(none)>
Date: Tue Mar 9 17:16:00 2010 -0500
Merged poly.py into constants.py. Added some docstrings.
---
constants.py | 58 ++++++++++++++++++++++++++++++++++++++++++++--------------
horizon.py | 8 +++++++-
julian.py | 56 +++++++++++++++++++++++++++++++++-----------------------
poly.py | 35 -----------------------------------
solar.py | 2 +-
5 files changed, 85 insertions(+), 74 deletions(-)
diff --git a/constants.py b/constants.py
index a1c85de..95a08a6 100644
--- a/constants.py
+++ b/constants.py
@@ -17,23 +17,53 @@
# You should have received a copy of the GNU General Public License along
# with Pysolar. If not, see <http://www.gnu.org/licenses/>.
-# Note about sources for the constants below:
-#
-# Most of the constants below come from a 2005 paper by Reda and Andreas:
-#
-# I. Reda and A. Andreas, "Solar Position Algorithm for Solar Radiation Applications,"
-# National Renewable Energy Laboratory, NREL/TP-560-34302, revised November 2005.
-# http://www.osti.gov/bridge/servlets/purl/15003974-iP3z6k/native/15003974.PDF
-#
-# However, it seems that Reda and Andreas took the bulk of the constants (L0, etc.)
-# from VSOP87:
-# http://en.wikipedia.org/wiki/Secular_variations_of_the_planetary_orbits#VSOP87
-#
-# See also ftp://ftp.imcce.fr/pub/ephem/planets/vsop87/VSOP87D.ear
+"""This file is consists of numerical constants for calculating corrections,
+such as the wiggling ("nutation") of the axis of the earth. It also includes
+functions for building dictionaries of polynomial functions for rapid
+calculation of corrections.
+
+Most of the constants come from a 2005 paper by Reda and Andreas:
+
+I. Reda and A. Andreas, "Solar Position Algorithm for Solar Radiation
+Applications," National Renewable Energy Laboratory, NREL/TP-560-34302,
+revised November 2005.
+
+http://www.osti.gov/bridge/servlets/purl/15003974-iP3z6k/native/15003974.PDF
+
+However, it seems that Reda and Andreas took the bulk of the constants
+(L0, etc.) from Pierre Bretagnon and Gerard Francou's Variations Seculaires
+des Orbites Planetaires, or VSOP87:
-"""Constants as input for ephemeris calculations
+http://en.wikipedia.org/wiki/Secular_variations_of_the_planetary_orbits#VSOP87
+
+See also ftp://ftp.imcce.fr/pub/ephem/planets/vsop87/VSOP87D.ear
"""
+
+def buildPolyFit((a, b, c, d)):
+ """Given coefficients a through d, this function returns a polynomial
+ function that can be used repeatedly.
+
+ """
+ return (lambda x: a + b * x + c * x ** 2 + (x ** 3) / d)
+
+def buildPolyDict():
+ """This function builds a dictionary of polynomial functions from a list of
+ coefficients, so that the functions can be called by name. This is used in
+ calculating nutation.
+
+ """
+ return dict([(name, buildPolyFit(coeffs)) for (name, coeffs) in coeff_list])
+
+
+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))
+ ]
+
earth_radius = 6378140.0 # meters
aberration_sin_terms = [[0,0,0,0,1],
diff --git a/horizon.py b/horizon.py
index 443999d..8011c18 100644
--- a/horizon.py
+++ b/horizon.py
@@ -17,7 +17,13 @@
# You should have received a copy of the GNU General Public License along
# with Pysolar. If not, see <http://www.gnu.org/licenses/>.
-"""Script for detecting angle to solar obstructions from spherically distorted images
+"""This script rectifies spherically distorted images in order to detect the
+angle to solar obstructions. It is not used in Pysolar's ephemeris
+calculations.
+
+An example of this script in action appears here:
+
+http://pingswept.org/2009/03/16/calculating-solar-panel-shading-in-python/
"""
from PIL import Image
diff --git a/julian.py b/julian.py
index e152b4b..4e072a0 100644
--- a/julian.py
+++ b/julian.py
@@ -17,37 +17,47 @@
# You should have received a copy of the GNU General Public License along
# with Pysolar. If not, see <http://www.gnu.org/licenses/>.
-"""Julian calendar calculations for calculating the position of the sun relative to the earth
+"""This file contains all the functions related to the Julian calendar, which
+are used in calculating the position of the sun relative to the earth
"""
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.0): # shift to accomodate leap years?
- year = year - 1.0
- month = month + 12.0
- day = utc_datetime.day + (((utc_datetime.hour * 3600.0) + (utc_datetime.minute * 60.0) + utc_datetime.second + (utc_datetime.microsecond / 1000000.0)) / 86400.0)
- gregorian_offset = 2.0 - (year // 100.0) + ((year // 100.0) // 4.0)
- julian_day = math.floor(365.25 * (year + 4716.0)) + math.floor(30.6001 * (month + 1.0)) + day - 1524.5
- if (julian_day <= 2299160.0):
- return julian_day # before October 5, 1852
- else:
- return julian_day + gregorian_offset # after October 5, 1852
+ return (julian_day - 2451545.0) / 36525.0
+
+def GetJulianDay(utc_datetime):
+ """This function is based on NREL/TP-560-34302 by Andreas and Reda
+
+ This function does not accept years before 0 because of the bounds check
+ on Python's datetime.year field.
+
+ """
+ year = utc_datetime.year
+ month = utc_datetime.month
+ if(month <= 2.0): # shift to accomodate leap years?
+ year = year - 1.0
+ month = month + 12.0
+ day = utc_datetime.day + (((utc_datetime.hour * 3600.0) + (utc_datetime.minute * 60.0) + utc_datetime.second + (utc_datetime.microsecond / 1000000.0)) / 86400.0)
+ gregorian_offset = 2.0 - (year // 100.0) + ((year // 100.0) // 4.0)
+ julian_day = math.floor(365.25 * (year + 4716.0)) + math.floor(30.6001 * (month + 1.0)) + day - 1524.5
+ if (julian_day <= 2299160.0):
+ 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
+ return (julian_ephemeris_day - 2451545.0) / 36525.0
def GetJulianEphemerisDay(julian_day, delta_seconds = 66.0):
- """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)
+ """delta_seconds is the 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
+
+ More details: http://en.wikipedia.org/wiki/DeltaT
+
+ """
+ return julian_day + (delta_seconds / 86400.0)
def GetJulianEphemerisMillenium(julian_ephemeris_century):
- return (julian_ephemeris_century / 10.0)
+ return (julian_ephemeris_century / 10.0)
diff --git a/poly.py b/poly.py
deleted file mode 100644
index 0335105..0000000
--- a/poly.py
+++ /dev/null
@@ -1,35 +0,0 @@
-#!/usr/bin/python
-
-# Copyright 2008-2010 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/>.
-
-"""Additional support constants and their calculation for solar geometry
-
-"""
-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():
- return dict([(name, buildPolyFit(coeffs)) for (name, coeffs) in coeff_list])
diff --git a/solar.py b/solar.py
index 6632ebc..6200c64 100644
--- a/solar.py
+++ b/solar.py
@@ -249,7 +249,7 @@ def GetNutation(jde):
jce = julian.GetJulianEphemerisCentury(jde)
nutation_long = []
nutation_oblique = []
- x = PrecalculateAberrations(poly.buildPolyDict(), jce)
+ x = PrecalculateAberrations(constants.buildPolyDict(), jce)
for i in range(len(abcd)):
sigmaxy = GetNutationAberrationXY(jce, i, x)
--
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