I am trying to locate the moon positons (Altitude and Azimuth) using python's ephem module and comparing it to a lookup table for apparent moon positions for my location. I am noticing a significant difference in the values that i obtain for the angles. Here is my test code.
>>> o = ephem.Observer()
>>> o.lat = 39.2545
>>> o.lon = -76.7095
>>> o.elevation = 80
>>> o.date = datetime.datetime.utcnow()
>>> print o.date
2012/8/13 21:00:55
>>> m = ephem.Moon(o)
>>> import math
>>> azimuth = math.degrees(m.az)
>>> azimuth
286.2894281178355
>>> alt = math.degrees(m.alt)
>>> alt
19.35235063580148
Now, compare these angles to the lookup table values:
Date/Time Zenith Azimuth
2012 Aug 13 21:00:00.0 88.45125 294.56966
2012 Aug 13 21:20:00.0 91.82583 297.59090
Note: Alt = 90 - Zenith. So our zenith value would be: 70.64764
My question is, why is there a difference? The lookup table gives the apparent angles. Does that have anything to do with it?
Your problem is that you are accidentally offering the lat
and lon
values in radians, because when PyEphem is given a floating-point number it always assumes that you are doing “raw math” and submitting values in radians:
>>> o.lat = 39.2545
>>> o.lon = -76.7095
If you instead want to provide degrees and have PyEphem translate, you can either provide strings:
>>> o.lat = '39.2545'
>>> o.lon = '-76.7095'
Or you can provide numbers that you compute using a math
function, if that helps you keep everything straight, since the PyEphem practice of converting strings to numbers is not a standard Python idiom, whereas everyone will understand math.radians()
when reading your code:
>>> o.lat = math.radians(39.2545)
>>> o.lon = math.radians(-76.7095)
The observer that you were actually asking about with those large radian values was at the location 89:07:01.8° N, 284:52:09.8° E which is extremely near the North Pole.