- Posts: 2
PySAM Windpower Error: "Error (-4) converting nested tuple 0 into row in matrix"
- Benjamin Preneta
- Topic Author
Less
More
15 Sep 2025 17:43 #14290
by Benjamin Preneta
PySAM Windpower Error: "Error (-4) converting nested tuple 0 into row in matrix" was created 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)
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)
Attachments:
Please Log in or Create an account to join the conversation.
- Paul Gilman
Less
More
- Posts: 5640
16 Sep 2025 09:48 #14293
by Paul Gilman
Replied by Paul Gilman on topic PySAM Windpower Error: "Error (-4) converting nested tuple 0 into row in matrix"
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:
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.
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
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.
Moderators: Paul Gilman