From 5493f92832859b04345a3f8dc1dba25bcf560535 Mon Sep 17 00:00:00 2001 From: brahim Date: Mon, 16 Sep 2024 11:57:32 +0200 Subject: [PATCH] The user can export raw acoustic backscatter data, displayed in the table of values, to csv file. Each acoustic file is exported to a csv file with the following default name : Table_ + name_of_file_aqa. --- View/mainwindow.py | 67 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/View/mainwindow.py b/View/mainwindow.py index c255555..871200e 100644 --- a/View/mainwindow.py +++ b/View/mainwindow.py @@ -15,9 +15,13 @@ from Model.read_table_for_open import ReadTableForOpen from View.about_window import AboutWindow import settings as stg +import numpy as np +import pandas as pd import sys +from os import chdir from subprocess import check_call +import time # from View.acoustic_data_tab import AcousticDataTab from functools import partial @@ -179,6 +183,10 @@ class Ui_MainWindow(object): self.actionOpen.triggered.connect(self.open) self.actionOpen.triggered.connect(lambda: print('tott')) + # --- Connect Action export acoustic backscatter values --- + self.actionTable_of_Backscatter_values.triggered.connect( + self.export_table_of_acoustic_BS_values_to_excel_or_libreOfficeCalc_file) + # --- Connect Action DB_Browser_for_SQLite --- self.actionDB_Browser_for_SQLite.triggered.connect(self.db_browser_for_sqlite) @@ -229,6 +237,65 @@ class Ui_MainWindow(object): # w.show() # sys.exit(new_app.exec_()) + def export_table_of_acoustic_BS_values_to_excel_or_libreOfficeCalc_file(self): + + if len(stg.BS_raw_data_reshape) != 0: + + # --- Open file dialog to select the directory --- + + name = QtWidgets.QFileDialog.getExistingDirectory(caption="Select Directory - Acoustic BS raw data Table") + print("name table to save ", name) + + # --- Save the raw acoustic backscatter data from a Dataframe to csv file --- + + t0 = time.time() + print("len(stg.BS_raw_data_reshape) ", len(stg.BS_raw_data_reshape)) + + if name: + + for i in range(len(stg.BS_raw_data_reshape)): + + header_list = [] + header_list.clear() + table_data = np.array([[]]) + for freq_ind, freq_value in enumerate(stg.freq_text[0]): + header_list.append("Time - " + freq_value) + header_list.append("Depth - " + freq_value) + header_list.append("BS - " + freq_value) + + if freq_ind == 0: + table_data = np.vstack((np.vstack((stg.time_reshape[i][:, freq_ind], + stg.depth_reshape[i][:, freq_ind])), + stg.BS_raw_data_reshape[i][:, freq_ind])) + + else: + table_data = np.vstack((table_data, + np.vstack((np.vstack( + (stg.time_reshape[i][:, freq_ind], + stg.depth_reshape[i][:, freq_ind])), + stg.BS_raw_data_reshape[i][:, freq_ind])) + )) + + exec("DataFrame_acoustic_" + str(i) + "= pd.DataFrame(None)") + exec("DataFrame_acoustic_" + str(i) + "= pd.DataFrame(data=table_data.transpose(), columns=header_list)") + + # exec("DataFrame_acoustic_" + str(i) + ".to_csv(" + + # "excel_writer=" + + # '/home/bmoudjed/Documents/3 SSC acoustic meas project/Graphical interface project/BS_raw_data_table.xlsx' + "," + + # "sheet_name=stg.filename_BS_raw_data[i]," + + # "header=DataFrame_acoustic.columns," + + # "engine=" + "xlsxwriter" + ")") + + exec("DataFrame_acoustic_" + str(i) + ".to_csv(" + + "path_or_buf=" + + " '/home/bmoudjed/Documents/3 SSC acoustic meas project/Graphical interface project/Table_" + + str(stg.filename_BS_raw_data[i][:-4]) + ".csv'" + ", " + + "sep=" + " ',' " + ", " + + "header=DataFrame_acoustic_" + str(i) + ".columns" + ")") + + t1 = time.time() - t0 + print("time duration export BS ", t1) + print("table of BS value Export finished") def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate