Compare commits

..

No commits in common. "17619f15acbd0f0ea08267adc6863a47dd8df572" and "b80e0f3c8ea0ae69d65a9fe2f5c9ec37c81afb41" have entirely different histories.

7 changed files with 338 additions and 408 deletions

View File

@ -20,19 +20,15 @@
# -*- coding: utf-8 -*-
import os
import time
import sqlite3
import logging
import numpy as np
from PyQt5.QtWidgets import QFileDialog, QApplication, QMessageBox
import sqlite3
import settings as stg
from settings import ABS_name
from os import chdir
import time
logger = logging.getLogger()
from settings import ABS_name
class CreateTableForSaveAs:
@ -169,32 +165,23 @@ class CreateTableForSaveAs:
def open_file_dialog(self):
name, _ = QFileDialog.getSaveFileName(
caption="Save As",
directory="",
filter="AcouSed Files (*.acd)",
options=QFileDialog.DontUseNativeDialog
)
options = QFileDialog.Options()
name = QFileDialog.getSaveFileName(
caption="Save As", directory="", filter="AcouSed Files (*.acd)", options=QFileDialog.DontUseNativeDialog)
if name != "":
filename = os.path.basename(name)
if os.path.splitext(filename)[1] != ".acd":
filename += ".acd"
if name[0]:
logger.debug(f"selected save file: '{filename}'")
stg.dirname_save_as = "/".join(name[0].split("/")[:-1]) + "/"
stg.filename_save_as = name[0].split("/")[-1]
stg.dirname_save_as = os.path.dirname(name)
stg.filename_save_as = filename
try:
os.chdir(stg.dirname_save_as)
except OSError as e:
logger.warning(f"chdir: {str(e)}")
chdir(stg.dirname_save_as)
start = time.time()
self.create_table()
print(f"end : {time.time() - start} sec")
else:
msgBox = QMessageBox()
msgBox.setWindowTitle("Save Error")
msgBox.setIcon(QMessageBox.Warning)
@ -205,7 +192,7 @@ class CreateTableForSaveAs:
def create_table(self):
# Create a new database and open a database connection to allow sqlite3 to work with it.
cnx = sqlite3.connect(stg.filename_save_as)
cnx = sqlite3.connect(stg.filename_save_as + '.acd')
# Create database cursor to execute SQL statements and fetch results from SQL queries.
cur = cnx.cursor()
@ -472,3 +459,6 @@ class CreateTableForSaveAs:
# Close database connection
cnx.close()

View File

@ -20,50 +20,37 @@
# -*- coding: utf-8 -*-
import os
import sys
import sqlite3
import logging
import numpy as np
from PyQt5.QtWidgets import QFileDialog, QApplication, QWidget, QTabWidget
import sqlite3
from os import path, chdir
import settings as stg
from settings import BS_raw_data, acoustic_data
from View.acoustic_data_tab import AcousticDataTab
logger = logging.getLogger()
class ReadTableForOpen:
def __init__(self):
self.opened = False
self.open_file_dialog()
pass
def open_file_dialog(self):
name, _ = QFileDialog.getOpenFileName(
caption="Open Acoused file",
directory="",
filter="Acoused file (*.acd)",
options=QFileDialog.DontUseNativeDialog
)
if name != "":
stg.dirname_open = os.path.dirname(name)
stg.filename_open = os.path.basename(name)
name = QFileDialog.getOpenFileName(caption="Open Acoused file", directory="", filter="Acoused file (*.acd)",
options=QFileDialog.DontUseNativeDialog)
try:
os.chdir(stg.dirname_open)
except OSError as e:
logger.warning(f"chdir: {str(e)}")
if name:
stg.dirname_open = path.dirname(name[0])
stg.filename_open = path.basename(name[0])
chdir(stg.dirname_open)
self.sql_file_to_open = open(stg.filename_open)
self.read_table()
self.opened = True
self.read_table()
def read_table(self):
@ -441,3 +428,4 @@ class ReadTableForOpen:
stg.BS_raw_data.append(np.reshape(stg.BS_raw_data_reshape[i],
(len(stg.freq[i]), stg.depth[i].shape[1], stg.time[i].shape[1])))

View File

