Hi , I am having trouble successfully running the code. I want to calculate hourly wind turbine power generation. I am new to pySAM. Can anyone help me fix the code?
from datetime import timezone as dt_timezone
import PySAM.PySSC as pssc
import numpy as np
ssc = pssc.PySSC()
# Resource inputs for SAM model:
wfd = ssc.data_create()
ssc.data_set_number(wfd, 'lat'.encode('utf-8'), lat)
ssc.data_set_number(wfd, 'lon'.encode('utf-8'), lon)
# Assuming all_data has the columns 'Year', 'Month', 'Day', 'Hour', 'Minute'
ssc.data_set_array(wfd, 'year'.encode('utf-8'), all_data["Year"].values)
ssc.data_set_array(wfd, 'month'.encode('utf-8'), all_data["Month"].values)
ssc.data_set_array(wfd, 'day'.encode('utf-8'), all_data["Day"].values)
ssc.data_set_array(wfd, 'hour'.encode('utf-8'), all_data["Hour"].values)
ssc.data_set_array(wfd, 'minute'.encode('utf-8'), all_data["Minute"].values)
# Set wind turbine powercurve parameters
wind_turbine_powercurve_windspeeds = [ 0, 0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75, 2, 2.25, 2.5, 2.75, 3, 3.25, 3.5, 3.75, 4, 4.25, 4.5, 4.75, 5, 5.25, 5.5, 5.75, 6, 6.25, 6.5, 6.75, 7, 7.25, 7.5, 7.75, 8, 8.25, 8.5, 8.75, 9, 9.25, 9.5, 9.75, 10, 10.25, 10.5, 10.75, 11, 11.25, 11.5, 11.75, 12, 12.25, 12.5, 12.75, 13, 13.25, 13.5, 13.75, 14, 14.25, 14.5, 14.75, 15, 15.25, 15.5, 15.75, 16, 16.25, 16.5, 16.75, 17, 17.25, 17.5, 17.75, 18, 18.25, 18.5, 18.75, 19, 19.25, 19.5, 19.75, 20, 20.25, 20.5, 20.75, 21, 21.25, 21.5, 21.75, 22, 22.25, 22.5, 22.75, 23, 23.25, 23.5, 23.75, 24, 24.25, 24.5, 24.75, 25, 25.25, 25.5, 25.75, 26, 26.25, 26.5, 26.75, 27, 27.25, 27.5, 27.75, 28, 28.25, 28.5, 28.75, 29, 29.25, 29.5, 29.75, 30, 30.25, 30.5, 30.75, 31, 31.25, 31.5, 31.75, 32, 32.25, 32.5, 32.75, 33, 33.25, 33.5, 33.75, 34, 34.25, 34.5, 34.75, 35, 35.25, 35.5, 35.75, 36, 36.25, 36.5, 36.75, 37, 37.25, 37.5, 37.75, 38, 38.25, 38.5, 38.75, 39, 39.25, 39.5, 39.75, 40 ]
wind_turbine_powercurve_powerout = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21.32, 33.51, 45.69, 65.21, 79.83, 104.25, 128.66, 157.97, 187.27, 216.58, 250.78, 292.32, 333.85, 375.4, 426.72, 475.6, 534.27, 597.81, 656.49, 724.94, 798.29, 871.63, 940.08, 1010, 1060, 1130, 1190, 1240, 1290, 1330, 1370, 1390, 1410, 1430, 1440, 1460, 1470, 1475, 1480, 1485, 1490, 1495, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
ssc.data_set_array(wfd, 'wind_turbine_powercurve_windspeeds'.encode('utf-8'), wind_turbine_powercurve_windspeeds)
ssc.data_set_array(wfd, 'wind_turbine_powercurve_powerout'.encode('utf-8'), wind_turbine_powercurve_powerout)
# Set other parameters from all_data
ssc.data_set_array(wfd, 'temp'.encode('utf-8'), all_data.values)
ssc.data_set_array(wfd, 'pressure'.encode('utf-8'), all_data.values)
ssc.data_set_array(wfd, 'wind_direction'.encode('utf-8'), all_data.values)
ssc.data_set_array(wfd, 'wind_speed'.encode('utf-8'), all_data.values)
# Specify the system Configuration
ssc.data_set_number(dat, 'wind_resource_model_choice'.encode('utf-8'), 0)
ssc.data_set_number(dat, 'system_capacity'.encode('utf-8'), 15) # System capacity in MW
ssc.data_set_number(dat, 'wind_turbine_hub_ht'.encode('utf-8'), 100) # Hub height in meters
ssc.data_set_number(dat, 'wind_turbine_rotor_diameter'.encode('utf-8'), 100) # Rotor diameter in meters
ssc.data_set_number(dat, 'wind_resource_shear'.encode('utf-8'), 0.14) # Wind shear
# Create SAM compliant object
dat = ssc.data_create()
ssc.data_set_table(dat, 'wind_resource_data'.encode('utf-8'), wfd)
ssc.data_free(wfd)
# Execute and retrieve generation results
mod = ssc.module_create('Windpower'.encode('utf-8'))
ssc.module_exec(mod, dat)
# Retrieve generation data
gen_data = np.array(ssc.data_get_array(dat, 'wind.Outputs.gen'.encode('utf-8')))
# Assign generation data to all_data DataFrame
all_data = gen_data
# Free the memory
ssc.data_free(dat)
ssc.module_free(mod)
all_data