qinghai-nuomuhong-guifan.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. # -*- coding: utf-8 -*-
  2. """
  3. Spyder 编辑器
  4. 这是一个临时脚本文件。
  5. """
  6. import datetime
  7. import multiprocessing
  8. from os import *
  9. import numpy as np
  10. import pandas as pd
  11. dianjian_str = """
  12. wind_turbine_number
  13. time_stamp 时间
  14. active_power 有功功率 kW
  15. rotor_speed 风轮转速 rpm
  16. generator_speed 发电机转速 rpm
  17. wind_velocity 风速 m/s
  18. pitch_angle_blade_1 叶片1角度 °
  19. pitch_angle_blade_2 叶片2角度 °
  20. pitch_angle_blade_3 叶片3角度 °
  21. cabin_position 机舱位置 °
  22. true_wind_direction
  23. yaw_error1 风向 °
  24. twisted_cable_angle
  25. main_bearing_temperature 主轴温度 ℃
  26. gearbox_oil_temperature 齿轮箱温度 ℃
  27. gearbox_low_speed_shaft_bearing_temperature 齿轮箱轴承温度 ℃
  28. gearboxmedium_speed_shaftbearing_temperature
  29. gearbox_high_speed_shaft_bearing_temperature 齿轮箱轴承温度2 ℃
  30. generatordrive_end_bearing_temperature 发电机驱动侧轴承温度 ℃
  31. generatornon_drive_end_bearing_temperature 发电机非驱动侧轴承温度 ℃
  32. cabin_temperature 机舱温度 ℃
  33. outside_cabin_temperature 舱外温度 ℃
  34. generator_winding1_temperature
  35. generator_winding2_temperature
  36. generator_winding3_temperature
  37. front_back_vibration_of_the_cabin
  38. side_to_side_vibration_of_the_cabin
  39. required_gearbox_speed
  40. inverter_speed_master_control
  41. actual_torque
  42. given_torque
  43. clockwise_yaw_count
  44. counterclockwise_yaw_count
  45. unusable
  46. power_curve_available
  47. set_value_of_active_power 有功功率设定 kW
  48. wind_turbine_status
  49. wind_turbine_status2
  50. turbulence_intensity
  51. """
  52. datas = [i for i in dianjian_str.split("\n") if i]
  53. dianjian_dict = dict()
  54. for data in datas:
  55. ds = data.split("\t")
  56. if len(ds) == 3:
  57. dianjian_dict[ds[0]] = ds[2]
  58. else:
  59. dianjian_dict[ds[0]] = ''
  60. def read_df(file_path):
  61. df = pd.read_csv(file_path, header=[0, 1])
  62. col_nams_map = dict()
  63. pre_col = ""
  64. for tuple_col in df.columns:
  65. col1 = tuple_col[0]
  66. col2 = tuple_col[1]
  67. if str(col1).startswith("Unnamed"):
  68. if pre_col:
  69. col1 = pre_col
  70. pre_col = ''
  71. else:
  72. col1 = ''
  73. else:
  74. pre_col = col1
  75. if str(col2).startswith("Unnamed"):
  76. col2 = ''
  77. col_nams_map[str(tuple_col)] = ''.join([col1, col2])
  78. # print(col_nams_map)
  79. # for k, v in col_nams_map.items():
  80. # if str(v).endswith('采样值'):
  81. # col_nams_map[k] = str(v)[:-3]
  82. df.columns = [str(col) for col in df.columns]
  83. df.rename(columns=col_nams_map, inplace=True)
  84. # for col, name in dianjian_dict.items():
  85. # if name in df.columns:
  86. # df.rename(columns={name: col}, inplace=True)
  87. # for col in df.columns:
  88. # if col not in dianjian_dict.keys():
  89. # del df[col]
  90. return df
  91. def get_wind_name_files(path):
  92. files = listdir(path)
  93. return files
  94. def combine_df(save_path, file):
  95. begin = datetime.datetime.now()
  96. df = read_df(file)
  97. print("读取", file, df.shape)
  98. df.replace("-", np.nan,inplace=True)
  99. df.to_csv(path.join(save_path, path.basename(file)), encoding='utf-8', index=False)
  100. print('整理完成', '耗时:', (datetime.datetime.now() - begin).seconds)
  101. if __name__ == '__main__':
  102. read_path = r'/data/download/collection_data/1进行中/诺木洪风电场-甘肃-华电/收资数据/min-666'
  103. save_path = r'/data/download/collection_data/1进行中/诺木洪风电场-甘肃-华电/清理数据/min-666'
  104. # read_path = r'D:\trans_data\诺木洪\收资数据\min-666'
  105. # save_path = r'D:\trans_data\诺木洪\清理数据\min-666'
  106. if not path.exists(save_path):
  107. makedirs(save_path, exist_ok=True)
  108. with multiprocessing.Pool(20) as pool:
  109. pool.starmap(combine_df, [(save_path, read_path + sep + file) for file in listdir(read_path)])