Skip to content

Instantly share code, notes, and snippets.

@th0ma5w
Created December 3, 2017 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save th0ma5w/e04a1486697de140f04aec40a3b37170 to your computer and use it in GitHub Desktop.
Save th0ma5w/e04a1486697de140f04aec40a3b37170 to your computer and use it in GitHub Desktop.
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