Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/NREL/main' into 502_sceneDict_bug
Browse files Browse the repository at this point in the history
  • Loading branch information
cdeline committed Aug 27, 2024
2 parents 7ea8133 + 7075a3a commit 07ba801
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 28 deletions.
62 changes: 35 additions & 27 deletions bifacial_radiance/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,9 @@ def _subhourlydatatoGencumskyformat(gencumskydata, label='right'):

#Resample to hourly. Gencumsky wants right-labeled data.
try:
gencumskydata = gencumskydata.resample('60T', closed='right', label='right').mean()
gencumskydata = gencumskydata.resample('60min', closed='right', label='right').mean()
except TypeError: # Pandas 2.0 error
gencumskydata = gencumskydata.resample('60T', closed='right', label='right').mean(numeric_only=True)
gencumskydata = gencumskydata.resample('60min', closed='right', label='right').mean(numeric_only=True)

if label == 'left': #switch from left to right labeled by adding an hour
gencumskydata.index = gencumskydata.index + pd.to_timedelta('1H')
Expand All @@ -294,7 +294,7 @@ def _subhourlydatatoGencumskyformat(gencumskydata, label='right'):
gencumskydata.loc[padend]=0
gencumskydata=gencumskydata.sort_index()
# Fill empty timestamps with zeros
gencumskydata = gencumskydata.resample('60T').asfreq().fillna(0)
gencumskydata = gencumskydata.resample('60min').asfreq().fillna(0)
# Mask leap year
leapmask = ~(_is_leap_and_29Feb(gencumskydata))
gencumskydata = gencumskydata[leapmask]
Expand Down Expand Up @@ -981,8 +981,7 @@ def _saveTempTMY(self, tmydata, filename=None, starttime=None, endtime=None,

if filename is None:
filename = 'temp.csv'



gencumskydata = None
gencumdict = None
if len(tmydata) == 8760:
Expand All @@ -991,24 +990,22 @@ def _saveTempTMY(self, tmydata, filename=None, starttime=None, endtime=None,
" temporary weather files in EPW folder.")
if coerce_year is None and starttime is not None:
coerce_year = starttime.year
# SILVANA: If user doesn't pass starttime, and doesn't select
# coerce_year, then do we really need to coerce it?
elif coerce_year is None:

elif coerce_year is None and len(tmydata.index[:-1].year.unique())>1:
coerce_year = 2021
print(f"Coercing year to {coerce_year}")
#with warnings.catch_warnings():
# warnings.simplefilter("ignore") # can't get rid of vectorized
#tmydata.index.values[:] = tmydata.index[:] + pd.DateOffset(year=(coerce_year))
#tmydata.index.values[-1] = tmydata.index[-1] + pd.DateOffset(year=(coerce_year+1))
tz = tmydata.index.tz
year_vector = np.full(shape=tmydata.__len__(), fill_value=coerce_year)
year_vector[-1] = coerce_year+1
tmydata.index = pd.to_datetime({
'year': year_vector,
'month': tmydata.index.month,
'day': tmydata.index.day,
'hour': tmydata.index.hour})
tmydata = tmydata.tz_localize(tz)

if coerce_year:
print(f"Coercing year to {coerce_year}")
tz = tmydata.index.tz
year_vector = np.full(shape=len(tmydata), fill_value=coerce_year)
year_vector[-1] = coerce_year+1
tmydata.index = pd.to_datetime({
'year': year_vector,
'month': tmydata.index.month,
'day': tmydata.index.day,
'hour': tmydata.index.hour})

tmydata = tmydata.tz_localize(tz)



Expand Down Expand Up @@ -1177,16 +1174,27 @@ def _convertTMYdate(data, meta):


import pvlib

#(tmydata, metadata) = pvlib.tmy.readtmy3(filename=tmyfile) #pvlib<=0.6
(tmydata, metadata) = pvlib.iotools.tmy.read_tmy3(filename=tmyfile,
coerce_year=coerce_year)
try:
(tmydata, metadata) = pvlib.iotools.tmy.read_tmy3(filename=tmyfile,
coerce_year=coerce_year,
map_variables=True)
except TypeError: # pvlib < 0.10
(tmydata, metadata) = pvlib.iotools.tmy.read_tmy3(filename=tmyfile,
coerce_year=coerce_year)

try:
tmydata = _convertTMYdate(tmydata, metadata)
except KeyError:
print('PVLib >= 0.8.0 is required for sub-hourly data input')


tmydata.rename(columns={'dni':'DNI',
'dhi':'DHI',
'temp_air':'DryBulb',
'wind_speed':'Wspd',
'ghi':'GHI',
'albedo':'Alb'
}, inplace=True) #as of v0.11, PVLib changed tmy3 column names..

return tmydata, metadata

Expand Down Expand Up @@ -1224,7 +1232,7 @@ def _readEPW(self, epwfile=None, label = 'right', coerce_year=None):
#(tmydata, metadata) = readepw(epwfile) #
(tmydata, metadata) = pvlib.iotools.epw.read_epw(epwfile,
coerce_year=coerce_year) #pvlib>0.6.1
#pvlib uses -1hr offset that needs to be un-done. Why did they do this?
#pvlib uses -1hr offset that needs to be un-done.
tmydata.index = tmydata.index+pd.Timedelta(hours=1)

# rename different field parameters to match output from
Expand Down
1 change: 1 addition & 0 deletions docs/sphinx/source/whatsnew/pending.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Bug fixes
* Updated Github Actions to make Coveralls fail silently if it has an internal server error (:pull:`517`)
* Fix PerformanceWarning and SettingWithCopyWarning (:issue:`515`)
* Switch from Versioneer to setuptools_scm (:pull:`522`)
* Enable `coerce_year`=None if the TMYfile is all the same year (:issue:`526`)

Documentation
~~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ coverage==7.2.1
cycler==0.11.0
idna==3.4
importlib-metadata==6.0.0
ipython==8.10.0
ipython==8.13.0
kiwisolver==1.4.4
matplotlib==3.5.1
more-itertools==9.1.0
Expand Down

0 comments on commit 07ba801

Please sign in to comment.