Example #1
0
def main(argv):
    config = read_parser(argv, Inputs, InputsOpt_Defaults)
    from Main_Analysis import main as invoke_signal

    if config['mode'] == 'spectrum':

        t, x, f, magX = invoke_signal([
            '--channel', 'AE_3', '--fs', '1.e6', '--power2', 'OFF', '--plot',
            'OFF'
        ])
        plt.show()

        df = f[2] - f[1]

        f_fund = 40.2093
        n_harm = 5
        F_harm = [(i + 1) * f_fund for i in range(n_harm)]

        NL_harm = [f_harm / df for f_harm in F_harm]

        AMP_harm = [magX[int(nl_harm)] for nl_harm in NL_harm]

        plt.plot(f, magX, 'r', F_harm, AMP_harm, 'o')

        plt.show()

    else:
        print('unknown mode')

    return
Example #2
0
def main(argv):
    config_input = read_parser(argv, Inputs, Inputs_opt, Defaults)

    # path = config_input['path']
    file = config_input['file']
    channel = config_input['channel']
    power2 = config_input['power2']
    save = config_input['save']

    file_h1 = config_input['file_h1']
    min_iter = int(config_input['min_iter'])
    max_iter = int(config_input['max_iter'])
    s_number = int(config_input['s_number'])
    tolerance = float(config_input['tolerance'])
    file_h2 = config_input['file_h2']
    file_h3 = config_input['file_h3']
    file_h4 = config_input['file_h4']
    file_h5 = config_input['file_h5']
    file_h6 = config_input['file_h6']
    file_h7 = config_input['file_h7']

    # filepath_x = join(path, file)
    # filename = filepath_x
    # # x = f_open_mat(filepath_x, channel)
    # # x = np.ndarray.flatten(x)

    # point_index = filepath_x.find('.')
    # extension = filepath_x[point_index+1] +filepath_x[point_index+2] + filepath_x[point_index+3]

    # # x = load_signal(filename, channel)
    # if extension == 'mat':
    # # x, channel = f_open_mat_2(filename)
    # # x = f_open_mat(filename, channel)
    # # x = np.ndarray.flatten(x)

    # print(filename)
    # print(channel)
    # x = f_open_mat_2(filename, channel)
    # x = np.ndarray.flatten(x)

    # elif extension == 'tdm': #tdms
    # x = f_open_tdms(filename, channel)
    # # x = f_open_tdms_2(filename)

    # elif extension == 'txt': #tdms
    # x = np.loadtxt(filename)
    # # filename = os.path.basename(filename) #changes from path to file
    # print(filepath_x)
    from Main_Analysis import invoke_signal

    dict_int = invoke_signal(config_input)
    x = dict_int['signal']
    filename = dict_int['filename']

    if power2 == 'auto':
        n_points = 2**(max_2power(len(x)))
    elif power2 == 'OFF':
        n_points = len(x)
    else:
        n_points = 2**power2

    x = x[0:n_points]

    # n_points = 2**int(power2)
    # x = x[0:n_points]

    if file_h1 != None and file_h2 == None:
        print('To calculate: h2')
        name_out = 'h2_'
        filepath_h1 = file_h1
        h1 = read_pickle(filepath_h1)
        x = x - h1
    elif file_h1 != None and file_h2 != None and file_h3 == None:
        print('To calculate: h3')
        name_out = 'h3_'
        filepath_h1 = file_h1
        h1 = read_pickle(filepath_h1)
        filepath_h2 = file_h2
        h2 = read_pickle(filepath_h2)
        x = x - h1 - h2
    elif file_h1 != None and file_h2 != None and file_h3 != None and file_h4 == None:
        print('To calculate: h4')
        name_out = 'h4_'
        filepath_h1 = file_h1
        h1 = read_pickle(filepath_h1)
        filepath_h2 = file_h2
        h2 = read_pickle(filepath_h2)
        filepath_h3 = file_h3
        h3 = read_pickle(filepath_h3)
        x = x - h1 - h2 - h3
    elif file_h1 != None and file_h2 != None and file_h3 != None and file_h4 != None and file_h5 == None:
        print('To calculate: h5')
        name_out = 'h5_'
        filepath_h1 = file_h1
        h1 = read_pickle(filepath_h1)
        filepath_h2 = file_h2
        h2 = read_pickle(filepath_h2)
        filepath_h3 = file_h3
        h3 = read_pickle(filepath_h3)
        filepath_h4 = file_h4
        h4 = read_pickle(filepath_h4)
        x = x - h1 - h2 - h3 - h4
    elif file_h1 != None and file_h2 != None and file_h3 != None and file_h4 != None and file_h5 != None and file_h6 == None:
        print('To calculate: h6')
        name_out = 'h6_'
        filepath_h1 = file_h1
        h1 = read_pickle(filepath_h1)
        filepath_h2 = file_h2
        h2 = read_pickle(filepath_h2)
        filepath_h3 = file_h3
        h3 = read_pickle(filepath_h3)
        filepath_h4 = file_h4
        h4 = read_pickle(filepath_h4)
        filepath_h5 = file_h5
        h5 = read_pickle(filepath_h5)
        x = x - h1 - h2 - h3 - h4 - h5
    elif file_h1 != None and file_h2 != None and file_h3 != None and file_h4 != None and file_h5 != None and file_h6 != None and file_h7 == None:
        print('To calculate: h7')
        name_out = 'h7_'
        filepath_h1 = file_h1
        h1 = read_pickle(filepath_h1)
        filepath_h2 = file_h2
        h2 = read_pickle(filepath_h2)
        filepath_h3 = file_h3
        h3 = read_pickle(filepath_h3)
        filepath_h4 = file_h4
        h4 = read_pickle(filepath_h4)
        filepath_h5 = file_h5
        h5 = read_pickle(filepath_h5)
        filepath_h6 = file_h6
        h6 = read_pickle(filepath_h6)
        x = x - h1 - h2 - h3 - h4 - h5 - h6
    else:
        print('To calculate: h1')
        name_out = 'h1_'

    print('Fs = 1 MHz for AE')
    fs = 1000000.
    dt = 1 / fs
    n = len(x)
    t = np.array([i * dt for i in range(n)])

    #++++++++++++++++++++++++++++ENVELOPES AND MEAN

    # x = butter_highpass(x=x, fs=1.e6, freq=80.e3, order=3, warm_points=None)

    # x = butter_demodulation(x=x, fs=10.e6, filter=['lowpass', 5000., 3], prefilter=['highpass', 80.e3, 3], type_rect='only_positives', dc_value='without_dc')
    # plt.plot(x)
    # plt.show()
    # h1 = sifting_iteration(t, x, min_iter, max_iter, s_number, tolerance)
    h1 = sifting_iteration_sd(t, x, min_iter, max_iter, tolerance)
    # h1 = sifting_iteration_sd_opt(t, x, min_iter, max_iter, tolerance)
    file = basename(file)

    if save == 'ON':
        print('Saving...')
        save_pickle(name_out + file[:-4] + '.pkl', h1)
        # np.savetxt(name_out + file[:-4] + '.txt', h1)

    print("--- %s seconds ---" % (time.time() - start_time))
    sys.exit()
