I’m getting different results in SAM and PySAM. This is a nexample for Pvwattsv8 with my own custom weather file. I only changed in SAM the system capacity to 100 MW, I generate the code to PySAM JSON and import it in Python. This works fine, with minor differences.
PySAM results
----------------------
PV capacity: 100.0 MW
PV power: 186,487,766 kWh
PV capacity factor: 21.3 %
PV LCOE nominal: 4.9 c$/kWh
But when I change the system_capacity to 500 MW, I get quite different values for the LCOE nominal.
PySAM results
----------------------
PV capacity: 500.0 MW
PV power: 932,435,679 kWh
PV capacity factor: 21.3 %
PV LCOE nominal: 2.01 c$/kWh
This is the Python code.
import json
import PySAM.Grid as Grid
import PySAM.Pvwattsv8 as Pvwattsv8
import PySAM.Singleowner as Singleowner
import PySAM.Utilityrate5 as UtilityRate
def execute_modules(modules):
for m in modules:
m.execute()
def load_modules(path, file_names, modules, execute=False):
for f, m in zip(file_names, modules):
with open(f'{path}/{f}.json', 'r') as file:
data = json.load(file)
for k, v in data.items():
if k != "number_inputs":
m.value(k, v)
if execute:
execute_modules(modules)
def load_pv(path, file_names, execute=True) -> [Pvwattsv8, Grid, UtilityRate, Singleowner]:
pv = Pvwattsv8.new()
pv_grid = Grid.from_existing(pv)
pv_ur = UtilityRate.from_existing(pv)
pv_so = Singleowner.from_existing(pv)
modules = [pv, pv_grid, pv_ur, pv_so]
load_modules(path, file_names, modules, execute)
return modules
if __name__ == '__main__':
# PySAM JSON path and files
pv_path = '/home/javi/Documents/PycharmProjects/IDA_2023/data/PV_watt_json'
pv_file_names = ['untitled_pvwattsv8', 'untitled_grid', 'untitled_utilityrate5', 'untitled_singleowner']
# Load PV modules, execute and show results
[pv, pv_grid, pv_ur, pv_so] = load_pv(pv_path, pv_file_names)
print(f'PV capacity: {pv.value("system_capacity")/1000:,} MW')
print(f'PV power: {round(sum(pv.Outputs.gen)):,} kWh')
print(f'PV capacity factor: {round(pv.Outputs.capacity_factor, 1)} %')
print(f'PV LCOE nominal: {round(pv_so.Outputs.lcoe_nom, 2)} c$/kWh')
print('\n')
# Change capacity
capacity = 500 * 1000 # kW
pv.value('system_capacity', capacity)
# Execute and show results
execute_modules([pv, pv_grid, pv_ur, pv_so])
print(f'PV capacity: {pv.value("system_capacity")/1000:,} MW')
print(f'PV power: {round(sum(pv.Outputs.gen)):,} kWh')
print(f'PV capacity factor: {round(pv.Outputs.capacity_factor, 1)} %')
print(f'PV LCOE nominal: {round(pv_so.Outputs.lcoe_nom, 2)} c$/kWh')