Skip to content

Improve performance of solarposition.ephemeris #512

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cwhanse opened this issue Jul 27, 2018 · 1 comment
Closed

Improve performance of solarposition.ephemeris #512

cwhanse opened this issue Jul 27, 2018 · 1 comment
Milestone

Comments

@cwhanse
Copy link
Member

cwhanse commented Jul 27, 2018

solarposition.ephemeris returns results in dataframe with a localized time index, rather than UTC time. This results in slow performance because the dataframe is assembled from Series and np.arrays that are calculated using UTC time, requiring a timezone conversion.

To Reproduce
Change line 693 from
DFOut = pd.DataFrame(index=time)

to

DFOut = pd.DataFrame(index=time_utc)

to observe the speedup: roughly 23 sec calculation time for 500k timesteps with index=time, and <5 seconds for index=time_utc

  • pvlib.__version__: 0.5.2
  • pandas.__version__: 0.20.3

Recommend that solarposition.ephemeris return a dataframe indexed in UTC time.

@wholmgren
Copy link
Member

The returned index is the same as the input index, and is not necessarily localized. I think the bottleneck is the same as in #502 -- in each case the DataFrame index is not the same as the first Series index. I agree with the proposed change, but suggest that we also add

DFOut.index = time

following the construction of the DataFrame. So the whole thing would look like

    # 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

Have not tested it, but I think it would work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants