def oscillograms(): test = ProcessSignal('191106') csv_types = test.read_type_file() csv_signals = csv_types['signal_files'] csv_signal_nums = csv_types['signal_nums'] excel_dicts = test.read_excel(csv_signal_nums)['numbers'] magnetron_nums = excel_dicts['magnetron'] for signal in csv_signals: file = test.open_file(signal, reduced=True) u = file['voltage'] t = file['time'] dt = file['time_resolution'] u_filt = test.bandpass_filter(t, u, 2.725e9, 2.755e9) num = signal[3:6] if int(num) < 66: absorbers = '№2, 3' elif 66 <= int(num) < 125 and num in magnetron_nums: absorbers = 0 elif 125 <= int(num) <= 184 and num in magnetron_nums: absorbers = '№2, 3, A' else: absorbers = 0 pl_d_nums = test.read_excel(csv_signal_nums)['dicts'].keys() if num in pl_d_nums: pl_density = test.read_excel(csv_signal_nums)['dicts'][num]['Ток плазмы, А'] test.oscill_picture(num, t, u, u_filt, pl_density, absorbers, save=True)
def pulse_duration(): test = ProcessSignal('190925') csv_types = test.read_type_file() csv_signals = csv_types['signal_files'] csv_signal_nums = csv_types['signal_nums'] pl_d_nums = test.read_excel(csv_signal_nums)['dicts'].keys() t_difs = [] pl_ds = [] for signal in csv_signals: file = test.open_file(signal) u = file['voltage'] t = file['time'] dt = file['time_resolution'] envelope = test.useful_part(t, u, dt) t_use, u_use = envelope['signal_time'], envelope['signal_voltage'] t_dif = t_use[-1] - t_use[0] t_difs.append(t_dif) num = signal[3:6] if num in pl_d_nums: pl_density = test.read_excel(csv_signal_nums)['dicts'][num]['Ток плазмы, А'] pl_ds.append(pl_density) pl_ds = np.array(pl_ds) t_difs = np.array(t_difs) sorted_inds = np.argsort(pl_ds) pl_ds_sorted = pl_ds[sorted_inds] t_difs_sorted = t_difs[sorted_inds] plt.plot(pl_ds_sorted, t_difs_sorted) #plt.plot(t_use, u_use) plt.show()
def noise_integrals_block(exp_num, file_nums): proc = ProcessSignal(str(exp_num)) shot_nums, density_vals, full_ints = [], [], [] for num in file_nums: file_name = f'str{num}.csv' file = proc.open_file(file_name, reduced=True) u = file['voltage'] t = file['time'] dt_2 = (t[-1] - t[0])**2 pl_density = proc.read_excel(file_name)['dicts'][num]['Ток плазмы, А'] freqs, amps = proc.fft_amplitude(t, u)['frequency'], proc.fft_amplitude( t, u)['amplitude'] full_int = np.round(dt_2 * proc.e_square(freqs, amps) / 2e-8, 3) density_vals.append(pl_density) shot_nums.append(num) full_ints.append(full_int) sorted_inds = np.argsort(density_vals) density_vals = np.asarray(density_vals)[sorted_inds] shot_nums = np.asarray(shot_nums)[sorted_inds] full_ints = np.asarray(full_ints)[sorted_inds] integrals_dict = { 'nums': shot_nums, 'density': density_vals, 'full_ints': full_ints } return integrals_dict
def two_antennas_time_max_dif(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() #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'] time_max_ch_1 = time_max print('volt_max =', volt_max, 'time_max', np.round(time_max / 1e-9, 3)) plt.plot(t, u) plt.plot(time_max, volt_max, marker='o') else: t, u = data['time'], (data['voltage'] - np.mean(data['voltage'])) #plt.plot(t, u) #plt.show() #plt.close() 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'] time_max_ch_2 = time_max print('volt_max =', volt_max, 'time_max', np.round(time_max / 1e-9, 3)) plt.plot(t, u) plt.plot(time_max, volt_max, marker='o') #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') plt.show() u_dif = time_max_ch_2 - time_max_ch_1 print('raw_u_dif', u_dif / 1e-12) print('time_dif =', np.round(u_dif / 1e-12))
def amp_max(): test = ProcessSignal('191001') csv_types = test.read_type_file() csv_signals = csv_types['signal_files'] csv_signal_nums = csv_types['signal_nums'] excel_dicts = test.read_excel(csv_signal_nums)['numbers'] magnetron_nums = excel_dicts['magnetron'] m_1_nums = [] m_2_nums = [] m_3_nums = [] for num in magnetron_nums: if 35 <= int(num) < 79: m_1_nums.append(num) elif 79 <= int(num) < 111: m_2_nums.append(num) elif 127 <= int(num) <= 150: m_3_nums.append(num) m_lists = [m_1_nums, m_2_nums, m_3_nums] labels_list = ['№2, 3', '№2, 3, A, Б, В', '№2, 3, A', 'Шум'] fig = plt.figure(num=1, dpi=200, figsize=[11.69, 8.27]) ax = fig.add_subplot(111) ax.set_prop_cycle(color=['blue', 'green', 'deepskyblue']) for i, list in enumerate(m_lists): u_maxs = [] pl_ds = [] for csv_signal in csv_signals: csv_num = csv_signal[3:6] for num in list: if csv_num == num: file = test.open_file(csv_signal) u = file['voltage'] t = file['time'] red_dict = test.proc_part_130_290(t, u) red_u = red_dict['part_u'] red_t = red_dict['part_t'] u_filt = test.bandpass_filter(red_t, red_u, 2.709e9, 2.769e9) u_max = np.max(np.array(u_filt)) pl_d = test.read_excel(csv_signal_nums)['dicts'][num]['Ток плазмы, А'] u_maxs.append(u_max) pl_ds.append(pl_d) sorted_inds = np.argsort(np.array(pl_ds)) pl_ds = np.array(pl_ds) pl_ds = pl_ds[sorted_inds] u_maxs = np.array(u_maxs) u_maxs = u_maxs[sorted_inds] line, = plt.plot(pl_ds, u_maxs, marker='o', linewidth=2) line.set_label('{}'.format(labels_list[i])) ax.set_ylim(bottom=0) ax.set_xlim(left=4, right=9) ax.set_xlabel(r'$Plasma\/density, arb.units $', fontsize=14) ax.set_ylabel(r'$Max\/amplitude$', fontsize=14) ax.grid(which='both', axis='both') ax.legend(loc='best', fontsize=16) ax.set_title('Max amplitude', fontsize=20) png_name = test.pics_path / 'max_amp.png' plt.savefig(png_name) plt.show()
def load_red_csv(): test = ProcessSignal('191001') types = test.read_type_file() csv_signals = types['signal_files'] for signal in csv_signals: open_dict = test.open_file(signal, reduced=True) t = open_dict['time'] u = open_dict['voltage'] plt.plot(t, u) plt.show()
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] ])
def two_exp_integrals(exp_num, table=False, data=True): test = ProcessSignal('{}'.format(exp_num)) csv_types = test.read_type_file() csv_signals = csv_types['signal_files'] pl_densities = np.zeros(len(csv_signals)) integrals = np.zeros(len(csv_signals)) nums = np.zeros(len(csv_signals)) csv_path = test.csv_files_path csv_dir_files = os.listdir(csv_path) test.reduce_fft() for i, csv_signal in enumerate(csv_signals): csv_signal_num = csv_signal[3:6] if csv_signal in csv_dir_files: file = test.open_file(csv_signal, reduced=True) pl_density = test.read_excel(csv_signal)['dicts'][csv_signal_num]['Ток плазмы, А'] pl_densities[i] = pl_density nums[i] = csv_signal_num t, u, dt = file['time'], file['voltage'], file['time_resolution'] plt.plot(t, u) integrals[i] = np.round(test.e_square(t, u) / 1e-7, 2) print(csv_signal_num, integrals[i]) plt.title("№ {}, e^2 = {}".format(csv_signal_num, integrals[i])) #plt.show() sorted_inds = np.argsort(pl_densities) pl_densities = pl_densities[sorted_inds] integrals = integrals[sorted_inds] nums = nums[sorted_inds] if table: ex_table = excel.Workbook() ex_table.create_sheet(title='Integral', index=0) sheet = ex_table['Integral'] sheet['A1'] = 'Номер' sheet['B1'] = 'Плотность плазмы, отн.ед.' sheet['C1'] = 'Интеграл, *10-8' table_size = integrals.size for k in range(table_size): cell = sheet.cell(row=k+2, column=1) cell.value = nums[k] cell = sheet.cell(row=k+2, column=2) cell.value = pl_densities[k] cell = sheet.cell(row=k+2, column=3) cell.value = integrals[k] path = test.excel_folder_path / 'Integral_{}.xlsx'.format(exp_num) ex_table.save(path) if data: integral_dict = {'pl_ds': pl_densities, 'integral_vals': integrals, 'shot_nums': nums} return integral_dict
def fft_amp_test(): test = ProcessSignal('191011') types = test.read_type_file() csv_signals = types['signal_files'] for signal in csv_signals: open_dict = test.open_file(signal, reduced=True) t = open_dict['time'] u = open_dict['voltage'] dt = open_dict['time_resolution'] amp_dict = test.fft_amplitude(t, u, dt) freq = amp_dict['frequency'] amp = amp_dict['amplitude'] plt.plot(freq, amp) plt.show()
def peak_mean_freq_calc(exp_num, central_freq=2.714e9, band_half_width=50e6): proc = ProcessSignal(f'{exp_num}') types = proc.read_type_file() csv_signals, csv_signal_nums = types['signal_files'], types['signal_nums'] excel_results = proc.read_excel(csv_signal_nums)['numbers'] magnetron_nums = excel_results['magnetron'] m_nums, m_plasma_dens, m_mean_freqs = [], [], [] for num in magnetron_nums: file_name = f'str{num}.csv' file_data = proc.open_file(file_name, reduced=True) t, u, dt = file_data['time'], file_data['voltage'], file_data['time_resolution'] pl_density = proc.read_excel(file_name)['dicts'][num]['Ток плазмы, А'] fft_results = proc.fft_amplitude(t, u) freqs, amps = fft_results['frequency'], fft_results['amplitude'] left_boundary, right_boundary = central_freq - band_half_width, central_freq + band_half_width noise_base_inds = np.logical_and(freqs >= left_boundary, freqs <= right_boundary) noise_base_freqs, noise_base_amps = freqs[noise_base_inds], amps[noise_base_inds] mean_freq = proc.mean_frequency(noise_base_freqs, noise_base_amps) spectrum_mean_freq = mean_freq['mean_freq'] m_nums.append(num), m_plasma_dens.append(pl_density), m_mean_freqs.append(spectrum_mean_freq) m_sorted_inds = np.argsort(np.asarray(m_plasma_dens)) m_nums_sort = np.asarray(m_nums)[m_sorted_inds] m_plasma_dens_sort = np.asarray(m_plasma_dens)[m_sorted_inds] m_mean_freqs_sort = np.asarray(m_mean_freqs)[m_sorted_inds] ex_table = xl.Workbook() ex_table.create_sheet(title='Mean_freq', index=0) sheet = ex_table['Mean_freq'] sheet['A1'] = 'Номер' sheet['B1'] = 'Плотность плазмы, отн.ед.' sheet['C1'] = 'Средняя частота, ГГц' for k in range(m_nums_sort.size): cell = sheet.cell(row=k + 2, column=1) cell.value = int(m_nums_sort[k]) cell = sheet.cell(row=k + 2, column=2) cell.value = m_plasma_dens_sort[k] cell = sheet.cell(row=k + 2, column=3) cell.value = m_mean_freqs_sort[k] path = proc.excel_folder_path / f'Mean_freq_{exp_num}_test.xlsx' ex_table.save(path) #peak_mean_freq_calc(210322)
def intgrals_calc_25(): #magnetron_in_vals = [8.7, 10.7, 13] test = ProcessSignal('201008') csv_files_list = os.listdir(test.csv_files_path) csv_types = test.read_type_file() csv_signals = csv_types['signal_files'] csv_signal_nums = csv_types['signal_nums'] excel_dicts = test.read_excel(csv_signal_nums)['numbers'] magnetron_nums = excel_dicts['magnetron'] reb_nums = excel_dicts['noise'] #m_classif_dict = m_signals_classification(magnetron_in_vals, magnetron_nums) magnetron_dict = {} reb_dict = {} for csv_signal in csv_signals: if csv_signal in csv_files_list: num = csv_signal[3:6] file = test.open_file(csv_signal, reduced=True) t, u = file['time'], file['voltage'] pl_density = test.read_excel(csv_signal)['dicts'][num]['Ток плазмы, А'] full_integral = np.round(test.e_square(t, u) / 1e-8, 3) if num in reb_nums: reb_dict[num] = {'n': pl_density, 'full_integral': full_integral, 'num': num} else: len_t = len(t) dt = np.abs(t[1] - t[0]) fft_u = rfft(u) freqs_fft = rfftfreq(len_t, dt) ind_mask = np.logical_and(2.695e9 < freqs_fft, freqs_fft < 2.725e9) u_empty = np.zeros(len(ind_mask)) u_empty[ind_mask] = fft_u[ind_mask] fft_filtered_u = irfft(u_empty) #plt.plot(t, u, color='k') #plt.plot(t, fft_filtered_u) #plt.show() absorbers = test.read_excel(csv_signal)['dicts'][num]['Поглотители в тракте магнетрона'] filtered_integral = np.round(test.e_square(t, fft_filtered_u) / 1e-8, 3) pedestal_integral = full_integral - filtered_integral magnetron_dict[num] = {'n': pl_density, 'full_integral': full_integral, 'peak_integral': filtered_integral, 'pedestal_integral': pedestal_integral, 'abs': absorbers, 'num': num} plt.plot(pl_density, full_integral, color='blue', marker='o') plt.plot(pl_density, filtered_integral, color='red', marker='o', linestyle='-') return reb_dict, magnetron_dict
def magnetron_integrals_bloc(exp_num, file_nums, central_freq=2.714, band_half_width=0.05): proc = ProcessSignal(str(exp_num)) shot_nums, density_vals, full_ints, peak_ints, exp_nums = [], [], [], [], [] for num in file_nums: file_name = f'str{num}.csv' file = proc.open_file(file_name, reduced=True) u = file['voltage'] t = file['time'] f_low = (central_freq - band_half_width) * 1e9 f_high = (central_freq + band_half_width) * 1e9 dt_2 = (t[-1] - t[0])**2 #pl_num = f'{(int(num) - 1):03d}' pl_density = proc.read_excel(file_name)['dicts'][num]['Ток плазмы, А'] 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) density_vals.append(pl_density) shot_nums.append(num) full_ints.append(full_int) peak_ints.append(peak_int) exp_nums.append(exp_num) sorted_inds = np.argsort(density_vals) density_vals = np.asarray(density_vals)[sorted_inds] shot_nums = np.asarray(shot_nums)[sorted_inds] full_ints, peak_ints = np.asarray(full_ints)[sorted_inds], np.asarray( peak_ints)[sorted_inds] integrals_dict = { 'nums': shot_nums, 'density': density_vals, 'full_ints': full_ints, 'peak_ints': peak_ints, 'exp_nums': exp_nums } return integrals_dict
def e_square_spectra(exp_num, signal_type='magnetron', scale='log'): proc = ProcessSignal(f'{exp_num}') types = proc.read_type_file() csv_signals, csv_signal_nums = types['signal_files'], types['signal_nums'] excel_results = proc.read_excel(csv_signal_nums)['numbers'] if signal_type == 'magnetron': nums_for_proc = excel_results['magnetron'] elif signal_type == 'noise': nums_for_proc = excel_results['noise'] for num in nums_for_proc: file_name = f'str{num}.csv' file_data = proc.open_file(file_name, True) t, u = file_data['time'], file_data['voltage'] fft_data = proc.fft_amplitude(t, u * u) freqs, amps = fft_data['frequency'][2::], fft_data['amplitude'][2::] inds = freqs <= 4e9 freqs_4, amps_4 = freqs[inds], amps[inds] pl_dens = proc.read_excel(file_name)['dicts'][num]['Ток плазмы, А'] fig = plt.figure(num=1, dpi=300) ax = fig.add_subplot(111) line, = ax.plot(freqs_4, amps_4) ax.set_xlim(left=1e9, right=4e9) if scale == 'log': ax.set_yscale('log') ax.set_ylim(bottom=10**(-5)) pic_name = r'Спектр квадрата напряжения\Логарифмический\ u_2_log_{}'.format(num) else: ax.set_ylim(bottom=0) pic_name = r'Спектр квадрата напряжения\Обычный\ u_2_{}'.format(num) ax.grid(which='both', axis='both') ax.set_title(r'$№={}, n={}$'.format(num, pl_dens)) png_name = proc.fft_pics_path / pic_name fig.savefig(png_name) plt.close(fig) plt.show()
def peak_width(exp_num): exp = ProcessSignal(str(exp_num)) types = exp.read_type_file() csv_signals = types['signal_files'] csv_signal_nums = types['signal_nums'] excel_results = exp.read_excel(csv_signal_nums)['numbers'] m_nums = excel_results['magnetron'] #m_nums = [excel_results['magnetron'][i] for i in range(len(excel_results['magnetron'])) if int(excel_results['magnetron'][i]) >= 125] nums = np.zeros(len(m_nums)) widths = np.zeros(len(m_nums)) np_s = np.zeros(len(m_nums)) k = 0 for i, csv_signal in enumerate(csv_signals): signal_num = csv_signal[3:6] if signal_num in m_nums: file = exp.open_file(csv_signal, reduced=True) use_t = file['time'] use_u = file['voltage'] dt = file['time_resolution'] fft_results = exp.fft_amplitude(use_t, use_u) freqs = fft_results['frequency'][1::] amps = fft_results['amplitude'][1::] np_s[k] = exp.read_excel( csv_signal_nums)['dicts'][signal_num]['Ток плазмы, А'] nums[k] = signal_num half_peak = max(amps) / 2 mean_freq = freqs[np.argmax(amps)] ''' plt.plot(freqs, amps) plt.plot(mean_freq, half_peak, color='red', marker='o') plt.show() ''' #half_peak_points inds = np.arange(0, len(amps)) r_bool_inds = freqs >= mean_freq r_inds = inds[r_bool_inds] w = 0 while amps[r_inds[w]] >= half_peak: w += 1 under_hp_r_ind = r_inds[w] over_hp_r_ind = r_inds[w - 1] under_hp_r_amp, under_hp_r_freq = amps[under_hp_r_ind], freqs[ under_hp_r_ind] over_hp_r_amp, over_hp_r_freq = amps[over_hp_r_ind], freqs[ over_hp_r_ind] print('under_ind:', under_hp_r_ind) # right_part x_r = np.array([over_hp_r_freq, under_hp_r_freq]) y_r = np.array([over_hp_r_amp, under_hp_r_amp]) k_r, b_r, r_value_r, p_value_r, std_err_r = linregress(x_r, y_r) right_x_interp = np.linspace(over_hp_r_freq, under_hp_r_freq, num=200) right_interp = k_r * right_x_interp + b_r right_inds = right_interp <= half_peak linreg_right_freq = right_x_interp[right_inds][0] #left_part l_bool_inds = freqs <= mean_freq l_inds = inds[l_bool_inds][::-1] t = 0 while amps[l_inds[t]] >= half_peak: t += 1 under_hp_l_ind = l_inds[t] over_hp_l_ind = l_inds[t - 1] under_hp_l_amp, under_hp_l_freq = amps[under_hp_l_ind], freqs[ under_hp_l_ind] over_hp_l_amp, over_hp_l_freq = amps[over_hp_l_ind], freqs[ over_hp_l_ind] x_l = np.array([over_hp_l_freq, under_hp_l_freq]) y_l = np.array([over_hp_l_amp, under_hp_l_amp]) k_l, b_l, l_value_l, p_value_l, std_err_l = linregress(x_l, y_l) left_x_interp = np.linspace(under_hp_l_freq, over_hp_l_freq, num=200) left_interp = k_l * left_x_interp + b_l left_inds = left_interp <= half_peak linreg_left_freq = left_x_interp[left_inds][-1] ''' plt.plot(freqs, amps) plt.plot(under_hp_l_freq, under_hp_l_amp, color='red', marker='o') plt.plot(over_hp_l_freq, over_hp_l_amp, color='green', marker='o') plt.plot(linreg_left_freq, half_peak, color='blue', marker='o') plt.title(f'{signal_num}') plt.show() ''' half_peak_width = np.round( ((linreg_right_freq - linreg_left_freq) / 1e6), 3) widths[k] = half_peak_width k += 1 ''' # high and bottom of spectrum h_inds = amps > half_peak b_inds = amps < half_peak b_freqs = freqs[b_inds] b_amps = amps[b_inds] right_b_inds = b_freqs > mean_freq left_b_inds = b_freqs < mean_freq print('left_inds', left_b_inds) left_h_amp, right_h_amp = amps[h_inds][0], amps[h_inds][-1] left_h_freq, right_h_freq = freqs[h_inds][0], freqs[h_inds][-1] left_b_amp = b_amps[left_b_inds][-1] left_b_freq = b_freqs[left_b_inds][-1] right_b_amp = b_amps[right_b_inds][0] right_b_freq = b_freqs[right_b_inds][0] #plt.plot(freq, amp) #plt.plot(b_freqs, b_amps, color='red') #plt.show() #print(mean_freq) #left_part x_l = np.array([left_b_freq, left_h_freq]) y_l = np.array([left_b_amp, left_h_amp]) k_l, b_l, r_value_l, p_value_l, std_err_l = linregress(x_l, y_l) left_x_interp = np.linspace(left_b_freq, left_h_freq, num=200) left_interp = k_l * left_x_interp + b_l left_inds = left_interp <= half_peak linreg_left_freq = left_x_interp[left_inds][-1] #right_part x_r = np.array([right_b_freq, right_h_freq]) y_r = np.array([right_b_amp, right_h_amp]) k_r, b_r, r_value_r, p_value_r, std_err_r = linregress(x_r, y_r) right_x_interp = np.linspace(right_h_freq, right_b_freq, num=200) right_interp = k_r * right_x_interp + b_r right_inds = right_interp <= half_peak linreg_right_freq = right_x_interp[right_inds][0] plt.plot(freqs, amps) plt.plot(right_x_interp[right_inds][0], right_interp[right_inds][0], marker='o', color='red') plt.plot(left_x_interp[left_inds][-1], left_interp[left_inds][-1], marker='o', color='green') plt.show() #result) half_peak_width = np.round(((linreg_right_freq - linreg_left_freq) / 1e6), 3) widths[k] = half_peak_width k += 1 ''' sorted_inds = np.argsort(np_s) np_s = np_s[sorted_inds] widths = widths[sorted_inds] nums = nums[sorted_inds] ex_table = xl.Workbook() ex_table.create_sheet(title='half_peak_plot', index=0) sheet = ex_table['half_peak_plot'] sheet['A1'] = 'Номер файла' sheet['B1'] = 'Плотность плазмы, отн.ед.' sheet['C1'] = 'Ширина пика на полувысоте, МГц' for i in range(np_s.size): cell = sheet.cell(row=i + 2, column=1) cell.value = nums[i] cell = sheet.cell(row=i + 2, column=2) cell.value = np_s[i] cell = sheet.cell(row=i + 2, column=3) cell.value = widths[i] path = exp.excel_folder_path / f'half_peak_width_{exp_num}.xlsx' ex_table.save(path)
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))
proc = ProcessSignal('201026') short_delay_signals = np.arange(29, 67, 2) long_delay_signals = np.arange(85, 109, 2) signal_list = [short_delay_signals, long_delay_signals] print(long_delay_signals) full_ints = [] peak_ints = [] ns = [] m_delays = [] nums = [] for signal in signal_list[1]: signal_file = f'str{signal:03d}.csv' file = proc.open_file(signal_file, reduced=False) t, u = file['time'], file['voltage'] if signal < 95: t_min, t_max = 960e-9, 1222e-9 else: t_min, t_max = 60e-9, 322e-9 cut_inds = np.logical_and(t >= t_min, t <= t_max) t_cut = t[cut_inds] u_cut = u[cut_inds] print(t[0]) dt_2 = (t_cut[-1] - t_cut[0])**2 u_filt = proc.bandpass_filter(t, u, 2.68e9, 2.74e9) ''' plt.plot(t, u) plt.plot(t_cut, u_cut) plt.plot(t, u_filt)
# cut_freq = p_freq_2[ind_cutoff] # cut_fft_amp = amp_fft_2[ind_cutoff] fft_amp_old_dict = {'frequency': p_freq, 'amplitude': amp_fft} return fft_amp_old_dict test = ProcessSignal('201026') csv_types = test.read_type_file() csv_signals = csv_types['signal_files'][1::] csv_signal_nums = csv_types['signal_nums'] excel_dicts = test.read_excel(csv_signal_nums)['numbers'] magnetron_nums = excel_dicts['magnetron'] reb_nums = excel_dicts['noise'] for csv_signal in csv_signals: num = csv_signal[3:6] file = test.open_file(csv_signal, reduced=False) t, u = file['time'], file['voltage'] cut_file_inds = np.logical_and(t > 70e-9, t < 332e-9) t_cut, u_cut = t[cut_file_inds], u[cut_file_inds] simple_cut_integral = np.round(test.e_square(t_cut, u_cut) / 1e-8, 2) pl_density = test.read_excel(csv_signal)['dicts'][num]['Ток плазмы, А'] #plt.plot(t, u) #plt.title(f'{u[0], u[-1], t[-1]-t[0]}') #plt.show() dt_2 = (t[-1] - t[0])**2 fft_old = fft_amplitude_old(t, u) amps_old, freqs_old = fft_old['amplitude'], fft_old['frequency'] fft_new = fft_amplitude_new(t, u) amps_new, freqs_new = fft_new['amplitude'], fft_new['frequency'] integral_u = np.round(test.e_square(t, u) / 1e-8, 2) fft_signal = test.fft_signal(t, u, np.abs(t[1] - t[0]))
def left_right_power(): test = ProcessSignal('191011') csv_types = test.read_type_file() csv_signals = csv_types['signal_files'] csv_signal_nums = csv_types['signal_nums'] excel_dicts = test.read_excel(csv_signal_nums)['numbers'] magnetron_nums = excel_dicts['magnetron'] print('All magnetron nums:', magnetron_nums) m_1_nums = [] m_2_nums = [] for num in magnetron_nums: if 66 <= int(num) < 112: m_1_nums.append(num) elif 112 <= int(num) < 152: m_2_nums.append(num) m_lists = [m_1_nums, m_2_nums] labels_list = ['№2, 3', '№2, 3, A'] for i, m_list in enumerate(m_lists): e_left = [] e_right = [] pl_d = [] fig = plt.figure(num=1, dpi=200, figsize=[11.69, 8.27]) ax = fig.add_subplot(111) ax.set_prop_cycle(color=['orange', 'indigo']) for signal in csv_signals: num = signal[3:6] if num in m_list: file = test.open_file(signal, reduced=True) u = file['voltage'] t = file['time'] dt = file['time_resolution'] u_highpass = test.highpass(t, u, 2.769e9) u_lowpass = test.lowpass(t, u, 2.706e9) fft_pass = test.fft_signal(t, u, dt) freqs = fft_pass['frequency'] amps = fft_pass['amplitude'] high_inds = freqs > 2.769e9 low_inds = freqs < 2.709e9 high_freqs = freqs[high_inds] low_freqs = freqs[low_inds] high_amps = amps[high_inds] low_amps = amps[low_inds] e_high = test.e_square(high_freqs, high_amps) e_low = test.e_square(low_freqs, low_amps) ''' e_high = test.e_square(t, u_highpass) e_low = test.e_square(t, u_lowpass) ''' pl_density = test.read_excel(csv_signal_nums)['dicts'][num]['Ток плазмы, А'] #plt.plot(fft_high['frequency'], fft_high['amplitude'], color='blue') #plt.plot(high_freqs, high_amps, color='red') #plt.plot(low_freqs, low_amps, color='k') e_left.append(e_low) e_right.append(e_high) pl_d.append(pl_density) #plt.show() pl_d = np.array(pl_d) inds = np.argsort(pl_d) pl_d = pl_d[inds] e_left = np.array(e_left)[inds] line1, = ax.plot(pl_d, e_left, marker='o') line1.set_label('f < 2,72 GHz') line2, = ax.plot(pl_d, e_right, marker='o') line2.set_label('f > 2,76 GHz') ax.set_ylim(bottom=0) ax.set_xlim(left=5) ax.set_xlabel(r'$Plasma\/density, arb.units $', fontsize=16) ax.set_ylabel(r'$\int E^2 dt $', fontsize=16) ax.legend(loc='best', fontsize=12) ax.grid(which='both', axis='both') ax.set_title('191011, {}'.format(labels_list[i]), fontsize=20) mean_png = test.pics_path / 'left_right_power{}.png'.format(i) fig.savefig(mean_png) plt.close(fig) plt.show()
def integral_plots(exp, type='integrals', table=True): fft_test = ProcessSignal(exp) csv_types = fft_test.read_type_file() csv_signals = csv_types['signal_files'] csv_signal_nums = csv_types['signal_nums'] print(csv_signals) excel_dicts = fft_test.read_excel(csv_signal_nums)['numbers'] magnetron_nums = excel_dicts['magnetron'] print('All magnetron nums:', magnetron_nums) m_1_nums = magnetron_nums m_2_nums = [] ''' for num in magnetron_nums: if 11 <= int(num) < 67: m_1_nums.append(num) elif 125 <= int(num) <= 184: m_2_nums.append(num) ''' m_lists = [m_1_nums, m_2_nums] labels_list = ['№2, 3 (четверть)', '№2, 3, A'] for j, list in enumerate(m_lists): if len(list) != 0: fig = plt.figure(num=1, dpi=200, figsize=[11.69, 8.27]) ax = fig.add_subplot(111) flist_len = len(list) print('We have {} nums'.format(flist_len)) print('Magnetron nums are:', list) pl_densities = np.zeros(flist_len) e_noise_ints = np.zeros(flist_len) e_peak_ints = np.zeros(flist_len) csv_nums = np.zeros(flist_len) magnetron_nums = np.zeros(flist_len) e_noise_ls = [] e_noise_rs = [] power_koefs = np.zeros(flist_len) for i, num in enumerate(list): for csv_signal in csv_signals: csv_num = csv_signal[3:6] if csv_num == num: magnetron_nums[i] = int(num) print('I am working on {} signal'.format(csv_num)) pl_density = fft_test.read_excel(csv_signal_nums)['dicts'][num]['Ток плазмы, А'] pl_densities[i] = pl_density csv_nums[i] = csv_num file = fft_test.open_file(csv_signal, reduced=True) time = file['time'] voltage = file['voltage'] dt = file['time_resolution'] n_dt = time[-1] - time[0] n_dt_2 = n_dt ** 2 fft = fft_test.fft_amplitude(time, voltage, dt) freqs = fft['frequency'] amps = fft['amplitude'] noise_inds_left = freqs < 2.725e9 noise_inds_right = freqs > 2.755e9 peak_inds = np.logical_and(freqs > 2.725e9, freqs < 2.755e9) freq_noise_l = freqs[noise_inds_left] amp_noise_l = amps[noise_inds_left] freq_noise_r = freqs[noise_inds_right] amp_noise_r = amps[noise_inds_right] freq_peak = freqs[peak_inds] amp_peak = amps[peak_inds] amp_noise_l = 2 * n_dt_2 * fft_test.e_square(freq_noise_l, amp_noise_l) amp_noise_r = 2 * n_dt_2 * fft_test.e_square(freq_noise_r, amp_noise_r) amp_noise = amp_noise_l + amp_noise_r amp_peak = 2 * n_dt_2 * fft_test.e_square(freq_peak, amp_peak) e_noise_ls.append(amp_noise_l) e_noise_rs.append(amp_noise_r) e_noise_ints[i] = amp_noise e_peak_ints[i] = amp_peak power_koefs[i] = amp_noise_r / amp_noise_l print('Creating plasma plot ...') pl_plot = noise_signal_plot(int(exp), type='amp_freq', left_right=True) pl_ds = pl_plot['pl_ds'] pl_nums = pl_plot['plasma_nums'] pl_e_ints = pl_plot['e_integs'] pl_koefs = pl_plot['koefs'] ind_sort = np.argsort(pl_densities) pl_densities = pl_densities[ind_sort] e_noise_ints = e_noise_ints[ind_sort] e_peak_ints = e_peak_ints[ind_sort] x_min = min(pl_ds[0], pl_densities[0]) - 0.5 x_max = max(pl_ds[-1], pl_densities[-1]) + 0.5 if type == 'integrals': ax.set_prop_cycle(color=['orange', 'indigo', 'green']) line3, = ax.plot(pl_ds, pl_e_ints, marker='D', linewidth=2) line3.set_label('Энергия в шумовом импульсе') line, = ax.plot(pl_densities, e_peak_ints, marker='o', linewidth=2) line.set_label('Энергия в пике') line2, = ax.plot(pl_densities, e_noise_ints, marker='^', linewidth=2) line2.set_label('Энергия в шумовом пъедестале') ax.set_ylabel(r'$K\int A^2 df $', fontsize=16) path_png = fft_test.pics_path / 'integral_{}.png'.format(labels_list[j]) if table: magnetron_nums = magnetron_nums[ind_sort] fft_test.integrals_table(magnetron_nums, pl_densities, e_peak_ints, e_noise_ints, pl_nums, pl_ds, pl_e_ints, labels_list[j]) if type == 'left_right': e_noise_ls = e_noise_ls[ind_sort] e_noise_rs = e_noise_rs[ind_sort] ax.set_prop_cycle(color=['red', 'blue']) line_pl_1, = ax.plot(pl_densities, e_noise_ls, marker='o') line_pl_1.set_label(r'$f < 2.725\/GHz$') line_pl_2, = ax.plot(pl_densities, e_noise_rs, marker='^') line_pl_2.set_label(r'$f > 2.755\/GHz$') ax.set_ylabel(r'$K\int A^2 df $', fontsize=16) path_png = fft_test.pics_path / 'left_right_power{}.png'.format(labels_list[j]) if table: magnetron_nums = magnetron_nums[ind_sort] fft_test.left_right_table(magnetron_nums, e_noise_ints, e_noise_ls, e_noise_rs, pl_densities, labels_list[j]) if type == 'left_right_koef': power_koefs = power_koefs[ind_sort] line, = ax.plot(pl_densities, power_koefs, marker='o', linewidth=2) line.set_label(r'$ P_{in} \ne 0 $') line1, = ax.plot(pl_ds, pl_koefs, marker='^', linewidth=2) line1.set_label(r'$P_{in} = 0$') ax.set_ylabel(r'$\frac{W(f>2.755\/ГГц)}{W(f<2.725\/ГГц)} $', fontsize=22) path_png = fft_test.pics_path / 'power_koef_{}.png'.format(labels_list[j]) ax.set_ylim(bottom=0) ax.set_xlim(left=x_min, right=x_max) ax.legend(loc='best', fontsize=12) ax.grid(which='both', axis='both') ax.set_xlabel(r'$Plasma\/density, arb.units $', fontsize=16) ax.set_title('{}, {}'.format(exp, labels_list[j]), fontsize=20) fig.savefig(path_png) plt.close(fig)
import numpy as np import openpyxl as excel from ProcessClass_10 import ProcessSignal test = ProcessSignal('191120') file_name = 'str018.csv' file = test.open_file(file_name, reduced=True) t, u, dt = file['time'], file['voltage'], file['time_resolution'] fft = test.fft_amplitude(t, u, dt) freqs = fft['frequency'] amps = fft['amplitude'] n_dt_2 = (t[-1] - t[0])**2 full_integral = 2 * n_dt_2 * test.e_square(freqs, amps) / 1e-8 print(full_integral) df_s = np.arange(5, 105, 5) * 1e6 noise_integrals = np.zeros(len(df_s)) peak_integrals = np.zeros(len(df_s)) magnetron_freq = 2.74e9 for i, df in enumerate(df_s): low_freq = magnetron_freq - df high_freq = magnetron_freq + df noise_inds_l = freqs < low_freq noise_inds_r = freqs > high_freq peak_inds = np.logical_and(freqs > low_freq, freqs < high_freq) noise_freqs_l, noise_amps_l = freqs[noise_inds_l], amps[noise_inds_l] noise_freqs_r, noise_amps_r = freqs[noise_inds_r], amps[noise_inds_r] peak_freqs, peak_amps = freqs[peak_inds], amps[peak_inds]
csv_files_list = os.listdir(test.csv_files_path) csv_types = test.read_type_file() csv_signals = csv_types['signal_files'] csv_signal_nums = csv_types['signal_nums'] excel_dicts = test.read_excel(csv_signal_nums)['numbers'] magnetron_nums = excel_dicts['magnetron'] reb_nums = excel_dicts['noise'] print(reb_nums) reb_dict = {} ambigous_nums = [] dt_list = [] for csv_signal in csv_signals: if csv_signal in csv_files_list: num = csv_signal[3:6] if num in magnetron_nums or num in reb_nums: full_file = test.open_file(csv_signal, reduced=False) t_full, u_full = full_file['time'], full_file['voltage'] file = test.open_file(csv_signal, reduced=True) t, u = file['time'], file['voltage'] dt = np.abs(t[1] - t[0]) pl_density = test.read_excel( csv_signal)['dicts'][num]['Ток плазмы, А'] full_integral = np.round(test.e_square(t, u) / 1e-8, 2) full_file_full_integral = np.round( test.e_square(t_full, u_full) / 1e-8, 2) filtered_u = fft_filter(t, u) filtered_u_full = fft_filter(t_full, u_full) filt_integral = np.round(test.e_square(t, filtered_u) / 1e-8, 3) filt_integral_full = np.round( test.e_square(t_full, filtered_u_full) / 1e-8, 2)
import matplotlib.pyplot as plt from ProcessClass_10 import ProcessSignal 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)
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)
test = ProcessSignal('200924') test.files_classification() csv_types = test.read_type_file() csv_signals = csv_types['signal_files'] csv_signal_nums = csv_types['signal_nums'] excel_dicts = test.read_excel(csv_signal_nums)['numbers'] magnetron_nums = excel_dicts['magnetron'] plasma_nums = excel_dicts['noise'] print('Magnetron nums are:', magnetron_nums, 'REB nums are:', plasma_nums) pl_densities = np.zeros(len(csv_signals)) integrals = np.zeros(len(csv_signals)) nums = np.zeros(len(csv_signals)) test.reduce_fft() for i, csv_signal in enumerate(csv_signals): csv_signal_num = csv_signal[3:6] file = test.open_file(csv_signal, reduced=True) pl_density = test.read_excel( csv_signal)['dicts'][csv_signal_num]['Ток плазмы, А'] pl_densities[i] = pl_density time = file['time'] voltage = file['voltage'] t, u, dt = file['time'], file['voltage'], file['time_resolution'] fft = test.fft_amplitude(t, u, dt) freqs = fft['frequency'] amps = fft['amplitude'] n_dt_2 = (t[-1] - t[0])**2 full_integral = 2 * n_dt_2 * test.e_square(freqs, amps) / 1e-8 integrals[i] = full_integral nums[i] = csv_signal_num ex_table = excel.Workbook()
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]])