From 4107429c6f9ca0bc463123d3037bbdd63c63cd9f Mon Sep 17 00:00:00 2001 From: James Fulton Date: Tue, 16 Dec 2025 12:56:50 +0000 Subject: [PATCH 1/2] 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/2] 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]