Skip to content

Commit

Permalink
utc localize
Browse files Browse the repository at this point in the history
  • Loading branch information
shirubana committed Apr 5, 2023
1 parent 7e49217 commit a9d31a0
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion bifacial_radiance/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,8 @@ def _tz_convert(metdata, metadata, tz_convert_val):

def NSRDBWeatherData(self, metadata, metdata, starttime=None,
endtime=None,
coerce_year=None, label='center'):
coerce_year=None, label='center',
tz_convert_val=None):
"""
To be used when working with dataframes from the NSRDB h5 (i.e. Eagle)
Assigns the metdata and weatherdata from a dataframe and dictonary
Expand All @@ -983,6 +984,23 @@ def NSRDBWeatherData(self, metadata, metdata, starttime=None,
Note: Labeling to center because NSRDB data is passed on the 30min mark
"""
def _tz_convert(metdata, metadata, tz_convert_val):
"""
convert metdata to a different local timzone. Particularly for
SolarGIS weather files which are returned in UTC by default.
----------
tz_convert_val : int
Convert timezone to this fixed value, following ISO standard
(negative values indicating West of UTC.)
Returns: metdata, metadata
"""
import pytz
if (type(tz_convert_val) == int) | (type(tz_convert_val) == float):
metadata['TZ'] = tz_convert_val
metdata = metdata.tz_convert(pytz.FixedOffset(tz_convert_val*60))
return metdata, metadata
# end _tz_convert

def _parseTimes(t, hour, coerce_year):
'''
parse time input t which could be string mm_dd_HH or YYYY-mm-dd_HHMM
Expand Down Expand Up @@ -1032,6 +1050,8 @@ def _parseTimes(t, hour, coerce_year):
return t_out, coerce_year
# end _parseTimes



metadata['TZ'] = metadata['timezone']
metadata['Name'] = metadata['county']
metadata['altitude'] = metadata['elevation']
Expand All @@ -1046,6 +1066,9 @@ def _parseTimes(t, hour, coerce_year):
'surface_albedo': 'Alb'
}, inplace=True)

metdata, metadata = _tz_convert(metdata, metadata, metadata['TZ'])
tzinfo = metdata.index.tzinfo

tempMetDatatitle = 'metdata_temp.csv'

# Parse the start and endtime strings.
Expand Down

0 comments on commit a9d31a0

Please sign in to comment.