From 13c3851c6dd4b69aa31eca044f41ee470457955e Mon Sep 17 00:00:00 2001 From: Dave Pitts Date: Wed, 9 Oct 2024 20:51:15 +0200 Subject: [PATCH 1/8] fix to pvlib/spa.py for issue #2077 --- pvlib/spa.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pvlib/spa.py b/pvlib/spa.py index 23c0d42ed4..d4181aaa49 100644 --- a/pvlib/spa.py +++ b/pvlib/spa.py @@ -413,8 +413,10 @@ def julian_day_dt(year, month, day, hour, minute, second, microsecond): 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 + - b - 1524.5) + jd = int(365.25 * (year + 4716)) + int(30.6001 * (month + 1)) + d - 1524.5 + if jd > 2299160.0: + jd += b + return jd From 24d07797987bda0baf968403dea664222b596e6f Mon Sep 17 00:00:00 2001 From: Dave Pitts Date: Tue, 15 Oct 2024 22:11:36 +0200 Subject: [PATCH 2/8] add-test_julian_day_issue_2207 --- pvlib/tests/test_spa.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/pvlib/tests/test_spa.py b/pvlib/tests/test_spa.py index f4b6dec03d..a91159bd68 100644 --- a/pvlib/tests/test_spa.py +++ b/pvlib/tests/test_spa.py @@ -1,6 +1,7 @@ import os import datetime as dt import warnings +import pytest try: from importlib import reload @@ -423,3 +424,28 @@ def test_solar_position_multithreaded(self): nresult, self.spa.solar_position( times, lat, lon, elev, pressure, temp, delta_t, atmos_refract, numthreads=3, sst=True)[:3], 5) + + # Define extra test cases for issue #2077 + test_cases_issue_2207 = [ + ((2000, 1, 1, 12, 0, 0), 2451545.0), + ((1999, 1, 1, 0, 0, 0), 2451179.5), + ((1987, 1, 27, 0, 0, 0), 2446822.5), + ((1987, 6, 19, 12, 0, 0), 2446966.0), + ((1988, 1, 27, 0, 0, 0), 2447187.5), + ((1988, 6, 19, 12, 0, 0), 2447332.0), + ((1900, 1, 1, 0, 0, 0), 2415020.5), + ((1600, 1, 1, 0, 0, 0), 2305447.5), + ((1600, 12, 31, 0, 0, 0), 2305812.5), + ((837, 4, 10, 7, 12, 0), 2026871.8), + ((-123, 12, 31, 0, 0, 0), 1676496.5), + ((-122, 1, 1, 0, 0, 0), 1676497.5), + ((-1000, 7, 12, 12, 0, 0), 1356001.0), + ((-1000, 2, 29, 0, 0, 0), 1355866.5), + ((-1001, 8, 17, 21, 36, 0), 1355671.4), + ((-4712, 1, 1, 12, 0, 0), 0.1), + ] + + @pytest.mark.parametrize("inputs, expected", test_cases_issue_2207) + def test_julian_day_issue_2207(inputs, expected): + result = pvlib.spa.julian_day_dt(*inputs, microsecond=0) + assert result == expected, f"Failed for inputs {inputs}: expected {expected}, got {result}" From 2e9791708cffab19d1e73eaec8ebc43d997ca2ff Mon Sep 17 00:00:00 2001 From: Dave Pitts Date: Tue, 22 Oct 2024 06:14:25 +0300 Subject: [PATCH 3/8] correct-test-indention-and-class --- pvlib/tests/test_spa.py | 49 +++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/pvlib/tests/test_spa.py b/pvlib/tests/test_spa.py index a91159bd68..7db4c73d62 100644 --- a/pvlib/tests/test_spa.py +++ b/pvlib/tests/test_spa.py @@ -2,6 +2,7 @@ import datetime as dt import warnings import pytest +import pylib try: from importlib import reload @@ -425,27 +426,27 @@ def test_solar_position_multithreaded(self): times, lat, lon, elev, pressure, temp, delta_t, atmos_refract, numthreads=3, sst=True)[:3], 5) - # Define extra test cases for issue #2077 - test_cases_issue_2207 = [ - ((2000, 1, 1, 12, 0, 0), 2451545.0), - ((1999, 1, 1, 0, 0, 0), 2451179.5), - ((1987, 1, 27, 0, 0, 0), 2446822.5), - ((1987, 6, 19, 12, 0, 0), 2446966.0), - ((1988, 1, 27, 0, 0, 0), 2447187.5), - ((1988, 6, 19, 12, 0, 0), 2447332.0), - ((1900, 1, 1, 0, 0, 0), 2415020.5), - ((1600, 1, 1, 0, 0, 0), 2305447.5), - ((1600, 12, 31, 0, 0, 0), 2305812.5), - ((837, 4, 10, 7, 12, 0), 2026871.8), - ((-123, 12, 31, 0, 0, 0), 1676496.5), - ((-122, 1, 1, 0, 0, 0), 1676497.5), - ((-1000, 7, 12, 12, 0, 0), 1356001.0), - ((-1000, 2, 29, 0, 0, 0), 1355866.5), - ((-1001, 8, 17, 21, 36, 0), 1355671.4), - ((-4712, 1, 1, 12, 0, 0), 0.1), - ] - - @pytest.mark.parametrize("inputs, expected", test_cases_issue_2207) - def test_julian_day_issue_2207(inputs, expected): - result = pvlib.spa.julian_day_dt(*inputs, microsecond=0) - assert result == expected, f"Failed for inputs {inputs}: expected {expected}, got {result}" +# Define extra test cases for issue #2077 +test_cases_issue_2207 = [ + ((2000, 1, 1, 12, 0, 0), 2451545.0), + ((1999, 1, 1, 0, 0, 0), 2451179.5), + ((1987, 1, 27, 0, 0, 0), 2446822.5), + ((1987, 6, 19, 12, 0, 0), 2446966.0), + ((1988, 1, 27, 0, 0, 0), 2447187.5), + ((1988, 6, 19, 12, 0, 0), 2447332.0), + ((1900, 1, 1, 0, 0, 0), 2415020.5), + ((1600, 1, 1, 0, 0, 0), 2305447.5), + ((1600, 12, 31, 0, 0, 0), 2305812.5), + ((837, 4, 10, 7, 12, 0), 2026871.8), + ((-123, 12, 31, 0, 0, 0), 1676496.5), + ((-122, 1, 1, 0, 0, 0), 1676497.5), + ((-1000, 7, 12, 12, 0, 0), 1356001.0), + ((-1000, 2, 29, 0, 0, 0), 1355866.5), + ((-1001, 8, 17, 21, 36, 0), 1355671.4), + ((-4712, 1, 1, 12, 0, 0), 0.1), +] + +@pytest.mark.parametrize("inputs, expected", test_cases_issue_2207) +def test_julian_day_issue_2207(inputs, expected): + result = pvlib.spa.julian_day_dt(*inputs, microsecond=0) + assert result == expected, f"Failed for inputs {inputs}" From 8717fb1e143898b5c7b8e549634becf0b860e55c Mon Sep 17 00:00:00 2001 From: Dave Pitts Date: Tue, 22 Oct 2024 06:45:45 +0300 Subject: [PATCH 4/8] fix-typos-cleanup --- pvlib/tests/test_spa.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pvlib/tests/test_spa.py b/pvlib/tests/test_spa.py index 7db4c73d62..9201c79358 100644 --- a/pvlib/tests/test_spa.py +++ b/pvlib/tests/test_spa.py @@ -2,7 +2,7 @@ import datetime as dt import warnings import pytest -import pylib +import pvlib try: from importlib import reload @@ -443,7 +443,7 @@ def test_solar_position_multithreaded(self): ((-1000, 7, 12, 12, 0, 0), 1356001.0), ((-1000, 2, 29, 0, 0, 0), 1355866.5), ((-1001, 8, 17, 21, 36, 0), 1355671.4), - ((-4712, 1, 1, 12, 0, 0), 0.1), + ((-4712, 1, 1, 12, 0, 0), 0.0), ] @pytest.mark.parametrize("inputs, expected", test_cases_issue_2207) From 314b8cddd22cb37d5947bc0511b88a772d087ce1 Mon Sep 17 00:00:00 2001 From: Dave Pitts Date: Tue, 22 Oct 2024 18:40:55 +0300 Subject: [PATCH 5/8] fix-linting-errors-add-blank-lines --- pvlib/tests/test_spa.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pvlib/tests/test_spa.py b/pvlib/tests/test_spa.py index 9201c79358..6323f902e9 100644 --- a/pvlib/tests/test_spa.py +++ b/pvlib/tests/test_spa.py @@ -426,6 +426,7 @@ def test_solar_position_multithreaded(self): times, lat, lon, elev, pressure, temp, delta_t, atmos_refract, numthreads=3, sst=True)[:3], 5) + # Define extra test cases for issue #2077 test_cases_issue_2207 = [ ((2000, 1, 1, 12, 0, 0), 2451545.0), @@ -450,3 +451,5 @@ def test_solar_position_multithreaded(self): def test_julian_day_issue_2207(inputs, expected): result = pvlib.spa.julian_day_dt(*inputs, microsecond=0) assert result == expected, f"Failed for inputs {inputs}" + + From 56ae5d46851a2403cf174604956d803ea0613bfa Mon Sep 17 00:00:00 2001 From: Dave Pitts Date: Thu, 24 Oct 2024 14:18:12 +0300 Subject: [PATCH 6/8] 2 blank lines before a function, one blank line at the end of a file. --- pvlib/tests/test_spa.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pvlib/tests/test_spa.py b/pvlib/tests/test_spa.py index 6323f902e9..fc9a95d830 100644 --- a/pvlib/tests/test_spa.py +++ b/pvlib/tests/test_spa.py @@ -447,9 +447,9 @@ def test_solar_position_multithreaded(self): ((-4712, 1, 1, 12, 0, 0), 0.0), ] + @pytest.mark.parametrize("inputs, expected", test_cases_issue_2207) def test_julian_day_issue_2207(inputs, expected): result = pvlib.spa.julian_day_dt(*inputs, microsecond=0) assert result == expected, f"Failed for inputs {inputs}" - From c85731f69e02eea145cc925a545b7b90c73e67db Mon Sep 17 00:00:00 2001 From: Kevin Anderson Date: Fri, 25 Oct 2024 14:33:56 -0400 Subject: [PATCH 7/8] one last linter fix --- pvlib/tests/test_spa.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pvlib/tests/test_spa.py b/pvlib/tests/test_spa.py index fc9a95d830..67cab4cbdb 100644 --- a/pvlib/tests/test_spa.py +++ b/pvlib/tests/test_spa.py @@ -452,4 +452,3 @@ def test_solar_position_multithreaded(self): def test_julian_day_issue_2207(inputs, expected): result = pvlib.spa.julian_day_dt(*inputs, microsecond=0) assert result == expected, f"Failed for inputs {inputs}" - From 696baf7d0a31bc509e6fc1421b996da1cec5d2ce Mon Sep 17 00:00:00 2001 From: Kevin Anderson Date: Fri, 25 Oct 2024 15:04:08 -0400 Subject: [PATCH 8/8] add whatsnew entry, contributors --- docs/sphinx/source/whatsnew/v0.11.2.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/sphinx/source/whatsnew/v0.11.2.rst b/docs/sphinx/source/whatsnew/v0.11.2.rst index 81d36fda64..9e0561fa6b 100644 --- a/docs/sphinx/source/whatsnew/v0.11.2.rst +++ b/docs/sphinx/source/whatsnew/v0.11.2.rst @@ -12,6 +12,11 @@ Enhancements ~~~~~~~~~~~~ +Bug fixes +~~~~~~~~~ +* :py:func:`~pvlib.spa.julian_day_dt` now accounts for the 10 day difference + between Julian and Gregorian calendars prior to the year 1582. (:issue:`2077`, :pull:`2249`) + Documentation ~~~~~~~~~~~~~ * Edited docstrings for :py:func:`~pvlib.pvsystem.dc_ohms_from_percent` and @@ -31,4 +36,6 @@ Contributors ~~~~~~~~~~~~ * Cliff Hansen (:ghuser:`cwhanse`) * Rajiv Daxini (:ghuser:`RDaxini`) +* Dave Pitts (:ghuser:`dgapitts`) +* Kurt Rhee (:ghuser:`kurt-rhee`)