1

I've only begun using PyEphem today so I'm at a bit of a loss as to why I get such incredibly incorrect results when I try to calculate the solar altitude and azimuth from an observer point. The code is really simple so I can't imagine where it's going wrong:

import ephem
loc = ephem.Observer()
loc.lon = -118.897123
loc.lat = 34.247778
loc.elevation = 55
sun = ephem.Sun()
sun.compute(loc)

When I print out loc I get:

<ephem.Observer date='2020/6/26 21:10:06' epoch='2000/1/1 12:00:00' lon='-6812:18:12.0' lat='1962:15:11.3' elevation=55.0m horizon=0:00:00.0 temp=15.0C pressure=1010.0mBar>

The lat/long and time are all right even though they're presented a little weirdly in the print(loc) statement. Still it's 2:10PM in Southern California so there is no reason that sun.alt and sun.az should print out 1.299 and 6.011 respectively.

Can someone please explain what the issue is here? PyEphem looks like a great library if I could just figure out how to use it correctly. Thanks for the help!

Miles Zoltak
  • 191
  • 11

1 Answers1

1

Set your lat & lon as strings and format the alt & az as strings:

>>> loc = ephem.Observer()
>>> loc.lon = '-118.897123'
>>> loc.lat = '34.247778'
>>> sun = ephem.Sun()
>>> sun.compute(loc)
>>> f"{sun.alt} {sun.az}"
'64:36:51.4 251:28:08.8'
>>> loc
<ephem.Observer date='2020/6/26 21:43:46' epoch='2000/1/1 12:00:00' lon='-118:53:49.6' lat='34:14:52.0' elevation=0.0m horizon=0:00:00.0 temp=15.0C pressure=1010.0mBar>
>>> 

Mike Organek
  • 11,647
  • 3
  • 11
  • 26
  • @MilesZoltak It looks like PyEphem is implemented mostly in `C` as `libastro`. It must be that `libastro` must have strings passed to it to parse into a scalar form of the `degrees:minutes:seconds` representation. The same must be true of the internal representation of `az` and `alt`--that is they need to be coerced into strings to display as `degrees:minutes:seconds`. Good luck with your stargazing! – Mike Organek Jun 27 '20 at 00:29