diff --git a/docs/sphinx/source/whatsnew/v0.7.2.rst b/docs/sphinx/source/whatsnew/v0.7.2.rst index 2eda805c1e..d49afad155 100644 --- a/docs/sphinx/source/whatsnew/v0.7.2.rst +++ b/docs/sphinx/source/whatsnew/v0.7.2.rst @@ -45,6 +45,8 @@ Bug fixes and various test functions. * Fix :py:func:`~pvlib.iotools.read_tmy3` so that when coerced to a single year the TMY3 index will be monotonically increasing. (:pull:`910`) +* Fix :py:func:`pvlib.spa.julian_day_dt` so that microseconds are scaled + correctly (:issue:`940`) (:pull:`942`) Testing ~~~~~~~ diff --git a/pvlib/spa.py b/pvlib/spa.py index 6c99a03f0c..743df5ce8e 100644 --- a/pvlib/spa.py +++ b/pvlib/spa.py @@ -430,7 +430,7 @@ def julian_day_dt(year, month, day, hour, minute, second, microsecond): month = month+12 a = int(year/100) b = 2 - a + int(a * 0.25) - frac_of_day = (microsecond + (second + minute * 60 + hour * 3600) + frac_of_day = (microsecond / 1e6 + (second + minute * 60 + hour * 3600) ) * 1.0 / (3600*24) d = day + frac_of_day jd = (int(365.25 * (year + 4716)) + int(30.6001 * (month + 1)) + d + diff --git a/pvlib/tests/test_spa.py b/pvlib/tests/test_spa.py index 196acd72cb..70b3b9090d 100644 --- a/pvlib/tests/test_spa.py +++ b/pvlib/tests/test_spa.py @@ -98,7 +98,8 @@ class SpaBase(object): """Test functions common to numpy and numba spa""" def test_julian_day_dt(self): - dt = times.tz_convert('UTC')[0] + # add 1us manually to the test timestamp (GH #940) + dt = times.tz_convert('UTC')[0] + pd.Timedelta(1, unit='us') year = dt.year month = dt.month day = dt.day @@ -106,7 +107,7 @@ def test_julian_day_dt(self): minute = dt.minute second = dt.second microsecond = dt.microsecond - assert_almost_equal(JD, + assert_almost_equal(JD + 1e-6 / (3600*24), # modify expected JD by 1us self.spa.julian_day_dt( year, month, day, hour, minute, second, microsecond), 6)