From 943cd7c1da7a28ce9a416e5f8c0aa77fd8316fb9 Mon Sep 17 00:00:00 2001 From: Will Holmgren Date: Mon, 13 Aug 2018 07:32:02 -0700 Subject: [PATCH] improve performance of ephemeris dataframe assembly --- docs/sphinx/source/whatsnew/v0.6.0.rst | 1 + pvlib/solarposition.py | 3 ++- pvlib/test/test_solarposition.py | 13 +++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/sphinx/source/whatsnew/v0.6.0.rst b/docs/sphinx/source/whatsnew/v0.6.0.rst index dc50a50d79..dc4ef4c4ad 100644 --- a/docs/sphinx/source/whatsnew/v0.6.0.rst +++ b/docs/sphinx/source/whatsnew/v0.6.0.rst @@ -60,6 +60,7 @@ Enhancements :func:`~pvlib.singlediode.bishop88_mpp`. * Add PVSyst thin-film recombination losses for CdTe and a:Si (:issue:`163`) * Python 3.7 officially supported. (:issue:`496`) +* Improve performance of solarposition.ephemeris. (:issue:`512`) Bug fixes diff --git a/pvlib/solarposition.py b/pvlib/solarposition.py index 324cca0272..6f18624884 100644 --- a/pvlib/solarposition.py +++ b/pvlib/solarposition.py @@ -690,13 +690,14 @@ def ephemeris(time, latitude, longitude, pressure=101325, temperature=12): ApparentSunEl = SunEl + Refract # make output DataFrame - DFOut = pd.DataFrame(index=time) + 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 diff --git a/pvlib/test/test_solarposition.py b/pvlib/test/test_solarposition.py index 8ff1f2c65a..b99e5e7ff4 100644 --- a/pvlib/test/test_solarposition.py +++ b/pvlib/test/test_solarposition.py @@ -260,6 +260,19 @@ def test_ephemeris_physical_dst(expected_solpos): assert_frame_equal(expected_solpos, ephem_data[expected_solpos.columns]) +def test_ephemeris_physical_no_tz(expected_solpos): + times = pd.date_range(datetime.datetime(2003,10,17,19,30,30), + periods=1, freq='D') + ephem_data = solarposition.ephemeris(times, golden_mst.latitude, + golden_mst.longitude, + pressure=82000, + temperature=11) + expected_solpos.index = times + expected_solpos = np.round(expected_solpos, 2) + ephem_data = np.round(ephem_data, 2) + assert_frame_equal(expected_solpos, ephem_data[expected_solpos.columns]) + + def test_get_solarposition_error(): times = pd.date_range(datetime.datetime(2003,10,17,13,30,30), periods=1, freq='D', tz=golden.tz)