Signal processing: Fix #8 and clean debug display code.

dev-brahim
Pierre-Antoine 2025-03-20 10:33:16 +01:00
parent be7627d93f
commit 998e1e7f8f
1 changed files with 80 additions and 100 deletions

View File

@ -475,6 +475,7 @@ class SignalProcessingTab(QWidget):
self.lineEdit_horizontal_average.returnPressed.connect(self.update_label_cells_sec)
self.pushbutton_average.clicked.connect(self.compute_averaged_BS_data)
self.pushbutton_average.clicked.connect(self.replot)
self.pushbutton_slider_left_to_begin.clicked.connect(self.slide_profile_number_to_begin)
@ -561,8 +562,7 @@ class SignalProcessingTab(QWidget):
self.combobox_freq_noise_from_profile_tail.blockSignals(False)
self.combobox_acoustic_data_choice.blockSignals(False)
@trace
def recompute(self, *args):
def recompute(self):
data_id = self.combobox_acoustic_data_choice.currentIndex()
self.compute_average_profile_tail()
@ -573,10 +573,10 @@ class SignalProcessingTab(QWidget):
elif stg.noise_method[data_id] == 1:
self.compute_noise_from_profile_tail_value()
self.remove_point_with_snr_filter()
self.compute_averaged_BS_data()
@trace
def replot(self, *args):
def replot(self):
self.plot_averaged_profile_tail()
self.plot_transect_with_SNR_data()
self.plot_pre_processed_BS_signal()
@ -646,8 +646,7 @@ class SignalProcessingTab(QWidget):
self.animation_groupbox_option_profile_tail.start()
# ------------------------------------------------------
@trace
def compute_average_profile_tail(self, *args):
def compute_average_profile_tail(self):
data_id = self.combobox_acoustic_data_choice.currentIndex()
freq_noise_id = self.combobox_freq_noise_from_profile_tail.currentIndex()
@ -712,8 +711,7 @@ class SignalProcessingTab(QWidget):
)
)
@trace
def plot_averaged_profile_tail(self, *args):
def plot_averaged_profile_tail(self):
# --- Plot averaged signal ---
@ -998,8 +996,7 @@ class SignalProcessingTab(QWidget):
pnw = PlotNoiseWindow()
pnw.exec()
@trace
def compute_noise_from_profile_tail_value(self, *args):
def compute_noise_from_profile_tail_value(self):
stg.noise_method[self.combobox_acoustic_data_choice.currentIndex()] = 1
@ -1080,8 +1077,7 @@ class SignalProcessingTab(QWidget):
# self.activate_list_of_pre_processed_data()
@trace
def plot_noise(self, *args):
def plot_noise(self):
self.horizontalLayout_groupbox_plot_noise_data.removeWidget(self.canvas_noise)
self.fig_noise, self.axis_noise = plt.subplots(nrows=1, ncols=1, layout="constrained")
@ -1112,8 +1108,7 @@ class SignalProcessingTab(QWidget):
self.axis_noise.tick_params(axis='both', which='minor', labelsize=10)
@trace
def plot_transect_with_SNR_data(self, *args):
def plot_transect_with_SNR_data(self):
# --- Condition if table is not filled ---
# if not self.lineEdit_noise_file.text():
if len(stg.BS_noise_raw_data) == 0:
@ -1305,6 +1300,8 @@ class SignalProcessingTab(QWidget):
self.verticalLayout_groupbox_plot_SNR.addWidget(self.scroll_SNR)
def remove_point_with_snr_filter(self):
if self.lineEdit_SNR_criterion.text() == '':
return
if len(stg.filename_BS_raw_data) == 0:
msgBox = QMessageBox()
@ -1369,8 +1366,7 @@ class SignalProcessingTab(QWidget):
self.compute_averaged_BS_data()
@trace
def plot_pre_processed_BS_signal(self, *args):
def plot_pre_processed_BS_signal(self):
data_id = self.combobox_acoustic_data_choice.currentIndex()
self.lineEdit_horizontal_average.setText(
@ -1400,7 +1396,6 @@ 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]
@ -1408,7 +1403,6 @@ 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]
@ -1416,31 +1410,31 @@ class SignalProcessingTab(QWidget):
x_time = stg.time[data_id]
y_depth = stg.depth[data_id]
for f, _ in enumerate(stg.freq[data_id]):
bed = False
logger.debug(f"x_time: {x_time[data_id].shape}")
logger.debug(f"y_depth: {y_depth[data_id].shape}")
for f, _ in enumerate(stg.freq[data_id]):
if stg.BS_stream_bed_pre_process_average[data_id].shape != (0,):
BS_data = stg.BS_stream_bed_pre_process_average
bed = True
elif stg.BS_cross_section_pre_process_average[data_id].shape != (0,):
BS_data = stg.BS_cross_section_pre_process_average
elif stg.BS_raw_data_pre_process_average[data_id].shape != (0,):
BS_data = stg.BS_raw_data_pre_process_average
elif stg.BS_stream_bed_pre_process_SNR[data_id].shape != (0,):
BS_data = stg.BS_stream_bed_pre_process_SNR
bed = True
elif stg.BS_cross_section_pre_process_SNR[data_id].shape != (0,):
BS_data = stg.BS_cross_section_pre_process_SNR
elif stg.BS_raw_data_pre_process_SNR[data_id].shape != (0,):
BS_data = stg.BS_raw_data_pre_process_SNR
elif stg.BS_stream_bed[data_id].shape != (0,):
BS_data = stg.BS_stream_bed
bed = True
elif stg.BS_cross_section[data_id].shape != (0,):
BS_data = stg.BS_cross_section
elif stg.BS_raw_data[data_id].shape != (0,):
BS_data = stg.BS_raw_data
logger.debug(f"BS_data: {BS_data[data_id].shape}")
val_min = np.nanmin(
BS_data[data_id][f, :, :]
)
@ -1457,7 +1451,7 @@ class SignalProcessingTab(QWidget):
cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max)
)
if bed:
if stg.depth_bottom[data_id].shape != (0,):
self.axis_BS[f].plot(
x_time[f, :], -stg.depth_bottom[data_id],
color='black', linewidth=1, linestyle="solid"
@ -1516,8 +1510,7 @@ class SignalProcessingTab(QWidget):
(1 / stg.nb_profiles_per_sec[self.combobox_acoustic_data_choice.currentIndex()][0])) +
" sec")
@trace
def compute_averaged_BS_data(self, *args):
def compute_averaged_BS_data(self):
if len(stg.filename_BS_raw_data) == 0:
msgBox = QMessageBox()
msgBox.setWindowTitle("Compute noise from profile tail error")
@ -1525,7 +1518,6 @@ class SignalProcessingTab(QWidget):
msgBox.setText("Download acoustic data in previous tab before applying SNR filter")
msgBox.setStandardButtons(QMessageBox.Ok)
msgBox.exec()
elif len(stg.BS_noise_raw_data) == 0:
msgBox = QMessageBox()
msgBox.setWindowTitle("SNR filter Error")
@ -1533,108 +1525,96 @@ class SignalProcessingTab(QWidget):
msgBox.setText("Define noise data (file or profile tail) before using SNR filter")
msgBox.setStandardButtons(QMessageBox.Ok)
msgBox.exec()
else:
data_id = self.combobox_acoustic_data_choice.currentIndex()
kernel_avg = np.ones(2 * int(float(self.lineEdit_horizontal_average.text().replace(",", "."))) + 1)
print(kernel_avg)
kernel_avg = np.ones(
2 * int(
float(
self.lineEdit_horizontal_average\
.text()\
.replace(",", ".")
)
) + 1
)
logger.debug(f"kernel_avg: {kernel_avg}")
stg.Nb_cells_to_average_BS_signal[data_id] = (
float(self.lineEdit_horizontal_average.text().replace(",", ".")))
float(
self.lineEdit_horizontal_average\
.text().replace(",", ".")
)
)
if stg.time_cross_section[data_id].shape != (0,):
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]
elif stg.depth[data_id].shape != (0,):
x_time = stg.time_cross_section[data_id]
y_depth = stg.depth[data_id]
else:
if stg.depth_cross_section[data_id].shape != (0,):
x_time = stg.time[data_id]
y_depth = stg.depth_cross_section[data_id]
elif stg.depth[data_id].shape != (0,):
x_time = stg.time[data_id]
y_depth = stg.depth[data_id]
if stg.BS_stream_bed_pre_process_SNR[data_id].shape != (0,):
BS = [
stg.BS_stream_bed_pre_process_SNR,
stg.BS_cross_section_pre_process_SNR,
stg.BS_raw_data_pre_process_SNR,
stg.BS_stream_bed,
stg.BS_cross_section,
stg.BS_raw_data,
]
stg.BS_stream_bed_pre_process_average[data_id] = (deepcopy(
stg.BS_stream_bed_pre_process_SNR[data_id]))
BS_ppa = [
stg.BS_stream_bed_pre_process_average,
stg.BS_cross_section_pre_process_average,
stg.BS_raw_data_pre_process_average,
stg.BS_stream_bed_pre_process_average,
stg.BS_cross_section_pre_process_average,
stg.BS_raw_data_pre_process_average,
]
for f, _ in enumerate(stg.freq[data_id]):
for i in range(y_depth.shape[1]):
time_shape, = x_time[data_id].shape
depth_shape, = y_depth[data_id].shape
logger.debug(f"time_shape: {time_shape}")
logger.debug(f"depth_shape: {depth_shape}")
stg.BS_stream_bed_pre_process_average[data_id][f, i, :] = (
convolve(stg.BS_stream_bed_pre_process_SNR[data_id][f, i, :],
kernel_avg))
BS_data = stg.BS_raw_data
BS_data_ppa = stg.BS_raw_data_pre_process_average
for i in range(len(BS)):
bs = BS[i]
logger.debug(f"BS data shape {bs[data_id].shape}")
if bs[data_id].shape == (0,):
continue
elif stg.BS_cross_section_pre_process_SNR[data_id].shape != (0,):
x, y, z = bs[data_id].shape
if y == depth_shape and z == time_shape:
BS_data = bs
BS_data_ppa = BS_ppa[i]
break
stg.BS_cross_section_pre_process_average[data_id] = (deepcopy(
stg.BS_cross_section_pre_process_SNR[data_id]))
logger.debug(f"BS_data: {BS_data[data_id].shape}")
for f, _ in enumerate(stg.freq[data_id]):
for i in range(y_depth.shape[1]):
BS_data_ppa[data_id] = deepcopy(BS_data[data_id])
stg.BS_cross_section_pre_process_average[data_id][f, i, :] = (
convolve(stg.BS_cross_section_pre_process_SNR[data_id][f, i, :],
kernel_avg))
for f, _ in enumerate(stg.freq[data_id]):
for i in range(y_depth.shape[1]):
BS_data_ppa[data_id][f, i, :] = (
convolve(
BS_data[data_id][f, i, :],
kernel_avg
)
)
elif stg.BS_raw_data_pre_process_SNR[data_id].shape != (0,):
logger.debug(
f"BS_data_ppa: {BS_data_ppa[data_id].shape}"
)
stg.BS_raw_data_pre_process_average[data_id] = (deepcopy(
stg.BS_raw_data_pre_process_SNR[data_id]))
for f, _ in enumerate(stg.freq[data_id]):
for i in range(y_depth.shape[1]):
stg.BS_raw_data_pre_process_average[data_id][f, i, :] = (
convolve(stg.BS_raw_data_pre_process_SNR[data_id][f, i, :],
kernel_avg))
elif stg.BS_stream_bed[data_id].shape != (0,):
stg.BS_stream_bed_pre_process_average[data_id] = (deepcopy(
stg.BS_stream_bed[data_id]))
for f, _ in enumerate(stg.freq[data_id]):
for i in range(y_depth.shape[1]):
stg.BS_stream_bed_pre_process_average[data_id][f, i, :] = (
convolve(stg.BS_stream_bed[data_id][f, i, :], kernel_avg))
elif stg.BS_cross_section[data_id].shape != (0,):
stg.BS_cross_section_pre_process_average[data_id] = (deepcopy(
stg.BS_cross_section[data_id]))
for f, _ in enumerate(stg.freq[data_id]):
for i in range(y_depth.shape[1]):
stg.BS_cross_section_pre_process_average[data_id][f, i, :] = (
convolve(stg.BS_cross_section[data_id][f, i, :],
kernel_avg))
elif stg.BS_raw_data[data_id].shape != (0,):
stg.BS_raw_data_pre_process_average[data_id] = (deepcopy(
stg.BS_raw_data[data_id]))
for f, _ in enumerate(stg.freq[data_id]):
for i in range(y_depth.shape[1]):
stg.BS_raw_data_pre_process_average[data_id][f, i, :] = (
convolve(stg.BS_raw_data[data_id][f, i, :], kernel_avg))
@trace
def plot_pre_processed_profile(self, *args):
def plot_pre_processed_profile(self):
data_id = self.combobox_acoustic_data_choice.currentIndex()
if ((data_id != -1) and