Wind turbine simulation

  • martinho
  • Topic Author
05 Jul 2023 13:18 #12277 by martinho
Wind turbine simulation was created by martinho
Hello, i,ve tried to make a code to simulate wind turbine but it doesn't working, the following message error display : Cell In[128], line 36, in <listcomp>(.0)
29 print(data_dict)
30 # Set the wind resource data
31 wind_turbine.Resource.wind_resource_data = {
32 'fields': ,
33 'heights': [0],
34 'val': [[float(data_dict[key][0])] for key in data_dict],
35 'perc': [[float(data_dict[key][1])] for key in data_dict],
---> 36 'sel_perc': [[float(data_dict[key][2])] for key in data_dict]
37 }
40 # Run the simulation
41 wind_turbine.execute()

IndexError: tuple index out of range
I don't know how to solve this problem.

Here is the code that i have made :

import PySAM.Windpower as wp
import csv

# Create a Windpower object
wind_turbine = wp.default("WindPowerSingleOwner")

# Set the turbine parameters
wind_turbine.system_capacity = 200  # Turbine capacity in kW
wind_turbine.max_cp = 0.45  # Maximum power coefficient
wind_turbine.max_tip_speed = 80  # Maximum tip speed in m/s
wind_turbine.cut_in_speed = 3  # Cut-in wind speed in m/s
wind_turbine.cut_out_speed = 25  # Cut-out wind speed in m/s

def csv_to_dict(file_path):
    result_dict = {}
    with open(file_path, 'r') as csvfile:
        reader = csv.DictReader(csvfile)
        for row in reader:
            key = row
            value = (row, row)
            result_dict[key] = value
    return result_dict

# Provide the file path to your CSV file
csv_file_path = 'C:/Users/arthu/AppData/Local/Packages/microsoft.windowscommunicationsapps_/LocalStat/Files/S0/5/Attachments/windSpeed[230584887].csv'

# Convert the CSV file to a dictionary
data_dict = csv_to_dict(csv_file_path)
# Set the wind resource data
wind_turbine.Resource.wind_resource_data = {
    'fields': ,
    'heights': [0],
    'val': [[float(data_dict[key][0])] for key in data_dict],
    'perc': [[float(data_dict[key][1])] for key in data_dict],
    'sel_perc': [[float(data_dict[key][2])] for key in data_dict]

# Run the simulation

# Access the wind turbine outputs
annual_energy = wind_turbine.Outputs.annual_energy

# Print the annual energy production
print("Annual Energy Production:", annual_energy, "kWh")

I am block and i will be very glad if someone can help me.
Good day to all

Please Log in or Create an account to join the conversation.

  • pgilman
07 Jul 2023 23:53 #12293 by pgilman
Replied by pgilman on topic Wind turbine simulation

I'm not sure if the square brackets in the path to the wind resource CSV file is causing problems. You might try a file without brackets in the name.

If that doesn't solve the problem and  you would like me to help troubleshoot, please attach a copy of the CSV file.

Best regards,

Please Log in or Create an account to join the conversation.

Moderators: pgilman
Powered by Kunena Forum