Skip to content

Allowing spa_c() to use localized time index #301

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
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/sphinx/source/whatsnew/v0.4.4.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ Documentation
* Fixes the Forecasting page's broken links to the tutorials.
* Fixes the Forecasting page's broken examples. (:issue:`299`)
* Fixes broken Classes link in the v0.3.0 documentation.
* Fixes timezone issue in solarposition spa_c function (:issue:`237`)


Contributors
~~~~~~~~~~~~

* Will Holmgren
* Marc Anoma
10 changes: 7 additions & 3 deletions pvlib/solarposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,11 @@ def spa_c(time, latitude, longitude, pressure=101325, altitude=0,

pvl_logger.debug('using built-in spa code to calculate solar position')

time_utc = time
# if localized, convert to UTC. otherwise, assume UTC.
try:
time_utc = time.tz_convert('UTC')
except TypeError:
time_utc = time

spa_out = []

Expand All @@ -184,7 +188,7 @@ def spa_c(time, latitude, longitude, pressure=101325, altitude=0,
hour=date.hour,
minute=date.minute,
second=date.second,
timezone=0, # must input localized or utc time
timezone=0, # date uses utc time
latitude=latitude,
longitude=longitude,
elevation=altitude,
Expand All @@ -193,7 +197,7 @@ def spa_c(time, latitude, longitude, pressure=101325, altitude=0,
delta_t=delta_t
))

spa_df = pd.DataFrame(spa_out, index=time_utc)
spa_df = pd.DataFrame(spa_out, index=time)

if raw_spa_output:
return spa_df
Expand Down