correction merge and correction interpolate fine profile

dev-brahim
brahim 2025-03-11 16:44:14 +01:00
parent baebe2e8cc
commit b28978311c
1 changed files with 107 additions and 85 deletions

View File

@ -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,):
if stg.depth_cross_section[data_choice].shape != (0,):
depth_data = stg.depth_cross_section
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.time_cross_section[data_choice].shape != (0,):
time_data = stg.time_cross_section
else:
time_data = stg.time
else:
depth_data = stg.depth
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]
)
if stg.time_cross_section[data_choice].shape != (0,):
time_data = stg.time_cross_sectino
else:
time_data = stg.time
self.interpolate_Mfine_profile_compute(
data_choice, depth_data, time_data
)
else:
def interpolate_Mfine_profile_compute(self, data_choice, depth_data, time_data):
range_cells = depth_data[data_choice][
self.combobox_freq2.currentIndex(), :
]
if stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (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]
] 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=[-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]
))
else:
stg.range_lin_interp, stg.M_profile_fine = (
self.inv_hc.M_profile_SCC_fine_interpolated(
sample_depth=[-stg.depth_fine[k[1]] for k in stg.fine_sample_profile],
M_profile=[stg.Ctot_fine[k[1]] for k in stg.fine_sample_profile],
range_cells=stg.depth[self.combobox_acoustic_data_choice.currentIndex()][self.combobox_freq2.currentIndex(), :],
r_bottom=[stg.depth_bottom[self.combobox_acoustic_data_choice.currentIndex()]
[
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]
))
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]]],