Skip to content

Commit

Permalink
Added setup.py
Browse files Browse the repository at this point in the history
  • Loading branch information
raidoz committed May 31, 2016
1 parent 4cdad19 commit 7a9f1ec
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 35 deletions.
23 changes: 23 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""
sunriseset: Calculate sunrise and sunset in a given location on a given date.
"""

from setuptools import setup

import sunriseset

doclines = __doc__.split("\n")

setup(name='sunriseset',
version=sunriseset.version,
description='Algorithm to calculate sunrise and sunset.',
long_description='\n'.join(doclines[2:]),
url='http://github.com/proactivity-lab/py-sunriseset',
author='Raido Pahtma',
author_email='[email protected]',
license='MIT',
platforms=['any'],
packages=['sunriseset'],
test_suite='nose.collector',
tests_require=['nose'],
zip_safe=False)
2 changes: 1 addition & 1 deletion sunriseset/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .sunriseset import *
from .sunriseset import *
11 changes: 8 additions & 3 deletions sunriseset/sunriseset.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
""" Algorithm to calculate sunrise and sunset."""
"""sunriseset.py: Algorithm to calculate sunrise and sunset."""

import math


__author__ = "Raido Pahtma"
__license__ = "MIT"


import math
version = "0.1.0"


ZENITH_OFFICIAL = 90+50/60.0
ZENITH_CIVIL = 96
ZENITH_NAUTICAL = 102
ZENITH_ASTRONOMICAL = 108


def sun_time(zenith, rising, year, month, day, longitude, latitude, local=0):
"""
Sunrise/Sunset Algorithm
Expand Down Expand Up @@ -191,7 +196,6 @@ def sun_time(zenith, rising, year, month, day, longitude, latitude, local=0):
UT = T - lngHour
NOTE: UT potentially needs to be adjusted into the range [0,24) by adding/subtracting 24
"""

UT = T - lngh

"""
Expand All @@ -207,6 +211,7 @@ def sun_time(zenith, rising, year, month, day, longitude, latitude, local=0):

return local_T


