Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Is the sun up in Columbus? Using PyEphem to figure it out
import ephem
def is_the_sun_up():
columbus = ephem.city('Columbus')
sun = ephem.Sun()
columbus.pressure = 0
sun.compute(columbus)
twilight = -6 * ephem.degree
return sun.alt > twilight
# Civil Twilight is defined as ending / beginning when the sun is 6 degrees below the horizon.
# Setting the pressure to 0 is to turn off atmospheric scattering calculations
#
# http://rhodesmill.org/pyephem/
# http://rhodesmill.org/pyephem/rise-set.html
# https://stackoverflow.com/questions/2637293/calculating-dawn-and-sunset-times-using-pyephem
# https://stackoverflow.com/questions/26501745/how-to-determine-if-it-is-daytime-light-outside-in-python-using-ephem-library
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment