Fix acoustic data loading without selection #3.

dev-brahim
Pierre-Antoine 2025-03-06 10:47:54 +01:00
parent 5ebd842346
commit 52b612ba3e
1 changed files with 59 additions and 44 deletions

View File

@ -21,11 +21,18 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from PyQt5.QtWidgets import (QWidget, QVBoxLayout, QHBoxLayout, QGroupBox, QPushButton, QComboBox, QLineEdit, QLabel, from PyQt5.QtWidgets import (
QGridLayout, QTableView, QSpacerItem, QSizePolicy, QFileDialog, QMessageBox, QScrollArea, QWidget, QVBoxLayout, QHBoxLayout, QGroupBox,
QSlider, QMenu, QCheckBox) QPushButton, QComboBox, QLineEdit, QLabel,
QGridLayout, QTableView, QSpacerItem, QSizePolicy,
QFileDialog, QMessageBox, QScrollArea,
QSlider, QMenu, QCheckBox
)
from PyQt5.QtGui import QPixmap, QIcon from PyQt5.QtGui import QPixmap, QIcon
from PyQt5.QtCore import Qt, QCoreApplication, pyqtSignal, QEvent, QSize, QPropertyAnimation from PyQt5.QtCore import (
Qt, QCoreApplication, pyqtSignal, QEvent, QSize,
QPropertyAnimation
)
import numpy as np import numpy as np
import pandas as pd import pandas as pd
@ -35,7 +42,7 @@ from matplotlib.colors import LogNorm, CSS4_COLORS, BoundaryNorm
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolBar from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolBar
from os import path import os
from copy import deepcopy from copy import deepcopy
import locale import locale
@ -1232,71 +1239,76 @@ class AcousticDataTab(QWidget):
self.combobox_frequency_information.currentIndex()])) self.combobox_frequency_information.currentIndex()]))
def open_dialog_box(self): def open_dialog_box(self):
abs_params = [
(None, None),
("AQUAscat file", "Aquascat file (*.aqa)"),
("UBSediFlow file", "UBSediFlow file (*.udt)"),
]
# --- Open dialog box + choice directory and select file ---
if self.combobox_ABS_system_choice.currentIndex() == 0: system = self.combobox_ABS_system_choice.currentIndex()
if system == 0:
msgBox = QMessageBox() msgBox = QMessageBox()
msgBox.setWindowTitle("Download Error") msgBox.setWindowTitle("Download Error")
msgBox.setIcon(QMessageBox.Warning) msgBox.setIcon(QMessageBox.Warning)
msgBox.setText("Choose ABS system before download acoustic files") msgBox.setText("Choose ABS system before download acoustic files")
msgBox.setStandardButtons(QMessageBox.Ok) msgBox.setStandardButtons(QMessageBox.Ok)
msgBox.exec() msgBox.exec()
elif self.combobox_ABS_system_choice.currentIndex() == 1: else:
abs_name, abs_file_type = abs_params[system]
filename = QFileDialog.getOpenFileNames(self, "AQUAscat file", filenames, _ = QFileDialog.getOpenFileNames(
[stg.path_BS_raw_data[-1] if self.fileListWidget.count() > 0 else ""][0], self, abs_name,
"Aquascat file (*.aqa)", [
options=QFileDialog.DontUseNativeDialog) stg.path_BS_raw_data[-1]
if self.fileListWidget.count() > 0
else ""
][0],
abs_file_type,
options=QFileDialog.DontUseNativeDialog
)
for n in filename[0]: if len(filenames) == 0:
return
stg.path_BS_raw_data.append(path.dirname(n)) for n in filenames:
stg.filename_BS_raw_data.append(path.basename(n)) stg.path_BS_raw_data.append(os.path.dirname(n))
stg.data_preprocessed.append(path.basename(n)) stg.filename_BS_raw_data.append(os.path.basename(n))
stg.data_preprocessed.append(os.path.basename(n))
elif self.combobox_ABS_system_choice.currentIndex() == 2: self.open_acoustic_data()
filename = QFileDialog.getOpenFileNames(self, "UBSediFlow file",
[stg.path_BS_raw_data[-1] if self.fileListWidget.count() > 0 else ""][0],
"UBSediFlow file (*.udt)",
options=QFileDialog.DontUseNativeDialog)
for n in filename[0]:
stg.path_BS_raw_data.append(path.dirname(n))
stg.filename_BS_raw_data.append(path.basename(n))
stg.data_preprocessed.append(path.basename(n))
def open_acoustic_data(self):
# --- Fill lineEdit with path and file names + load acoustic data --- # --- Fill lineEdit with path and file names + load acoustic data ---
# --- fill date, hour and measurements information + fill frequency combobox for bottom detection --- # --- fill date, hour and measurements information + fill frequency combobox for bottom detection ---
if self.combobox_ABS_system_choice.currentIndex() != 0: system = self.combobox_ABS_system_choice.currentIndex()
if system != 0:
try: try:
self.load_BS_acoustic_raw_data() self.load_BS_acoustic_raw_data()
except ValueError as e: except ValueError as e:
msgBox = QMessageBox() msgBox = QMessageBox()
msgBox.setWindowTitle("Download Error") msgBox.setWindowTitle("Download Error")
msgBox.setIcon(QMessageBox.Warning) msgBox.setIcon(QMessageBox.Warning)
msgBox.setText("Please select a file") msgBox.setText("Please select a file")
msgBox.setStandardButtons(QMessageBox.Ok) msgBox.setStandardButtons(QMessageBox.Ok)
msgBox.exec() msgBox.exec()
else: else:
if self.fileListWidget.count() == 0: if self.fileListWidget.count() == 0:
for p, f in zip(stg.path_BS_raw_data,
for p, f in zip(stg.path_BS_raw_data, stg.filename_BS_raw_data): stg.filename_BS_raw_data):
self.fileListWidget.addFilenames([f]) self.fileListWidget.addFilenames([f])
self.fileListWidget.setToolTip(p) self.fileListWidget.setToolTip(p)
else: else:
for k in range(self.fileListWidget.count(),
for k in range(self.fileListWidget.count(), len(stg.filename_BS_raw_data), 1): len(stg.filename_BS_raw_data),
self.fileListWidget.addFilenames([stg.filename_BS_raw_data[k]]) 1):
self.fileListWidget.setToolTip(stg.path_BS_raw_data[k]) self.fileListWidget.addFilenames(
[stg.filename_BS_raw_data[k]]
)
self.fileListWidget.setToolTip(
stg.path_BS_raw_data[k]
)
self.fill_measurements_information_groupbox() self.fill_measurements_information_groupbox()
self.fill_table() self.fill_table()
@ -1304,7 +1316,11 @@ class AcousticDataTab(QWidget):
self.update_frequency_combobox() self.update_frequency_combobox()
self.water_attenuation() self.water_attenuation()
stg.acoustic_data = list(range(self.fileListWidget.count())) stg.acoustic_data = list(
range(
self.fileListWidget.count()
)
)
def rename_file_in_ListWidget(self, event): def rename_file_in_ListWidget(self, event):
@ -2719,4 +2735,3 @@ class AcousticDataTab(QWidget):
self.update_plot_profile() self.update_plot_profile()
self.fig_BS.canvas.draw_idle() self.fig_BS.canvas.draw_idle()