Beispiel #1
0
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()
Beispiel #2
0
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)
Beispiel #3
0
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 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
Beispiel #6
0
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
Beispiel #7
0
def fft_reb_noise(exp_num, table=False):
    proc = ProcessSignal(f'{exp_num}')
    types = proc.read_type_file()
    csv_signal_nums = types['signal_nums']
    excel_results = proc.read_excel(csv_signal_nums)['numbers']
    noise_nums = excel_results['noise']
    print(excel_results)
Beispiel #8
0
def magnetron_exp(exp_num):
    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']
    magnetron_nums = excel_dicts['magnetron']
    lists = [magnetron_nums]
    dict_list = [
        magnetron_integrals_bloc(exp_num, lists[i]) for i in range(len(lists))
    ]
    fill_excel_table(exp_num, dict_list, proc)
def absorber_classification(exp_number, magnetron_dicts):
    test = ProcessSignal(str(exp_number))
    types = test.read_type_file()
    csv_signal_nums = types['signal_nums']
    magnetron_nums = test.read_excel(csv_signal_nums)['numbers']['magnetron']
    dicts = test.read_excel(csv_signal_nums)['dicts']
    absorbers_list = []*(len(magnetron_nums))
    for num in magnetron_nums:
        absorbers_list.append(dicts[num]['Поглотители в тракте магнетрона'])
    uniq_abs = set(absorbers_list)
    print(uniq_abs)

    abs_dict = {}
    for element in uniq_abs:
        nums_list = []
        for dict_num in magnetron_dicts:
            absorbers = magnetron_dicts[dict_num]['abs']
            if absorbers == element:
                nums_list.append(magnetron_dicts[dict_num])
        abs_dict[element] = nums_list
    return abs_dict
def m_signals_classification(magnetron_in_vals, magnetron_nums):
    test = ProcessSignal('200925')
    m_classif_dict = {}
    for val in magnetron_in_vals:
        file_numbers = []
        for m_num in magnetron_nums:
            magnetron_in = test.read_excel(m_num)['dicts'][m_num]['Входное напряжение магнетрона, В']
            if magnetron_in == val:
                file_numbers.append(m_num)
            else:
                pass
        m_classif_dict[val] = file_numbers
    return m_classif_dict
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
Beispiel #12
0
def energy_4_experiments():
    exps = [210119, 210204, 210211, 210304]
    l_col = [19.5, 26.5, 34.5, 20.5]
    n_low, n_max = 9, 11
    fig = plt.figure(num=1, dpi=300)
    ax1 = fig.add_subplot(211)
    ax2 = fig.add_subplot(212)
    colors = ['orange', 'mediumblue', 'limegreen', 'red']
    for i, exp in enumerate(exps):
        proc = ProcessSignal(str(exp))
        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']
        magnetron_nums = excel_dicts['magnetron']
        magnetron_dict = magnetron_integrals_bloc(exp, magnetron_nums)
        nums = magnetron_dict['nums']
        dens_vals = magnetron_dict['density']
        noise = magnetron_dict['full_ints'] - magnetron_dict['peak_ints']
        peak = magnetron_dict['peak_ints']
        noise_to_full = noise / magnetron_dict['full_ints']
        exp_nums = magnetron_dict['exp_nums']

        ind_mask = np.logical_and(dens_vals >= n_low, dens_vals <= n_max)
        dens_vals, noise_to_full, exp_num = dens_vals[ind_mask], noise_to_full[
            ind_mask], exp_nums[0]
        peak = peak[ind_mask]
        print(f'Creating plot for experiment {exp}...')
        col_len = [l_col[i]] * noise_to_full.size
        print(col_len)
        ax2.plot(col_len, peak, marker='.', linestyle=' ', color=colors[i])
        ax1.plot(col_len,
                 noise_to_full,
                 marker='.',
                 linestyle=' ',
                 color=colors[i])

    ax1.grid(which='both', axis='both')
    ax1.set_ylabel(r'$W_{1} / W$')
    ax1.set_xlim(left=17)
    ax2.grid(which='both', axis='both')
    ax2.set_xlabel(r'$L_{кол}, см$')
    ax2.set_ylabel(r'$W_{f0}$')
    ax2.set_xlim(left=17)
    ax1.set_title(r' Плотности {} - {} отн.ед.'.format(n_low, n_max))
    fig_path = Path(
        r'C:\Users\d_Nice\Documents\SignalProcessing\2021\210423\Pictures')
    png_name = fig_path / f'4_exp_energy(17)'
    fig.savefig(png_name)
    plt.close(fig)
    plt.show()
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()
Beispiel #14
0
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
Beispiel #15
0
def series_fft(exp_num):
    fft_test = ProcessSignal(f'{exp_num}')
    types = fft_test.read_type_file()
    csv_signals = types['signal_files']
    #csv_signals = ['str097.csv']
    csv_signal_nums = types['signal_nums']
    excel_results = fft_test.read_excel(csv_signal_nums)['numbers']
    noise_nums = excel_results['noise']
    #magnetron_nums = excel_results['magnetron']
    magnetron_nums = [f'{i:03d}' for i in range(131, 187, 1)]
    print('Magnetron nums are', magnetron_nums)
    print('Noise nums are:', noise_nums)
    fft_test.part_fft(csv_signals,
                      interest_nums=magnetron_nums,
                      part_nums=noise_nums,
                      fft_type='full', block_full=False,
                      block_part=False, peak=True, noise=False)
