Sediment calibration: Some refactoring.

dev
Pierre-Antoine 2025-04-29 10:07:45 +02:00
parent fbda28eb86
commit 0b10926978
1 changed files with 58 additions and 58 deletions

View File

@ -67,7 +67,9 @@ class SedimentCalibrationTab(QWidget):
self._setup_widgets() self._setup_widgets()
def _path_icon(self, icon): def _path_icon(self, icon):
return os.path.join("icons", icon) return os.path.join(
os.path.dirname(__file__), "..", "icons", icon
)
def _setup_icons(self): def _setup_icons(self):
self.icon_folder = QIcon(self._path_icon("folder.png")) self.icon_folder = QIcon(self._path_icon("folder.png"))
@ -2065,88 +2067,86 @@ class SedimentCalibrationTab(QWidget):
stg.alpha_s = [alpha_s_freq1, alpha_s_freq2] stg.alpha_s = [alpha_s_freq1, alpha_s_freq2]
logger.debug(f"\u03B1s for frequency of freq1 : {alpha_s_freq1:.2f} /m \n") logger.debug(
logger.debug(f"\u03B1s for frequency of freq2 : {alpha_s_freq2:.2f} /m") f"\u03B1s for frequency of freq1 : {alpha_s_freq1:.2f} / m"
)
logger.debug(
f"\u03B1s for frequency of freq2 : {alpha_s_freq2:.2f} / m"
)
self.lineEdit_alphas_freq1.clear() self.lineEdit_alphas_freq1.clear()
self.lineEdit_alphas_freq1.setText(str("%.5f" % alpha_s_freq1)) self.lineEdit_alphas_freq1.setText(f"{alpha_s_freq1:.5f}")
self.lineEdit_alphas_freq2.clear() self.lineEdit_alphas_freq2.clear()
self.lineEdit_alphas_freq2.setText(str("%.5f" % alpha_s_freq2)) self.lineEdit_alphas_freq2.setText(f"{alpha_s_freq2:.5f}")
title = "Alpha computation error"
icon = self._path_icon("no_approved.png")
if (alpha_s_freq1 < 0) or (alpha_s_freq2 < 0): if (alpha_s_freq1 < 0) or (alpha_s_freq2 < 0):
text = "Sediment sound attenuation is negative !"
msgBox = QMessageBox()
msgBox.setWindowTitle("Alpha computation error")
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()
elif isinf(alpha_s_freq1) or isinf(alpha_s_freq2): elif isinf(alpha_s_freq1) or isinf(alpha_s_freq2):
text = "Sediment sound attenuation is infinite !"
msgBox = QMessageBox()
msgBox.setWindowTitle("Alpha computation error")
msgBox.setIconPixmap(
QPixmap(self._path_icon("no_approved.png")).scaledToHeight(32, Qt.SmoothTransformation))
msgBox.setText("Sediment sound attenuation is infinite !")
msgBox.setStandardButtons(QMessageBox.Ok)
msgBox.exec()
else: else:
title = "Alpha computation validation"
icon = self._path_icon("approved.png")
text = "Sediment sound attenuation is positive."
msgBox = QMessageBox() msgBox = QMessageBox()
msgBox.setWindowTitle("Alpha computation validation") msgBox.setWindowTitle(title)
msgBox.setIconPixmap(QPixmap(self._path_icon("approved.png")).scaledToHeight(32, Qt.SmoothTransformation)) msgBox.setIconPixmap(
msgBox.setText("Sediment sound attenuation is positive.") QPixmap(icon).scaledToHeight(
32, Qt.SmoothTransformation
)
)
msgBox.setText(text)
msgBox.setStandardButtons(QMessageBox.Ok) msgBox.setStandardButtons(QMessageBox.Ok)
msgBox.exec() msgBox.exec()
def compute_zeta(self): def compute_zeta(self):
# --- Compute zeta ---
if stg.M_profile_fine.shape == (0,): if stg.M_profile_fine.shape == (0,):
msgBox = QMessageBox() msgBox = QMessageBox()
msgBox.setWindowTitle("Zeta computation error") msgBox.setWindowTitle("Zeta computation error")
msgBox.setIcon(QMessageBox.Warning) msgBox.setIcon(QMessageBox.Warning)
msgBox.setText("Please interpolate fine profile") msgBox.setText("Please interpolate fine profile")
msgBox.setStandardButtons(QMessageBox.Ok) msgBox.setStandardButtons(QMessageBox.Ok)
msgBox.exec() msgBox.exec()
return
data_id = self.combobox_acoustic_data_choice.currentIndex()
freq_1 = self.combobox_freq1.currentIndex()
freq_2 = self.combobox_freq2.currentIndex()
if stg.depth_cross_section[data_id].shape != (0,):
depth_data = stg.depth_cross_section
else: else:
depth_data = stg.depth
if stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,): zeta_freq1 = self.inv_hc.zeta(
alpha_s = stg.alpha_s[0],
zeta_freq1 = self.inv_hc.zeta(alpha_s=stg.alpha_s[0], r = depth_data[data_id][freq_1, :],
r=stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()][ M_profile_fine = stg.M_profile_fine
self.combobox_freq1.currentIndex(), :], )
M_profile_fine=stg.M_profile_fine) zeta_freq2 = self.inv_hc.zeta(
zeta_freq2 = self.inv_hc.zeta(alpha_s=stg.alpha_s[1], alpha_s = stg.alpha_s[1],
r=stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()][ r = depth_data[data_id][freq_2, :],
self.combobox_freq2.currentIndex(), :], M_profile_fine = stg.M_profile_fine
M_profile_fine=stg.M_profile_fine) )
else:
zeta_freq1 = self.inv_hc.zeta(alpha_s=stg.alpha_s[0],
r=stg.depth[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq1.currentIndex(), :],
M_profile_fine=stg.M_profile_fine)
zeta_freq2 = self.inv_hc.zeta(alpha_s=stg.alpha_s[1],
r=stg.depth[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), :],
M_profile_fine=stg.M_profile_fine)
stg.zeta = [zeta_freq1, zeta_freq2] stg.zeta = [zeta_freq1, zeta_freq2]
logger.debug(f"\u03B6 for frequency of freq1 : {zeta_freq1:.3f} /m \n") logger.debug(
logger.debug(f"\u03B6 for frequency of freq2 : {zeta_freq2:.3f} /m") f"\u03B6 for frequency of freq1 : {zeta_freq1:.3f} / m"
)
logger.debug(
f"\u03B6 for frequency of freq2 : {zeta_freq2:.3f} / m"
)
self.lineEdit_zeta_freq1.clear() self.lineEdit_zeta_freq1.clear()
self.lineEdit_zeta_freq1.setText(str("%.5f" % zeta_freq1)) self.lineEdit_zeta_freq1.setText(f"{zeta_freq1:.5f}")
self.lineEdit_zeta_freq2.clear() self.lineEdit_zeta_freq2.clear()
self.lineEdit_zeta_freq2.setText(str("%.5f" % zeta_freq2)) self.lineEdit_zeta_freq2.setText(f"{zeta_freq2:.5f}")
def save_calibration(self): def save_calibration(self):
data_id = self.combobox_acoustic_data_choice.currentIndex() data_id = self.combobox_acoustic_data_choice.currentIndex()