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 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 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 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()
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() 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):
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'] t = file['time'] dt = file['time_resolution'] dt_2 = (t[-1] - t[0]) ** 2 pl_density = proc.read_excel(signal)['dicts'][num]['Ток плазмы, А']
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) plt.title(signal) plt.show() ''' integral = np.round(proc.e_square(t_cut, u_cut) / 1e-8, 3) freqs, amps = proc.fft_amplitude(t_cut, u_cut)['frequency'], proc.fft_amplitude( t_cut, u_cut)['amplitude'] peak_inds = np.logical_and(freqs >= 2.695e9, freqs <= 2.725e9) p_freqs, p_amps = freqs[peak_inds], amps[peak_inds] plt.plot(freqs, amps) plt.title(signal) plt.xlim(left=0e9, right=4e9) plt.show() 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) print('num =', signal, integral, full_int) n = proc.read_excel( f'{signal:03d}')['dicts'][f'{signal:03d}']['Ток плазмы, А'] m_delay = proc.read_excel(
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'][:12:] magnetron_nums = excel_dicts['magnetron'][0:0:] nums, n_s, l_ints, r_ints = [], [], [], [] l_noise_ints, r_noise_ints, noise_ns, n_nums = [], [], [], [] for signal in csv_signals: num = signal[3:6] file = proc.open_file(signal, reduced=True) u = file['voltage'] t = file['time'] dt = file['time_resolution'] dt_2 = (t[-1] - t[0])**2 fft_data = proc.fft_amplitude(t, u) freqs, amps = fft_data['frequency'][1::], fft_data['amplitude'][1::] left_inds = freqs <= 2.71e9 - 50e6 l_freqs = freqs[left_inds] l_amps = amps[left_inds] l_int = np.round(dt_2 * proc.e_square(l_freqs, l_amps) / 2e-8, 3) r_inds = freqs >= 2.71e9 + 50e6 r_freqs = freqs[r_inds] r_amps = amps[r_inds] r_int = np.round(dt_2 * proc.e_square(r_freqs, r_amps) / 2e-8, 3) ''' plt.plot(freqs, amps) plt.plot(l_freqs, l_amps) plt.plot(r_freqs, r_amps) plt.title(f'l_int = {l_int}, r_int = {r_int}') plt.xlim(right=6e9)
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 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)
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)