#!/usr/bin/env python # -*- coding: utf-8 -*- # time: 2023/3/2 10:28 # file: config.py # author: David # company: shenyang JY """ 模型调参及系统功能配置 """ import argparse import pandas as pd from pathlib import Path from app.common.logs import logger, params """ 调用思路 xxxx 1. 从入口参数中获取IN OUT文件位置 xxxx 2. 按照训练和预测加载和解析数据 3. 对数据进行预处理 4. 执行训练,保存模型 5. 执行预测,输出结果 """ def material(input_file, isDq=True): basi, station_info_w, station_info_d_w, station_info_s, station_info_d_s, nwp_w, nwp_s, nwp_w_h, nwp_s_h, power = ( 'DQYC_IN_BASIC.txt', 'DQYC_IN_PLANT_WIND.txt', 'DQYC_IN_PLANT_DETAIL_WIND.txt', 'DQYC_IN_PLANT_SOLAR.txt', 'DQYC_IN_PLANT_DETAIL_SOLAR.txt', 'DQYC_IN_FORECAST_WEATHER_WIND.txt', 'DQYC_IN_FORECAST_WEATHER_SOLAR.txt', 'DQYC_IN_FORECAST_WEATHER_WIND_H.txt', 'DQYC_IN_FORECAST_WEATHER_SOLAR_H.txt', 'DQYC_IN_HISTORY_POWER_LONG.txt') basi_area = 'DQYC_AREA_IN_BASIC' nwp_v, nwp_v_h = 'DQYC_IN_FORECAST_WEATHER.txt', 'DQYC_IN_FORECAST_WEATHER_H.txt' nwp_own, nwp_own_h = 'DQYC_IN_FORECAST_WEATHER_OWNER.txt', 'DQYC_IN_FORECAST_WEATHER_OWNER_H.txt', input_file = Path(input_file) basic = pd.read_csv(input_file / basi, sep=r'\s+', header=0) power = pd.read_csv(input_file / power, sep=r'\s+', header=0) plant_type = int(basic.loc[basic['PropertyID'].to_list().index(('PlantType')), 'Value']) if isDq: nwp_v = pd.read_csv(input_file / '0' / nwp_v, sep=r'\s+', header=0) nwp_v_h = pd.read_csv(input_file / '0' / nwp_v_h, sep=r'\s+', header=0) nwp_own = pd.read_csv(input_file / '1' / nwp_own, sep=r'\s+', header=0) nwp_own_h = pd.read_csv(input_file / '1' / nwp_own_h, sep=r'\s+', header=0) if params['switch_nwp_owner']: nwp_v, nwp_v_h = nwp_own, nwp_own_h # 如果是风电 if plant_type == 0: station_info = pd.read_csv(input_file / station_info_w, sep=r'\s+', header=0) station_info_d = pd.read_csv(input_file / station_info_d_w, sep=r'\s+', header=0) nwp = pd.read_csv(input_file / nwp_w, sep=r'\s+', header=0) nwp_h = pd.read_csv(input_file / nwp_w_h, sep=r'\s+', header=0) return station_info, station_info_d, nwp, nwp_h, power, nwp_v, nwp_v_h # 如果是光伏 elif plant_type == 1: station_info = pd.read_csv(input_file / station_info_s, sep=r'\s+', header=0) station_info_d = pd.read_csv(input_file / station_info_d_s, sep=r'\s+', header=0) nwp = pd.read_csv(input_file / nwp_s, sep=r'\s+', header=0) nwp_h = pd.read_csv(input_file / nwp_s_h, sep=r'\s+', header=0) return station_info, station_info_d, nwp, nwp_h, power, nwp_v, nwp_v_h else: # 区域级预测待定,可能需要遍历获取场站数据 basic_area = pd.read_csv(input_file / basi_area, sep=r'\s+', header=0) return basic_area def input_file_handler(input_file: str, model_name: str): # DQYC:短期预测,qy:区域级 if 'dqyc' in input_file.lower(): station_info, station_info_d, nwp, nwp_h, power, nwp_v, nwp_v_h = material(input_file, True) cap = round(float(station_info['PlantCap'][0]), 2) # 含有predict,预测 if 'predict' in input_file.lower(): pre_data = nwp_v if model_name == 'fmi': from app.predict.tf_fmi_pre import model_prediction elif model_name == 'cnn': from app.predict.tf_cnn_pre import model_prediction else: from app.predict.tf_lstm_pre import model_prediction model_prediction(pre_data, input_file, cap) else: logger.info("预测路径错误!") else: # 区域级预测:未完 # basic_area = material(input_file, False) logger.info("区域级预测待开放。") def main(): # 创建解析器对象 parser = argparse.ArgumentParser(description="程序描述") # 创建 # 添加参数 parser.add_argument("input_file", help="输入文件路径") # 第一个位置参数 parser.add_argument("--model_name", default="cnn", help='选择短期模型') # 第二个位置参数(可选) # 解析参数 args = parser.parse_args() # 使用参数 print(f"文件: {args.input_file}") input_file_handler(args.input_file, args.model_name) if __name__ == "__main__": main()