From 0cd9964594041797410e86e0839c8c796fb8d1c8 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby Date: Mon, 24 Mar 2025 13:50:13 +0100 Subject: [PATCH] Signal processing: Fix open study file crash. --- Model/read_table_for_open.py | 46 ++++++++++++++++++++--------------- View/acoustic_data_tab.py | 4 +-- View/signal_processing_tab.py | 23 ++++++++++++------ main.py | 2 +- 4 files changed, 45 insertions(+), 30 deletions(-) diff --git a/Model/read_table_for_open.py b/Model/read_table_for_open.py index 60cf2d5..2729db0 100644 --- a/Model/read_table_for_open.py +++ b/Model/read_table_for_open.py @@ -107,18 +107,18 @@ class ReadTableForOpen: FROM AcousticFile WHERE (acoustic_data = {k}) ''' - data = self.execute(query) + data = self.execute(query)[0] print("data acoustic file", data) stg.filename_BS_raw_data.append( - [str(y[1]) + '.aqa' for y in data][0] + str(data[1]) + '.aqa' ) - stg.ABS_name.append([z[2] for z in data][0]) - stg.path_BS_noise_data.append([z[3] for z in data][0]) - stg.filename_BS_noise_data.append([z[4] for z in data][0]) - stg.noise_method.append([z[5] for z in data][0]) - stg.noise_value.append([z[6] for z in data][0]) - stg.data_preprocessed.append([z[7] for z in data][0]) + stg.ABS_name.append(data[2]) + stg.path_BS_noise_data.append(data[3]) + stg.filename_BS_noise_data.append(data[4]) + stg.noise_method.append(data[5]) + stg.noise_value.append(data[6]) + stg.data_preprocessed.append(data[7]) logger.debug("data acoustic file:") logger.debug(f"- {stg.filename_BS_raw_data}") @@ -370,6 +370,7 @@ class ReadTableForOpen: stg.time_noise.append(np.array([])) stg.depth_noise.append(np.array([])) stg.BS_noise_raw_data.append(np.array([])) + stg.BS_noise_averaged_data.append(np.array([])) else: stg.time_noise.append( np_f64_parse(time).reshape( @@ -390,6 +391,7 @@ class ReadTableForOpen: ) ) ) + stg.BS_noise_averaged_data.append(np.array([])) def read_table_BS_raw_data_SNR(self, query, i): np_f64_parse = lambda d: np.frombuffer(d, dtype=np.float64) @@ -406,9 +408,11 @@ class ReadTableForOpen: SNR_vars = [ (stg.SNR_raw_data, stg.BS_raw_data), (stg.SNR_cross_section, stg.BS_cross_section), - (stg.SNR_cross_section, stg.BS_stream_bed), + (stg.SNR_stream_bed, stg.BS_stream_bed), ] + stg.SNR_stream_bed.append(np.array([])) + for dest, resh in SNR_vars: SNR = np_f64_parse(next(it)) @@ -417,7 +421,6 @@ class ReadTableForOpen: else: dest.append(SNR.reshape(resh[i].shape)) - def read_table_BS_raw_data_rest(self, query, i): np_f64_parse = lambda d: np.frombuffer(d, dtype=np.float64) data = self.execute( @@ -481,16 +484,21 @@ class ReadTableForOpen: WHERE (acoustic_data = {s}) ''' - data3 = self.execute(query3) + data = self.execute(query3) + x = data[0] - stg.temperature = [x[1] for x in data3][0] - stg.tmin.append([(x[2], x[3]) for x in data3]) - stg.tmax.append([(x[4], x[5]) for x in data3]) - stg.rmin.append([(x[6], x[7]) for x in data3]) - stg.rmax.append([(x[8], x[9]) for x in data3]) - stg.freq_bottom_detection.append([(x[10], x[11]) for x in data3]) - stg.SNR_filter_value.append([x[12] for x in data3]) - stg.Nb_cells_to_average_BS_signal.append([x[13] for x in data3]) + stg.temperature = [x[1]][0] + stg.tmin.append((x[2], x[3])) + stg.tmax.append((x[4], x[5])) + stg.rmin.append((x[6], x[7])) + stg.rmax.append((x[8], x[9])) + stg.freq_bottom_detection.append((x[10], x[11])) + stg.SNR_filter_value.append(x[12]) + stg.Nb_cells_to_average_BS_signal.append(x[13]) + + logger.debug(f"stg.tmin: {stg.tmin}") + logger.debug(f"stg.tmin: {stg.tmax}") + logger.debug(f"stg.SNR_filter_value: {stg.SNR_filter_value}") def read_table_sediment_file(self): query = f''' diff --git a/View/acoustic_data_tab.py b/View/acoustic_data_tab.py index 0100bee..9794129 100644 --- a/View/acoustic_data_tab.py +++ b/View/acoustic_data_tab.py @@ -1653,9 +1653,9 @@ class AcousticDataTab(QWidget): stg.gain_tx.append(acoustic_data._gain_tx) stg.water_attenuation.append([]) - # --- The other acoustic variables lists are filled with empty object. --- - # --- They will be used for pre- and post-processing --- + self.initiate_setting_parameters_new_others() + def initiate_setting_parameters_new_others(self): stg.BS_cross_section.append(np.array([])) stg.depth_cross_section.append(np.array([])) stg.time_cross_section.append(np.array([])) diff --git a/View/signal_processing_tab.py b/View/signal_processing_tab.py index 5182c46..753ef46 100644 --- a/View/signal_processing_tab.py +++ b/View/signal_processing_tab.py @@ -521,15 +521,12 @@ class SignalProcessingTab(QWidget): self.blockSignals(True) self.combobox_acoustic_data_choice.blockSignals(True) - self.combobox_acoustic_data_choice.addItems(stg.filename_BS_raw_data) - - # self.recompute() - # self.replot() + self.update_SignalPreprocessingTab(recompute=True) self.combobox_acoustic_data_choice.blockSignals(False) self.blockSignals(False) - def update_SignalPreprocessingTab(self): + def update_SignalPreprocessingTab(self, recompute=True): """ The tab is updated in two cases : - the user remove a file (in the list widget) in the first tab (Acoustic data), so that the combobox @@ -567,7 +564,9 @@ class SignalProcessingTab(QWidget): stg.freq_text[data_id] ) - self.recompute() + if recompute: + self.recompute() + self.replot() logger.debug("Update the Signal preprocessing tab... Done") @@ -795,9 +794,17 @@ class SignalProcessingTab(QWidget): self.compute_average_profile_tail() - self.lineEdit_SNR_criterion.setText(str(stg.SNR_filter_value[self.combobox_acoustic_data_choice.currentIndex()])) + self.lineEdit_SNR_criterion.setText( + str(stg.SNR_filter_value[ + self.combobox_acoustic_data_choice.currentIndex() + ]) + ) - self.lineEdit_horizontal_average.setText(str(stg.Nb_cells_to_average_BS_signal[self.combobox_acoustic_data_choice.currentIndex()])) + self.lineEdit_horizontal_average.setText( + str(stg.Nb_cells_to_average_BS_signal[ + self.combobox_acoustic_data_choice.currentIndex() + ]) + ) self.combobox_frequency_profile.clear() self.combobox_frequency_profile.addItems( diff --git a/main.py b/main.py index 93ff65f..74587f7 100644 --- a/main.py +++ b/main.py @@ -97,7 +97,7 @@ class MainApplication(QMainWindow): self.tabs = [ self.acoustic_data_tab, - # self.signal_processing_tab, + self.signal_processing_tab, # self.sample_data_tab, # self.sediment_calibration_tab, # self.acoustic_inversion_tab,