# Reverse Sun position algorithm?

To find the sun's position (elevation, azimuth) we can use many algorithms including the PSA algorithm.

These algorithm share the fact that the input is the local time, longitude and latitude and the output is the elevation and azimuth.

is there any algorithms that we can use to reverse this, the input would be the sun position and the output would be the local time ?

thanks

-
OK, If have the long and lat, how to get the local time ? –  Mina Samy Oct 20 '11 at 12:10

http://stackoverflow.com/questions/257717/position-of-the-sun-given-time-of-day-and-lat-long has a good set of descriptions of how to do approximately what you want. In short, you either want to use a code or look up the sun's ephemeris.

Using pyephem, for example:

import ephem
o = ephem.Observer()
# lon/lat for LA
o.lon = "118:15:00"
o.lat = "34:03"
sun = ephem.Sun(o)
sun.alt
sun.az


But since you want the inverse, you can get the alt/az as a function of time:

import datetime
dt5 = datetime.timedelta(minutes=5)
time = datetime.datetime.now()
alt,az,times = [],[],[]
for ii in xrange(100): # do 100 steps of 5 minutes
time = time+dt5
o.date = time.strftime("%Y/%m/%d %H:%M:%S")
sun.compute(o)
alt.append(sun.alt)
az.append(sun.az)
times.append(o.date)


You can then invert this data to find time as a function of alt/az. That doesn't quite answer your question, though - I'll keep an eye out for a direct answer.

The Hour Angle HA is the current time referenced to Solar noon. It can be computed by:
$$\cos(HA) = \frac{\sin(alt_\odot) - \sin(\delta_\odot) \sin(Latitude)}{cos(\delta_\odot)}$$ Where $alt_\odot$ is the altitude or elevation angle of the sun and $\delta_\odot$ is the declination of the sun and can be approximated by: $$\delta_\odot = -23.44^o \cos\left(\frac{360^o}{365} (N+10)\right)$$ where $N$ is the ordinal date and is 1 at January 1st