python - How to calculate the angle of the sun above the horizon using pyEphem -


i'm new pyephem , simple question. want calculate angle of sun above horizon @ gps point , date. code follows:

import ephem import datetime  date = datetime.datetime(2010,1,1,12,0,0) print "date: " + str(date)  obs=ephem.observer() obs.lat='31:00' obs.long='-106:00' obs.date = date print obs  sun = ephem.sun(obs) sun.compute(obs) print float(sun.alt) print str(sun.alt) sun_angle = float(sun.alt) * 57.2957795 # convert radians degrees print "sun_angle: %f" % sun_angle 

and output is:

python suntry.py date: 2010-01-01 12:00:00 <ephem.observer date='2010/1/1 12:00:00' epoch='2000/1/1 12:00:00' lon=-106:00:00.0 lat=31:00:00.0 elevation=0.0m horizon=0:00:00.0 temp=15.0c pressure=1010.0mbar> -0.44488877058 -25:29:24.9 sun_angle: -25.490249 

why alt negative? gps location somewhere in mexico , i've specified 12 noon in date parameter of observer. sun should pretty directly overhead have thought alt variable return angle somewhere int range of 70 - 90 degrees? missing here?

thanks

stephen

i believe problem in pyephem, dates in utc. no matter local timezone observer's lat/lon, if tell noon, assumes mean noon in utc. means have pass in time intend converted utc.

the utc time "somewhere in mexico @ datetime.datetime(2010,1,1,12,0,0)" datetime.datetime(2010,1,1,18,0,0).

with new date, output

sun_angle: 33.672932 

that still seems kind of low, more reasonable -25.

if want programmatic way of doing it, can (at own risk) meddle module pytz.

tz_mexico = pytz.timezone('america/mexico_city') mexico_time = datetime.datetime(2010,1,1,12,0,0,0,tz_mexico) utc_time = mexico_time.astimezone(pytz.utc) obs.date = utc_time 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -