From f376314249241d89fa4a8d04a275b6e2cc35fe0b Mon Sep 17 00:00:00 2001 From: "Adam R. Jensen" <39184289+AdamRJensen@users.noreply.github.com> Date: Fri, 1 Aug 2025 15:51:35 +0200 Subject: [PATCH 1/2] Change refraction correction limit in ephemeris solar position algorithm --- pvlib/solarposition.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pvlib/solarposition.py b/pvlib/solarposition.py index 7284191d68..07005c298f 100644 --- a/pvlib/solarposition.py +++ b/pvlib/solarposition.py @@ -828,7 +828,7 @@ def ephemeris(time, latitude, longitude, pressure=101325.0, temperature=12.0): TanEl = pd.Series(np.tan(np.radians(Elevation)), index=time_utc) Refract = pd.Series(0., index=time_utc) - Refract[(Elevation > 5) & (Elevation <= 85)] = ( + Refract[(Elevation > 5) & (Elevation <= 90)] = ( 58.1/TanEl - 0.07/(TanEl**3) + 8.6e-05/(TanEl**5)) Refract[(Elevation > -0.575) & (Elevation <= 5)] = ( From 068b02ba8380b4cd8f3a5a41626c561942869626 Mon Sep 17 00:00:00 2001 From: "Adam R. Jensen" <39184289+AdamRJensen@users.noreply.github.com> Date: Sat, 2 Aug 2025 15:05:20 +0200 Subject: [PATCH 2/2] Add testing and whatsnew --- docs/sphinx/source/whatsnew/v0.13.1.rst | 3 +++ tests/test_solarposition.py | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/docs/sphinx/source/whatsnew/v0.13.1.rst b/docs/sphinx/source/whatsnew/v0.13.1.rst index d83667b302..2029b7596b 100644 --- a/docs/sphinx/source/whatsnew/v0.13.1.rst +++ b/docs/sphinx/source/whatsnew/v0.13.1.rst @@ -6,6 +6,9 @@ v0.13.1 (Anticipated September, 2025) Breaking Changes ~~~~~~~~~~~~~~~~ +* Change refraction for solar elevation angles between 85 and 90 + degrees to be calculated rather than set to 0 in + :py:func:`~pvlib.solarposition.ephemeris`. (:pull:`2524`) Deprecations diff --git a/tests/test_solarposition.py b/tests/test_solarposition.py index 88093e05f9..5be76ec42c 100644 --- a/tests/test_solarposition.py +++ b/tests/test_solarposition.py @@ -964,3 +964,15 @@ def test_spa_python_numba_physical_dst(expected_solpos, golden): temperature=11, delta_t=67, atmos_refract=0.5667, how='numpy', numthreads=1) + + +def test_ephmeris_refraction_85_90_degrees(): + # Test that refraction is calculated rather than set to zero + # for solar elevatoin angles between 85 and 90 degrees + # PR#2524 + # The below example has a solar elevation angle of 87.9 + result = solarposition.ephemeris( + time=pd.date_range('2020-03-23 12', periods=1, tz='UTC'), + latitude=0, longitude=0) + refraction = (result['apparent_zenith'] - result['zenith']).iloc[0] + assert refraction == -0.0005818446332597205