@ -51,7 +51,7 @@ class UpdateTableForSave:
def update_table(self):
# Create a new database and open a database connection to allow sqlite3 to work with it.
cnx = sqlite3.connect(stg.filename_save_as)
cnx = sqlite3.connect(stg.filename_save_as + '.acd')
# Create database cursor to execute SQL statements and fetch results from SQL queries.
cur = cnx.cursor()
@ -104,10 +104,7 @@ class UpdateTableForSave:
# Drop Table if exists
cur.execute("DROP TABLE if exists Measure")
cur.execute(
"""
CREATE TABLE Measure(
ID INTEGER PRIMARY KEY AUTOINCREMENT,
cur.execute("""CREATE TABLE Measure(ID INTEGER PRIMARY KEY AUTOINCREMENT,
acoustic_data INTEGER,
Date STRING,
Hour STRING,
@ -124,52 +121,25 @@ class UpdateTableForSave:
NbPingsAveragedPerProfile FLOAT,
GainRx FLOAT,
GainTx FLOAT
)"""
)
""")
# Fill the table Measure
for i in stg.acoustic_data:
for j in range(stg.freq[i].shape[0]):
cur.execute(
'''
INSERT into Measure(
acoustic_data,
Date, Hour,
frequency,
sound_attenuation,
kt_read, kt_corrected,
NbProfiles, NbProfilesPerSeconds,
NbCells, CellSize,
PulseLength,
NbPingsPerSeconds,
NbPingsAveragedPerProfile,
GainRx, GainTx
) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)''',
(
stg.acoustic_data[i],
(
str(stg.date[i].year) + str('-') +
str(stg.date[i].month) + str('-') +
str(stg.date[i].day)
),
(
str(stg.hour[i].hour) + str(':') +
str(stg.hour[i].minute)
),
stg.freq[i][j],
stg.water_attenuation[i][j],
stg.kt_read[j],
stg.kt_corrected[j],
stg.nb_profiles[i][j],
stg.nb_profiles_per_sec[i][j],
stg.nb_cells[i][j],
stg.cell_size[i][j],
stg.pulse_length[i][j],
stg.nb_pings_per_sec[i][j],
stg.nb_pings_averaged_per_profile[i][j],
stg.gain_rx[i][j], stg.gain_tx[i][j]
)
cur.execute(''' INSERT into Measure(acoustic_data, Date, Hour, frequency, sound_attenuation, kt_read, kt_corrected, NbProfiles,
NbProfilesPerSeconds, NbCells, CellSize, PulseLength,
NbPingsPerSeconds, NbPingsAveragedPerProfile, GainRx, GainTx,
)
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)''',
(stg.acoustic_data[i], stg.freq[i][j], stg.water_attenuation[i][j], stg.kt_read[j], stg.kt_corrected[j],
stg.nb_profiles[i][j], stg.nb_profiles_per_sec[i][j], stg.nb_cells[i][j],
stg.cell_size[i][j], stg.pulse_length[i][j], stg.nb_pings_per_sec[i][j],
stg.nb_pings_averaged_per_profile[i][j], stg.gain_rx[i][j], stg.gain_tx[i][j],
str(stg.date[i].year) + str('-') + str(stg.date[i].month) + str('-') + str(stg.date[i].day),
str(stg.hour[i].hour) + str(':') + str(stg.hour[i].minute)
))
# Commit the transaction after executing INSERT.
cnx.commit()
@ -447,3 +417,6 @@ class UpdateTableForSave:
# Close database connection
cnx.close()

View File

@ -21,18 +21,11 @@
# -*- 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
@ -42,7 +35,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
import os
from os import path
from copy import deepcopy
import locale
@ -1239,76 +1232,71 @@ 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)"),
]
system = self.combobox_ABS_system_choice.currentIndex()
if system == 0:
# --- Open dialog box + choice directory and select file ---
if self.combobox_ABS_system_choice.currentIndex() == 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()
else:
abs_name, abs_file_type = abs_params[system]
elif self.combobox_ABS_system_choice.currentIndex() == 1:
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
)
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)
if len(filenames) == 0:
return
for n in filename[0]:
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))
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()
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))
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 ---
system = self.combobox_ABS_system_choice.currentIndex()
if system != 0:
if self.combobox_ABS_system_choice.currentIndex() != 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()
@ -1316,11 +1304,7 @@ 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):
@ -2735,3 +2719,4 @@ class AcousticDataTab(QWidget):
self.update_plot_profile()
self.fig_BS.canvas.draw_idle()

View File

@ -262,33 +262,20 @@ class Ui_MainWindow(object):
def save_as(self):
CreateTableForSaveAs()
self.mainwindow.setWindowTitle(
"AcouSed - " +
stg.filename_save_as
)
self.mainwindow.setWindowTitle("AcouSed - " + stg.filename_save_as + ".acd")
def save(self):
UpdateTableForSave()
def open(self):
reader = ReadTableForOpen()
if reader.opened:
self.mainwindow.open_study_update_tabs()
ReadTableForOpen()
def load_calibration_constant_values(self):
cc_kt = CalibrationConstantKt()
cc_kt.exec()
def db_browser_for_sqlite(self):
try:
Popen("sqlitebrowser")
except OSError as e:
msg_box = QtWidgets.QMessageBox()
msg_box.setWindowTitle("DB Browser for SQLite Error")
msg_box.setIcon(QtWidgets.QMessageBox.Critical)
msg_box.setText(f"DB Browser for SQLite Error:\n {str(e)}")
msg_box.setStandardButtons(QtWidgets.QMessageBox.Ok)
msg_box.exec()
Popen(f"sqlitebrowser", shell=True)
def about_window(self):
print("about")

