From 57b5490f5f6b431830e7d4ca2e33a46a418488a6 Mon Sep 17 00:00:00 2001 From: brahim Date: Fri, 19 Jul 2024 17:46:44 +0200 Subject: [PATCH] The sediment calibration tab includes plot of acoustic recordings and profile of the concentration of fine sediments. The user can choose the data, frequencies and select the samples for the calibration. --- View/sample_data_tab.py | 4 +- View/sediment_calibration_tab.py | 557 +++++++++++++++++++++++++++++++ 2 files changed, 559 insertions(+), 2 deletions(-) create mode 100644 View/sediment_calibration_tab.py diff --git a/View/sample_data_tab.py b/View/sample_data_tab.py index bf6369f..2b6ffff 100644 --- a/View/sample_data_tab.py +++ b/View/sample_data_tab.py @@ -710,7 +710,7 @@ class SampleDataTab(QWidget): self.item_checkbox_fine.setCheckState(Qt.Unchecked) self.tableWidget_fine.setItem(i, 1, self.item_checkbox_fine) self.item_checkbox_fine.setText("F" + str(i + 1)) - stg.sample_fine.append("F" + str(i + 1)) + stg.sample_fine.append(("F" + str(i + 1), i)) # print(f"S{i+1} ", self.tableWidget_sample.item(i, 1).checkState()) # --- Fill table with data --- @@ -927,7 +927,7 @@ class SampleDataTab(QWidget): self.item_checkbox_sand.setCheckState(Qt.Unchecked) self.tableWidget_sand.setItem(i, 1, self.item_checkbox_sand) self.item_checkbox_sand.setText("S" + str(i + 1)) - stg.sample_sand.append("S" + str(i + 1)) + stg.sample_sand.append(("S" + str(i + 1), i)) # print(f"S{i+1} ", self.tableWidget_sample.item(i, 1).checkState()) # --- Fill table with data --- diff --git a/View/sediment_calibration_tab.py b/View/sediment_calibration_tab.py new file mode 100644 index 0000000..cdbdd1d --- /dev/null +++ b/View/sediment_calibration_tab.py @@ -0,0 +1,557 @@ +import sys + +import matplotlib.pyplot as plt +from PyQt5.QtWidgets import (QWidget, QMainWindow, QApplication, QVBoxLayout, QHBoxLayout, QGroupBox, QComboBox, + QGridLayout, QLabel, QPushButton, QSpinBox, QDoubleSpinBox, QAbstractSpinBox, QSpacerItem, + QSizePolicy, QSlider, QLineEdit, QDial) + +from PyQt5.QtCore import QCoreApplication, Qt +from PyQt5.QtGui import QStandardItemModel, QIcon, QPixmap + +import settings as stg + +import numpy as np + +from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas +from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolBar +from matplotlib.colors import LogNorm + +from View.checkable_combobox import CheckableComboBox + +from Model.acoustic_inversion_method_high_concentration import AcousticInversionMethodHighConcentration + + +class SedimentCalibrationTab(QWidget): + + ''' This class generates the Sediment Calibration Tab ''' + + def __init__(self, widget_tab): + super().__init__() + + self.path_icon = "./icons/" + self.icon_update = self.path_icon + "update.png" + + self.inv_hc = AcousticInversionMethodHighConcentration() + + ### --- General layout of widgets --- + + self.verticalLayoutMain = QVBoxLayout(widget_tab) + + self.horizontalLayoutTop = QHBoxLayout() + self.verticalLayoutMain.addLayout(self.horizontalLayoutTop, 5) # 1O units is 100% , 1 units is 10% + + self.horizontalLayoutBottom = QHBoxLayout() + self.verticalLayoutMain.addLayout(self.horizontalLayoutBottom, 5) + + # -------------------------------------------------------------------------------------------------------------- + + self.groupbox_acoustic_data = QGroupBox() + self.horizontalLayoutTop.addWidget(self.groupbox_acoustic_data, 6) + + self.groupbox_Mfine_profile = QGroupBox() + self.horizontalLayoutTop.addWidget(self.groupbox_Mfine_profile, 4) + + # ++++++++++++++++++++++++++++++ + # +++ Groupbox acoustic data +++ + + self.verticalLayout_groupbox_acoustic_data = QVBoxLayout(self.groupbox_acoustic_data) + + # self.horizontalLayout_acoustic_data_choice = QHBoxLayout() + # self.verticalLayout_groupbox_acoustic_data.addLayout(self.horizontalLayout_acoustic_data_choice) + + self.gridLayout_data_choice = QGridLayout() + self.verticalLayout_groupbox_acoustic_data.addLayout(self.gridLayout_data_choice) + + self.pushbutton_update_acoustic_file = QPushButton() + self.pushbutton_update_acoustic_file.setIcon(QIcon(self.icon_update)) + # self.horizontalLayout_acoustic_data_choice.addWidget(self.pushbutton_update_acoustic_file) + self.gridLayout_data_choice.addWidget(self.pushbutton_update_acoustic_file, 0, 0, 2, 1) + + self.combobox_acoustic_data_choice = QComboBox() + # self.horizontalLayout_acoustic_data_choice.addWidget(self.combobox_acoustic_data_choice) + self.gridLayout_data_choice.addWidget(self.combobox_acoustic_data_choice, 0, 1, 1, 1) + + self.combobox_freq1 = QComboBox() + # self.horizontalLayout_acoustic_data_choice.addWidget(self.combobox_freq1) + self.gridLayout_data_choice.addWidget(self.combobox_freq1, 0, 2, 1, 1) + + self.combobox_freq2 = QComboBox() + # self.horizontalLayout_acoustic_data_choice.addWidget(self.combobox_freq2) + self.gridLayout_data_choice.addWidget(self.combobox_freq2, 0, 3, 1, 1) + + # self.horizontalLayout_sample_data_choice = QHBoxLayout() + # self.verticalLayout_groupbox_acoustic_data.addLayout(self.horizontalLayout_sample_data_choice) + + # self.label_fine_sample_choice = QLabel() + # self.label_fine_sample_choice.setText("Fine sediments :") + # self.horizontalLayout_sample_data_choice.addWidget(self.label_fine_sample_choice) + + self.combobox_fine_sample_choice = CheckableComboBox() + # self.horizontalLayout_sample_data_choice.addWidget(self.combobox_fine_sample_choice) + self.gridLayout_data_choice.addWidget(self.combobox_fine_sample_choice, 1, 1, 1, 1) + + # self.label_sand_sample_choice = QLabel() + # self.label_sand_sample_choice.setText("Sand sediments :") + # self.horizontalLayout_sample_data_choice.addWidget(self.label_sand_sample_choice) + + self.combobox_sand_sample_choice = CheckableComboBox() + # self.horizontalLayout_sample_data_choice.addWidget(self.combobox_sand_sample_choice) + self.gridLayout_data_choice.addWidget(self.combobox_sand_sample_choice, 1, 2, 1, 1) + + self.pushbutton_plot_sample = QPushButton() + self.pushbutton_plot_sample.setText("Plot sample") + # self.horizontalLayout_sample_data_choice.addWidget(self.pushbutton_plot_sample) + self.gridLayout_data_choice.addWidget(self.pushbutton_plot_sample, 1, 3, 1, 1) + + self.canvas_BS = FigureCanvas() + self.verticalLayout_groupbox_acoustic_data.addWidget(self.canvas_BS) + + # -------------------------------------------------------------------------------------------------------------- + + # +++++++++++++++++++++++++++++++++++++++++++ + # +++ Groupbox Fine concentration profile +++ + + self.verticalLayout_groupbox_Mfine_profile = QVBoxLayout(self.groupbox_Mfine_profile) + + self.canvas_Mfine = FigureCanvas() + self.toolbar_Mfine = NavigationToolBar(self.canvas_Mfine, self) + + self.verticalLayout_groupbox_Mfine_profile.addWidget(self.toolbar_Mfine) + self.verticalLayout_groupbox_Mfine_profile.addWidget(self.canvas_Mfine) + + # -------------------------------------------------------------------------------------------------------------- + + self.groupbox_FCB = QGroupBox() + self.horizontalLayoutBottom.addWidget(self.groupbox_FCB, 6) + + self.groupbox_sediment_calibration = QGroupBox() + self.horizontalLayoutBottom.addWidget(self.groupbox_sediment_calibration, 4) + + # ++++++++++++++++++++ + # +++ Groupbox FCB +++ + + self.verticalLayout_groupbox_FCB = QVBoxLayout(self.groupbox_FCB) + + self.canvas_FCB = FigureCanvas() + self.toolbar_FCB = NavigationToolBar(self.canvas_FCB, self) + + self.verticalLayout_groupbox_FCB.addWidget(self.toolbar_FCB) + self.verticalLayout_groupbox_FCB.addWidget(self.canvas_FCB) + + # +++++++++++++++++++++++++++++++++++++ + # +++ Groupbox sediment calibration +++ + + self.groupbox_sediment_calibration.setTitle("Sediment calibration") + + self.gridLayout_groupbox_sediment_calibration = QGridLayout(self.groupbox_sediment_calibration) + + self.label_freq1 = QLabel("freq1") + self.gridLayout_groupbox_sediment_calibration.addWidget(self.label_freq1, 0, 1, 1, 1) + + self.label_freq2 = QLabel("freq2") + self.gridLayout_groupbox_sediment_calibration.addWidget(self.label_freq2, 0, 2, 1, 1) + + self.label_ks = QLabel() + self.label_ks.setText("ks") + self.gridLayout_groupbox_sediment_calibration.addWidget(self.label_ks, 1, 0, 1, 1) + + self.label_sv = QLabel() + self.label_sv.setText("sv") + self.gridLayout_groupbox_sediment_calibration.addWidget(self.label_sv, 2, 0, 1, 1) + + self.label_X = QLabel() + self.label_X.setText("X") + self.gridLayout_groupbox_sediment_calibration.addWidget(self.label_X, 3, 0, 1, 1) + + self.label_alphas = QLabel() + self.label_alphas.setText("\u03B1s") + self.gridLayout_groupbox_sediment_calibration.addWidget(self.label_alphas, 4, 0, 1, 1) + + self.label_zeta = QLabel() + self.label_zeta.setText("\u03B6") + self.gridLayout_groupbox_sediment_calibration.addWidget(self.label_zeta, 5, 0, 1, 1) + + # ============================================================================================================== + # ---------------------------------------- Connect signal of widget -------------------------------------------- + # ============================================================================================================== + + self.pushbutton_update_acoustic_file.clicked.connect(self.function_pushbutton_update_acoustic_file) + + self.pushbutton_plot_sample.clicked.connect(self.function_pushbutton_plot_sample) + + # ============================================================================================================== + # ----------------------------------- Functions for Signal processing Tab -------------------------------------- + # ============================================================================================================== + + def function_pushbutton_update_acoustic_file(self): + self.update_acoustic_data() + + def function_pushbutton_plot_sample(self): + self.sample_choice_for_calibration() + self.plot_acoustic_recording() + self.plot_profile_of_concentration_fine() + + def update_acoustic_data(self): + + self.combobox_acoustic_data_choice.clear() + self.combobox_acoustic_data_choice.addItems(stg.filename_BS_raw_data) + self.combobox_acoustic_data_choice.currentIndexChanged.connect(self.plot_acoustic_recording) + + self.combobox_freq1.clear() + self.combobox_freq1.addItems(stg.freq_text[self.combobox_acoustic_data_choice.currentIndex()]) + + self.combobox_freq2.clear() + self.combobox_freq2.addItems(stg.freq_text[self.combobox_acoustic_data_choice.currentIndex()]) + self.combobox_freq2.currentIndexChanged.connect(self.plot_acoustic_recording) + + self.combobox_fine_sample_choice.clear() + self.combobox_fine_sample_choice.addItems([f[0] for f in stg.sample_fine]) + + self.combobox_sand_sample_choice.clear() + self.combobox_sand_sample_choice.addItems([s[0] for s in stg.sample_sand]) + + self.plot_acoustic_recording() + + def plot_acoustic_recording(self): + + self.verticalLayout_groupbox_acoustic_data.removeWidget(self.canvas_BS) + self.fig_BS, self.axis_BS = plt.subplots(nrows=1, ncols=1, sharex=True, sharey=False, layout='constrained') + self.canvas_BS = FigureCanvas(self.fig_BS) + self.verticalLayout_groupbox_acoustic_data.addWidget(self.canvas_BS) + + if stg.BS_stream_bed[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,): + + val_min = np.nanmin( + stg.BS_stream_bed[self.combobox_acoustic_data_choice.currentIndex()][self.combobox_freq2.currentIndex(), + :, :]) + val_max = np.nanmax( + stg.BS_stream_bed[self.combobox_acoustic_data_choice.currentIndex()][self.combobox_freq2.currentIndex(), + :, :]) + if val_min == 0: + val_min = 1e-5 + + self.axis_BS.pcolormesh( + stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()][ + self.combobox_freq2.currentIndex(), :], + -stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()][ + self.combobox_freq2.currentIndex(), :], + stg.BS_stream_bed[self.combobox_acoustic_data_choice.currentIndex()][self.combobox_freq2.currentIndex(), + :, :], + cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max)) + + elif stg.BS_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,): + + val_min = np.nanmin( + stg.BS_cross_section[self.combobox_acoustic_data_choice.currentIndex()][ + self.combobox_freq2.currentIndex(), :, :]) + val_max = np.nanmax( + stg.BS_cross_section[self.combobox_acoustic_data_choice.currentIndex()][ + self.combobox_freq2.currentIndex(), :, :]) + if val_min == 0: + val_min = 1e-5 + + self.axis_BS.pcolormesh( + stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()][ + self.combobox_freq2.currentIndex(), :], + -stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()][ + self.combobox_freq2.currentIndex(), :], + stg.BS_cross_section[self.combobox_acoustic_data_choice.currentIndex()][ + self.combobox_freq2.currentIndex(), :, :], + cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max)) + + elif stg.BS_raw_data[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,): + + val_min = np.nanmin( + stg.BS_raw_data[self.combobox_acoustic_data_choice.currentIndex()][self.combobox_freq2.currentIndex(), :, + :]) + val_max = np.nanmax( + stg.BS_raw_data[self.combobox_acoustic_data_choice.currentIndex()][self.combobox_freq2.currentIndex(), :, + :]) + if val_min == 0: + val_min = 1e-5 + + self.axis_BS.pcolormesh( + stg.time[self.combobox_acoustic_data_choice.currentIndex()][self.combobox_freq2.currentIndex(), :], + -stg.depth[self.combobox_acoustic_data_choice.currentIndex()][self.combobox_freq2.currentIndex(), :], + stg.BS_raw_data[self.combobox_acoustic_data_choice.currentIndex()][self.combobox_freq2.currentIndex(), :, + :], + cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max)) + + print("stg.fine_sample_profile ", stg.fine_sample_profile) + print("stg.sand_sample_target ", stg.sand_sample_target) + + if (stg.fine_sample_profile) or (stg.sand_sample_target): + + self.axis_BS.scatter([stg.time_fine[f[1]] for f in stg.fine_sample_profile], + [stg.depth_fine[f[1]] for f in stg.fine_sample_profile], + marker='o', s=20, facecolor="k", edgecolor="None") + self.axis_BS.scatter([stg.time_sand[s[1]] for s in stg.sand_sample_target], + [stg.depth_sand[s[1]] for s in stg.sand_sample_target], + marker='o', s=50, facecolor="None", edgecolor="k") + + for i in stg.fine_sample_profile: + self.axis_BS.text(stg.time_fine[i[1]] + 5, stg.depth_fine[i[1]] - .2, i[0], + fontstyle="normal", fontweight="light", fontsize=8) + + for j in stg.sand_sample_target: + self.axis_BS.text(stg.time_sand[j[1]] - 12, stg.depth_sand[j[1]] - .2, j[0], + fontstyle="normal", fontweight="light", fontsize=8) + + elif (stg.sample_fine) or (stg.sample_sand): + + self.axis_BS.scatter(stg.time_fine, stg.depth_fine, marker='o', s=20, facecolor="k", edgecolor="None") + self.axis_BS.scatter(stg.time_sand, stg.depth_sand, marker='o', s=50, facecolor="None", edgecolor="k") + + for i in stg.sample_fine: + self.axis_BS.text(stg.time_fine[i[1]] + 5, stg.depth_fine[i[1]] - .2, i[0], + fontstyle="normal", fontweight="light", fontsize=8) + + for j in stg.sample_sand: + self.axis_BS.text(stg.time_sand[j[1]] - 12, stg.depth_sand[j[1]] - .2, j[0], + fontstyle="normal", fontweight="light", fontsize=8) + + # self.axis_BS.set_xticks([]) + # self.axis_BS.set_yticks([]) + self.axis_BS.set_xlabel("Time (sec)") + self.axis_BS.set_ylabel("Depth (m)") + self.fig_BS.canvas.draw_idle() + + def sample_choice_for_calibration(self): + # --- List selected fine samples --- + stg.fine_sample_profile = [(f, int(f[1:]) - 1) for f in self.combobox_fine_sample_choice.currentData()] + print(f"stg.fine_sample_profile : {stg.fine_sample_profile}") + + # --- List selected sand samples --- + stg.sand_sample_target = [(s, int(s[1:]) - 1) for s in self.combobox_sand_sample_choice.currentData()] + print(f"stg.sand_sample_target : {stg.sand_sample_target}") + + def plot_profile_of_concentration_fine(self): + + if stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,): + + print("test find indice of time ", np.where( np.abs(stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()][self.combobox_freq2.currentIndex(), :] + - (stg.time_fine[stg.fine_sample_profile[-1][1]])) == + np.nanmin(np.abs(stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()][self.combobox_freq2.currentIndex(), :] + - (stg.time_fine[stg.fine_sample_profile[-1][1]]))) )) + print(stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()][self.combobox_freq2.currentIndex(), :]) + print(stg.time_fine[stg.fine_sample_profile[-1][1]]) + + range_lin_interp, M_profile_fine = ( + self.inv_hc.M_profile_SCC_fine_interpolated( + sample_depth=[-stg.depth_fine[k[1]] for k in stg.fine_sample_profile], + M_profile=[stg.Ctot_fine[k[1]] for k in stg.fine_sample_profile], + range_cells=stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()][self.combobox_freq2.currentIndex(), :], + r_bottom=stg.depth_bottom[self.combobox_acoustic_data_choice.currentIndex()] + [ + np.where( np.abs(stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()][self.combobox_freq2.currentIndex(), :] + - stg.time_fine[stg.fine_sample_profile[-1][1]]) == + np.nanmin(np.abs(stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()][self.combobox_freq2.currentIndex(), :] + - stg.time_fine[stg.fine_sample_profile[-1][1]])) )[0][0] + ] + ) + ) + # print(f"range_lin_interp : {range_lin_interp}") + # print(f"M_profile_fine : {M_profile_fine}") + else: + range_lin_interp, M_profile_fine = ( + self.inv_hc.M_profile_SCC_fine_interpolated( + sample_depth=[-stg.depth_fine[k[1]] for k in stg.fine_sample_profile], + M_profile=[stg.Ctot_fine[k[1]] for k in stg.fine_sample_profile], + range_cells=stg.depth[self.combobox_acoustic_data_choice.currentIndex()][self.combobox_freq2.currentIndex(), :], + r_bottom=stg.depth_bottom[self.combobox_acoustic_data_choice.currentIndex()])) + + M_profile_fine = M_profile_fine[:len(range_lin_interp)] + print(f"M_profile_fine : {M_profile_fine}") + + # --- Plot profile of the concentration of the fine sediments --- + self.verticalLayout_groupbox_Mfine_profile.removeWidget(self.canvas_Mfine) + self.verticalLayout_groupbox_Mfine_profile.removeWidget(self.toolbar_Mfine) + self.fig_Mfine, self.ax_Mfine = plt.subplots(1, 1, layout="constrained") + self.canvas_Mfine = FigureCanvas(self.fig_Mfine) + self.toolbar_Mfine = NavigationToolBar(self.canvas_Mfine, self) + self.verticalLayout_groupbox_Mfine_profile.addWidget(self.toolbar_Mfine) + self.verticalLayout_groupbox_Mfine_profile.addWidget(self.canvas_Mfine) + + self.ax_Mfine.plot([stg.Ctot_fine[c] for _, c in stg.fine_sample_profile], + [stg.depth_fine[c] for _, c in stg.fine_sample_profile], + marker="o", mfc="k", mec="k", ms=12, ls="None") + + self.ax_Mfine.plot(M_profile_fine[:len(range_lin_interp)], -range_lin_interp, + marker="*", mfc="b", mec="b", ms=8, ls="None") + + self.ax_Mfine.set_xlabel("Concentration fine sediments (g/L)") + self.ax_Mfine.set_ylabel("Depth (m)") + + for i in stg.fine_sample_profile: + self.ax_Mfine.text(stg.time_fine[i[1]], stg.depth_fine[i[1]] - .05, i[0], + fontstyle="normal", fontweight="light", fontsize=12) + + self.ax_Mfine.set_xlabel("Fine sediments concentration (g/L)") + self.ax_Mfine.set_ylabel("Depth (m)") + + def range_cells_function(self): + """ Computing the real cell size, that depends on the temperature """ + + # defaut Aquascat cell size + aquascat_cell_size = stg.r[0, 1] - stg.r[0, 0] + # Pulse duration + tau = aquascat_cell_size * 2 / 1500 # figure 2.9 1500 vitesse du son entrée pour le paramètrage des mesures aquascat + # Sound speed + cel = self.inv_hc.water_velocity(self.spinbox_temperature_water_attenuation.value()) + # Real cell size + real_cell_size = cel * tau / 2 # voir fig 2.9 + + # Converting to real cell profile + real_r = stg.r / aquascat_cell_size * real_cell_size # (/ aquascat_cell_size) pour ramener BS.r entre 0 et 1 + # (* real_cell_size) pour remettre les échelles spatiales sur la taille réelle des cellules + + # R with right shape (numpy array) + R_real = real_r # np.repeat(real_r, len(stg.freq), axis=1) + + return R_real + + + def compute_FCB(self): + + print(f"self.range_cells_function() : {self.range_cells_function()}") + print(f"self.range_cells_function() shape : {self.range_cells_function().shape}") + R_real = np.repeat(self.range_cells_function()[:, :, np.newaxis], stg.t.shape[1], axis=2) + print(f"R_real shape : {R_real.shape}") + if (stg.BS_stream_bed_pre_process_average.size == 0) and (stg.BS_stream_bed_pre_process_SNR.size == 0): + stg.FCB = (np.log(stg.BS_stream_bed) + np.log(R_real) + + 2 * stg.water_attenuation * R_real) + elif stg.BS_stream_bed_pre_process_SNR.size == 0: + stg.FCB = (np.log(stg.BS_stream_bed_pre_process_average) + np.log(R_real) + + 2 * stg.water_attenuation * R_real) + else: + stg.FCB = (np.log(stg.BS_stream_bed_pre_process_SNR) + np.log(R_real) + + 2 * stg.water_attenuation * R_real) + self.plot_FCB() + + # def fit_FCB_profile_with_linear_regression_and_compute_alphaS(self): + # + # if stg.FCB.size == 0: + # msgBox = QMessageBox() + # msgBox.setWindowTitle("Linear regression error") + # msgBox.setIcon(QMessageBox.Warning) + # msgBox.setText("Please compute FCB before") + # msgBox.setStandardButtons(QMessageBox.Ok) + # msgBox.exec() + # else: + # try: + # y0 = stg.FCB[self.combobox_frequency_compute_alphaS.currentIndex(), :, self.slider.value()] + # y = y0[np.where(np.isnan(y0) == False)] + # + # x0 = stg.r[0, :].reshape(-1) + # x = x0[np.where(np.isnan(y0) == False)] + # + # value1 = np.where(np.round(np.abs(x - self.spinbox_alphaS_computation_from.value()), 2) + # == np.min(np.round(np.abs(x - self.spinbox_alphaS_computation_from.value()), 2))) + # value2 = np.where(np.round(np.abs(x - self.spinbox_alphaS_computation_to.value()), 2) + # == np.min(np.round(np.abs(x - self.spinbox_alphaS_computation_to.value()), 2))) + # + # # print(np.round(np.abs(x - self.spinbox_alphaS_computation_from.value()), 2)) + # # # print("value1 ", value1[0][0]) + # # print(np.round(np.abs(x - self.spinbox_alphaS_computation_to.value()), 2)) + # # print("value2 ", value2[0][0]) + # + # # print("y limited ", y[value1[0][0]:value2[0][0]]) + # + # lin_reg_compute = stats.linregress(x[value1[0][0]:value2[0][0]], y[value1[0][0]:value2[0][0]]) + # except ValueError: + # msgBox = QMessageBox() + # msgBox.setWindowTitle("Linear regression error") + # msgBox.setIcon(QMessageBox.Warning) + # msgBox.setText("Please check boundaries to fit a linear line") + # msgBox.setStandardButtons(QMessageBox.Ok) + # msgBox.exec() + # else: + # stg.lin_reg = (lin_reg_compute.slope, lin_reg_compute.intercept) + # # print(f"y = {stg.lin_reg[0]}x + {stg.lin_reg[1]}") + # + # self.label_alphaS.clear() + # self.label_alphaS.setText(f"\u03B1s = {-0.5*stg.lin_reg[0]:.4f} dB/m") + # + # # for i, value_freq in enumerate(stg.freq): + # # for k, value_t in enumerate(stg.t): + # # # print(f"indice i: {i}, indice k: {k}") + # # # print(f"values of FCB: {stg.FCB[:, i, k]}") + # # y = stg.FCB[:, i, k] + # # # print("y : ", y) + # # # print(f"values of FCB where FCB is not Nan {y[np.where(np.isnan(y) == False)]}") + # # # print(f"values of r where FCB is not Nan {x[np.where(np.isnan(y) == False)]}") + # # lin_reg_compute = stats.linregress(x[np.where(np.isnan(y) == False)], y[np.where(np.isnan(y) == False)]) + # # lin_reg_tuple = (lin_reg_compute.slope, lin_reg_compute.intercept) + # # stg.lin_reg.append(lin_reg_tuple) + # + # # print(f"y = {lin_reg.slope}x + {lin_reg.intercept}") + # + # # plt.figure() + # # plt.plot(stg.r, stg.FCB[:, 0, 825], 'k-', stg.r, lin_reg.slope*stg.r + lin_reg.intercept, "b--") + # # plt.show() + # + # # print("lin_reg length ", len(stg.lin_reg)) + # # print("lin_reg ", stg.lin_reg) + + + + # print([stg.time_fine[c] for _, c in stg.fine_sample_profile]) + # print([stg.depth_fine[c] for _, c in stg.fine_sample_profile]) + + # --- Plot positions of the samples selected in comboboxes --- + # self.scat.set_array(np.array([[stg.time_fine[c] for _, c in stg.fine_sample_profile], + # [stg.depth_fine[c] for _, c in stg.fine_sample_profile]]).transpose()) + # self.scat.set_array(np.array([[stg.time_fine[c] for _, c in stg.fine_sample_profile], + # [stg.depth_fine[c] for _, c in stg.fine_sample_profile]]).transpose()) + + # self.gridLayout_groupbox_data_choice = QGridLayout(self.groupbox_acoustic_data_choice) + # + # self.gridLayout_groupbox_data_choice.addWidget(self.combobox_acoustic_data_choice, 0, 0, 1, 4) + # self.combobox_acoustic_data_choice.addItems(["acoustic data 1", "acoustic data 2", "acoustic data 3"]) + # + # self.label_temperature = QLabel("Temperature = ") + # self.gridLayout_groupbox_data_choice.addWidget(self.label_temperature, 1, 0, 1, 1) + # + # self.label_temperature_value = QLabel("7 °C") + # self.gridLayout_groupbox_data_choice.addWidget(self.label_temperature_value, 1, 1, 1, 1) + # + # self.label_sound_velocity = QLabel("Sound velocity (m/s) = ") + # self.gridLayout_groupbox_data_choice.addWidget(self.label_sound_velocity, 1, 2, 1, 1) + # + # self.spinbox_sound_velocity_value = QSpinBox() + # self.gridLayout_groupbox_data_choice.addWidget(self.spinbox_sound_velocity_value, 1, 3, 1, 1) + # + # self.label_freq1 = QLabel("freq 1:") + # self.gridLayout_groupbox_data_choice.addWidget(self.label_freq1, 2, 0, 1, 1) + # self.combobox_freq1 = QComboBox() + # self.combobox_freq1.addItems(["0.3 MHz", "0.5 MHz", "1 MHz", "5 MHz"]) + # self.gridLayout_groupbox_data_choice.addWidget(self.combobox_freq1, 2, 1, 1, 1) + # + # self.label_freq2 = QLabel("freq 2:") + # self.gridLayout_groupbox_data_choice.addWidget(self.label_freq2, 2, 2, 1, 1) + # self.combobox_freq2 = QComboBox() + # self.combobox_freq2.addItems(["0.3 MHz", "0.5 MHz", "1 MHz", "5 MHz"]) + # self.gridLayout_groupbox_data_choice.addWidget(self.combobox_freq2, 2, 3, 1, 1) + # + # self.label_kt = QLabel("kt = :") + # self.gridLayout_groupbox_data_choice.addWidget(self.label_kt, 3, 0, 1, 1) + # + # self.spinbox_kt_freq1 = QDoubleSpinBox() + # self.spinbox_kt_freq1.setDecimals(5) + # self.gridLayout_groupbox_data_choice.addWidget(self.spinbox_kt_freq1, 3, 1, 1, 1) + # + # self.spinbox_kt_freq2 = QDoubleSpinBox() + # self.spinbox_kt_freq2.setDecimals(5) + # self.gridLayout_groupbox_data_choice.addWidget(self.spinbox_kt_freq2, 3, 3, 1, 1) + # + # self.groupbox_acoustic_data_plot = QGroupBox() + # self.verticalLayout_groupbox_acoustic_data_plot = QVBoxLayout(self.groupbox_acoustic_data_plot) + # self.gridLayout_groupbox_data_choice.addWidget(self.groupbox_acoustic_data_plot, 4, 0, 1, 4) + # + # self.fig_acoustic, self.ax_acoustic = plt.subplots(nrows=1, ncols=1, layout="constrained") + # self.canvas_fig_acoustic = FigureCanvas(self.fig_acoustic) + # self.verticalLayout_groupbox_acoustic_data_plot.addWidget(self.canvas_fig_acoustic) + + + +