PySAM Windpower Error: "Error (-4) converting nested tuple 0 into row in matrix"

  • Benjamin Preneta
  • Topic Author
More
15 Sep 2025 17:43 #14290 by Benjamin Preneta
Hello,

I am attempting to use the PySAM Windpower module to generate a capacity factor for a single standard/basic turbine given standard atmospheric conditions with an inputted hourly windspeed .csv file (generated from the BC-HRRR CONUS (NOAA+NREL) dataset). I believe I have ensured this file is formatted and accessed properly for PySAM to function however I continually receive the error: "Error (-4) converting nested tuple 0 into row in matrix". PySAM seems to be detecting tuples in the windspeed data despite explicitly formatting this data as a list and debugging for silent sources of failures or mismatched formatting. I am unsure if I am missing something obvious or there is a deeper error. The script can be found below with the attached file. Thank you.import os
import time
import pandas as pd
from PySAM.Windpower import Windpower

# === INPUT FILE ===
input_csv = r"C:\...2023_28.787-98.376.csv"

# === OUTPUT FILE ===
output_csv = r"C:...cf_summary_single.csv"

print("Script started at:", time.strftime("%a %b %d %H:%M:%S %Y"))

results = []

try:
# --- 1. Read metadata row ---
with open(input_csv, 'r') as f:
metadata_row = f.readline().strip().split(',')
metadata = dict(zip(metadata_row[::2], metadata_rowcolor=#0000ff]1[/color]::[color=#0000ff]2[/color))
lat = float(metadata.get("Latitude", 0))
lon = float(metadata.get("Longitude", 0))
tz = int(metadata.get("Data Timezone", 0))

# --- 2. Load hourly wind speed data ---
df = pd.read_csv(input_csv, skiprows=1)
df = df[color=#008000]'Year'[/color], [color=#008000]'Month'[/color], [color=#008000]'Day'[/color], [color=#008000]'Hour'[/color], [color=#008000]'Minute'[/color], [color=#008000]'Wind Speed at 100m (m/s)'[/color]
df.columns = color=#008000]'year'[/color], [color=#008000]'month'[/color], [color=#008000]'day'[/color], [color=#008000]'hour'[/color], [color=#008000]'minute'[/color], [color=#008000]'wspd'[/color
df = df.astype(float)
data_matrix = [list(row) for row in df.values]

# --- 3. Format wind_resource_data for PySAM ---
wind_resource_data = {
'fields': color=#008000]'year'[/color], [color=#008000]'month'[/color], [color=#008000]'day'[/color], [color=#008000]'hour'[/color], [color=#008000]'minute'[/color], [color=#008000]'wspd'[/color,
'heights': color=#0000ff]100[/color,
'data': data_matrix,
'lat': lat,
'lon': lon,
'tz': tz
}

# --- 4. Run PySAM Windpower ---
wp = Windpower.new()
wp.Resource.wind_resource_model_choice = 0
wp.Resource.wind_resource_data = wind_resource_data

# 2 MW standard turbine
wp.Turbine.wind_resource_shear = 0.14
wp.Turbine.wind_turbine_hub_ht = 100
wp.Turbine.wind_turbine_rotor_diameter = 100

wp.Turbine.calculate_powercurve({
'turbine_size': 2000,
'rotor_diameter': 100,
'elevation': 0,
'max_cp': 0.48,
'max_tip_speed': 80,
'max_tip_sp_ratio': 7,
'cut_in': 3,
'cut_out': 25,
'drive_train': 0
})

wp.Farm.system_capacity = 2000
wp.Farm.wind_farm_wake_model = 0
wp.Farm.wind_farm_xCoordinates = color=#0000ff]0[/color
wp.Farm.wind_farm_yCoordinates = color=#0000ff]0[/color
wp.Farm.wind_resource_turbulence_coeff = 0.1

wp.execute()
cf = wp.Outputs.capacity_factor
results.append({"filename": os.path.basename(input_csv), "capacity_factor": cf})
print(f"Processed {input_csv}: CF = {cf:.3f}")

except Exception as e:
print(f"Failed to process {input_csv}: {e}")

# --- Save result ---
pd.DataFrame(results).to_csv(output_csv, index=False)
print("\nSaved result to:", output_csv)

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

  • Paul Gilman
More
16 Sep 2025 09:48 #14293 by Paul Gilman
Hi Benjamin,

You can find a description of the SAM CSV Format for Wind in SAM's Help system: samrepo.nrelcloud.org/help/weather_format_csv_wind.html

As mentioned in that description, the format requires the following data:
  • Wind speed for at least one height above the ground
  • Wind direction for at least one height above the ground
  • Temperature for at least one height above the ground
  • Atmospheric pressure for at least one height above the ground
Your weather file only contains wind speed data for one height above the ground.

If you are downloading data from the NREL Developer Network's BC-HRRR CONUS endpoint, the files provided by the API should be in the correct format. However, that dataset provides atmospheric pressure at ground level. To use it with the PySAM Windpower module (or SAM's Wind Power model), you will need to adjust the pressure data to be at one of the wind speed measurement heights. For example, if you have wind speed data at 100 m, then you will need pressure data at 100 m.

Let me know if you continue to have trouble after fixing the weather data issues.

Best regards,
Paul.
 

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

  • Benjamin Preneta
  • Topic Author
More
19 Sep 2025 11:55 #14303 by Benjamin Preneta
Hi Paul,

Thank you for the prompt and helpful response! I have corrected the formatting of the weather file but am still running into an issue that still seems to be related to PySAM parsing the data. I have changed my script to specifically troubleshoot for this and copied the 'windpower-example' script and set up found on the github ( github.com/NREL/pysam/blob/main/Examples/Windpower_Example/windpower-example.py ). Please see the attached .csv file and config .json along with the script below:

import json
from pathlib import Path
import PySAM.Windpower as wp

# === SETUP ===
input_json = r"C:path_to\windpower-inputs.json"
weather_file = r"C:path_to\2023_28.79-98.38.csv"

# === CREATE MODEL ===
wind = wp.new()

# === LOAD ALL CONFIG INCLUDING TURBINE PARAMETERS ===
with open(input_json, 'r') as file:
    config = json.load(file)
    for k, v in config.items():
        wind.value(k, v)

# === SET WEATHER FILE ===
wind.value('wind_resource_filename', weather_file)
wind.value('wind_resource_model_choice', 0)  

# === RUN MODEL ===
wind.execute()

# === OUTPUT ===
print("Results from windpower-inputs.json")
print("
")
print(f"Annual energy (kWh): {wind.Outputs.annual_energy:,.2f}")
print(f"Capacity factor:     {wind.Outputs.capacity_factor:.4f}")

This yields the following error:
"Exception: windpower execution error.
    exec fail(windpower): error reading wind resource file for interpolation at time step 0:"

Because I am directly using the example script and a json configuration I don't believe it is a coding error and thus must be in the weather file but cannot seem to figure out where it is coming from since the weather file seems formatted correctly with all inputs as described in the link you sent above.

I greatly appreciate any suggestions!

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

  • Paul Gilman
More
19 Sep 2025 14:52 - 19 Sep 2025 14:55 #14304 by Paul Gilman
Hi Benjamin,

I made the following changes to your wind resource file to fix the problem:

1. Remove the word "surface" from the pressure column header.
2. Add "100 m" to the pressure column header.
3. Remove trailing commas from data rows.

See the attached modified version of your file.

Also for more things that can cause the wind resource file reader to fail, see  sam.nrel.gov/forum/forum-general/4223-error-running-wind-data-file.html .

I will revise the format description in Help to explain that the word "surface" must not be in the pressure column header.

Best regards,
Paul.
Last edit: 19 Sep 2025 14:55 by Paul Gilman.

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

  • Benjamin Preneta
  • Topic Author
More
24 Sep 2025 12:22 #14310 by Benjamin Preneta
This was very helpful, thank you.

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

Moderators: Paul Gilman
Powered by Kunena Forum