#!/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 args, logger """" 调用思路 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='\s+', header=0) power = pd.read_csv(input_file / power, sep='\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='\s+', header=0) nwp_v_h = pd.read_csv(input_file / '0' / nwp_v_h, sep='\s+', header=0) nwp_own = pd.read_csv(input_file / '1' / nwp_own, sep='\s+', header=0) nwp_own_h = pd.read_csv(input_file / '1' / nwp_own_h, sep='\s+', header=0) if args['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='\s+', header=0) station_info_d = pd.read_csv(input_file / station_info_d_w, sep='\s+', header=0) nwp = pd.read_csv(input_file / nwp_w, sep='\s+', header=0) nwp_h = pd.read_csv(input_file / nwp_w_h, sep='\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='\s+', header=0) station_info_d = pd.read_csv(input_file / station_info_d_s, sep='\s+', header=0) nwp = pd.read_csv(input_file / nwp_s, sep='\s+', header=0) nwp_h = pd.read_csv(input_file / nwp_s_h, sep='\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='\s+', header=0) return basic_area def input_file_handler(input_file: 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(station_info['PlantCap'][0], 2) # 含有model,训练 if 'model' in input_file.lower(): train_data = pd.merge(nwp_v_h, power, on='Datetime') if args['model_name'] == 'fmi': from tf_fmi_train import model_training elif args['model_name'] == 'cnn': from tf_cnn_train import model_training else: from tf_lstm_train import model_training model_training(train_data, input_file, cap) # 含有predict,预测 else: logger.info("训练路径错误!") else: # 区域级预测:未完 basic_area = material(input_file, False) def main(): # 创建解析器对象 parser = argparse.ArgumentParser(description="程序描述") # 创建 # 添加参数 parser.add_argument("input_file", help="输入文件路径") # 解析参数 args = parser.parse_args() # 使用参数 print(f"文件: {args.input_file}") input_file_handler(args.input_file) if __name__ == "__main__": main()