I'm tring to make a code to simulation a wind turbine but it doesn't work, the error message that diplay said me that there is a worst tuple in my dictionnary but i've verified that several times but ther is no error. I need help.
Here is the code that i'm tring to execute :
your textimport PySAM.Windpower as wp
your textimport csv
your text# Create a Windpower object
your textwind_turbine = wp.default("WindPowerSingleOwner")
your text# Set the turbine parameters
your textwind_turbine.system_capacity = 200 # Turbine capacity in kW
your textwind_turbine.max_cp = 0.45 # Maximum power coefficient
your textwind_turbine.max_tip_speed = 80 # Maximum tip speed in m/s
your textwind_turbine.cut_in_speed = 3 # Cut-in wind speed in m/s
your textwind_turbine.cut_out_speed = 25 # Cut-out wind speed in m/s
your textdef csv_to_dict(file_path):
result_dict = {}
with open(file_path, 'r') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
val = float(row['val'])
perc = float(row['perc'])
sel_perc = float(row['sel_perc'])
result_dict[val] = (perc, sel_perc)
return result_dict
your text# Provide the file path to your CSV file
your textcsv_file_path = 'C:/Users/arthu/OneDrive/Documents/INTERNSHIP/SAM/05-07-your text2023/windSpeed.csv'
your text# Convert the CSV file to a dictionary
your textdata_dict = csv_to_dict(csv_file_path)
your textprint(data_dict)
#Set the wind resource data
your textwind_turbine.Resource.wind_resource_data = {
'fields': ['wind_speed', 'perc', 'sel_perc'], # Field names representing wind your textspeed, perc, and sel_perc
'heights': [0], # Single height value since we have only one field
'wind_speed': [[float(key)] for key in data_dict], # Wind speeds as a nested your textlist
'perc': [[data_dict[key][0]] for key in data_dict], # Perc as a nested list
'sel_perc': [[data_dict[key][1]] for key in data_dict] # Sel_perc as a nested your textlist
your text}
Run the simulation
your textwind_turbine.execute()
Access the wind turbine outputs
your textannual_energy = wind_turbine.Outputs.annual_energy
Print the annual energy production
your textprint("Annual Energy Production:", annual_energy, "kWh")*
When i execute this above code, it disply the following message error :
Cell In[25], line 32 30 print(data_dict) 31 #Set the wind resource data ---> 32 wind_turbine.Resource.wind_resource_data = { 33 'fields': ['wind_speed', 'perc', 'sel_perc'], # Field names representing wind speed, perc, and sel_perc 34 'heights': [0], # Single height value since we have only one field 35 'wind_speed': [[float(key)] for key in data_dict], # Wind speeds as a nested list 36 'perc': [[data_dict[key][0]] for key in data_dict], # Perc as a nested list 37 'sel_perc': [[data_dict[key][1]] for key in data_dict] # Sel_perc as a nested list 38 } 40 # Run the simulation 41 wind_turbine.execute()
Exception: Error (-4) converting nested tuple 0 into row in matrix.
I will be very glad if someone could help me
I've decribed my problem in the previous content
You are using dict instead of dict.keys!
Try using this instead of the wind_turbine.resource.wind_resource_data you're setting: