Forked from meresmclr/pyephem_sunrise_sunset.py
Last active
October 25, 2024 04:54
-
-
Save scivision/228cad3ee5efe74dd5230ddb19bf36fe to your computer and use it in GitHub Desktop.
Python example of computing sunrise/sunset using PyEphem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ephem | |
import datetime | |
Boston=ephem.Observer() | |
Boston.lat='42.3462' | |
Boston.lon='-71.0978' | |
Boston.date = datetime.datetime.now() | |
# %% these parameters are for super-precise estimates, not necessary. | |
Boston.elevation = 3 # meters | |
Boston.pressure = 1010 # millibar | |
Boston.temp = 25 # deg. Celcius | |
Boston.horizon = 0 | |
sun = ephem.Sun() | |
print("Next sunrise in Boston will be: ",ephem.localtime(Boston.next_rising(sun))) | |
print("Next sunset in Boston will be: ",ephem.localtime(Boston.next_setting(sun))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Boston.date = datetime.datetime.now()
is wrong. All PyEphem dates are expressed in Universal Time (UTC), which is similar to Standard Time in Greenwich, England. datetime.datetime.now() returns a local time!!! UseBoston.date = datetime.datetime.utcnow()
orBoston.date = ephem.now()
to get the current UTC time.