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 -*-
from PyQt5.QtWidgets import (QWidget, QVBoxLayout, QHBoxLayout, QGroupBox, QPushButton, QComboBox, QLineEdit, QLabel,
QGridLayout, QTableView, QSpacerItem, QSizePolicy, QFileDialog, QMessageBox, QScrollArea,
QSlider, QMenu, QCheckBox)
from PyQt5.QtWidgets import (
QWidget, QVBoxLayout, QHBoxLayout, QGroupBox,
QPushButton, QComboBox, QLineEdit, QLabel,
QGridLayout, QTableView, QSpacerItem, QSizePolicy,
QFileDialog, QMessageBox, QScrollArea,
QSlider, QMenu, QCheckBox
)
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 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 NavigationToolbar2QT as NavigationToolBar
from os import path
import os
from copy import deepcopy
import locale
@ -1232,71 +1239,76 @@ class AcousticDataTab(QWidget):
self.combobox_frequency_information.currentIndex()]))
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.setWindowTitle("Download Error")
msgBox.setIcon(QMessageBox.Warning)
msgBox.setText("Choose ABS system before download acoustic files")
msgBox.setStandardButtons(QMessageBox.Ok)
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",
[stg.path_BS_raw_data[-1] if self.fileListWidget.count() > 0 else ""][0],
"Aquascat file (*.aqa)",
options=QFileDialog.DontUseNativeDialog)
filenames, _ = QFileDialog.getOpenFileNames(
self, abs_name,
[
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))
stg.filename_BS_raw_data.append(path.basename(n))
stg.data_preprocessed.append(path.basename(n))
for n in filenames:
stg.path_BS_raw_data.append(os.path.dirname(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:
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))
self.open_acoustic_data()
def open_acoustic_data(self):
# --- Fill lineEdit with path and file names + load acoustic data ---
# --- 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:
self.load_BS_acoustic_raw_data()
except ValueError as e:
msgBox = QMessageBox()
msgBox.setWindowTitle("Download Error")
msgBox.setIcon(QMessageBox.Warning)
msgBox.setText("Please select a file")
msgBox.setStandardButtons(QMessageBox.Ok)
msgBox.exec()
else:
if self.fileListWidget.count() == 0:
for p, f in zip(stg.path_BS_raw_data, stg.filename_BS_raw_data):
for p, f in zip(stg.path_BS_raw_data,
stg.filename_BS_raw_data):
self.fileListWidget.addFilenames([f])
self.fileListWidget.setToolTip(p)
else:
for k in range(self.fileListWidget.count(), len(stg.filename_BS_raw_data), 1):
self.fileListWidget.addFilenames([stg.filename_BS_raw_data[k]])
self.fileListWidget.setToolTip(stg.path_BS_raw_data[k])
for k in range(self.fileListWidget.count(),
len(stg.filename_BS_raw_data),
1):
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_table()
@ -1304,7 +1316,11 @@ class AcousticDataTab(QWidget):
self.update_frequency_combobox()
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):
@ -2719,4 +2735,3 @@ class AcousticDataTab(QWidget):
self.update_plot_profile()
self.fig_BS.canvas.draw_idle()