[Tutor] Sun Location System
Carlos
carloslara at web.de
Wed Nov 29 19:38:32 CET 2006
Hi Again,
I have been working in a sun location system and it seems like is
working now. But I have two issues that I hope you can help me solve.
I have a number of functions in this script and I would like to know
which is the best way to pass values among them? Here is the script so far:
#####################################################################
from math import *
# I would like to substitute Lat for the location name
def Sol_Pos (Lat, Month, Day, Hour):
month_index = Month -1
date_index = Day -1
def J_Day(month_index,date_index):
j_day=0
date_val=date_index+1
if (month_index==0):
j_day = 0+date_val
elif (month_index==1):
j_day=31+date_val
elif (month_index==2):
j_day=59+date_val
elif (month_index==3):
j_day=90+date_val
elif (month_index==4):
j_day=120+date_val
elif (month_index==5):
j_day=151+date_val
elif (month_index==6):
j_day=181+date_val
elif (month_index==7):
j_day=212+date_val
elif (month_index==8):
j_day=243+date_val
elif (month_index==9):
j_day=273+date_val
elif (month_index==10):
j_day=304+date_val
elif (month_index==11):
j_day=334+date_val
return j_day
def Dec(J_Day):
Dec = 23.45 * sin(radians(( j_day + 284.0) * 360/365))
return Dec
def H_Ang(Hour):
Hour_Angle = 15*(12-Hour)
return Hour_Angle
def Alt(Lat, Dec, H_Ang):
lat_r = radians(Lat)
decl_r = radians(Dec)
hour_r = radians(H_Ang)
sin_alt_r =
cos(lat_r)*cos(decl_r)*cos(hour_r)+sin(lat_r)*sin(decl_r)
sin2alt = sin_alt_r * sin_alt_r
cos_alt_r = sqrt(1 - sin2alt)
Alt = degrees(atan(sin_alt_r / cos_alt_r))
return Sol_Alt
def Az(Lat, Dec, H_Ang):
lat_R = radians(Lat)
decl_R = radians(Dec)
hour_R = radians(H_Ang)
x_azm = sin(hour_R) * cos(decl_R)
y_azm = (-(cos(hour_R))*cos(decl_R)*sin(lat_R))+(cos(lat_R)*
sin(decl_R))
if Lat > 0:
y_azm = y_azm * -1
Azimuth = degrees(atan2(x_azm, y_azm))
return Azimuth
####################################################################
And my idea is to give the script a location name, date and hour and it
will return the sun position relative to that info. So how can I work
with info of this type?
30.30 48.20 Abadan, Iran
45.40 -98.40 Aberdeen Ap, South Dakota - USA
57.10 -2.10 Aberdeen, Scotland
46.90 -123.80 Aberdeen, Washington - USA
5.30 -4.00 Abidjan, Ivory Coasti
32.40 -99.60 Abilene Ap, Texas - USA
5.50 -0.20 Accra, Ghana
I know that a dictionary probably is a solution, but as you can imagine
formatting this data is going to take a long time, there are too many
locations. Is there a solution for this problem?
Thanks for your help,
Carlos
More information about the Tutor
mailing list