Skip to content

Commit 1d5650b

Browse files
authored
Allowing spa_c() to use localized time index 0.4.5 (#333)
* Allowing spa_c() to use localized time index * converting time to 'UTC' if time index is localized * Updating whatsnew file with changes * move note from one whatsnew to the other
1 parent 69d1bf3 commit 1d5650b

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

docs/sphinx/source/whatsnew/v0.4.5.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Bug fixes
99

1010
* Fix pandas 0.20 incompatibilities in Location.get_clearsky,
1111
solarposition.ephemeris (:issue:`325`)
12+
* Fixes timezone issue in solarposition spa_c function (:issue:`237`)
1213
* Added NREL Bird clear sky model. (:issue:`276`)
1314
* Added lower accuracy formulas for equation of time, declination, hour angle
1415
and solar zenith.
@@ -31,5 +32,6 @@ Contributors
3132
~~~~~~~~~~~~
3233

3334
* Will Holmgren
35+
* Marc Anoma
3436
* Mark Mikofski
3537
* Birgit Schachler

pvlib/solarposition.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,11 @@ def spa_c(time, latitude, longitude, pressure=101325, altitude=0,
182182

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

185-
time_utc = time
185+
# if localized, convert to UTC. otherwise, assume UTC.
186+
try:
187+
time_utc = time.tz_convert('UTC')
188+
except TypeError:
189+
time_utc = time
186190

187191
spa_out = []
188192

@@ -193,7 +197,7 @@ def spa_c(time, latitude, longitude, pressure=101325, altitude=0,
193197
hour=date.hour,
194198
minute=date.minute,
195199
second=date.second,
196-
timezone=0, # must input localized or utc time
200+
timezone=0, # date uses utc time
197201
latitude=latitude,
198202
longitude=longitude,
199203
elevation=altitude,
@@ -202,7 +206,7 @@ def spa_c(time, latitude, longitude, pressure=101325, altitude=0,
202206
delta_t=delta_t
203207
))
204208

205-
spa_df = pd.DataFrame(spa_out, index=time_utc)
209+
spa_df = pd.DataFrame(spa_out, index=time)
206210

207211
if raw_spa_output:
208212
return spa_df

0 commit comments

Comments
 (0)