main.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 logger, params
  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=r'\s+', header=0)
  32. power = pd.read_csv(input_file / power, sep=r'\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=r'\s+', header=0)
  36. nwp_v_h = pd.read_csv(input_file / '0' / nwp_v_h, sep=r'\s+', header=0)
  37. nwp_own = pd.read_csv(input_file / '1' / nwp_own, sep=r'\s+', header=0)
  38. nwp_own_h = pd.read_csv(input_file / '1' / nwp_own_h, sep=r'\s+', header=0)
  39. if params['switch_nwp_owner']:
  40. nwp_v, nwp_v_h = nwp_own, nwp_own_h
  41. # 如果是风电
  42. if plant_type == 0:
  43. station_info = pd.read_csv(input_file / station_info_w, sep=r'\s+', header=0)
  44. station_info_d = pd.read_csv(input_file / station_info_d_w, sep=r'\s+', header=0)
  45. nwp = pd.read_csv(input_file / nwp_w, sep=r'\s+', header=0)
  46. nwp_h = pd.read_csv(input_file / nwp_w_h, sep=r'\s+', header=0)
  47. return station_info, station_info_d, nwp, nwp_h, power, nwp_v, nwp_v_h
  48. # 如果是光伏
  49. elif plant_type == 1:
  50. station_info = pd.read_csv(input_file / station_info_s, sep=r'\s+', header=0)
  51. station_info_d = pd.read_csv(input_file / station_info_d_s, sep=r'\s+', header=0)
  52. nwp = pd.read_csv(input_file / nwp_s, sep=r'\s+', header=0)
  53. nwp_h = pd.read_csv(input_file / nwp_s_h, sep=r'\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=r'\s+', header=0)
  58. return basic_area
  59. def input_file_handler(input_file: str, model_name: 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(float(station_info['PlantCap'][0]), 2)
  64. # 含有predict,预测
  65. if 'predict' in input_file.lower():
  66. pre_data = nwp_v
  67. if model_name == 'fmi':
  68. from app.predict.tf_fmi_pre import model_prediction
  69. elif model_name == 'cnn':
  70. from app.predict.tf_cnn_pre import model_prediction
  71. else:
  72. from app.predict.tf_lstm_pre import model_prediction
  73. model_prediction(pre_data, input_file, cap)
  74. else:
  75. logger.info("预测路径错误!")
  76. else:
  77. # 区域级预测:未完
  78. # basic_area = material(input_file, False)
  79. logger.info("区域级预测待开放。")
  80. def main():
  81. # 创建解析器对象
  82. parser = argparse.ArgumentParser(description="程序描述")
  83. # 创建
  84. # 添加参数
  85. parser.add_argument("input_file", help="输入文件路径") # 第一个位置参数
  86. parser.add_argument("--model_name", default="cnn", help='选择短期模型') # 第二个位置参数(可选)
  87. # 解析参数
  88. args = parser.parse_args()
  89. # 使用参数
  90. print(f"文件: {args.input_file}")
  91. input_file_handler(args.input_file, args.model_name)
  92. if __name__ == "__main__":
  93. main()