Page 1 of 1

Sunrise and Sunset calculation in Python

Posted: Thu Jul 02, 2015 6:59 pm
by wymand
Here is a link to my blog http://tigermountainsprings.net/wp/?p=343 on adding
Sunrise and Sunset calculation to a Raspberry Pi running Python.
this is part of my Chicken Coop Control http://tigermountainsprings.net/wp/ system
that I use to operate and protect the chicken coop and flock.

Re: Sunrise and Sunset calculation in Python

Posted: Thu Jul 02, 2015 7:51 pm
by DougieLawson

Code: Select all

#!/usr/bin/python
import ephem
import datetime

somewhere = ephem.Observer()
somewhere.lat = '51.2xxxxxx0' # <== change me
somewhere.lon = '-1.1xxxxxx0' # <== and change me
somewhere.elevation = 112
print somewhere.date

sun = ephem.Sun()
r1 = somewhere.next_rising(sun)
s1 = somewhere.next_setting(sun)

somewhere.horizon = '-0:34'
r2 = somewhere.next_rising(sun)
s2 = somewhere.next_setting(sun)
print ("Visual sunrise %s" % r1)
print ("Visual sunset %s" % s1)
print ("Naval obs sunrise %s" % r2)
print ("Naval obs sunset %s" % s2)
I've obfuscated my lat/long (+ve lat == N of equator, +ve long == E of Greenwich).

Re: Sunrise and Sunset calculation in Python

Posted: Mon Oct 31, 2016 7:32 pm
by rfeyer
Question:
The results above are given in UTC time.
How would you extract 4 hours from the given results as I live in EDT?

Re: Sunrise and Sunset calculation in Python

Posted: Wed Nov 02, 2016 8:10 pm
by DougieLawson
Of course they're in GMT/UTC that's my local TZ.

http://rhodesmill.org/pyephem/quick.html#local-time

Re: Sunrise and Sunset calculation in Python

Posted: Thu Nov 03, 2016 11:41 pm
by richrarobi
Had the same problem, found this treasure: http://pythonhosted.org/astral/
Works for me ...
Any use?