Example #3
0
def main(argv):
    config_input = read_parser(argv, Inputs, Inputs_opt, Defaults)

    file = config_input['file']
    if file == None:
        root = Tk()
        root.withdraw()
        root.update()
        file = filedialog.askopenfilename()
        config_input['file'] = file
        root.destroy()

    channel = config_input['channel']
    power2 = config_input['power2']
    save = config_input['save']

    min_iter = int(config_input['min_iter'])
    max_iter = int(config_input['max_iter'])
    s_number = int(config_input['s_number'])
    tolerance = float(config_input['tolerance'])

    dict_int = invoke_signal(config_input)
    x = dict_int['signal']
    filename = dict_int['filename']

    if power2 == 'auto':
        n_points = 2**(max_2power(len(x)))
    elif power2 == 'OFF':
        n_points = len(x)
    else:
        n_points = 2**power2

    x = x[0:n_points]

    dt = 1. / config_input['fs']
    n = len(x)
    t = np.array([i * dt for i in range(n)])

    for count in range(config_input['n_imf']):
        count += 1

        print('To calculate: h' + str(count))
        name_out = 'h' + str(count) + '_'

        print("--- %s seconds Inicia Sifting ---" % (time.time() - start_time))

        # h = sifting_iteration_sd(t, x, min_iter, max_iter, tolerance)

        # h = sifting_iteration_ez_opt(t, x, min_iter, max_iter, s_number, tolerance)
        h = sifting_iteration_s_corr(t, x, min_iter, max_iter, s_number,
                                     tolerance)

        file = basename(file)

        print('Saving...')
        myname = name_out + file[:-4] + '.pkl'
        save_pickle(myname, h)

        print("--- %s seconds ---" % (time.time() - start_time))

        x = x - h

    sys.exit()
