Skip to content

Commit fa888c6

Browse files
dfulukandersolar
andauthored
Remove pandas series usage from ephemeris (#2626)
* Remove pandas series usage from ephemeris * Fix line length * Add note to release notes * remove v0.13.2 entries * v0.15.1 whatsnew --------- Co-authored-by: Kevin Anderson <kevin.anderso@gmail.com>
1 parent d559e2a commit fa888c6

File tree

2 files changed

+32
-22
lines changed

2 files changed

+32
-22
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Enhancements
2929
~~~~~~~~~~~~
3030
* Use ``k`` and ``cap_adjustment`` from :py:func:`pvlib.pvsystem.Array.module_parameters` in :py:func:`pvlib.pvsystem.PVSystem.pvwatts_dc`
3131
(:issue:`2714`, :pull:`2715`)
32-
32+
* Accelerate the internals of :py:func:`~pvlib.solarpostion.ephemeris`. (:pull:`2626`)
3333

3434
Documentation
3535
~~~~~~~~~~~~~
@@ -84,4 +84,5 @@ Contributors
8484
* Rohan Saxena (:ghuser:`r0hansaxena`)
8585
* Marco Fumagalli (:ghuser:`fuma900`)
8686
* Jean-Baptiste Pasquier (:ghuser:`pasquierjb`)
87+
* James Fulton (:ghuser:`dfulu`)
8788

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)