Reputation: 1046
I have recently downloaded and installed the PySolar module and would like to use it to calculate sun position (azimuth and altitude).
The problem I am having is that the results calculated do not match the results calculated by the NOAA Solar calculator http://www.esrl.noaa.gov/gmd/grad/solcalc/azel.html
For example. Using the PySol
>>> import datetime, solar
>>> d = datetime.datetime(2007,12,21,9,0,0,0)
>>> lat = 41.5
>>> long = -111.5
>>> solar.GetAltitude(lat, long, d)
-63.0267096801
>>solar.GetAzimuth(lat, long, d)
-235.44406245
Using the NOAA model The Altitude is calculated at 0.7 and Azimuth is calculated at 237.64.
Therefore there is a discrepancy between the two values. To summarise:
If you have any suggestions what I am doing wrong or how I can calculate the correct altitude and azimuth for a given location, it would be much appreciated.
Upvotes: 1
Views: 1847
Reputation: 1
Change -111 to +111 and your results might be better. Going west is positive.
Upvotes: -1
Reputation: 28370
Your datetime.datetime has no tzinfo value so will give you the GMT time which is about 7 hours off from the local time. The other factor could well be that NOAA used DMS rather than decimal lat/long so you need to remember to input 41,30,0 and -111,30,0 for the values.
N.B. You might find it instructive to try PyEphrem for this sort of calculation as I find that the documentation is clearer.
Upvotes: 2