Signal processing: Some refactoring.

dev
Pierre-Antoine 2025-04-23 11:41:12 +02:00
parent 99103bc98a
commit 79ee1c3cfa
1 changed files with 54 additions and 50 deletions

View File

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