Skip to content

Commit 52f3c57

Browse files
committed
Merge branch 'main' of https://github.com/pvlib/pvlib-python into pvsystem-temp-models
2 parents 12e27ff + fa888c6 commit 52f3c57

2 files changed

Lines changed: 33 additions & 21 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Enhancements
3131
(:issue:`2714`, :pull:`2715`)
3232
* Include `ross` and `faiman_rad` in the allowed models within
3333
:py:meth:`pvlib.pvsystem.PVSystem.get_cell_temperature` (:issue:`2625`, :pull:`2631`)
34+
* Accelerate the internals of :py:func:`~pvlib.solarpostion.ephemeris`. (:pull:`2626`)
3435

3536
Documentation
3637
~~~~~~~~~~~~~
@@ -86,3 +87,5 @@ Contributors
8687
* Marco Fumagalli (:ghuser:`fuma900`)
8788
* Jean-Baptiste Pasquier (:ghuser:`pasquierjb`)
8889
* Rodrigo Amaro e Silva (:ghuser:`ramaroesilva`)
90+
* James Fulton (:ghuser:`dfulu`)
91+

pvlib/solarposition.py

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -826,34 +826,43 @@ def ephemeris(time, latitude, longitude, pressure=101325.0, temperature=12.0):
826826

827827
# Calculate refraction correction
828828
Elevation = SunEl
829-
TanEl = pd.Series(np.tan(np.radians(Elevation)), index=time_utc)
830-
Refract = pd.Series(0., index=time_utc)
831-
832-
Refract[(Elevation > 5) & (Elevation <= 85)] = (
833-
58.1/TanEl - 0.07/(TanEl**3) + 8.6e-05/(TanEl**5))
834-
835-
Refract[(Elevation > -0.575) & (Elevation <= 5)] = (
836-
Elevation *
837-
(-518.2 + Elevation*(103.4 + Elevation*(-12.79 + Elevation*0.711))) +
838-
1735)
829+
TanEl = np.tan(np.radians(Elevation))
830+
Refract = np.zeros(len(time_utc))
831+
832+
mask = (Elevation > 5) & (Elevation <= 85)
833+
Refract[mask] = (
834+
58.1/TanEl[mask] - 0.07/(TanEl[mask]**3) + 8.6e-05/(TanEl[mask]**5))
835+
836+
mask = (Elevation > -0.575) & (Elevation <= 5)
837+
Refract[mask] = (
838+
Elevation[mask] * (
839+
-518.2 + Elevation[mask]*(
840+
103.4 + Elevation[mask]*(-12.79 + Elevation[mask]*0.711)
841+
)
842+
) + 1735
843+
)
839844

840-
Refract[(Elevation > -1) & (Elevation <= -0.575)] = -20.774 / TanEl
845+
mask = (Elevation > -1) & (Elevation <= -0.575)
846+
Refract[mask] = -20.774 / TanEl[mask]
841847

842848
Refract *= (283/(273. + temperature)) * (pressure/101325.) / 3600.
843849

844850
ApparentSunEl = SunEl + Refract
845851

846852
# make output DataFrame
847-
DFOut = pd.DataFrame(index=time_utc)
848-
DFOut['apparent_elevation'] = ApparentSunEl
849-
DFOut['elevation'] = SunEl
850-
DFOut['azimuth'] = SunAz
851-
DFOut['apparent_zenith'] = 90 - ApparentSunEl
852-
DFOut['zenith'] = 90 - SunEl
853-
DFOut['solar_time'] = SolarTime
854-
DFOut.index = time
855-
856-
return DFOut
853+
result = pd.DataFrame(
854+
{
855+
"apparent_elevation": ApparentSunEl,
856+
"elevation": SunEl,
857+
"azimuth": SunAz,
858+
"apparent_zenith": 90 - ApparentSunEl,
859+
"zenith": 90 - SunEl,
860+
"solar_time": SolarTime,
861+
},
862+
index=time
863+
)
864+
865+
return result
857866

858867

859868
def calc_time(lower_bound, upper_bound, latitude, longitude, attribute, value,

0 commit comments

Comments
 (0)