Example #4
0
def main(argv):
	config = read_parser(argv, Inputs, InputsOpt_Defaults)
	from Main_Analysis import invoke_signal
	
	if config['mode'] == 'avg_spectrum':
		n_avg = config['n_avg']
		magX_list =  []
		for i in range(n_avg):			
			dict_int = invoke_signal(config)
			x = dict_int['signal']
			t = dict_int['time']
			f = dict_int['freq']
			magX = dict_int['mag_fft']
			filename = dict_int['filename']
			
			
			if i == 0:
				magX_avg = np.zeros(len(magX))
			magX_avg = magX_avg + magX
		magX_avg = magX_avg / float(n_avg)
		
		fig, ax = plt.subplots()
		ax.plot(f, magX_avg)
		ax.set_xlabel('Frequency [Hz]')
		plt.show()
		
		
		if config['save'] == 'ON':
			mydict = {}
			mydict['freq_array'] = f
			mydict['avg_spectrum'] = magX_avg		
			
			if config['name'] == 'auto':
				import datetime
				stamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
			else:
				stamp = config['name']
			save_pickle('avg_spectrum_' + config['channel'] + stamp + '.pkl', mydict)
		else:
			print('no save')
		
		# plt.plot(f/1000., magX_avg)
		# plt.xlabel('Frequenz [kHz]')
		# params = {'mathtext.default': 'regular' }          
		# plt.rcParams.update(params)
		# plt.ylabel('Amplitude [mV]')
		# plt.show()
		

	elif config['mode'] == 'plot_spectrum':
		
		magX_avg_list = []
		f_list = []
		
		root = Tk()
		root.withdraw()
		root.update()
		Filenames = filedialog.askopenfilenames()
		root.destroy()	
		
		for filename in Filenames:
			print(os.path.basename(filename))
			mydict = read_pickle(filename)		
			f_list.append(mydict['freq_array'])
			magX_avg_list.append(mydict['avg_spectrum'])
			
		

		channel = 'AE_1'
		element = 'Mag-FFT'
		fig, ax = plt.subplots(nrows=3, ncols=1, sharex=True, sharey=True)
		# ax[].set_title(channel + ' ' + element + '\n' + os.path.basename(filename), fontsize=10)
		
		ax[0].set_title('BMB am Punkt D', fontsize=10, fontweight='bold')
		ax[1].set_title('Drahtbuerste am Punkt F', fontsize=10, fontweight='bold')
		ax[2].set_title('Kugelfall Maximale Hoehe', fontsize=10, fontweight='bold')
		ax[0].title.set_position([0.5, 1.0])
		ax[1].title.set_position([0.5, 0.8])
		ax[2].title.set_position([0.5, 0.8])

		
		
		ax[0].plot(f_list[0]/1000., magX_avg_list[0], 'r')
		ax[1].plot(f_list[1]/1000., magX_avg_list[1], 'r')
		ax[2].plot(f_list[2]/1000., magX_avg_list[2], 'r')
		
	
		ax[2].set_xlabel('Frequenz kHz')
		ax[0].ticklabel_format(axis='y', style='sci', scilimits=(-1, 1))
		ax[1].ticklabel_format(axis='y', style='sci', scilimits=(-1, 1))
		ax[2].ticklabel_format(axis='y', style='sci', scilimits=(-1, 1))
		params = {'mathtext.default': 'regular' }          
		plt.rcParams.update(params)
		ax[0].set_ylabel('Amplitude (m$V_{in}$)')
		ax[1].set_ylabel('Amplitude (m$V_{in}$)')
		ax[2].set_ylabel('Amplitude (m$V_{in}$)')
		
		plt.show()
		
	elif config['mode'] == 'plot_avg_spectrum':
		
		magX_avg_list = []
		f_list = []
		
		root = Tk()
		root.withdraw()
		root.update()
		Filenames = filedialog.askopenfilenames()
		root.destroy()	
		
		for filename in Filenames:
			print(os.path.basename(filename))
			mydict = read_pickle(filename)		
			f_list.append(mydict['freq_array'])
			magX_avg_list.append(mydict['avg_spectrum'])
			
		

		channel = config['channel']
		element = 'Mag-FFT'
		fig, ax = plt.subplots(nrows=2, ncols=1, sharex=True, sharey=True)
		# ax[].set_title(channel + ' ' + element + '\n' + os.path.basename(filename), fontsize=10)
		
		# ax.set_title(config['channel'] + ' FFT-Average WB-Source at F', fontsize=10, fontweight='bold')
		# title = config['channel'] + ' FFT-Mittelwert Hsu-Nielsen-Bursts'
		title = config['channel'] + ' FFT-Mittelwert'
		title = title.replace('_', '-')
		
		
		ax[0].set_title('Mit Lack', fontsize=12)
		ax[1].set_title('Ohne Lack', fontsize=12)
		# ax.ticklabel_format(axis='y', style='sci', scilimits=(-1, 1))
		
		
		ax[0].plot(np.array(f_list[0])/1000., magX_avg_list[0]*1000., 'r')
		ax[1].plot(np.array(f_list[1])/1000., magX_avg_list[1]*1000., 'darkred')

		
	
		# ax.set_xlabel('Frequency (kHz)')
		ax[1].set_xlabel('Frequenz [kHz]', fontsize=12)

		params = {'mathtext.default': 'regular' }          
		plt.rcParams.update(params)
		ax[1].set_ylabel('Amplitude [mV]', fontsize=12)
		ax[0].set_ylabel('Amplitude [mV]', fontsize=12)
		ax[0].tick_params(axis='both', labelsize=11)
		ax[1].tick_params(axis='both', labelsize=11)

		plt.tight_layout()
		plt.show()
		
		
	
	else:
		print('unknown mode')
		
		
		
	return
