def load_origin_signal(self): if self.__parameters is None: self.__origin_signal = None self.__origin_spectrogram = None if self.__parameters is not None and self.__origin_signal is None: params = self.__parameters bin_data = BinaryFile() bin_data.path = params['file_path'] bin_data.use_avg_values = False bin_data.resample_frequency = params['resample_frequency'] bin_data.read_date_time_start = params['dt_start'] bin_data.read_date_time_stop = params['dt_stop'] if bin_data.signals is None: self.__origin_signal = None self.__origin_spectrogram = None else: index_channel = 'XYZ'.index(params['component']) signal = bin_data.ordered_signal_by_components[:, index_channel] self.__origin_signal = signal self.__origin_spectrogram = specgram( signal_data=signal, frequency_of_signal=params['resample_frequency'])
bin_data = BinaryFile() bin_data.path = os.path.join(root, file) bin_data.use_avg_values = False i = 0 while True: left_time_lim = bin_data.datetime_start + timedelta( minutes=i * time_step_minutes) if left_time_lim > bin_data.datetime_stop: break right_time_lim = bin_data.datetime_start + timedelta( minutes=(i + 1) * time_step_minutes) if right_time_lim > bin_data.datetime_stop: right_time_lim = bin_data.datetime_stop bin_data.read_date_time_start = left_time_lim bin_data.read_date_time_stop = right_time_lim signal_data = bin_data.ordered_signal_by_components for component in components: signal = signal_data[:, 'XYZ'.index(component)] smooth_av_spec = average_spectrum( signal=signal, frequency=bin_data.signal_frequency, window=window_size, overlap=overlap_size, med_filter=median_param, marmett_filter=marmett_param) no_smooth_av_spectrum = average_spectrum( signal=signal, frequency=bin_data.signal_frequency, window=window_size,
from SeisCore.BinaryFile.BinaryFile import BinaryFile from SeisCore.Functions.Spectrogram import create_spectrogram from datetime import timedelta bin_file = r'/media/michael/77E9-B4C6/YM_002_K14_2019-12-08_04-30-40.xx' bin_data = BinaryFile() bin_data.path = bin_file bin_data.resample_frequency = 250 bin_data.read_date_time_start = bin_data.datetime_start + timedelta(minutes=30) bin_data.read_date_time_stop = bin_data.datetime_start + timedelta(minutes=60) signal_z = bin_data.signals[:, 0] create_spectrogram(signal_z, 250, '/media/michael/77E9-B4C6', 'test2', 1, 30, 0)
def run(self): finished_parts_count = 0 params = self.parameters for index, key in enumerate(self.files_info): cur_file_data = self.files_info[key] dt_start = cur_file_data['datetime_start'] dt_stop = cur_file_data['datetime_stop'] file_path = cur_file_data['path'] file_name = os.path.basename(file_path).split('.')[0] cross_dt_start = max(params['dt_start'], dt_start) cross_dt_stop = min(params['dt_stop'], dt_stop) bin_data = BinaryFile() bin_data.path = file_path bin_data.use_avg_values = True bin_data.resample_frequency = params['resample_frequency'] part_count = int(round( (cross_dt_stop - cross_dt_start).total_seconds() // ( params['interval_size'] * 60))) for i in range(part_count): read_dt_start = cross_dt_start + timedelta( minutes=params['interval_size'] * i) read_dt_stop = read_dt_start + timedelta( minutes=params['interval_size']) read_dt_start_label = datetime.strftime(read_dt_start, '%Y-%m-%d_%H-%M-%S') bin_data.read_date_time_start = read_dt_start bin_data.read_date_time_stop = read_dt_stop signals = bin_data.signals record_type=bin_data.record_type for component in params['components']: component_signal=signals[:, record_type.index(component)] output_folder = os.path.join(params['output_folder'], file_name, f'{component}Component') if not os.path.exists(output_folder): os.makedirs(output_folder) output_name = f'SP_{component}Component_{file_name}_{read_dt_start_label}' create_spectrogram(signal_data=component_signal, frequency=params['resample_frequency'], output_folder=output_folder, output_name=output_name, min_frequency=params['visual_min_frequency'], max_frequency=params['visual_max_frequency'], time_start=0) output_name = f'SIG_{component}Component_{file_name}_{read_dt_start_label}' plot_signal(time_start_sec=0, frequency=params['resample_frequency'], signal=component_signal, label=output_name, output_folder=output_folder, output_name=output_name) finished_parts_count += 1 percent_value = finished_parts_count / self.parts_count * 100 self.finished_percent.emit(percent_value)
def run(self): params = self.parameters dt = (params['dt_stop'] - params['dt_start']).total_seconds() discrete_amount = int(round(dt * params['resample_frequency'])) components_amount = len(params['components']) files_amount = len(self.files_info.keys()) frequencies_list = rfftfreq(params['window_size'], 1 / params['resample_frequency']) frequency_count = frequencies_list.shape[0] joined_signal_array = np.empty( shape=(components_amount, discrete_amount, files_amount), dtype=np.int) average_spectrum_data = np.empty( shape=(components_amount, 2, frequency_count, files_amount), dtype=np.float) bin_files_list = list(self.files_info.keys()) for index in range(len(bin_files_list)): bin_files_list[index] = bin_files_list[index].split('.')[0] finished_parts_count = 0 for index_a, key in enumerate(self.files_info): cur_file_data = self.files_info[key] file_path = cur_file_data['path'] bin_data = BinaryFile() bin_data.path = file_path bin_data.use_avg_values = True bin_data.resample_frequency = params['resample_frequency'] bin_data.read_date_time_start = params['dt_start'] bin_data.read_date_time_stop = params['dt_stop'] signals = bin_data.signals if signals.shape[0]>discrete_amount: signals=signals[:discrete_amount] if params['detrend_frequency']!=0: for i in range(signals.shape[1]): signals[:,i]=detrend(signal=signals[:,i], frequency=bin_data.resample_frequency, edge_frequency=params['detrend_frequency']) record_type=bin_data.record_type for index_b, component in enumerate(params['components']): compoment_signal = signals[:, record_type.index(component)] joined_signal_array[index_b, :, index_a] = compoment_signal # calculating average unsmoothed spectrum av_spec_simple_component = average_spectrum( signal=compoment_signal, frequency=params['resample_frequency'], window=params['window_size'], offset=params['overlap_size'], med_filter=None, marmett_filter=None) average_spectrum_data[index_b, 0, :, index_a] = \ av_spec_simple_component[:, 1] # calculating average smoothed spectrum av_spec_smooth_component = average_spectrum( signal=compoment_signal, frequency=params['resample_frequency'], window=params['window_size'], offset=params['overlap_size'], med_filter=params['median_filter'], marmett_filter=params['marmett_filter']) average_spectrum_data[index_b, 1, :, index_a] = \ av_spec_smooth_component[:, 1] finished_parts_count += 1 percent_value = finished_parts_count / self.parts_count * 100 self.finished_percent.emit(percent_value) result_correlate_matrix = np.empty( shape=(components_amount, files_amount, files_amount), dtype=np.float) for component in range(components_amount): result_correlate_matrix[component, :, :] = cross_correlation( frequency=frequencies_list, f_min_analysis=params['correlation_min_frequency'], f_max_analysis=params['correlation_max_frequency'], amplitudes=average_spectrum_data[component, 1, :, :]) # result data exporting read_dt_start_label = datetime.strftime(params['dt_start'], '%Y-%m-%d_%H-%M-%S') for index_a, bin_file_name in enumerate(self.files_info): bin_file_name = bin_file_name.split('.')[0] file_processing_result_folder = \ os.path.join(params['output_folder'], bin_file_name) if not os.path.exists(file_processing_result_folder): os.mkdir(file_processing_result_folder) for index_b, component_label in enumerate(params['components']): if params['is_selection_signal_file']: dat_file_name = f'{bin_file_name}_ClearSignal_' \ f'{component_label}_Component.dat' export_path = os.path.join(file_processing_result_folder, dat_file_name) np.savetxt(fname=export_path, X=joined_signal_array[index_b, :, index_a], fmt='%i') if params['is_selection_signal_graph']: png_file_name = \ f'{bin_file_name}_ClearSignal_{component_label}_{read_dt_start_label}' plot_signal(time_start_sec=0, frequency=params['resample_frequency'], signal=joined_signal_array[index_b, :, index_a], label=png_file_name, output_folder=file_processing_result_folder, output_name=png_file_name) if params['is_spectrum_graph']: png_file_name = '{}_AverageSpectrum_{}_Component_' \ 'Graph'.format(bin_file_name, component_label) plot_average_spectrum( frequency=frequencies_list, origin_amplitudes=average_spectrum_data[ index_b, 0, :, index_a], smooth_amplitudes=average_spectrum_data[ index_b, 1, :, index_a], f_min=params['visual_min_frequency'], f_max=params['visual_max_frequency'], output_folder=file_processing_result_folder, output_name=png_file_name) if params['is_unsmoothed_spectrum_file']: file_name = \ f'{bin_file_name}_{component_label}_Component.sc' export_path = os.path.join( file_processing_result_folder, file_name) temp_array = np.empty( shape=(frequencies_list.shape[0], 2), dtype=np.float) temp_array[:, 0] = frequencies_list temp_array[:, 1] = average_spectrum_data[index_b, 0, :, index_a] np.savetxt(fname=export_path, X=temp_array, fmt='%f', delimiter='\t') if params['is_smoothed_spectrum_file']: file_name = \ f'{bin_file_name}_{component_label}_Component.ssc' export_path = os.path.join( file_processing_result_folder, file_name) temp_array = np.empty( shape=(frequencies_list.shape[0], 2), dtype=np.float) temp_array[:, 0] = frequencies_list temp_array[:, 1] = \ average_spectrum_data[index_b, 1, :, index_a] np.savetxt(fname=export_path, X=temp_array, fmt='%f', delimiter='\t') if params['is_correlation_graph']: png_file_name = \ f'{bin_file_name}_Separate_Correlation_{component_label}_Component_Graph' plot_single_correlation( devices=bin_files_list, correlation_data=result_correlate_matrix[ index_b, index_a, :], output_folder=file_processing_result_folder, output_name=png_file_name) finished_parts_count += 1 percent_value = finished_parts_count / self.parts_count * 100 self.finished_percent.emit(percent_value) colors = list() for i in range(len(self.files_info.keys())): colors.append(generate_random_color()) for index_a, component_label in enumerate(params['components']): if params['is_general_smooth_spectrum_graph']: file_name = f'SmoothSpectrums_{component_label}_Component' plot_all_smooth_spectrums( spectrums_name_list=bin_files_list, frequency=frequencies_list, spectrum_data=average_spectrum_data[index_a, 1, :, :], f_min_visualize=params['visual_min_frequency'], f_max_visualize=params['visual_max_frequency'], colors=colors, output_folder=params['output_folder'], output_name=file_name) if params['is_correlation_matrix_file']: file_name = f'CorrelationMatrix_{component_label}_Component.dat' header = 'NULL\t' + '\t'.join(bin_files_list) + '\n' write_lines = list() write_lines.append(header) corr_matrix = result_correlate_matrix[index_a, :, :] for i in range(corr_matrix.shape[0]): t = list() t.append(bin_files_list[i]) for j in range(corr_matrix.shape[1]): t.append(str(corr_matrix[i, j])) s = '\t'.join(t) + '\n' write_lines.append(s) export_path = os.path.join(params['output_folder'], file_name) f = open(export_path, 'w') for line in write_lines: f.write(line) f.close() if params['is_general_correlation_graph']: file_name = f'Correlations_{component_label}_Component' plot_correlation(devices=bin_files_list, colors=colors, correlation_matrix=result_correlate_matrix[ index_a, :, :], output_folder=params['output_folder'], output_name=file_name)
def calculation(self): folder_path = self._ui.leInputFolder.text() export_folder_path = self._ui.leOutputFolder.text() file_list = self._ui.teFilesList.toPlainText() dt_start = self._ui.dtMinDt.dateTime() dt_stop = self._ui.dtMaxDt.dateTime() if folder_path is None or file_list is None or export_folder_path is None: return None files = file_list.split('\n') extract_data = None for index, file in enumerate(files): full_path = os.path.join(folder_path, file) bin_data = BinaryFile() bin_data.path = full_path bin_data.record_type = 'XYZ' bin_data.use_avg_values = False bin_data.read_date_time_start = dt_start.toPyDateTime() bin_data.read_date_time_stop = dt_stop.toPyDateTime() bin_data.resample_frequency = self._ui.sbResampleFrequency.value() if bin_data.signals is None: continue if extract_data is None: discrete_count = bin_data.signals.shape[0] extract_data = np.empty(shape=(discrete_count, 3 * len(files)), dtype=np.int) extract_data[:, 3 * index:3 * (index + 1)] = bin_data.signals if extract_data is None: return None sum_trace = np.empty(shape=(extract_data.shape[0], 3), dtype=np.int) channel_plots = [self.channel_a_plot, self.channel_b_plot, self.channel_c_plot] spectrum_plots = [self.channel_a_spectrum, self.channel_b_spectrum, self.channel_c_spectrum] window_size = self._ui.sbWindowSize.value() overlap_size = self._ui.sbOverlapSize.value() median_filter = self._ui.sbMedianFilter.value() marmett_filter = self._ui.sbMarmettFilter.value() resample_frequency = self._ui.sbResampleFrequency.value() if marmett_filter == 0: marmett_filter = None if median_filter == 0: median_filter = None spectrums = None for i in range(3): channel_signals = extract_data[:, i:3 * len(files):3] sum_trace[:, i] = np.sum(channel_signals, axis=1) channel_plot = channel_plots[i] spectrum_plot = spectrum_plots[i] channel_plot.clear() channel_plot.plot(sum_trace[:, i], pen=(196, 255, 18)) spectrum_plot.clear() spectrum_data = average_spectrum(signal=sum_trace[:, i], frequency=resample_frequency, window=window_size, overlap=overlap_size, med_filter=median_filter, marmett_filter=marmett_filter) if spectrums is None: spectrums = np.empty(shape=(spectrum_data.shape[0], 4), dtype=np.float) spectrums[:, :2] = spectrum_data else: spectrums[:, 1 + i] = spectrum_data[:, 1] spectrum_plot.plot(spectrum_data, pen=(255, 0, 0)) tmp_file_a = os.path.join(export_folder_path, 'sum_trace.npy') tmp_file_b = os.path.join(export_folder_path, 'spectrums.npy') np.save(tmp_file_a, sum_trace) np.save(tmp_file_b, spectrums) output_file_sum_trace = os.path.join(export_folder_path, 'SumTraces.dat') output_file_spectrums = os.path.join(export_folder_path, 'Spectrums.dat') np.savetxt(output_file_sum_trace, sum_trace, fmt='%i', delimiter='\t', header='Channel_1\tChannel_2\tChannel_3', comments='') np.savetxt(output_file_spectrums, spectrums, fmt='%f', delimiter='\t', header='Frequency\tChannel_1\tChannel_2\tChannel_3', comments='')
bin_data = BinaryFile() bin_data.path = '/media/michael/Data/Projects/HydroFracturing/NorthDeposit' \ '/Perforation/Binary/12_SigmaN001_2020-04-11_12-15-15.bin' signal = bin_data.signals[1000:2000] plt.plot(signal) plt.show() print(signal.shape[0]) signal = signal[ (signal[:, 0] != 0) * (signal[:, 1] != 0) * (signal[:, 2] != 0)] print(signal.shape[0]) print("") exit(1) bin_data.read_date_time_start = datetime(2019, 7, 28, 8, 0, 0) + timedelta( seconds=-1 * 3) bin_data.read_date_time_stop = datetime(2019, 7, 28, 8, 0, 2) print(bin_data.discrete_amount) print(bin_data.check_correct()) exit(0) bin_data.read_date_time_start = datetime(2019, 7, 28, 8, 0, 0) + timedelta( seconds=-1 * 3) bin_data.read_date_time_stop = datetime(2019, 7, 28, 8, 0, 2) signal = bin_data.signals[:, 0] check_function(signal=signal, frequency=1000, order=3, long_window=0.5, short_window=0.05) # sfa=sl_filter_a(signal,100,1,1,0.05)
# read_dt_start=datetime.datetime(2019,12,5,14) # read_dt_stop=datetime.datetime(2019,12,5,14,10) bandpass_filter_limits = (0, 0.4) bandpass_step = 0.1 spectrograms_freq_limits = (0, 250) for file in files: file_path = os.path.join(root, file) bin_data = BinaryFile() bin_data.path = file_path bin_data.use_avg_values = False for dt_lims in read_limits: bin_data.read_date_time_start = dt_lims[0] bin_data.read_date_time_stop = dt_lims[1] signal = bin_data.signals[:, 0] file_name = os.path.basename(file_path).split('.')[0] for band_f_min in np.arange(bandpass_filter_limits[0], bandpass_filter_limits[1], bandpass_step): # band_f_max=band_f_min+bandpass_step band_f_max = 500 exp_folder_name = f'{band_f_min}-{band_f_max}_Hz' date_interval_template=f'{dt_lims[0].strftime("%Y-%m-%d-%H-%M-%S")}_' \ f'{dt_lims[1].strftime("%Y-%m-%d-%H-%M-%S")}' exp_path = os.path.join(output_folder, file_name, date_interval_template, exp_folder_name)