Calculate “Solar Noon” using ephem, translating to local time

I have looked at the examples here on using ephem to calculate sunrise and sunset, and have that working great.

I get in trouble when I try to calculate the midpoint between those two times. Here's what I have:

import datetime
import ephem

o = ephem.Observer()
o.lat, o.long, o.date = '37.0625', '-95.677068', datetime.datetime.utcnow()
sun = ephem.Sun(o)
print "sunrise:", o.previous_rising(sun), "UTC"
print "sunset:",o.next_setting(sun), "UTC"
print "noon:",datetime.timedelta((o.next_setting(sun)-o.previous_rising(sun))/2)

I get:

sunrise: 2010/11/2 12:47:40 UTC
sunset: 2010/11/2 23:24:25 UTC
noon: 5:18:22.679044

That's where I'm stuck. I'm a python beginner and frankly not much of a programmer in general.

Any suggestions would be most welcome!

8
задан Lorin Rivers 2 November 2010 в 22:09
поделиться