main.py 4.0 KB

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