From 6628d610de16908e6299c9b71fc20b31077ab4f9 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby Date: Mon, 10 Mar 2025 12:05:07 +0100 Subject: [PATCH 01/11] Sediment calibration: Refactoring __init__ and minor change. --- View/sediment_calibration_tab.py | 624 +++++++++++++++++++++---------- View/signal_processing_tab.py | 16 +- 2 files changed, 441 insertions(+), 199 deletions(-) diff --git a/View/sediment_calibration_tab.py b/View/sediment_calibration_tab.py index eba470b..6061be9 100644 --- a/View/sediment_calibration_tab.py +++ b/View/sediment_calibration_tab.py @@ -20,11 +20,15 @@ # -*- coding: utf-8 -*- +import os import matplotlib.pyplot as plt import pandas as pd -from PyQt5.QtWidgets import (QWidget, QVBoxLayout, QHBoxLayout, QGroupBox, QComboBox, - QGridLayout, QLabel, QPushButton, QSlider, QLineEdit, QFileDialog, QMessageBox, QFrame) +from PyQt5.QtWidgets import ( + QWidget, QVBoxLayout, QHBoxLayout, QGroupBox, QComboBox, + QGridLayout, QLabel, QPushButton, QSlider, QLineEdit, + QFileDialog, QMessageBox, QFrame +) from PyQt5.QtCore import Qt, QPropertyAnimation, QSize from PyQt5.QtGui import QIcon, QPixmap, QFont @@ -39,8 +43,6 @@ 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 @@ -53,40 +55,59 @@ class SedimentCalibrationTab(QWidget): 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.icon_approved = QIcon(self.path_icon + "approved.png") - self.icon_no_approved = QIcon(self.path_icon + "no_approved.png") - + self._widget_tab = widget_tab self.inv_hc = AcousticInversionMethodHighConcentration() - ### --- General layout of widgets --- + self._setup_icons() + self._setup_widgets() - self.verticalLayoutMain = QVBoxLayout(widget_tab) + def _path_icon(self, icon): + return os.path.join("icons", icon) + def _setup_icons(self): + 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.icon_approved = QIcon(self._path_icon("approved.png")) + self.icon_no_approved = QIcon(self._path_icon("no_approved.png")) + + + def _setup_widgets(self): + self.verticalLayoutMain = QVBoxLayout(self._widget_tab) + + # 1O units is 100% , 1 units is 10% self.horizontalLayoutTop = QHBoxLayout() - self.verticalLayoutMain.addLayout(self.horizontalLayoutTop, 5) # 1O units is 100% , 1 units is 10% + self.verticalLayoutMain.addLayout(self.horizontalLayoutTop, 5) 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._setup_widgets_acoustic_data() + self._setup_widgets_concentration() + self._setup_widgets_calibration() + self._setup_widgets_fcb() - self.groupbox_acoustic_data.setTitle("Step 1 : acoustic and sample data choice") + self._setup_connections() + + def _setup_widgets_acoustic_data(self): + self.groupbox_acoustic_data.setTitle( + "Step 1 : acoustic and sample data choice" + ) self.horizontalLayout_groupbox_acoustic_data = QHBoxLayout(self.groupbox_acoustic_data) @@ -96,73 +117,115 @@ class SedimentCalibrationTab(QWidget): self.groupbox_data_plot = QGroupBox() self.horizontalLayout_groupbox_acoustic_data.addWidget(self.groupbox_data_plot, 7) - # --- Groupbox data choice --- self.verticalLayout_groupbox_data_choice = QVBoxLayout(self.groupbox_data_choice) - # -------------------------------------------- + self._setup_widgets_acoustic_data_1() + self._setup_widgets_acoustic_data_2() + self._setup_widgets_acoustic_data_3() + self._setup_widgets_acoustic_data_plot() + + def _setup_widgets_acoustic_data_1(self): self.groupbox_acoustic_recording = QGroupBox() self.groupbox_acoustic_recording.setTitle("➊") - self.verticalLayout_groupbox_data_choice.addWidget(self.groupbox_acoustic_recording) + self.verticalLayout_groupbox_data_choice.addWidget( + self.groupbox_acoustic_recording + ) - self.gridLayout_groupbox_acoustic_recording = QGridLayout(self.groupbox_acoustic_recording) + self.gridLayout_groupbox_acoustic_recording = QGridLayout( + self.groupbox_acoustic_recording + ) self.pushbutton_update_acoustic_file = QPushButton() self.pushbutton_update_acoustic_file.setIcon(self.icon_update) - self.gridLayout_groupbox_acoustic_recording.addWidget(self.pushbutton_update_acoustic_file, 0, 0, 1, 2) + self.gridLayout_groupbox_acoustic_recording.addWidget( + self.pushbutton_update_acoustic_file, 0, 0, 1, 2 + ) self.label_acoustic_data_choice = QLabel() self.label_acoustic_data_choice.setText("Acoustic data") - self.gridLayout_groupbox_acoustic_recording.addWidget(self.label_acoustic_data_choice, 1, 0, 1, 1) + self.gridLayout_groupbox_acoustic_recording.addWidget( + self.label_acoustic_data_choice, 1, 0, 1, 1 + ) self.combobox_acoustic_data_choice = QComboBox() - self.gridLayout_groupbox_acoustic_recording.addWidget(self.combobox_acoustic_data_choice, 1, 1, 1, 1) + self.gridLayout_groupbox_acoustic_recording.addWidget( + self.combobox_acoustic_data_choice, 1, 1, 1, 1 + ) - # -------------------------------------------- + def _setup_widgets_acoustic_data_2(self): self.groupbox_frequency = QGroupBox() self.groupbox_frequency.setTitle("➋") - self.verticalLayout_groupbox_data_choice.addWidget(self.groupbox_frequency) + self.verticalLayout_groupbox_data_choice.addWidget( + self.groupbox_frequency + ) - self.gridLayout_groupbox_frequency = QGridLayout(self.groupbox_frequency) + self.gridLayout_groupbox_frequency = QGridLayout( + self.groupbox_frequency + ) self.label_freq1_choice = QLabel() self.label_freq1_choice.setText("Frequency 1") - self.gridLayout_groupbox_frequency.addWidget(self.label_freq1_choice, 0, 0, 1, 1) + self.gridLayout_groupbox_frequency.addWidget( + self.label_freq1_choice, 0, 0, 1, 1 + ) self.combobox_freq1 = QComboBox() - self.gridLayout_groupbox_frequency.addWidget(self.combobox_freq1, 0, 1, 1, 1) + self.gridLayout_groupbox_frequency.addWidget( + self.combobox_freq1, 0, 1, 1, 1 + ) self.label_freq2_choice = QLabel() self.label_freq2_choice.setText("Frequency 2") - self.gridLayout_groupbox_frequency.addWidget(self.label_freq2_choice, 1, 0, 1, 1) + self.gridLayout_groupbox_frequency.addWidget( + self.label_freq2_choice, 1, 0, 1, 1 + ) self.combobox_freq2 = QComboBox() - self.gridLayout_groupbox_frequency.addWidget(self.combobox_freq2, 1, 1, 1, 1) + self.gridLayout_groupbox_frequency.addWidget( + self.combobox_freq2, 1, 1, 1, 1 + ) - # -------------------------------------------- + def _setup_widgets_acoustic_data_3(self): self.groupbox_sample = QGroupBox() self.groupbox_sample.setTitle("➌") - self.verticalLayout_groupbox_data_choice.addWidget(self.groupbox_sample) + self.verticalLayout_groupbox_data_choice.addWidget( + self.groupbox_sample + ) - self.gridLayout_groupbox_sample = QGridLayout(self.groupbox_sample) + self.gridLayout_groupbox_sample = QGridLayout( + self.groupbox_sample + ) self.label_fine_profile = QLabel() self.label_fine_profile.setText("Fine profile") - self.gridLayout_groupbox_sample.addWidget(self.label_fine_profile, 0, 0, 1, 1) + self.gridLayout_groupbox_sample.addWidget( + self.label_fine_profile, 0, 0, 1, 1 + ) self.combobox_fine_sample_choice = CheckableComboBox() - self.gridLayout_groupbox_sample.addWidget(self.combobox_fine_sample_choice, 0, 1, 1, 1) + self.gridLayout_groupbox_sample.addWidget( + self.combobox_fine_sample_choice, 0, 1, 1, 1 + ) self.label_sand_target = QLabel() self.label_sand_target.setText("Sand target") - self.gridLayout_groupbox_sample.addWidget(self.label_sand_target, 1, 0, 1, 1) + self.gridLayout_groupbox_sample.addWidget( + self.label_sand_target, 1, 0, 1, 1 + ) self.combobox_sand_sample_choice = QComboBox() - self.gridLayout_groupbox_sample.addWidget(self.combobox_sand_sample_choice, 1, 1, 1, 1) + self.gridLayout_groupbox_sample.addWidget( + self.combobox_sand_sample_choice, 1, 1, 1, 1 + ) self.pushbutton_plot_sample = QPushButton() self.pushbutton_plot_sample.setText("Plot sample") - self.gridLayout_groupbox_sample.addWidget(self.pushbutton_plot_sample, 2, 0, 1, 2) + self.gridLayout_groupbox_sample.addWidget( + self.pushbutton_plot_sample, 2, 0, 1, 2 + ) - # --- Groupbox data plot --- - self.verticalLayout_groupbox_data_plot = QVBoxLayout(self.groupbox_data_plot) + def _setup_widgets_acoustic_data_plot(self): + self.verticalLayout_groupbox_data_plot = QVBoxLayout( + self.groupbox_data_plot + ) self.canvas_BS = FigureCanvas() self.toolbar_BS = NavigationToolBar(self.canvas_BS, self) @@ -171,318 +234,436 @@ class SedimentCalibrationTab(QWidget): self.verticalLayout_groupbox_data_plot.addWidget(self.toolbar_BS) self.verticalLayout_groupbox_data_plot.addWidget(self.canvas_BS) - # -------------------------------------------------------------------------------------------------------------- - # +++++++++++++++++++++++++++++++++++++++++++ - # +++ Groupbox Fine concentration profile +++ - - self.groupbox_Mfine_profile.setTitle("Step 2 : profile of the fine sediment concentration") - self.horizontalLayout_groupbox_Mfine_profile = QHBoxLayout(self.groupbox_Mfine_profile) + def _setup_widgets_concentration(self): + self.groupbox_Mfine_profile.setTitle( + "Step 2 : profile of the fine sediment concentration" + ) + self.horizontalLayout_groupbox_Mfine_profile = QHBoxLayout( + self.groupbox_Mfine_profile + ) self.groupbox_interpolate_info = QGroupBox() - self.horizontalLayout_groupbox_Mfine_profile.addWidget(self.groupbox_interpolate_info, 4) + self.horizontalLayout_groupbox_Mfine_profile.addWidget( + self.groupbox_interpolate_info, 4 + ) self.groupbox_interpolate_plot = QGroupBox() - self.horizontalLayout_groupbox_Mfine_profile.addWidget(self.groupbox_interpolate_plot, 6) + self.horizontalLayout_groupbox_Mfine_profile.addWidget( + self.groupbox_interpolate_plot, 6 + ) - # --- Groupbox interpolate info --- - self.gridLayout_groupbox_interpolate_info = QGridLayout(self.groupbox_interpolate_info) + self._setup_widgets_concentration_interpolate() + self._setup_widgets_concentration_interpolate_plot() + + def _setup_widgets_concentration_interpolate(self): + self.gridLayout_groupbox_interpolate_info = QGridLayout( + self.groupbox_interpolate_info + ) self.pushbutton_interpolate_Mfine_profile = QPushButton() self.pushbutton_interpolate_Mfine_profile.setText("Interpolate") - self.gridLayout_groupbox_interpolate_info.addWidget(self.pushbutton_interpolate_Mfine_profile, 0, 0, 1, 4, Qt.AlignCenter) + self.gridLayout_groupbox_interpolate_info.addWidget( + self.pushbutton_interpolate_Mfine_profile, 0, 0, 1, 4, + Qt.AlignCenter + ) self.label_sample_fine = QLabel() self.label_sample_fine.setText("Sample") - self.gridLayout_groupbox_interpolate_info.addWidget(self.label_sample_fine, 1, 0, 1, 1, Qt.AlignCenter) + self.gridLayout_groupbox_interpolate_info.addWidget( + self.label_sample_fine, 1, 0, 1, 1, Qt.AlignCenter + ) self.label_depth_fine = QLabel() self.label_depth_fine.setText("Depth (m)") - self.gridLayout_groupbox_interpolate_info.addWidget(self.label_depth_fine, 1, 1, 1, 1, Qt.AlignCenter) + self.gridLayout_groupbox_interpolate_info.addWidget( + self.label_depth_fine, 1, 1, 1, 1, Qt.AlignCenter + ) self.label_time_fine = QLabel() self.label_time_fine.setText("time") - self.gridLayout_groupbox_interpolate_info.addWidget(self.label_time_fine, 1, 2, 1, 1, Qt.AlignCenter) + self.gridLayout_groupbox_interpolate_info.addWidget( + self.label_time_fine, 1, 2, 1, 1, Qt.AlignCenter + ) self.label_concentration_fine = QLabel() self.label_concentration_fine.setText("Cfine (g/L)") - self.gridLayout_groupbox_interpolate_info.addWidget(self.label_concentration_fine, 1, 3, 1, 1, Qt.AlignCenter) + self.gridLayout_groupbox_interpolate_info.addWidget( + self.label_concentration_fine, 1, 3, 1, 1, Qt.AlignCenter + ) self.double_horizontal_line = QFrame() self.double_horizontal_line.setFrameShape(QFrame.HLine) self.double_horizontal_line.setFrameShadow(QFrame.Sunken) self.double_horizontal_line.setLineWidth(1) self.double_horizontal_line.setMidLineWidth(3) - self.gridLayout_groupbox_interpolate_info.addWidget(self.double_horizontal_line, 4, 0, 1, 4, Qt.AlignCenter) + self.gridLayout_groupbox_interpolate_info.addWidget( + self.double_horizontal_line, 4, 0, 1, 4, Qt.AlignCenter + ) self.label_sample_sand = QLabel() self.label_sample_sand.setText("Sample") - self.gridLayout_groupbox_interpolate_info.addWidget(self.label_sample_sand, 5, 0, 1, 1, Qt.AlignCenter) + self.gridLayout_groupbox_interpolate_info.addWidget( + self.label_sample_sand, 5, 0, 1, 1, Qt.AlignCenter + ) self.label_depth_sand = QLabel() self.label_depth_sand.setText("Depth (m)") - self.gridLayout_groupbox_interpolate_info.addWidget(self.label_depth_sand, 5, 1, 1, 1, Qt.AlignCenter) + self.gridLayout_groupbox_interpolate_info.addWidget( + self.label_depth_sand, 5, 1, 1, 1, Qt.AlignCenter + ) self.label_time_sand = QLabel() self.label_time_sand.setText("time") - self.gridLayout_groupbox_interpolate_info.addWidget(self.label_time_sand, 5, 2, 1, 1, Qt.AlignCenter) + self.gridLayout_groupbox_interpolate_info.addWidget( + self.label_time_sand, 5, 2, 1, 1, Qt.AlignCenter + ) self.label_concentration_sand = QLabel() self.label_concentration_sand.setText("Csand (g/L)") - self.gridLayout_groupbox_interpolate_info.addWidget(self.label_concentration_sand, 5, 3, 1, 1, Qt.AlignCenter) + self.gridLayout_groupbox_interpolate_info.addWidget( + self.label_concentration_sand, 5, 3, 1, 1, Qt.AlignCenter + ) - # --- Groupbox interpolate plot --- - self.verticalLayout_groupbox_interpolate_plot = QVBoxLayout(self.groupbox_interpolate_plot) + def _setup_widgets_concentration_interpolate_plot(self): + self.verticalLayout_groupbox_interpolate_plot = QVBoxLayout( + self.groupbox_interpolate_plot + ) self.canvas_Mfine = FigureCanvas() self.toolbar_Mfine = NavigationToolBar(self.canvas_Mfine, self) - self.verticalLayout_groupbox_interpolate_plot.addWidget(self.toolbar_Mfine) - self.verticalLayout_groupbox_interpolate_plot.addWidget(self.canvas_Mfine) + self.verticalLayout_groupbox_interpolate_plot\ + .addWidget(self.toolbar_Mfine) + self.verticalLayout_groupbox_interpolate_plot\ + .addWidget(self.canvas_Mfine) - # -------------------------------------------------------------------------------------------------------------- + + def _setup_widgets_calibration(self): 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) self.horizontalLayout_groupboxes_Import_Compute_Calibration = QHBoxLayout() self.verticalLayout_groupbox_sediment_calibration.addLayout(self.horizontalLayout_groupboxes_Import_Compute_Calibration) - # --- Groupbox import calibration file --- + self._setup_widgets_calibration_import_file() + self._setup_widgets_calibration_compute() + self._setup_widgets_calibration_parameters() + + def _setup_widgets_calibration_import_file(self): self.groupbox_sediment_calibration_import = QGroupBox() - self.groupbox_sediment_calibration_import.setTitle("Import sediment calibration file") + 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.horizontalLayout_groupboxes_Import_Compute_Calibration.addWidget(self.groupbox_sediment_calibration_import) + self.horizontalLayout_groupboxes_Import_Compute_Calibration.addWidget( + self.groupbox_sediment_calibration_import + ) - self.gridLayout_groupbox_sediment_calibration_import = QGridLayout(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.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) + self.gridLayout_groupbox_sediment_calibration_import.addWidget( + self.lineEdit_import_calibration, 0, 1, 1, 2 + ) - # --- Compute calibration --- + def _setup_widgets_calibration_compute(self): self.groupbox_sediment_calibration_compute = QGroupBox() - self.groupbox_sediment_calibration_compute.setTitle("Compute sediment calibration") + self.groupbox_sediment_calibration_compute.setTitle( + "Compute sediment calibration" + ) self.groupbox_sediment_calibration_compute.setCheckable(True) self.groupbox_sediment_calibration_compute.setChecked(False) - self.horizontalLayout_groupboxes_Import_Compute_Calibration.addWidget(self.groupbox_sediment_calibration_compute) + self.horizontalLayout_groupboxes_Import_Compute_Calibration\ + .addWidget(self.groupbox_sediment_calibration_compute) - self.gridLayout_groupbox_sediment_calibration_compute = QGridLayout(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.pushbutton_compute_calibration.setToolTip("Calibration is computed at abscissa 'sand target'") - self.gridLayout_groupbox_sediment_calibration_compute.addWidget(self.pushbutton_compute_calibration, 0, 0, 1, 3) + self.pushbutton_compute_calibration.setText( + "Compute Calibration" + ) + self.pushbutton_compute_calibration.setToolTip( + "Calibration is computed at abscissa 'sand target'" + ) + self.gridLayout_groupbox_sediment_calibration_compute\ + .addWidget(self.pushbutton_compute_calibration, 0, 0, 1, 3) - # --- Calibration parameter --- + + def _setup_widgets_calibration_parameters(self): self.groupbox_sediment_calibration_parameter = QGroupBox() - self.gridLayout_groupbox_sediment_calibration_parameter = QGridLayout(self.groupbox_sediment_calibration_parameter) + self.gridLayout_groupbox_sediment_calibration_parameter = \ + QGridLayout(self.groupbox_sediment_calibration_parameter) - self.verticalLayout_groupbox_sediment_calibration.addWidget(self.groupbox_sediment_calibration_parameter) + self.verticalLayout_groupbox_sediment_calibration\ + .addWidget(self.groupbox_sediment_calibration_parameter) self.label_temperature = QLabel() self.label_temperature.setText("T = 0.00 °C") - self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.label_temperature, 0, 0, 1, 1) + self.gridLayout_groupbox_sediment_calibration_parameter\ + .addWidget(self.label_temperature, 0, 0, 1, 1) self.label_freq1 = QLabel("Frequency 1") - self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.label_freq1, 1, 1, 1, 2, Qt.AlignCenter) + self.gridLayout_groupbox_sediment_calibration_parameter\ + .addWidget(self.label_freq1, 1, 1, 1, 2, Qt.AlignCenter) self.label_freq2 = QLabel("Frequency 2") - self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.label_freq2, 1, 3, 1, 2, Qt.AlignCenter) + self.gridLayout_groupbox_sediment_calibration_parameter\ + .addWidget(self.label_freq2, 1, 3, 1, 2, Qt.AlignCenter) self.label_kt = QLabel() self.label_kt.setText("kt") - self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.label_kt, 2, 0, 1, 1, Qt.AlignCenter) + self.gridLayout_groupbox_sediment_calibration_parameter\ + .addWidget(self.label_kt, 2, 0, 1, 1, Qt.AlignCenter) self.label_kt_freq1 = QLabel() self.label_kt_freq1.setText("0.00") - self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.label_kt_freq1, 2, 1, 1, 1, Qt.AlignRight) + self.gridLayout_groupbox_sediment_calibration_parameter\ + .addWidget(self.label_kt_freq1, 2, 1, 1, 1, Qt.AlignRight) self.label_kt_freq1_unit = QLabel() self.label_kt_freq1_unit.setText("V.m1.5") - self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.label_kt_freq1_unit, 2, 2, 1, 1, - Qt.AlignLeft) + self.gridLayout_groupbox_sediment_calibration_parameter\ + .addWidget(self.label_kt_freq1_unit, 2, 2, 1, 1, Qt.AlignLeft) self.label_kt_freq2 = QLabel() self.label_kt_freq2.setText("0.00") - self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.label_kt_freq2, 2, 3, 1, 1, Qt.AlignRight) + self.gridLayout_groupbox_sediment_calibration_parameter\ + .addWidget(self.label_kt_freq2, 2, 3, 1, 1, Qt.AlignRight) self.label_kt_freq2_unit = QLabel() self.label_kt_freq2_unit.setText("V.m1.5") - self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.label_kt_freq2_unit, 2, 4, 1, 1, - Qt.AlignLeft) + self.gridLayout_groupbox_sediment_calibration_parameter\ + .addWidget(self.label_kt_freq2_unit, 2, 4, 1, 1, Qt.AlignLeft) self.horizontalLine = QFrame() self.horizontalLine.setFrameShape(QFrame.HLine) self.horizontalLine.setFrameShadow(QFrame.Sunken) self.horizontalLine.setLineWidth(1) self.horizontalLine.setMidLineWidth(0) - self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.horizontalLine, 3, 0, 1, 6) + self.gridLayout_groupbox_sediment_calibration_parameter\ + .addWidget(self.horizontalLine, 3, 0, 1, 6) self.label_ks = QLabel() self.label_ks.setText("ks") - self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.label_ks, 4, 0, 1, 1, Qt.AlignCenter) + self.gridLayout_groupbox_sediment_calibration_parameter\ + .addWidget(self.label_ks, 4, 0, 1, 1, Qt.AlignCenter) self.lineEdit_ks_freq1 = QLineEdit() self.lineEdit_ks_freq1.setMaximumWidth(100) self.lineEdit_ks_freq1.setText("0.00") - self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.lineEdit_ks_freq1, 4, 1, 1, 1) + self.gridLayout_groupbox_sediment_calibration_parameter\ + .addWidget(self.lineEdit_ks_freq1, 4, 1, 1, 1) self.label_ks_freq1_unit = QLabel() self.label_ks_freq1_unit.setText("m.kg-0.5") - self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.label_ks_freq1_unit, 4, 2, 1, 1, - Qt.AlignLeft) + self.gridLayout_groupbox_sediment_calibration_parameter\ + .addWidget(self.label_ks_freq1_unit, 4, 2, 1, 1, Qt.AlignLeft) self.lineEdit_ks_freq2 = QLineEdit() self.lineEdit_ks_freq2.setMaximumWidth(100) self.lineEdit_ks_freq2.setText("0.00") - self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.lineEdit_ks_freq2, 4, 3, 1, 1) + self.gridLayout_groupbox_sediment_calibration_parameter\ + .addWidget(self.lineEdit_ks_freq2, 4, 3, 1, 1) self.label_ks_freq2_unit = QLabel() self.label_ks_freq2_unit.setText("m.kg-0.5") - self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.label_ks_freq2_unit, 4, 4, 1, 1, - Qt.AlignLeft) + self.gridLayout_groupbox_sediment_calibration_parameter\ + .addWidget(self.label_ks_freq2_unit, 4, 4, 1, 1, Qt.AlignLeft) self.label_sv = QLabel() self.label_sv.setText("sv") - self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.label_sv, 5, 0, 1, 1, Qt.AlignCenter) + self.gridLayout_groupbox_sediment_calibration_parameter\ + .addWidget(self.label_sv, 5, 0, 1, 1, Qt.AlignCenter) self.lineEdit_sv_freq1 = QLineEdit() self.lineEdit_sv_freq1.setMaximumWidth(100) self.lineEdit_sv_freq1.setText("0.00") - self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.lineEdit_sv_freq1, 5, 1, 1, 1) + self.gridLayout_groupbox_sediment_calibration_parameter\ + .addWidget(self.lineEdit_sv_freq1, 5, 1, 1, 1) self.label_sv_freq1_unit = QLabel() self.label_sv_freq1_unit.setText("m-1") - self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.label_sv_freq1_unit, 5, 2, 1, 1) + self.gridLayout_groupbox_sediment_calibration_parameter\ + .addWidget(self.label_sv_freq1_unit, 5, 2, 1, 1) self.lineEdit_sv_freq2 = QLineEdit() self.lineEdit_sv_freq2.setMaximumWidth(100) self.lineEdit_sv_freq2.setText("0.00") - self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.lineEdit_sv_freq2, 5, 3, 1, 1) + self.gridLayout_groupbox_sediment_calibration_parameter\ + .addWidget(self.lineEdit_sv_freq2, 5, 3, 1, 1) self.label_sv_freq2_unit = QLabel() self.label_sv_freq2_unit.setText("m-1") - self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.label_sv_freq2_unit, 5, 4, 1, 1) + self.gridLayout_groupbox_sediment_calibration_parameter\ + .addWidget(self.label_sv_freq2_unit, 5, 4, 1, 1) self.label_X = QLabel() self.label_X.setText("X") - self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.label_X, 6, 0, 1, 1, Qt.AlignCenter) + self.gridLayout_groupbox_sediment_calibration_parameter\ + .addWidget(self.label_X, 6, 0, 1, 1, Qt.AlignCenter) self.lineEdit_X = QLineEdit() self.lineEdit_X.setMaximumWidth(100) self.lineEdit_X.setText("0.00") - self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.lineEdit_X, 6, 2, 1, 1, Qt.AlignCenter) + self.gridLayout_groupbox_sediment_calibration_parameter\ + .addWidget(self.lineEdit_X, 6, 2, 1, 1, Qt.AlignCenter) self.label_alphas = QLabel() self.label_alphas.setText("\u03B1s") - self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.label_alphas, 7, 0, 1, 1, Qt.AlignCenter) + self.gridLayout_groupbox_sediment_calibration_parameter\ + .addWidget(self.label_alphas, 7, 0, 1, 1, Qt.AlignCenter) self.lineEdit_alphas_freq1 = QLineEdit() self.lineEdit_alphas_freq1.setMaximumWidth(100) self.lineEdit_alphas_freq1.setText("0.00") - self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.lineEdit_alphas_freq1, 7, 1, 1, 1) + self.gridLayout_groupbox_sediment_calibration_parameter\ + .addWidget(self.lineEdit_alphas_freq1, 7, 1, 1, 1) self.label_alphas_freq1_unit = QLabel() self.label_alphas_freq1_unit.setText("m-1") - self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.label_alphas_freq1_unit, 7, 2, 1, 1, Qt.AlignLeft) + self.gridLayout_groupbox_sediment_calibration_parameter\ + .addWidget(self.label_alphas_freq1_unit, 7, 2, 1, 1, Qt.AlignLeft) self.lineEdit_alphas_freq2 = QLineEdit() self.lineEdit_alphas_freq2.setMaximumWidth(100) self.lineEdit_alphas_freq2.setText("0.00") - self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.lineEdit_alphas_freq2, 7, 3, 1, 1) + self.gridLayout_groupbox_sediment_calibration_parameter\ + .addWidget(self.lineEdit_alphas_freq2, 7, 3, 1, 1) self.label_alphas_freq2_unit = QLabel() self.label_alphas_freq2_unit.setText("m-1") - self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.label_alphas_freq2_unit, 7, 4, 1, 1, Qt.AlignLeft) + self.gridLayout_groupbox_sediment_calibration_parameter\ + .addWidget(self.label_alphas_freq2_unit, 7, 4, 1, 1, Qt.AlignLeft) self.label_zeta = QLabel() self.label_zeta.setText("\u03B6") - self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.label_zeta, 8, 0, 1, 1, Qt.AlignCenter) + self.gridLayout_groupbox_sediment_calibration_parameter\ + .addWidget(self.label_zeta, 8, 0, 1, 1, Qt.AlignCenter) self.lineEdit_zeta_freq1 = QLineEdit() self.lineEdit_zeta_freq1.setMaximumWidth(100) self.lineEdit_zeta_freq1.setText("0.00") - self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.lineEdit_zeta_freq1, 8, 1, 1, 1) + self.gridLayout_groupbox_sediment_calibration_parameter\ + .addWidget(self.lineEdit_zeta_freq1, 8, 1, 1, 1) self.label_zeta_freq1_unit = QLabel() self.label_zeta_freq1_unit.setText("m-1") - self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.label_zeta_freq1_unit, 8, 2, 1, 1, - Qt.AlignLeft) + self.gridLayout_groupbox_sediment_calibration_parameter\ + .addWidget(self.label_zeta_freq1_unit, 8, 2, 1, 1, Qt.AlignLeft) self.lineEdit_zeta_freq2 = QLineEdit() self.lineEdit_zeta_freq2.setMaximumWidth(100) self.lineEdit_zeta_freq2.setText("0.00") - self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.lineEdit_zeta_freq2, 8, 3, 1, 1) + self.gridLayout_groupbox_sediment_calibration_parameter\ + .addWidget(self.lineEdit_zeta_freq2, 8, 3, 1, 1) self.label_zeta_freq2_unit = QLabel() self.label_zeta_freq2_unit.setText("m-1") - self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.label_zeta_freq2_unit, 8, 4, 1, 1, - Qt.AlignLeft) + self.gridLayout_groupbox_sediment_calibration_parameter\ + .addWidget(self.label_zeta_freq2_unit, 8, 4, 1, 1, Qt.AlignLeft) self.pushbutton_save_calibration = QPushButton() self.pushbutton_save_calibration.setText("Save calibration") - self.gridLayout_groupbox_sediment_calibration_parameter.addWidget(self.pushbutton_save_calibration,9, 5, 1, 1) + self.gridLayout_groupbox_sediment_calibration_parameter\ + .addWidget(self.pushbutton_save_calibration,9, 5, 1, 1) - # ++++++++++++++++++++ - # +++ Groupbox FCB +++ - self.groupbox_FCB.setTitle("Step 3 (for information) : Fluid Corrected Backscatter") + def _setup_widgets_fcb(self): + self.groupbox_FCB.setTitle( + "Step 3 (for information) : Fluid Corrected Backscatter" + ) self.horizontalLayout_groupbox_FCB = QHBoxLayout(self.groupbox_FCB) self.groupbox_FCB.setCheckable(True) self.groupbox_FCB.setChecked(False) - # --- Groupbox FCB option --- + self._setup_widgets_fcb_options() + self._setup_widgets_fcb_plot() + + def _setup_widgets_fcb_options(self): self.groupbox_FCB_option = QGroupBox() self.verticalLayout_groupbox_FCB_option = QVBoxLayout(self.groupbox_FCB_option) - self.horizontalLayout_groupbox_FCB.addWidget(self.groupbox_FCB_option, 4) + self.horizontalLayout_groupbox_FCB\ + .addWidget(self.groupbox_FCB_option, 4) self.groupbox_FCB_text = QGroupBox() self.verticalLayout_groupbox_FCB_text = QVBoxLayout(self.groupbox_FCB_text) - self.verticalLayout_groupbox_FCB_option.addWidget(self.groupbox_FCB_text) + self.verticalLayout_groupbox_FCB_option\ + .addWidget(self.groupbox_FCB_text) self.label_FCB_explanation = QLabel() - self.label_FCB_explanation.setText("When fine sediments concentration is constant \n " - "and effect on sound attenuation on sand is negligible, \n " - "this sediment attenuation alphas can be compared \n " - "to the obtained by the sediment calibration computation.") - self.verticalLayout_groupbox_FCB_text.addWidget(self.label_FCB_explanation) + self.label_FCB_explanation.setText( + "When fine sediments concentration is constant \n " + "and effect on sound attenuation on sand is negligible, \n " + "this sediment attenuation alphas can be compared \n " + "to the obtained by the sediment calibration computation." + ) + self.verticalLayout_groupbox_FCB_text\ + .addWidget(self.label_FCB_explanation) self.gridLayout_groupbox_FCB_text_alphas = QGridLayout() - self.verticalLayout_groupbox_FCB_text.addLayout(self.gridLayout_groupbox_FCB_text_alphas) + self.verticalLayout_groupbox_FCB_text\ + .addLayout(self.gridLayout_groupbox_FCB_text_alphas) self.label_FCB_explanation_alphas_positive_icon = QLabel() self.label_FCB_explanation_alphas_positive_icon.setPixmap( - QPixmap(self.path_icon + "approved.png").scaledToHeight(16, Qt.SmoothTransformation)) + QPixmap(self._path_icon("approved.png")).scaledToHeight( + 16, Qt.SmoothTransformation + ) + ) self.gridLayout_groupbox_FCB_text_alphas.addWidget( - self.label_FCB_explanation_alphas_positive_icon, 0, 0, 1, 1, Qt.AlignCenter) + self.label_FCB_explanation_alphas_positive_icon, + 0, 0, 1, 1, Qt.AlignCenter + ) self.label_FCB_explanation_alphas_positive = QLabel() - self.label_FCB_explanation_alphas_positive.setText("αs FCB > 0 : comparison with calibration") + self.label_FCB_explanation_alphas_positive.setText( + "αs FCB > 0 : comparison with calibration" + ) self.label_FCB_explanation_alphas_positive.setFont(QFont('Ubuntu', 12)) - self.gridLayout_groupbox_FCB_text_alphas.addWidget(self.label_FCB_explanation_alphas_positive, 0, 1, 1, 1, Qt.AlignLeft) + self.gridLayout_groupbox_FCB_text_alphas.addWidget( + self.label_FCB_explanation_alphas_positive, + 0, 1, 1, 1, Qt.AlignLeft + ) self.label_FCB_explanation_alphas_negative_icon = QLabel() - self.label_FCB_explanation_alphas_negative_icon.setPixmap(QPixmap(self.path_icon + "no_approved.png").scaledToHeight(16, Qt.SmoothTransformation)) - self.gridLayout_groupbox_FCB_text_alphas.addWidget(self.label_FCB_explanation_alphas_negative_icon, 1, 0, 1, 1, Qt.AlignCenter) + self.label_FCB_explanation_alphas_negative_icon.setPixmap( + QPixmap(self._path_icon("no_approved.png")).scaledToHeight( + 16, Qt.SmoothTransformation + ) + ) + self.gridLayout_groupbox_FCB_text_alphas.addWidget( + self.label_FCB_explanation_alphas_negative_icon, + 1, 0, 1, 1, Qt.AlignCenter + ) self.label_FCB_explanation_alphas_negative = QLabel() - self.label_FCB_explanation_alphas_negative.setText("αs FCB < 0 : do not compare with calibration") + self.label_FCB_explanation_alphas_negative.setText( + "αs FCB < 0 : do not compare with calibration" + ) self.label_FCB_explanation_alphas_negative.setFont(QFont('Ubuntu', 12)) - self.gridLayout_groupbox_FCB_text_alphas.addWidget(self.label_FCB_explanation_alphas_negative, 1, 1, 1, 1, Qt.AlignLeft) + self.gridLayout_groupbox_FCB_text_alphas.addWidget( + self.label_FCB_explanation_alphas_negative, + 1, 1, 1, 1, Qt.AlignLeft + ) self.groupbox_FCB_compute = QGroupBox() self.gridLayout_groupbox_FCB_compute = QGridLayout(self.groupbox_FCB_compute) @@ -490,51 +671,77 @@ class SedimentCalibrationTab(QWidget): self.label_frequency_FCB = QLabel() self.label_frequency_FCB.setText("Frequency ") - self.gridLayout_groupbox_FCB_compute.addWidget(self.label_frequency_FCB, 0, 0, 1, 3, Qt.AlignCenter) + self.gridLayout_groupbox_FCB_compute.addWidget( + self.label_frequency_FCB, 0, 0, 1, 3, Qt.AlignCenter + ) self.combobox_frequency_FCB = QComboBox() - self.gridLayout_groupbox_FCB_compute.addWidget(self.combobox_frequency_FCB, 0, 3, 1, 3, Qt.AlignCenter) + self.gridLayout_groupbox_FCB_compute.addWidget( + self.combobox_frequency_FCB, 0, 3, 1, 3, Qt.AlignCenter + ) self.label_from = QLabel() self.label_from.setText("From ") - self.gridLayout_groupbox_FCB_compute.addWidget(self.label_from, 1, 0, 1, 1, Qt.AlignCenter) + self.gridLayout_groupbox_FCB_compute.addWidget( + self.label_from, 1, 0, 1, 1, Qt.AlignCenter + ) self.lineEdit_FCB_from = QLineEdit() self.lineEdit_FCB_from.setMaximumWidth(100) - self.gridLayout_groupbox_FCB_compute.addWidget(self.lineEdit_FCB_from, 1, 1, 1, 1, Qt.AlignCenter) + self.gridLayout_groupbox_FCB_compute.addWidget( + self.lineEdit_FCB_from, 1, 1, 1, 1, Qt.AlignCenter + ) self.label_FCB_from_unit = QLabel() self.label_FCB_from_unit.setText("m") - self.gridLayout_groupbox_FCB_compute.addWidget(self.label_FCB_from_unit, 1, 2, 1, 1, Qt.AlignLeft) + self.gridLayout_groupbox_FCB_compute.addWidget( + self.label_FCB_from_unit, 1, 2, 1, 1, Qt.AlignLeft + ) self.label_to = QLabel() self.label_to.setText("to ") - self.gridLayout_groupbox_FCB_compute.addWidget(self.label_to, 1, 3, 1, 1, Qt.AlignCenter) + self.gridLayout_groupbox_FCB_compute.addWidget( + self.label_to, 1, 3, 1, 1, Qt.AlignCenter + ) self.lineEdit_FCB_to = QLineEdit() self.lineEdit_FCB_to.setMaximumWidth(100) - self.gridLayout_groupbox_FCB_compute.addWidget(self.lineEdit_FCB_to, 1, 4, 1, 1, Qt.AlignCenter) + self.gridLayout_groupbox_FCB_compute.addWidget( + self.lineEdit_FCB_to, 1, 4, 1, 1, Qt.AlignCenter + ) self.label_FCB_to_unit = QLabel() self.label_FCB_to_unit.setText("m") - self.gridLayout_groupbox_FCB_compute.addWidget(self.label_FCB_to_unit, 1, 5, 1, 1, Qt.AlignLeft) + self.gridLayout_groupbox_FCB_compute.addWidget( + self.label_FCB_to_unit, 1, 5, 1, 1, Qt.AlignLeft + ) self.pushbutton_FCB_fit = QPushButton() self.pushbutton_FCB_fit.setText("Compute and Plot Linear regression") - self.gridLayout_groupbox_FCB_compute.addWidget(self.pushbutton_FCB_fit, 2, 0, 1, 3, Qt.AlignCenter) + self.gridLayout_groupbox_FCB_compute.addWidget( + self.pushbutton_FCB_fit, 2, 0, 1, 3, Qt.AlignCenter + ) self.label_alphaS_FCB = QLabel() - self.label_alphaS_FCB.setText("αs = " + "0.0" + "dB/m") + self.label_alphaS_FCB.setText( + "αs = " + "0.0" + "dB/m" + ) self.label_alphaS_FCB.setFont(QFont("Ubuntu", 14, QFont.Normal)) - self.gridLayout_groupbox_FCB_compute.addWidget(self.label_alphaS_FCB, 2, 4, 1, 2) + self.gridLayout_groupbox_FCB_compute.addWidget( + self.label_alphaS_FCB, 2, 4, 1, 2 + ) - # --- Groupbox FCB plot --- + + def _setup_widgets_fcb_plot(self): self.verticalLayout_groupbox_FCB_plot_and_slider_FCB = QVBoxLayout() - self.horizontalLayout_groupbox_FCB.addLayout(self.verticalLayout_groupbox_FCB_plot_and_slider_FCB, 8) + 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.verticalLayout_groupbox_FCB_plot_and_slider_FCB\ + .addWidget(self.groupbox_FCB_plot) self.canvas_FCB = FigureCanvas() self.toolbar_FCB = NavigationToolBar(self.canvas_FCB, self) @@ -543,11 +750,16 @@ class SedimentCalibrationTab(QWidget): 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.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_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) @@ -563,8 +775,12 @@ class SedimentCalibrationTab(QWidget): 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.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) @@ -576,37 +792,58 @@ class SedimentCalibrationTab(QWidget): 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) + def _setup_connections(self): + 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_plot_sample\ + .clicked.connect( + self.function_pushbutton_plot_sample + ) - self.pushbutton_interpolate_Mfine_profile.clicked.connect(self.interpolate_Mfine_profile) + 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.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.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.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_compute_calibration\ + .clicked.connect(self.function_pushbutton_compute_calibration) - self.pushbutton_save_calibration.clicked.connect(self.save_calibration) + self.pushbutton_save_calibration\ + .clicked.connect(self.save_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_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) + self.pushbutton_FCB_fit\ + .clicked.connect( + self.fit_FCB_profile_with_linear_regression_and_compute_alphaS + ) # ============================================================================================================== # ----------------------------------- Functions for Signal processing Tab -------------------------------------- @@ -1424,8 +1661,8 @@ class SedimentCalibrationTab(QWidget): "Calibration file (*.xls, *.ods, *csv)", options=QFileDialog.DontUseNativeDialog) - dir_name = path.dirname(filename[0]) - name = path.basename(filename[0]) + dir_name = os.path.dirname(filename[0]) + name = os.path.basename(filename[0]) stg.path_calibration_file = dir_name stg.filename_calibration_file = name @@ -1465,7 +1702,7 @@ class SedimentCalibrationTab(QWidget): msgBox = QMessageBox() msgBox.setWindowTitle("Calibration import error") msgBox.setIconPixmap( - QPixmap(self.path_icon + "no_approved.png").scaledToHeight(32, Qt.SmoothTransformation)) + QPixmap(self._path_icon("no_approved.png")).scaledToHeight(32, Qt.SmoothTransformation)) msgBox.setText("Update data before importing calibration") msgBox.setStandardButtons(QMessageBox.Ok) msgBox.exec() @@ -1956,7 +2193,7 @@ class SedimentCalibrationTab(QWidget): msgBox = QMessageBox() msgBox.setWindowTitle("Alpha computation error") - msgBox.setIconPixmap(QPixmap(self.path_icon + "no_approved.png").scaledToHeight(32, Qt.SmoothTransformation)) + msgBox.setIconPixmap(QPixmap(self._path_icon("no_approved.png")).scaledToHeight(32, Qt.SmoothTransformation)) msgBox.setText("Sediment sound attenuation is negative !") msgBox.setStandardButtons(QMessageBox.Ok) msgBox.exec() @@ -1965,7 +2202,7 @@ class SedimentCalibrationTab(QWidget): msgBox = QMessageBox() msgBox.setWindowTitle("Alpha computation validation") - msgBox.setIconPixmap(QPixmap(self.path_icon + "approved.png").scaledToHeight(32, Qt.SmoothTransformation)) + msgBox.setIconPixmap(QPixmap(self._path_icon("approved.png")).scaledToHeight(32, Qt.SmoothTransformation)) msgBox.setText("Sediment sound attenuation is positive.") msgBox.setStandardButtons(QMessageBox.Ok) msgBox.exec() @@ -2027,7 +2264,7 @@ class SedimentCalibrationTab(QWidget): if dir_save_cal: - stg.path_calibration_file = path.dirname(dir_save_cal) + stg.path_calibration_file = os.path.dirname(dir_save_cal) cal_array = [[' ', stg.freq_text[self.combobox_acoustic_data_choice.currentIndex()][stg.frequencies_for_calibration[0][1]], stg.freq_text[self.combobox_acoustic_data_choice.currentIndex()][stg.frequencies_for_calibration[1][1]]], @@ -2466,4 +2703,3 @@ class SedimentCalibrationTab(QWidget): self.lineEdit_slider_FCB.setText( str(stg.time[self.combobox_acoustic_data_choice.currentIndex()][ self.combobox_frequency_FCB.currentIndex(), self.slider_FCB.value()-1])) - diff --git a/View/signal_processing_tab.py b/View/signal_processing_tab.py index b9f9cee..3d2b2df 100644 --- a/View/signal_processing_tab.py +++ b/View/signal_processing_tab.py @@ -14,19 +14,25 @@ # # # You should have received a copy of the GNU General Public License # # along with this program. If not, see . # -from cProfile import label # by Brahim MOUDJED # # ============================================================================== # # -*- coding: utf-8 -*- +from cProfile import label -from PyQt5.QtWidgets import (QWidget, QHBoxLayout, QVBoxLayout, QPushButton, QGroupBox, QLabel, - QSpinBox, QComboBox, QLineEdit, QSlider, QGridLayout, QMessageBox, - QScrollArea, QFileDialog, QSpacerItem, QSizePolicy) +from PyQt5.QtWidgets import ( + QWidget, QHBoxLayout, QVBoxLayout, QPushButton, QGroupBox, + QLabel, QSpinBox, QComboBox, QLineEdit, QSlider, + QGridLayout, QMessageBox, QScrollArea, QFileDialog, + QSpacerItem, QSizePolicy +) from PyQt5.QtGui import QIcon -from PyQt5.QtCore import Qt, QCoreApplication, QEvent, pyqtSignal, QPropertyAnimation, QSize +from PyQt5.QtCore import ( + Qt, QCoreApplication, QEvent, pyqtSignal, QPropertyAnimation, + QSize +) import numpy as np from copy import deepcopy From 8f7e6795988f6209da5caec91054025fb6534c9e Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby Date: Mon, 10 Mar 2025 14:23:11 +0100 Subject: [PATCH 02/11] Sediment calibration: Refactoring method 'interpolate_Mfine_profile'. --- View/sediment_calibration_tab.py | 147 +++++++++++++------------------ 1 file changed, 61 insertions(+), 86 deletions(-) diff --git a/View/sediment_calibration_tab.py b/View/sediment_calibration_tab.py index 6061be9..970241c 100644 --- a/View/sediment_calibration_tab.py +++ b/View/sediment_calibration_tab.py @@ -21,9 +21,18 @@ # -*- coding: utf-8 -*- import os +import logging + +from scipy.stats import linregress + +import numpy as np +import pandas as pd import matplotlib.pyplot as plt -import pandas as pd +from matplotlib.colors import LogNorm +from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas +from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolBar + from PyQt5.QtWidgets import ( QWidget, QVBoxLayout, QHBoxLayout, QGroupBox, QComboBox, QGridLayout, QLabel, QPushButton, QSlider, QLineEdit, @@ -35,18 +44,10 @@ from PyQt5.QtGui import 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 View.checkable_combobox import CheckableComboBox - from Model.acoustic_inversion_method_high_concentration import AcousticInversionMethodHighConcentration +logger = logging.getLogger() class SedimentCalibrationTab(QWidget): @@ -861,7 +862,6 @@ class SedimentCalibrationTab(QWidget): self.compute_FCB() def update_acoustic_data(self): - self.combobox_acoustic_data_choice.clear() self.combobox_acoustic_data_choice.addItems(stg.data_preprocessed) self.combobox_acoustic_data_choice.currentIndexChanged.connect(self.plot_acoustic_recording) @@ -1510,89 +1510,64 @@ class SedimentCalibrationTab(QWidget): marker="*", mfc="b", mec="b", ms=8, ls="None") def interpolate_Mfine_profile(self): + data_choice = self.combobox_acoustic_data_choice.currentIndex() - 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]]) - - if stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,): - - 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] - ] - ) - ) + if stg.depth_cross_section[data_choice].shape != (0,): + range_cells = stg.depth_cross_section[data_choice][ + self.combobox_freq2.currentIndex(), : + ] + if stg.time_cross_section[data_choice].shape != (0,): + time_data = stg.time_cross_section 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_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[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[self.combobox_acoustic_data_choice.currentIndex()][self.combobox_freq2.currentIndex(), :] - - stg.time_fine[stg.fine_sample_profile[-1][1]])) )[0][0] - ] - ) - ) + time_data = stg.time else: + range_cells=stg.depth[data_choice][ + self.combobox_freq2.currentIndex(), : + ] - if stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,): - - 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()] - [ - 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] - ] - )) - + if stg.time_cross_section[data_choice].shape != (0,): + time_data = stg.time_cross_sectino else: + time_data = stg.time - 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()] - [ - np.where(np.abs(stg.time[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[self.combobox_acoustic_data_choice.currentIndex()][ - self.combobox_freq2.currentIndex(), :] - - stg.time_fine[stg.fine_sample_profile[-1][1]])))[0][0] - ] - )) + 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] + + r_bottom = stg.depth_bottom[data_choice][ + np.where( + np.abs( + time_data[data_choice][ + self.combobox_freq2.currentIndex(), : + ] + - stg.time_fine[stg.fine_sample_profile[-1][1]] + ) == np.nanmin( + np.abs( + time_data[data_choice][ + self.combobox_freq2.currentIndex(), : + ] + - stg.time_fine[stg.fine_sample_profile[-1][1]]) + ) + )[0][0] + ] + + logger.debug( + "call 'inv_hc.M_profile_SCC_fine_interpolated' params:" + ) + logger.debug(f"sample_depth = {sample_depth}") + logger.debug(f"M_profile = {M_profile}") + logger.debug(f"range_cells = {range_cells}") + logger.debug(f"r_bottom = {r_bottom}") + + stg.range_lin_interp, stg.M_profile_fine = ( + self.inv_hc.M_profile_SCC_fine_interpolated( + sample_depth=sample_depth, + M_profile=M_profile, + range_cells=range_cells, + r_bottom=r_bottom + ) + ) stg.range_lin_interp = stg.range_lin_interp stg.M_profile_fine = stg.M_profile_fine From 5eb78b812ddf39ad85769f09907a5ddf73f669f3 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby Date: Mon, 10 Mar 2025 14:43:08 +0100 Subject: [PATCH 03/11] Fix interpolate button action without correct data. --- View/sediment_calibration_tab.py | 60 ++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 11 deletions(-) diff --git a/View/sediment_calibration_tab.py b/View/sediment_calibration_tab.py index 970241c..fd5a9a0 100644 --- a/View/sediment_calibration_tab.py +++ b/View/sediment_calibration_tab.py @@ -1509,13 +1509,35 @@ class SedimentCalibrationTab(QWidget): self.ax_Mfine.plot(stg.M_profile_fine, -stg.range_lin_interp, marker="*", mfc="b", mec="b", ms=8, ls="None") + def interpolate_data_validity_message_box(self): + msgBox = QMessageBox() + msgBox.setWindowTitle("Interpolate (step 2)") + msgBox.setIconPixmap( + QPixmap( + self._path_icon("no_approved.png") + ) + .scaledToHeight(32, Qt.SmoothTransformation) + ) + msgBox.setText( + "Please select and valid the sample data with" + + "click on 'sample plot' button" + ) + msgBox.setStandardButtons(QMessageBox.Ok) + msgBox.exec() + + def interpolate_Mfine_profile(self): - data_choice = self.combobox_acoustic_data_choice.currentIndex() + # Variable 'stg.sand_sample_target_indice' is set only at + # 'plot sample' button click + if len(stg.sand_sample_target_indice) == 0: + self.interpolate_data_validity_message_box() + return + + data_choice = self.combobox_acoustic_data_choice\ + .currentIndex() if stg.depth_cross_section[data_choice].shape != (0,): - range_cells = stg.depth_cross_section[data_choice][ - self.combobox_freq2.currentIndex(), : - ] + depth_data = stg.depth_cross_section if stg.time_cross_section[data_choice].shape != (0,): time_data = stg.time_cross_section @@ -1523,17 +1545,31 @@ class SedimentCalibrationTab(QWidget): time_data = stg.time else: - range_cells=stg.depth[data_choice][ - self.combobox_freq2.currentIndex(), : - ] + depth_data = stg.depth if stg.time_cross_section[data_choice].shape != (0,): time_data = stg.time_cross_sectino else: time_data = stg.time - 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] + self.interpolate_Mfine_profile_compute( + data_choice, depth_data, time_data + ) + + def interpolate_Mfine_profile_compute(self, data_choice, depth_data, time_data): + range_cells=depth_data[data_choice][ + self.combobox_freq2.currentIndex(), : + ] + + 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 + ] r_bottom = stg.depth_bottom[data_choice][ np.where( @@ -1546,7 +1582,7 @@ class SedimentCalibrationTab(QWidget): np.abs( time_data[data_choice][ self.combobox_freq2.currentIndex(), : - ] + ] - stg.time_fine[stg.fine_sample_profile[-1][1]]) ) )[0][0] @@ -1571,7 +1607,9 @@ class SedimentCalibrationTab(QWidget): stg.range_lin_interp = stg.range_lin_interp stg.M_profile_fine = stg.M_profile_fine - stg.M_profile_fine = stg.M_profile_fine[:stg.range_lin_interp.shape[0]] + stg.M_profile_fine = stg.M_profile_fine[ + :stg.range_lin_interp.shape[0] + ] self.plot_profile_of_concentration_fine() From 86b9f85ec61de3385b44ee1740bbe0a9048eb167 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby Date: Mon, 10 Mar 2025 15:14:09 +0100 Subject: [PATCH 04/11] Sediment calibration: Skip somme crash and refactoring. --- View/sediment_calibration_tab.py | 147 ++++++++++++++++++++----------- 1 file changed, 96 insertions(+), 51 deletions(-) diff --git a/View/sediment_calibration_tab.py b/View/sediment_calibration_tab.py index fd5a9a0..f19d770 100644 --- a/View/sediment_calibration_tab.py +++ b/View/sediment_calibration_tab.py @@ -851,37 +851,50 @@ class SedimentCalibrationTab(QWidget): # ============================================================================================================== def function_pushbutton_update_acoustic_file(self): + if len(stg.data_preprocessed) == 0: + return + + if (len(stg.sample_fine) == 0 or len(stg.sample_sand) == 0): + return + self.update_acoustic_data() # self.compute_depth_2D() - def function_pushbutton_plot_sample(self): - self.sample_choice_for_calibration() - self.plot_acoustic_recording() - self.summary_samples_choices() - 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.data_preprocessed) - self.combobox_acoustic_data_choice.currentIndexChanged.connect(self.plot_acoustic_recording) + 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_freq1.currentIndexChanged.connect(self.update_label_freq1_for_calibration) - self.combobox_freq1.currentIndexChanged.connect(self.update_label_kt_value_for_calibration) + self.combobox_freq1.addItems( + stg.freq_text[self.combobox_acoustic_data_choice.currentIndex()] + ) + self.combobox_freq1.currentIndexChanged\ + .connect(self.update_label_freq1_for_calibration) + self.combobox_freq1.currentIndexChanged\ + .connect(self.update_label_kt_value_for_calibration) self.combobox_freq2.clear() - self.combobox_freq2.addItems(stg.freq_text[self.combobox_acoustic_data_choice.currentIndex()]) - self.combobox_freq2.currentIndexChanged.connect(self.update_label_freq2_for_calibration) - self.combobox_freq2.currentIndexChanged.connect(self.update_label_kt_value_for_calibration) - self.combobox_freq2.currentIndexChanged.connect(self.plot_acoustic_recording) + self.combobox_freq2.addItems( + stg.freq_text[self.combobox_acoustic_data_choice.currentIndex()] + ) + self.combobox_freq2.currentIndexChanged\ + .connect(self.update_label_freq2_for_calibration) + self.combobox_freq2.currentIndexChanged\ + .connect(self.update_label_kt_value_for_calibration) + 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_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.combobox_sand_sample_choice.addItems( + [s[0] for s in stg.sample_sand] + ) self.plot_acoustic_recording() @@ -892,39 +905,72 @@ class SedimentCalibrationTab(QWidget): self.update_label_freq2_for_calibration() self.update_label_kt_value_for_calibration() - def plot_acoustic_recording(self): + def function_pushbutton_plot_sample(self): + if (self.combobox_acoustic_data_choice.currentIndex() == -1): + return + self.sample_choice_for_calibration() + self.plot_acoustic_recording() + self.summary_samples_choices() + self.plot_profile_of_concentration_fine() + self.compute_FCB() + + def plot_acoustic_recording(self): # --- Record frequencies for calibration --- stg.frequencies_for_calibration.clear() - stg.frequencies_for_calibration.append((stg.freq[self.combobox_acoustic_data_choice.currentIndex()][ - self.combobox_freq1.currentIndex()], - self.combobox_freq1.currentIndex())) - stg.frequencies_for_calibration.append((stg.freq[self.combobox_acoustic_data_choice.currentIndex()][ - self.combobox_freq2.currentIndex()], - self.combobox_freq2.currentIndex())) + stg.frequencies_for_calibration.append( + ( + stg.freq[self.combobox_acoustic_data_choice.currentIndex()][ + self.combobox_freq1.currentIndex() + ], + self.combobox_freq1.currentIndex() + ) + ) + stg.frequencies_for_calibration.append( + ( + stg.freq[self.combobox_acoustic_data_choice.currentIndex()][ + self.combobox_freq2.currentIndex() + ], + self.combobox_freq2.currentIndex() + ) + ) stg.frequency_for_inversion = tuple() - stg.frequency_for_inversion = (stg.freq[self.combobox_acoustic_data_choice.currentIndex()][ - self.combobox_freq2.currentIndex()], - self.combobox_freq2.currentIndex()) + stg.frequency_for_inversion = ( + stg.freq[self.combobox_acoustic_data_choice.currentIndex()][ + self.combobox_freq2.currentIndex() + ], + self.combobox_freq2.currentIndex() + ) # --- Plot acoustic data recording --- self.verticalLayout_groupbox_data_plot.removeWidget(self.toolbar_BS) self.verticalLayout_groupbox_data_plot.removeWidget(self.canvas_BS) - self.fig_BS, self.axis_BS = plt.subplots(nrows=1, ncols=1, sharex=True, sharey=False, layout='constrained') + 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.toolbar_BS = NavigationToolBar(self.canvas_BS, self) self.verticalLayout_groupbox_data_plot.addWidget(self.toolbar_BS) self.verticalLayout_groupbox_data_plot.addWidget(self.canvas_BS) - if stg.BS_stream_bed_pre_process_average[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,): - + 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(), :, :]) + 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(), :, :]) + 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 @@ -1509,23 +1555,6 @@ class SedimentCalibrationTab(QWidget): self.ax_Mfine.plot(stg.M_profile_fine, -stg.range_lin_interp, marker="*", mfc="b", mec="b", ms=8, ls="None") - def interpolate_data_validity_message_box(self): - msgBox = QMessageBox() - msgBox.setWindowTitle("Interpolate (step 2)") - msgBox.setIconPixmap( - QPixmap( - self._path_icon("no_approved.png") - ) - .scaledToHeight(32, Qt.SmoothTransformation) - ) - msgBox.setText( - "Please select and valid the sample data with" - + "click on 'sample plot' button" - ) - msgBox.setStandardButtons(QMessageBox.Ok) - msgBox.exec() - - def interpolate_Mfine_profile(self): # Variable 'stg.sand_sample_target_indice' is set only at # 'plot sample' button click @@ -1613,6 +1642,22 @@ class SedimentCalibrationTab(QWidget): self.plot_profile_of_concentration_fine() + def interpolate_data_validity_message_box(self): + msgBox = QMessageBox() + msgBox.setWindowTitle("Interpolate (step 2)") + msgBox.setIconPixmap( + QPixmap( + self._path_icon("no_approved.png") + ) + .scaledToHeight(32, Qt.SmoothTransformation) + ) + msgBox.setText( + "Please select and valid the sample data with" + + "click on 'sample plot' button" + ) + msgBox.setStandardButtons(QMessageBox.Ok) + msgBox.exec() + # ------------------------------------------------------------------ # --------------- Functions for sediment calibration --------------- # ------------------------------------------------------------------ From 0ce60afd0409a9e26ccb67c7c9709334586fc87c Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby Date: Mon, 10 Mar 2025 15:17:19 +0100 Subject: [PATCH 05/11] Sediment calibration: Skip crash compute button without data. --- View/sediment_calibration_tab.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/View/sediment_calibration_tab.py b/View/sediment_calibration_tab.py index f19d770..bb400c3 100644 --- a/View/sediment_calibration_tab.py +++ b/View/sediment_calibration_tab.py @@ -1559,7 +1559,7 @@ class SedimentCalibrationTab(QWidget): # Variable 'stg.sand_sample_target_indice' is set only at # 'plot sample' button click if len(stg.sand_sample_target_indice) == 0: - self.interpolate_data_validity_message_box() + self._data_validity_message_box() return data_choice = self.combobox_acoustic_data_choice\ @@ -1642,7 +1642,7 @@ class SedimentCalibrationTab(QWidget): self.plot_profile_of_concentration_fine() - def interpolate_data_validity_message_box(self): + def _data_validity_message_box(self): msgBox = QMessageBox() msgBox.setWindowTitle("Interpolate (step 2)") msgBox.setIconPixmap( @@ -1911,6 +1911,9 @@ class SedimentCalibrationTab(QWidget): axis=1)) def function_pushbutton_compute_calibration(self): + if len(stg.sand_sample_target_indice) == 0: + self._data_validity_message_box() + return self.label_temperature.clear() self.label_temperature.setText("T = " + str(stg.temperature) + " °C") From b7ae9dfe692256eb59b4770c52f871604abdb846 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby Date: Mon, 10 Mar 2025 15:47:40 +0100 Subject: [PATCH 06/11] Sediment calibration: Some refactoring and fix #6. --- View/sediment_calibration_tab.py | 128 +++++++++++++------------------ 1 file changed, 53 insertions(+), 75 deletions(-) diff --git a/View/sediment_calibration_tab.py b/View/sediment_calibration_tab.py index bb400c3..6aa9227 100644 --- a/View/sediment_calibration_tab.py +++ b/View/sediment_calibration_tab.py @@ -1928,28 +1928,42 @@ class SedimentCalibrationTab(QWidget): self.compute_zeta() def compute_ks(self): - - # --- 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)) + 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) + 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 + ) - 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) + 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 + ) 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") + logger.debug( + "ks for frequency of " + + f"{stg.freq[self.combobox_acoustic_data_choice.currentIndex()][self.combobox_freq1.currentIndex()]} : " + + f"{ks_freq1} m/kg^0.5 \n" + ) + logger.debug( + "ks for frequency of " + + f"{stg.freq[self.combobox_acoustic_data_choice.currentIndex()][self.combobox_freq2.currentIndex()]} : " + + f"{ks_freq2} m/kg^0.5" + ) self.lineEdit_ks_freq1.clear() self.lineEdit_ks_freq1.setText(str("%.5f" % ks_freq1)) @@ -1958,8 +1972,6 @@ class SedimentCalibrationTab(QWidget): self.lineEdit_ks_freq2.setText(str("%.5f" % ks_freq2)) def compute_sv(self): - - # --- Compute sv --- sv_freq1 = self.inv_hc.sv(ks=stg.ks[0], M_sand=stg.Ctot_sand[stg.sand_sample_target[0][1]]) sv_freq2 = self.inv_hc.sv(ks=stg.ks[1], M_sand=stg.Ctot_sand[stg.sand_sample_target[0][1]]) @@ -1975,8 +1987,6 @@ class SedimentCalibrationTab(QWidget): self.lineEdit_sv_freq2.setText(str("%.5f" % sv_freq2)) def compute_X(self): - - # --- 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=stg.sv[0], sv_freq2=stg.sv[1]) @@ -1989,71 +1999,39 @@ class SedimentCalibrationTab(QWidget): self.lineEdit_X.setText(str("%.2f" % X_exponent)) def compute_kt2D_kt3D(self): - - # --- Compute kt2D, kt3D and depth_2D --- - for i in range(self.combobox_acoustic_data_choice.count()): - if stg.depth_cross_section[i].shape != (0,): - - if stg.time_cross_section[i].shape != (0,): - - if stg.kt_corrected != stg.kt_read: - - stg.kt2D[i] = np.repeat(np.array([stg.kt_corrected]).transpose(), - stg.time_cross_section[i].shape[1], axis=1) - stg.kt3D[i] = np.repeat(stg.kt2D[i][:, np.newaxis, :], stg.depth_cross_section[i].shape[1], axis=1) - - else: - - stg.kt2D[i] = np.repeat(np.array([stg.kt_read]).transpose(), - stg.time_cross_section[i].shape[1], axis=1) - stg.kt3D[i] = np.repeat(stg.kt2D[i][:, np.newaxis, :], stg.depth_cross_section[i].shape[1], axis=1) - - elif stg.time[i].shape != (0,): - - if (stg.kt_corrected != stg.kt_read): - - stg.kt2D[i] = np.repeat(np.array([stg.kt_corrected]).transpose(), stg.time[i].shape[1], axis=1) - stg.kt3D[i] = np.repeat(stg.kt2D[i][:, np.newaxis, :], stg.depth_cross_section[i].shape[1], axis=1) - - else: - - stg.kt2D[i] = np.repeat(np.array([stg.kt_read]).transpose(), stg.time[i].shape[1], axis=1) - stg.kt3D[i] = np.repeat(stg.kt2D[i][:, np.newaxis, :], stg.depth_cross_section[i].shape[1], axis=1) - + depth_data = stg.depth_cross_section elif stg.depth[i].shape != (0,): + depth_data = stg.depth + else: + continue - if stg.time_cross_section[i].shape != (0,): + if stg.time_cross_section[i].shape != (0,): + time_data = stg.time_cross_section + elif stg.time[i].shape != (0,): + time_data = stg.time + else: + continue - if (stg.kt_corrected != stg.kt_read): + if stg.kt_corrected != stg.kt_read: + kt_data = stg.kt_corrected + else: + kt_data = stg.kt_read - stg.kt2D[i] = np.repeat(np.array([stg.kt_corrected]).transpose(), - stg.time_cross_section[i].shape[1], axis=1) - stg.kt3D[i] = np.repeat(stg.kt2D[i][:, np.newaxis, :], stg.depth[i].shape[1], axis=1) + stg.kt2D[i] = np.repeat( + np.array([kt_data]).transpose(), + time_data[i].shape[1], + axis=1 + ) - else: - - stg.kt2D[i] = np.repeat(np.array([stg.kt_read]).transpose(), - stg.time_cross_section[i].shape[1], axis=1) - stg.kt3D[i] = np.repeat(stg.kt2D[i][:, np.newaxis, :], stg.depth[i].shape[1], axis=1) - - elif stg.time[i].shape != (0,): - - if (stg.kt_corrected != stg.kt_read): - - stg.kt2D[i] = np.repeat(np.array([stg.kt_corrected]).transpose(), stg.time[i].shape[1], axis=1) - stg.kt3D[i] = np.repeat(stg.kt2D[i][:, np.newaxis, :], - stg.depth[i].shape[1], - axis=1) - - else: - - stg.kt2D[i] = np.repeat(np.array([stg.kt_read]).transpose(), stg.time[i].shape[1], axis=1) - stg.kt3D[i] = np.repeat(stg.kt2D[i][:, np.newaxis, :], stg.depth[i].shape[1], axis=1) + stg.kt3D[i] = np.repeat( + stg.kt2D[i][:, np.newaxis, :], + depth_data[i].shape[1], + axis=1 + ) def compute_J_cross_section(self): - for i in range(self.combobox_acoustic_data_choice.count()): J_cross_section_freq1 = np.array([]) From f5eb9a18c62db34c542beef0ad4588d0dd74c7f0 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby Date: Mon, 10 Mar 2025 17:04:31 +0100 Subject: [PATCH 07/11] SQL: Fix empty/partiel study save #12. --- Model/create_table_for_save_as.py | 435 ++++++++++++++++++------------ 1 file changed, 267 insertions(+), 168 deletions(-) diff --git a/Model/create_table_for_save_as.py b/Model/create_table_for_save_as.py index c4170f0..dbab7df 100644 --- a/Model/create_table_for_save_as.py +++ b/Model/create_table_for_save_as.py @@ -210,11 +210,22 @@ class CreateTableForSaveAs: # Create database cursor to execute SQL statements and fetch results from SQL queries. cur = cnx.cursor() - # -------------------------------------------------------------------------------------------------------------- - # +++++++++++++++++++++++++++ - # --- Table Acoustic File --- - # +++++++++++++++++++++++++++ + self.create_table_acoustic_file(cnx, cur) + self.create_table_measure(cnx, cur) + self.create_table_BSRawData(cnx, cur) + self.create_table_settings(cnx, cur) + self.create_table_sediments_file(cnx, cur) + self.create_table_sediments_data(cnx, cur) + self.create_table_calibration(cnx, cur) + self.create_table_inversion(cnx, cur) + cnx.commit() + + # Close database + cur.close() + cnx.close() + + def create_table_acoustic_file(self, cnx, cur): start_table_File = time.time() cur.execute("DROP TABLE if exists AcousticFile") @@ -222,28 +233,42 @@ class CreateTableForSaveAs: cur.execute(self.create_AcousticFile) for i in stg.acoustic_data: - print("stg.acoustic_data ", stg.acoustic_data[i]) - print("stg.filename_BS_raw_data ", stg.filename_BS_raw_data[i]) - print('stg.ABS_name', stg.ABS_name) - print("stg.path_BS_raw_data ", stg.path_BS_raw_data[i]) + logger.debug(f"stg.acoustic_data: {stg.acoustic_data[i]}") + logger.debug("stg.filename_BS_raw_data: " + + f"{stg.filename_BS_raw_data[i]}") + logger.debug(f"stg.ABS_name: {stg.ABS_name}") + logger.debug(f"stg.path_BS_raw_data: {stg.path_BS_raw_data[i]}") - cur.execute(''' INSERT into AcousticFile(acoustic_data, acoustic_file, ABS_name, path_BS_noise_data, - filename_BS_noise_data, noise_method, noise_value, data_preprocessed) - VALUES(?, ?, ?, ?, ?, ?, ?, ?)''', - (stg.acoustic_data[i], stg.filename_BS_raw_data[i].split('.')[0], stg.ABS_name[i], - stg.path_BS_noise_data[i], stg.filename_BS_noise_data[i], stg.noise_method[i], - stg.noise_value[i], stg.data_preprocessed[i]) - ) + cur.execute( + ''' + INSERT into AcousticFile( + acoustic_data, + acoustic_file, + ABS_name, + path_BS_noise_data, + filename_BS_noise_data, + noise_method, + noise_value, + data_preprocessed) + VALUES(?, ?, ?, ?, ?, ?, ?, ?) + ''', + ( + stg.acoustic_data[i], + stg.filename_BS_raw_data[i].split('.')[0], + stg.ABS_name[i], + stg.path_BS_noise_data[i], + stg.filename_BS_noise_data[i], + stg.noise_method[i], + stg.noise_value[i], + stg.data_preprocessed[i] + ) + ) cnx.commit() - print(f"table File : {time.time() - start_table_File} sec") - - # -------------------------------------------------------------------------------------------------------------- - # +++++++++++++++++++++ - # --- Table Measure --- - # +++++++++++++++++++++ + logger.info(f"table File : {time.time() - start_table_File} sec") + def create_table_measure(self, cnx, cur): start_table_Measure = time.time() # Drop Table if exists @@ -251,35 +276,52 @@ class CreateTableForSaveAs: # Execute the CREATE TABLE statement cur.execute(self.create_Measure) - print("stg.date ", stg.date, "stg.hour ", stg.hour) - # Fill the table Measure + + logger.debug(f"stg.date: {stg.date}, stg.hour: {stg.hour}") + for i in stg.acoustic_data: - for j in range(stg.freq[i].shape[0]): - - cur.execute(''' INSERT into Measure(acoustic_data, Date, Hour, frequency, sound_attenuation, kt_read, kt_corrected, - NbProfiles, NbProfilesPerSeconds, NbCells, CellSize, PulseLength, - NbPingsPerSeconds, NbPingsAveragedPerProfile, GainRx, GainTx - ) - VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)''', - (stg.acoustic_data[i], #stg.date[i], stg.hour[i], - str(stg.date[i].year) + str('-') + str(stg.date[i].month) + str('-') + str(stg.date[i].day), - str(stg.hour[i].hour) + str(':') + str(stg.hour[i].minute), - stg.freq[i][j], stg.water_attenuation[i][j], stg.kt_read[j], stg.kt_corrected[j], - stg.nb_profiles[i][j], stg.nb_profiles_per_sec[i][j], stg.nb_cells[i][j], - stg.cell_size[i][j], stg.pulse_length[i][j], stg.nb_pings_per_sec[i][j], - stg.nb_pings_averaged_per_profile[i][j], stg.gain_rx[i][j], stg.gain_tx[i][j])) + cur.execute( + ''' + INSERT into Measure( + acoustic_data, + Date, Hour, + frequency, + sound_attenuation, + kt_read, kt_corrected, + NbProfiles, NbProfilesPerSeconds, + NbCells, CellSize, + PulseLength, + NbPingsPerSeconds, + NbPingsAveragedPerProfile, + GainRx, GainTx + ) + VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) + ''', + ( + stg.acoustic_data[i], #stg.date[i], stg.hour[i], + str(stg.date[i].year) + str('-') + + str(stg.date[i].month) + str('-') + + str(stg.date[i].day), + str(stg.hour[i].hour) + str(':') + str(stg.hour[i].minute), + stg.freq[i][j], + stg.water_attenuation[i][j], + stg.kt_read[j], stg.kt_corrected[j], + stg.nb_profiles[i][j], stg.nb_profiles_per_sec[i][j], + stg.nb_cells[i][j], stg.cell_size[i][j], + stg.pulse_length[i][j], + stg.nb_pings_per_sec[i][j], + stg.nb_pings_averaged_per_profile[i][j], + stg.gain_rx[i][j], stg.gain_tx[i][j] + ) + ) # Commit the transaction after executing INSERT. cnx.commit() - print(f"table Measure : {time.time() - start_table_Measure} sec") - - # -------------------------------------------------------------------------------------------------------------- - # +++++++++++++++++++++++++ - # --- Table BSRawData_i --- - # +++++++++++++++++++++++++ + logger.info(f"table Measure : {time.time() - start_table_Measure} sec") + def create_table_BSRawData(self, cnx, cur): start_table_BSRawData = time.time() cur.execute('DROP TABLE if exists BSRawData') @@ -288,105 +330,140 @@ class CreateTableForSaveAs: cur.execute(self.create_BSRawData) for i in stg.acoustic_data: + cur.execute( + ''' + INSERT into BSRawData( + acoustic_data, + time, depth, + BS_raw_data, + time_reshape, + depth_reshape, + BS_raw_data_reshape, + time_cross_section, depth_cross_section, + BS_cross_section, BS_stream_bed, + depth_bottom, val_bottom, ind_bottom, + time_noise, depth_noise, BS_noise_raw_data, + SNR_raw_data, SNR_cross_section, SNR_stream_bed, + BS_raw_data_pre_process_SNR, BS_raw_data_pre_process_average, + BS_cross_section_pre_process_SNR, BS_cross_section_pre_process_average, + BS_stream_bed_pre_process_SNR, BS_stream_bed_pre_process_average, + BS_mean + ) + VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?) + ''', + ( + stg.acoustic_data[i], stg.time[i].tobytes(), + stg.depth[i].tobytes(), stg.BS_raw_data[i].tobytes(), + stg.time_reshape[i].tobytes(), stg.depth_reshape[i].tobytes(), + stg.BS_raw_data_reshape[i].tobytes(), + stg.time_cross_section[i].tobytes(), + stg.depth_cross_section[i].tobytes(), + stg.BS_cross_section[i].tobytes(), stg.BS_stream_bed[i].tobytes(), + stg.depth_bottom[i].tobytes(), np.array(stg.val_bottom[i]).tobytes(), + np.array(stg.ind_bottom[i]).tobytes(), + stg.time_noise[i].tobytes(), stg.depth_noise[i].tobytes(), + stg.BS_noise_raw_data[i].tobytes(), + stg.SNR_raw_data[i].tobytes(), stg.SNR_cross_section[i].tobytes(), + stg.SNR_stream_bed[i].tobytes(), + stg.BS_raw_data_pre_process_SNR[i].tobytes(), + stg.BS_raw_data_pre_process_average[i].tobytes(), + stg.BS_cross_section_pre_process_SNR[i].tobytes(), + stg.BS_cross_section_pre_process_average[i].tobytes(), + stg.BS_stream_bed_pre_process_SNR[i].tobytes(), + stg.BS_stream_bed_pre_process_average[i].tobytes(), + stg.BS_mean[i].tobytes() + ) + ) - cur.execute(''' INSERT into BSRawData(acoustic_data, time, depth, BS_raw_data, - time_reshape, depth_reshape, BS_raw_data_reshape, - time_cross_section, depth_cross_section, - BS_cross_section, BS_stream_bed, - depth_bottom, val_bottom, ind_bottom, - time_noise, depth_noise, BS_noise_raw_data, - SNR_raw_data, SNR_cross_section, SNR_stream_bed, - BS_raw_data_pre_process_SNR, BS_raw_data_pre_process_average, - BS_cross_section_pre_process_SNR, BS_cross_section_pre_process_average, - BS_stream_bed_pre_process_SNR, BS_stream_bed_pre_process_average, - BS_mean) - VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)''', - (stg.acoustic_data[i], stg.time[i].tobytes(), - stg.depth[i].tobytes(), stg.BS_raw_data[i].tobytes(), - stg.time_reshape[i].tobytes(), stg.depth_reshape[i].tobytes(), stg.BS_raw_data_reshape[i].tobytes(), - stg.time_cross_section[i].tobytes(), stg.depth_cross_section[i].tobytes(), - stg.BS_cross_section[i].tobytes(), stg.BS_stream_bed[i].tobytes(), - stg.depth_bottom[i].tobytes(), np.array(stg.val_bottom[i]).tobytes(), np.array(stg.ind_bottom[i]).tobytes(), - stg.time_noise[i].tobytes(), stg.depth_noise[i].tobytes(), stg.BS_noise_raw_data[i].tobytes(), - stg.SNR_raw_data[i].tobytes(), stg.SNR_cross_section[i].tobytes(), stg.SNR_stream_bed[i].tobytes(), - stg.BS_raw_data_pre_process_SNR[i].tobytes(), stg.BS_raw_data_pre_process_average[i].tobytes(), - stg.BS_cross_section_pre_process_SNR[i].tobytes(), stg.BS_cross_section_pre_process_average[i].tobytes(), - stg.BS_stream_bed_pre_process_SNR[i].tobytes(), stg.BS_stream_bed_pre_process_average[i].tobytes(), - stg.BS_mean[i].tobytes() - ) - ) + logger.debug(f"stg.ind_bottom: {stg.ind_bottom[i]}") + logger.debug(np.array([stg.ind_bottom[i]]), + np.array(stg.ind_bottom[i]).shape) - print("stg.ind_bottom ", stg.ind_bottom[i]) - print(np.array([stg.ind_bottom[i]]), np.array(stg.ind_bottom[i]).shape) - # Commit the transaction after executing INSERT. + # Commit the transaction after executing INSERT. cnx.commit() - print(f"table BSRawData : {time.time() - start_table_BSRawData} sec") - - # -------------------------------------------------------------------------------------------------------------- - # ++++++++++++++++++++++ - # --- Table Settings --- - # ++++++++++++++++++++++ + logger.info(f"table BSRawData : {time.time() - start_table_BSRawData} sec") + def create_table_settings(self, cnx, cur): start_table_Settings = time.time() cur.execute("DROP TABLE if exists Settings") cur.execute(self.create_Settings) - print(stg.acoustic_data, stg.temperature, stg.rmin, stg.rmax, stg.tmin, stg.tmax) + logger.debug(f"acoustic_data: {stg.acoustic_data}") + logger.debug(f"temperature: {stg.temperature}") + logger.debug(f"rmin: {stg.rmin}, rmax: {stg.rmax}") + logger.debug(f"tmin: {stg.tmin}, tmax: {stg.tmax}") for i in stg.acoustic_data: - cur.execute('''INSERT into Settings(acoustic_data, temperature, - tmin_index, tmin_value, tmax_index, tmax_value, - rmin_index, rmin_value, rmax_index, rmax_value, - freq_bottom_detection_index, freq_bottom_detection_value, - SNR_filter_value, Nb_cells_to_average_BS_signal - ) - VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)''', - (stg.acoustic_data[i], stg.temperature, - stg.tmin[i][0], stg.tmin[i][1], stg.tmax[i][0], stg.tmax[i][1], - stg.rmin[i][0], stg.rmin[i][1], stg.rmax[i][0], stg.rmax[i][1], - stg.freq_bottom_detection[i][0], stg.freq_bottom_detection[i][1], - stg.SNR_filter_value[i], stg.Nb_cells_to_average_BS_signal[i] - ) - ) + cur.execute( + ''' + INSERT into Settings( + acoustic_data, temperature, + tmin_index, tmin_value, tmax_index, tmax_value, + rmin_index, rmin_value, rmax_index, rmax_value, + freq_bottom_detection_index, freq_bottom_detection_value, + SNR_filter_value, Nb_cells_to_average_BS_signal + ) + VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) + ''', + ( + stg.acoustic_data[i], stg.temperature, + stg.tmin[i][0], stg.tmin[i][1], + stg.tmax[i][0], stg.tmax[i][1], + stg.rmin[i][0], stg.rmin[i][1], + stg.rmax[i][0], stg.rmax[i][1], + stg.freq_bottom_detection[i][0], + stg.freq_bottom_detection[i][1], + stg.SNR_filter_value[i], + stg.Nb_cells_to_average_BS_signal[i] + ) + ) cnx.commit() - print(f"table Settings : {time.time() - start_table_Settings} sec") - - # -------------------------------------------------------------------------------------------------------------- - # ++++++++++++++++++++++++++++ - # --- Table Sediments File --- - # ++++++++++++++++++++++++++++ + logger.info(f"table Settings : {time.time() - start_table_Settings} sec") + def create_table_sediments_file(self, cnx, cur): start_table_SedimentsFile = time.time() cur.execute("DROP TABLE if exists SedimentsFile") cur.execute(self.create_SedimentsFile) - cur.execute('''INSERT into SedimentsFile(path_fine, filename_fine, radius_grain_fine, - path_sand, filename_sand, radius_grain_sand, - time_column_label, distance_from_bank_column_label, - depth_column_label, Ctot_fine_column_label, D50_fine_column_label, - Ctot_sand_column_label, D50_sand_column_label) - VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)''', - (stg.path_fine, stg.filename_fine, stg.radius_grain_fine.tobytes(), - stg.path_sand, stg.filename_sand, stg.radius_grain_sand.tobytes(), - stg.columns_fine[0], stg.columns_fine[1], stg.columns_fine[2], - stg.columns_fine[3], stg.columns_fine[4], stg.columns_sand[3], stg.columns_sand[4])) + if stg.path_fine != "" and path_sand != "": + cur.execute( + ''' + INSERT into SedimentsFile( + path_fine, filename_fine, radius_grain_fine, + path_sand, filename_sand, radius_grain_sand, + time_column_label, distance_from_bank_column_label, + depth_column_label, Ctot_fine_column_label, + D50_fine_column_label, + Ctot_sand_column_label, D50_sand_column_label + ) + VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) + ''', + ( + stg.path_fine, stg.filename_fine, + stg.radius_grain_fine.tobytes(), + stg.path_sand, stg.filename_sand, + stg.radius_grain_sand.tobytes(), + stg.columns_fine[0], stg.columns_fine[1], + stg.columns_fine[2], stg.columns_fine[3], + stg.columns_fine[4], + stg.columns_sand[3], stg.columns_sand[4] + ) + ) cnx.commit() - print(f"table SedimentsFile : {time.time() - start_table_SedimentsFile} sec") + logger.info(f"table SedimentsFile : {time.time() - start_table_SedimentsFile} sec") - # -------------------------------------------------------------------------------------------------------------- - # ++++++++++++++++++++++++++++ - # --- Table Sediments Data --- - # ++++++++++++++++++++++++++++ + def create_table_sediments_data(self, cnx, cur): start_table_SedimentsData = time.time() cur.execute("DROP TABLE if exists SedimentsData") @@ -394,59 +471,79 @@ class CreateTableForSaveAs: cur.execute(self.create_SedimentsData) for f in range(len(stg.sample_fine)): - cur.execute('''INSERT into SedimentsData(sample_fine_name, sample_fine_index, distance_from_bank_fine, - depth_fine, time_fine, Ctot_fine, Ctot_fine_per_cent, D50_fine, - frac_vol_fine, frac_vol_fine_cumul, - sample_sand_name, sample_sand_index, distance_from_bank_sand, - depth_sand, time_sand, Ctot_sand, Ctot_sand_per_cent, D50_sand, - frac_vol_sand, frac_vol_sand_cumul - ) - VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)''', - (stg.sample_fine[f][0] , stg.sample_fine[f][1], - stg.distance_from_bank_fine[f], stg.depth_fine[f], stg.time_fine[f], stg.Ctot_fine[f], - stg.Ctot_fine_per_cent[f], stg.D50_fine[f], - stg.frac_vol_fine[f].tobytes(), stg.frac_vol_fine_cumul[f].tobytes(), - stg.sample_sand[f][0], stg.sample_sand[f][1], - stg.distance_from_bank_sand[f], stg.depth_sand[f], stg.time_sand[f], stg.Ctot_sand[f], - stg.Ctot_sand_per_cent[f], stg.D50_sand[f], - stg.frac_vol_sand[f].tobytes(), stg.frac_vol_sand_cumul[f].tobytes())) + cur.execute( + ''' + INSERT into SedimentsData( + sample_fine_name, sample_fine_index, + distance_from_bank_fine, + depth_fine, time_fine, Ctot_fine, + Ctot_fine_per_cent, D50_fine, + frac_vol_fine, frac_vol_fine_cumul, + sample_sand_name, sample_sand_index, + distance_from_bank_sand, + depth_sand, time_sand, Ctot_sand, + Ctot_sand_per_cent, D50_sand, + frac_vol_sand, frac_vol_sand_cumul + ) + VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) + ''', + ( + stg.sample_fine[f][0] , stg.sample_fine[f][1], + stg.distance_from_bank_fine[f], stg.depth_fine[f], + stg.time_fine[f], stg.Ctot_fine[f], + stg.Ctot_fine_per_cent[f], stg.D50_fine[f], + stg.frac_vol_fine[f].tobytes(), + stg.frac_vol_fine_cumul[f].tobytes(), + stg.sample_sand[f][0], stg.sample_sand[f][1], + stg.distance_from_bank_sand[f], stg.depth_sand[f], + stg.time_sand[f], stg.Ctot_sand[f], + stg.Ctot_sand_per_cent[f], stg.D50_sand[f], + stg.frac_vol_sand[f].tobytes(), + stg.frac_vol_sand_cumul[f].tobytes() + ) + ) cnx.commit() - print(f"table SedimentsData : {time.time() - start_table_SedimentsData} sec") - - # -------------------------------------------------------------------------------------------------------------- - # ++++++++++++++++++++++++++++++ - # --- Table Calibration --- - # ++++++++++++++++++++++++++++++ + logger.info(f"table SedimentsData : {time.time() - start_table_SedimentsData} sec") + def create_table_calibration(self, cnx, cur): start_table_Calibration = time.time() cur.execute("DROP TABLE if exists Calibration") cur.execute(self.create_Calibration) - cur.execute('''INSERT into Calibration(path_calibration_file, filename_calibration_file, - range_lin_interp, M_profile_fine, - ks, sv, X_exponent, alpha_s, zeta, - FCB, depth_real, lin_reg) - VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)''', - (stg.path_calibration_file, stg.filename_calibration_file, - stg.range_lin_interp.tobytes(), stg.M_profile_fine.tobytes(), - np.array(stg.ks).tobytes(), np.array(stg.sv).tobytes(), np.array(stg.X_exponent).tobytes(), - np.array(stg.alpha_s).tobytes(), np.array(stg.zeta).tobytes(), - stg.FCB.tobytes(), stg.depth_real.tobytes(), np.array(stg.lin_reg).tobytes()) - ) + if len(stg.range_lin_interp) != 0: + cur.execute( + ''' + INSERT into Calibration( + path_calibration_file, filename_calibration_file, + range_lin_interp, M_profile_fine, + ks, sv, X_exponent, alpha_s, zeta, + FCB, depth_real, lin_reg + ) + VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) + ''', + ( + stg.path_calibration_file, stg.filename_calibration_file, + stg.range_lin_interp.tobytes(), + stg.M_profile_fine.tobytes(), + np.array(stg.ks).tobytes(), np.array(stg.sv).tobytes(), + np.array(stg.X_exponent).tobytes(), + np.array(stg.alpha_s).tobytes(), + np.array(stg.zeta).tobytes(), + stg.FCB.tobytes(), stg.depth_real.tobytes(), + np.array(stg.lin_reg).tobytes() + ) + ) cnx.commit() - print(f"table Calibration : {time.time() - start_table_Calibration} sec") - - # -------------------------------------------------------------------------------------------------------------- - # ++++++++++++++++++++++++++++++ - # --- Table Inversion --- - # ++++++++++++++++++++++++++++++ + logger.info(f"table Calibration : {time.time() - start_table_Calibration} sec") + def create_table_inversion(self, cnx, cur): start_table_Inversion = time.time() cur.execute("DROP TABLE if exists Inversion") @@ -454,21 +551,23 @@ class CreateTableForSaveAs: cur.execute(self.create_Inversion) for i in range(len(stg.SSC_fine)): - cur.execute('''INSERT into Inversion(J_cross_section_freq1, J_cross_section_freq2, - VBI_cross_section, SSC_fine, SSC_sand) - VALUES(?, ?, ?, ?, ?)''', - (stg.J_cross_section[i][0].tobytes(), stg.J_cross_section[i][1].tobytes(), - stg.VBI_cross_section[i].tobytes(), stg.SSC_fine[i].tobytes(), stg.SSC_sand[i].tobytes()) - ) + cur.execute( + ''' + INSERT into Inversion( + J_cross_section_freq1, J_cross_section_freq2, + VBI_cross_section, SSC_fine, SSC_sand + ) + VALUES(?, ?, ?, ?, ?) + ''', + ( + stg.J_cross_section[i][0].tobytes(), + stg.J_cross_section[i][1].tobytes(), + stg.VBI_cross_section[i].tobytes(), + stg.SSC_fine[i].tobytes(), + stg.SSC_sand[i].tobytes() + ) + ) cnx.commit() - print(f"table Inversion : {time.time() - start_table_Inversion} sec") - - # -------------------------------------------------------------------------------------------------------------- - - # Close database cursor - cur.close() - - # Close database connection - cnx.close() + logger.info(f"table Inversion : {time.time() - start_table_Inversion} sec") From 87098ff1522a6314e3e29ba7b39565d354f84efe Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby Date: Mon, 10 Mar 2025 17:12:45 +0100 Subject: [PATCH 08/11] SQL: Some refactoring. --- Model/create_table_for_save_as.py | 289 ++++++++++++++++-------------- 1 file changed, 154 insertions(+), 135 deletions(-) diff --git a/Model/create_table_for_save_as.py b/Model/create_table_for_save_as.py index dbab7df..43aed08 100644 --- a/Model/create_table_for_save_as.py +++ b/Model/create_table_for_save_as.py @@ -38,132 +38,151 @@ class CreateTableForSaveAs: def __init__(self): - self.create_AcousticFile = """CREATE TABLE AcousticFile( - ID INTEGER PRIMARY KEY AUTOINCREMENT, - acoustic_data INTEGER, - acoustic_file STRING, - ABS_name STRING, - path_BS_noise_data STRING, - filename_BS_noise_data STRING, - noise_method FLOAT, - noise_value FLOAT, - data_preprocessed STRING - ) - """ + self.create_AcousticFile = """ + CREATE TABLE AcousticFile( + ID INTEGER PRIMARY KEY AUTOINCREMENT, + acoustic_data INTEGER, + acoustic_file STRING, + ABS_name STRING, + path_BS_noise_data STRING, + filename_BS_noise_data STRING, + noise_method FLOAT, + noise_value FLOAT, + data_preprocessed STRING + ) + """ - self.create_Measure = """ CREATE TABLE Measure( - ID INTEGER PRIMARY KEY AUTOINCREMENT, - acoustic_data INTEGER, - Date DATE, - Hour TIME, - frequency FLOAT, - sound_attenuation FLOAT, - kt_read FLOAT, - kt_corrected FLOAT, - NbProfiles FLOAT, - NbProfilesPerSeconds FLOAT, - NbCells FLOAT, - CellSize FLOAT, - PulseLength FLOAT, - NbPingsPerSeconds FLOAT, - NbPingsAveragedPerProfile FLOAT, - GainRx FLOAT, - GainTx FLOAT - ) - """ + self.create_Measure = """ + CREATE TABLE Measure( + ID INTEGER PRIMARY KEY AUTOINCREMENT, + acoustic_data INTEGER, + Date DATE, + Hour TIME, + frequency FLOAT, + sound_attenuation FLOAT, + kt_read FLOAT, + kt_corrected FLOAT, + NbProfiles FLOAT, + NbProfilesPerSeconds FLOAT, + NbCells FLOAT, + CellSize FLOAT, + PulseLength FLOAT, + NbPingsPerSeconds FLOAT, + NbPingsAveragedPerProfile FLOAT, + GainRx FLOAT, + GainTx FLOAT + ) + """ - self.create_BSRawData = '''CREATE TABLE BSRawData( - ID INTEGER PRIMARY KEY AUTOINCREMENT, - acoustic_data INTEGER, - time BLOB, depth BLOB, BS_raw_data BLOB, - time_reshape BLOB, depth_reshape BLOB, BS_raw_data_reshape BLOB, - time_cross_section BLOB, depth_cross_section BLOB, BS_cross_section BLOB, BS_stream_bed BLOB, - depth_bottom, val_bottom, ind_bottom, - time_noise BLOB, depth_noise BLOB, BS_noise_raw_data BLOB, - SNR_raw_data BLOB, SNR_cross_section BLOB, SNR_stream_bed BLOB, - BS_raw_data_pre_process_SNR BLOB, BS_raw_data_pre_process_average BLOB, - BS_cross_section_pre_process_SNR BLOB, BS_cross_section_pre_process_average BLOB, - BS_stream_bed_pre_process_SNR BLOB, BS_stream_bed_pre_process_average BLOB, - BS_mean BLOB - )''' + self.create_BSRawData = """ + CREATE TABLE BSRawData( + ID INTEGER PRIMARY KEY AUTOINCREMENT, + acoustic_data INTEGER, + time BLOB, depth BLOB, BS_raw_data BLOB, + time_reshape BLOB, depth_reshape BLOB, BS_raw_data_reshape BLOB, + time_cross_section BLOB, depth_cross_section BLOB, + BS_cross_section BLOB, BS_stream_bed BLO B, + depth_bottom, val_bottom, ind_bottom, + time_noise BLOB, depth_noise BLOB, BS_noise_raw_data BLOB, + SNR_raw_data BLOB, SNR_cross_section BLOB, SNR_stream_bed BLOB, + BS_raw_data_pre_process_SNR BLOB, + BS_raw_data_pre_process_average BLOB, + BS_cross_section_pre_process_SNR BLOB, + BS_cross_section_pre_process_average BLOB, + BS_stream_bed_pre_process_SNR BLOB, + BS_stream_bed_pre_process_average BLOB, + BS_mean BLOB + ) + """ - self.create_Settings = '''CREATE TABLE Settings( - ID INTEGER PRIMARY KEY AUTOINCREMENT, - acoustic_data INTEGER, - temperature FLOAT, - tmin_index FLOAT, tmin_value FLOAT, tmax_index FLOAT, tmax_value FLOAT, - rmin_index FLOAT, rmin_value FLOAT, rmax_index FLOAT, rmax_value FLOAT, - freq_bottom_detection_index FLOAT, freq_bottom_detection_value STRING, - SNR_filter_value FLOAT, Nb_cells_to_average_BS_signal FLOAT - )''' + self.create_Settings = """ + CREATE TABLE Settings( + ID INTEGER PRIMARY KEY AUTOINCREMENT, + acoustic_data INTEGER, + temperature FLOAT, + tmin_index FLOAT, tmin_value FLOAT, + tmax_index FLOAT, tmax_value FLOAT, + rmin_index FLOAT, rmin_value FLOAT, + rmax_index FLOAT, rmax_value FLOAT, + freq_bottom_detection_index FLOAT, + freq_bottom_detection_value STRING, + SNR_filter_value FLOAT, Nb_cells_to_average_BS_signal FLOAT + ) + """ - self.create_SedimentsFile = """CREATE TABLE SedimentsFile( - ID INTEGER PRIMARY KEY AUTOINCREMENT, - path_fine STRING, - filename_fine STRING, - radius_grain_fine BLOB, - path_sand STRING, - filename_sand STRING, - radius_grain_sand BLOB, - time_column_label STRING, - distance_from_bank_column_label STRING, - depth_column_label STRING, - Ctot_fine_column_label STRING, - D50_fine_column_label STRING, - Ctot_sand_column_label STRING, - D50_sand_column_label STRING - ) - """ + self.create_SedimentsFile = """ + CREATE TABLE SedimentsFile( + ID INTEGER PRIMARY KEY AUTOINCREMENT, + path_fine STRING, + filename_fine STRING, + radius_grain_fine BLOB, + path_sand STRING, + filename_sand STRING, + radius_grain_sand BLOB, + time_column_label STRING, + distance_from_bank_column_label STRING, + depth_column_label STRING, + Ctot_fine_column_label STRING, + D50_fine_column_label STRING, + Ctot_sand_column_label STRING, + D50_sand_column_label STRING + ) + """ - self.create_SedimentsData = """CREATE TABLE SedimentsData( - ID INTEGER PRIMARY KEY AUTOINCREMENT, - sample_fine_name STRING, - sample_fine_index INTEGER, - distance_from_bank_fine FLOAT, - depth_fine FLOAT, - time_fine FLOAT, - Ctot_fine FLOAT, - Ctot_fine_per_cent FLOAT, - D50_fine FLOAT, - frac_vol_fine BLOB, - frac_vol_fine_cumul BLOB, - sample_sand_name STRING, - sample_sand_index INTEGER, - distance_from_bank_sand FLOAT, - depth_sand FLOAT, - time_sand FLOAT, - Ctot_sand FLOAT, - Ctot_sand_per_cent FLOAT, - D50_sand FLOAT, - frac_vol_sand BLOB, - frac_vol_sand_cumul BLOB - ) - """ + self.create_SedimentsData = """ + CREATE TABLE SedimentsData( + ID INTEGER PRIMARY KEY AUTOINCREMENT, + sample_fine_name STRING, + sample_fine_index INTEGER, + distance_from_bank_fine FLOAT, + depth_fine FLOAT, + time_fine FLOAT, + Ctot_fine FLOAT, + Ctot_fine_per_cent FLOAT, + D50_fine FLOAT, + frac_vol_fine BLOB, + frac_vol_fine_cumul BLOB, + sample_sand_name STRING, + sample_sand_index INTEGER, + distance_from_bank_sand FLOAT, + depth_sand FLOAT, + time_sand FLOAT, + Ctot_sand FLOAT, + Ctot_sand_per_cent FLOAT, + D50_sand FLOAT, + frac_vol_sand BLOB, + frac_vol_sand_cumul BLOB + ) + """ - self.create_Calibration = """CREATE TABLE Calibration( - ID INTEGER PRIMARY KEY AUTOINCREMENT, - path_calibration_file STRING, - filename_calibration_file STRING, - range_lin_interp BLOB, - M_profile_fine BLOB, - ks BLOB, - sv BLOB, - X_exponent BLOB, - alpha_s BLOB, - zeta BLOB, - FCB BLOB, - depth_real BLOB, - lin_reg BLOB - )""" + self.create_Calibration = """ + CREATE TABLE Calibration( + ID INTEGER PRIMARY KEY AUTOINCREMENT, + path_calibration_file STRING, + filename_calibration_file STRING, + range_lin_interp BLOB, + M_profile_fine BLOB, + ks BLOB, + sv BLOB, + X_exponent BLOB, + alpha_s BLOB, + zeta BLOB, + FCB BLOB, + depth_real BLOB, + lin_reg BLOB + ) + """ - self.create_Inversion = """CREATE TABLE Inversion( - ID INTEGER PRIMARY KEY AUTOINCREMENT, - J_cross_section_freq1 BLOB, - J_cross_section_freq2 BLOB, - VBI_cross_section BLOB, - SSC_fine BLOB, - SSC_sand BLOB - )""" + self.create_Inversion = """ + CREATE TABLE Inversion( + ID INTEGER PRIMARY KEY AUTOINCREMENT, + J_cross_section_freq1 BLOB, + J_cross_section_freq2 BLOB, + VBI_cross_section BLOB, + SSC_fine BLOB, + SSC_sand BLOB + ) + """ self.open_file_dialog() @@ -240,7 +259,7 @@ class CreateTableForSaveAs: logger.debug(f"stg.path_BS_raw_data: {stg.path_BS_raw_data[i]}") cur.execute( - ''' + """ INSERT into AcousticFile( acoustic_data, acoustic_file, @@ -251,7 +270,7 @@ class CreateTableForSaveAs: noise_value, data_preprocessed) VALUES(?, ?, ?, ?, ?, ?, ?, ?) - ''', + """, ( stg.acoustic_data[i], stg.filename_BS_raw_data[i].split('.')[0], @@ -282,7 +301,7 @@ class CreateTableForSaveAs: for i in stg.acoustic_data: for j in range(stg.freq[i].shape[0]): cur.execute( - ''' + """ INSERT into Measure( acoustic_data, Date, Hour, @@ -297,7 +316,7 @@ class CreateTableForSaveAs: GainRx, GainTx ) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) - ''', + """, ( stg.acoustic_data[i], #stg.date[i], stg.hour[i], str(stg.date[i].year) + str('-') @@ -331,7 +350,7 @@ class CreateTableForSaveAs: for i in stg.acoustic_data: cur.execute( - ''' + """ INSERT into BSRawData( acoustic_data, time, depth, @@ -351,7 +370,7 @@ class CreateTableForSaveAs: ) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) - ''', + """, ( stg.acoustic_data[i], stg.time[i].tobytes(), stg.depth[i].tobytes(), stg.BS_raw_data[i].tobytes(), @@ -399,7 +418,7 @@ class CreateTableForSaveAs: for i in stg.acoustic_data: cur.execute( - ''' + """ INSERT into Settings( acoustic_data, temperature, tmin_index, tmin_value, tmax_index, tmax_value, @@ -408,7 +427,7 @@ class CreateTableForSaveAs: SNR_filter_value, Nb_cells_to_average_BS_signal ) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) - ''', + """, ( stg.acoustic_data[i], stg.temperature, stg.tmin[i][0], stg.tmin[i][1], @@ -435,7 +454,7 @@ class CreateTableForSaveAs: if stg.path_fine != "" and path_sand != "": cur.execute( - ''' + """ INSERT into SedimentsFile( path_fine, filename_fine, radius_grain_fine, path_sand, filename_sand, radius_grain_sand, @@ -445,7 +464,7 @@ class CreateTableForSaveAs: Ctot_sand_column_label, D50_sand_column_label ) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) - ''', + """, ( stg.path_fine, stg.filename_fine, stg.radius_grain_fine.tobytes(), @@ -472,7 +491,7 @@ class CreateTableForSaveAs: for f in range(len(stg.sample_fine)): cur.execute( - ''' + """ INSERT into SedimentsData( sample_fine_name, sample_fine_index, distance_from_bank_fine, @@ -487,7 +506,7 @@ class CreateTableForSaveAs: ) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) - ''', + """, ( stg.sample_fine[f][0] , stg.sample_fine[f][1], stg.distance_from_bank_fine[f], stg.depth_fine[f], @@ -517,7 +536,7 @@ class CreateTableForSaveAs: if len(stg.range_lin_interp) != 0: cur.execute( - ''' + """ INSERT into Calibration( path_calibration_file, filename_calibration_file, range_lin_interp, M_profile_fine, @@ -525,7 +544,7 @@ class CreateTableForSaveAs: FCB, depth_real, lin_reg ) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) - ''', + """, ( stg.path_calibration_file, stg.filename_calibration_file, stg.range_lin_interp.tobytes(), @@ -552,13 +571,13 @@ class CreateTableForSaveAs: for i in range(len(stg.SSC_fine)): cur.execute( - ''' + """ INSERT into Inversion( J_cross_section_freq1, J_cross_section_freq2, VBI_cross_section, SSC_fine, SSC_sand ) VALUES(?, ?, ?, ?, ?) - ''', + """, ( stg.J_cross_section[i][0].tobytes(), stg.J_cross_section[i][1].tobytes(), From f872b625c2dcb5a4dae83cafe9f77387389d64ed Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby Date: Mon, 10 Mar 2025 17:14:11 +0100 Subject: [PATCH 09/11] SQL: Minor change. --- Model/create_table_for_save_as.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Model/create_table_for_save_as.py b/Model/create_table_for_save_as.py index 43aed08..eeedb82 100644 --- a/Model/create_table_for_save_as.py +++ b/Model/create_table_for_save_as.py @@ -37,7 +37,6 @@ logger = logging.getLogger() class CreateTableForSaveAs: def __init__(self): - self.create_AcousticFile = """ CREATE TABLE AcousticFile( ID INTEGER PRIMARY KEY AUTOINCREMENT, @@ -222,11 +221,7 @@ class CreateTableForSaveAs: msgBox.exec() def create_table(self): - - # Create a new database and open a database connection to allow sqlite3 to work with it. cnx = sqlite3.connect(stg.filename_save_as) - - # Create database cursor to execute SQL statements and fetch results from SQL queries. cur = cnx.cursor() self.create_table_acoustic_file(cnx, cur) @@ -240,7 +235,6 @@ class CreateTableForSaveAs: cnx.commit() - # Close database cur.close() cnx.close() From 2697acddfe03c9d1e6bc8eb02facc8e67b116d47 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby Date: Tue, 11 Mar 2025 09:34:04 +0100 Subject: [PATCH 10/11] Sample data: Refactoring some functions. --- View/sample_data_tab.py | 261 ++++++++++++++++++++++++++-------------- 1 file changed, 172 insertions(+), 89 deletions(-) diff --git a/View/sample_data_tab.py b/View/sample_data_tab.py index 7d714e6..4eec985 100644 --- a/View/sample_data_tab.py +++ b/View/sample_data_tab.py @@ -20,12 +20,8 @@ # -*- coding: utf-8 -*- - -from PyQt5.QtWidgets import (QWidget, QVBoxLayout, QHBoxLayout, QGroupBox, QLabel, QSpacerItem, QSizePolicy, - QTableWidget, QPushButton, QLineEdit, - QTableWidgetItem, QComboBox, QFileDialog, QGridLayout, QMessageBox) -from PyQt5.QtGui import QIcon -from PyQt5.QtCore import Qt, QCoreApplication, pyqtSignal +import os +import logging import numpy as np import pandas as pd @@ -36,7 +32,13 @@ from matplotlib.colors import LogNorm, BASE_COLORS from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolBar -from os import path +from PyQt5.QtWidgets import ( + QWidget, QVBoxLayout, QHBoxLayout, QGroupBox, QLabel, + QSpacerItem, QSizePolicy, QTableWidget, QPushButton, QLineEdit, + QTableWidgetItem, QComboBox, QFileDialog, QGridLayout, QMessageBox +) +from PyQt5.QtGui import QIcon +from PyQt5.QtCore import Qt, QCoreApplication, pyqtSignal from Model.granulo_loader import GranuloLoader @@ -48,6 +50,7 @@ import settings as stg _translate = QCoreApplication.translate +logger = logging.getLogger() class SampleDataTab(QWidget): @@ -57,8 +60,7 @@ class SampleDataTab(QWidget): def __init__(self, widget_tab): super().__init__() - path_icon = "./icons/" - icon_folder = QIcon(path_icon + "folder.png") + icon_folder = QIcon(os.path.join("icons", "folder.png")) ### --- General layout of widgets --- @@ -269,20 +271,36 @@ class SampleDataTab(QWidget): self.groupbox_plot_PSD.setTitle(_translate("CONSTANT_STRING", cs.DISTRIBUTION_PLOT)) - # ------------------------------------------------------------------------------------------------------------------ - # --- Function to select directory and file name of fine sediments sample data --- - def open_dialog_box_fine_sediment(self): + def last_opened_file_path(self, priority="sand"): + lst = [] + + if priority == "sand": + lst += [stg.path_sand] + lst += [stg.path_fine] + else: + lst += [stg.path_fine] + lst += [stg.path_sand] + + lst += stg.path_BS_raw_data + + for path in lst: + if path != "": + return path + + return "" + + def open_dialog_box_fine_sediment(self): filename_fine_sediment = QFileDialog.getOpenFileName( self, "Fine sediment file", - [stg.path_fine if stg.path_fine else stg.path_sand if stg.path_sand - else stg.path_BS_raw_data[-1] if self.combobox_acoustic_data.count() > 0 else ""][0], + self.last_opened_file_path(priority="fine"), "Fine sediment file (*.xlsx, *xls, *.ods)", - options=QFileDialog.DontUseNativeDialog) + options=QFileDialog.DontUseNativeDialog + ) try: - stg.path_fine = path.dirname(filename_fine_sediment[0]) - stg.filename_fine = path.basename(filename_fine_sediment[0]) + stg.path_fine = os.path.dirname(filename_fine_sediment[0]) + stg.filename_fine = os.path.basename(filename_fine_sediment[0]) self.load_fine_sediment_data() except IsADirectoryError: msgBox = QMessageBox() @@ -291,25 +309,24 @@ class SampleDataTab(QWidget): msgBox.setText("Please select a file") msgBox.setStandardButtons(QMessageBox.Ok) msgBox.exec() + except Exception as e: + logger.error(e) else: self.lineEdit_fine_sediment.clear() self.lineEdit_fine_sediment.setText(stg.filename_fine) self.lineEdit_fine_sediment.setToolTip(stg.path_fine) self.fill_table_fine() - # --- Function to select directory and file name of sand sediments sample data --- def open_dialog_box_sand_sediment(self): - filename_sand_sediment = QFileDialog.getOpenFileName( self, "Sand sediment file", - [stg.path_sand if stg.path_sand else stg.path_fine if stg.path_fine - else stg.path_BS_raw_data[-1] if self.combobox_acoustic_data.count() > 0 else ""][0], + self.last_opened_file_path(priority="sand"), "Sand sediment file (*.xlsx, *xls, *.ods)", options=QFileDialog.DontUseNativeDialog) try: - stg.path_sand = path.dirname(filename_sand_sediment[0]) - stg.filename_sand = path.basename(filename_sand_sediment[0]) + stg.path_sand = os.path.dirname(filename_sand_sediment[0]) + stg.filename_sand = os.path.basename(filename_sand_sediment[0]) self.load_sand_sediment_data() except IsADirectoryError: msgBox = QMessageBox() @@ -318,13 +335,17 @@ class SampleDataTab(QWidget): msgBox.setText("Please select a file") msgBox.setStandardButtons(QMessageBox.Ok) msgBox.exec() + except Exception as e: + logger.error(e) else: self.lineEdit_sand_sediment.setText(stg.filename_sand) self.lineEdit_sand_sediment.setToolTip(stg.path_sand) self.fill_table_sand() def load_fine_sediment_data(self): - fine_granulo_data = GranuloLoader(stg.path_fine + "/" + stg.filename_fine) + fine_granulo_data = GranuloLoader( + os.path.join(stg.path_fine, stg.filename_fine) + ) stg.columns_fine = fine_granulo_data._data.columns stg.time_fine = fine_granulo_data._time stg.distance_from_bank_fine = fine_granulo_data._y @@ -336,7 +357,9 @@ class SampleDataTab(QWidget): stg.frac_vol_fine_cumul = fine_granulo_data._frac_vol_cumul def load_sand_sediment_data(self): - sand_granulo_data = GranuloLoader(stg.path_sand + "/" + stg.filename_sand) + sand_granulo_data = GranuloLoader( + os.path.join(stg.path_sand, stg.filename_sand) + ) stg.columns_sand = sand_granulo_data._data.columns stg.time_sand = sand_granulo_data._time stg.distance_from_bank_sand = sand_granulo_data._y @@ -360,35 +383,54 @@ class SampleDataTab(QWidget): # --- Function to fill table of values --- def fill_table_fine(self): if self.lineEdit_fine_sediment.text(): - - self.row_fine = self.tableWidget_fine.setRowCount(len(stg.depth_fine)) - self.column_fine = self.tableWidget_fine.setColumnCount(6 + stg.radius_grain_fine.shape[0]) + self.row_fine = self.tableWidget_fine.setRowCount( + len(stg.depth_fine) + ) + self.column_fine = self.tableWidget_fine.setColumnCount( + 6 + stg.radius_grain_fine.shape[0] + ) # --- Set horizontal header --- - - horizontal_header = list(itertools.chain(["Color", "Sample"], - list(map(str, stg.columns_fine[[0, 2]])), - list(map(str, stg.columns_fine[3:])))) + horizontal_header = list( + itertools.chain( + ["Color", "Sample"], + list(map(str, stg.columns_fine[[0, 2]])), + list(map(str, stg.columns_fine[3:])) + ) + ) for horizontal_header_text in horizontal_header: self.horizontal_header_item_fine = QTableWidgetItem() - self.tableWidget_fine.setHorizontalHeaderItem(horizontal_header.index(horizontal_header_text), - self.horizontal_header_item_fine) + self.tableWidget_fine.setHorizontalHeaderItem( + horizontal_header.index(horizontal_header_text), + self.horizontal_header_item_fine + ) self.horizontal_header_item_fine.setText(horizontal_header_text) # --- Set vertical header (color) --- self.tableWidget_fine.verticalHeader().setVisible(False) color_list = BASE_COLORS + + self.comboBox_sample_table_fine = [] for i in range(self.tableWidget_fine.rowCount()): - exec("self.comboBox_sample_table_fine" + str(i) + "= QComboBox()") - exec("self.comboBox_sample_table_fine" + str(i) + ".addItems(color_list)") - eval(f"self.tableWidget_fine.setCellWidget(i, 0, self.comboBox_sample_table_fine{i})") - eval(f"self.comboBox_sample_table_fine{i}.currentTextChanged." - f"connect(self.plot_total_concentration)") - eval(f"self.comboBox_sample_table_fine{i}.currentTextChanged." - f"connect(self.plot_PSD_fine_and_sand_sediments)") - eval(f"self.comboBox_sample_table_fine{i}.currentTextChanged." - f"connect(self.update_plot_sample_position_on_transect)") + self.comboBox_sample_table_fine.append( + QComboBox() + ) + + self.comboBox_sample_table_fine[i].addItems(color_list) + self.tableWidget_fine.setCellWidget( + i, 0, self.comboBox_sample_table_fine[i] + ) + + self.comboBox_sample_table_fine[i]\ + .currentTextChanged\ + .connect(self.plot_total_concentration) + self.comboBox_sample_table_fine[i]\ + .currentTextChanged\ + .connect(self.plot_PSD_fine_and_sand_sediments) + self.comboBox_sample_table_fine[i]\ + .currentTextChanged\ + .connect(self.update_plot_sample_position_on_transect) # --- Fill Sample column with checkbox --- for i in range(self.tableWidget_fine.rowCount()): @@ -401,12 +443,21 @@ class SampleDataTab(QWidget): # --- Fill table with data --- for i in range(stg.frac_vol_fine.shape[0]): for j in range(stg.frac_vol_fine.shape[1]): - self.tableWidget_fine.setItem(i, 2, QTableWidgetItem(str(stg.time_fine[i]))) - self.tableWidget_fine.setItem(i, 3, QTableWidgetItem(str(stg.depth_fine[i]))) - - self.tableWidget_fine.setItem(i, 4, QTableWidgetItem(str(stg.Ctot_fine[i]))) - self.tableWidget_fine.setItem(i, 5, QTableWidgetItem(str(stg.D50_fine[i]))) - self.tableWidget_fine.setItem(i, j + 6, QTableWidgetItem(str(stg.frac_vol_fine[i, j]))) + self.tableWidget_fine.setItem( + i, 2, QTableWidgetItem(str(stg.time_fine[i])) + ) + self.tableWidget_fine.setItem( + i, 3, QTableWidgetItem(str(stg.depth_fine[i])) + ) + self.tableWidget_fine.setItem( + i, 4, QTableWidgetItem(str(stg.Ctot_fine[i])) + ) + self.tableWidget_fine.setItem( + i, 5, QTableWidgetItem(str(stg.D50_fine[i])) + ) + self.tableWidget_fine.setItem( + i, j + 6, QTableWidgetItem(str(stg.frac_vol_fine[i, j])) + ) # --- Connect checkbox to all checkboxes of tableWidget --- # self.allChkBox.stateChanged.connect(self.check_allChkBox) @@ -422,7 +473,6 @@ class SampleDataTab(QWidget): self.plot_sample_position_on_transect() self.plot_total_concentration() self.plot_PSD_fine_and_sand_sediments() - else: msgBox = QMessageBox() msgBox.setWindowTitle("Fill table Error") @@ -433,35 +483,47 @@ class SampleDataTab(QWidget): def fill_table_sand(self): if self.lineEdit_sand_sediment.text(): - self.row_sand = self.tableWidget_sand.setRowCount(len(stg.depth_sand)) self.column_sand = self.tableWidget_sand.setColumnCount(6 + stg.radius_grain_sand.shape[0]) - # --- Set horizontal header --- - - horizontal_header = list(itertools.chain(["Color", "Sample"], - list(map(str, stg.columns_sand[[0, 2]])), - list(map(str, stg.columns_sand[3:])))) + horizontal_header = list( + itertools.chain( + ["Color", "Sample"], + list(map(str, stg.columns_sand[[0, 2]])), + list(map(str, stg.columns_sand[3:])) + ) + ) for horizontal_header_text in horizontal_header: self.horizontal_header_item_sand = QTableWidgetItem() - self.tableWidget_sand.setHorizontalHeaderItem(horizontal_header.index(horizontal_header_text), - self.horizontal_header_item_sand) + self.tableWidget_sand.setHorizontalHeaderItem( + horizontal_header.index(horizontal_header_text), + self.horizontal_header_item_sand + ) self.horizontal_header_item_sand.setText(horizontal_header_text) # --- Set vertical header (color) --- self.tableWidget_sand.verticalHeader().setVisible(False) color_list = BASE_COLORS + + self.comboBox_sample_table_sand = [] for i in range(self.tableWidget_sand.rowCount()): - exec("self.comboBox_sample_table_sand" + str(i) + "= QComboBox()") - exec("self.comboBox_sample_table_sand" + str(i) + ".addItems(color_list)") - eval(f"self.tableWidget_sand.setCellWidget(i, 0, self.comboBox_sample_table_sand{i})") - eval(f"self.comboBox_sample_table_sand{i}.currentTextChanged." - f"connect(self.plot_total_concentration)") - eval(f"self.comboBox_sample_table_sand{i}.currentTextChanged." - f"connect(self.plot_PSD_fine_and_sand_sediments)") - eval(f"self.comboBox_sample_table_sand{i}.currentTextChanged." - f"connect(self.update_plot_sample_position_on_transect)") + self.comboBox_sample_table_sand.append(QComboBox()) + + self.comboBox_sample_table_sand[i].addItems(color_list) + self.tableWidget_sand.setCellWidget( + i, 0, self.comboBox_sample_table_sand[i] + ) + + self.comboBox_sample_table_sand[i]\ + .currentTextChanged\ + .connect(self.plot_total_concentration) + self.comboBox_sample_table_sand[i]\ + .currentTextChanged\ + .connect(self.plot_PSD_fine_and_sand_sediments) + self.comboBox_sample_table_sand[i]\ + .currentTextChanged\ + .connect(self.update_plot_sample_position_on_transect) # --- Fill Sample column with checkbox --- for i in range(self.tableWidget_sand.rowCount()): @@ -474,20 +536,37 @@ class SampleDataTab(QWidget): # --- Fill table with data --- for i in range(stg.frac_vol_sand.shape[0]): for j in range(stg.frac_vol_sand.shape[1]): - self.tableWidget_sand.setItem(i, 2, QTableWidgetItem(str(stg.time_sand[i]))) - self.tableWidget_sand.setItem(i, 3, QTableWidgetItem(str(stg.depth_sand[i]))) - - self.tableWidget_sand.setItem(i, 4, QTableWidgetItem(str(stg.Ctot_sand[i]))) - self.tableWidget_sand.setItem(i, 5, QTableWidgetItem(str(stg.D50_sand[i]))) - self.tableWidget_sand.setItem(i, j + 6, QTableWidgetItem(str(stg.frac_vol_sand[i, j]))) + self.tableWidget_sand.setItem( + i, 2, QTableWidgetItem(str(stg.time_sand[i])) + ) + self.tableWidget_sand.setItem( + i, 3, QTableWidgetItem(str(stg.depth_sand[i])) + ) + self.tableWidget_sand.setItem( + i, 4, QTableWidgetItem(str(stg.Ctot_sand[i])) + ) + self.tableWidget_sand.setItem( + i, 5, QTableWidgetItem(str(stg.D50_sand[i])) + ) + self.tableWidget_sand.setItem( + i, j + 6, QTableWidgetItem(str(stg.frac_vol_sand[i, j])) + ) # --- Connect checkbox items of tableWidget to update plots --- - self.tableWidget_sand.itemChanged.connect(self.update_plot_sample_position_on_transect) - self.tableWidget_sand.itemChanged.connect(self.plot_total_concentration) - self.tableWidget_sand.itemChanged.connect(self.plot_PSD_fine_and_sand_sediments) + self.tableWidget_sand\ + .itemChanged\ + .connect(self.update_plot_sample_position_on_transect) + self.tableWidget_sand\ + .itemChanged\ + .connect(self.plot_total_concentration) + self.tableWidget_sand\ + .itemChanged\ + .connect(self.plot_PSD_fine_and_sand_sediments) - self.combobox_x_axis.currentIndexChanged.connect(self.plot_total_concentration) - self.combobox_y_axis.currentIndexChanged.connect(self.plot_total_concentration) + self.combobox_x_axis.currentIndexChanged\ + .connect(self.plot_total_concentration) + self.combobox_y_axis.currentIndexChanged\ + .connect(self.plot_total_concentration) self.plot_sample_position_on_transect() self.plot_total_concentration() @@ -502,7 +581,7 @@ class SampleDataTab(QWidget): if self.tableWidget_fine.item(i, 1).checkState() == 2: if self.tableWidget_fine.item(i, 1).checkState() == Qt.Checked: position.append(i) - eval(f"color_list.append(self.comboBox_sample_table_fine{i}.currentText())") + color_list.append(self.comboBox_sample_table_fine[i].currentText()) sample_checkbox[0, i] = 2 return position, color_list @@ -570,7 +649,9 @@ class SampleDataTab(QWidget): if self.tableWidget_sand.item(i, 1).checkState() == 2: if self.tableWidget_sand.item(i, 1).checkState() == Qt.Checked: position.append(i) - eval(f"color_list.append(self.comboBox_sample_table_sand{i}.currentText())") + color_list.append( + self.comboBox_sample_table_sand[i].currentText() + ) sample_checkbox[0, i] = 2 return position, color_list @@ -646,7 +727,6 @@ class SampleDataTab(QWidget): self.combobox_acoustic_data.showPopup() def fill_comboboxes_and_plot_transect(self): - self.combobox_acoustic_data.clear() for n, m in enumerate(stg.noise_method): if stg.noise_method[n] == 0: @@ -659,19 +739,23 @@ class SampleDataTab(QWidget): self.combobox_frequencies.currentIndexChanged.connect(self.update_plot_sample_position_on_transect) def plot_sample_position_on_transect(self): + self.verticalLayout_groupbox_plot_transect\ + .removeWidget(self.canvas_plot_sample_position_on_transect) - self.verticalLayout_groupbox_plot_transect.removeWidget(self.canvas_plot_sample_position_on_transect) + fig, axis = plt.subplots(nrows=1, ncols=1, layout="constrained") - self.figure_plot_sample_position_on_transect, self.axis_plot_sample_position_on_transect = \ - plt.subplots(nrows=1, ncols=1, layout="constrained") - self.canvas_plot_sample_position_on_transect = FigureCanvas(self.figure_plot_sample_position_on_transect) + self.figure_plot_sample_position_on_transect = fig + self.axis_plot_sample_position_on_transect = axis - self.verticalLayout_groupbox_plot_transect.addWidget(self.canvas_plot_sample_position_on_transect) + self.canvas_plot_sample_position_on_transect = FigureCanvas( + self.figure_plot_sample_position_on_transect + ) + + self.verticalLayout_groupbox_plot_transect\ + .addWidget(self.canvas_plot_sample_position_on_transect) if self.combobox_acoustic_data.count() == 0: - if self.tableWidget_fine.columnCount() > 10: - position_list_fine, color_list_fine = self.extract_position_list_and_color_list_from_table_checkboxes_fine() self.axis_plot_sample_position_on_transect.scatter( @@ -1696,4 +1780,3 @@ class SampleDataTab(QWidget): self.axis_plot_PSD[1].set_ylabel('Cumulative size volume fraction') self.figure_plot_PSD.canvas.draw_idle() - From a5268c6214e68fd16d4b6a5e847d29c70a5dd2d1 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby Date: Tue, 11 Mar 2025 11:35:52 +0100 Subject: [PATCH 11/11] Sample data: Fix #29. --- View/sample_data_tab.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/View/sample_data_tab.py b/View/sample_data_tab.py index 4eec985..8e42dd0 100644 --- a/View/sample_data_tab.py +++ b/View/sample_data_tab.py @@ -382,6 +382,8 @@ class SampleDataTab(QWidget): # ------------------------------------------------------------------------------------------------------------------ # --- Function to fill table of values --- def fill_table_fine(self): + self.tableWidget_fine.blockSignals(True) + if self.lineEdit_fine_sediment.text(): self.row_fine = self.tableWidget_fine.setRowCount( len(stg.depth_fine) @@ -473,6 +475,8 @@ class SampleDataTab(QWidget): self.plot_sample_position_on_transect() self.plot_total_concentration() self.plot_PSD_fine_and_sand_sediments() + + self.tableWidget_fine.blockSignals(False) else: msgBox = QMessageBox() msgBox.setWindowTitle("Fill table Error") @@ -482,6 +486,8 @@ class SampleDataTab(QWidget): msgBox.exec() def fill_table_sand(self): + self.tableWidget_sand.blockSignals(True) + if self.lineEdit_sand_sediment.text(): self.row_sand = self.tableWidget_sand.setRowCount(len(stg.depth_sand)) self.column_sand = self.tableWidget_sand.setColumnCount(6 + stg.radius_grain_sand.shape[0]) @@ -572,6 +578,8 @@ class SampleDataTab(QWidget): self.plot_total_concentration() self.plot_PSD_fine_and_sand_sediments() + self.tableWidget_sand.blockSignals(False) + # --- Function to extract position of sample from table checkboxes to update plots --- def extract_position_list_and_color_list_from_table_checkboxes_fine(self): position = []