View File

@ -1,8 +1,7 @@
from PyQt5.QtWidgets import (
QApplication, QWidget, QVBoxLayout, QHBoxLayout,
QTextEdit, QPushButton, QSpacerItem, QSpinBox,
QSizePolicy, QFontComboBox, QColorDialog
)
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QHBoxLayout, QTextEdit, QPushButton, QSpacerItem, \
QSpinBox, QSizePolicy, QFontComboBox, QColorDialog
from PyQt5.QtGui import QPixmap, QIcon, QFont
from PyQt5.QtCore import Qt
@ -190,21 +189,27 @@ class NoteTab(QWidget):
self.textEdit.setAlignment(Qt.AlignJustify)
def print_settings(self):
self.textEdit.setText(
"Acoustic data: \n\n"
self.textEdit.setText("Acoustic data: \n\n"
f" ABS raw data file: {stg.path_BS_raw_data}/{stg.filename_BS_raw_data} \n"
f" ABS noise data file: {stg.path_BS_noise_data}/{stg.filename_BS_noise_data} \n"
"\n\n"
"------------------------------------------------------------------------- \n\n\n"
"Particle size data: \n"
f" Fine sediments data file: {stg.path_fine}/{stg.filename_fine} \n"
f" Sand sediments data file: {stg.path_sand}/{stg.filename_sand} \n"
f" Fine sediments data file: {stg.fine_sediment_path}/{stg.fine_sediment_filename} \n"
f" Sand sediments data file: {stg.sand_sediment_path}/{stg.sand_sediment_filename} \n"
"\n\n"
"------------------------------------------------------------------------- \n\n\n"
)
"------------------------------------------------------------------------- \n\n\n")
# "Acoustic Inversion parameters: \n"
# f" frequencies to compute VBI: {stg.freq_text[int(stg.frequencies_to_compute_VBI[0, 0])]}, "
# f"{stg.freq_text[int(stg.frequencies_to_compute_VBI[1, 0])]} \n"
# f" frequency to compute SSC: {stg.freq_text[int(stg.frequency_to_compute_SSC[0])]}")
# if __name__ == "__main__":
# app = QApplication(sys.argv)
# window = NoteTab()
# window.show()
# sys.exit(app.exec_())

18
main.py
View File

@ -33,7 +33,7 @@ logging.basicConfig(
)
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
logger.setLevel(logging.INFO)
class MainApplication(QMainWindow):
@ -49,18 +49,15 @@ class MainApplication(QMainWindow):
height = size.height()
self.resize(int(PERCENT_SCREEN_SIZE*width), int(PERCENT_SCREEN_SIZE*height))
try:
self.read_table_open = ReadTableForOpen()
# **************************************************
# -------------- 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\
.editTextChanged\
.connect(
self.acoustic_data_tab.ABS_system_choice
)
self.acoustic_data_tab.combobox_ABS_system_choice.editTextChanged.connect(
self.acoustic_data_tab.ABS_system_choice)
# **************************************************
# --------- Signal pre-processing data tab ----------
@ -95,6 +92,8 @@ class MainApplication(QMainWindow):
# self.user_manual_tab = UserManualTab(self.ui_mainwindow.tab7)
self.ui_mainwindow.actionOpen.triggered.connect(self.trig_open)
# **************************************************
# ---------------- Text File Error -----------------
@ -107,7 +106,9 @@ class MainApplication(QMainWindow):
sortie.write(traceback.format_exc())
# traceback.TracebackException.from_exception(e).print(file=sortie)
def open_study_update_tabs(self):
def trig_open(self):
self.read_table_open.open_file_dialog()
self.acoustic_data_tab.combobox_ABS_system_choice.setCurrentText(stg.ABS_name[0])
self.acoustic_data_tab.fileListWidget.addFilenames(stg.filename_BS_raw_data)
@ -118,6 +119,7 @@ class MainApplication(QMainWindow):
self.sample_data_tab.lineEdit_fine_sediment.setToolTip(stg.path_fine)
# self.sample_data_tab.fill_table_fine()
if __name__ == '__main__':
# print("sys.argv:", [arg for arg in sys.argv])
# app = MainApplication(sys.argv)