acoused/View/sediment_calibration_tab.py

2116 lines
118 KiB
Python

import sys
import matplotlib.pyplot as plt
import pandas as pd
from PyQt5.QtWidgets import (QWidget, QMainWindow, QApplication, QVBoxLayout, QHBoxLayout, QGroupBox, QComboBox,
QGridLayout, QLabel, QPushButton, QSpinBox, QDoubleSpinBox, QAbstractSpinBox, QSpacerItem,
QSizePolicy, QSlider, QLineEdit, QDial, QFileDialog)
from PyQt5.QtCore import QCoreApplication, Qt, QPropertyAnimation, QSize
from PyQt5.QtGui import QStandardItemModel, QIcon, QPixmap, QFont
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 scipy.stats import linregress
from os import path
from View.checkable_combobox import CheckableComboBox
from Model.acoustic_inversion_method_high_concentration import AcousticInversionMethodHighConcentration
from settings import depth_cross_section, BS_raw_data_pre_process_average, BS_raw_data_pre_process_SNR, BS_raw_data
class SedimentCalibrationTab(QWidget):
''' This class generates the Sediment Calibration Tab '''
def __init__(self, widget_tab):
super().__init__()
self.path_icon = "./icons/"
self.icon_folder = QIcon(self.path_icon + "folder.png")
self.icon_triangle_left = QIcon(self.path_icon + "triangle_left.png")
self.icon_triangle_left_to_begin = QIcon(self.path_icon + "triangle_left_to_begin.png")
self.icon_triangle_right = QIcon(self.path_icon + "triangle_right.png")
self.icon_triangle_right_to_end = QIcon(self.path_icon + "triangle_right_to_end.png")
self.icon_update = QIcon(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.groupbox_acoustic_data.setTitle("Step 1 : acoustic and sample data choice")
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(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.groupbox_Mfine_profile.setTitle("Step 2 : profile of the fine sediment concentration")
self.verticalLayout_groupbox_Mfine_profile = QVBoxLayout(self.groupbox_Mfine_profile)
self.pushbutton_interpolate_Mfine_profile = QPushButton()
self.pushbutton_interpolate_Mfine_profile.setText("Interpolate")
self.verticalLayout_groupbox_Mfine_profile.addWidget(self.pushbutton_interpolate_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_sediment_calibration = QGroupBox()
self.horizontalLayoutBottom.addWidget(self.groupbox_sediment_calibration, 4)
self.groupbox_FCB = QGroupBox()
self.horizontalLayoutBottom.addWidget(self.groupbox_FCB, 6)
# +++++++++++++++++++++++++++++++++++++
# +++ Groupbox sediment calibration +++
self.groupbox_sediment_calibration.setTitle("Step 3 : Compute Calibration")
self.verticalLayout_groupbox_sediment_calibration = QVBoxLayout(self.groupbox_sediment_calibration)
# --- Groupbox import calibration file ---
self.groupbox_sediment_calibration_import = QGroupBox()
self.groupbox_sediment_calibration_import.setTitle("Import sediment calibration file")
self.groupbox_sediment_calibration_import.setCheckable(True)
self.groupbox_sediment_calibration_import.setChecked(True)
self.verticalLayout_groupbox_sediment_calibration.addWidget(self.groupbox_sediment_calibration_import)
self.gridLayout_groupbox_sediment_calibration_import = QGridLayout(self.groupbox_sediment_calibration_import)
self.pushbutton_import_calibration = QPushButton()
self.pushbutton_import_calibration.setText('Import calibration')
self.gridLayout_groupbox_sediment_calibration_import.addWidget(self.pushbutton_import_calibration, 0, 0, 1, 1)
self.lineEdit_import_calibration = QLineEdit()
self.gridLayout_groupbox_sediment_calibration_import.addWidget(self.lineEdit_import_calibration, 0, 1, 1, 2)
# --- Compute calibration ---
self.groupbox_sediment_calibration_compute = QGroupBox()
self.groupbox_sediment_calibration_compute.setTitle("Compute sediment calibration")
self.groupbox_sediment_calibration_compute.setCheckable(True)
self.groupbox_sediment_calibration_compute.setChecked(False)
self.verticalLayout_groupbox_sediment_calibration.addWidget(self.groupbox_sediment_calibration_compute)
self.gridLayout_groupbox_sediment_calibration_compute = QGridLayout(self.groupbox_sediment_calibration_compute)
self.pushbutton_compute_calibration = QPushButton()
self.pushbutton_compute_calibration.setText("Compute Calibration")
self.gridLayout_groupbox_sediment_calibration_compute.addWidget(self.pushbutton_compute_calibration, 0, 0, 1, 3)
# --- Calibration parameter ---
self.groupbox_sediment_calibration_parameter = QGroupBox()
self.gridLayout_groupbox_sediment_calibration_parameter = QGridLayout(self.groupbox_sediment_calibration_parameter)
self.verticalLayout_groupbox_sediment_calibration.addWidget(self.groupbox_sediment_calibration_parameter)
self.label_freq1 = QLabel("Frequency 1")
self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.label_freq1, 1, 1, 1, 1)
self.label_freq2 = QLabel("Frequency 2")
self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.label_freq2, 1, 2, 1, 1)
self.label_ks = QLabel()
self.label_ks.setText("ks")
self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.label_ks, 2, 0, 1, 1)
self.spinbox_ks_freq1 = QDoubleSpinBox()
self.spinbox_ks_freq1.setDecimals(8)
self.spinbox_ks_freq1.setSuffix(" m/kg^0.5")
self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.spinbox_ks_freq1, 2, 1, 1, 1)
self.spinbox_ks_freq2 = QDoubleSpinBox()
self.spinbox_ks_freq2.setDecimals(8)
self.spinbox_ks_freq2.setSuffix(" m/kg^0.5")
self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.spinbox_ks_freq2, 2, 2, 1, 1)
self.label_sv = QLabel()
self.label_sv.setText("sv")
self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.label_sv, 3, 0, 1, 1)
self.spinbox_sv_freq1 = QDoubleSpinBox()
self.spinbox_sv_freq1.setDecimals(8)
self.spinbox_sv_freq1.setSuffix(" /m")
self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.spinbox_sv_freq1, 3, 1, 1, 1)
self.spinbox_sv_freq2 = QDoubleSpinBox()
self.spinbox_sv_freq2.setDecimals(8)
self.spinbox_sv_freq2.setSuffix(" /m")
self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.spinbox_sv_freq2, 3, 2, 1, 1)
self.label_X = QLabel()
self.label_X.setText("X")
self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.label_X, 4, 0, 1, 1)
self.spinbox_X = QDoubleSpinBox()
self.spinbox_X.setDecimals(2)
self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.spinbox_X, 4, 1, 1, 2)
self.label_alphas = QLabel()
self.label_alphas.setText("\u03B1s")
self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.label_alphas, 5, 0, 1, 1)
self.spinbox_alphas_freq1 = QDoubleSpinBox()
self.spinbox_alphas_freq1.setDecimals(4)
self.spinbox_alphas_freq1.setSuffix(" /m")
self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.spinbox_alphas_freq1, 5, 1, 1, 1)
self.spinbox_alphas_freq2 = QDoubleSpinBox()
self.spinbox_alphas_freq2.setDecimals(4)
self.spinbox_alphas_freq2.setSuffix(" /m")
self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.spinbox_alphas_freq2, 5, 2, 1, 1)
self.label_zeta = QLabel()
self.label_zeta.setText("\u03B6")
self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.label_zeta, 6, 0, 1, 1)
self.spinbox_zeta_freq1 = QDoubleSpinBox()
self.spinbox_zeta_freq1.setDecimals(4)
self.spinbox_zeta_freq1.setSuffix(" /m")
self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.spinbox_zeta_freq1, 6, 1, 1, 1)
self.spinbox_zeta_freq2 = QDoubleSpinBox()
self.spinbox_zeta_freq2.setDecimals(4)
self.spinbox_zeta_freq2.setSuffix(" /m")
self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.spinbox_zeta_freq2, 6, 2, 1, 1)
# self.groupbox_calibration_compute_size_change()
# self.animaiton_groupbox_compute = QPropertyAnimation(self.groupbox_sediment_calibration_compute, b"size")
# self.animaiton_groupbox_compute.setStartValue(QSize(self.groupbox_sediment_calibration_compute.width(), 25))
#
# self.animaiton_groupbox_compute.start()
# setStartValue(QSize(self.groupbox_sediment_calibration_compute.width(),
# self.groupbox_sediment_calibration_compute.height()))
#
# self.animaiton_groupbox_compute.setEndValue(
# QSize(self.groupbox_sediment_calibration_compute.width(),
# self.groupbox_sediment_calibration_compute.sizeHint().height()))
# else:
# self.animaiton_groupbox_compute.setEndValue(QSize(self.groupbox_sediment_calibration_compute.width(), 25))
# ++++++++++++++++++++
# +++ Groupbox FCB +++
self.groupbox_FCB.setTitle("Step 3 (optional) : Fluid Corrected Backscatter")
self.horizontalLayout_groupbox_FCB = QHBoxLayout(self.groupbox_FCB)
# --- Groupbox FCB option ---
self.groupbox_FCB_option = QGroupBox()
self.gridLayout_groupbox_FCB_option = QGridLayout(self.groupbox_FCB_option)
self.horizontalLayout_groupbox_FCB.addWidget(self.groupbox_FCB_option, 4)
self.label_temperature = QLabel()
self.label_temperature.setText("Temperature : ")
self.label_frequency_FCB = QLabel()
self.label_frequency_FCB.setText("Frequency ")
self.gridLayout_groupbox_FCB_option.addWidget(self.label_frequency_FCB, 0, 0, 1, 2)
self.combobox_frequency_FCB = QComboBox()
self.gridLayout_groupbox_FCB_option.addWidget(self.combobox_frequency_FCB, 0, 2, 1, 2)
self.label_from = QLabel()
self.label_from.setText("From ")
self.gridLayout_groupbox_FCB_option.addWidget(self.label_from, 1, 0, 1, 1)
self.spinbox_FCB_from = QDoubleSpinBox()
self.gridLayout_groupbox_FCB_option.addWidget(self.spinbox_FCB_from, 1, 1, 1, 1)
self.label_to = QLabel()
self.label_to.setText(" to ")
self.gridLayout_groupbox_FCB_option.addWidget(self.label_to, 1, 2, 1, 1)
self.spinbox_FCB_to = QDoubleSpinBox()
self.gridLayout_groupbox_FCB_option.addWidget(self.spinbox_FCB_to, 1, 3, 1, 1)
self.pushbutton_FCB_fit = QPushButton()
self.gridLayout_groupbox_FCB_option.addWidget(self.pushbutton_FCB_fit, 2, 1, 1, 2)
self.label_alphaS_FCB = QLabel()
self.label_alphaS_FCB.setText("\u03B1s = " + "0.0" + "dB/m")
self.label_alphaS_FCB.setFont(QFont("Ubuntu", 14, QFont.Normal))
self.gridLayout_groupbox_FCB_option.addWidget(self.label_alphaS_FCB, 3, 1, 1, 2)
# --- Groupbox FCB plot ---
self.verticalLayout_groupbox_FCB_plot_and_slider_FCB = QVBoxLayout()
self.horizontalLayout_groupbox_FCB.addLayout(self.verticalLayout_groupbox_FCB_plot_and_slider_FCB, 8)
self.groupbox_FCB_plot = QGroupBox()
self.verticalLayout_groupbox_FCB_plot = QVBoxLayout(self.groupbox_FCB_plot)
self.verticalLayout_groupbox_FCB_plot_and_slider_FCB.addWidget(self.groupbox_FCB_plot)
self.canvas_FCB = FigureCanvas()
self.toolbar_FCB = NavigationToolBar(self.canvas_FCB, self)
self.verticalLayout_groupbox_FCB_plot.addWidget(self.toolbar_FCB)
self.verticalLayout_groupbox_FCB_plot.addWidget(self.canvas_FCB)
self.horizontalLayout_slider_FCB = QHBoxLayout()
self.verticalLayout_groupbox_FCB_plot_and_slider_FCB.addLayout(self.horizontalLayout_slider_FCB)
self.pushbutton_left_to_begin_FCB = QPushButton()
self.pushbutton_left_to_begin_FCB.setIcon(self.icon_triangle_left_to_begin)
self.horizontalLayout_slider_FCB.addWidget(self.pushbutton_left_to_begin_FCB)
self.pushbutton_left_FCB = QPushButton()
self.pushbutton_left_FCB.setIcon(self.icon_triangle_left)
self.horizontalLayout_slider_FCB.addWidget(self.pushbutton_left_FCB)
self.lineEdit_slider_FCB = QLineEdit()
self.lineEdit_slider_FCB.setText("1")
self.lineEdit_slider_FCB.setFixedWidth(50)
self.horizontalLayout_slider_FCB.addWidget(self.lineEdit_slider_FCB)
self.pushbutton_right_FCB = QPushButton()
self.pushbutton_right_FCB.setIcon(self.icon_triangle_right)
self.horizontalLayout_slider_FCB.addWidget(self.pushbutton_right_FCB)
self.pushbutton_right_to_end_FCB = QPushButton()
self.pushbutton_right_to_end_FCB.setIcon(self.icon_triangle_right_to_end)
self.horizontalLayout_slider_FCB.addWidget(self.pushbutton_right_to_end_FCB)
self.slider_FCB = QSlider()
self.horizontalLayout_slider_FCB.addWidget(self.slider_FCB)
self.slider_FCB.setOrientation(Qt.Horizontal)
self.slider_FCB.setCursor(Qt.OpenHandCursor)
self.slider_FCB.setMinimum(1)
self.slider_FCB.setMaximum(10)
self.slider_FCB.setTickInterval(1)
self.slider_FCB.setValue(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)
self.pushbutton_interpolate_Mfine_profile.clicked.connect(self.interpolate_Mfine_profile)
self.groupbox_sediment_calibration_import.toggled.connect(self.groupbox_calibration_import_toggle)
self.groupbox_sediment_calibration_import.toggled.connect(self.groupbox_calibration_import_size_change)
self.pushbutton_import_calibration.clicked.connect(self.import_calibration_file)
self.groupbox_sediment_calibration_compute.toggled.connect(self.groupbox_calibration_compute_toggle)
self.groupbox_sediment_calibration_compute.toggled.connect(self.groupbox_calibration_compute_size_change)
self.pushbutton_compute_calibration.clicked.connect(self.function_pushbutton_compute_calibration)
self.pushbutton_left_to_begin_FCB.clicked.connect(self.slider_profile_number_to_begin_FCB)
self.pushbutton_left_FCB.clicked.connect(self.slider_profile_number_to_left_FCB)
self.pushbutton_right_FCB.clicked.connect(self.slider_profile_number_to_right_FCB)
self.pushbutton_right_to_end_FCB.clicked.connect(self.slider_profile_number_to_end_FCB)
self.lineEdit_slider_FCB.returnPressed.connect(self.profile_number_on_lineEdit_FCB)
self.slider_FCB.valueChanged.connect(self.update_lineEdit_by_moving_slider_FCB)
self.pushbutton_FCB_fit.clicked.connect(self.fit_FCB_profile_with_linear_regression_and_compute_alphaS)
# ==============================================================================================================
# ----------------------------------- 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()
self.compute_FCB()
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):
# --- Record frequencies for calibration ---
stg.frequencies_for_calibration[self.combobox_acoustic_data_choice.currentIndex()].clear()
(stg.frequencies_for_calibration[self.combobox_acoustic_data_choice.currentIndex()].
append((stg.freq[self.combobox_acoustic_data_choice.currentIndex()][self.combobox_freq1.currentIndex()],
self.combobox_freq1.currentIndex())))
(stg.frequencies_for_calibration[self.combobox_acoustic_data_choice.currentIndex()].
append((stg.freq[self.combobox_acoustic_data_choice.currentIndex()][self.combobox_freq2.currentIndex()],
self.combobox_freq2.currentIndex())))
stg.frequency_for_inversion[self.combobox_acoustic_data_choice.currentIndex()].clear()
stg.frequency_for_inversion[self.combobox_acoustic_data_choice.currentIndex()].append((
stg.freq[self.combobox_acoustic_data_choice.currentIndex()][self.combobox_freq2.currentIndex()],
self.combobox_freq2.currentIndex()))
# --- Plot acoustic data recording ---
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_pre_process_average[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
val_min = np.nanmin(
stg.BS_stream_bed_pre_process_average[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), :, :])
val_max = np.nanmax(
stg.BS_stream_bed_pre_process_average[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_pre_process_average[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), :, :],
cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max))
elif stg.BS_stream_bed_pre_process_SNR[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
val_min = np.nanmin(
stg.BS_stream_bed_pre_process_SNR[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), :, :])
val_max = np.nanmax(
stg.BS_stream_bed_pre_process_SNR[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_pre_process_SNR[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), :, :],
cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max))
elif stg.BS_stream_bed[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
print("totototototototoott")
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_pre_process_average[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
val_min = np.nanmin(
stg.BS_cross_section_pre_process_average[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), :, :])
val_max = np.nanmax(
stg.BS_cross_section_pre_process_average[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_pre_process_average[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_pre_process_SNR[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
val_min = np.nanmin(
stg.BS_cross_section_pre_process_SNR[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), :, :])
val_max = np.nanmax(
stg.BS_cross_section_pre_process_SNR[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_pre_process_SNR[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 BS_raw_data_pre_process_average[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
val_min = np.nanmin(stg.BS_raw_data_pre_process_average[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), :, :])
val_max = np.nanmax(stg.BS_raw_data_pre_process_average[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_pre_process_average[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), :, :],
cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max))
elif BS_raw_data_pre_process_SNR[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
val_min = np.nanmin(stg.BS_raw_data_pre_process_SNR[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), :, :])
val_max = np.nanmax(stg.BS_raw_data_pre_process_SNR[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_pre_process_SNR[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))
# --- Plot samples ---
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)
# --- Plot vertical red line for position of FCB profile ---
if stg.sand_sample_target_indice:
if depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
if stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
self.red_line_plot_return, = (
self.axis_BS.plot(
stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), stg.sand_sample_target_indice[0][1]] *
np.ones(stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape[1]),
-stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), :],
color='red', linestyle="solid", linewidth=2))
else:
self.red_line_plot_return, = (
self.axis_BS.plot(
stg.time[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), stg.sand_sample_target_indice[0][1]] *
np.ones(stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape[1]),
-stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), :],
color='red', linestyle="solid", linewidth=2))
else:
if stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
self.red_line_plot_return, = (
self.axis_BS.plot(
stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), stg.sand_sample_target_indice[0][1]] *
np.ones(stg.depth[self.combobox_acoustic_data_choice.currentIndex()].shape[1]),
-stg.depth[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), :],
color='red', linestyle="solid", linewidth=2))
else:
self.red_line_plot_return, = (
self.axis_BS.plot(
stg.time[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), stg.sand_sample_target_indice[0][1]] *
np.ones(stg.depth[self.combobox_acoustic_data_choice.currentIndex()].shape[1]),
-stg.depth[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), :],
color='red', linestyle="solid", linewidth=2))
# 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}")
# --- Find index in time (along acoustic recording) of sand sample target ---
if stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
t1 = (
np.where(np.abs(stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq1.currentIndex()] - stg.time_sand[stg.sand_sample_target[0][1]]) ==
np.nanmin(np.abs(stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq1.currentIndex()] - stg.time_sand[stg.sand_sample_target[0][1]])))[0][0]
)
t2 = (
np.where(np.abs(stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex()] - stg.time_sand[stg.sand_sample_target[0][1]]) ==
np.nanmin(np.abs(stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex()] - stg.time_sand[stg.sand_sample_target[0][1]])))[0][0]
)
else:
t1 = (
np.where(np.abs(stg.time[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq1.currentIndex()] - stg.time_sand[
stg.sand_sample_target[0][1]]) ==
np.nanmin(np.abs(stg.time[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq1.currentIndex()] - stg.time_sand[
stg.sand_sample_target[0][1]])))[0][0]
)
t2 = (
np.where(np.abs(stg.time[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex()] - stg.time_sand[
stg.sand_sample_target[0][1]]) ==
np.nanmin(np.abs(stg.time[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex()] - stg.time_sand[
stg.sand_sample_target[0][1]])))[0][0]
)
# --- Find index in depth (along acoustic recording) of sand sample target ---
if stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
d1 = (
np.where(np.abs(stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq1.currentIndex()] - (-stg.depth_sand[stg.sand_sample_target[0][1]]) ) ==
np.nanmin(np.abs(stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq1.currentIndex()] - (-stg.depth_sand[stg.sand_sample_target[0][1]]) )))[0][0]
)
d2 = (
np.where(np.abs(stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex()] - (-stg.depth_sand[stg.sand_sample_target[0][1]]) ) ==
np.nanmin(np.abs(stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex()] - (-stg.depth_sand[stg.sand_sample_target[0][1]]) )))[0][0]
)
else:
d1 = (
np.where(np.abs(stg.depth[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq1.currentIndex()] - (-stg.depth_sand[
stg.sand_sample_target[0][1]]) ) ==
np.nanmin(np.abs(stg.depth[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq1.currentIndex()] - (-stg.depth_sand[
stg.sand_sample_target[0][1]]) )))[0][0]
)
d2 = (
np.where(np.abs(stg.depth[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex()] - (-stg.depth_sand[
stg.sand_sample_target[0][1]]) ) ==
np.nanmin(np.abs(stg.depth[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex()] - (-stg.depth_sand[
stg.sand_sample_target[0][1]]) )))[0][0]
)
stg.sand_sample_target_indice = [(d1, t1), (d2, t2)]
print("stg.sand_sample_target_indice ", stg.sand_sample_target_indice)
def plot_profile_of_concentration_fine(self):
# --- 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)
for t, c in stg.fine_sample_profile:
self.ax_Mfine.plot(stg.Ctot_fine[c], stg.depth_fine[c],
marker="o", mfc="k", mec="k", ms=10, ls="None")
self.ax_Mfine.text(stg.Ctot_fine[c] + 0.05 * stg.Ctot_fine[c], stg.depth_fine[c], t,
fontstyle="normal", fontweight="light", fontsize=12)
self.ax_Mfine.set_xlabel("Concentration fine sediments (g/L)")
self.ax_Mfine.set_ylabel("Depth (m)")
if stg.M_profile_fine:
self.ax_Mfine.plot(stg.M_profile_fine, [-r for r in stg.range_lin_interp],
marker="*", mfc="b", mec="b", ms=8, ls="None")
def interpolate_Mfine_profile(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]])
stg.range_lin_interp, stg.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:
stg.range_lin_interp, stg.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()]))
print(f"1 M_profile_fine : {stg.M_profile_fine}")
stg.range_lin_interp = stg.range_lin_interp.tolist()
stg.M_profile_fine = stg.M_profile_fine.tolist()
stg.M_profile_fine = stg.M_profile_fine[:len(stg.range_lin_interp)]
print(f"2 M_profile_fine : {stg.M_profile_fine}")
self.plot_profile_of_concentration_fine()
# 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)
# ------------------------------------------------------------------
# --------------- Functions for sediment calibration ---------------
# ------------------------------------------------------------------
def groupbox_calibration_import_toggle(self):
if self.groupbox_sediment_calibration_import.isChecked() == True:
self.groupbox_sediment_calibration_compute.setChecked(False)
elif self.groupbox_sediment_calibration_import.isChecked() == True:
self.groupbox_sediment_calibration_compute.setChecked(False)
def groupbox_calibration_import_size_change(self):
duration = 500
self.animaiton_groupbox_import = QPropertyAnimation(self.groupbox_sediment_calibration_import, b"size")
self.animaiton_groupbox_import.setDuration(duration)
self.animaiton_groupbox_import.setStartValue(QSize(self.groupbox_sediment_calibration_import.width(),
self.groupbox_sediment_calibration_import.height()))
if self.groupbox_sediment_calibration_import.isChecked():
self.animaiton_groupbox_import.setEndValue(
QSize(self.groupbox_sediment_calibration_import.width(),
self.groupbox_sediment_calibration_import.sizeHint().height()))
else:
self.animaiton_groupbox_import.setEndValue(QSize(self.groupbox_sediment_calibration_import.width(), 25))
self.animaiton_groupbox_import.start()
def groupbox_calibration_compute_toggle(self):
if self.groupbox_sediment_calibration_compute.isChecked() == True:
self.groupbox_sediment_calibration_import.setChecked(False)
elif self.groupbox_sediment_calibration_compute.isChecked() == True:
self.groupbox_sediment_calibration_import.setChecked(False)
def groupbox_calibration_compute_size_change(self):
print("self.groupbox_sediment_calibration_compute.isChecked() ", self.groupbox_sediment_calibration_compute.isChecked())
duration = 500
self.animaiton_groupbox_compute = QPropertyAnimation(self.groupbox_sediment_calibration_compute, b"size")
self.animaiton_groupbox_compute.setDuration(duration)
self.animaiton_groupbox_compute.setStartValue(QSize(self.groupbox_sediment_calibration_compute.width(),
self.groupbox_sediment_calibration_compute.height()))
if self.groupbox_sediment_calibration_compute.isChecked():
print("Checked")
self.animaiton_groupbox_compute.setEndValue(
QSize(self.groupbox_sediment_calibration_compute.width(),
self.groupbox_sediment_calibration_compute.sizeHint().height()))
else:
print("Non Checked")
self.animaiton_groupbox_compute.setEndValue(QSize(self.groupbox_sediment_calibration_compute.width(), 25))
self.animaiton_groupbox_compute.start()
def import_calibration_file(self):
filename = QFileDialog.getOpenFileName(self, "Open file",
[stg.path_BS_raw_data[-1] if stg.path_BS_raw_data[-1] != "" else ""][0],
"Calibration file (*.xls, *.ods)")
dir_name = path.dirname(filename[0])
name = path.basename(filename[0])
stg.calibration_file.clear()
stg.calibration_file.append(dir_name)
stg.calibration_file.append(name)
print("stg.calibration_file ", stg.calibration_file)
self.lineEdit_import_calibration.clear()
self.lineEdit_import_calibration.setText(name)
self.lineEdit_import_calibration.setToolTip(dir_name)
self.read_calibration_file_and_fill_parameter()
def read_calibration_file_and_fill_parameter(self):
# --- Read calibration file ---
data = pd.read_excel(stg.calibration_file[0] + "/" + stg.calibration_file[1], header=0, index_col=0)
print(data.head())
print(data.iloc[0][0])
print(type(data.iloc[0][0]))
# --- Fill spinboxes of calibration parameter ---
self.spinbox_ks_freq1.clear()
self.spinbox_ks_freq1.setValue(float(data.iloc[0][0]))
self.spinbox_ks_freq2.clear()
self.spinbox_ks_freq2.setValue(float(data.iloc[0][1]))
self.spinbox_sv_freq1.clear()
self.spinbox_sv_freq1.setValue(float(data.iloc[1][0]))
self.spinbox_sv_freq2.clear()
self.spinbox_sv_freq2.setValue(float(data.iloc[1][1]))
self.spinbox_X.clear()
self.spinbox_X.setValue(float(data.iloc[2][0]))
self.spinbox_alphas_freq1.clear()
self.spinbox_alphas_freq1.setValue(float(data.iloc[3][0]))
self.spinbox_alphas_freq2.clear()
self.spinbox_alphas_freq2.setValue(float(data.iloc[3][1]))
self.spinbox_zeta_freq1.clear()
self.spinbox_zeta_freq1.setValue(float(data.iloc[4][0]))
self.spinbox_zeta_freq2.clear()
self.spinbox_zeta_freq2.setValue(float(data.iloc[4][1]))
def function_pushbutton_compute_calibration(self):
# --- Compute frequency ---
self.label_freq1.clear()
self.label_freq1.setText(str(self.combobox_freq1.currentText()))
self.label_freq2.clear()
self.label_freq2.setText(str(self.combobox_freq2.currentText()))
# --- Compute ks ---
psd_number_of_particles = (
self.inv_hc.compute_particle_size_distribution_in_number_of_particles(
num_sample=stg.sand_sample_target[0][1], r_grain=stg.radius_grain_sand,
frac_vol_cumul=stg.frac_vol_sand_cumul))
ks_freq1 = self.inv_hc.ks(proba_num=psd_number_of_particles,
freq=stg.freq[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq1.currentIndex()],
C=stg.water_velocity[self.combobox_acoustic_data_choice.currentIndex()])
ks_freq2 = self.inv_hc.ks(proba_num=psd_number_of_particles,
freq=stg.freq[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex()],
C=stg.water_velocity[self.combobox_acoustic_data_choice.currentIndex()])
stg.ks = [ks_freq1, ks_freq2]
print("\n************************************************************** \n")
print(f"ks for frequency of {stg.freq[self.combobox_acoustic_data_choice.currentIndex()][self.combobox_freq1.currentIndex()]} : {ks_freq1} m/kg^0.5 \n")
print(f"ks for frequency of {stg.freq[self.combobox_acoustic_data_choice.currentIndex()][self.combobox_freq2.currentIndex()]} : {ks_freq2} m/kg^0.5")
self.spinbox_ks_freq1.clear()
self.spinbox_ks_freq1.setValue(ks_freq1)
self.spinbox_ks_freq2.clear()
self.spinbox_ks_freq2.setValue(ks_freq2)
# --- Compute sv ---
sv_freq1 = self.inv_hc.sv(ks=ks_freq1, M_sand=stg.Ctot_sand[stg.sand_sample_target[0][1]])
sv_freq2 = self.inv_hc.sv(ks=ks_freq2, M_sand=stg.Ctot_sand[stg.sand_sample_target[0][1]])
stg.sv = [sv_freq1, sv_freq2]
print(f"sv for frequency of {stg.freq[self.combobox_acoustic_data_choice.currentIndex()][self.combobox_freq1.currentIndex()]} : {sv_freq1:.8f} /m \n")
print(f"sv for frequency of {stg.freq[self.combobox_acoustic_data_choice.currentIndex()][self.combobox_freq2.currentIndex()]} : {sv_freq2:.8f} /m")
self.spinbox_sv_freq1.clear()
self.spinbox_sv_freq1.setValue(sv_freq1)
self.spinbox_sv_freq2.clear()
self.spinbox_sv_freq2.setValue(sv_freq2)
# --- Compute exponent X ---
X_exponent = self.inv_hc.X_exponent(freq1=stg.freq[self.combobox_acoustic_data_choice.currentIndex()][self.combobox_freq1.currentIndex()],
freq2=stg.freq[self.combobox_acoustic_data_choice.currentIndex()][self.combobox_freq2.currentIndex()],
sv_freq1=sv_freq1, sv_freq2=sv_freq2)
stg.X_exponent.append(X_exponent)
print(f"Exponent X = {X_exponent:.2f}\n")
self.spinbox_X.clear()
self.spinbox_X.setValue(X_exponent)
# --- Compute kt2D, kt3D and depth_2D ---
if stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
if stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
stg.depth_2D[self.combobox_acoustic_data_choice.currentIndex()] = (
np.zeros((stg.freq[self.combobox_acoustic_data_choice.currentIndex()].shape[0],
stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape[1],
stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape[1])))
for f, _ in enumerate(stg.freq[self.combobox_acoustic_data_choice.currentIndex()]):
stg.depth_2D[self.combobox_acoustic_data_choice.currentIndex()][f, :, :] = (
np.repeat(np.transpose(stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()]
[self.combobox_freq1.currentIndex()])[:, np.newaxis],
stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape[1],
axis=1))
print("kt cor ", stg.kt_corrected)
print("kt read", stg.kt_read)
if (stg.kt_corrected[self.combobox_acoustic_data_choice.currentIndex()] !=
stg.kt_read[self.combobox_acoustic_data_choice.currentIndex()]):
kt2D = np.repeat(
np.array([stg.kt_corrected[self.combobox_acoustic_data_choice.currentIndex()]]).transpose(),
stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape[1],
axis=1)
kt3D = np.repeat(
kt2D[:, np.newaxis, :],
stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape[1],
axis=1)
else:
kt2D = np.repeat(
np.array([stg.kt_read[self.combobox_acoustic_data_choice.currentIndex()]]).transpose(),
stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape[1],
axis=1)
print(stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape)
print("kt2D shape ", kt2D.shape)
print("kt2D ", kt2D)
kt3D = np.repeat(
kt2D[:, np.newaxis, :],
stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape[1],
axis=1)
print("kt3D shape ", kt3D.shape)
print("kt3D ", kt3D)
elif stg.time[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
stg.depth_2D[self.combobox_acoustic_data_choice.currentIndex()] = (
np.zeros((stg.freq[self.combobox_acoustic_data_choice.currentIndex()].shape[0],
stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape[1],
stg.time[self.combobox_acoustic_data_choice.currentIndex()].shape[1])))
for f, _ in enumerate(stg.freq[self.combobox_acoustic_data_choice.currentIndex()]):
stg.depth_2D[self.combobox_acoustic_data_choice.currentIndex()][f, :, :] = (
np.repeat(
np.transpose(stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()]
[self.combobox_freq1.currentIndex()])[:, np.newaxis],
stg.time[self.combobox_acoustic_data_choice.currentIndex()].shape[1],
axis=1))
print("kt cor ", stg.kt_corrected)
print("kt read", stg.kt_read)
if (stg.kt_corrected[self.combobox_acoustic_data_choice.currentIndex()] !=
stg.kt_read[self.combobox_acoustic_data_choice.currentIndex()]):
kt2D = np.repeat(
np.array([stg.kt_corrected[self.combobox_acoustic_data_choice.currentIndex()]]).transpose(),
stg.time[self.combobox_acoustic_data_choice.currentIndex()].shape[1],
axis=1)
kt3D = np.repeat(
kt2D[:, np.newaxis, :],
stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape[1],
axis=1)
else:
kt2D = np.repeat(
np.array([stg.kt_read[self.combobox_acoustic_data_choice.currentIndex()]]).transpose(),
stg.time[self.combobox_acoustic_data_choice.currentIndex()].shape[1],
axis=1)
print(stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape)
print("kt2D shape ", kt2D.shape)
print("kt2D ", kt2D)
kt3D = np.repeat(
kt2D[:, np.newaxis, :],
stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape[1],
axis=1)
print("kt3D shape ", kt3D.shape)
print("kt3D ", kt3D)
elif stg.depth[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
if stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
stg.depth_2D[self.combobox_acoustic_data_choice.currentIndex()] = (
np.zeros((stg.freq[self.combobox_acoustic_data_choice.currentIndex()].shape[0],
stg.depth[self.combobox_acoustic_data_choice.currentIndex()].shape[1],
stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape[1])))
for f, _ in enumerate(stg.freq[self.combobox_acoustic_data_choice.currentIndex()]):
stg.depth_2D[self.combobox_acoustic_data_choice.currentIndex()][f, :, :] = (
np.repeat(
np.transpose(stg.depth[self.combobox_acoustic_data_choice.currentIndex()]
[self.combobox_freq1.currentIndex()])[:, np.newaxis],
stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape[1],
axis=1))
print("kt cor ", stg.kt_corrected)
print("kt read", stg.kt_read)
if (stg.kt_corrected[self.combobox_acoustic_data_choice.currentIndex()] !=
stg.kt_read[self.combobox_acoustic_data_choice.currentIndex()]):
kt2D = np.repeat(
np.array([stg.kt_corrected[self.combobox_acoustic_data_choice.currentIndex()]]).transpose(),
stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape[1],
axis=1)
kt3D = np.repeat(
kt2D[:, np.newaxis, :],
stg.depth[self.combobox_acoustic_data_choice.currentIndex()].shape[1],
axis=1)
else:
kt2D = np.repeat(
np.array([stg.kt_read[self.combobox_acoustic_data_choice.currentIndex()]]).transpose(),
stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape[1],
axis=1)
print(stg.depth[self.combobox_acoustic_data_choice.currentIndex()].shape)
print("kt2D shape ", kt2D.shape)
print("kt2D ", kt2D)
kt3D = np.repeat(
kt2D[:, np.newaxis, :],
stg.depth[self.combobox_acoustic_data_choice.currentIndex()].shape[1],
axis=1)
print("kt3D shape ", kt3D.shape)
print("kt3D ", kt3D)
elif stg.time[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
stg.depth_2D[self.combobox_acoustic_data_choice.currentIndex()] = (
np.zeros((stg.freq[self.combobox_acoustic_data_choice.currentIndex()].shape[0],
stg.depth[self.combobox_acoustic_data_choice.currentIndex()].shape[1],
stg.time[self.combobox_acoustic_data_choice.currentIndex()].shape[1])))
for f, _ in enumerate(stg.freq[self.combobox_acoustic_data_choice.currentIndex()]):
stg.depth_2D[self.combobox_acoustic_data_choice.currentIndex()][f, :, :] = (
np.repeat(
np.transpose(stg.depth[self.combobox_acoustic_data_choice.currentIndex()]
[self.combobox_freq1.currentIndex()])[:, np.newaxis],
stg.time[self.combobox_acoustic_data_choice.currentIndex()].shape[1],
axis=1))
print("kt cor ", stg.kt_corrected)
print("kt read", stg.kt_read)
if (stg.kt_corrected[self.combobox_acoustic_data_choice.currentIndex()] !=
stg.kt_read[self.combobox_acoustic_data_choice.currentIndex()]):
kt2D = np.repeat(
np.array([stg.kt_corrected[self.combobox_acoustic_data_choice.currentIndex()]]).transpose(),
stg.time[self.combobox_acoustic_data_choice.currentIndex()].shape[1],
axis=1)
kt3D = np.repeat(
kt2D[:, np.newaxis, :],
stg.depth[self.combobox_acoustic_data_choice.currentIndex()].shape[1],
axis=1)
else:
kt2D = np.repeat(
np.array([stg.kt_read[self.combobox_acoustic_data_choice.currentIndex()]]).transpose(),
stg.time[self.combobox_acoustic_data_choice.currentIndex()].shape[1],
axis=1)
print(stg.depth[self.combobox_acoustic_data_choice.currentIndex()].shape)
print("kt2D shape ", kt2D.shape)
print("kt2D ", kt2D)
kt3D = np.repeat(
kt2D[:, np.newaxis, :],
stg.depth[self.combobox_acoustic_data_choice.currentIndex()].shape[1],
axis=1)
print("kt3D shape ", kt3D.shape)
print("kt3D ", kt3D)
# --- Compute J ---
if stg.BS_stream_bed_pre_process_average[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
J_cross_section_freq1 = self.inv_hc.j_cross_section(
BS=stg.BS_stream_bed_pre_process_average[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq1.currentIndex(), :, :],
r2D=stg.depth_2D[self.combobox_acoustic_data_choice.currentIndex()][self.combobox_freq1.currentIndex(),
:, :],
kt=kt3D[self.combobox_freq1.currentIndex(), :, :])
J_cross_section_freq2 = self.inv_hc.j_cross_section(
BS=stg.BS_stream_bed_pre_process_average[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), :, :],
r2D=stg.depth_2D[self.combobox_acoustic_data_choice.currentIndex()][self.combobox_freq2.currentIndex(),
:, :],
kt=kt3D[self.combobox_freq2.currentIndex(), :, :])
elif stg.BS_stream_bed_pre_process_SNR[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
J_cross_section_freq1 = self.inv_hc.j_cross_section(
BS=stg.BS_stream_bed_pre_process_SNR[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq1.currentIndex(), :, :],
r2D=stg.depth_2D[self.combobox_acoustic_data_choice.currentIndex()][self.combobox_freq1.currentIndex(),
:, :],
kt=kt3D[self.combobox_freq1.currentIndex(), :, :])
J_cross_section_freq2 = self.inv_hc.j_cross_section(
BS=stg.BS_stream_bed_pre_process_SNR[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), :, :],
r2D=stg.depth_2D[self.combobox_acoustic_data_choice.currentIndex()][self.combobox_freq2.currentIndex(),
:, :],
kt=kt3D[self.combobox_freq2.currentIndex(), :, :])
elif stg.BS_stream_bed[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
# stg.depth_2D[self.combobox_acoustic_data_choice.currentIndex()] = (
# np.zeros(stg.BS_stream_bed[self.combobox_acoustic_data_choice.currentIndex()].shape))
# for f, _ in enumerate(stg.freq[self.combobox_acoustic_data_choice.currentIndex()]):
# stg.depth_2D[self.combobox_acoustic_data_choice.currentIndex()][f, :, :] = (
# np.repeat(np.transpose(stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()]
# [self.combobox_freq1.currentIndex()])[:, np.newaxis],
# stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape[1],
# axis=1))
#
# print("kt cor ", stg.kt_corrected)
# print("kt read", stg.kt_read)
#
# if (stg.kt_corrected[self.combobox_acoustic_data_choice.currentIndex()] !=
# stg.kt_read[self.combobox_acoustic_data_choice.currentIndex()]):
# kt2D = np.repeat(np.array([stg.kt_corrected[self.combobox_acoustic_data_choice.currentIndex()]]).transpose(),
# stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape[1],
# axis=1)
# kt3D = np.repeat(kt2D[:, np.newaxis, :],
# stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape[1], axis=1)
# else:
# kt2D = np.repeat(np.array([stg.kt_read[self.combobox_acoustic_data_choice.currentIndex()]]).transpose(),
# stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape[1],
# axis=1)
# print(stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape)
# print("kt2D shape ", kt2D.shape)
# print("kt2D ", kt2D)
# kt3D = np.repeat(kt2D[:, np.newaxis, :],
# stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape[1], axis=1)
# print("kt3D shape ", kt3D.shape)
# print("kt3D ", kt3D)
J_cross_section_freq1 = self.inv_hc.j_cross_section(
BS=stg.BS_stream_bed[self.combobox_acoustic_data_choice.currentIndex()][self.combobox_freq1.currentIndex(), :, :],
r2D=stg.depth_2D[self.combobox_acoustic_data_choice.currentIndex()][self.combobox_freq1.currentIndex(), :, :],
kt=kt3D[self.combobox_freq1.currentIndex(), :, :])
J_cross_section_freq2 = self.inv_hc.j_cross_section(
BS=stg.BS_stream_bed[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), :, :],
r2D=stg.depth_2D[self.combobox_acoustic_data_choice.currentIndex()][self.combobox_freq2.currentIndex(), :, :],
kt=kt3D[self.combobox_freq2.currentIndex(), :, :])
elif stg.BS_cross_section_pre_process_average[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
J_cross_section_freq1 = self.inv_hc.j_cross_section(
BS=stg.BS_cross_section_pre_process_average[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq1.currentIndex(), :, :],
r2D=stg.depth_2D[self.combobox_acoustic_data_choice.currentIndex()][self.combobox_freq1.currentIndex(),
:, :],
kt=kt3D[self.combobox_freq1.currentIndex(), :, :])
J_cross_section_freq2 = self.inv_hc.j_cross_section(
BS=stg.BS_cross_section_pre_process_average[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), :, :],
r2D=stg.depth_2D[self.combobox_acoustic_data_choice.currentIndex()][self.combobox_freq2.currentIndex(),
:, :],
kt=kt3D[self.combobox_freq2.currentIndex(), :, :])
elif stg.BS_cross_section_pre_process_SNR[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
J_cross_section_freq1 = self.inv_hc.j_cross_section(
BS=stg.BS_cross_section_pre_process_SNR[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq1.currentIndex(), :, :],
r2D=stg.depth_2D[self.combobox_acoustic_data_choice.currentIndex()][self.combobox_freq1.currentIndex(),
:, :],
kt=kt3D[self.combobox_freq1.currentIndex(), :, :])
J_cross_section_freq2 = self.inv_hc.j_cross_section(
BS=stg.BS_cross_section_pre_process_SNR[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), :, :],
r2D=stg.depth_2D[self.combobox_acoustic_data_choice.currentIndex()][self.combobox_freq2.currentIndex(),
:, :],
kt=kt3D[self.combobox_freq2.currentIndex(), :, :])
elif stg.BS_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
# stg.depth_2D[self.combobox_acoustic_data_choice.currentIndex()] = np.zeros(stg.BS_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape)
# for f, _ in enumerate(stg.freq[self.combobox_acoustic_data_choice.currentIndex()]):
# stg.depth_2D[self.combobox_acoustic_data_choice.currentIndex()][f, :, :] = np.repeat(
# np.transpose(stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()]
# [self.combobox_freq1.currentIndex()])[:, np.newaxis],
# stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape[1],
# axis=1)
#
# if stg.kt_corrected[self.combobox_acoustic_data_choice.currentIndex()]:
# kt2D = np.repeat(np.array(stg.kt_corrected[self.combobox_acoustic_data_choice.currentIndex()]),
# stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape[1],
# axis=1)
# kt3D = np.repeat(kt2D[:, :, np.newaxis],
# stg.freq[self.combobox_acoustic_data_choice.currentIndex()].shape[0], axis=2)
# else:
# kt2D = np.repeat(np.array(stg.kt_read[self.combobox_acoustic_data_choice.currentIndex()]),
# stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape[1],
# axis=1)
# kt3D = np.repeat(kt2D[:, :, np.newaxis],
# stg.freq[self.combobox_acoustic_data_choice.currentIndex()].shape[0], axis=2)
J_cross_section_freq1 = self.inv_hc.j_cross_section(
BS=stg.BS_cross_section[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq1.currentIndex(), :, :],
r2D=stg.depth_2D[self.combobox_freq1.currentIndex(), :, :][self.combobox_freq1.currentIndex(), :, :],
kt=kt3D[self.combobox_freq1.currentIndex(), :, :])
J_cross_section_freq2 = self.inv_hc.j_cross_section(
BS=stg.BS_cross_section[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), :, :],
r2D=stg.depth_2D[self.combobox_freq2.currentIndex(), :, :][self.combobox_freq2.currentIndex(), :, :],
kt=kt3D[self.combobox_freq2.currentIndex(), :, :])
elif stg.BS_raw_data_pre_process_average[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
J_cross_section_freq1 = self.inv_hc.j_cross_section(
BS=stg.BS_raw_data_pre_process_average[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq1.currentIndex(), :, :],
r2D=stg.depth_2D[self.combobox_freq1.currentIndex(), :, :],
kt=kt3D[self.combobox_freq1.currentIndex(), :, :])
J_cross_section_freq2 = self.inv_hc.j_cross_section(
BS=stg.BS_raw_data_pre_process_average[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), :, :],
r2D=stg.depth_2D[self.combobox_freq2.currentIndex(), :, :],
kt=kt3D[self.combobox_freq2.currentIndex(), :, :])
elif stg.BS_raw_data_pre_process_SNR[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
J_cross_section_freq1 = self.inv_hc.j_cross_section(
BS=stg.BS_raw_data_pre_process_SNR[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq1.currentIndex(), :, :],
r2D=stg.depth_2D[self.combobox_freq1.currentIndex(), :, :],
kt=kt3D[self.combobox_freq1.currentIndex(), :, :])
J_cross_section_freq2 = self.inv_hc.j_cross_section(
BS=stg.BS_raw_data_pre_process_SNR[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), :, :],
r2D=stg.depth_2D[self.combobox_freq2.currentIndex(), :, :],
kt=kt3D[self.combobox_freq2.currentIndex(), :, :])
elif stg.BS_raw_data:
# stg.depth_2D = np.zeros(stg.BS_raw_data[self.combobox_acoustic_data_choice.currentIndex()].shape)
# for f, _ in enumerate(stg.freq[self.combobox_acoustic_data_choice.currentIndex()]):
# stg.depth_2D[f, :, :] = np.repeat(
# np.transpose(stg.depth[self.combobox_acoustic_data_choice.currentIndex()]
# [self.combobox_freq1.currentIndex()])[:, np.newaxis],
# stg.time[self.combobox_acoustic_data_choice.currentIndex()].shape[1],
# axis=1)
#
# if stg.kt_corrected[self.combobox_acoustic_data_choice.currentIndex()]:
# kt2D = np.repeat(np.array(stg.kt_corrected[self.combobox_acoustic_data_choice.currentIndex()]),
# stg.depth[self.combobox_acoustic_data_choice.currentIndex()].shape[1],
# axis=1)
# kt3D = np.repeat(kt2D[:, :, np.newaxis],
# stg.freq[self.combobox_acoustic_data_choice.currentIndex()].shape[0], axis=2)
# else:
# kt2D = np.repeat(np.array(stg.kt_read[self.combobox_acoustic_data_choice.currentIndex()]),
# stg.depth[self.combobox_acoustic_data_choice.currentIndex()].shape[1],
# axis=1)
# kt3D = np.repeat(kt2D[:, :, np.newaxis],
# stg.freq[self.combobox_acoustic_data_choice.currentIndex()].shape[0], axis=2)
J_cross_section_freq1 = self.inv_hc.j_cross_section(
BS=stg.BS_raw_data[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq1.currentIndex(), :, :],
r2D=stg.depth_2D[self.combobox_freq1.currentIndex(), :, :],
kt=kt3D[self.combobox_freq1.currentIndex(), :, :])
J_cross_section_freq2 = self.inv_hc.j_cross_section(
BS=stg.BS_raw_data[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), :, :],
r2D=stg.depth_2D[self.combobox_freq2.currentIndex(), :, :],
kt=kt3D[self.combobox_freq2.currentIndex(), :, :])
stg.J_cross_section.append(J_cross_section_freq1)
stg.J_cross_section.append(J_cross_section_freq2)
print("J_cross_section_freq1.shape ", J_cross_section_freq1.shape)
print("J_cross_section_freq2.shape ", J_cross_section_freq2.shape)
# --- Compute alpha_s ---
if stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
alpha_s_freq1 = self.inv_hc.alpha_s(
sv=sv_freq1,
j_cross_section=J_cross_section_freq1[stg.sand_sample_target_indice[0][0],
stg.sand_sample_target_indice[0][1]],
depth=stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq1.currentIndex(), stg.sand_sample_target_indice[0][0]],
alpha_w=stg.water_attenuation[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq1.currentIndex()])
alpha_s_freq2 = self.inv_hc.alpha_s(
sv=sv_freq2,
j_cross_section=J_cross_section_freq2[stg.sand_sample_target_indice[1][0],
stg.sand_sample_target_indice[1][1]],
depth=stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), stg.sand_sample_target_indice[1][0]],
alpha_w=stg.water_attenuation[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex()])
else:
alpha_s_freq1 = self.inv_hc.alpha_s(
sv=sv_freq1,
j_cross_section=J_cross_section_freq1[stg.sand_sample_target_indice[0][0],
stg.sand_sample_target_indice[0][1]],
depth=stg.depth[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq1.currentIndex(), stg.sand_sample_target_indice[0][0]],
alpha_w=stg.water_attenuation[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq1.currentIndex()])
alpha_s_freq2 = self.inv_hc.alpha_s(
sv=sv_freq2,
j_cross_section=J_cross_section_freq2[stg.sand_sample_target_indice[1][0],
stg.sand_sample_target_indice[1][1]],
depth=stg.depth[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), stg.sand_sample_target_indice[1][0]],
alpha_w=stg.water_attenuation[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex()])
stg.alpha_s = [alpha_s_freq1, alpha_s_freq2]
print(f"\u03B1s for frequency of freq1 : {alpha_s_freq1:.2f} /m \n")
print(f"\u03B1s for frequency of freq2 : {alpha_s_freq2:.2f} /m")
self.spinbox_alphas_freq1_compute.clear()
self.spinbox_alphas_freq1_compute.setValue(alpha_s_freq1)
self.spinbox_alphas_freq2.clear()
self.spinbox_alphas_freq2.setValue(alpha_s_freq2)
# --- Compute zeta ---
if stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
zeta_freq1 = self.inv_hc.zeta(alpha_s=alpha_s_freq1,
r=stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq1.currentIndex(), :],
M_profile_fine=stg.M_profile_fine)
zeta_freq2 = self.inv_hc.zeta(alpha_s=alpha_s_freq2,
r=stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), :],
M_profile_fine=stg.M_profile_fine)
else:
zeta_freq1 = self.inv_hc.zeta(alpha_s=alpha_s_freq1,
r=stg.depth[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq1.currentIndex(), :],
M_profile_fine=stg.M_profile_fine)
zeta_freq2 = self.inv_hc.zeta(alpha_s=alpha_s_freq2,
r=stg.depth[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), :],
M_profile_fine=stg.M_profile_fine)
stg.zeta = [zeta_freq1, zeta_freq2]
print(f"\u03B6 for frequency of freq1 : {zeta_freq1:.3f} /m \n")
print(f"\u03B6 for frequency of freq2 : {zeta_freq2:.3f} /m")
self.spinbox_zeta_freq1.clear()
self.spinbox_zeta_freq1.setValue(zeta_freq1)
self.spinbox_zeta_freq2.clear()
self.spinbox_zeta_freq2.setValue(zeta_freq2)
# --- Compute FCB ---
# ------------ Computing real cell size ------------ #
def range_cells_function(self):
""" Computing the real cell size, that depends on the temperature """
if stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
aquascat_cell_size = []
tau = []
real_cell_size = []
stg.depth_real[self.combobox_acoustic_data_choice.currentIndex()] = (
np.zeros(stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape))
for f in range(stg.freq[self.combobox_acoustic_data_choice.currentIndex()].shape[0]):
print("f = ", f)
# defaut Aquascat cell size
aquascat_cell_size.append(
stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()][f, 1] -
stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()][f, 0])
# Pulse duration
tau.append(aquascat_cell_size[f] * 2 / 1500) # figure 2.9 1500 vitesse du son entrée pour le paramètrage des mesures aquascat
print(stg.water_velocity[self.combobox_acoustic_data_choice.currentIndex()])
print(tau)
# Real cell size
real_cell_size.append(stg.water_velocity[self.combobox_acoustic_data_choice.currentIndex()] * tau[f] / 2) # voir fig 2.9
# Converting to real cell profile
stg.depth_real[self.combobox_acoustic_data_choice.currentIndex()][f, :] = \
(stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()][f, :] /
aquascat_cell_size[f] * real_cell_size[f]) # (/ aquascat_cell_size) pour ramener BS.r entre 0 et 1
print("stg.depth_real ", stg.depth_real)
# (* real_cell_size) pour remettre les échelles spatiales sur la taille réelle des cellules
else:
aquascat_cell_size = []
tau = []
real_cell_size = []
stg.depth_real[self.combobox_acoustic_data_choice.currentIndex()] = (
np.zeros(stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape))
for f in range(stg.freq[self.combobox_acoustic_data_choice.currentIndex()].shape[0]):
# defaut Aquascat cell size
aquascat_cell_size.append(
stg.depth[self.combobox_acoustic_data_choice.currentIndex()][f, 1] -
stg.depth[self.combobox_acoustic_data_choice.currentIndex()][f, 0])
# Pulse duration
tau.append(aquascat_cell_size[f] * 2 / 1500) # figure 2.9 1500 vitesse du son entrée pour le paramètrage des mesures aquascat
# Real cell size
real_cell_size.append(stg.water_velocity[self.combobox_acoustic_data_choice.currentIndex()] * tau[f] / 2) # voir fig 2.9
# Converting to real cell profile
stg.depth_real[self.combobox_acoustic_data_choice.currentIndex()][f, :] = \
(stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()][f, :] /
aquascat_cell_size[f] * real_cell_size[f]) # (/ 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
print("R_real 2D ", stg.depth_real[self.combobox_acoustic_data_choice.currentIndex()].shape)
if stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
stg.depth_real[self.combobox_acoustic_data_choice.currentIndex()] = (
np.repeat(stg.depth_real[self.combobox_acoustic_data_choice.currentIndex()][:, :, np.newaxis],
stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape[1], axis=2))
print("R_real 3D ", stg.depth_real[self.combobox_acoustic_data_choice.currentIndex()].shape)
def compute_FCB(self):
# if stg.BS_stream_bed.size == 0:
# msgBox = QMessageBox()
# msgBox.setWindowTitle("FCB Error")
# msgBox.setIcon(QMessageBox.Warning)
# msgBox.setText("Load Backscatter data from acoustic data tab and compute water attenuation")
# msgBox.setStandardButtons(QMessageBox.Ok)
# msgBox.exec()
# else:
# R_real = np.repeat(self.range_cells_function()[:, :, np.newaxis], stg.t.shape[1], axis=2)
# 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.combobox_frequency_FCB.clear()
self.combobox_frequency_FCB.addItems(stg.freq_text[self.combobox_acoustic_data_choice.currentIndex()])
self.range_cells_function()
if stg.BS_stream_bed_pre_process_average[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
stg.FCB[self.combobox_acoustic_data_choice.currentIndex()] = \
(np.log(stg.BS_stream_bed_pre_process_average[self.combobox_acoustic_data_choice.currentIndex()]) +
np.log(stg.depth_real[self.combobox_acoustic_data_choice.currentIndex()]) +
2 * stg.water_attenuation[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_frequency_FCB.currentIndex()] *
stg.depth_real[self.combobox_acoustic_data_choice.currentIndex()])
elif stg.BS_stream_bed_pre_process_SNR[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
stg.FCB[self.combobox_acoustic_data_choice.currentIndex()] = \
(np.log(stg.BS_stream_bed_pre_process_SNR[self.combobox_acoustic_data_choice.currentIndex()]) +
np.log(stg.depth_real[self.combobox_acoustic_data_choice.currentIndex()]) +
2 * stg.water_attenuation[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_frequency_FCB.currentIndex()] *
stg.depth_real[self.combobox_acoustic_data_choice.currentIndex()])
elif stg.BS_stream_bed[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
print("zzzzzzzzzzzzzzzzzzzzz")
print(np.log(stg.BS_stream_bed[self.combobox_acoustic_data_choice.currentIndex()]).shape)
print(np.log(stg.depth_real[self.combobox_acoustic_data_choice.currentIndex()]).shape)
print(stg.water_attenuation[self.combobox_acoustic_data_choice.currentIndex()])
print(stg.depth_real[self.combobox_acoustic_data_choice.currentIndex()].shape)
print("zzzzzzzzzzzzzzzzzzzzz")
stg.FCB[self.combobox_acoustic_data_choice.currentIndex()] = \
(np.log(stg.BS_stream_bed[self.combobox_acoustic_data_choice.currentIndex()]) +
np.log(stg.depth_real[self.combobox_acoustic_data_choice.currentIndex()]) +
2 * stg.water_attenuation[self.combobox_acoustic_data_choice.currentIndex()][self.combobox_frequency_FCB.currentIndex()] *
stg.depth_real[self.combobox_acoustic_data_choice.currentIndex()])
elif stg.BS_cross_section_pre_process_average[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
stg.FCB[self.combobox_acoustic_data_choice.currentIndex()] = \
(np.log(stg.BS_cross_section_pre_process_average[self.combobox_acoustic_data_choice.currentIndex()]) +
np.log(stg.depth_real[self.combobox_acoustic_data_choice.currentIndex()]) +
2 * stg.water_attenuation[self.combobox_acoustic_data_choice.currentIndex()] *
stg.depth_real[self.combobox_acoustic_data_choice.currentIndex()])
elif stg.BS_cross_section_pre_process_SNR[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
stg.FCB[self.combobox_acoustic_data_choice.currentIndex()] = \
(np.log(stg.BS_cross_section_pre_process_SNR[self.combobox_acoustic_data_choice.currentIndex()]) +
np.log(stg.depth_real[self.combobox_acoustic_data_choice.currentIndex()]) +
2 * stg.water_attenuation[self.combobox_acoustic_data_choice.currentIndex()] *
stg.depth_real[self.combobox_acoustic_data_choice.currentIndex()])
elif stg.BS_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
stg.FCB[self.combobox_acoustic_data_choice.currentIndex()] = \
(np.log(stg.BS_cross_section[self.combobox_acoustic_data_choice.currentIndex()]) +
np.log(stg.depth_real[self.combobox_acoustic_data_choice.currentIndex()]) +
2 * stg.water_attenuation[self.combobox_acoustic_data_choice.currentIndex()] *
stg.depth_real[self.combobox_acoustic_data_choice.currentIndex()])
elif stg.BS_raw_data_pre_process_average[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
stg.FCB[self.combobox_acoustic_data_choice.currentIndex()] = \
(np.log(stg.BS_raw_data_pre_process_average[self.combobox_acoustic_data_choice.currentIndex()]) +
np.log(stg.depth_real[self.combobox_acoustic_data_choice.currentIndex()]) +
2 * stg.water_attenuation[self.combobox_acoustic_data_choice.currentIndex()] *
stg.depth_real[self.combobox_acoustic_data_choice.currentIndex()])
elif stg.BS_raw_data_pre_process_SNR[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
stg.FCB[self.combobox_acoustic_data_choice.currentIndex()] = \
(np.log(stg.BS_raw_data_pre_process_SNR[self.combobox_acoustic_data_choice.currentIndex()]) +
np.log(stg.depth_real[self.combobox_acoustic_data_choice.currentIndex()]) +
2 * stg.water_attenuation[self.combobox_acoustic_data_choice.currentIndex()] *
stg.depth_real[self.combobox_acoustic_data_choice.currentIndex()])
elif BS_raw_data[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
stg.FCB[self.combobox_acoustic_data_choice.currentIndex()] = \
(np.log(stg.BS_raw_data[self.combobox_acoustic_data_choice.currentIndex()]) +
np.log(stg.depth_real[self.combobox_acoustic_data_choice.currentIndex()]) +
2 * stg.water_attenuation[self.combobox_acoustic_data_choice.currentIndex()] *
stg.depth_real[self.combobox_acoustic_data_choice.currentIndex()])
print("FCB ", stg.FCB[self.combobox_acoustic_data_choice.currentIndex()].shape)
self.plot_FCB()
def plot_FCB(self):
if stg.FCB[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
if stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
self.slider_FCB.setMaximum(stg.time_cross_section[
self.combobox_acoustic_data_choice.currentIndex()].shape[1])
else:
self.slider_FCB.setMaximum(stg.time[self.combobox_acoustic_data_choice.currentIndex()].shape[1])
self.slider_FCB.setValue(stg.sand_sample_target_indice[0][1])
self.verticalLayout_groupbox_FCB_plot.removeWidget(self.canvas_FCB)
self.verticalLayout_groupbox_FCB_plot.removeWidget(self.toolbar_FCB)
self.fig_FCB, self.axis_FCB = plt.subplots(nrows=1, ncols=1, layout="constrained")
self.canvas_FCB = FigureCanvas(self.fig_FCB)
self.toolbar_FCB = NavigationToolBar(self.canvas_FCB, self)
self.verticalLayout_groupbox_FCB_plot.addWidget(self.toolbar_FCB)
self.verticalLayout_groupbox_FCB_plot.addWidget(self.canvas_FCB)
if stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
self.axis_FCB.plot(
stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_frequency_FCB.currentIndex()],
stg.FCB[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_frequency_FCB.currentIndex(), :, self.slider_FCB.value() - 1],
linestyle="solid", linewidth=1, color="k")
else:
self.axis_FCB.plot(
stg.depth[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_frequency_FCB.currentIndex()],
stg.FCB[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_frequency_FCB.currentIndex(), :, self.slider_FCB.value() - 1],
linestyle="solid", linewidth=1, color="k")
self.axis_FCB.text(.95, .05,
stg.freq_text[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_frequency_FCB.currentIndex()],
fontsize=10, fontweight='bold', fontname="Ubuntu",
fontstyle="normal", c="black", alpha=0.2,
horizontalalignment='right', verticalalignment='bottom',
transform=self.axis_FCB.transAxes)
# if len(stg.lin_reg) != 0:
# self.axis_FCB_profile[self.combobox_frequency_compute_alphaS.currentIndex()]. \
# plot(stg.r[f, :], stg.lin_reg[0]*stg.r[f, :] + stg.lin_reg[1], linestyle="dashed", linewidth=1, color="b")
self.fig_FCB.supxlabel("Depth (m)")
self.fig_FCB.supylabel("FCB")
self.fig_FCB.canvas.draw_idle()
self.slider_FCB.valueChanged.connect(self.update_plot_FCB)
self.combobox_frequency_FCB.currentIndexChanged.connect(self.update_plot_FCB)
def update_plot_FCB(self):
if stg.FCB[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
self.axis_FCB.cla()
if stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
self.axis_FCB.plot(
stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_frequency_FCB.currentIndex()],
stg.FCB[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_frequency_FCB.currentIndex(), :, self.slider_FCB.value() - 1],
linestyle="solid", linewidth=1, color="k")
else:
self.axis_FCB.plot(
stg.depth[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_frequency_FCB.currentIndex()],
stg.FCB[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_frequency_FCB.currentIndex(), :, self.slider_FCB.value() - 1],
linestyle="solid", linewidth=1, color="k")
self.axis_FCB.text(.95, .05,
stg.freq_text[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_frequency_FCB.currentIndex()],
fontsize=10, fontweight='bold', fontname="Ubuntu",
fontstyle="normal", c="black", alpha=0.2,
horizontalalignment='right', verticalalignment='bottom',
transform=self.axis_FCB.transAxes)
self.fig_FCB.canvas.draw_idle()
# --- Update red line on acoustic record plot ---
if stg.sand_sample_target_indice:
if depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
if stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
self.red_line_plot_return.set_data(
stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), self.slider_FCB.value() -1] *
np.ones(
stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape[
1]),
-stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), :])
else:
self.red_line_plot_return.set_data(
stg.time[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), self.slider_FCB.value() -1] *
np.ones(stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape[
1]),
-stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), :])
else:
if stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
self.red_line_plot_return.set_data(
stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), self.slider_FCB.value() -1] *
np.ones(stg.depth[self.combobox_acoustic_data_choice.currentIndex()].shape[1]),
-stg.depth[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), :])
else:
self.red_line_plot_return.set_data(
stg.time[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), self.slider_FCB.value() -1] *
np.ones(stg.depth[self.combobox_acoustic_data_choice.currentIndex()].shape[1]),
-stg.depth[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), :])
self.fig_BS.canvas.draw_idle()
def fit_FCB_profile_with_linear_regression_and_compute_alphaS(self):
self.update_plot_FCB()
if stg.FCB[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
# --- Identify FCB profile where value are not NaN ---
y0 = stg.FCB[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_frequency_FCB.currentIndex(), :, self.slider_FCB.value() - 1]
y = y0[np.where(np.isnan(y0) == False)]
if stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
# --- Select depth corresponding to the FCB profile where value are not NaN ---
x0 = stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_frequency_FCB.currentIndex(), :]
x = x0[np.where(np.isnan(y0) == False)]
# --- Find the indices of the values between which the linear regression is fitted ---
value1 = np.where(np.round(np.abs(x - self.spinbox_FCB_from.value()), 2) ==
np.min(np.round(np.abs(x - self.spinbox_FCB_from.value()), 2)))[0][0]
value2 = np.where(np.round(np.abs(x - self.spinbox_FCB_to.value()), 2) ==
np.min(np.round(np.abs(x - self.spinbox_FCB_to.value()), 2)))[0][0]
print("value1 ", value1)
print("value2 ", value2)
lin_reg_compute = linregress(x[value1:value2], y[value1:value2])
print("lin_reg_compute ", lin_reg_compute)
stg.lin_reg[self.combobox_acoustic_data_choice.currentIndex()] = (lin_reg_compute.slope, lin_reg_compute.intercept)
print("stg.lin_reg ", stg.lin_reg)
# --- Plot result of linear regression ---
self.axis_FCB.plot(
stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_frequency_FCB.currentIndex(), value1:value2],
stg.lin_reg[self.combobox_acoustic_data_choice.currentIndex()][0] *
stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_frequency_FCB.currentIndex(), value1:value2] +
stg.lin_reg[self.combobox_acoustic_data_choice.currentIndex()][1],
linestyle="dashed", linewidth=1, color="b")
else:
# --- Select depth corresponding to the FCB profile where value are not NaN ---
x0 = stg.depth[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_frequency_FCB.currentIndex(), :]
x = x0[np.where(np.isnan(y0) == False)]
# --- Find the indices of the values between which the linear regression is fitted ---
value1 = np.where(np.round(np.abs(x - self.spinbox_FCB_from.value()), 2) ==
np.min(np.round(np.abs(x - self.spinbox_FCB_from.value()), 2)))[0][0]
value2 = np.where(np.round(np.abs(x - self.spinbox_FCB_to.value()), 2) ==
np.min(np.round(np.abs(x - self.spinbox_FCB_to.value()), 2)))[0][0]
print("value1 ", value1)
print("value2 ", value2)
lin_reg_compute = linregress(x[value1:value2], y[value1:value2])
print("lin_reg_compute ", lin_reg_compute)
stg.lin_reg[self.combobox_acoustic_data_choice.currentIndex()] = (
lin_reg_compute.slope, lin_reg_compute.intercept)
# --- Plot result of linear regression ---
self.axis_FCB.plot(
stg.depth[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_frequency_FCB.currentIndex(), value1:value2],
stg.lin_reg[self.combobox_acoustic_data_choice.currentIndex()][0] *
stg.depth[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_frequency_FCB.currentIndex(), value1:value2] +
stg.lin_reg[self.combobox_acoustic_data_choice.currentIndex()][1],
linestyle="dashed", linewidth=1, color="b")
self.fig_FCB.canvas.draw_idle()
# --- Display the value of alphaS compute with FCB ---
self.label_alphaS_FCB.clear()
self.label_alphaS_FCB.setText(f"\u03B1s = {-0.5*stg.lin_reg[self.combobox_acoustic_data_choice.currentIndex()][0]:.4f} dB/m")
# 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)
def slider_profile_number_to_begin_FCB(self):
self.slider_FCB.setValue(int(self.slider_FCB.minimum()))
self.lineEdit_slider_FCB.setText(str(self.slider_FCB.value()))
def slider_profile_number_to_right_FCB(self):
self.slider_FCB.setValue(int(self.slider_FCB.value()) + 1)
self.lineEdit_slider_FCB.setText(str(self.slider_FCB.value()))
def slider_profile_number_to_left_FCB(self):
self.slider_FCB.setValue(int(self.slider_FCB.value()) - 1)
self.lineEdit_slider_FCB.setText(str(self.slider_FCB.value()))
def slider_profile_number_to_end_FCB(self):
self.slider_FCB.setValue(int(self.slider_FCB.maximum()))
self.lineEdit_slider_FCB.setText(str(self.slider_FCB.value()))
def profile_number_on_lineEdit_FCB(self):
self.slider_FCB.setValue(int(self.lineEdit_slider_FCB.text()))
def update_lineEdit_by_moving_slider_FCB(self):
self.lineEdit_slider_FCB.setText(str(self.slider_FCB.value()))