Skip to content

Commit

Permalink
Merge pull request #60 from ArneBachmann/master
Browse files Browse the repository at this point in the history
Corrected leap seconds table for 2016 and added entry for 2017. Sorry for the delay, Arne! Thanks for the code.
  • Loading branch information
pingswept authored Nov 3, 2017
2 parents 55debbb + 287fa38 commit c2a0869
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
4 changes: 3 additions & 1 deletion pysolar/solartime.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
[ # two entries per year starting from 1972, first for 23:59:59 June 30,
# second for 23:59:59 December 31. +1 indicates that 23:59:60 follows,
# -1 indicates that 23:59:59 does not exist, not that the latter has ever occurred.
# source: https://www.nist.gov/pml/time-and-frequency-division/atomic-standards/leap-second-and-ut1-utc-information
(+1, +1), # 1972
(0, +1), # 1973
(0, +1), # 1974
Expand Down Expand Up @@ -81,7 +82,8 @@
(0, 0), # 2013
(0, 0), # 2014
(+1, 0), # 2015
(+1, 0), # 2016
(0, +1), # 2016
(0, 0) # 2017
]

def get_leap_seconds(when) :
Expand Down
23 changes: 12 additions & 11 deletions test/testsolar.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@
import datetime
import unittest


class testSolar(unittest.TestCase):

def setUp(self):
self.d = datetime.datetime(2003, 10, 17, 19, 30, 30, tzinfo = datetime.timezone.utc)
self.d = datetime.datetime(2003, 10, 17, 19, 30, 30, tzinfo = datetime.timezone.utc) # only works with Python 3
self.d += datetime.timedelta(seconds = time.get_delta_t(self.d) - time.tt_offset - time.get_leap_seconds(self.d))
# Reda & Andreas say that this time is in "Local Standard Time", which they
# define as 7 hours behind UT (not UTC). Hence the adjustment to convert UT
Expand Down Expand Up @@ -157,32 +158,32 @@ def testPressureWithElevation(self):
def testTemperatureWithElevation(self):
self.assertAlmostEqual(277.9600, self.temperature_with_elevation, 4)


class TestApi(unittest.TestCase):
test_when = datetime.datetime(2016, 12, 19, 23, 0, 0, tzinfo=datetime.timezone.utc )
test_when = datetime.datetime(2016, 12, 19, 23, 0, 0, tzinfo=datetime.timezone.utc)

def testGetPosition(self):
az, al = solar.get_position(59.6365662,12.5350953, TestApi.test_when)
self.assertAlmostEqual(az, 357.1496112)
self.assertAlmostEqual(al, -53.7673267)
self.assertAlmostEqual(az, 357.1431475)
self.assertAlmostEqual(al, -53.7672218)

az, al = solar.get_position(-43, 172, TestApi.test_when)
self.assertAlmostEqual(az, 50.4936927)
self.assertAlmostEqual(al, 63.0945557)
self.assertAlmostEqual(az, 50.5003507)
self.assertAlmostEqual(al, 63.0922058)

# From Greenwich
az, al = solar.get_position(51.4826, 0, TestApi.test_when)
self.assertAlmostEqual(az, 333.0476242)
self.assertAlmostEqual(al, -59.8384205)
self.assertAlmostEqual(az, 333.0403866)
self.assertAlmostEqual(al, -59.8372445)

def testGetAltitude(self):
al = solar.get_altitude(-43, 172, TestApi.test_when)
self.assertAlmostEqual(al, 63.0945557)
self.assertAlmostEqual(al, 63.0922058)

def testGetAzimuth(self):
az = solar.get_azimuth(-43, 172, TestApi.test_when)
self.assertAlmostEqual(az, 50.4936927)
self.assertAlmostEqual(az, 50.5003507)


if __name__ == "__main__":
unittest.main(verbosity=2)
#end if

0 comments on commit c2a0869

Please sign in to comment.