[Tutor] lists, arrays and saving data
Chris Begert
cbeg at gmx.de
Sun Nov 21 14:12:47 CET 2010
Hi Gurus
I just wrote my first little python program; so yes I'm very new to all this.
The goal in the end is to have a program that shows how the sun moves from the point of view of a given location (i.e. solar paths added to some sort of stereographic diagram).
My very first program calculates the height (altitude) and direction of the sun (Azimuth) at a specific location during a specific time.
So here's my question (I'm sure its obvious for most of you):
How do I store a years worth of data of angles in an array / list / whatever is most useful when using Python?
Thanks in advance for your answers.
Cheers
Chris
BTW,Here's what I wrote:
## http://answers.google.com/answers/threadview/id/782886.html
## Das Programm berechnet die Höhe und Richtung der Sonne zu einer bestimmten Zeit für einen bestimmten Ort
## Die Formeln sind vor der obigen webseite und sollten geprüft werden.
## Ist die Equation of Time genauer?
from datetime import date
import datetime
import math
## geht das einfacher?
from math import sin
from math import cos
from math import degrees
from math import radians
from math import acos
## Input - später ein drop-down menü
print("Please specify your location")
long = float(input("Longitude in degrees: "))
lati = float(input("Latitude in degrees: "))
## Das wird später mal ne range basierend auf dem Ort
month = int(input("Month: "))
day = int(input("Day: "))
hour = float(input("Hour: "))
minutes = float(input("Minutes: "))
## Berechnung der Nummer des Tages
time = hour + minutes/60
Nd = datetime.datetime(2010,month,day).timetuple().tm_yday
## this is the fractional year
gdeg = (360/365.25)*(Nd + time/24)
g = math.radians(gdeg)
## SOLAR DECLINATION
## Follows the calculation of the declination of the sun, again you an use a table or a formula
##"Table of the Declination of the Sun": http://www.wsanford.com/~wsanford/exo/sundials/DEC_Sun.html
## Or use the following formula:
D = 0.396372-22.91327*math.cos(g)+4.02543*math.sin(g)-0.387205*math.cos(2*g)+0.051967*math.sin(2*g)-0.154527*math.cos(3*g) + 0.084798*math.sin(3*g)
##Now calculate the TIME CORRECTION for solar angle:
TC = 0.004297+0.107029*math.cos(g)-1.837877*sin(g)-0.837378*cos(2*g)-2.340475*sin(2*g)
## Now we can calculate the Solar Hour Angle (SHA)
SHA = (time-12)*15 + long + TC
if SHA > 180:
SHA = SHA - 360
elif SHA< -180:
SHA = SHA + 360
else:
SHA = SHA
print(SHA)
##Now we can calculate the Sun Zenith Angle (SZA):
cosSZA = sin(radians(lati))*sin(radians(D))+cos(radians(lati))*cos(radians(D))*cos(radians(SHA))
SZA = degrees(acos(cosSZA))
altitude = 90 - SZA
##To finish we will calculate the Azimuth Angle (AZ):
cosAZ = (sin(radians(D)) - sin(radians(lati)) * cos(radians(SZA))) / (cos(radians(lati))*sin(radians(SZA)))
AZ = degrees(acos(cosAZ))
print("Altitude: ", altitude)
print("Azimuth: ",AZ)
--
GMX DSL Doppel-Flat ab 19,99 €/mtl.! Jetzt auch mit
gratis Notebook-Flat! http://portal.gmx.net/de/go/dsl
More information about the Tutor
mailing list