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.
Sunrise and Sunset calculation in Python
Never stop learning
Never stop evolving
Never stop evolving
- DougieLawson
- Posts: 42760
- Joined: Sun Jun 16, 2013 11:19 pm
- Location: A small cave in deepest darkest Basingstoke, UK
Re: Sunrise and Sunset calculation in Python
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)
Languages using left-hand whitespace for syntax are ridiculous
DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.
The use of crystal balls and mind reading is prohibited.
DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.
The use of crystal balls and mind reading is prohibited.
Re: Sunrise and Sunset calculation in Python
Question:
The results above are given in UTC time.
How would you extract 4 hours from the given results as I live in EDT?
The results above are given in UTC time.
How would you extract 4 hours from the given results as I live in EDT?
- DougieLawson
- Posts: 42760
- Joined: Sun Jun 16, 2013 11:19 pm
- Location: A small cave in deepest darkest Basingstoke, UK
Re: Sunrise and Sunset calculation in Python
Of course they're in GMT/UTC that's my local TZ.
http://rhodesmill.org/pyephem/quick.html#local-time
http://rhodesmill.org/pyephem/quick.html#local-time
Languages using left-hand whitespace for syntax are ridiculous
DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.
The use of crystal balls and mind reading is prohibited.
DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.
The use of crystal balls and mind reading is prohibited.
-
- Posts: 273
- Joined: Sun Feb 08, 2015 1:13 pm
Re: Sunrise and Sunset calculation in Python
Had the same problem, found this treasure: http://pythonhosted.org/astral/
Works for me ...
Any use?
Works for me ...
Any use?