diff --git a/View/acoustic_data_tab.py b/View/acoustic_data_tab.py index 240f532..f26071e 100644 --- a/View/acoustic_data_tab.py +++ b/View/acoustic_data_tab.py @@ -18,6 +18,8 @@ from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as Navigatio from os import path from copy import deepcopy +import locale +locale.setlocale(locale.LC_ALL, '') # import Translation.biblio_string as bs import Translation.constant_string as cs @@ -392,7 +394,7 @@ class AcousticDataTab(QWidget): self.label_xmax_m.setText("m") self.gridLayout_groupbox_xaxis_space.addWidget(self.label_xmax_m, 0, 7, 1, 1) - # --- Group Box bathymetry computation algorithm to plot bottom of transect--- + # --- Group Box bathymetry computation algorithm to detect and plot bottom of transect--- self.groupbox_compute_bathymetry = QGroupBox() # # self.groupbox_crosssectionbottom.setTitle("Plot bottom of cross section") @@ -433,9 +435,7 @@ class AcousticDataTab(QWidget): self.pushbutton_compute_bathymetry_algorithm.setText("Compute \n&& \nPlot") self.gridlayout_compute_bathymetry.addWidget(self.pushbutton_compute_bathymetry_algorithm, 0, 7, 2, 1) - # self.pushButton_plot = QPushButton() - # self.pushButton_plot.setText("Plot") - # self.verticalLayout_displayoption.addWidget(self.pushButton_plot) + self.pushbutton_compute_bathymetry_algorithm.clicked.connect(self.detect_bottom) # ===================================================== # BOTTOM HORIZONTAL BOX LAYOUT @@ -1047,57 +1047,102 @@ class AcousticDataTab(QWidget): # cbar.set_ticklabels(['0', '1', '2', '10', '100', r'10$^3$', r'10$^6$']) self.fig_SNR.canvas.draw_idle() + def detect_bottom(self): + if self.lineEdit_acoustic_file.text() == "": + msgBox = QMessageBox() + msgBox.setWindowTitle("Detect bottom Error") + msgBox.setIcon(QMessageBox.Warning) + msgBox.setText("Load data before compute bathymety algorithm") + msgBox.setStandardButtons(QMessageBox.Ok) + msgBox.exec() + elif self.tableModel.rowCount(1) == 10: + msgBox = QMessageBox() + msgBox.setWindowTitle("Detect bottom Error") + msgBox.setIcon(QMessageBox.Warning) + msgBox.setText("Fill table before compute bathymety algorithm") + msgBox.setStandardButtons(QMessageBox.Ok) + msgBox.exec() + elif self.canvas_BS == None: + msgBox = QMessageBox() + msgBox.setWindowTitle("Detect bottom Error") + msgBox.setIcon(QMessageBox.Warning) + msgBox.setText("Plot transect before compute bathymety algorithm") + msgBox.setStandardButtons(QMessageBox.Ok) + msgBox.exec() + else: + acoustic_data = self.load_BS_acoustic_raw_data() + # Selecting the range in which we look for the bottom reflection + rmin = np.int(self.spinbox_depth_min.text()) # 4 + rmax = np.int(self.spinbox_depth_max.text()) # 8 - # self.ax[f].plot(self.model.r_bottom_cross_section, color='red', linewidth=2) - # - # def plot_snr_data(self): - # - # # self.canvas_snrdata = FigureCanvas(self.figure) - # - # frequency = self._model.Freq - # for f in range(len(frequency)): - # # self.axis = self.figure.add_subplot(4, 1, f+1) - # val_min = np.nanmin(self._model.snr[:, f, :]) - # val_max = np.nanmax(self._model.snr[:, f, :]) - # # val_min = np.nanmin(self.model.V_noise[:, f, :]) - # # val_max = np.nanmax(self.model.V_noise[:, f, :]) - # # if val_min == 0: - # # val_min = 0.5 - # if val_min == 0: - # val_min = 0.5 - # # self.axis[f].imshow(np.asarray(np.array(self.model.V_noise[:, f, :], dtype=float)), aspect='auto', - # # extent=[0, 2300, self.model.depth[-1][0], self.model.depth[0][0]], - # # cmap='hsv', norm=LogNorm(vmin=val_min, vmax=val_max)) - # - # # self.axis[f].pcolormesh(self.model.dist_BS_section, np.flipud(self.model.BS_raw_cross_section.r), - # # self.model.snr[:, f, :], - # # cmap='hsv', norm=LogNorm(vmin=val_min, vmax=val_max), shading='gouraud') - # - # x, y = np.meshgrid(self._model.dist_BS_section, self._model.BS_raw_cross_section.r) - # if val_max > 1000: - # levels = np.array([00.1, 1, 2, 10, 100, 1000, val_max]) - # else: - # levels = np.array([00.1, 1, 2, 10, 100, val_max]) - # bounds = [00.1, 1, 2, 10, 100, 1000, val_max, val_max * 1.2] - # norm = BoundaryNorm(boundaries=bounds, ncolors=300) - # pcm_snr = self.axis[f].contourf(x, y, np.flipud(self._model.snr[:, f, :]), levels, - # cmap='gist_rainbow', linewidths=None, norm=norm, - # extent=[self._model.dist_BS_section[0], self._model.dist_BS_section[-1], - # self._model.BS_raw_cross_section.r[-1], self._model.BS_raw_cross_section.r[0]]) - # - # self.axis[f].plot(self._model.dist_BS_section, - # np.max(self._model.r_bottom_cross_section) - self._model.r_bottom_cross_section + np.min( - # self._model.r_bottom_cross_section), - # color='k', linewidth=2) - # self.axis[f].text(1, .70, self._model.freq_text[f], - # fontsize=14, fontweight='bold', fontname="Ubuntu", c="black", alpha=0.5, - # horizontalalignment='right', verticalalignment='bottom', transform=self.axis[f].transAxes) - # - # self.figure.supxlabel('Distance from left bank (m)', fontsize=10) - # self.figure.supylabel('Depth (m)', fontsize=10) - # # self.figure.tight_layout() - # cbar_snr = self.figure.colorbar(pcm_snr, ax=self.axis[:], shrink=1, location='right') - # cbar_snr.set_label(label='SNR', rotation=270) - # self.figure.canvas.draw_idle() - # - # + # empty result arrays + r_bottom = np.zeros(acoustic_data._nb_profiles) + val_bottom = np.zeros(acoustic_data._nb_profiles) + r_bottom_ind = [] + # ----------- Detecting the bottom ------------- + for d in range(acoustic_data._nb_profiles): + # Index of the range where we look for the peak + ind_min = np.where(acoustic_data._r >= rmin)[0][0] + ind_max = np.where(acoustic_data._r <= rmax)[0][-1] + # Getting the peak + val_bottom[d] = np.nanmax(acoustic_data._BS_raw_data[ind_min:ind_max, + self.combobox_freq_choice.currentIndex() - 1, d]) + # Getting the range cell of the peak + ind_bottom = np.where(acoustic_data._BS_raw_data[ind_min:ind_max, + self.combobox_freq_choice.currentIndex() - 1, d] == val_bottom[d])[0][0] + r_bottom[d] = acoustic_data._r[ind_bottom + ind_min] + r_bottom_ind.append(ind_bottom + ind_min) + # Updating the range where we will look for the peak (in the next cell) + rmin = r_bottom[d] - locale.atof(self.doublespinbox_next_cell.text()) # 0.75 + rmax = r_bottom[d] + locale.atof(self.doublespinbox_next_cell.text()) # 0.75 + + BS_section_bottom = np.zeros((acoustic_data._BS_raw_data.shape[0], acoustic_data._BS_raw_data.shape[2])) + + for i in range(BS_section_bottom.shape[0]): + # print(r_bottom_temp_ind[i]) + # print(i) + BS_section_bottom[r_bottom_ind[i]][i] = 1 + # print(BS_section_bottom[r_bottom_temp_ind[i]][i]) + + # --- Plot transect with bathymetry --- + for f in range(acoustic_data._freq.shape[0]): + self.axis_BS[f].cla() + + val_min = np.min(acoustic_data._BS_raw_data[:, f, :]) + val_max = np.max(acoustic_data._BS_raw_data[:, f, :]) + if val_min == 0: + val_min = 1e-5 + + pcm = self.axis_BS[f].pcolormesh( + acoustic_data._time[np.where(np.round(acoustic_data._time, 2) == self.spinbox_tmin.value())[0][0]: + np.where(np.round(acoustic_data._time, 2) == self.spinbox_tmax.value())[0][0]], + acoustic_data._r , + np.flipud(acoustic_data._BS_raw_data[:, f, + np.where(np.round(acoustic_data._time, 2) == self.spinbox_tmin.value())[0][0]: + np.where(np.round(acoustic_data._time, 2) == self.spinbox_tmax.value())[0][0]]), + cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max))#, shading='gouraud') + + self.axis_BS[f].plot( + acoustic_data._time[np.where(np.round(acoustic_data._time, 2) == self.spinbox_tmin.value())[0][0]: + np.where(np.round(acoustic_data._time, 2) == self.spinbox_tmax.value())[0][0]], + np.max(r_bottom[np.where(np.round(acoustic_data._time, 2) == self.spinbox_tmin.value())[0][0]: + np.where(np.round(acoustic_data._time, 2) == self.spinbox_tmax.value())[0][0]]) + - r_bottom[np.where(np.round(acoustic_data._time, 2) == self.spinbox_tmin.value())[0][0]: + np.where(np.round(acoustic_data._time, 2) == self.spinbox_tmax.value())[0][0]] + + np.min(r_bottom[np.where(np.round(acoustic_data._time, 2) == self.spinbox_tmin.value())[0][0]: + np.where(np.round(acoustic_data._time, 2) == self.spinbox_tmax.value())[0][0]]), + # np.max(self._model.r_bottom_cross_section) - self._model.r_bottom_cross_section + np.min(self._model.r_bottom_cross_section), + color='black', linewidth=1, linestyle="--") + + # self.axis_BS[f].text(1, .70, acoustic_data._freq_text[f], + # fontsize=14, fontweight='bold', fontname="Ubuntu", c="black", alpha=0.5, + # horizontalalignment='right', verticalalignment='bottom', transform=self.axis_BS[f].transAxes) + + # self.fig_BS.supxlabel('Distance from left bank (m)', fontsize=10) + # self.fig_BS.supylabel('Depth (m)', fontsize=10) + # # plt.subplots_adjust(bottom=0.125, top=0.98, right=1.03, left=0.08, hspace=0.1) + # # self.fig.tight_layout() + # cbar = self.fig_BS.colorbar(pcm, ax=self.axis_BS[:], shrink=1, location='right') + # cbar.set_label(label='Backscatter acoustic signal (V)', rotation=270, labelpad=10) + self.fig_BS.canvas.draw_idle() + return r_bottom, val_bottom, r_bottom_ind, BS_section_bottom