The option 'Import calibration file' is added. The user can choose either to import calibration (default) or to compute calibration.

dev-brahim
brahim 2024-09-12 10:59:54 +02:00
parent 6e6991f0e5
commit 34b0fd48d6
2 changed files with 257 additions and 92 deletions

View File

@ -1,11 +1,12 @@
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)
QSizePolicy, QSlider, QLineEdit, QDial, QFileDialog)
from PyQt5.QtCore import QCoreApplication, Qt
from PyQt5.QtCore import QCoreApplication, Qt, QPropertyAnimation, QSize
from PyQt5.QtGui import QStandardItemModel, QIcon, QPixmap, QFont
import settings as stg
@ -18,6 +19,8 @@ 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
@ -137,10 +140,137 @@ class SedimentCalibrationTab(QWidget):
# --------------------------------------------------------------------------------------------------------------
self.groupbox_sediment_calibration = QGroupBox()
self.horizontalLayoutBottom.addWidget(self.groupbox_sediment_calibration, 5)
self.horizontalLayoutBottom.addWidget(self.groupbox_sediment_calibration, 4)
self.groupbox_FCB = QGroupBox()
self.horizontalLayoutBottom.addWidget(self.groupbox_FCB, 5)
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 +++
@ -151,7 +281,7 @@ class SedimentCalibrationTab(QWidget):
# --- 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, 3)
self.horizontalLayout_groupbox_FCB.addWidget(self.groupbox_FCB_option, 4)
self.label_temperature = QLabel()
self.label_temperature.setText("Temperature : ")
@ -187,7 +317,7 @@ class SedimentCalibrationTab(QWidget):
# --- 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, 7)
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)
@ -233,87 +363,6 @@ class SedimentCalibrationTab(QWidget):
self.slider_FCB.setTickInterval(1)
self.slider_FCB.setValue(1)
# +++++++++++++++++++++++++++++++++++++
# +++ Groupbox sediment calibration +++
self.groupbox_sediment_calibration.setTitle("Step 4 : Compute Calibration")
self.gridLayout_groupbox_sediment_calibration = QGridLayout(self.groupbox_sediment_calibration)
self.pushbutton_compute_calibration = QPushButton()
self.pushbutton_compute_calibration.setText("Compute Calibration")
self.gridLayout_groupbox_sediment_calibration.addWidget(self.pushbutton_compute_calibration, 0, 0, 1, 1)
self.label_freq1 = QLabel("Frequency 1")
self.gridLayout_groupbox_sediment_calibration.addWidget(self.label_freq1, 1, 1, 1, 1)
self.label_freq2 = QLabel("Frequency 2")
self.gridLayout_groupbox_sediment_calibration.addWidget(self.label_freq2, 1, 2, 1, 1)
self.label_ks = QLabel()
self.label_ks.setText("ks")
self.gridLayout_groupbox_sediment_calibration.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.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.addWidget(self.spinbox_ks_freq2, 2, 2, 1, 1)
self.label_sv = QLabel()
self.label_sv.setText("sv")
self.gridLayout_groupbox_sediment_calibration.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.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.addWidget(self.spinbox_sv_freq2, 3, 2, 1, 1)
self.label_X = QLabel()
self.label_X.setText("X")
self.gridLayout_groupbox_sediment_calibration.addWidget(self.label_X, 4, 0, 1, 1)
self.spinbox_X = QDoubleSpinBox()
self.spinbox_X.setDecimals(2)
self.gridLayout_groupbox_sediment_calibration.addWidget(self.spinbox_X, 4, 1, 1, 2)
self.label_alphas = QLabel()
self.label_alphas.setText("\u03B1s")
self.gridLayout_groupbox_sediment_calibration.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.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.addWidget(self.spinbox_alphas_freq2, 5, 2, 1, 1)
self.label_zeta = QLabel()
self.label_zeta.setText("\u03B6")
self.gridLayout_groupbox_sediment_calibration.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.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.addWidget(self.spinbox_zeta_freq2, 6, 2, 1, 1)
# ==============================================================================================================
# ---------------------------------------- Connect signal of widget --------------------------------------------
# ==============================================================================================================
@ -324,6 +373,14 @@ class SedimentCalibrationTab(QWidget):
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)
@ -335,9 +392,9 @@ class SedimentCalibrationTab(QWidget):
self.pushbutton_FCB_fit.clicked.connect(self.fit_FCB_profile_with_linear_regression_and_compute_alphaS)
# ==============================================================================================================
# ----------------------------------- Functions for Signal processing Tab --------------------------------------
# ==============================================================================================================
# ==============================================================================================================
# ----------------------------------- Functions for Signal processing Tab --------------------------------------
# ==============================================================================================================
def function_pushbutton_update_acoustic_file(self):
self.update_acoustic_data()
@ -902,6 +959,112 @@ class SedimentCalibrationTab(QWidget):
# ------------------------------------------------------------------
# --------------- 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 ---
@ -1418,8 +1581,8 @@ class SedimentCalibrationTab(QWidget):
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.clear()
self.spinbox_alphas_freq1.setValue(alpha_s_freq1)
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)

View File

@ -177,6 +177,8 @@ frequencies_for_calibration = []
range_lin_interp = []
M_profile_fine = []
calibration_file = []
ks = []
sv = []
X_exponent = []