Beispiel #16
0
def multi_integral_excel(exp_num):
    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']
    magnetron_nums = excel_dicts['magnetron']
    magnetron_nums = [
        csv_signal_nums[i] for i in range(len(csv_signal_nums))
        if int(csv_signal_nums[i]) % 2 == 0
    ]
    print(magnetron_nums)
    list_1 = [
        magnetron_nums[i] for i in range(len(magnetron_nums))
        if 6 < int(magnetron_nums[i]) < 31
    ]
    list_2 = [
        magnetron_nums[i] for i in range(len(magnetron_nums))
        if 30 < int(magnetron_nums[i]) < 49
    ]
    list_3 = [
        magnetron_nums[i] for i in range(len(magnetron_nums))
        if 48 < int(magnetron_nums[i]) < 67
    ]
    list_4 = [
        magnetron_nums[i] for i in range(len(magnetron_nums))
        if 66 < int(magnetron_nums[i]) < 89
    ]
    list_5 = [
        magnetron_nums[i] for i in range(len(magnetron_nums))
        if 88 < int(magnetron_nums[i]) < 107
    ]
    list_6 = [
        magnetron_nums[i] for i in range(len(magnetron_nums))
        if 106 < int(magnetron_nums[i]) < 123
    ]
    list_7 = [
        magnetron_nums[i] for i in range(len(magnetron_nums))
        if 122 < int(magnetron_nums[i]) < 136
    ]
    lists = [list_1, list_2, list_3, list_4, list_5, list_6, list_7]
    dict_list = [
        magnetron_integrals_bloc(exp_num, lists[i]) for i in range(len(lists))
    ]
    fill_excel_table(exp_num, dict_list, proc)
    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(
        f'{signal:03d}')['dicts'][f'{signal:03d}']['Задержка магнетрона, нс']

    full_ints.append(full_int)
    peak_ints.append(peak_int)
    ns.append(n)
    m_delays.append(m_delay)
    nums.append(signal)

ind_sort = np.argsort(np.asarray(ns))
ns = np.asarray(ns)[ind_sort]
m_delays = np.asarray(m_delays)[ind_sort]
nums = np.asarray(nums)[ind_sort]
full_ints, peak_ints = np.asarray(full_ints)[ind_sort], np.asarray(
    peak_ints)[ind_sort]
import os
from pathlib import Path
import numpy as np
import csv
from scipy.stats import linregress
import openpyxl as xl
import matplotlib.gridspec as gridspec
from scipy.fftpack import rfft, rfftfreq, irfft

folder_path = Path(r'C:\Users\d_Nice\Documents\SignalProcessing\2020\201124')

proc = ProcessSignal('201124')
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']
list_3_4 = ['str013.csv', 'str039.csv']
list_1_4 = ['str043.csv', 'str071.csv']

files = os.listdir(folder_path)
magnetron_files = [
    files[i] for i in range(len(files))
    if files[i][3:6] in magnetron_nums and 'csv' in files[i]
]
noise_files = [
    files[i] for i in range(len(files))
    if files[i][3:6] in noise_nums and 'csv' in files[i]
]
Beispiel #19
0
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
Beispiel #20
0
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)
Beispiel #21
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 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)
Beispiel #23
0
import numpy as np
import openpyxl as excel
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)
import numpy as np
import openpyxl as excel
import matplotlib.pyplot as plt
from ProcessClass_10 import ProcessSignal

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
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)