"Chris Begert" <c...@gmx.de> wrote

How do I store a years worth of data of angles in an
array / list / whatever is most useful when using Python?

The choice of data structure usually depends on how
you plan on accessing/using it. So we can't advise
until we know more about what you plan on doing with it!
The good news it that in Python its usuially easy to
switch between the various options if you think you got
it wrong!

Having said that my guess is that a list of tuples will be
your best starting point. Put all the values for a given time
into a tuple (or maybe a dictionary). Then store the list
of timed values in a list (or another dictionary(keyed by time) )


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

from math import sin,cos,degrees,radians,acos

is easier to type :-)

## Input - später ein drop-down menü
print("Please specify your location")
long = float(input("Longitude in degrees: "))
lati = float(input("Latitude in degrees: "))

If you put this in a function which returns the values you
need it will be easier to convert to a GUI(or web page) later.

month =  int(input("Month: "))
day =  int(input("Day: "))
hour = float(input("Hour: "))
minutes = float(input("Minutes: "))

Are you sure you want to allow floating point hours and minutes?

time = hour + minutes/60

See above comment - what if hours is 1.5 and minutes is 37.3?
Is time sensible?

Nd = datetime.datetime(2010,month,day).timetuple().tm_yday


gdeg = (360/365.25)*(Nd + time/24)
g = math.radians(gdeg)

you imported radians so you don't need the math prefix

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)


Fopr long calculations you might find it easioer to read/antain if you put a set of parent around the outside then separate your main terms into lines, like this:

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

Using symbols for the constants would help too, especially
if there are some standard names you can use, like alpha etc?

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

HTH,


--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to