A context menu is added. Update Table for Save action created.
parent
4d8000993d
commit
825b5aa9bb
|
|
@ -0,0 +1,89 @@
|
||||||
|
import numpy as np
|
||||||
|
from PyQt5.QtWidgets import QFileDialog, QApplication
|
||||||
|
import sqlite3
|
||||||
|
import settings as stg
|
||||||
|
from os import chdir, getcwd
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
class UpdateTableForSave:
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
|
||||||
|
start = time.time()
|
||||||
|
chdir(stg.dirname_save_as)
|
||||||
|
print("get cwd for save :", getcwd())
|
||||||
|
print("stg.filename_save_as ", stg.filename_save_as)
|
||||||
|
self.update_table()
|
||||||
|
print(f"end : {time.time() - start} sec")
|
||||||
|
|
||||||
|
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 + '.acd')
|
||||||
|
|
||||||
|
# Create database cursor to execute SQL statements and fetch results from SQL queries.
|
||||||
|
cur = cnx.cursor()
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------------------------------------------
|
||||||
|
# --- Table BSRawData_i ---
|
||||||
|
start_table_BSRawData = time.time()
|
||||||
|
|
||||||
|
# # --- Fill table BSRawData_i with data stg.depth_reshape ---
|
||||||
|
#
|
||||||
|
# for i in stg.acoustic_data:
|
||||||
|
# exec("query1 = '''ALTER TABLE BSRawData ADD COLUMN BS_cross_section BLOB''' ")
|
||||||
|
#
|
||||||
|
# exec("cur.execute(query1)")
|
||||||
|
#
|
||||||
|
# # Commit the transaction after executing INSERT.
|
||||||
|
# cnx.commit()
|
||||||
|
#
|
||||||
|
# for i in stg.acoustic_data:
|
||||||
|
# cur.execute(f"''' UPDATE BSRawData SET BS_cross_section = " + str(stg.BS_cross_section[i].tobytes()) + " WHERE acoustic_data =" + str(i) + " ''' ")
|
||||||
|
#
|
||||||
|
# # Commit the transaction after executing INSERT.
|
||||||
|
# cnx.commit()
|
||||||
|
#
|
||||||
|
# print(f"end : {time.time() - start_table_BSRawData} sec")
|
||||||
|
|
||||||
|
if stg.BS_cross_section:
|
||||||
|
|
||||||
|
cur.execute(''' DROP TABLE BSRawData ''')
|
||||||
|
print(f"end : {time.time() - start_table_BSRawData} sec")
|
||||||
|
|
||||||
|
cur.execute('''CREATE TABLE BSRawData(
|
||||||
|
ID INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
acoustic_data INTEGER,
|
||||||
|
time BLOB,
|
||||||
|
time_cross_section BLOB,
|
||||||
|
depth BLOB,
|
||||||
|
depth_cross_section BLOB,
|
||||||
|
BS_raw_data BLOB,
|
||||||
|
BS_cross_section BLOB)''')
|
||||||
|
|
||||||
|
for i in stg.acoustic_data:
|
||||||
|
|
||||||
|
cur.execute(''' INSERT into BSRawData(acoustic_data, time, time_cross_section,
|
||||||
|
depth, depth_cross_section,
|
||||||
|
BS_raw_data, BS_cross_section)
|
||||||
|
VALUES(?, ?, ?, ?, ?, ?, ?)''',
|
||||||
|
(stg.acoustic_data[i], stg.time[i].tobytes(), stg.time_cross_section[i].tobytes(),
|
||||||
|
stg.depth[i].tobytes(), stg.depth_cross_section[i].tobytes(),
|
||||||
|
stg.BS_raw_data[i].tobytes(), stg.BS_cross_section[i].tobytes()))
|
||||||
|
|
||||||
|
cnx.commit()
|
||||||
|
|
||||||
|
if stg.depth_bottom:
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
# Close database cursor
|
||||||
|
cur.close()
|
||||||
|
|
||||||
|
# Close database connection
|
||||||
|
cnx.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -954,6 +954,9 @@ class AcousticDataTab(QWidget):
|
||||||
self.max_selected_file = 1
|
self.max_selected_file = 1
|
||||||
# self.btnToggled()
|
# self.btnToggled()
|
||||||
|
|
||||||
|
plt.rcParams['figure.max_open_warning'] = 100
|
||||||
|
print("plt.rcParams['figure.max_open_warning'] ", plt.rcParams['figure.max_open_warning'])
|
||||||
|
|
||||||
# --------------------------------------------------------------------------------------------------------------
|
# --------------------------------------------------------------------------------------------------------------
|
||||||
# --- Connect signal of widget ---
|
# --- Connect signal of widget ---
|
||||||
|
|
||||||
|
|
@ -1689,8 +1692,20 @@ class AcousticDataTab(QWidget):
|
||||||
self.tableView.setModel(self.tableModel)
|
self.tableView.setModel(self.tableModel)
|
||||||
|
|
||||||
# --- Clear figure area for backscattered acoutsic signal recording ---
|
# --- Clear figure area for backscattered acoutsic signal recording ---
|
||||||
self.canvas_BS.figure.clear()
|
# self.canvas_BS.figure.clear()
|
||||||
self.canvas_plot_profile.figure.clear()
|
# self.fig_BS.clf()
|
||||||
|
# for ax in range(len(self.axis_BS)):
|
||||||
|
# self.axis_BS[ax].cla()
|
||||||
|
# print("axis BS : ", self.axis_BS)
|
||||||
|
# # self.axis_BS.tolist().clear()
|
||||||
|
# # print("clear axis BS : ", self.axis_BS)
|
||||||
|
#
|
||||||
|
# self.canvas_plot_profile.figure.clear()
|
||||||
|
# print("0 fig profile : ", self.fig_profile)
|
||||||
|
# self.fig_profile.delaxes(self.axis_profile)
|
||||||
|
# print("1 fig profile : ", self.fig_profile)
|
||||||
|
# # self.axis_profile.clear()
|
||||||
|
|
||||||
self.combobox_frequency_profile.clear()
|
self.combobox_frequency_profile.clear()
|
||||||
# self.verticalLayout_groupbox_transect_2Dplot_raw_BS_data.removeWidget(self.scroll_BS)
|
# self.verticalLayout_groupbox_transect_2Dplot_raw_BS_data.removeWidget(self.scroll_BS)
|
||||||
# self.canvas_BS = FigureCanvas()
|
# self.canvas_BS = FigureCanvas()
|
||||||
|
|
@ -1707,6 +1722,15 @@ class AcousticDataTab(QWidget):
|
||||||
# self.canvas_plot_profile = FigureCanvas()
|
# self.canvas_plot_profile = FigureCanvas()
|
||||||
# self.verticalLayout_groupbox_plot_profile.addWidget(self.canvas_plot_profile)
|
# self.verticalLayout_groupbox_plot_profile.addWidget(self.canvas_plot_profile)
|
||||||
|
|
||||||
|
self.canvas_BS.figure.clear()
|
||||||
|
self.fig_BS.clf()
|
||||||
|
print("axis BS : ", self.axis_BS)
|
||||||
|
self.axis_BS.tolist().clear()
|
||||||
|
print("clear axis BS : ", self.axis_BS)
|
||||||
|
self.canvas_plot_profile.figure.clear()
|
||||||
|
self.fig_profile.clear()
|
||||||
|
self.axis_profile.clear()
|
||||||
|
|
||||||
self.slider.setValue(0)
|
self.slider.setValue(0)
|
||||||
self.slider.setMaximum(10)
|
self.slider.setMaximum(10)
|
||||||
|
|
||||||
|
|
@ -1918,8 +1942,11 @@ class AcousticDataTab(QWidget):
|
||||||
# self.label_tx.setText(
|
# self.label_tx.setText(
|
||||||
# _translate("CONSTANT_STRING", cs.GAIN_TX) + ": " + ', '.join(map(str, stg.gain_tx[self.fileListWidget.currentRow()])))
|
# _translate("CONSTANT_STRING", cs.GAIN_TX) + ": " + ', '.join(map(str, stg.gain_tx[self.fileListWidget.currentRow()])))
|
||||||
|
|
||||||
print("self.fileListWidget.count() ", self.fileListWidget.currentRow())
|
print("self.fileListWidget.currentItem() ", self.fileListWidget.currentItem())
|
||||||
if self.fileListWidget.count() > 0:
|
print("self.fileListWidget.currentRow ", self.fileListWidget.currentRow())
|
||||||
|
print("self.fileListWidget.count() ", self.fileListWidget.count())
|
||||||
|
|
||||||
|
if self.fileListWidget.currentRow() != -1:
|
||||||
|
|
||||||
self.label_date_acoustic_file.clear()
|
self.label_date_acoustic_file.clear()
|
||||||
self.label_date_acoustic_file.setText("Date: " + str(stg.date[self.fileListWidget.currentRow()]))
|
self.label_date_acoustic_file.setText("Date: " + str(stg.date[self.fileListWidget.currentRow()]))
|
||||||
|
|
@ -2156,34 +2183,35 @@ class AcousticDataTab(QWidget):
|
||||||
|
|
||||||
def fill_table(self):
|
def fill_table(self):
|
||||||
|
|
||||||
if self.fileListWidget.count() == 1:
|
if self.fileListWidget.currentRow() != -1:
|
||||||
|
|
||||||
header_list = []
|
# header_list = []
|
||||||
for freq_ind, freq_value in enumerate(stg.freq_text[0]):
|
# for freq_ind, freq_value in enumerate(stg.freq_text[0]):
|
||||||
header_list.append("Time - " + freq_value)
|
# header_list.append("Time - " + freq_value)
|
||||||
header_list.append("Depth - " + freq_value)
|
# header_list.append("Depth - " + freq_value)
|
||||||
header_list.append("BS - " + freq_value)
|
# header_list.append("BS - " + freq_value)
|
||||||
|
#
|
||||||
if freq_ind == 0:
|
# if freq_ind == 0:
|
||||||
table_data = np.vstack((np.vstack((stg.time_reshape[0][:, freq_ind],
|
# table_data = np.vstack((np.vstack((stg.time_reshape[0][:, freq_ind],
|
||||||
stg.depth_reshape[0][:, freq_ind])),
|
# stg.depth_reshape[0][:, freq_ind])),
|
||||||
stg.BS_raw_data_reshape[0][:, freq_ind]))
|
# stg.BS_raw_data_reshape[0][:, freq_ind]))
|
||||||
else:
|
# else:
|
||||||
table_data = np.vstack((table_data,
|
# table_data = np.vstack((table_data,
|
||||||
np.vstack((np.vstack((stg.time_reshape[0][:, freq_ind],
|
# np.vstack((np.vstack((stg.time_reshape[0][:, freq_ind],
|
||||||
stg.depth_reshape[0][:, freq_ind])),
|
# stg.depth_reshape[0][:, freq_ind])),
|
||||||
stg.BS_raw_data_reshape[0][:, freq_ind]))
|
# stg.BS_raw_data_reshape[0][:, freq_ind]))
|
||||||
))
|
# ))
|
||||||
|
#
|
||||||
print(header_list)
|
# print("1 header_list ", header_list)
|
||||||
print(table_data.shape)
|
# print("1 table_data.shape ", table_data.shape)
|
||||||
|
#
|
||||||
stg.DataFrame_acoustic = pd.DataFrame(data=table_data.transpose(), columns=header_list)
|
# stg.DataFrame_acoustic = pd.DataFrame(data=table_data.transpose(), columns=header_list)
|
||||||
|
#
|
||||||
else:
|
# else:
|
||||||
|
|
||||||
header_list = []
|
header_list = []
|
||||||
header_list.clear()
|
header_list.clear()
|
||||||
|
table_data = np.array([[]])
|
||||||
for freq_ind, freq_value in enumerate(stg.freq_text[0]):
|
for freq_ind, freq_value in enumerate(stg.freq_text[0]):
|
||||||
header_list.append("Time - " + freq_value)
|
header_list.append("Time - " + freq_value)
|
||||||
header_list.append("Depth - " + freq_value)
|
header_list.append("Depth - " + freq_value)
|
||||||
|
|
@ -2201,10 +2229,11 @@ class AcousticDataTab(QWidget):
|
||||||
stg.BS_raw_data_reshape[self.fileListWidget.currentRow()][:, freq_ind]))
|
stg.BS_raw_data_reshape[self.fileListWidget.currentRow()][:, freq_ind]))
|
||||||
))
|
))
|
||||||
|
|
||||||
|
stg.DataFrame_acoustic = pd.DataFrame(None)
|
||||||
stg.DataFrame_acoustic = pd.DataFrame(data=table_data.transpose(), columns=header_list)
|
stg.DataFrame_acoustic = pd.DataFrame(data=table_data.transpose(), columns=header_list)
|
||||||
|
|
||||||
print(header_list)
|
print("2 header_list ", header_list)
|
||||||
print(table_data.shape)
|
print("2 table_data.shape", table_data.shape)
|
||||||
# stg.DataFrame_acoustic = (
|
# stg.DataFrame_acoustic = (
|
||||||
# pd.DataFrame(np.concatenate((stg.time_reshape[self.fileListWidget.currentRow()],
|
# pd.DataFrame(np.concatenate((stg.time_reshape[self.fileListWidget.currentRow()],
|
||||||
# stg.BS_raw_data_reshape[self.fileListWidget.currentRow()]), axis=1),
|
# stg.BS_raw_data_reshape[self.fileListWidget.currentRow()]), axis=1),
|
||||||
|
|
@ -2284,6 +2313,8 @@ class AcousticDataTab(QWidget):
|
||||||
# self.groupbox_xaxis_space.setDisabled(True)
|
# self.groupbox_xaxis_space.setDisabled(True)
|
||||||
|
|
||||||
def compute_time(self):
|
def compute_time(self):
|
||||||
|
if self.fileListWidget.currentRow() != -1:
|
||||||
|
|
||||||
if ((self.fileListWidget.count() == 1) and (len(stg.tmax) == 0)):
|
if ((self.fileListWidget.count() == 1) and (len(stg.tmax) == 0)):
|
||||||
|
|
||||||
print("Config 1 : time")
|
print("Config 1 : time")
|
||||||
|
|
@ -2441,6 +2472,8 @@ class AcousticDataTab(QWidget):
|
||||||
# )
|
# )
|
||||||
|
|
||||||
def compute_depth(self):
|
def compute_depth(self):
|
||||||
|
if self.fileListWidget.currentRow() != -1:
|
||||||
|
|
||||||
if ((self.fileListWidget.count() == 1) and (len(stg.rmax) == 0)):
|
if ((self.fileListWidget.count() == 1) and (len(stg.rmax) == 0)):
|
||||||
|
|
||||||
# --- rmim / rmax ---
|
# --- rmim / rmax ---
|
||||||
|
|
@ -2536,6 +2569,8 @@ class AcousticDataTab(QWidget):
|
||||||
print("rmax ", stg.rmax)
|
print("rmax ", stg.rmax)
|
||||||
|
|
||||||
def compute_BS_cross_section(self):
|
def compute_BS_cross_section(self):
|
||||||
|
if self.fileListWidget.currentRow() != -1:
|
||||||
|
|
||||||
if (self.fileListWidget.count() == 1) and (len(stg.BS_cross_section) == 0):
|
if (self.fileListWidget.count() == 1) and (len(stg.BS_cross_section) == 0):
|
||||||
|
|
||||||
print("Config 1 : BS_cross_section")
|
print("Config 1 : BS_cross_section")
|
||||||
|
|
@ -2565,12 +2600,14 @@ class AcousticDataTab(QWidget):
|
||||||
print(f"BS_cross_section shape : {stg.BS_cross_section[self.fileListWidget.currentRow()].shape}")
|
print(f"BS_cross_section shape : {stg.BS_cross_section[self.fileListWidget.currentRow()].shape}")
|
||||||
|
|
||||||
def update_frequency_combobox(self):
|
def update_frequency_combobox(self):
|
||||||
|
if self.fileListWidget.currentRow() != -1:
|
||||||
self.combobox_frequency_bathymetry.clear()
|
self.combobox_frequency_bathymetry.clear()
|
||||||
self.combobox_frequency_bathymetry.addItems([f for f in stg.freq_text[self.fileListWidget.currentRow()]])
|
self.combobox_frequency_bathymetry.addItems([f for f in stg.freq_text[self.fileListWidget.currentRow()]])
|
||||||
self.combobox_frequency_profile.clear()
|
self.combobox_frequency_profile.clear()
|
||||||
self.combobox_frequency_profile.addItems([f for f in stg.freq_text[self.fileListWidget.currentRow()]])
|
self.combobox_frequency_profile.addItems([f for f in stg.freq_text[self.fileListWidget.currentRow()]])
|
||||||
|
|
||||||
def set_range_for_doubleRangeSlider_intg_area(self):
|
def set_range_for_doubleRangeSlider_intg_area(self):
|
||||||
|
if self.fileListWidget.currentRow() != -1:
|
||||||
self.doubleRangeSlider_intg_area.setRange(min=-stg.depth_cross_section[self.fileListWidget.currentRow()][0, -1],
|
self.doubleRangeSlider_intg_area.setRange(min=-stg.depth_cross_section[self.fileListWidget.currentRow()][0, -1],
|
||||||
max=-stg.depth_cross_section[self.fileListWidget.currentRow()][0, 0])
|
max=-stg.depth_cross_section[self.fileListWidget.currentRow()][0, 0])
|
||||||
|
|
||||||
|
|
@ -2611,6 +2648,9 @@ class AcousticDataTab(QWidget):
|
||||||
# self.verticalLayout_groupbox_transect_2Dplot_raw_BS_data.addWidget(self.scroll_BS)
|
# self.verticalLayout_groupbox_transect_2Dplot_raw_BS_data.addWidget(self.scroll_BS)
|
||||||
|
|
||||||
# plt.close(self.fig_BS)
|
# plt.close(self.fig_BS)
|
||||||
|
|
||||||
|
if self.fileListWidget.currentRow() != -1:
|
||||||
|
|
||||||
self.verticalLayout_groupbox_transect_2Dplot_raw_BS_data.removeWidget(self.scroll_BS)
|
self.verticalLayout_groupbox_transect_2Dplot_raw_BS_data.removeWidget(self.scroll_BS)
|
||||||
|
|
||||||
self.fig_BS, self.axis_BS = plt.subplots(nrows=stg.freq[self.fileListWidget.currentRow()].shape[0], ncols=1,
|
self.fig_BS, self.axis_BS = plt.subplots(nrows=stg.freq[self.fileListWidget.currentRow()].shape[0], ncols=1,
|
||||||
|
|
@ -2872,8 +2912,8 @@ class AcousticDataTab(QWidget):
|
||||||
if (len(stg.depth_bottom) != 0) and (len(stg.depth_bottom) == self.fileListWidget.count()):
|
if (len(stg.depth_bottom) != 0) and (len(stg.depth_bottom) == self.fileListWidget.count()):
|
||||||
if stg.depth_bottom[self.fileListWidget.currentRow()].shape != (0,):
|
if stg.depth_bottom[self.fileListWidget.currentRow()].shape != (0,):
|
||||||
|
|
||||||
print("stg.depth_bottom ", stg.depth_bottom)
|
# print("stg.depth_bottom ", stg.depth_bottom)
|
||||||
print("len(stg.depth_bottom) ", len(stg.depth_bottom))
|
# print("len(stg.depth_bottom) ", len(stg.depth_bottom))
|
||||||
self.axis_BS[f].plot(stg.time_cross_section[self.fileListWidget.currentRow()][self.combobox_frequency_bathymetry.currentIndex(), :],
|
self.axis_BS[f].plot(stg.time_cross_section[self.fileListWidget.currentRow()][self.combobox_frequency_bathymetry.currentIndex(), :],
|
||||||
-stg.depth_bottom[self.fileListWidget.currentRow()],
|
-stg.depth_bottom[self.fileListWidget.currentRow()],
|
||||||
color='black', linewidth=1, linestyle="solid")
|
color='black', linewidth=1, linestyle="solid")
|
||||||
|
|
@ -2899,6 +2939,7 @@ class AcousticDataTab(QWidget):
|
||||||
# plt.close(self.fig_BS)
|
# plt.close(self.fig_BS)
|
||||||
|
|
||||||
def plot_profile(self):
|
def plot_profile(self):
|
||||||
|
if self.fileListWidget.currentRow() != -1:
|
||||||
|
|
||||||
self.combobox_frequency_profile.setCurrentIndex(0)
|
self.combobox_frequency_profile.setCurrentIndex(0)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -174,6 +174,7 @@ class Ui_MainWindow(object):
|
||||||
|
|
||||||
# --- Connect Action Open ---
|
# --- Connect Action Open ---
|
||||||
self.actionOpen.triggered.connect(self.open)
|
self.actionOpen.triggered.connect(self.open)
|
||||||
|
self.actionOpen.triggered.connect(lambda: print('tott'))
|
||||||
|
|
||||||
# --- Connect Action DB_Browser_for_SQLite ---
|
# --- Connect Action DB_Browser_for_SQLite ---
|
||||||
self.actionDB_Browser_for_SQLite.triggered.connect(self.db_browser_for_sqlite)
|
self.actionDB_Browser_for_SQLite.triggered.connect(self.db_browser_for_sqlite)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue