def write_2_antennas_osc_csv(exp_num, file_nums): print(f'Experiment {exp_num}') test = ProcessSignal(str(exp_num)) nums_mtrx = np.reshape(np.asarray(file_nums), (int(len(file_nums) / 2), 2)) central_freq = 2.714E9 for j in range(nums_mtrx.shape[0]): antennas_data_dict = {} for i in range(nums_mtrx.shape[1]): file_num = f'{nums_mtrx[j, i]}' file_name = f'str{file_num}.csv' data = test.open_file(file_name, reduced=False) filt_freq_min, filt_freq_max = central_freq - 15e6, central_freq + 15e6 if int(nums_mtrx[j, i]) % 2 == 0: t, u = data['time'], data['voltage'] - np.mean(data['voltage']) u_filt = test.fft_filter(t, u, filt_freq_min, filt_freq_max) antennas_data_dict['t_main'], antennas_data_dict[ 'u_main'] = t, u antennas_data_dict['u_filt_main'] = u_filt plt.plot(t, u) else: #t, u = data['time'], (data['voltage'] - np.mean(data['voltage'])) / 3.16 t, u = data['time'], (data['voltage'] - np.mean(data['voltage'])) u_filt = test.fft_filter(t, u, filt_freq_min, filt_freq_max) antennas_data_dict['t'], antennas_data_dict['u'] = t, u antennas_data_dict['u_filt'] = u_filt plt.plot(t + 4.347E-9, u) plt.show() print(f'Writing {nums_mtrx[j, i]} csv file...') print(antennas_data_dict.keys()) dif_file_path = test.exp_file_path / '2_antennas_CSV' dif_file_path.mkdir(parents=True, exist_ok=True) file = open(str(dif_file_path / f'{nums_mtrx[j, 0]}_{nums_mtrx[j, 1]}.csv'), 'w', newline='') with file: writer = csv.writer(file) writer.writerow([ 't_main(s)', 'V_main(V)', 'V_main_filt(V)', 't(s)', 'V(V)', 'V_filt(V)' ]) for i in range( 1, max(len(antennas_data_dict['t_main']), len(antennas_data_dict['t']))): writer.writerow([ antennas_data_dict['t_main'][i], antennas_data_dict['u_main'][i], antennas_data_dict['u_filt_main'][i], antennas_data_dict['t'][i], antennas_data_dict['u'][i], antennas_data_dict['u_filt'][i] ])
nums, n_s, mean_freqs = [], [], [] noise_freqs, noise_ns, n_nums = [], [], [] for signal in csv_signals:proc = ProcessSignal('201110') csv_types = proc.read_type_file() csv_signals = csv_types['signal_files'] csv_signal_nums = csv_types['signal_nums'] excel_dicts = proc.read_excel(csv_signal_nums)['numbers'] noise_nums = excel_dicts['noise'] magnetron_nums = excel_dicts['magnetron'][:18:] num = signal[3:6] if num in magnetron_nums: file = proc.open_file(signal, reduced=True) u = file['voltage'] t = file['time'] u_filt = proc.fft_filter(t, u, 2.695e9, 2.725e9, filt_type='bandstop') dt = file['time_resolution'] dt_2 = (t[-1] - t[0]) ** 2 pl_density = proc.read_excel(signal)['dicts'][num]['Ток плазмы, А'] fft_data = proc.fft_amplitude(t, u_filt) freqs, amps = fft_data['frequency'], fft_data['amplitude'] mean_freq = proc.mean_frequency(freqs, amps)['mean_freq'] nums.append(num) n_s.append(pl_density) mean_freqs.append(mean_freq) if num in noise_nums: file = proc.open_file(signal, reduced=True) u = file['voltage']
def all_integrals_proc(exp_num, nums, table=True, central_freq=2.714, band_half_width=0.05): proc = ProcessSignal(str(exp_num)) csv_types = proc.read_type_file() csv_signals = csv_types['signal_files'] csv_signal_nums = csv_types['signal_nums'] excel_dicts = proc.read_excel(csv_signal_nums)['numbers'] noise_nums = [ str(int(excel_dicts['noise'][i]) + 1) for i in range(len(excel_dicts['noise'])) if int(excel_dicts['noise'][i]) + 1 in nums ] magnetron_nums = [ str(int(excel_dicts['magnetron'][i]) + 1) for i in range(len(excel_dicts['magnetron'])) if int(excel_dicts['magnetron'][i]) + 1 in nums ] print('Noise:', noise_nums, '\n', 'Amplifier:', magnetron_nums) nums, n_s, full_ints, peak_ints = [], [], [], [] noise_ints, noise_ns, n_nums = [], [], [] for signal in csv_signals: num = signal[3:6] if num in magnetron_nums: file = proc.open_file(signal, reduced=True) u = file['voltage'] t = file['time'] f_low = (central_freq - band_half_width) * 1e9 f_high = (central_freq + band_half_width) * 1e9 u_filt = proc.fft_filter(t, u, f_low, f_high) dt_2 = (t[-1] - t[0])**2 pl_density = proc.read_excel(signal)['dicts'][num]['Ток плазмы, А'] integral = np.round(proc.e_square(t, u) / 1e-8, 3) filt_int = np.round(proc.e_square(t, u_filt) / 1e-8, 3) freqs, amps = proc.fft_amplitude( t, u)['frequency'], proc.fft_amplitude(t, u)['amplitude'] peak_inds = np.logical_and(freqs >= f_low, freqs <= f_high) p_freqs, p_amps = freqs[peak_inds], amps[peak_inds] full_int = np.round(dt_2 * proc.e_square(freqs, amps) / 2e-8, 3) peak_int = np.round(dt_2 * proc.e_square(p_freqs, p_amps) / 2e-8, 3) n_s.append(pl_density) nums.append(num) full_ints.append(full_int) peak_ints.append(peak_int) print('peak_int = ', np.round(integral, 2), 'noise_int =', np.round(integral - filt_int, 2), 'noise_fft =', np.round(full_int - peak_int, 2)) if num in noise_nums: file = proc.open_file(signal, reduced=True) u = file['voltage'] t = file['time'] dt = file['time_resolution'] f_low = (central_freq - band_half_width) * 1e9 f_high = (central_freq + band_half_width) * 1e9 u_filt = proc.fft_filter(t, u, f_low, f_high) dt_2 = (t[-1] - t[0])**2 pl_density = proc.read_excel(signal)['dicts'][num]['Ток плазмы, А'] freqs, amps = proc.fft_amplitude( t, u)['frequency'], proc.fft_amplitude(t, u)['amplitude'] noise_int = np.round(dt_2 * proc.e_square(freqs, amps) / 2e-8, 3) noise_ints.append(noise_int) noise_ns.append(pl_density) n_nums.append(num) ind_sort = np.argsort(np.asarray(n_s)) ns_sort = np.asarray(n_s)[ind_sort] nums_sort = np.asarray(nums)[ind_sort] full_ints_sort, peak_ints_sort = np.asarray( full_ints)[ind_sort], np.asarray(peak_ints)[ind_sort] print('Sorted amplifier numbers:', nums_sort) n_ind_sort = np.argsort(np.asarray(noise_ns)) noise_ns_sort, n_nums_sort, noise_ints_sort = np.asarray( noise_ns)[n_ind_sort], np.asarray(n_nums)[n_ind_sort], np.asarray( noise_ints)[n_ind_sort] print('Sorted noise numbers:', n_nums_sort) if table: ex_table = excel.Workbook() ex_table.create_sheet(title='Integral', index=0) sheet = ex_table['Integral'] sheet['A1'] = 'Номер(шум)' sheet['B1'] = 'Плотность плазмы, отн.ед.' sheet['C1'] = 'W_f0, *10-8' sheet['D1'] = 'W_1, *10-8' sheet['F1'] = 'Номер' sheet['G1'] = 'Плотность плазмы, отн.ед.' sheet['H1'] = 'W_2, *10-8' for z in range(full_ints_sort.size): cell = sheet.cell(row=z + 2, column=1) cell.value = int(nums_sort[z]) cell = sheet.cell(row=z + 2, column=2) cell.value = ns_sort[z] cell = sheet.cell(row=z + 2, column=3) cell.value = peak_ints_sort[z] cell = sheet.cell(row=z + 2, column=4) cell.value = full_ints_sort[z] - peak_ints_sort[z] for k in range(noise_ints_sort.size): cell = sheet.cell(row=k + 2, column=6) cell.value = int(n_nums_sort[k]) cell = sheet.cell(row=k + 2, column=7) cell.value = noise_ns_sort[k] cell = sheet.cell(row=k + 2, column=8) cell.value = noise_ints_sort[k] path = proc.excel_folder_path / f'Integrals_{exp_num}_2_antennas.xlsx' ex_table.save(path) else: noise_dict = { 'nums': n_nums_sort, 'density_vals': noise_ns_sort, 'w_2': noise_ints_sort } magnetron_dict = { 'nums': nums_sort, 'density_vals': ns_sort, 'w_f0': peak_ints_sort, 'w_1': full_ints_sort - peak_ints_sort } return noise_dict, magnetron_dict
def two_antennas_ampl_relate(exp_num, file_nums, pts): print(f'Experiment {exp_num}') test = ProcessSignal(str(exp_num)) nums_mtrx = np.reshape(np.asarray(file_nums), (int(len(file_nums) / 2), 2)) print(nums_mtrx) central_freq = 2.714E9 compare_pts = [pts[i] * 1E-9 for i in range(len(pts))] for pt in compare_pts: for j in range(nums_mtrx.shape[0]): for i in range(nums_mtrx.shape[1]): print(nums_mtrx[j, i], 'pt=', np.round(pt / 1e-9, 1)) file_num = f'{nums_mtrx[j, i]}' file_name = f'str{file_num}.csv' data = test.open_file(file_name, reduced=False) filt_freq_min, filt_freq_max = central_freq - 15e6, central_freq + 15e6 if int(nums_mtrx[j, i]) % 2 == 0: t, u = data['time'], data['voltage'] - np.mean( data['voltage']) plt.plot(t, u) plt.show() plt.close() u_filt = test.fft_filter(t, u, filt_freq_min, filt_freq_max) #pl_density = test.read_excel(file_name)['dicts'][file_num]['Ток плазмы, А'] ind_mask = np.logical_and(t >= pt, t <= pt + 1E-9) t, u = t[ind_mask], u[ind_mask] peak_dict = find_zeros(t, u) time_max, volt_max, time_min, volt_min = peak_dict[ 'time_max'], peak_dict['volt_max'], peak_dict[ 'time_min'], peak_dict['volt_min'] delta_main = volt_max - volt_min print('volt_max =', volt_max, 'time_max', time_max) u_filt = u_filt[ind_mask] filt_dict = find_zeros(t, u_filt) time_max_filt, volt_max_filt = filt_dict[ 'time_max'], filt_dict['volt_max'] time_min_filt, volt_min_filt = filt_dict[ 'time_min'], filt_dict['volt_min'] delta_main_filt = volt_max_filt - volt_min_filt plt.plot(t, u) plt.plot(time_min, volt_min, marker='o') plt.plot(time_max, volt_max, marker='o') else: #t, u = data['time'] + 4.347E-9, (data['voltage'] - np.mean(data['voltage'])) t, u = data['time'], (data['voltage'] - np.mean(data['voltage'])) plt.plot(t, u) plt.show() plt.close() u_filt = test.fft_filter(t, u, filt_freq_min, filt_freq_max) ind_mask = np.logical_and(t >= pt, t <= pt + 1E-9) t, u = t[ind_mask], u[ind_mask] peak_dict = find_zeros(t, u) time_max, volt_max, time_min, volt_min = peak_dict[ 'time_max'], peak_dict['volt_max'], peak_dict[ 'time_min'], peak_dict['volt_min'] delta_sub = volt_max - volt_min print('volt_max =', volt_max, 'time_max', time_max) u_filt = u_filt[ind_mask] filt_dict = find_zeros(t, u_filt) time_max_filt, volt_max_filt = filt_dict[ 'time_max'], filt_dict['volt_max'] time_min_filt, volt_min_filt = filt_dict[ 'time_min'], filt_dict['volt_min'] delta_sub_filt = volt_max_filt - volt_min_filt #plt.plot(t, u_filt) #plt.plot(time_min_filt, volt_min_filt, marker='o') #plt.plot(time_max_filt, volt_max_filt, marker='o') u_relat_filt = delta_main_filt / delta_sub_filt u_relat = delta_main / delta_sub print('Отн_без_фильтра:', np.round(u_relat, 3)) print('Oтн_фильтр:', np.round(u_relat_filt, 3))
def two_antennas_max_table(exp_num, file_nums): print(f'Experiment {exp_num}') test = ProcessSignal(str(exp_num)) nums_mtrx = np.reshape(np.asarray(file_nums), (int(len(file_nums) / 2), 2)) print(nums_mtrx) central_freq = 2.714E9 pts = [100, 200, 300, 400] compare_pts = [pts[i] * 1E-9 for i in range(len(pts))] col_nums = [i for i in range(3, 3 + len(compare_pts))] print(col_nums) ex_table = excel.Workbook() ex_table.create_sheet(title='Integral', index=0) sheet = ex_table['Integral'] sheet['A1'] = exp_num sheet['A2'] = 'No (центр/бок)' sheet['B2'] = 'n, отн.ед.' sheet['C1'] = 'Без фильтра' sheet[f'{get_column_letter(3 + len(compare_pts) +1)}1'] = 'Фильтрованный' for n in range(len(col_nums)): letter = get_column_letter(col_nums[n]) sheet[ f'{letter}2'] = f't_{n + 1} = {np.round(compare_pts[n] / 1e-9, 0)}' filt_letter = get_column_letter(col_nums[n] + len(col_nums) + 1) sheet[ f'{filt_letter}2'] = f't_{n + 1} = {np.round(compare_pts[n] / 1e-9, 0)} c' for k, pt in enumerate(compare_pts): for j in range(nums_mtrx.shape[0]): antennas_data_dict = {} for i in range(nums_mtrx.shape[1]): print(nums_mtrx[j, i], 'pt=', pt) file_num = f'{nums_mtrx[j, i]}' file_name = f'str{file_num}.csv' data = test.open_file(file_name, reduced=False) filt_freq_min, filt_freq_max = central_freq - 15e6, central_freq + 15e6 if int(nums_mtrx[j, i]) % 2 == 0: t, u = data['time'], data['voltage'] - np.mean( data['voltage']) u_filt = test.fft_filter(t, u, filt_freq_min, filt_freq_max) pl_density = test.read_excel( file_name)['dicts'][file_num]['Ток плазмы, А'] ind_mask = np.logical_and(t >= pt, t <= pt + 1E-9) t, u = t[ind_mask], u[ind_mask] peak_dict = find_zeros(t, u) time_max, volt_max, time_min, volt_min = peak_dict[ 'time_max'], peak_dict['volt_max'], peak_dict[ 'time_min'], peak_dict['volt_min'] delta_main = volt_max - volt_min u_filt = u_filt[ind_mask] filt_dict = find_zeros(t, u_filt) time_max_filt, volt_max_filt = filt_dict[ 'time_max'], filt_dict['volt_max'] time_min_filt, volt_min_filt = filt_dict[ 'time_min'], filt_dict['volt_min'] delta_main_filt = volt_max_filt - volt_min_filt cell = sheet.cell(row=j + 3, column=2) cell.value = f'{pl_density}' plt.plot(t, u) plt.plot(time_min, volt_min, marker='o') plt.plot(time_max, volt_max, marker='o') else: t_shift = 4.347E-9 t_shift = 0 t, u = data['time'] + t_shift, (data['voltage'] - np.mean(data['voltage'])) u_filt = test.fft_filter(t, u, filt_freq_min, filt_freq_max) ind_mask = np.logical_and(t >= pt, t <= pt + 1E-9) t, u = t[ind_mask], u[ind_mask] peak_dict = find_zeros(t, u) time_max, volt_max, time_min, volt_min = peak_dict[ 'time_max'], peak_dict['volt_max'], peak_dict[ 'time_min'], peak_dict['volt_min'] delta_sub = volt_max - volt_min u_filt = u_filt[ind_mask] filt_dict = find_zeros(t, u_filt) time_max_filt, volt_max_filt = filt_dict[ 'time_max'], filt_dict['volt_max'] time_min_filt, volt_min_filt = filt_dict[ 'time_min'], filt_dict['volt_min'] delta_sub_filt = volt_max_filt - volt_min_filt plt.plot(t, u_filt) plt.plot(time_min_filt, volt_min_filt, marker='o') plt.plot(time_max_filt, volt_max_filt, marker='o') u_relat_filt = delta_main_filt / delta_sub_filt u_relat = delta_main / delta_sub column = col_nums[k] column_filt = column + len(compare_pts) + 1 cell = sheet.cell(row=j + 3, column=column) cell.value = f'{np.round(u_relat, 3)}' cell = sheet.cell(row=j + 3, column=column_filt) cell.value = f'{np.round(u_relat_filt, 3)}' print(u_relat_filt) plt.title(nums_mtrx[j, i]) #plt.show() cell = sheet.cell(row=j + 3, column=1) cell.value = f'{int(nums_mtrx[j, i]) -1 } / {nums_mtrx[j, i]}' path = test.excel_folder_path / f'Ampl_{exp_num}_2_antennas_123_129.xlsx' ex_table.save(path)
ind_mask = np.logical_and(low_freq < freqs_fft, freqs_fft < high_freq) bandpass_filter = np.zeros(len(fft_u)) bandpass_filter[ind_mask] = 1 b_filt_u = irfft(fft_u * bandpass_filter) return b_filt_u ''' file_data = open_file(file) t, u = file_data['t'], np.asarray(file_data['u']) fft_u = fft_filter(t, u) origin_data = open_file(origin_filt_file, filtered=True) t_filt_or, u_filt_or = origin_data['t_filt'], origin_data['u_filt'] ''' #plt.plot(t, u) #plt.plot(t, fft_u) #plt.plot(t_filt_or, u_filt_or) #plt.show() proc = ProcessSignal('201111') file = 'str019.csv' file_data = proc.open_file(file) t, u = file_data['time'], file_data['voltage'] fft_filt_u = proc.fft_filter(t, u) bandpass_u = proc.bandpass_filter(t, u, 2.695e9, 2.725e9) new_file_path = path / 'new_file_19_1.csv' new_file = open(str(new_file_path), 'w', newline='') with new_file: writer = csv.writer(new_file) for i in range(0, len(t)): writer.writerow([0, 0, 0, t[i], u[i], fft_filt_u[i], bandpass_u[i]])