def get_hdf5_file(shotnum,isprint=True): """ 从HDF5文件读取 HMode_Ha 信号 :param shotnum: 炮号 :param isprint: 打印错误信息 :return: HMode_Ha 信号 """ try: _, signal = mh.read_channel(shotnum, channel="HMode_Ha") if max(signal) <= Signal_th: if isprint: print("{} Maximum < Signal_th ({}), pass".format(shotnum,Signal_th)) return None freq = mh.get_attrs("T_Freq", shot_number=shotnum, channel="HMode_Ha") / 1000 if not freq == default_Freq: if isprint: print("Frequency should be 10/ms,but it is : {}/ms, pass".format(freq)) return None # 部分信号长度不足,进行扩充 signal = np.append(signal, [0] * signal_max_len) return signal except: if isprint: print("Something is wrong,pass") return None
def label_data(shots): """ 通过查看各通道信号,给数据打标签,并通过 save_label 存储 :param shots: :return: """ data = {} for shot in shots: if shot in pdc.bad_shots or not if_all_channel_exist(shot): continue print("shot is: ", shot) i = 1 figure, ax = plt.subplots() figure.suptitle('炮号:{} '.format(shot), size=20) for channel in pdc.Channels: plt.subplot(pdc.fig_height, pdc.fig_width, i) plt.subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=None, hspace=0.5) plt.title(channel, size=15) plt.xlabel(" Time (ms)", size=12) Time, value = mh.read_channel(shot_number=shot, channel=channel) plt.plot(Time, value) if channel is "Ha_MidPlane_1": plt.text(200, 3, "击穿时间: {:} ms.".format(np.where(value > 0.5)[0][0]), size=16) plt.plot(40 * [10], np.arange(0, 4, 0.1), linestyle="-.") i += 1 # 打标签 if pdc.maxshow: plt.get_current_fig_manager().window.showMaximized() plt.show() if not pdc.is_save_label: continue try: data[shot] = int(input("please input label: ")) except ValueError: continue if len(data) == pdc.save_numbers: save_label(data) data = {}
def padding_len_to_same(shot): """ 将数据扩充为统一长度 :param shot: 炮号 :return: 包含5个通道的字典 """ _, gas = mh.read_channel(shot, "GasPuffing_FeedForward") _, m_d_h = mh.read_channel(shot, "Mag_detla_H") data = { "IP": ip_subtract_target_ip(shot), "HX": max_of_hx(shot), "Ha_MidPlane_1": re_sampling_ha(shot), "Mag_detla_H": m_d_h, "GasPuffing_" "FeedForward": gas[500:], } del gas, m_d_h for channel, value in data.items(): channel_len = min(tc.Channels_len[channel], len(value)) data[channel] = np.append(value[0:channel_len], np.zeros(tc.Signal_max_len - channel_len)) return data
def re_sampling_ha(shot): # 采样率不一样,只能先这样将就了 _, ha = mh.read_channel(shot, channel="Mag_detla_H") return ha[::10]
def max_of_hx(shot): _, hx1 = mh.read_channel(shot, channel="HX_1") _, hx2 = mh.read_channel(shot, channel="HX_2") # hx_len = min(len(hx1), len(hx2)) return np.maximum(hx1, hx2)
def ip_subtract_target_ip(shot): _, ip = mh.read_channel(shot, channel="IP") _, target_ip = mh.read_channel(shot, channel="Target_IP") ip_len = min(len(ip), len(target_ip), tc.Channels_len["IP"]) return ip[0:ip_len] - target_ip[0:ip_len]