- Posts: 19
LCOE Output from pySAM iteration different from SAM GUI
- galla1ab
- Topic Author
Less
More
18 Aug 2022 17:19 #11357
by galla1ab
LCOE Output from pySAM iteration different from SAM GUI was created by galla1ab
Hello,
I am running pvwatts8 using pySAM for multiple locations in my study area. I've run into an issue where the LCOE output does not reflect the output when running the same location and system size in the GUI of SAM. Below is the code I am using, picking just one location the weather file used is for 41.712 latitude and -72.358 longitude. The code below returns a LCOE of 74.42 cents per kWh where as the GUI of SAM returns 7.29 cents per kWh. The system nameplate kWdc capacity is 3338 with a grc of 0.37. Any help understanding this discrepancy is much appreciated.
Adam
Code:
import PySAM.Pvwattsv8 as pv
import PySAM.Singleowner as so
import PySAM.ResourceTools as tools
import csv
import pandas as pd
kW_filename = open('C:/Dissertation/Chapter_1_SolarSiting/Data/CT_Data/Parcel_Analysis/Results/Version_1/Test.csv', 'r')
file = csv.DictReader(kW_filename)
Kw_list = []
weather_files = []
acres = []
#Solar_ID = []
for col in file:
Kw_list.append(col)
weather_files.append(col)
acres.append(col)
#Solar_ID.append(col)
print('System Capacity (kW):', Kw_list)
print('weather file name:', weather_files)
print('Total parcel acres:', acres)
i = 0
capacity_factor_list = []
annual_energy_list = []
Example_PPA_list = []
Levelized_cost_list = []
lat_list = []
lon_list = []
for kW in Kw_list:
pvSingleOwner_model = pv.default("PVWattsSingleOwner")
financial_model = so.from_existing(pvSingleOwner_model, 'PVWattsSingleOwner')
pvSingleOwner_model.value("system_capacity", float(kW))
pvSingleOwner_model.value("gcr", 0.37)
pvSingleOwner_model.value("array_type", 0)
weather_path = "C:/Users/adam.gallaher/SAM Downloaded Weather Files/%s" % weather_files
weather_data = tools.SAM_CSV_to_solar_data(weather_path)
pvSingleOwner_model.SolarResource.solar_resource_data = weather_data
i = i + 1
pvSingleOwner_model.execute(0)
financial_model.execute(0)
capacity_factor = pvSingleOwner_model.Outputs.capacity_factor
capacity_factor_list.append(capacity_factor)
print(capacity_factor)
annual_energy = pvSingleOwner_model.Outputs.annual_energy
annual_energy_list.append(annual_energy)
print(annual_energy)
Example_PPA = financial_model.Outputs.ppa
Example_PPA_list.append(Example_PPA)
print(Example_PPA)
Levelized_cost = financial_model.Outputs.lcoe_real
Levelized_cost_list.append(Levelized_cost)
print(Levelized_cost)
lat = pvSingleOwner_model.Outputs.lat
lat_list.append(lat)
print(lat)
long = pvSingleOwner_model.Outputs.lon
lon_list.append(long)
print(long)
dictionary = {'Capacity Factor': capacity_factor_list, 'Annual Energy Output (kWh)': annual_energy_list, 'Example PPA (cents/kWh)': Example_PPA_list,
'LCOE (cents/kWh)': Levelized_cost_list, 'Latitude': lat_list, 'Longitude': lon_list, 'weather_files': weather_files, 'Acres': acres, 'kW': Kw_list,}
dataframe = pd.DataFrame(dictionary)
dataframe.to_csv('C:/Dissertation/Chapter_1_SolarSiting/Data/CT_Data/Parcel_Analysis/Results/Version_1/Test_Output.csv')
I am running pvwatts8 using pySAM for multiple locations in my study area. I've run into an issue where the LCOE output does not reflect the output when running the same location and system size in the GUI of SAM. Below is the code I am using, picking just one location the weather file used is for 41.712 latitude and -72.358 longitude. The code below returns a LCOE of 74.42 cents per kWh where as the GUI of SAM returns 7.29 cents per kWh. The system nameplate kWdc capacity is 3338 with a grc of 0.37. Any help understanding this discrepancy is much appreciated.
Adam
Code:
import PySAM.Pvwattsv8 as pv
import PySAM.Singleowner as so
import PySAM.ResourceTools as tools
import csv
import pandas as pd
kW_filename = open('C:/Dissertation/Chapter_1_SolarSiting/Data/CT_Data/Parcel_Analysis/Results/Version_1/Test.csv', 'r')
file = csv.DictReader(kW_filename)
Kw_list = []
weather_files = []
acres = []
#Solar_ID = []
for col in file:
Kw_list.append(col)
weather_files.append(col)
acres.append(col)
#Solar_ID.append(col)
print('System Capacity (kW):', Kw_list)
print('weather file name:', weather_files)
print('Total parcel acres:', acres)
i = 0
capacity_factor_list = []
annual_energy_list = []
Example_PPA_list = []
Levelized_cost_list = []
lat_list = []
lon_list = []
for kW in Kw_list:
pvSingleOwner_model = pv.default("PVWattsSingleOwner")
financial_model = so.from_existing(pvSingleOwner_model, 'PVWattsSingleOwner')
pvSingleOwner_model.value("system_capacity", float(kW))
pvSingleOwner_model.value("gcr", 0.37)
pvSingleOwner_model.value("array_type", 0)
weather_path = "C:/Users/adam.gallaher/SAM Downloaded Weather Files/%s" % weather_files
weather_data = tools.SAM_CSV_to_solar_data(weather_path)
pvSingleOwner_model.SolarResource.solar_resource_data = weather_data
i = i + 1
pvSingleOwner_model.execute(0)
financial_model.execute(0)
capacity_factor = pvSingleOwner_model.Outputs.capacity_factor
capacity_factor_list.append(capacity_factor)
print(capacity_factor)
annual_energy = pvSingleOwner_model.Outputs.annual_energy
annual_energy_list.append(annual_energy)
print(annual_energy)
Example_PPA = financial_model.Outputs.ppa
Example_PPA_list.append(Example_PPA)
print(Example_PPA)
Levelized_cost = financial_model.Outputs.lcoe_real
Levelized_cost_list.append(Levelized_cost)
print(Levelized_cost)
lat = pvSingleOwner_model.Outputs.lat
lat_list.append(lat)
print(lat)
long = pvSingleOwner_model.Outputs.lon
lon_list.append(long)
print(long)
dictionary = {'Capacity Factor': capacity_factor_list, 'Annual Energy Output (kWh)': annual_energy_list, 'Example PPA (cents/kWh)': Example_PPA_list,
'LCOE (cents/kWh)': Levelized_cost_list, 'Latitude': lat_list, 'Longitude': lon_list, 'weather_files': weather_files, 'Acres': acres, 'kW': Kw_list,}
dataframe = pd.DataFrame(dictionary)
dataframe.to_csv('C:/Dissertation/Chapter_1_SolarSiting/Data/CT_Data/Parcel_Analysis/Results/Version_1/Test_Output.csv')
Please Log in or Create an account to join the conversation.
- pgilman
Less
More
- Posts: 5447
19 Aug 2022 10:47 #11359
by pgilman
Replied by pgilman on topic LCOE Output from pySAM iteration different from SAM GUI
Hi Adam,
The most likely cause is that the inputs in your .sam file are different from the inputs your Python code is setting.
If you would like me to help troubleshoot, please attach a copy of the .sam file you are using for this comparison and a copy of the weather file you are using.
Best regards,
Paul.
The most likely cause is that the inputs in your .sam file are different from the inputs your Python code is setting.
If you would like me to help troubleshoot, please attach a copy of the .sam file you are using for this comparison and a copy of the weather file you are using.
Best regards,
Paul.
Please Log in or Create an account to join the conversation.
- galla1ab
- Topic Author
Less
More
- Posts: 19
19 Aug 2022 15:16 #11369
by galla1ab
Replied by galla1ab on topic LCOE Output from pySAM iteration different from SAM GUI
Hello Paul,
Thank you for getting back to me. When I first ran SAM against pySAM I only adjust the same parameters so they should be identical as I mostly rely on the default values however there could be a discrepancy I am unaware of. Attached are the two .SAM files that I used for a test and the associated weather file. Thank you again for providing assistance with this.
I've also included the csv I use as inputs for my pySAM code.
Thank you,
Adam
Thank you for getting back to me. When I first ran SAM against pySAM I only adjust the same parameters so they should be identical as I mostly rely on the default values however there could be a discrepancy I am unaware of. Attached are the two .SAM files that I used for a test and the associated weather file. Thank you again for providing assistance with this.
I've also included the csv I use as inputs for my pySAM code.
Thank you,
Adam
Attachments:
Please Log in or Create an account to join the conversation.
- pgilman
Less
More
- Posts: 5447
19 Aug 2022 15:45 #11370
by pgilman
Replied by pgilman on topic LCOE Output from pySAM iteration different from SAM GUI
Hi Adam,
Can you send your python code as a text file with the correct indentation, and please test it to make sure it works? The code in your original email runs with an error about the argument to float() after I tried to fix the indentation as best I could:
Best regards,
Paul.
Can you send your python code as a text file with the correct indentation, and please test it to make sure it works? The code in your original email runs with an error about the argument to float() after I tried to fix the indentation as best I could:
Code:
pvSingleOwner_model.value("system_capacity", float(kW))
TypeError: float() argument must be a string or a number, not 'dict'
Best regards,
Paul.
Please Log in or Create an account to join the conversation.
- galla1ab
- Topic Author
Less
More
- Posts: 19
19 Aug 2022 15:51 #11371
by galla1ab
Replied by galla1ab on topic LCOE Output from pySAM iteration different from SAM GUI
Hello Paul,
Sorry about that. Attached is my .py file and a .txt file of the code. I hope that helps.
Thank you,
Adam
Sorry about that. Attached is my .py file and a .txt file of the code. I hope that helps.
Thank you,
Adam
Attachments:
Please Log in or Create an account to join the conversation.
- pgilman
Less
More
- Posts: 5447
22 Aug 2022 10:34 - 22 Aug 2022 10:35 #11374
by pgilman
Replied by pgilman on topic LCOE Output from pySAM iteration different from SAM GUI
Hi Adam,
There is a difference somewhere in the default input values for the Single Owner financial model between PySAM and SAM. The PySAM and SAM defaults are stored in different files, so it is possible that the current PySAM defaults are for an older version of SAM. We will try to track that down and fix it.
The best way to ensure you get the same results from SAM and PySAM is to export the input data from a SAM file to "JSON for PySAM " and then import the JSON data into PySAM. That gives you better control over the PySAM input data than relying on the defaults. Those steps are described in the PySAM documentation here: nrel-pysam.readthedocs.io/en/master/Import.html .
I did that for your Test_SAM_1.sam file and use the attached Python script to verify that the results from SAM and PySAM are the same. The NPV metric is a better metric than PPA price for testing the financial model because by default the PPA price is an input set on the Financial Paramters page:
Here are the steps I followed:
Best regards,
Paul.
There is a difference somewhere in the default input values for the Single Owner financial model between PySAM and SAM. The PySAM and SAM defaults are stored in different files, so it is possible that the current PySAM defaults are for an older version of SAM. We will try to track that down and fix it.
The best way to ensure you get the same results from SAM and PySAM is to export the input data from a SAM file to "JSON for PySAM " and then import the JSON data into PySAM. That gives you better control over the PySAM input data than relying on the defaults. Those steps are described in the PySAM documentation here: nrel-pysam.readthedocs.io/en/master/Import.html .
I did that for your Test_SAM_1.sam file and use the attached Python script to verify that the results from SAM and PySAM are the same. The NPV metric is a better metric than PPA price for testing the financial model because by default the PPA price is an input set on the Financial Paramters page:
Here are the steps I followed:
- Start SAM and open the Test_SAM_1.sam file.
- On the Case menu, click Generate Code and choose PySAM JSON (at the bottom of the list of options). I saved the files in a folder named "case 1".
- Run the attached pvwattsv8-single-owner-from-sam.py script.
Best regards,
Paul.
Attachments:
Last edit: 22 Aug 2022 10:35 by pgilman.
Please Log in or Create an account to join the conversation.
Moderators: pgilman