From 53b23490ae9fd1533714e4bd4b914111fbfd1ca7 Mon Sep 17 00:00:00 2001 From: dmy Date: Fri, 26 Dec 2025 09:22:56 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4--yearly=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- excel_reader.py | 40 ++++++++++++++++++++++++---------------- main.py | 26 ++++---------------------- storage_optimization.py | 4 ++-- 3 files changed, 30 insertions(+), 40 deletions(-) diff --git a/excel_reader.py b/excel_reader.py index c402d6f..568fe47 100644 --- a/excel_reader.py +++ b/excel_reader.py @@ -110,20 +110,28 @@ def read_system_parameters(file_path: str) -> SystemParameters: max_storage_capacity = None try: + # 获取各参数值,区分None、NaN、0和有效值 + def get_param_with_default(param_name, default_value): + value = get_param_value(param_name) + if value is None or pd.isna(value): + return default_value + else: + return value + return SystemParameters( - max_curtailment_wind=get_param_value('最大弃风率') or 0.1, - max_curtailment_solar=get_param_value('最大弃光率') or 0.1, - max_grid_ratio=get_param_value('最大上网电量比例') or 0.2, - storage_efficiency=get_param_value('储能效率') or 0.9, - discharge_rate=get_param_value('放电倍率') or 1.0, - charge_rate=get_param_value('充电倍率') or 1.0, + max_curtailment_wind=get_param_with_default('最大弃风率', 0.1), + max_curtailment_solar=get_param_with_default('最大弃光率', 0.1), + max_grid_ratio=get_param_with_default('最大上网电量比例', 0.2), + storage_efficiency=get_param_with_default('储能效率', 0.9), + discharge_rate=get_param_with_default('放电倍率', 1.0), + charge_rate=get_param_with_default('充电倍率', 1.0), max_storage_capacity=max_storage_capacity, - rated_thermal_capacity=get_param_value('额定火电装机容量') or 100.0, - rated_solar_capacity=get_param_value('额定光伏装机容量') or 100.0, - rated_wind_capacity=get_param_value('额定风电装机容量') or 100.0, - available_thermal_energy=get_param_value('火电可用发电量') or 2400.0, - available_solar_energy=get_param_value('光伏可用发电量') or 600.0, - available_wind_energy=get_param_value('风电可用发电量') or 1200.0 + rated_thermal_capacity=get_param_with_default('额定火电装机容量', 100.0), + rated_solar_capacity=get_param_with_default('额定光伏装机容量', 100.0), + rated_wind_capacity=get_param_with_default('额定风电装机容量', 100.0), + available_thermal_energy=get_param_with_default('火电可用发电量', 2400.0), + available_solar_energy=get_param_with_default('光伏可用发电量', 600.0), + available_wind_energy=get_param_with_default('风电可用发电量', 1200.0) ) except (KeyError, IndexError, Exception) as e: print(f"读取参数失败:{str(e)},使用默认参数") @@ -307,7 +315,7 @@ def create_excel_template(file_path: str, data_type: str = "8760"): 1.0, # 放电倍率 1.0, # 充电倍率 '', # 最大储能容量(空表示无限制) - 100.0, # 额定火电装机容量 + 0.0, # 额定火电装机容量(可以为0) 100.0, # 额定光伏装机容量 100.0, # 额定风电装机容量 2400.0, # 火电可用发电量 @@ -322,7 +330,7 @@ def create_excel_template(file_path: str, data_type: str = "8760"): '储能放电倍率(C-rate,>0)', '储能充电倍率(C-rate,>0)', '储能容量上限(MWh,空表示无限制)', - '额定火电装机容量(MW)', + '额定火电装机容量(MW,可以为0)', '额定光伏装机容量(MW)', '额定风电装机容量(MW)', '火电可用发电量(MWh)', @@ -337,7 +345,7 @@ def create_excel_template(file_path: str, data_type: str = "8760"): '>0', '>0', '>0或空', - '>0', + '≥0', '>0', '>0', '≥0', @@ -352,7 +360,7 @@ def create_excel_template(file_path: str, data_type: str = "8760"): '1.0', '1.0', '无限制', - '100.0', + '0.0', '100.0', '100.0', '2400.0', diff --git a/main.py b/main.py index 79718dd..0942fda 100644 --- a/main.py +++ b/main.py @@ -410,11 +410,8 @@ def main(): show_window = '--show' in sys.argv # 检查是否包含--show参数 display_only = '--display-only' in sys.argv # 检查是否只显示不保存 - 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 command == '--excel': if len(sys.argv) < 3: print("错误:请指定Excel文件路径") print("用法:python main.py --excel <文件路径>") @@ -513,22 +510,7 @@ def main(): available_wind_energy=1200.0 ) - # 对于 --yearly 参数,也需要设置默认参数 - if command == '--yearly': - params = SystemParameters( - max_curtailment_wind=0.1, - max_curtailment_solar=0.1, - max_grid_ratio=0.2, - storage_efficiency=0.9, - discharge_rate=1.0, - charge_rate=1.0, - rated_thermal_capacity=100.0, - rated_solar_capacity=100.0, - rated_wind_capacity=100.0, - available_thermal_energy=2400.0, - available_solar_energy=600.0, - available_wind_energy=1200.0 - ) + # 显示当前使用的系统参数 print("\n=== 当前使用的系统参数 ===") @@ -576,7 +558,7 @@ 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(" python main.py --show # 显示图形窗口(可与其他参数组合使用)") diff --git a/storage_optimization.py b/storage_optimization.py index 7dde301..a3a2689 100644 --- a/storage_optimization.py +++ b/storage_optimization.py @@ -88,8 +88,8 @@ def validate_inputs( if params.max_storage_capacity is not None and params.max_storage_capacity <= 0: raise ValueError("储能容量上限必须大于0") # 验证新增的额定装机容量参数 - if params.rated_thermal_capacity <= 0: - raise ValueError("额定火电装机容量必须大于0") + if params.rated_thermal_capacity < 0: + raise ValueError("额定火电装机容量必须为非负值") if params.rated_solar_capacity <= 0: raise ValueError("额定光伏装机容量必须大于0") if params.rated_wind_capacity <= 0: