Skip to content

Commit 943fcbe

Browse files
Account for gregorian/julian offset before 1582 in spa.julian_day_dt (#2249)
* fix to pvlib/spa.py for issue #2077 * add-test_julian_day_issue_2207 * correct-test-indention-and-class * fix-typos-cleanup * fix-linting-errors-add-blank-lines * 2 blank lines before a function, one blank line at the end of a file. * one last linter fix * add whatsnew entry, contributors --------- Co-authored-by: Kevin Anderson <[email protected]>
1 parent 38eb89e commit 943fcbe

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

docs/sphinx/source/whatsnew/v0.11.2.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ Enhancements
1212
~~~~~~~~~~~~
1313

1414

15+
Bug fixes
16+
~~~~~~~~~
17+
* :py:func:`~pvlib.spa.julian_day_dt` now accounts for the 10 day difference
18+
between Julian and Gregorian calendars prior to the year 1582. (:issue:`2077`, :pull:`2249`)
19+
1520
Documentation
1621
~~~~~~~~~~~~~
1722
* Edited docstrings for :py:func:`~pvlib.pvsystem.dc_ohms_from_percent` and
@@ -37,6 +42,8 @@ Contributors
3742
~~~~~~~~~~~~
3843
* Cliff Hansen (:ghuser:`cwhanse`)
3944
* Rajiv Daxini (:ghuser:`RDaxini`)
45+
* Dave Pitts (:ghuser:`dgapitts`)
46+
* Kurt Rhee (:ghuser:`kurt-rhee`)
4047
* Mark Mikofski (:ghuser:`mikofski`)
4148
* matsuobasho (:ghuser:`matsuobasho`)
4249
* Echedey Luis (:ghuser:`echedey-ls`)

pvlib/spa.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,10 @@ def julian_day_dt(year, month, day, hour, minute, second, microsecond):
413413
frac_of_day = (microsecond / 1e6 + (second + minute * 60 + hour * 3600)
414414
) * 1.0 / (3600*24)
415415
d = day + frac_of_day
416-
jd = (int(365.25 * (year + 4716)) + int(30.6001 * (month + 1)) + d +
417-
b - 1524.5)
416+
jd = int(365.25 * (year + 4716)) + int(30.6001 * (month + 1)) + d - 1524.5
417+
if jd > 2299160.0:
418+
jd += b
419+
418420
return jd
419421

420422

pvlib/tests/test_spa.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import os
22
import datetime as dt
33
import warnings
4+
import pytest
5+
import pvlib
46

57
try:
68
from importlib import reload
@@ -423,3 +425,30 @@ def test_solar_position_multithreaded(self):
423425
nresult, self.spa.solar_position(
424426
times, lat, lon, elev, pressure, temp, delta_t,
425427
atmos_refract, numthreads=3, sst=True)[:3], 5)
428+
429+
430+
# Define extra test cases for issue #2077
431+
test_cases_issue_2207 = [
432+
((2000, 1, 1, 12, 0, 0), 2451545.0),
433+
((1999, 1, 1, 0, 0, 0), 2451179.5),
434+
((1987, 1, 27, 0, 0, 0), 2446822.5),
435+
((1987, 6, 19, 12, 0, 0), 2446966.0),
436+
((1988, 1, 27, 0, 0, 0), 2447187.5),
437+
((1988, 6, 19, 12, 0, 0), 2447332.0),
438+
((1900, 1, 1, 0, 0, 0), 2415020.5),
439+
((1600, 1, 1, 0, 0, 0), 2305447.5),
440+
((1600, 12, 31, 0, 0, 0), 2305812.5),
441+
((837, 4, 10, 7, 12, 0), 2026871.8),
442+
((-123, 12, 31, 0, 0, 0), 1676496.5),
443+
((-122, 1, 1, 0, 0, 0), 1676497.5),
444+
((-1000, 7, 12, 12, 0, 0), 1356001.0),
445+
((-1000, 2, 29, 0, 0, 0), 1355866.5),
446+
((-1001, 8, 17, 21, 36, 0), 1355671.4),
447+
((-4712, 1, 1, 12, 0, 0), 0.0),
448+
]
449+
450+
451+
@pytest.mark.parametrize("inputs, expected", test_cases_issue_2207)
452+
def test_julian_day_issue_2207(inputs, expected):
453+
result = pvlib.spa.julian_day_dt(*inputs, microsecond=0)
454+
assert result == expected, f"Failed for inputs {inputs}"

0 commit comments

Comments
 (0)