From 4107429c6f9ca0bc463123d3037bbdd63c63cd9f Mon Sep 17 00:00:00 2001 From: James Fulton Date: Tue, 16 Dec 2025 12:56:50 +0000 Subject: [PATCH 1/5] Remove pandas series usage from ephemeris --- pvlib/solarposition.py | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/pvlib/solarposition.py b/pvlib/solarposition.py index 2b8a43e9d0..579f077909 100644 --- a/pvlib/solarposition.py +++ b/pvlib/solarposition.py @@ -826,34 +826,40 @@ def ephemeris(time, latitude, longitude, pressure=101325.0, temperature=12.0): # Calculate refraction correction Elevation = SunEl - TanEl = pd.Series(np.tan(np.radians(Elevation)), index=time_utc) - Refract = pd.Series(0., index=time_utc) + TanEl = np.tan(np.radians(Elevation)) + Refract = np.zeros(len(time_utc)) - Refract[(Elevation > 5) & (Elevation <= 85)] = ( - 58.1/TanEl - 0.07/(TanEl**3) + 8.6e-05/(TanEl**5)) + mask = (Elevation > 5) & (Elevation <= 85) + Refract[mask] = ( + 58.1/TanEl[mask] - 0.07/(TanEl[mask]**3) + 8.6e-05/(TanEl[mask]**5)) - Refract[(Elevation > -0.575) & (Elevation <= 5)] = ( - Elevation * - (-518.2 + Elevation*(103.4 + Elevation*(-12.79 + Elevation*0.711))) + + mask = (Elevation > -0.575) & (Elevation <= 5) + Refract[mask] = ( + Elevation[mask] * + (-518.2 + Elevation[mask]*(103.4 + Elevation[mask]*(-12.79 + Elevation[mask]*0.711))) + 1735) - Refract[(Elevation > -1) & (Elevation <= -0.575)] = -20.774 / TanEl + mask = (Elevation > -1) & (Elevation <= -0.575) + Refract[mask] = -20.774 / TanEl[mask] Refract *= (283/(273. + temperature)) * (pressure/101325.) / 3600. ApparentSunEl = SunEl + Refract # make output DataFrame - DFOut = pd.DataFrame(index=time_utc) - DFOut['apparent_elevation'] = ApparentSunEl - DFOut['elevation'] = SunEl - DFOut['azimuth'] = SunAz - DFOut['apparent_zenith'] = 90 - ApparentSunEl - DFOut['zenith'] = 90 - SunEl - DFOut['solar_time'] = SolarTime - DFOut.index = time - - return DFOut + result = pd.DataFrame( + { + "apparent_elevation": ApparentSunEl, + "elevation": SunEl, + "azimuth": SunAz, + "apparent_zenith": 90 - ApparentSunEl, + "zenith": 90 - SunEl, + "solar_time": SolarTime, + }, + index=time + ) + + return result def calc_time(lower_bound, upper_bound, latitude, longitude, attribute, value, From 68dd4f7d25b6a9c37dd59bbce09e772acb83cd50 Mon Sep 17 00:00:00 2001 From: James Fulton Date: Tue, 16 Dec 2025 16:18:31 +0000 Subject: [PATCH 2/5] Fix line length --- pvlib/solarposition.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pvlib/solarposition.py b/pvlib/solarposition.py index 579f077909..2920864c91 100644 --- a/pvlib/solarposition.py +++ b/pvlib/solarposition.py @@ -835,9 +835,12 @@ def ephemeris(time, latitude, longitude, pressure=101325.0, temperature=12.0): mask = (Elevation > -0.575) & (Elevation <= 5) Refract[mask] = ( - Elevation[mask] * - (-518.2 + Elevation[mask]*(103.4 + Elevation[mask]*(-12.79 + Elevation[mask]*0.711))) + - 1735) + Elevation[mask] * ( + -518.2 + Elevation[mask]*( + 103.4 + Elevation[mask]*(-12.79 + Elevation[mask]*0.711) + ) + ) + 1735 + ) mask = (Elevation > -1) & (Elevation <= -0.575) Refract[mask] = -20.774 / TanEl[mask] From 1fb289d6adbd3f0362aa7cd435f87fe3dfde67b6 Mon Sep 17 00:00:00 2001 From: James Fulton Date: Mon, 5 Jan 2026 13:57:33 +0000 Subject: [PATCH 3/5] Add note to release notes --- docs/sphinx/source/whatsnew/v0.13.2.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/sphinx/source/whatsnew/v0.13.2.rst b/docs/sphinx/source/whatsnew/v0.13.2.rst index b6170a6053..e8718069c5 100644 --- a/docs/sphinx/source/whatsnew/v0.13.2.rst +++ b/docs/sphinx/source/whatsnew/v0.13.2.rst @@ -46,6 +46,7 @@ Enhancements MERRA-2 reanalysis data. (:pull:`2572`) * Add :py:func:`~pvlib.spectrum.spectral_factor_polo`, a function for estimating spectral mismatch factors for vertical PV façades. (:issue:`2406`, :pull:`2491`) +* Accelerate the internals of :py:func:`~pvlib.solarpostion.ephemeris`. (:pull:`2626`) Documentation ~~~~~~~~~~~~~ @@ -87,3 +88,4 @@ Contributors * Anton Driesse (:ghuser:`adriesse`) * Rajiv Daxini (:ghuser:`RDaxini`) * Kevin Anderson (:ghuser:`kandersolar`) +* James Fulton (:ghuser:`dfulu`) From 4956113b1f749e163ea95639f9abf5ad07592cd0 Mon Sep 17 00:00:00 2001 From: Kevin Anderson Date: Thu, 2 Apr 2026 09:38:46 -0400 Subject: [PATCH 4/5] remove v0.13.2 entries --- docs/sphinx/source/whatsnew/v0.13.2.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/sphinx/source/whatsnew/v0.13.2.rst b/docs/sphinx/source/whatsnew/v0.13.2.rst index e8718069c5..b6170a6053 100644 --- a/docs/sphinx/source/whatsnew/v0.13.2.rst +++ b/docs/sphinx/source/whatsnew/v0.13.2.rst @@ -46,7 +46,6 @@ Enhancements MERRA-2 reanalysis data. (:pull:`2572`) * Add :py:func:`~pvlib.spectrum.spectral_factor_polo`, a function for estimating spectral mismatch factors for vertical PV façades. (:issue:`2406`, :pull:`2491`) -* Accelerate the internals of :py:func:`~pvlib.solarpostion.ephemeris`. (:pull:`2626`) Documentation ~~~~~~~~~~~~~ @@ -88,4 +87,3 @@ Contributors * Anton Driesse (:ghuser:`adriesse`) * Rajiv Daxini (:ghuser:`RDaxini`) * Kevin Anderson (:ghuser:`kandersolar`) -* James Fulton (:ghuser:`dfulu`) From 56bda787747670caa8b61174327114a522783c2f Mon Sep 17 00:00:00 2001 From: Kevin Anderson Date: Thu, 2 Apr 2026 09:40:11 -0400 Subject: [PATCH 5/5] v0.15.1 whatsnew --- docs/sphinx/source/whatsnew/v0.15.1.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/sphinx/source/whatsnew/v0.15.1.rst b/docs/sphinx/source/whatsnew/v0.15.1.rst index 75ab242c94..873f13c317 100644 --- a/docs/sphinx/source/whatsnew/v0.15.1.rst +++ b/docs/sphinx/source/whatsnew/v0.15.1.rst @@ -29,7 +29,7 @@ Enhancements ~~~~~~~~~~~~ * Use ``k`` and ``cap_adjustment`` from :py:func:`pvlib.pvsystem.Array.module_parameters` in :py:func:`pvlib.pvsystem.PVSystem.pvwatts_dc` (:issue:`2714`, :pull:`2715`) - +* Accelerate the internals of :py:func:`~pvlib.solarpostion.ephemeris`. (:pull:`2626`) Documentation ~~~~~~~~~~~~~ @@ -84,4 +84,5 @@ Contributors * Rohan Saxena (:ghuser:`r0hansaxena`) * Marco Fumagalli (:ghuser:`fuma900`) * Jean-Baptiste Pasquier (:ghuser:`pasquierjb`) +* James Fulton (:ghuser:`dfulu`)