From 0e8715de891f1f00f4eab68277bccda276e4b7b9 Mon Sep 17 00:00:00 2001 From: Marc Anoma Date: Thu, 2 Feb 2017 11:36:37 -0800 Subject: [PATCH 1/2] Allowing spa_c() to use localized time index * converting time to 'UTC' if time index is localized --- pvlib/solarposition.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pvlib/solarposition.py b/pvlib/solarposition.py index 7b9690a69d..1b80393dbf 100644 --- a/pvlib/solarposition.py +++ b/pvlib/solarposition.py @@ -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 = [] @@ -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, @@ -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 From c8cef3fb21b0c7026ada08f0d649f8c77fac7b10 Mon Sep 17 00:00:00 2001 From: Marc Anoma Date: Thu, 2 Feb 2017 11:48:33 -0800 Subject: [PATCH 2/2] Updating whatsnew file with changes --- docs/sphinx/source/whatsnew/v0.4.4.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/sphinx/source/whatsnew/v0.4.4.txt b/docs/sphinx/source/whatsnew/v0.4.4.txt index 48ff7da142..0f3d8d8fd6 100644 --- a/docs/sphinx/source/whatsnew/v0.4.4.txt +++ b/docs/sphinx/source/whatsnew/v0.4.4.txt @@ -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 \ No newline at end of file