Sunrise Sunset
This class will determine the sunrise and sunset. It can use either official, civil, nautical, amateur, or astronomical zenith.
CVS Repository This is off site.
The constructor takes three positional arguments and one keyword argument. The date argument is a datetime object with timezone info, lat and lon are floating point values, and zenith is a string consisting of any of the above bold values--the default is official.
ss = SunriseSunset(date, lat, lon, zenith='official')
There are two callable methods after the class is instantiated.
The getSunRiseSet() method returns a tuple of datetime objects with timezome info.
rise, set = ss.getSunRiseSet()
The isNight() method returns True if it is nighttime and False if it is daytime. The optional collar keyword argument if changed will skew the results to either before or after the real sunrise and sunset. This is useful if lead and lag times are needed around the actual sunrise and sunset.
isNight = ss.isNight(collar=0)
The formula was taken from a VBScript implementation which is broken for certain times of the day. It can be found at:
I also found valuable information on these sites:
http://stjarnhimlen.se/english.html