Wind turbine power generation code

  • ashis2sedai
  • Topic Author
More
05 Dec 2023 22:34 #12732 by ashis2sedai
Wind turbine power generation code was created by ashis2sedai
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

 

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

  • pgilman
More
06 Dec 2023 17:07 #12738 by pgilman
Replied by pgilman on topic Wind turbine power generation code
Hi Ashish,

I recommend using the PySAM Python package because it is better documented and has some helpful supporting functions:

nrel-pysam.readthedocs.io/en/main/index.html

Otherwise, if you want to run SSC directly from Python, you can get started using the code generator as described here: sam.nrel.gov/software-development-kit-sdk.html . Here are the specific steps to generate code for the wind power model.

1. Create a Wind / No financial case in SAM.
2. On the Case menu, choose Generate code.
3. Choose Python 3 as the language.
4. Click OK and create a folder to save the files.

SAM creates a set of files inculding a Python script that sets the wind power model inputs, runs a simulation, and reads and displays some sample results. You can run the script to confirm it works, and then modify it as needed for your analysis.

Again, I strongly recommend using PySAM instead of this approach.

Best regards,
Paul.



 

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

  • ashis2sedai
  • Topic Author
More
06 Dec 2023 21:00 #12739 by ashis2sedai
Replied by ashis2sedai on topic Wind turbine power generation code
Thanks Paul, 

pySAM seems to be way easier. Thanks for your help. 

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

Moderators: pgilman
Powered by Kunena Forum