From 571ac20d37fb441431f222589aa267bda8a6d696 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby Date: Wed, 12 Mar 2025 16:36:53 +0100 Subject: [PATCH] Acoustic data: refactoring plot and fix #17. --- View/acoustic_data_tab.py | 117 ++++++++++++++++++++++++-------------- 1 file changed, 74 insertions(+), 43 deletions(-) diff --git a/View/acoustic_data_tab.py b/View/acoustic_data_tab.py index 4b16696..73c29a2 100644 --- a/View/acoustic_data_tab.py +++ b/View/acoustic_data_tab.py @@ -22,6 +22,7 @@ import os import locale +import logging import numpy as np import pandas as pd @@ -63,6 +64,7 @@ locale.setlocale(locale.LC_ALL, '') _translate = QCoreApplication.translate +logger = logging.getLogger() class AcousticDataTab(QWidget): COMPTEUR = 1 @@ -630,7 +632,7 @@ class AcousticDataTab(QWidget): self.fileListWidget.itemSelectionChanged.connect(self.compute_tmin_tmax) self.fileListWidget.itemSelectionChanged.connect(self.compute_rmin_rmax) self.fileListWidget.itemSelectionChanged.connect(self.update_frequency_combobox) - self.fileListWidget.itemSelectionChanged.connect(self.plot_backscattered_acoustic_signal_recording) + # self.fileListWidget.itemSelectionChanged.connect(self.plot_backscattered_acoustic_signal_recording) self.fileListWidget.itemSelectionChanged.connect(self.plot_profile) self.fileListWidget.itemSelectionChanged.connect(self.update_plot_backscattered_acoustic_signal_recording) self.fileListWidget.itemSelectionChanged.connect(self.update_plot_profile) @@ -1304,6 +1306,8 @@ class AcousticDataTab(QWidget): msgBox.setStandardButtons(QMessageBox.Ok) msgBox.exec() else: + self.fileListWidget.blockSignals(True) + if self.fileListWidget.count() == 0: for p, f in zip(stg.path_BS_raw_data, stg.filename_BS_raw_data): @@ -1332,6 +1336,8 @@ class AcousticDataTab(QWidget): ) ) + self.fileListWidget.blockSignals(False) + def rename_file_in_ListWidget(self, event): if event == QEvent.MouseButtonPress: @@ -2282,59 +2288,83 @@ class AcousticDataTab(QWidget): "-" + str("%.5s" % stg.depth[self.fileListWidget.currentRow()][0, 0])) def plot_backscattered_acoustic_signal_recording(self): + if self.fileListWidget.count() <= 0: + return - if self.fileListWidget.count() > 0: + layout = self.verticalLayout_groupbox_transect_2Dplot_raw_BS_data + file_id = self.fileListWidget.currentRow() + freq_id = self.combobox_frequency_profile.currentIndex() - self.verticalLayout_groupbox_transect_2Dplot_raw_BS_data.removeWidget(self.toolbar_BS) - self.verticalLayout_groupbox_transect_2Dplot_raw_BS_data.removeWidget(self.scroll_BS) + layout.removeWidget(self.toolbar_BS) + layout.removeWidget(self.scroll_BS) - self.fig_BS, self.axis_BS = plt.subplots(nrows=stg.freq[self.fileListWidget.currentRow()].shape[0], ncols=1, - sharex=False, sharey=False, layout="constrained") - self.canvas_BS = FigureCanvas(self.fig_BS) - self.toolbar_BS = NavigationToolBar(self.canvas_BS, self) + self.fig_BS, self.axis_BS = plt.subplots( + nrows=stg.freq[file_id].shape[0], + ncols=1, sharex=False, sharey=False, + layout="constrained" + ) + self.canvas_BS = FigureCanvas(self.fig_BS) + self.toolbar_BS = NavigationToolBar(self.canvas_BS, self) - self.scroll_BS.setWidget(self.canvas_BS) + self.scroll_BS.setWidget(self.canvas_BS) - self.verticalLayout_groupbox_transect_2Dplot_raw_BS_data.addWidget(self.toolbar_BS) - self.verticalLayout_groupbox_transect_2Dplot_raw_BS_data.addWidget(self.scroll_BS) + layout.addWidget(self.toolbar_BS) + layout.addWidget(self.scroll_BS) - for f, _ in enumerate(stg.freq[self.fileListWidget.currentRow()]): + for f, _ in enumerate(stg.freq[file_id]): + val_min = np.nanmin(stg.BS_raw_data[file_id][f, :, :]) + val_max = np.nanmax(stg.BS_raw_data[file_id][f, :, :]) + if val_min == 0: + val_min = 1e-5 - val_min = np.nanmin(stg.BS_raw_data[self.fileListWidget.currentRow()][f, :, :]) - val_max = np.nanmax(stg.BS_raw_data[self.fileListWidget.currentRow()][f, :, :]) - if val_min == 0: - val_min = 1e-5 + if self.combobox_ABS_system_choice.currentIndex() == 1: + pcm = self.axis_BS[f].pcolormesh( + stg.time[file_id][f, :], + -stg.depth[file_id][f, :], + stg.BS_raw_data[file_id][f, :, :], + cmap='viridis', + norm=LogNorm(vmin=val_min, vmax=val_max) + ) + elif self.combobox_ABS_system_choice.currentIndex() == 2: + pcm = self.axis_BS[f].pcolormesh( + stg.time[file_id][f, :], + -stg.depth[file_id][f, :], + np.log(stg.BS_raw_data[file_id][f, :, :]), + cmap='Blues' + ) - if self.combobox_ABS_system_choice.currentIndex() == 1: + self.axis_BS[f].text( + 1, .70, stg.freq_text[file_id][f], + fontsize=14, fontweight='bold', fontname="DejaVu Sans", + c="black", alpha=0.5, + horizontalalignment='right', verticalalignment='bottom', + transform=self.axis_BS[f].transAxes + ) - pcm = self.axis_BS[f].pcolormesh(stg.time[self.fileListWidget.currentRow()][f, :], - -stg.depth[self.fileListWidget.currentRow()][f, :], - stg.BS_raw_data[self.fileListWidget.currentRow()][f, :, :], - cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max)) + # --- Plot red solid line on transect to visualize position of + # --- plotted profile --- + self.axis_BS[freq_id].plot( + stg.time[file_id][ + freq_id, self.slider.value() - 1 + ] + * np.ones(stg.depth[file_id].shape[1]), + -stg.depth[file_id][freq_id, :], + color='red', linestyle="solid", linewidth=2 + ) - elif self.combobox_ABS_system_choice.currentIndex() == 2: - pcm = self.axis_BS[f].pcolormesh(stg.time[self.fileListWidget.currentRow()][f, :], - -stg.depth[self.fileListWidget.currentRow()][f, :], - np.log(stg.BS_raw_data[self.fileListWidget.currentRow()][f, :, :]), - cmap='Blues') + self.fig_BS.supxlabel('Time (sec)', fontsize=10) + self.fig_BS.supylabel('Depth (m)', fontsize=10) - self.axis_BS[f].text(1, .70, stg.freq_text[self.fileListWidget.currentRow()][f], - fontsize=14, fontweight='bold', fontname="DejaVu Sans", c="black", alpha=0.5, - horizontalalignment='right', verticalalignment='bottom', - transform=self.axis_BS[f].transAxes) + cbar = self.fig_BS.colorbar( + pcm, ax=self.axis_BS[:], + shrink=1, location='right' + ) - # --- Plot red solid line on transect to visualize position of plotted profile --- - self.axis_BS[self.combobox_frequency_profile.currentIndex()].plot( - stg.time[self.fileListWidget.currentRow()][self.combobox_frequency_profile.currentIndex(), - self.slider.value() - 1] * np.ones(stg.depth[self.fileListWidget.currentRow()].shape[1]), - -stg.depth[self.fileListWidget.currentRow()][self.combobox_frequency_profile.currentIndex(), :], - color='red', linestyle="solid", linewidth=2) - - self.fig_BS.supxlabel('Time (sec)', fontsize=10) - self.fig_BS.supylabel('Depth (m)', fontsize=10) - cbar = self.fig_BS.colorbar(pcm, ax=self.axis_BS[:], shrink=1, location='right') - cbar.set_label(label='Acoustic backscatter signal (V)', rotation=270, labelpad=10) - self.fig_BS.canvas.draw_idle() + cbar.set_label( + label='Acoustic backscatter signal (V)', + rotation=270, labelpad=10 + ) + self.fig_BS.canvas.draw_idle() def update_plot_backscattered_acoustic_signal_recording(self): @@ -2465,7 +2495,8 @@ class AcousticDataTab(QWidget): self.combobox_frequency_profile.currentIndexChanged.connect(self.update_plot_profile) self.combobox_frequency_profile.currentIndexChanged.connect( - self.update_plot_backscattered_acoustic_signal_recording) + self.update_plot_backscattered_acoustic_signal_recording + ) self.slider.setMaximum(stg.time[self.fileListWidget.currentRow()].shape[1])