# 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
Commented Oct 20, 2011 at 12:10

https://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

• Thanks for the answer, but the altitude is calculated by this equation: sin theta=cos hcos DCos Lat+sin D*sin Lat, where h is the hour angle too, how to solve this
– Mina Samy
Commented Oct 22, 2011 at 11:39
• Altitude refers to the angle the sun appears at above the horizon. You have to have it as an input. The way your question was phrased, I assumed that the sun's position (i.e., altitude and azimuth) were known. Commented Oct 23, 2011 at 14:44
• Could you clarify what you meant in your original question if my answer doesn't satisfy it? What did you mean by "the input would be the sun position" ? Commented Oct 23, 2011 at 15:35
• The sun position is its azimuth and elevation, I was wondering if I can predict the time where the sun's Azimuth would be in a certain position (azimuth) regardless of the elevation.
– Mina Samy
Commented Oct 24, 2011 at 12:29
• The solar azimuth angle is given by a simple formula en.wikipedia.org/wiki/Solar_azimuth_angle but depends on the elevation. The azimuth angle is therefore dependent on the elevation. If you know the azimuth angle, elevation, and your latitude, you can determine the time. If you know the time and latitude, you can determine the sun's elevation and azimuth angle. Commented Oct 24, 2011 at 15:30