def left_right_noise(): test = ProcessSignal('191106') noise_dict = noise_signal_plot(191106, type='amp_freq', left_right=True) pl_d = noise_dict['pl_ds'] r_power = noise_dict['r_power'] l_power = noise_dict['l_power'] full_power = noise_dict['e_integs'] plasma_nums = noise_dict['plasma_nums'] fig = plt.figure(num=1, dpi=300) ax = fig.add_subplot(111) line_r, = ax.plot(pl_d, r_power, marker='^', linewidth=0.9, color='blue', ms=3) line_l, = ax.plot(pl_d, l_power, marker='o', linewidth=0.9, color='red', ms=3) line_l.set_label(r'$f < 2.725\/GHz$') line_r.set_label(r'$f > 2.755\/GHz$') ax.set_xlabel('Plasma density, arb.units', fontsize=12) ax.set_ylabel(r'$K\int A^2 df $', fontsize=12) ax.set_ylim(bottom=0) ax.legend() ax.set_title(r'$191106. P_{in}=0 $') ax.grid(which='both', axis='both') png_name = test.pics_path / 'noise_power' fig.savefig(png_name) test.left_right_table(plasma_nums, full_power, l_power, r_power, pl_d, 'noise')
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)