diff --git a/View/signal_processing_tab.py b/View/signal_processing_tab.py index 7b504d3..01059db 100644 --- a/View/signal_processing_tab.py +++ b/View/signal_processing_tab.py @@ -431,11 +431,13 @@ class SignalProcessingTab(QWidget): self.widget_scrollArea_list_preprocessed_data.setLayout(self.verticalLayout_scrollArea_list_pre_processed_data) # Add content to the widget (labels in this example) + self.lineEdit_list_pre_processed_data = [] for i in range(20): - exec("self.lineEdit_list_pre_processed_data_" + str(i) + "= QLineEdit()") - eval("self.verticalLayout_scrollArea_list_pre_processed_data.addWidget(" - "self.lineEdit_list_pre_processed_data_" + str(i) + ")") - eval("self.lineEdit_list_pre_processed_data_" + str(i) + ".setDisabled(True)") + self.lineEdit_list_pre_processed_data.append(QLineEdit()) + self.verticalLayout_scrollArea_list_pre_processed_data.addWidget( + self.lineEdit_list_pre_processed_data[i] + ) + self.lineEdit_list_pre_processed_data[i].setDisabled(True) # Set the widget as the scroll area's widget @@ -531,7 +533,7 @@ class SignalProcessingTab(QWidget): self.blockSignals(False) def full_update_fill_text(self): - data_id = self.combobox_acoustic_data_choice.currentIndex() + data_id = max(0, self.combobox_acoustic_data_choice.currentIndex()) self.lineEdit_profile_tail_value.setText( str(stg.noise_value[data_id]) @@ -559,7 +561,7 @@ class SignalProcessingTab(QWidget): msgBox.setStandardButtons(QMessageBox.Ok) msgBox.exec() else: - data_id = self.combobox_acoustic_data_choice.currentIndex() + data_id = max(0, self.combobox_acoustic_data_choice.currentIndex()) self.combobox_acoustic_data_choice.blockSignals(True) self.combobox_freq_noise_from_profile_tail.blockSignals(True) @@ -592,7 +594,7 @@ class SignalProcessingTab(QWidget): self.combobox_acoustic_data_choice.blockSignals(False) def _is_correct_shape(self, data): - data_id = self.combobox_acoustic_data_choice.currentIndex() + data_id = max(0, self.combobox_acoustic_data_choice.currentIndex()) if stg.time_cross_section[data_id].shape != (0,): x_time = stg.time_cross_section[data_id] @@ -619,7 +621,7 @@ class SignalProcessingTab(QWidget): return (y == depth_shape and z == time_shape) def recompute(self): - data_id = self.combobox_acoustic_data_choice.currentIndex() + data_id = max(0, self.combobox_acoustic_data_choice.currentIndex()) self.compute_average_profile_tail() @@ -639,19 +641,21 @@ class SignalProcessingTab(QWidget): 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)") - eval("self.lineEdit_list_pre_processed_data_" + str( - self.combobox_acoustic_data_choice.currentIndex()) + ".setEnabled(True)") - eval("self.lineEdit_list_pre_processed_data_" + str( - self.combobox_acoustic_data_choice.currentIndex()) + ".returnPressed.connect(self.rename_preprocessed_data)") + data_id = max(0, self.combobox_acoustic_data_choice.currentIndex()) - eval("self.lineEdit_list_pre_processed_data_" + str(self.combobox_acoustic_data_choice.currentIndex()) + - ".setText(stg.filename_BS_raw_data[self.combobox_acoustic_data_choice.currentIndex()])") + for i in range(self.combobox_acoustic_data_choice.count()): + self.lineEdit_list_pre_processed_data[i].setDisabled(True) + + self.lineEdit_list_pre_processed_data[data_id].setEnabled(True) + self.lineEdit_list_pre_processed_data[data_id]\ + .returnPressed.connect(self.rename_preprocessed_data) + + self.lineEdit_list_pre_processed_data[data_id]\ + .setText(stg.filename_BS_raw_data[data_id]) def rename_preprocessed_data(self): - exec("stg.data_preprocessed[self.combobox_acoustic_data_choice.currentIndex()] = " - "self.lineEdit_list_pre_processed_data_" + str(self.combobox_acoustic_data_choice.currentIndex()) + ".text()") + stg.data_preprocessed[data_id] = \ + self.lineEdit_list_pre_processed_data[data_id].text() # ------------------------------------------------------ @@ -703,7 +707,7 @@ class SignalProcessingTab(QWidget): # ------------------------------------------------------ def compute_average_profile_tail(self): - data_id = self.combobox_acoustic_data_choice.currentIndex() + data_id = max(0, self.combobox_acoustic_data_choice.currentIndex()) freq_noise_id = self.combobox_freq_noise_from_profile_tail.currentIndex() if ((float(self.lineEdit_val1.text()) == 0) @@ -790,7 +794,7 @@ class SignalProcessingTab(QWidget): msgBox.exec() else: - data_id = self.combobox_acoustic_data_choice.currentIndex() + data_id = max(0, self.combobox_acoustic_data_choice.currentIndex()) freq_noise_id = self.combobox_freq_noise_from_profile_tail.currentIndex() if stg.BS_mean[data_id].shape == (0,): @@ -851,36 +855,35 @@ class SignalProcessingTab(QWidget): # ------------------------------------------------------ def combobox_acoustic_data_choice_change_index(self): + data_id = max(0, self.combobox_acoustic_data_choice.currentIndex()) + self.combobox_frequency_profile.blockSignals(True) self.compute_average_profile_tail() + logger.debug(f"stg.SNR_filter_value: {stg.SNR_filter_value}") + self.lineEdit_SNR_criterion.setText( - str(stg.SNR_filter_value[ - self.combobox_acoustic_data_choice.currentIndex() - ]) + str(stg.SNR_filter_value[data_id]) ) self.lineEdit_horizontal_average.setText( - str(stg.Nb_cells_to_average_BS_signal[ - self.combobox_acoustic_data_choice.currentIndex() - ]) + str(stg.Nb_cells_to_average_BS_signal[data_id]) ) self.combobox_frequency_profile.clear() self.combobox_frequency_profile.addItems( - [f for f in stg.freq_text[self.combobox_acoustic_data_choice.currentIndex()]]) + [f for f in stg.freq_text[data_id]] + ) self.recompute() self.replot() if self.combobox_acoustic_data_choice.count() > 0: - for i in range(self.combobox_acoustic_data_choice.count()): - eval("self.lineEdit_list_pre_processed_data_" + str(i) + ".setDisabled(True)") - # - eval("self.lineEdit_list_pre_processed_data_" + str( - self.combobox_acoustic_data_choice.currentIndex()) + ".setEnabled(True)") + self.lineEdit_list_pre_processed_data[i].setDisabled(True) + + self.lineEdit_list_pre_processed_data[data_id].setEnabled(True) self.combobox_frequency_profile.blockSignals(False) @@ -888,7 +891,7 @@ class SignalProcessingTab(QWidget): if len(stg.filename_BS_raw_data) == 0: pass else: - data_id = self.combobox_acoustic_data_choice.currentIndex() + data_id = max(0, self.combobox_acoustic_data_choice.currentIndex()) stg.BS_noise_raw_data[data_id] = np.array([]) stg.BS_noise_averaged_data[data_id] = np.array([]) @@ -1027,7 +1030,7 @@ class SignalProcessingTab(QWidget): def load_noise_data_and_compute_SNR(self): - data_id = self.combobox_acoustic_data_choice.currentIndex() + data_id = max(0, self.combobox_acoustic_data_choice.currentIndex()) stg.noise_method[data_id] = 0 @@ -1081,7 +1084,7 @@ class SignalProcessingTab(QWidget): pnw.exec() def compute_noise_from_profile_tail_value(self): - data_id = self.combobox_acoustic_data_choice.currentIndex() + data_id = max(0, self.combobox_acoustic_data_choice.currentIndex()) stg.noise_method[data_id] = 1 stg.noise_value[data_id] = ( @@ -1134,7 +1137,6 @@ class SignalProcessingTab(QWidget): stg.BS_noise_raw_data[data_id] ** 2)) # else: - stg.BS_noise_raw_data[data_id] = ( np.full(stg.BS_raw_data[data_id].shape, float(self.lineEdit_profile_tail_value.text().replace(",", ".")))) @@ -1213,7 +1215,7 @@ class SignalProcessingTab(QWidget): # elif self.canvas_SNR == None: else: - data_id = self.combobox_acoustic_data_choice.currentIndex() + data_id = max(0, self.combobox_acoustic_data_choice.currentIndex()) if ((data_id != -1) and (stg.BS_noise_raw_data[data_id].shape != (0,))): @@ -1342,7 +1344,7 @@ class SignalProcessingTab(QWidget): msgBox.exec() else: - data_id = self.combobox_acoustic_data_choice.currentIndex() + data_id = max(0, self.combobox_acoustic_data_choice.currentIndex()) stg.SNR_filter_value[data_id] = ( float(self.lineEdit_SNR_criterion.text().replace(",", "."))) @@ -1389,7 +1391,7 @@ class SignalProcessingTab(QWidget): self.compute_averaged_BS_data() def plot_pre_processed_BS_signal(self): - data_id = self.combobox_acoustic_data_choice.currentIndex() + data_id = max(0, self.combobox_acoustic_data_choice.currentIndex()) self.lineEdit_horizontal_average.setText( str(stg.Nb_cells_to_average_BS_signal[data_id]) @@ -1518,16 +1520,18 @@ 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]) - print(self.combobox_acoustic_data_choice.currentIndex()) + data_id = max(0, self.combobox_acoustic_data_choice.currentIndex()) + self.label_cells_horizontal.clear() self.label_cells_horizontal.setText( - "cells = +/- " + - str((float(self.lineEdit_horizontal_average.text().replace(",", ".")) // 2) * - (1 / stg.nb_profiles_per_sec[self.combobox_acoustic_data_choice.currentIndex()][0])) + - " sec") + "cells = +/- " + + str( + (float( + self.lineEdit_horizontal_average.text().replace(",", ".") + ) // 2) + * (1 / stg.nb_profiles_per_sec[data_id][0]) + ) + " sec" + ) def compute_averaged_BS_data(self): if len(stg.filename_BS_raw_data) == 0: @@ -1545,7 +1549,7 @@ class SignalProcessingTab(QWidget): msgBox.setStandardButtons(QMessageBox.Ok) msgBox.exec() else: - data_id = self.combobox_acoustic_data_choice.currentIndex() + data_id = max(0, self.combobox_acoustic_data_choice.currentIndex()) n_average = 2 * int(float(self.lineEdit_horizontal_average.text().replace(",", "."))) + 1 kernel_avg = np.ones(n_average) logger.debug(f"kernel_avg: {kernel_avg}") @@ -1629,7 +1633,7 @@ class SignalProcessingTab(QWidget): ) def plot_pre_processed_profile(self): - data_id = self.combobox_acoustic_data_choice.currentIndex() + data_id = max(0, self.combobox_acoustic_data_choice.currentIndex()) if ((data_id != -1) and (stg.BS_noise_raw_data[data_id].shape != (0,))): @@ -1861,7 +1865,7 @@ class SignalProcessingTab(QWidget): self.slider.setMaximum(10) def update_plot_pre_processed_profile(self): - data_id = self.combobox_acoustic_data_choice.currentIndex() + data_id = max(0, self.combobox_acoustic_data_choice.currentIndex()) if ((data_id != -1) and (stg.BS_noise_raw_data[data_id].shape != (0,))):