Пример #1
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()
 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]))
 simple_amps_fft, simple_freqs_fft = fft_signal['amplitude'], fft_signal[
     'frequency']
 simple_fft_integral = np.round(
     dt_2 * test.e_square(simple_freqs_fft, simple_amps_fft) / 2e-8, 2)
 integral_amp_old = np.round(
     dt_2 * test.e_square(freqs_old, amps_old) / 2e-8, 2)
 integral_amp_new = np.round(
     dt_2 * test.e_square(freqs_new, amps_new) / 2e-8, 2)
 integral_amp = test.e_square(freqs_new, amps_new)
 plt.plot(freqs_old, amps_old, color='k')
 plt.plot(freqs_new, amps_new, color='red')
 plt.xlim(left=2.7e9, right=2.78e9)
 plt.title(
     f'num = {num}, e_2 = {integral_u}, amp_2 = {simple_cut_integral}, peak={np.max(amps_new)}'
 )