Example #5
0
def main(argv):
    config = read_parser(argv, Inputs, InputsOpt_Defaults)

    if config['mode'] == 'boxplot_features':
        print('Select normal signal..')
        dict_signal_normal = invoke_signal(config)

        x_normal = dict_signal_normal['signal']
        t_normal = dict_signal_normal['time']
        filename_signal_normal = dict_signal_normal['filename']

        dict_features_normal = calculate_features_2(t_normal, x_normal, config)

        print('Select ANORMAL signal!!.')
        dict_signal_anormal = invoke_signal(config)

        x_anormal = dict_signal_anormal['signal']
        t_anormal = dict_signal_anormal['time']
        filename_signal_anormal = dict_signal_anormal['filename']

        dict_features_anormal = calculate_features_2(t_anormal, x_anormal,
                                                     config)

        fig1, ax1 = plt.subplots()
        ax1.boxplot(
            [dict_features_normal['crest'], dict_features_anormal['crest']])
        ax1.set_xticklabels(['Gearbox-Source', 'WB-Source'], fontsize=11)
        ax1.set_ylabel('Crest Factor (-)', fontsize=11)
        plt.tight_layout()
        plt.savefig(config['channel'] +
                    '_crest_hp_80_box_thr_3_wt_1000_n_1.png')

        fig1d, ax1d = plt.subplots()
        ax1d.boxplot(
            [dict_features_normal['crest'], dict_features_anormal['crest']])
        ax1d.set_xticklabels(['Getriebe-Quelle', 'DB-Quelle'], fontsize=11)
        ax1d.set_ylabel('Crest-Faktor (-)', fontsize=11)
        plt.tight_layout()
        plt.savefig('DE_' + config['channel'] +
                    '_crest_hp_80_box_thr_3_wt_1000_n_1.png')

        fig2, ax2 = plt.subplots()
        ax2.boxplot(
            [dict_features_normal['rms'], dict_features_anormal['rms']])
        ax2.set_xticklabels(['Gearbox-Source', 'WB-Source'], fontsize=11)
        ax2.set_ylabel('RMS Value (m$V_{in}$)', fontsize=11)
        plt.tight_layout()
        plt.savefig(config['channel'] + '_rms_hp_80_box_thr_3_wt_1000_n_1.png')

        fig2d, ax2d = plt.subplots()
        ax2d.boxplot(
            [dict_features_normal['rms'], dict_features_anormal['rms']])
        ax2d.set_xticklabels(['Getriebe-Quelle', 'DB-Quelle'], fontsize=11)
        ax2d.set_ylabel('RMS-Wert (m$V_{in}$)', fontsize=11)
        plt.tight_layout()
        plt.savefig('DE_' + config['channel'] +
                    '_rms_hp_80_box_thr_3_wt_1000_n_1.png')

        fig3, ax3 = plt.subplots()
        ax3.boxplot(
            [dict_features_normal['count'], dict_features_anormal['count']])
        ax3.set_xticklabels(['Gearbox-Source', 'WB-Source'], fontsize=11)
        ax3.set_ylabel('Cycles Count (-)', fontsize=11)
        plt.tight_layout()
        plt.savefig(config['channel'] +
                    '_count_hp_80_box_thr_3_wt_1000_n_1.png')

        fig3, ax3d = plt.subplots()
        ax3d.boxplot(
            [dict_features_normal['count'], dict_features_anormal['count']])
        ax3d.set_xticklabels(['Getriebe-Quelle', 'DB-Quelle'], fontsize=11)
        ax3d.set_ylabel('Zyklusanzahl (-)', fontsize=11)
        plt.tight_layout()
        plt.savefig('DE_' + config['channel'] +
                    '_count_hp_80_box_thr_3_wt_1000_n_1.png')

    elif config['mode'] == 'plot_three_burst':

        Xs = []
        Ts = []
        Filenames = []
        for i in range(3):
            dict_int = invoke_signal(config)
            x = dict_int['signal']
            t = dict_int['time']
            f = dict_int['freq']
            magX = dict_int['mag_fft']
            filename_x = dict_int['filename']

            Xs.append(x)
            Ts.append(t)
            Filenames.append(filename_x)

        fig, ax = plt.subplots(nrows=1, ncols=3)
        for i in range(3):
            ax[i].plot(Ts[i], Xs[i])
            ax[i].set_ylabel('Amplitude [m$V_{in}$]', fontsize=12)

            title = config['channel'] + ' WFM Burst an F (Wdh. ' + str(i +
                                                                       1) + ')'
            title = title.replace('_', '-')

            ax[i].set_title(title, fontsize=12)
            ax[i].set_xlabel('Dauer [s]', fontsize=12)
            ax[i].tick_params(axis='both', labelsize=11)
            ax[i].ticklabel_format(axis='x', style='sci', scilimits=(-1, 1))
        fig.set_size_inches(16, 4)
        plt.show()

    elif config['mode'] == 'wfm_features':
        params = {'mathtext.default': 'regular'}
        plt.rcParams.update(params)

        dict_signal = invoke_signal(config)

        x = dict_signal['signal']
        t = dict_signal['time']
        filename = dict_signal['filename']

        dict_features = calculate_features_2(t, x, config)

        fig1, ax1 = plt.subplots()
        ax1.plot(t, x)
        ax1b = ax1.twinx()
        ax1.set_ylabel('Amplitude (m$V_{in}$)')
        ax1.set_xlabel('Time (s)')
        ax1.set_title(config['channel'] + ' WFM ' + filename, fontsize=10)
        ax1b.plot(dict_features['ini_time'], dict_features['crest'], 'ro')
        ax1b.set_ylabel('Crest Factor (-)', color='r')
        ax1b.tick_params('y', colors='r')
        plt.tight_layout()
        plt.savefig(config['channel'] +
                    '_crest_hp_80_source_brush_thr_3_wt_1000_n_1.png')

        fig2, ax2 = plt.subplots()
        ax2.plot(t, x)
        ax2b = ax2.twinx()
        ax2.set_ylabel('Amplitude (m$V_{in}$)')
        ax2.set_xlabel('Zeit (s)')
        ax2.set_title(config['channel'] + ' WFM ' + filename, fontsize=10)
        ax2b.plot(dict_features['ini_time'], dict_features['crest'], 'ro')
        ax2b.set_ylabel('Crest-Faktor (-)', color='r')
        ax2b.tick_params('y', colors='r')
        plt.tight_layout()
        plt.savefig('DE_' + config['channel'] +
                    '_crest_hp_80_source_brush_thr_3_wt_1000_n_1.png')

        fig3, ax3 = plt.subplots()
        ax3.plot(t, x)
        ax3b = ax3.twinx()
        ax3.set_ylabel('Amplitude (m$V_{in}$)')
        ax3.set_xlabel('Time (s)')
        ax3.set_title(config['channel'] + ' WFM ' + filename, fontsize=10)
        ax3b.plot(dict_features['ini_time'], dict_features['rms'], 'ro')
        ax3b.set_ylabel('RMS Value (m$V_{in}$)', color='r')
        ax3b.tick_params('y', colors='r')
        plt.tight_layout()
        plt.savefig(config['channel'] +
                    '_rms_hp_80_source_brush_thr_3_wt_1000_n_1.png')

        fig4, ax4 = plt.subplots()
        ax4.plot(t, x)
        ax4b = ax4.twinx()
        ax4.set_ylabel('Amplitude (m$V_{in}$)')
        ax4.set_xlabel('Zeit (s)')
        ax4.set_title(config['channel'] + ' WFM ' + filename, fontsize=10)
        ax4b.plot(dict_features['ini_time'], dict_features['rms'], 'ro')
        ax4b.set_ylabel('RMS Wert (m$V_{in}$)', color='r')
        ax4b.tick_params('y', colors='r')
        plt.tight_layout()
        plt.savefig('DE_' + config['channel'] +
                    '_rms_hp_80_source_brush_thr_3_wt_1000_n_1.png')

        fig5, ax5 = plt.subplots()
        ax5.plot(t, x)
        ax5b = ax5.twinx()
        ax5.set_ylabel('Amplitude (m$V_{in}$)')
        ax5.set_xlabel('Time (s)')
        ax5.set_title(config['channel'] + ' WFM ' + filename, fontsize=10)
        ax5b.plot(dict_features['ini_time'], dict_features['count'], 'ro')
        ax5b.set_ylabel('Cycles Count (-)', color='r')
        ax5b.tick_params('y', colors='r')
        plt.tight_layout()
        plt.savefig(config['channel'] +
                    '_count_hp_80_source_brush_thr_3_wt_1000_n_1.png')

        fig6, ax6 = plt.subplots()
        ax6.plot(t, x)
        ax6b = ax6.twinx()
        ax6.set_ylabel('Amplitude (m$V_{in}$)')
        ax6.set_xlabel('Zeit (s)')
        ax6.set_title(config['channel'] + ' WFM ' + filename, fontsize=10)
        ax6b.plot(dict_features['ini_time'], dict_features['count'], 'ro')
        ax6b.set_ylabel('Zyklusanzahl (-)', color='r')
        ax6b.tick_params('y', colors='r')
        plt.tight_layout()
        plt.savefig('DE_' + config['channel'] +
                    '_count_hp_80_source_brush_thr_3_wt_1000_n_1.png')

    elif config['mode'] == 'obtain_features':
        rise = []
        dura = []
        crest = []
        count = []
        maxcorr = []
        rms = []
        freq = []
        max = []

        print('Select reference burst')
        root = Tk()
        root.withdraw()
        root.update()
        filename_burst = filedialog.askopenfilename()
        root.destroy()
        reference = read_pickle(filename_burst)

        for i in range(config['n_signals']):
            print('Select signal..')
            dict_signal = invoke_signal(config)

            x = dict_signal['signal']
            t = dict_signal['time']
            filename_signal = dict_signal['filename']

            dict_features = calculate_features(t, x, reference, config)

            rise.append(dict_features['rise'])
            dura.append(dict_features['dura'])
            crest.append(dict_features['crest'])
            count.append(dict_features['count'])
            maxcorr.append(dict_features['maxcorr'])
            rms.append(dict_features['rms'])
            freq.append(dict_features['freq'])
            max.append(dict_features['max'])

        rise = [element for list_in in rise for element in list_in]
        dura = [element for list_in in dura for element in list_in]
        crest = [element for list_in in crest for element in list_in]
        count = [element for list_in in count for element in list_in]
        maxcorr = [element for list_in in maxcorr for element in list_in]
        rms = [element for list_in in rms for element in list_in]
        freq = [element for list_in in freq for element in list_in]
        max = [element for list_in in max for element in list_in]

        caca = 'AA'
        names = [
            'Rise time (us)', 'Duration (us)', 'Crest Factor (-)', 'Count (-)',
            'Max. Cross-Corr. (-)', 'RMS Value (mV)', 'Main Freq. (kHz)',
            'Max. Value (mV)', 'Initial Time (s)'
        ]
        features = [rise, dura, crest, count, maxcorr, rms, freq, max]
        box_8_plot(caca, names, features)

        dict_out = {'features': features, 'names': names}

        save_pickle(
            config['channel'] + '_features_thr_05_wt_500_HSN_point_E.pkl',
            dict_out)

    elif config['mode'] == 'plot_8_box_vs':
        print('Select features normal pickle')
        root = Tk()
        root.withdraw()
        root.update()
        filename = filedialog.askopenfilename()
        root.destroy()
        dict_normal = read_pickle(filename)

        print('Select features Anormal pickle...')
        root = Tk()
        root.withdraw()
        root.update()
        filename = filedialog.askopenfilename()
        root.destroy()
        dict_anormal = read_pickle(filename)

        features_normal = dict_normal['features']
        features_anormal = dict_anormal['features']

        names = dict_normal['names']
        labels = ['Gearbox', 'HSN']
        box_8_plot_vs(labels, names, features_normal, features_anormal)

        names = [
            'Steigungszeit [us]', 'Dauer [us]', 'Crest-Faktor [-]',
            'Überschwingungen [-]', 'Max. Kreuzkorrelation [-]',
            'RMS-Wert [mV]', 'Frequenz [kHz]', 'Max. Wert [mV]',
            'Initial Time (s)'
        ]
        labels = ['Getriebe', 'HSN']
        box_8_plot_vs(labels, names, features_normal, features_anormal)

    else:
        print('unknown mode')

    return
