8000 sam iotools #1371 by shirubana · Pull Request #1556 · pvlib/pvlib-python · GitHub
[go: up one dir, main page]

Skip to content

sam iotools #1371 #1556

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
loop data
addresses data looping when data goes from example June one year to May the next one.
  • Loading branch information
shirubana committed Oct 14, 2022
commit 492e3738e80032bd6dc9362e6dda314e4b373038
25 changes: 16 additions & 9 deletions pvlib/iotools/sam.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,19 @@ def _fillYearSAMStyle(df, freq='60T'):
23, 60-int(freq[:-1]))
).tz_localize(tzinfo)

df2 = _averageSAMStyle(df, freq)
df2.iloc[0] = 0 # set first datapt to zero to forward fill w zeros
df2.iloc[-1] = 0 # set last datapt to zero to forward fill w zeros
df2.loc[starttime] = 0
df2.loc[endtime] = 0
df2 = df2.resample(freq).ffill()
return df2
df.iloc[0] = 0 # set first datapt to zero to forward fill w zeros
df.iloc[-1] = 0 # set last datapt to zero to forward fill w zeros
df.loc[starttime] = 0
df.loc[endtime] = 0
df = df.resample(freq).ffill()
return df

# Modify this to cut into different years. Right now handles partial year
# and sub-hourly interval.
if standardSAM:
data = _averageSAMStyle(data, '60T')
filterdatesLeapYear = ~(_is_leap_and_29Feb(data))
data = data[filterdatesLeapYear]
data = _fillYearSAMStyle(data)

# metadata
latitude = metadata['latitude']
Expand Down Expand Up @@ -134,15 +133,23 @@ def _fillYearSAMStyle(df, freq='60T'):
if 'wdir' in data:
savedata['wdir'] = data.wdir.values

savedata = savedata.sort_values(by=['Month','Day','Hour'])

if 'albedo' in data:
savedata['Albedo'] = data.albedo.values

# Not elegant but seems to work for the standardSAM format
if standardSAM and len(data) < 8760:
savedata = _fillYearSAMStyle(savedata)

# Not elegant but seems to work for the standardSAM format
if 'Albedo' in savedata:
if standardSAM and savedata.Albedo.iloc[0] == 0:
savedata.loc[savedata.index[0], 'Albedo'] = savedata.loc[
savedata.index[1]]['Albedo']
savedata.loc[savedata.index[-1], 'Albedo'] = savedata.loc[
savedata.index[-2]]['Albedo']
savedata['Albedo'] = savedata['Albedo'].fillna(0.99).clip(lower=0.01,
upper=0.99)

with open(savefile, 'w', newline='') as ict:
# Write the header lines, including the index variable for
Expand Down
0