main.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # time: 2023/3/2 10:28
  4. # file: config.py
  5. # author: David
  6. # company: shenyang JY
  7. """
  8. 模型调参及系统功能配置
  9. """
  10. import argparse
  11. import pandas as pd
  12. from pathlib import Path
  13. from app.common.logs import args, logger
  14. """"
  15. 调用思路
  16. xxxx 1. 从入口参数中获取IN OUT文件位置 xxxx
  17. 2. 按照训练和预测加载和解析数据
  18. 3. 对数据进行预处理
  19. 4. 执行训练,保存模型,输出状态
  20. 5. 执行预测,输出结果,输出状态
  21. """
  22. def material(input_file, isDq=True):
  23. 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 = (
  24. 'DQYC_IN_BASIC.txt', 'DQYC_IN_PLANT_WIND.txt', 'DQYC_IN_PLANT_DETAIL_WIND.txt', 'DQYC_IN_PLANT_SOLAR.txt',
  25. 'DQYC_IN_PLANT_DETAIL_SOLAR.txt', 'DQYC_IN_FORECAST_WEATHER_WIND.txt', 'DQYC_IN_FORECAST_WEATHER_SOLAR.txt',
  26. 'DQYC_IN_FORECAST_WEATHER_WIND_H.txt', 'DQYC_IN_FORECAST_WEATHER_SOLAR_H.txt', 'DQYC_IN_HISTORY_POWER_LONG.txt')
  27. basi_area = 'DQYC_AREA_IN_BASIC'
  28. nwp_v, nwp_v_h = 'DQYC_IN_FORECAST_WEATHER.txt', 'DQYC_IN_FORECAST_WEATHER_H.txt' # 多版本气象
  29. nwp_own, nwp_own_h = 'DQYC_IN_FORECAST_WEATHER_OWNER.txt', 'DQYC_IN_FORECAST_WEATHER_OWNER_H.txt',
  30. input_file = Path(input_file)
  31. basic = pd.read_csv(input_file / basi, sep='\s+', header=0)
  32. power = pd.read_csv(input_file / power, sep='\s+', header=0)
  33. plant_type = int(basic.loc[basic['PropertyID'].to_list().index(('PlantType')), 'Value'])
  34. if isDq:
  35. nwp_v = pd.read_csv(input_file / '0' / nwp_v, sep='\s+', header=0)
  36. nwp_v_h = pd.read_csv(input_file / '0' / nwp_v_h, sep='\s+', header=0)
  37. nwp_own = pd.read_csv(input_file / '1' / nwp_own, sep='\s+', header=0)
  38. nwp_own_h = pd.read_csv(input_file / '1' / nwp_own_h, sep='\s+', header=0)
  39. if args['switch_nwp_owner']:
  40. nwp_v, nwp_v_h = nwp_own, nwp_own_h
  41. # 如果是风电
  42. if plant_type < 2:
  43. station_info = pd.read_csv(input_file / station_info_w, sep='\s+', header=0)
  44. station_info_d = pd.read_csv(input_file / station_info_d_w, sep='\s+', header=0)
  45. nwp = pd.read_csv(input_file / nwp_w, sep='\s+', header=0)
  46. nwp_h = pd.read_csv(input_file / nwp_w_h, sep='\s+', header=0)
  47. return station_info, station_info_d, nwp, nwp_h, power, nwp_v, nwp_v_h
  48. # 如果是光伏
  49. elif plant_type == 2:
  50. station_info = pd.read_csv(input_file / station_info_s, sep='\s+', header=0)
  51. station_info_d = pd.read_csv(input_file / station_info_d_s, sep='\s+', header=0)
  52. nwp = pd.read_csv(input_file / nwp_s, sep='\s+', header=0)
  53. nwp_h = pd.read_csv(input_file / nwp_s_h, sep='\s+', header=0)
  54. return station_info, station_info_d, nwp, nwp_h, power, nwp_v, nwp_v_h
  55. else:
  56. # 区域级预测待定,可能需要遍历获取场站数据
  57. basic_area = pd.read_csv(input_file / basi_area, sep='\s+', header=0)
  58. return basic_area
  59. def input_file_handler(input_file: str):
  60. # DQYC:短期预测,qy:区域级
  61. if 'dqyc' in input_file.lower():
  62. station_info, station_info_d, nwp, nwp_h, power, nwp_v, nwp_v_h = material(input_file, True)
  63. cap = round(station_info['PlantCap'][0], 2)
  64. # 含有model,训练
  65. if 'model' in input_file.lower():
  66. train_data = pd.merge(nwp_v_h, power, on='Datetime')
  67. if args['model_name'] == 'fmi':
  68. from tf_fmi_train import model_training
  69. elif args['model_name'] == 'cnn':
  70. from tf_cnn_train import model_training
  71. else:
  72. from tf_lstm_train import model_training
  73. model_training(train_data, input_file, cap)
  74. # 含有predict,预测
  75. else:
  76. logger.info("训练路径错误!")
  77. else:
  78. # 区域级预测:未完
  79. basic_area = material(input_file, False)
  80. def main():
  81. # 创建解析器对象
  82. parser = argparse.ArgumentParser(description="程序描述")
  83. # 创建
  84. # 添加参数
  85. parser.add_argument("input_file", help="输入文件路径")
  86. # 解析参数
  87. args = parser.parse_args()
  88. # 使用参数
  89. print(f"文件: {args.input_file}")
  90. input_file_handler(args.input_file)
  91. if __name__ == "__main__":
  92. main()