From be7627d93f8ccac64166653d6d63076c4d2a5f12 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby Date: Wed, 19 Mar 2025 18:08:33 +0100 Subject: [PATCH] Signal processing: Refactoring with recompute and replot method. --- View/signal_processing_tab.py | 96 ++++++++++++++++++++--------------- 1 file changed, 54 insertions(+), 42 deletions(-) diff --git a/View/signal_processing_tab.py b/View/signal_processing_tab.py index 47929f9..47e670e 100644 --- a/View/signal_processing_tab.py +++ b/View/signal_processing_tab.py @@ -462,15 +462,16 @@ class SignalProcessingTab(QWidget): self.pushbutton_clear_noise_data.clicked.connect(self.clear_noise_data) self.pushbutton_plot_profile_tail.clicked.connect(self.compute_average_profile_tail) - self.pushbutton_plot_profile_tail.clicked.connect(self.plot_averaged_profile_tail) + self.pushbutton_plot_profile_tail.clicked.connect(self.replot) - self.pushbutton_apply_noise_from_profile_tail.clicked.connect(self.plot_averaged_profile_tail) self.pushbutton_apply_noise_from_profile_tail.clicked.connect(self.compute_noise_from_profile_tail_value) + self.pushbutton_apply_noise_from_profile_tail.clicked.connect(self.replot) self.combobox_freq_noise_from_profile_tail.currentIndexChanged.connect(self.compute_average_profile_tail) self.combobox_freq_noise_from_profile_tail.currentIndexChanged.connect(self.plot_averaged_profile_tail) self.pushbutton_Apply_SNR_filter.clicked.connect(self.remove_point_with_snr_filter) + self.pushbutton_Apply_SNR_filter.clicked.connect(self.replot) self.lineEdit_horizontal_average.returnPressed.connect(self.update_label_cells_sec) self.pushbutton_average.clicked.connect(self.compute_averaged_BS_data) @@ -552,14 +553,35 @@ class SignalProcessingTab(QWidget): stg.freq_text[data_id] ) - self.compute_average_profile_tail() - self.plot_averaged_profile_tail() + self.recompute() + self.replot() logger.debug("Update the Signal preprocessing tab... Done") self.combobox_freq_noise_from_profile_tail.blockSignals(False) self.combobox_acoustic_data_choice.blockSignals(False) + @trace + def recompute(self, *args): + data_id = self.combobox_acoustic_data_choice.currentIndex() + + self.compute_average_profile_tail() + + if stg.noise_method[data_id] == 0: + if stg.filename_BS_noise_data[data_id] != "": + self.load_noise_data_and_compute_SNR() + elif stg.noise_method[data_id] == 1: + self.compute_noise_from_profile_tail_value() + + self.compute_averaged_BS_data() + + @trace + def replot(self, *args): + self.plot_averaged_profile_tail() + self.plot_transect_with_SNR_data() + self.plot_pre_processed_BS_signal() + self.plot_pre_processed_profile() + def activate_list_of_pre_processed_data(self): for i in range(self.combobox_acoustic_data_choice.count()): eval("self.lineEdit_list_pre_processed_data_" + str(i) + ".setDisabled(True)") @@ -690,9 +712,6 @@ class SignalProcessingTab(QWidget): ) ) - if stg.BS_noise_raw_data[data_id].shape != (0,): - self.compute_noise_from_profile_tail_value() - @trace def plot_averaged_profile_tail(self, *args): @@ -761,20 +780,19 @@ class SignalProcessingTab(QWidget): # ------------------------------------------------------ def combobox_acoustic_data_choice_change_index(self): + self.combobox_frequency_profile.blockSignals(True) self.compute_average_profile_tail() - self.plot_averaged_profile_tail() self.lineEdit_SNR_criterion.setText(str(stg.SNR_filter_value[self.combobox_acoustic_data_choice.currentIndex()])) - self.plot_transect_with_SNR_data() - self.plot_pre_processed_BS_signal() self.lineEdit_horizontal_average.setText(str(stg.Nb_cells_to_average_BS_signal[self.combobox_acoustic_data_choice.currentIndex()])) self.combobox_frequency_profile.clear() self.combobox_frequency_profile.addItems( [f for f in stg.freq_text[self.combobox_acoustic_data_choice.currentIndex()]]) - self.plot_pre_processed_profile() + + self.replot() if self.combobox_acoustic_data_choice.count() > 0: @@ -784,12 +802,11 @@ class SignalProcessingTab(QWidget): eval("self.lineEdit_list_pre_processed_data_" + str( self.combobox_acoustic_data_choice.currentIndex()) + ".setEnabled(True)") + self.combobox_frequency_profile.blockSignals(False) + def clear_noise_data(self): - if len(stg.filename_BS_raw_data) == 0: - pass - else: stg.BS_noise_raw_data[self.combobox_acoustic_data_choice.currentIndex()] = np.array([]) @@ -981,7 +998,8 @@ class SignalProcessingTab(QWidget): pnw = PlotNoiseWindow() pnw.exec() - def compute_noise_from_profile_tail_value(self): + @trace + def compute_noise_from_profile_tail_value(self, *args): stg.noise_method[self.combobox_acoustic_data_choice.currentIndex()] = 1 @@ -1029,7 +1047,7 @@ class SignalProcessingTab(QWidget): stg.SNR_cross_section[self.combobox_acoustic_data_choice.currentIndex()] = ( np.divide((stg.BS_cross_section[self.combobox_acoustic_data_choice.currentIndex()] - stg.BS_noise_raw_data[self.combobox_acoustic_data_choice.currentIndex()]) ** 2, - stg.BS_noise_raw_data[self.combobox_acoustic_data_choice.currentIndex()] ** 2)) + stg.BS_noise_raw_data[self.combobox_acoustic_data_choice.currentIndex()] ** 2)) # else: @@ -1060,10 +1078,6 @@ class SignalProcessingTab(QWidget): else: self.slider.setMaximum(stg.time[self.combobox_acoustic_data_choice.currentIndex()].shape[1]) - self.plot_transect_with_SNR_data() - self.plot_pre_processed_BS_signal() - self.plot_pre_processed_profile() - # self.activate_list_of_pre_processed_data() @trace @@ -1309,33 +1323,34 @@ class SignalProcessingTab(QWidget): msgBox.exec() else: + data_id = self.combobox_acoustic_data_choice.currentIndex() - stg.SNR_filter_value[self.combobox_acoustic_data_choice.currentIndex()] = ( + stg.SNR_filter_value[data_id] = ( float(self.lineEdit_SNR_criterion.text().replace(",", "."))) - if stg.BS_stream_bed[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,): + if stg.BS_stream_bed[data_id].shape != (0,): stg.BS_stream_bed_pre_process_SNR = deepcopy(stg.BS_stream_bed) - for f, _ in enumerate(stg.freq[self.combobox_acoustic_data_choice.currentIndex()]): - stg.BS_stream_bed_pre_process_SNR[self.combobox_acoustic_data_choice.currentIndex()][ + for f, _ in enumerate(stg.freq[data_id]): + stg.BS_stream_bed_pre_process_SNR[data_id][ f, - np.where(stg.SNR_stream_bed[self.combobox_acoustic_data_choice.currentIndex()][f, :, :] < + np.where(stg.SNR_stream_bed[data_id][f, :, :] < float(self.lineEdit_SNR_criterion.text().replace(",", ".")))[0], - np.where(stg.SNR_stream_bed[self.combobox_acoustic_data_choice.currentIndex()][f, :, :] < + np.where(stg.SNR_stream_bed[data_id][f, :, :] < float(self.lineEdit_SNR_criterion.text().replace(",", ".")))[1]] \ = np.nan - elif stg.BS_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,): + elif stg.BS_cross_section[data_id].shape != (0,): stg.BS_cross_section_pre_process_SNR = deepcopy(stg.BS_cross_section) - for f, _ in enumerate(stg.freq[self.combobox_acoustic_data_choice.currentIndex()]): - stg.BS_cross_section_pre_process_SNR[self.combobox_acoustic_data_choice.currentIndex()][ + for f, _ in enumerate(stg.freq[data_id]): + stg.BS_cross_section_pre_process_SNR[data_id][ f, - np.where(stg.SNR_cross_section[self.combobox_acoustic_data_choice.currentIndex()][f, :, + np.where(stg.SNR_cross_section[data_id][f, :, :] < float(self.lineEdit_SNR_criterion.text().replace(",", ".")))[0], - np.where(stg.SNR_cross_section[self.combobox_acoustic_data_choice.currentIndex()][f, :, + np.where(stg.SNR_cross_section[data_id][f, :, :] < float(self.lineEdit_SNR_criterion.text().replace(",", ".")))[1]] \ = np.nan @@ -1343,17 +1358,16 @@ class SignalProcessingTab(QWidget): stg.BS_raw_data_pre_process_SNR = deepcopy(stg.BS_raw_data) - for f, _ in enumerate(stg.freq[self.combobox_acoustic_data_choice.currentIndex()]): - stg.BS_raw_data_pre_process_SNR[self.combobox_acoustic_data_choice.currentIndex()][ + for f, _ in enumerate(stg.freq[data_id]): + stg.BS_raw_data_pre_process_SNR[data_id][ f, - np.where(stg.SNR_raw_data[self.combobox_acoustic_data_choice.currentIndex()][f, :, + np.where(stg.SNR_raw_data[data_id][f, :, :] < float(self.lineEdit_SNR_criterion.text().replace(",", ".")))[0], - np.where(stg.SNR_raw_data[self.combobox_acoustic_data_choice.currentIndex()][f, :, + np.where(stg.SNR_raw_data[data_id][f, :, :] < float(self.lineEdit_SNR_criterion.text().replace(",", ".")))[1]] \ = np.nan self.compute_averaged_BS_data() - self.update_plot_pre_processed_profile() @trace def plot_pre_processed_BS_signal(self, *args): @@ -1386,6 +1400,7 @@ class SignalProcessingTab(QWidget): .addWidget(self.scroll_BS) if stg.time_cross_section[data_id].shape != (0,): + logger.info("time_cross_section") if stg.depth_cross_section[data_id].shape != (0,): x_time = stg.time_cross_section[data_id] y_depth = stg.depth_cross_section[data_id] @@ -1393,6 +1408,7 @@ class SignalProcessingTab(QWidget): x_time = stg.time_cross_section[data_id] y_depth = stg.depth[data_id] else: + logger.info("time") if stg.depth_cross_section[data_id].shape != (0,): x_time = stg.time[data_id] y_depth = stg.depth_cross_section[data_id] @@ -1489,7 +1505,6 @@ class SignalProcessingTab(QWidget): .addWidget(self.scroll_BS) def update_label_cells_sec(self): - print("Je change la valeur du moyennage") print(stg.nb_profiles_per_sec) print(stg.nb_profiles_per_sec[self.combobox_acoustic_data_choice.currentIndex()][0]) @@ -1501,8 +1516,8 @@ class SignalProcessingTab(QWidget): (1 / stg.nb_profiles_per_sec[self.combobox_acoustic_data_choice.currentIndex()][0])) + " sec") - def compute_averaged_BS_data(self): - + @trace + def compute_averaged_BS_data(self, *args): if len(stg.filename_BS_raw_data) == 0: msgBox = QMessageBox() msgBox.setWindowTitle("Compute noise from profile tail error") @@ -1618,9 +1633,6 @@ class SignalProcessingTab(QWidget): stg.BS_raw_data_pre_process_average[data_id][f, i, :] = ( convolve(stg.BS_raw_data[data_id][f, i, :], kernel_avg)) - self.plot_pre_processed_BS_signal() - self.update_plot_pre_processed_profile() - @trace def plot_pre_processed_profile(self, *args): data_id = self.combobox_acoustic_data_choice.currentIndex()