Search code examples
pythonpython-2.7astronomypyephem

Pyephem Alt. and Az are completely wrong


I'm getting completely incorrect values for altitude and azimuth of the sun when calculated using the pyephem library.

I've already established my observer location, which is determined by raw_input for the lat and lon. I've checked to make sure this input is appropriate, and it is.

I have a bit of code in a for loop that adds the altitude and azimuth of the sun to my list, DataPoint:

TempTime = str(DataPoint)[2:28] #strange date/time format. this fixes it
observer.date = TempTime
SunData = ep.Sun(observer)
DataPoint.append(SunData.alt)
DataPoint.append(SunData.az)

so, while this should work, this website calculates different values for my date/time and location.

If someone could help me figure out what I'm doing wrong, that'd be great.


Solution

  • Pyephem isn't wrong, your TempTime stripping method is wrong. Note this code from pyephem's tutorial:

    gatech.date = '1984/5/30 16:22:56'   # 12:22:56 EDT
    

    When setting the time for an observer, you need to use GMT, not EST, EDT, CST, etc etc. Since you're getting an altitude of BELOW the horizon on the eastern side, pyephem is assuming that you're passing it a morning GMT time, which will lead to a pre-sunrise EDT (or whatever presumably American timezone you're using.).