Files
multi_energy_complementarity/tests/test_extreme_single_renewable.py
2025-12-27 19:15:56 +08:00

103 lines
3.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
创建一个明确的测试算例,验证只有风电时弃电量不受限制
这个测试会创建一个风电远超负荷的场景,来验证弃风是否真的不受限制
"""
import sys
import os
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'src'))
import pandas as pd
import numpy as np
def create_extreme_wind_test():
"""创建极端风电测试场景:风电远超负荷"""
# 创建24小时数据
hours = list(range(1, 25))
# 风电出力:设计为远超负荷,强制产生弃风
wind_output = [200, 180, 160, 140, 120, 100, 80, 60, 50, 40, 30, 25, 20, 15, 10, 8, 6, 5, 4, 3, 2, 1, 0.5, 0.2]
# 光伏出力全部为0
solar_output = [0.0] * 24
# 火电出力全部为0
thermal_output = [0.0] * 24
# 负荷需求:较低,确保风电远超负荷
load_demand = [20.0] * 24 # 只有20MW负荷风电最高200MW
# 创建DataFrame
data = {
'小时': hours,
'光伏出力(MW)': solar_output,
'风电出力(MW)': wind_output,
'火电出力(MW)': thermal_output,
'负荷需求(MW)': load_demand
}
df = pd.DataFrame(data)
# 保存为Excel文件
excel_file = 'extreme_wind_test.xlsx'
df.to_excel(excel_file, index=False, sheet_name='data')
print(f"已创建极端风电测试文件: {excel_file}")
print(f"风电总出力: {sum(wind_output):.1f} MWh")
print(f"负荷总需求: {sum(load_demand):.1f} MWh")
print(f"风电超额: {sum(wind_output) - sum(load_demand):.1f} MWh (应该被弃掉)")
return excel_file
def create_extreme_solar_test():
"""创建极端光伏测试场景:光伏远超负荷"""
# 创建24小时数据
hours = list(range(1, 25))
# 风电出力全部为0
wind_output = [0.0] * 24
# 光伏出力:设计为远超负荷,强制产生弃光
solar_output = [0, 0, 0, 0, 0, 0, 50, 100, 150, 200, 180, 150, 120, 100, 80, 60, 40, 20, 10, 5, 2, 1, 0.5, 0.2]
# 火电出力全部为0
thermal_output = [0.0] * 24
# 负荷需求:较低,确保光伏远超负荷
load_demand = [30.0] * 24 # 只有30MW负荷光伏最高200MW
# 创建DataFrame
data = {
'小时': hours,
'光伏出力(MW)': solar_output,
'风电出力(MW)': wind_output,
'火电出力(MW)': thermal_output,
'负荷需求(MW)': load_demand
}
df = pd.DataFrame(data)
# 保存为Excel文件
excel_file = 'extreme_solar_test.xlsx'
df.to_excel(excel_file, index=False, sheet_name='data')
print(f"已创建极端光伏测试文件: {excel_file}")
print(f"光伏总出力: {sum(solar_output):.1f} MWh")
print(f"负荷总需求: {sum(load_demand):.1f} MWh")
print(f"光伏超额: {sum(solar_output) - sum(load_demand):.1f} MWh (应该被弃掉)")
return excel_file
if __name__ == "__main__":
print("创建极端单一可再生能源测试文件...")
wind_file = create_extreme_wind_test()
print()
solar_file = create_extreme_solar_test()
print()
print(f"测试文件已创建完成:")
print(f"1. {wind_file} - 极端单一风电场景 (风电远超负荷)")
print(f"2. {solar_file} - 极端单一光伏场景 (光伏远超负荷)")
print(f"\n预期结果:")
print(f"- 如果弃电量不受限制,应该能看到大量的弃风/弃光")
print(f"- 如果弃电量受限制,系统会通过其他方式处理超额电力")
print(f"\n可以使用以下命令测试:")
print(f"uv run python main.py --excel {wind_file}")
print(f"uv run python main.py --excel {solar_file}")