Reputation: 1
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 text
import PySAM.Windpower as wp
your text
import csv
your text
# Create a Windpower object
your text
wind_turbine = wp.default("WindPowerSingleOwner")
your text
# Set the turbine parameters
your text
wind_turbine.system_capacity = 200 # Turbine capacity in kW
your text
wind_turbine.max_cp = 0.45 # Maximum power coefficient
your text
wind_turbine.max_tip_speed = 80 # Maximum tip speed in m/s
your text
wind_turbine.cut_in_speed = 3 # Cut-in wind speed in m/s
your text
wind_turbine.cut_out_speed = 25 # Cut-out wind speed in m/s
your text
def 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 text
csv_file_path = 'C:/Users/arthu/OneDrive/Documents/INTERNSHIP/SAM/05-07-your text
2023/windSpeed.csv'
your text
# Convert the CSV file to a dictionary
your text
data_dict = csv_to_dict(csv_file_path)
your text
print(data_dict)
#Set the wind resource data
your text
wind_turbine.Resource.wind_resource_data = {
'fields': ['wind_speed', 'perc', 'sel_perc'], # Field names representing wind your text
speed, 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 text
list
'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 text
list
your text
}
your text
wind_turbine.execute()
your text
annual_energy = wind_turbine.Outputs.annual_energy
your text
print("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
Upvotes: 0
Views: 61
Reputation: 425
You are using dict instead of dict.keys!
Try using this instead of the wind_turbine.resource.wind_resource_data you're setting:
wind_turbine.Resource.wind_resource_data = {
'fields': ['wind_speed', 'perc', 'sel_perc'], # Field names representing wind speed, perc, and sel_perc
'heights': [0], # Single height value since we have only one field
'wind_speed': [[float(key)] for key in data_dict.keys()], # Wind speeds as a nested list
'perc': [[data_dict[key][0]] for key in data_dict.keys()], # Perc as a nested list
'sel_perc': [[data_dict[key][1]] for key in data_dict.keys()] # Sel_perc as a nested list
}
Upvotes: 0