Skip to content

Account for gregorian/julian offset before 1582 in spa.julian_day_dt #2249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/sphinx/source/whatsnew/v0.11.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -37,6 +42,8 @@ Contributors
~~~~~~~~~~~~
* Cliff Hansen (:ghuser:`cwhanse`)
* Rajiv Daxini (:ghuser:`RDaxini`)
* Dave Pitts (:ghuser:`dgapitts`)
* Kurt Rhee (:ghuser:`kurt-rhee`)
* Mark Mikofski (:ghuser:`mikofski`)
* matsuobasho (:ghuser:`matsuobasho`)
* Echedey Luis (:ghuser:`echedey-ls`)
6 changes: 4 additions & 2 deletions pvlib/spa.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
29 changes: 29 additions & 0 deletions pvlib/tests/test_spa.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os
import datetime as dt
import warnings
import pytest
import pvlib

try:
from importlib import reload
Expand Down Expand Up @@ -423,3 +425,30 @@ 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.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}"