Example #6
0
def main(argv):
    config = read_parser(argv, Inputs, InputsOpt_Defaults)
    from Main_Analysis import invoke_signal

    if config['mode'] == 'plot_envelope':

        # t, x, f, magX, filename = invoke_signal(config)
        dict_int = invoke_signal(config)
        xraw = dict_int['signal_raw']
        x = dict_int['signal']
        t = dict_int['time']
        filename = dict_int['filename']

        v_max = np.max(xraw)
        xraw = xraw / v_max
        x = x / np.max(x)
        x = x - np.min(x)

        xraw = xraw * v_max
        x = x * v_max

        fig1, ax1 = plt.subplots()
        ax1.plot(t, xraw, label='Signal')
        ax1.plot(t, x, label='Envelope')
        ax1.set_title(config['channel'] + ' WFM ' + filename, fontsize=10)
        ax1.set_xlabel('Time (s)')
        params = {'mathtext.default': 'regular'}
        plt.rcParams.update(params)
        ax1.set_ylabel('Amplitude (m$V_{in}$)')
        plt.legend()
        plt.tight_layout()
        plt.savefig('AE_3_demod_bp_100_450_lp_36_source_gearbox_n_1.png')
        ax1.set_xlim(left=2.74, right=4.76)
        plt.savefig('AE_3_demod_bp_100_450_lp_36_source_gearbox_n_2.png')

        fig2, ax2 = plt.subplots()
        ax2.plot(t, xraw, label='Signal')
        ax2.plot(t, x, label='Huellkurve')
        ax2.set_title(config['channel'] + ' WFM ' + filename, fontsize=10)
        ax2.set_xlabel('Zeit (s)')
        params = {'mathtext.default': 'regular'}
        plt.rcParams.update(params)
        ax2.set_ylabel('Amplitude (m$V_{in}$)')
        plt.legend()
        plt.tight_layout()
        plt.savefig('DE_AE_3_demod_bp_100_450_lp_36_source_gearbox_n_1.png')
        ax2.set_xlim(left=2.74, right=4.76)
        plt.savefig('DE_AE_3_demod_bp_100_450_lp_36_source_gearbox_n_2.png')

        # fig_22, ax_22 = plt.subplots(nrows=2, ncols=1, sharex=True)
        # ax_22[1].plot(t, xnewraw)
        # ax_22[0].plot(t, xraw)

        # ax_22[1].set_title(config['channel'] + ' WFM Erkennung der Bursts', fontsize=11)
        # ax_22[1].set_xlabel('Zeit (s)', fontsize=12)
        # ax_22[1].set_ylabel('Amplitude (m$V_{in}$)', fontsize=12)

        # # params = {'mathtext.default': 'regular' }
        # # plt.rcParams.update(params)
        # ax_22[0].set_ylabel('Amplitude (m$V_{in}$)', fontsize=12)
        # ax_22[0].tick_params(axis='both', labelsize=11)
        # ax_22[1].tick_params(axis='both', labelsize=11)

        # ax_22[0].set_title(config['channel'] + ' WFM mit Filter', fontsize=11)

        plt.show()

    elif config['mode'] == 'compare_envelope':
        print('invoke NO drahtburst')
        dict_int = invoke_signal(config)
        xraw = dict_int['signal_raw']
        x = dict_int['signal']
        t = dict_int['time']
        filename = dict_int['filename']

        v_max = np.max(xraw)
        xraw = xraw / v_max
        x = x / np.max(x)
        x = x - np.min(x)

        xraw = xraw * v_max
        x = x * v_max

        print('invoke WITH drahtburst')
        dict_int = invoke_signal(config)
        yraw = dict_int['signal_raw']
        y = dict_int['signal']
        ty = dict_int['time']
        filename_y = dict_int['filename']

        m_max = np.max(yraw)
        yraw = yraw / m_max
        y = y / np.max(y)
        y = y - np.min(y)

        yraw = yraw * m_max
        y = y * m_max

        # fig1, ax1 = plt.subplots()
        # ax1.plot(t, xraw, label='Signal')
        # ax1.plot(t, x, label='Envelope')
        # ax1.set_title(config['channel'] + ' WFM ' + filename, fontsize=10)
        # ax1.set_xlabel('Time (s)')
        # params = {'mathtext.default': 'regular' }
        # plt.rcParams.update(params)
        # ax1.set_ylabel('Amplitude (m$V_{in}$)')
        # plt.legend()
        # plt.tight_layout()
        # plt.savefig('AE_3_demod_bp_100_450_lp_36_source_gearbox_n_1.png')
        # ax1.set_xlim(left=2.74, right=4.76)
        # plt.savefig('AE_3_demod_bp_100_450_lp_36_source_gearbox_n_2.png')

        label = config['channel']
        label = label.replace('_', '-')

        fig2, ax2 = plt.subplots(nrows=2, ncols=1, sharex=True, sharey=True)
        ax2[0].plot(t, xraw, label='Signal')
        ax2[0].plot(t, x, label='Huellkurve')
        ax2[0].set_title(label + ' ohne Drahtbuerste', fontsize=11)
        # ax2[0].set_xlabel('Zeit (s)', fontsize=12)
        params = {'mathtext.default': 'regular'}
        plt.rcParams.update(params)
        ax2[0].set_ylabel('Amplitude [m$V_{in}$]', fontsize=12)
        # plt.legend(fontsize=10)
        # ax2[0].set_xlim(left=2.74, right=4.76)
        ax2[0].tick_params(axis='both', labelsize=11)

        ax2[1].plot(t, yraw, label='Signal')
        ax2[1].plot(ty, y, label='Huellkurve')
        ax2[1].set_title(label + ' mit Drahtbuerste', fontsize=11)
        ax2[1].set_xlabel('Dauer [s]', fontsize=12)
        params = {'mathtext.default': 'regular'}
        plt.rcParams.update(params)
        ax2[1].set_ylabel('Amplitude [m$V_{in}$]', fontsize=12)

        # ax2[1].set_xlim(left=2.74, right=4.76)
        ax2[1].tick_params(axis='both', labelsize=11)

        plt.legend(fontsize=10)
        plt.tight_layout()

        # fig_22, ax_22 = plt.subplots(nrows=2, ncols=1, sharex=True)
        # ax_22[1].plot(t, xnewraw)
        # ax_22[0].plot(t, xraw)

        # ax_22[1].set_title(config['channel'] + ' WFM Erkennung der Bursts', fontsize=11)
        # ax_22[1].set_xlabel('Zeit (s)', fontsize=12)
        # ax_22[1].set_ylabel('Amplitude (m$V_{in}$)', fontsize=12)

        # # params = {'mathtext.default': 'regular' }
        # # plt.rcParams.update(params)
        # ax_22[0].set_ylabel('Amplitude (m$V_{in}$)', fontsize=12)
        # ax_22[0].tick_params(axis='both', labelsize=11)
        # ax_22[1].tick_params(axis='both', labelsize=11)

        # ax_22[0].set_title(config['channel'] + ' WFM mit Filter', fontsize=11)

        plt.show()

    else:
        print('unknown mode')

    return