def data_integration(tw_wave): try: new_tw_wave_ = [] wavelength_set = [] wavelength_standard_set = [] optical_order = [2, 0, 4, 1, 3, 5] for i_oo in optical_order: new_tw_wave_.append(tw_wave[i_oo]) for single_wavelength in new_tw_wave_: wavelength_counter = c_Counter(single_wavelength) wavelength_counter_max = max(wavelength_counter, key=wavelength_counter.get) wavelength_mean = sum(single_wavelength) / len(single_wavelength) wavelength_set.append([wavelength_counter_max, wavelength_mean]) wavelength_standard = (wavelength_counter_max + wavelength_mean) / 2 wavelength_standard_set.append(wavelength_standard) info('6个传感器的标准波长:') info(wavelength_standard_set) return new_tw_wave_, wavelength_standard_set except Exception as e: info('optical_fiber:', e)
def tw_txt_integration_display(tw_txt): tw_integration_ = [] if len(tw_txt) != 0: tw_txt_arr = array(tw_txt) for single_optical in tw_txt_arr: single_set_ = c_Counter(single_optical) single_max_ = max(single_set_, key=single_set_.get) tw_integration_.append(single_optical - single_max_) return tw_integration_
def data_integration(tw_wave): try: wave_max_set = [] new_tw_wave_ = [] new_arr_wave_ = [] optical_order = [2, 0, 4, 1, 3, 5] for i_oo in optical_order: new_tw_wave_.append(tw_wave[i_oo]) new_tw_wave_ *= 2 tw_arr = array(new_tw_wave_) for wave in tw_arr: if len(wave) != 0: wave_dict = c_Counter(wave) wave_max = max(wave_dict, key=wave_dict.get) new_arr_wave_.append(wave - wave_max) wave_max_set.append(wave_max) wave_display(new_tw_wave_) new_arr_ = data_calibration(new_arr_wave_) return new_tw_wave_, new_arr_ except Exception as e: info('optical_fiber:', e)
def optical_data_splitting_test(txt_list, frequency): try: wheel_count = 0 # 车轮数量计数 optical_all_data = [] # 一维的数据:所有传感器的数据;二维的数据:各个传感器所有的峰值 if len(txt_list) != 0: x_coordinate = [] all_each_optical_normalization = [] for each_optical in txt_list: x_wheel_set = [] max_wheel_set = [] max_wheel_single_set = [] each_optical_normalization = data_normalization(each_optical) all_each_optical_normalization.append( each_optical_normalization) y_after_filter = butter_lowpass_filter( each_optical_normalization, 500, 5000) max_single = [] for i in range(0, len(y_after_filter) - 200, 200): m = max(y_after_filter[i:i + 200]) if 0.4 < m: max_single.append(m) dividing_line = min(max_single) - 0.05 for i in range(len(each_optical)): x_coordinate.append(round(i / frequency, 4)) if each_optical_normalization[i] > dividing_line: wheel_set = [x_coordinate[i], each_optical[i]] x_wheel_set.append(wheel_set) max_wheel_single_set.append(x_wheel_set[0]) for i in range(1, len( x_wheel_set)): # 两数据之间间隔>=time_gap则视为两段,<time_gap视为一段 if x_wheel_set[i][0] - x_wheel_set[i - 1][0] < time_gap: max_wheel_single_set.append(x_wheel_set[i]) elif x_wheel_set[i][0] - x_wheel_set[i - 1][0] >= time_gap: max_wheel_set.append(max_wheel_single_set) max_wheel_single_set = [x_wheel_set[i]] if len(max_wheel_single_set) >= 2: max_wheel_set.append(max_wheel_single_set) x_data = [] if len(max_wheel_set) != 0: for max_wheel in max_wheel_set: if len(max_wheel) != 0: get_no = round(len(max_wheel) / 2) x_data.append(max_wheel[get_no][0]) wheel_dict = {} for i in range(len(each_optical)): wheel_dict.update({ round(x_coordinate[i], 4): round(each_optical[i], 12) }) last_wheel_value = list(wheel_dict)[-1] x_wheel_list = [] unit_interval = round(1 / frequency, 4) for x in x_data: if int(x / unit_interval) <= int( single_wheel_data_count / 2): x_list = [ round(unit_interval * a, 4) for a in range(single_wheel_data_count) ] x_wheel_list.append(x_list) elif int(single_wheel_data_count / 2) <= int( x / unit_interval) <= int( last_wheel_value / unit_interval) - int( single_wheel_data_count / 2): x_list = [ round(unit_interval * a, 4) for a in range( int(frequency * x) - int(single_wheel_data_count / 2), int(frequency * x) + int(single_wheel_data_count / 2)) ] x_wheel_list.append(x_list) else: x_list = [ round(unit_interval * a, 4) for a in range( int(frequency * last_wheel_value) - single_wheel_data_count, int(frequency * last_wheel_value)) ] x_wheel_list.append(x_list) y_wheel = [] y_single_optical = [] for x_wheel in x_wheel_list: for x_w in x_wheel: y_w = wheel_dict[x_w] y_wheel.append(y_w) y_single_optical.append(y_wheel) y_wheel = [] if len(y_single_optical) == 32: wheel_count += 1 # optical_all_data的输出格式:三维列表[12个传感器×32个车轮×600个数据][12×32×600]的矩阵 optical_all_data.append(y_single_optical) # 新增optical_all_data的size不一致的处理 len_list = [] for optical_data in optical_all_data: len_opt_data = len(optical_data) len_list.append(len_opt_data) zero_list = [] len_count = c_Counter(len_list) len_ = max(len_count, key=len_count.get) if len(len_count) != 1: zero_ = [0.0] * single_wheel_data_count for i in range(len_): zero_list.append(zero_) len_new_list = [] for i in range(len(optical_all_data)): len_opt_all_data_ = len(optical_all_data[i]) if len_opt_all_data_ != len_: optical_all_data[i] = zero_list len_opt_all_data_ = len(optical_all_data[i]) len_new_list.append(len_opt_all_data_) return optical_all_data except Exception as e: info(e)