1.可以读excel文件
2.可以计算8760小时
This commit is contained in:
74
main.py
74
main.py
@@ -10,6 +10,7 @@
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
from storage_optimization import optimize_storage_capacity, SystemParameters
|
||||
from excel_reader import read_excel_data, create_excel_template, analyze_excel_data
|
||||
|
||||
# 设置中文字体
|
||||
plt.rcParams['font.sans-serif'] = ['SimHei', 'Microsoft YaHei', 'DejaVu Sans']
|
||||
@@ -27,6 +28,12 @@ def plot_system_curves(solar_output, wind_output, thermal_output, load_demand, r
|
||||
load_demand: 负荷曲线 (MW) - 支持24小时或8760小时
|
||||
result: 优化结果字典
|
||||
"""
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
# 设置中文字体
|
||||
plt.rcParams['font.sans-serif'] = ['SimHei', 'Microsoft YaHei', 'DejaVu Sans']
|
||||
plt.rcParams['axes.unicode_minus'] = False # 解决负号显示问题
|
||||
hours = np.arange(len(solar_output))
|
||||
data_length = len(solar_output)
|
||||
|
||||
@@ -160,12 +167,56 @@ def main():
|
||||
import sys
|
||||
|
||||
# 检查命令行参数
|
||||
use_yearly_data = len(sys.argv) > 1 and sys.argv[1] == '--yearly'
|
||||
if len(sys.argv) < 2:
|
||||
print_usage()
|
||||
return
|
||||
|
||||
if use_yearly_data:
|
||||
command = sys.argv[1]
|
||||
|
||||
if command == '--yearly':
|
||||
print("生成8760小时全年数据...")
|
||||
solar_output, wind_output, thermal_output, load_demand = generate_yearly_data()
|
||||
print(f"数据长度: {len(solar_output)} 小时")
|
||||
elif command == '--excel':
|
||||
if len(sys.argv) < 3:
|
||||
print("错误:请指定Excel文件路径")
|
||||
print("用法:python main.py --excel <文件路径>")
|
||||
return
|
||||
|
||||
excel_file = sys.argv[2]
|
||||
print(f"从Excel文件读取数据:{excel_file}")
|
||||
|
||||
try:
|
||||
data = read_excel_data(excel_file)
|
||||
solar_output = data['solar_output']
|
||||
wind_output = data['wind_output']
|
||||
thermal_output = data['thermal_output']
|
||||
load_demand = data['load_demand']
|
||||
|
||||
print(f"成功读取{data['data_type']}小时数据")
|
||||
print(f"原始数据长度:{data['original_length']}小时")
|
||||
print(f"处理后数据长度:{len(solar_output)}小时")
|
||||
|
||||
# 显示数据统计
|
||||
stats = analyze_excel_data(excel_file)
|
||||
if stats:
|
||||
print("\n数据统计:")
|
||||
print(f" 总发电量: {stats['total_generation']:.2f} MW")
|
||||
print(f" 总负荷: {stats['total_load']:.2f} MW")
|
||||
print(f" 最大光伏出力: {stats['max_solar']:.2f} MW")
|
||||
print(f" 最大风电出力: {stats['max_wind']:.2f} MW")
|
||||
print(f" 最大负荷: {stats['max_load']:.2f} MW")
|
||||
|
||||
except Exception as e:
|
||||
print(f"读取Excel文件失败:{str(e)}")
|
||||
return
|
||||
elif command == '--create-template':
|
||||
template_type = sys.argv[2] if len(sys.argv) > 2 else "8760"
|
||||
template_file = f"data_template_{template_type}.xlsx"
|
||||
|
||||
print(f"创建{template_type}小时Excel模板:{template_file}")
|
||||
create_excel_template(template_file, template_type)
|
||||
return
|
||||
else:
|
||||
print("使用24小时示例数据...")
|
||||
# 示例数据
|
||||
@@ -174,8 +225,9 @@ def main():
|
||||
thermal_output = [5.0] * 24
|
||||
load_demand = [3.0, 4.0, 5.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0, 18.0, 20.0, 18.0,
|
||||
16.0, 14.0, 12.0, 10.0, 8.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0, 2.0]
|
||||
|
||||
# 系统参数
|
||||
|
||||
|
||||
# 系统参数
|
||||
params = SystemParameters(
|
||||
max_curtailment_wind=0.1,
|
||||
max_curtailment_solar=0.1,
|
||||
@@ -198,5 +250,19 @@ def main():
|
||||
print("\n曲线图已保存为 'system_curves.png'")
|
||||
|
||||
|
||||
def print_usage():
|
||||
"""打印使用说明"""
|
||||
print("多能互补系统储能容量优化程序")
|
||||
print("\n使用方法:")
|
||||
print(" python main.py --excel <文件路径> # 从Excel文件读取数据")
|
||||
print(" python main.py --yearly # 使用8760小时全年数据")
|
||||
print(" python main.py --create-template [类型] # 创建Excel模板(24或8760)")
|
||||
print(" python main.py # 使用24小时示例数据")
|
||||
print("\n示例:")
|
||||
print(" python main.py --excel data.xlsx")
|
||||
print(" python main.py --create-template 8760")
|
||||
print(" python main.py --create-template 24")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user