Unable to create power curves using pySAM with outputs from rex
Closed this issue · 10 comments
NOTE: The actual problem is in pySAM/SAM but I wanted to start the conversation here to see if there is a recommended workaround or alternative.
Bug Description
I'm using WindX.get_SAM_lat_lon()
to generate a CSV file to use with pySAM
, being sure to set the out_path
parameter to add the metadata on the first line of the output file. With out_path
I see something like this:
Header:
Location ID | Latitude | Longitude | Country | State | County | Time Zone | Elevation | Offshore | Version |
---|---|---|---|---|---|---|---|---|---|
29833 | 40.40789 | -73.4505 | United States | None | None | -5 | 0 | 1 | v1.0.0 |
Followed by:
Year | Month | Day | Hour | Pressure | Temperature | Direction | Speed |
---|---|---|---|---|---|---|---|
2019 | 1 | 1 | 0 | 0.982206 | 11.52 | 228.38 | 17.77 |
2019 | 1 | 1 | 1 | 0.98037 | 12.23 | 221.76 | 19.18 |
2019 | 1 | 1 | 2 | 0.978593 | 12.05 | 212.86 | 23.19 |
When this file gets loaded by pySAM I am encountering an error that it isn't able to load the weather file because it can't find the year.
Full Traceback
windpower execution error.
exec fail(windpower): failed to read local weather file: test.csv error reading data column type specifier in col 1 of 8: 'year' len: 4
I renamed the extension to .srw
to test running it with the SAM GUI and encountered the same error, with persistent popups stating: "Could not check hub height compared to resource height. This may indicate a problem with you weather file."
Code Sample
# rex
with rex.WindX('/nrel/wtk/mid_atlantic/Mid_Atlantic_2019.h5', hsds=True, hsds_kwargs={'bucket': 'nrel-pds-hsds'}) as f:
f.get_SAM_lat_lon(lat_lon=(40.407887, -73.45053), hub_height=120, out_path='test.csv', require_wind_dir=True)
# pySAM
generator = wp.default('WindPowerNone')
generator.Resource.assign({'wind_resource_model_choice': 0})
generator.Resource.assign({'wind_resource_filename': 'test.csv'})
# assign other parameters
generator.execute() # <--- error here
To Reproduce
See notes above.
Expected behavior
- have rex output a compliant CSV/SRW file
- update SAM to recognize the alternate CSV/SRW format
Screenshots
N/A
System (please complete the following information):
- Windows 10
- rex version 0.2.64
- pySAM version 2.2.4
Additional context
N/A
Charge code
N/A
@mike-welch, damn, looks like SAM changed something as this was working. I'll reach out to them and update the format as needed. Keep you posted!
@mike-welch can you attach the resource csv you're trying to use?
@mike-welch can you attach the resource csv you're trying to use?
Here you go: test.csv
Just pinging to see if there are any updates.
I didn't mention this above, but I wrote a function to convert from the output CSV to an SRW file... 🤷
def CSV_to_SRW(df, year, latitude, longitude):
if len(df) != 8760:
raise ValueError(f'Dataframe must have 8760 rows, not {len(df)}!')
# Create dataframe and set headers
srw = pd.DataFrame(index=range(8765),columns=range(10))
srw.iloc[0, :] = ['', 'city??', 'state??', 'USA', year, latitude, longitude, 'elevation??', '-5', 8760]
srw.iloc[1, 0] = 'WTK .csv converted to .srw for SAM'
srw.iloc[2:5, :4] = [
['temperature', 'pressure', 'direction', 'speed'],
['C', 'atm', 'degres', 'm/s'],
['100', '100', '100', '100'],
]
# Add data
srw.iloc[5:, 0] = df['Temperature']
srw.iloc[5:, 1] = df['Pressure']
srw.iloc[5:, 2].fillna('0', inplace=True) # TODO: wind direction
srw.iloc[5:, 3] = df['Speed']
return srw.fillna('')
@mike-welch thanks for the nudge. We haven't had any luck reproducing on our end but will keep digging.
Regarding the above. Are you passing the SRW file to SAM or the .csv? Do either work or do both fail?
@mike-welch, while we try to debug this, have you considered using reV to compute the CF profiles?
https://nrel.github.io/reV/misc/examples.running_locally.html
I noticed that in your example your running PySAM instead of the SAM Application. reV wraps PySAM with rex to allow for computing CF-profiles for multiple locations at the same time.
🤔 I'll have to check that out...
The important piece for the work we're doing is creation of the 8760 power outputs, hence the linkage with SAM/PySAM. It looks like I can do the same with reV, which is good news. Please correct me there if I am wrong... (In generation.json I see clipped power
which I think would work for wind and dc
/ac
for solar.)
@mike-welch, FYI, I've got a fix implemented here: #113
I'll let you know when we merge and release it. It was not a straight forward fix as it appears the WindPower module has different file formatting requirements than PV...
Thank you for the updated version @MRossol. 🙏
Once I remembered to use out_path
things started to work! I'm writing a CSV, renaming it to an SRW, and am then able to use it with the SAM desktop app and PySAM
without any issues.