def convert_time(ut):
"""
Convert the sun_time float value to a string.
Expand Down
61 changes: 30 additions & 31 deletions test_sunriseset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,46 @@

from sunriseset import sun_time, convert_time, ZENITH_OFFICIAL, ZENITH_CIVIL, ZENITH_NAUTICAL, ZENITH_ASTRONOMICAL


class SunriseSunsetTest(unittest.TestCase):

def test_zenith(self):
print
for zenith in [ZENITH_OFFICIAL, ZENITH_CIVIL, ZENITH_NAUTICAL, ZENITH_ASTRONOMICAL]:
print "----------------------------------------------------------------------"
print "zenith %f" % (zenith)
srise = sun_time(zenith, True, 2015, 7, 18, 24.7453, 59.4372, 3)
sset = sun_time(zenith, False, 2015, 7, 18, 24.7453, 59.4372, 3)
print "Sunrise %s(%.6f), sunset %s(%.6f)" % (convert_time(srise), srise, convert_time(sset), sset)

def test_rovaniemi(self):
def test_tallinn(self):
print
print "Rovaniemi 66.5014N, 25.7347E -----------------------------------------"
srise = sun_time(ZENITH_OFFICIAL, True, 2013, 7, 6, 25.7347, 66.5014, 3)
sset = sun_time(ZENITH_OFFICIAL, False, 2013, 7, 6, 25.7347, 66.5014, 3)
print "Tallinn -----------------------------------------"
# 59.433900 24.754900
year = 2016
srise = sun_time(ZENITH_OFFICIAL, True, year, 2, 17, 24.754900, 59.433900, 3)
sset = sun_time(ZENITH_OFFICIAL, False, year, 2, 17, 24.754900, 59.433900, 3)
print "Sunrise %s(%.6f), sunset %s(%.6f)" % (convert_time(srise), srise, convert_time(sset), sset)
srise = sun_time(ZENITH_OFFICIAL, True, 2013, 7, 7, 25.7347, 66.5014, 3)
sset = sun_time(ZENITH_OFFICIAL, False, 2013, 7, 7, 25.7347, 66.5014, 3)
srise = sun_time(ZENITH_OFFICIAL, True, year, 2, 17, 24.754900, 59.433900, 0)
sset = sun_time(ZENITH_OFFICIAL, False, year, 2, 17, 24.754900, 59.433900, 0)
print "Sunrise %s(%.6f), sunset %s(%.6f)" % (convert_time(srise), srise, convert_time(sset), sset)

srise = sun_time(ZENITH_OFFICIAL, True, year, 2, 17, 59.433900, 24.754900, 0)
sset = sun_time(ZENITH_OFFICIAL, False, year, 2, 17, 59.433900, 24.754900, 0)
print "Sunrise %s(%.6f), sunset %s(%.6f)" % (convert_time(srise), srise, convert_time(sset), sset)
srise = sun_time(ZENITH_OFFICIAL, True, 2013, 7, 8, 25.7347, 66.5014, 3)
sset = sun_time(ZENITH_OFFICIAL, False, 2013, 7, 8, 25.7347, 66.5014, 3)

srise = sun_time(ZENITH_OFFICIAL, True, 2016, 3, 17, 24.754900, 59.433900, 0)
sset = sun_time(ZENITH_OFFICIAL, False, 2016, 3, 17, 24.754900, 59.433900, 0)
print "Sunrise %s(%.6f), sunset %s(%.6f)" % (convert_time(srise), srise, convert_time(sset), sset)

def test_janmayen(self):
def test_2016(self):
print
print "Jan Mayen 70.9833N, 7.5333E ------------------------------------------"
srise = sun_time(ZENITH_OFFICIAL, True, 2015, 8, 1, 7.5333, 70.9833, 0)
sset = sun_time(ZENITH_OFFICIAL, False, 2015, 8, 1, 7.5333, 70.9833, 0)
print "Tallinn 2016 -----------------------------------"
# 59.433900 24.754900
year = 2016
srise = sun_time(ZENITH_OFFICIAL, True, year, 3, 29, 24.754900, 59.433900, 3)
sset = sun_time(ZENITH_OFFICIAL, False, year, 3, 29, 24.754900, 59.433900, 3)
print "Sunrise %s(%.6f), sunset %s(%.6f)" % (convert_time(srise), srise, convert_time(sset), sset)
srise = sun_time(ZENITH_OFFICIAL, True, 2015, 7, 31, 7.5333, 70.9833, 0)
sset = sun_time(ZENITH_OFFICIAL, False, 2015, 7, 31, 7.5333, 70.9833, 0)

srise = sun_time(ZENITH_OFFICIAL, True, year, 3, 30, 24.754900, 59.433900, 3)
sset = sun_time(ZENITH_OFFICIAL, False, year, 3, 30, 24.754900, 59.433900, 3)
print "Sunrise %s(%.6f), sunset %s(%.6f)" % (convert_time(srise), srise, convert_time(sset), sset)

def test_husavik(self):
print
print "Husavik 66.0500N, 17.3167E -------------------------------------------"
# 2015-06-02 sunrise 02:17, no sunset
srise = sun_time(ZENITH_OFFICIAL, True, 2015, 6, 2, 17.3167, 66.0500, 0)
sset = sun_time(ZENITH_OFFICIAL, False, 2015, 6, 2, 17.3167, 66.0500, 0)
srise = sun_time(ZENITH_OFFICIAL, True, year, 3, 31, 24.754900, 59.433900, 3)
sset = sun_time(ZENITH_OFFICIAL, False, year, 3, 31, 24.754900, 59.433900, 3)
print "Sunrise %s(%.6f), sunset %s(%.6f)" % (convert_time(srise), srise, convert_time(sset), sset)
srise = sun_time(ZENITH_OFFICIAL, True, 2015, 6, 3, 17.3167, 66.0500, 0)
sset = sun_time(ZENITH_OFFICIAL, False, 2015, 6, 3, 17.3167, 66.0500, 0)

srise = sun_time(ZENITH_OFFICIAL, True, year, 4, 1, 24.754900, 59.433900, 3)
sset = sun_time(ZENITH_OFFICIAL, False, year, 4, 1, 24.754900, 59.433900, 3)
print "Sunrise %s(%.6f), sunset %s(%.6f)" % (convert_time(srise), srise, convert_time(sset), sset)

0 comments on commit 7a9f1ec

Please sign in to comment.