From 73bf3cf9d32dadfaecb3bad4554e394682851e2c Mon Sep 17 00:00:00 2001 From: brahim Date: Tue, 11 Mar 2025 11:39:09 +0100 Subject: [PATCH 1/3] The user can reload signal processing after acoustic data boundaries values modification without crash #8 --- View/signal_processing_tab.py | 7 +++++-- main.py | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/View/signal_processing_tab.py b/View/signal_processing_tab.py index 3d29e53..83eda72 100644 --- a/View/signal_processing_tab.py +++ b/View/signal_processing_tab.py @@ -641,6 +641,9 @@ class SignalProcessingTab(QWidget): stg.BS_mean[self.combobox_acoustic_data_choice.currentIndex()] = ( np.nanmean(stg.BS_raw_data[self.combobox_acoustic_data_choice.currentIndex()][:, :, val1:val2], axis=2)) + if stg.BS_noise_raw_data[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,): + self.compute_noise_from_profile_tail_value() + def plot_averaged_profile_tail(self): # --- Plot averaged signal --- @@ -926,7 +929,7 @@ class SignalProcessingTab(QWidget): # --- Compute noise from value and compute SNR --- if stg.BS_stream_bed[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,): - + stg.BS_noise_raw_data[self.combobox_acoustic_data_choice.currentIndex()] = np.array([]) stg.BS_noise_raw_data[self.combobox_acoustic_data_choice.currentIndex()] = ( np.full(stg.BS_stream_bed[self.combobox_acoustic_data_choice.currentIndex()].shape, float(self.lineEdit_profile_tail_value.text().replace(",", ".")))) @@ -986,7 +989,7 @@ class SignalProcessingTab(QWidget): self.plot_pre_processed_BS_signal() self.plot_pre_processed_profile() - self.activate_list_of_pre_processed_data() + # self.activate_list_of_pre_processed_data() def plot_noise(self): self.horizontalLayout_groupbox_plot_noise_data.removeWidget(self.canvas_noise) diff --git a/main.py b/main.py index e747805..caca3fb 100644 --- a/main.py +++ b/main.py @@ -33,7 +33,8 @@ logging.basicConfig( ) logger = logging.getLogger() -logger.setLevel(logging.DEBUG) +# logger.setLevel(logging.DEBUG) +logger.setLevel(logging.INFO) class MainApplication(QMainWindow): @@ -53,7 +54,6 @@ class MainApplication(QMainWindow): # -------------- Acoustic data tab --------------- self.acoustic_data_tab = AcousticDataTab(self.ui_mainwindow.tab1) - print("0 AcousticDataTab ", id(AcousticDataTab)) self.acoustic_data_tab\ .combobox_ABS_system_choice\ From baebe2e8cc21b453efcf6bbfc58f7b1ef1f01511 Mon Sep 17 00:00:00 2001 From: brahim Date: Tue, 11 Mar 2025 15:32:39 +0100 Subject: [PATCH 2/3] interpolate Mifine profile is corrected with depth_bottom --- View/sediment_calibration_tab.py | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/View/sediment_calibration_tab.py b/View/sediment_calibration_tab.py index eba470b..82ba174 100644 --- a/View/sediment_calibration_tab.py +++ b/View/sediment_calibration_tab.py @@ -1276,13 +1276,6 @@ class SedimentCalibrationTab(QWidget): 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 = ( @@ -1290,13 +1283,13 @@ class SedimentCalibrationTab(QWidget): 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()] + 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 len(stg.depth_bottom[self.combobox_acoustic_data_choice.currentIndex()]) != 0 else np.array([])][0] ) ) @@ -1307,13 +1300,13 @@ class SedimentCalibrationTab(QWidget): 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()] + 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] - ] + ] if len(stg.depth_bottom[self.combobox_acoustic_data_choice.currentIndex()]) else np.array([])][0] ) ) @@ -1326,7 +1319,7 @@ class SedimentCalibrationTab(QWidget): 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()] + 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(), :] @@ -1335,7 +1328,7 @@ class SedimentCalibrationTab(QWidget): 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 len(stg.depth_bottom[self.combobox_acoustic_data_choice.currentIndex()]) != 0 else np.array([])][0] )) else: @@ -1345,7 +1338,7 @@ class SedimentCalibrationTab(QWidget): 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()] + 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(), :] @@ -1354,7 +1347,7 @@ class SedimentCalibrationTab(QWidget): stg.time[self.combobox_acoustic_data_choice.currentIndex()][ self.combobox_freq2.currentIndex(), :] - stg.time_fine[stg.fine_sample_profile[-1][1]])))[0][0] - ] + ] if len(stg.depth_bottom[self.combobox_acoustic_data_choice.currentIndex()]) else np.array([])][0] )) stg.range_lin_interp = stg.range_lin_interp From b28978311c6f1bb46b77546750fec3d088dadbc3 Mon Sep 17 00:00:00 2001 From: brahim Date: Tue, 11 Mar 2025 16:44:14 +0100 Subject: [PATCH 3/3] correction merge and correction interpolate fine profile --- View/sediment_calibration_tab.py | 192 +++++++++++++++++-------------- 1 file changed, 107 insertions(+), 85 deletions(-) diff --git a/View/sediment_calibration_tab.py b/View/sediment_calibration_tab.py index 82ba174..141d8dc 100644 --- a/View/sediment_calibration_tab.py +++ b/View/sediment_calibration_tab.py @@ -19,32 +19,35 @@ # ============================================================================== # # -*- 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 PyQt5.QtWidgets import (QWidget, QVBoxLayout, QHBoxLayout, QGroupBox, QComboBox, - QGridLayout, QLabel, QPushButton, QSlider, QLineEdit, QFileDialog, QMessageBox, QFrame) +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, + QFileDialog, QMessageBox, QFrame +) from PyQt5.QtCore import Qt, QPropertyAnimation, QSize 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 os import path - from View.checkable_combobox import CheckableComboBox - from Model.acoustic_inversion_method_high_concentration import AcousticInversionMethodHighConcentration +logger = logging.getLogger() + class SedimentCalibrationTab(QWidget): @@ -1273,89 +1276,108 @@ class SedimentCalibrationTab(QWidget): marker="*", mfc="b", mec="b", ms=8, ls="None") def interpolate_Mfine_profile(self): + # Variable 'stg.sand_sample_target_indice' is set only at + # 'plot sample' button click + if len(stg.sand_sample_target_indice) == 0: + self._data_validity_message_box() + return - if stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,): + data_choice = self.combobox_acoustic_data_choice \ + .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_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 len(stg.depth_bottom[self.combobox_acoustic_data_choice.currentIndex()]) != 0 else np.array([])][0] - ) - ) + if stg.depth_cross_section[data_choice].shape != (0,): + depth_data = stg.depth_cross_section + 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] - ] if len(stg.depth_bottom[self.combobox_acoustic_data_choice.currentIndex()]) else np.array([])][0] - ) - ) + time_data = stg.time else: + depth_data = stg.depth - 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 len(stg.depth_bottom[self.combobox_acoustic_data_choice.currentIndex()]) != 0 else np.array([])][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] - ] if len(stg.depth_bottom[self.combobox_acoustic_data_choice.currentIndex()]) else np.array([])][0] - )) + 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( + 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] + ] if len(stg.depth_bottom[data_choice])!=0 else np.array([])][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 - 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() + def _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 --------------- # ------------------------------------------------------------------ @@ -1417,8 +1439,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 @@ -2020,7 +2042,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]]],