From cb94bb3c5db2f245b35f57169601231929b23d65 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby Date: Wed, 12 Mar 2025 15:02:02 +0100 Subject: [PATCH] Acoustic data: Refactoring. --- View/acoustic_data_tab.py | 316 +++++++++++++++++++++++++------------- 1 file changed, 210 insertions(+), 106 deletions(-) diff --git a/View/acoustic_data_tab.py b/View/acoustic_data_tab.py index 872acb1..d958e5a 100644 --- a/View/acoustic_data_tab.py +++ b/View/acoustic_data_tab.py @@ -1107,7 +1107,6 @@ class AcousticDataTab(QWidget): def distance_from_ABS_to_free_surface(self): if self.fileListWidget.count() == 0: - msgBox = QMessageBox() msgBox.setWindowTitle("Distance ABS - Free surface Error") msgBox.setIcon(QMessageBox.Warning) @@ -1116,18 +1115,22 @@ class AcousticDataTab(QWidget): msgBox.exec() self.lineEdit_distance_from_ABS_to_free_surface.setText("0.00") - else: - - stg.distance_from_ABS_to_free_surface[self.fileListWidget.currentRow()] = ( - float(self.lineEdit_distance_from_ABS_to_free_surface.text().replace(",", "."))) + stg.distance_from_ABS_to_free_surface[self.fileListWidget\ + .currentRow()] = ( + float( + self.lineEdit_distance_from_ABS_to_free_surface\ + .text().replace(",", ".") + ) + ) self.lineEdit_distance_from_ABS_to_free_surface.setText( str("%4s" % stg.distance_from_ABS_to_free_surface[self.fileListWidget.currentRow()])) def refresh_distance_from_ABS_to_free_surface(self): - - acoustic_data = AcousticDataLoader(stg.path_BS_raw_data[self.fileListWidget.currentRow()] + "/" + - stg.filename_BS_raw_data[self.fileListWidget.currentRow()]) + acoustic_data = AcousticDataLoader( + stg.path_BS_raw_data[self.fileListWidget.currentRow()] + "/" + + stg.filename_BS_raw_data[self.fileListWidget.currentRow()] + ) stg.depth[self.fileListWidget.currentRow()] = acoustic_data._r stg.depth_reshape[self.fileListWidget.currentRow()] = acoustic_data.reshape_r() @@ -1448,14 +1451,20 @@ class AcousticDataTab(QWidget): def clear_files_from_ListWidget(self): - list_to_clear = ["stg.acoustic_data", "stg.date", "stg.hour", "stg.freq", "stg.freq_text", "stg.temperature", - "stg.nb_profiles", "stg.nb_profiles_per_sec", "stg.nb_cells", "stg.cell_size", - "stg.pulse_length", "stg.nb_pings_per_sec", "stg.nb_pings_averaged_per_profile", - "stg.kt_read", "stg.kt_corrected", "stg.gain_rx", "stg.gain_tx", - "stg.BS_raw_data", "stg.time", "stg.depth", - "stg.BS_raw_data_reshape", "stg.time_reshape", "stg.depth_reshape", - "stg.rmin", "stg.rmax", "stg.tmin", "stg.tmax", - "stg.time_cross_section", "stg.depth_cross_section", "stg.BS_cross_section"] + list_to_clear = [ + "stg.acoustic_data", "stg.date", "stg.hour", + "stg.freq", "stg.freq_text", "stg.temperature", + "stg.nb_profiles", "stg.nb_profiles_per_sec", + "stg.nb_cells", "stg.cell_size", + "stg.pulse_length", "stg.nb_pings_per_sec", + "stg.nb_pings_averaged_per_profile", + "stg.kt_read", "stg.kt_corrected", "stg.gain_rx", "stg.gain_tx", + "stg.BS_raw_data", "stg.time", "stg.depth", + "stg.BS_raw_data_reshape", "stg.time_reshape", "stg.depth_reshape", + "stg.rmin", "stg.rmax", "stg.tmin", "stg.tmax", + "stg.time_cross_section", "stg.depth_cross_section", + "stg.BS_cross_section" + ] for k in list_to_clear: if isinstance(k, list): @@ -1537,34 +1546,42 @@ class AcousticDataTab(QWidget): self.slider.setMaximum(10) def load_BS_acoustic_raw_data(self): - 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): if self.combobox_ABS_system_choice.currentIndex() == 1: - - acoustic_data = AcousticDataLoader(p + "/" + f) - + acoustic_data = AcousticDataLoader( + os.path.join(p, f) + ) elif self.combobox_ABS_system_choice.currentIndex() == 2: + acoustic_data = AcousticDataLoaderUBSediFlow( + os.path.join(p, f) + ) - acoustic_data = AcousticDataLoaderUBSediFlow(p + "/" + f) - - self.initiate_setting_parameters(acoustic_data=acoustic_data) - + self.initiate_setting_parameters( + acoustic_data=acoustic_data + ) else: - - for k in range(self.fileListWidget.count(), len(stg.filename_BS_raw_data), 1): - + for k in range(self.fileListWidget.count(), + len(stg.filename_BS_raw_data), 1): if self.combobox_ABS_system_choice.currentIndex() == 1: - - acoustic_data = AcousticDataLoader(stg.path_BS_raw_data[k] + "/" + stg.filename_BS_raw_data[k]) - + acoustic_data = AcousticDataLoader( + os.path.join( + stg.path_BS_raw_data[k], + stg.filename_BS_raw_data[k] + ) + ) elif self.combobox_ABS_system_choice.currentIndex() == 2: + acoustic_data = AcousticDataLoaderUBSediFlow( + os.path.join( + stg.path_BS_raw_data[k], + stg.filename_BS_raw_data[k] + ) + ) - acoustic_data = AcousticDataLoaderUBSediFlow(stg.path_BS_raw_data[k] + "/" + stg.filename_BS_raw_data[k]) - - self.initiate_setting_parameters(acoustic_data=acoustic_data) + self.initiate_setting_parameters( + acoustic_data=acoustic_data + ) def initiate_setting_parameters(self, acoustic_data): # --- The acoustic variables are field with loaded data --- @@ -1651,84 +1668,171 @@ class AcousticDataTab(QWidget): stg.SSC_sand.append(np.array([])) def fill_measurements_information_groupbox(self): + if self.fileListWidget.currentRow() == -1: + return - if self.fileListWidget.currentRow() != -1: + self.fill_measurements_information_groupbox_datetime() + self.fill_measurements_information_groupbox_frequency() + self.fill_measurements_information_groupbox_cells() + self.fill_measurements_information_groupbox_kt() - self.label_date_acoustic_file.clear() - self.label_date_acoustic_file.setText("Date: " + str(stg.date[self.fileListWidget.currentRow()])) - self.gridLayout_groupbox_info.addWidget(self.label_date_acoustic_file, 1, 0, 1, 1, Qt.AlignLeft) + def fill_measurements_information_groupbox_datetime(self): + self.label_date_acoustic_file.clear() + self.label_date_acoustic_file.setText( + "Date: " + str(stg.date[self.fileListWidget.currentRow()]) + ) + self.gridLayout_groupbox_info.addWidget( + self.label_date_acoustic_file, + 1, 0, 1, 1, + Qt.AlignLeft + ) - self.label_hour_acoustic_file.clear() - self.label_hour_acoustic_file.setText("Hour: " + str(stg.hour[self.fileListWidget.currentRow()])) - self.gridLayout_groupbox_info.addWidget(self.label_hour_acoustic_file, 1, 1, 1, 1, Qt.AlignLeft) + self.label_hour_acoustic_file.clear() + self.label_hour_acoustic_file.setText( + "Hour: " + str(stg.hour[self.fileListWidget.currentRow()]) + ) + self.gridLayout_groupbox_info.addWidget( + self.label_hour_acoustic_file, + 1, 1, 1, 1, + Qt.AlignLeft + ) - self.combobox_frequency_information.clear() - self.combobox_frequency_information.addItems(stg.freq_text[self.fileListWidget.currentRow()]) - self.combobox_frequency_information.currentIndexChanged.connect(self.combobox_frequency_information_update) + def fill_measurements_information_groupbox_frequency(self): + file_id = self.fileListWidget.currentRow() + freq_id = self.combobox_frequency_information.currentIndex() - self.lineEdit_temperature.setText(str(stg.temperature)) + self.combobox_frequency_information.clear() + self.combobox_frequency_information.addItems( + stg.freq_text[file_id] + ) + self.combobox_frequency_information\ + .currentIndexChanged\ + .connect(self.combobox_frequency_information_update) - self.label_profiles_value.setText(str(stg.nb_profiles[self.fileListWidget.currentRow()] - [self.combobox_frequency_information.currentIndex()])) - self.gridLayout_groupbox_info.addWidget(self.label_profiles_value, 8, 1, 1, 1, Qt.AlignLeft) + self.lineEdit_temperature.setText(str(stg.temperature)) - self.label_profiles_per_sec_value.setText(str(stg.nb_profiles_per_sec[self.fileListWidget.currentRow()] - [self.combobox_frequency_information.currentIndex()]) + " Hz") - self.gridLayout_groupbox_info.addWidget(self.label_profiles_per_sec_value, 9, 1, 1, 1, Qt.AlignLeft) + self.label_profiles_value.setText( + str(stg.nb_profiles[file_id][freq_id]) + ) + self.gridLayout_groupbox_info.addWidget( + self.label_profiles_value, + 8, 1, 1, 1, + Qt.AlignLeft + ) - self.label_cells_value.setText(str(stg.nb_cells[self.fileListWidget.currentRow()] - [self.combobox_frequency_information.currentIndex()])) - self.gridLayout_groupbox_info.addWidget(self.label_cells_value, 10, 1, 1, 1, Qt.AlignLeft) + self.label_profiles_per_sec_value.setText( + str(stg.nb_profiles_per_sec[file_id][freq_id]) + " Hz" + ) + self.gridLayout_groupbox_info.addWidget( + self.label_profiles_per_sec_value, + 9, 1, 1, 1, + Qt.AlignLeft + ) - self.label_cell_size_value.setText(str(100*round(stg.cell_size[self.fileListWidget.currentRow()] - [self.combobox_frequency_information.currentIndex()], 3)) + " cm") - self.gridLayout_groupbox_info.addWidget(self.label_cell_size_value, 11, 1, 1, 1, Qt.AlignLeft) + def fill_measurements_information_groupbox_cells(self): + file_id = self.fileListWidget.currentRow() + freq_id = self.combobox_frequency_information.currentIndex() - self.label_pulse_length_value.setText(str(round(stg.pulse_length[self.fileListWidget.currentRow()] - [self.combobox_frequency_information.currentIndex()], 6)) + " sec") - self.gridLayout_groupbox_info.addWidget(self.label_pulse_length_value, 12, 1, 1, 1, Qt.AlignLeft) + self.label_cells_value.setText( + str(stg.nb_cells[file_id][freq_id]) + ) + self.gridLayout_groupbox_info.addWidget( + self.label_cells_value, + 10, 1, 1, 1, + Qt.AlignLeft + ) - self.label_pings_per_sec_value.setText(str(stg.nb_pings_per_sec[self.fileListWidget.currentRow()] - [self.combobox_frequency_information.currentIndex()]) + " Hz") - self.gridLayout_groupbox_info.addWidget(self.label_pings_per_sec_value, 13, 1, 1, 1, Qt.AlignLeft) + self.label_cell_size_value.setText( + str(100*round(stg.cell_size[file_id][freq_id], 3)) + " cm" + ) - self.label_pings_per_profile_value.setText(str(stg.nb_pings_averaged_per_profile[self.fileListWidget.currentRow()] - [self.combobox_frequency_information.currentIndex()])) - self.gridLayout_groupbox_info.addWidget(self.label_pings_per_profile_value, 14, 1, 1, 1, Qt.AlignLeft) + self.gridLayout_groupbox_info.addWidget( + self.label_cell_size_value, + 11, 1, 1, 1, + Qt.AlignLeft + ) - stg.kt_corrected.clear() - for f in range(stg.freq[self.fileListWidget.currentRow()].shape[0]): - stg.kt_corrected.append( - self.calib_kt.data_ABS[self.combobox_ABS_name.currentText()].iloc[ - np.where( - np.abs(np.array([stg.freq[self.fileListWidget.currentRow()][f] - l for l in - self.calib_kt.data_ABS[self.combobox_ABS_name.currentText()][ - self.calib_kt.data_ABS[ - self.combobox_ABS_name.currentText()].columns[0]].values])) - == - np.min(np.abs(np.array([stg.freq[self.fileListWidget.currentRow()][f] - l for l in - self.calib_kt.data_ABS[self.combobox_ABS_name.currentText()][ - self.calib_kt.data_ABS[ - self.combobox_ABS_name.currentText()].columns[ - 0]].values]) - )) - )[0][0] - ][1]) + self.label_pulse_length_value.setText( + str(round(stg.pulse_length[file_id][freq_id], 6)) + " sec" + ) + self.gridLayout_groupbox_info.addWidget( + self.label_pulse_length_value, + 12, 1, 1, 1, + Qt.AlignLeft + ) + + self.label_pings_per_sec_value.setText( + str(stg.nb_pings_per_sec[file_id][freq_id]) + " Hz" + ) + + self.gridLayout_groupbox_info.addWidget( + self.label_pings_per_sec_value, + 13, 1, 1, 1, + Qt.AlignLeft + ) + + self.label_pings_per_profile_value.setText( + str(stg.nb_pings_averaged_per_profile[file_id][freq_id]) + ) + + self.gridLayout_groupbox_info.addWidget( + self.label_pings_per_profile_value, + 14, 1, 1, 1, + Qt.AlignLeft + ) + + def fill_measurements_information_groupbox_kt(self): + file_id = self.fileListWidget.currentRow() + freq_id = self.combobox_frequency_information.currentIndex() + abs_id = self.combobox_ABS_name.currentText() + + data_ABS = self.calib_kt.data_ABS[abs_id]["Frequency"].values + + stg.kt_corrected.clear() + for f in range(stg.freq[file_id].shape[0]): + freq_array = np.array( + [ + stg.freq[file_id][f] - freq + for freq in data_ABS + ] + ) + + stg.kt_corrected.append( + self.calib_kt.data_ABS[abs_id].iloc[ + np.where( + np.abs( + freq_array + ) == np.min( + np.abs( + freq_array + ) + ) + )[0][0] + ][1] + ) - self.lineEdit_kt.setText(str("%.4f" % stg.kt_corrected[self.combobox_frequency_information.currentIndex()])) - self.lineEdit_kt.setEnabled(True) - self.lineEdit_kt.returnPressed.connect(self.kt_value) + self.lineEdit_kt.setText( + str("%.4f" % stg.kt_corrected[freq_id]) + ) + self.lineEdit_kt.setEnabled(True) + self.lineEdit_kt.returnPressed.connect(self.kt_value) - self.lineEdit_rx.setText(str("%.2f" % stg.gain_rx[self.fileListWidget.currentRow()][self.combobox_frequency_information.currentIndex()])) - self.lineEdit_rx.setEnabled(False) - self.checkbox_rx.stateChanged.connect(self.activate_unactivate_spinbox_rx) - self.lineEdit_rx.returnPressed.connect(self.gain_rx_value) + self.lineEdit_rx.setText( + str("%.2f" % stg.gain_rx[file_id][freq_id]) + ) + self.lineEdit_rx.setEnabled(False) + self.checkbox_rx.stateChanged.connect( + self.activate_unactivate_spinbox_rx + ) + self.lineEdit_rx.returnPressed.connect(self.gain_rx_value) - self.lineEdit_tx.setText(str("%.2f" % stg.gain_tx[self.fileListWidget.currentRow()][self.combobox_frequency_information.currentIndex()])) - self.lineEdit_tx.setEnabled(False) - self.checkbox_tx.stateChanged.connect(self.activate_unactivate_spinbox_tx) - self.lineEdit_tx.returnPressed.connect(self.gain_tx_value) + self.lineEdit_tx.setText(str("%.2f" % stg.gain_tx[file_id][freq_id])) + self.lineEdit_tx.setEnabled(False) + self.checkbox_tx.stateChanged.connect( + self.activate_unactivate_spinbox_tx + ) + self.lineEdit_tx.returnPressed.connect(self.gain_tx_value) def combobox_frequency_information_update(self): if self.fileListWidget.count() > 0: @@ -2117,7 +2221,7 @@ class AcousticDataTab(QWidget): cmap='Blues') self.axis_BS[f].text(1, .70, stg.freq_text[self.fileListWidget.currentRow()][f], - fontsize=14, fontweight='bold', fontname="Ubuntu", c="black", alpha=0.5, + fontsize=14, fontweight='bold', fontname="DejaVu Sans", c="black", alpha=0.5, horizontalalignment='right', verticalalignment='bottom', transform=self.axis_BS[f].transAxes) @@ -2248,7 +2352,7 @@ class AcousticDataTab(QWidget): color='black', linewidth=1, linestyle="solid") self.axis_BS[f].text(1, .70, stg.freq_text[self.fileListWidget.currentRow()][f], - fontsize=14, fontweight='bold', fontname="Ubuntu", c="black", alpha=0.5, + fontsize=14, fontweight='bold', fontname="DejaVu Sans", c="black", alpha=0.5, horizontalalignment='right', verticalalignment='bottom', transform=self.axis_BS[f].transAxes) @@ -2289,7 +2393,7 @@ class AcousticDataTab(QWidget): -stg.depth[self.fileListWidget.currentRow()][self.combobox_frequency_profile.currentIndex(), :], linestyle='solid', color='k', linewidth=1) self.axis_profile.text(.95, .05, stg.freq_text[self.fileListWidget.currentRow()][self.combobox_frequency_profile.currentIndex()], - fontsize=10, fontweight='bold', fontname="Ubuntu", + fontsize=10, fontweight='bold', fontname="DejaVu Sans", fontstyle="normal", c="black", alpha=0.2, horizontalalignment='right', verticalalignment='bottom', transform=self.axis_profile.transAxes) @@ -2348,7 +2452,7 @@ class AcousticDataTab(QWidget): # --- Write frequency on graph --- self.axis_profile.text(.95, .90, stg.freq_text[self.fileListWidget.currentRow()][ self.combobox_frequency_profile.currentIndex()], - fontsize=14, fontweight='bold', fontname="Ubuntu", + fontsize=14, fontweight='bold', fontname="DejaVu Sans", fontstyle="normal", c="black", alpha=0.2, horizontalalignment='right', verticalalignment='bottom', transform=self.axis_profile.transAxes) @@ -2372,7 +2476,7 @@ class AcousticDataTab(QWidget): self.combobox_frequency_profile.currentIndex(), :])) self.axis_profile.text(.95, 1 - position_x + 0.05, "River bed", - fontsize=10, fontweight='normal', fontname="Ubuntu", + fontsize=10, fontweight='normal', fontname="DejaVu Sans", fontstyle="italic", c="red", alpha=0.2, horizontalalignment='right', verticalalignment='bottom', transform=self.axis_profile.transAxes) @@ -2397,7 +2501,7 @@ class AcousticDataTab(QWidget): # --- Write frequency on graph --- self.axis_profile.text(.95, .05, stg.freq_text[self.fileListWidget.currentRow()][ self.combobox_frequency_profile.currentIndex()], - fontsize=10, fontweight='bold', fontname="Ubuntu", + fontsize=10, fontweight='bold', fontname="DejaVu Sans", fontstyle="normal", c="black", alpha=0.2, horizontalalignment='right', verticalalignment='bottom', transform=self.axis_profile.transAxes) @@ -2421,7 +2525,7 @@ class AcousticDataTab(QWidget): self.combobox_frequency_profile.currentIndex(), :])) self.axis_profile.text(.95, 1 - position_x + 0.05, "River bed", - fontsize=10, fontweight='normal', fontname="Ubuntu", + fontsize=10, fontweight='normal', fontname="DejaVu Sans", fontstyle="italic", c="red", alpha=0.2, horizontalalignment='right', verticalalignment='bottom', transform=self.axis_profile.transAxes) @@ -2605,7 +2709,7 @@ class AcousticDataTab(QWidget): color='black', linewidth=1, linestyle="solid") self.axis_BS[f].text(1, .70, stg.freq_text[self.fileListWidget.currentRow()][f], - fontsize=14, fontweight='bold', fontname="Ubuntu", c="black", alpha=0.5, + fontsize=14, fontweight='bold', fontname="DejaVu Sans", c="black", alpha=0.5, horizontalalignment='right', verticalalignment='bottom', transform=self.axis_BS[f].transAxes) @@ -2733,7 +2837,7 @@ class AcousticDataTab(QWidget): color='black', linewidth=1, linestyle="solid") self.axis_BS[f].text(1, .70, stg.freq_text[self.fileListWidget.currentRow()][f], - fontsize=14, fontweight='bold', fontname="Ubuntu", c="black", + fontsize=14, fontweight='bold', fontname="DejaVu Sans", c="black", alpha=0.5, horizontalalignment='right', verticalalignment='bottom', transform=self.axis_BS[f].transAxes)