Skip to content

Commit

Permalink
Merge pull request #530 from NREL/fix_deprecations
Browse files Browse the repository at this point in the history
Fix deprecation warnings in PVLib and pandas.resample
  • Loading branch information
cdeline authored Aug 27, 2024
2 parents 290c923 + 83e9544 commit 7075a3a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
27 changes: 19 additions & 8 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 @@ -1174,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 @@ -1221,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
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 7075a3a

Please sign in to comment.