Enhance SAM with features tailored to your specific needs! We collaborate with companies, universities, and organizations to privately fund new capabilities or analyses. Your investment drives innovation while benefiting the broader energy community. Email us to learn more.

Converting nestle tuple 0 into row in matrix

  • Martineau
  • Topic Author
More
10 Jul 2023 00:55 #12298 by Martineau
Hello everyone, 
I'm trying to make a code to simulate wind turbine with PySAM, but I have a problem, I can't execute the code. 

Here is the code that i've 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:
            val = float(row)
            try:
                perc = float(row)
            except ValueError:
                perc = None
            try:
                sel_perc = float(row)
            except ValueError:
                sel_perc = None
            result_dict[val] = (perc, sel_perc)
    return result_dict

# Provide the file path to your CSV file
csv_file_path = 'C:/Users/arthu/OneDrive/Documents/INTERNSHIP/SAM/05-07-2023/windSpeed.csv'

# Convert the CSV file to a dictionary
data_dict = csv_to_dict(csv_file_path)

# Print the values of data_dict
for key, value in data_dict.items():
    print(f"Key: {key}, Value: {value}")

# Construct the wind resource data dictionary
wind_resource_data = {
    'fields': ,
    'heights': [0],
    'val': [key for key in data_dict.keys()],
    'perc': [data_dict[key][0] for key in data_dict.keys() if data_dict[key][0] is not None],
    'sel_perc': [data_dict[key][1] for key in data_dict.keys() if data_dict[key][1] is not None]
}

# Print the wind resource data dictionary
print("Wind Resource Data:")
print(wind_resource_data)

# Set the wind resource data
wind_turbine.Resource.wind_resource_data = wind_resource_data

# Run the simulation
wind_turbine.execute()

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

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

When I execute this program, it display the error message : Cell In[39], line 55
52 print(wind_resource_data)
54 # Set the wind resource data
---> 55 wind_turbine.Resource.wind_resource_data = wind_resource_data
57 # Run the simulation
58 wind_turbine.execute()

Exception: Error (-4) converting nested tuple 0 into row in matrix.

I don't know what this error message means
I've tried several solution like change the file path but it's not working.
I have attached the CSV file.
I will be very glad if someone could help me

Attachments:

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

  • Paul Gilman
More
12 Jul 2023 10:26 #12315 by Paul Gilman
Replied by Paul Gilman on topic Converting nestle tuple 0 into row in matrix
Hi Martineau,

I was not able to test your script because of a syntax error in the construction of 'wind_resource_data'.

Best regards,
Paul.

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

Moderators: Paul Gilman
Powered by Kunena Forum