From 815610ab20d29672f58f1963dd01b1bedeff22d6 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby Date: Mon, 28 Apr 2025 16:50:53 +0200 Subject: [PATCH] Acoustic inversion: Fix fine and sand sample choice duplication. --- View/acoustic_inversion_tab.py | 137 +++++++-------------------------- 1 file changed, 28 insertions(+), 109 deletions(-) diff --git a/View/acoustic_inversion_tab.py b/View/acoustic_inversion_tab.py index 85975a4..0751697 100644 --- a/View/acoustic_inversion_tab.py +++ b/View/acoustic_inversion_tab.py @@ -936,6 +936,7 @@ class AcousticInversionTab(QWidget): def fill_combobox_fine_sample(self): data_id = self.combobox_acoustic_data_choice.currentIndex() + self.combobox_fine_sample_choice.clear() self.combobox_fine_sample_choice.addItems( [f for f, _ in stg.sample_fine] ) @@ -1507,121 +1508,39 @@ class AcousticInversionTab(QWidget): # --- Plot sand SSC : measured vs inverted --- def fill_combobox_sand_sample(self): + data_id = self.combobox_acoustic_data_choice.currentIndex() - self.combobox_sand_sample_choice.addItems([f for f, _ in stg.sample_sand]) + self.combobox_sand_sample_choice.clear() + self.combobox_sand_sample_choice.addItems( + [f for f, _ in stg.sample_sand] + ) # --- Get position (index, value) of sample in acoustic measurement space --- - if ((stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,)) and - (stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,))): + if stg.time_cross_section[data_id].shape != (0,): + time_data = stg.time_cross_section + else: + time_data = stg.time - for j in range(len(stg.time_sand)): + if stg.depth_cross_section[data_id].shape != (0,): + depth_data = stg.depth_cross_section + else: + depth_data = stg.depth - (stg.sand_sample_position. - append( - ( - np.where( - np.abs(stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()][ - stg.frequency_for_inversion[1]] - stg.time_sand[j]) - == - np.nanmin(np.abs(stg.time_cross_section[ - self.combobox_acoustic_data_choice.currentIndex()][ - stg.frequency_for_inversion[1]] - stg.time_sand[j])) - )[0][0], - np.where( - np.abs(stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()][ - stg.frequency_for_inversion[1]] - (-stg.depth_sand[j])) - == - np.nanmin(np.abs(stg.depth_cross_section[ - self.combobox_acoustic_data_choice.currentIndex()][ - stg.frequency_for_inversion[1]] - (-stg.depth_sand[j]))) - )[0][0] - ) - ) - ) - - elif ((stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,)) and - (stg.depth[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,))): - - for j in range(len(stg.time_sand)): - - (stg.sand_sample_position. - append( - ( - np.where( - np.abs(stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()][ - stg.frequency_for_inversion[1]] - stg.time_sand[j]) - == - np.nanmin(np.abs(stg.time_cross_section[ - self.combobox_acoustic_data_choice.currentIndex()][ - stg.frequency_for_inversion[1]] - stg.time_sand[j])) - )[0][0], - np.where( - np.abs(stg.depth[self.combobox_acoustic_data_choice.currentIndex()][ - stg.frequency_for_inversion[1]] - (-stg.depth_sand[j])) - == - np.nanmin(np.abs(stg.depth[ - self.combobox_acoustic_data_choice.currentIndex()][ - stg.frequency_for_inversion[1]] - (-stg.depth_sand[j]))) - )[0][0] - ) - ) - ) - - elif ((stg.time[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,)) and - (stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,))): - - for j in range(len(stg.time_sand)): - - (stg.sand_sample_position. - append( - ( - np.where( - np.abs(stg.time[self.combobox_acoustic_data_choice.currentIndex()][ - stg.frequency_for_inversion[1]] - stg.time_sand[j]) - == - np.nanmin(np.abs(stg.time[ - self.combobox_acoustic_data_choice.currentIndex()][ - stg.frequency_for_inversion[1]] - stg.time_sand[j])) - )[0][0], - np.where( - np.abs(stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()][ - stg.frequency_for_inversion[1]] - (-stg.depth_sand[j])) - == - np.nanmin(np.abs(stg.depth_cross_section[ - self.combobox_acoustic_data_choice.currentIndex()][ - stg.frequency_for_inversion[1]] - (-stg.depth_sand[j]))) - )[0][0] - ) - ) - ) - - elif ((stg.time[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,)) and - (stg.depth[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,))): - - for j in range(len(stg.time_sand)): - - (stg.sand_sample_position. - append( - ( - np.where( - np.abs(stg.time[self.combobox_acoustic_data_choice.currentIndex()][ - stg.frequency_for_inversion[1]] - stg.time_sand[j]) - == - np.nanmin(np.abs(stg.time[ - self.combobox_acoustic_data_choice.currentIndex()][ - stg.frequency_for_inversion[1]] - stg.time_sand[j])) - )[0][0], - np.where( - np.abs(stg.depth[self.combobox_acoustic_data_choice.currentIndex()][ - stg.frequency_for_inversion[1]] - (-stg.depth_sand[j])) - == - np.nanmin(np.abs(stg.depth[ - self.combobox_acoustic_data_choice.currentIndex()][ - stg.frequency_for_inversion[1]] - (-stg.depth_sand[j]))) - )[0][0] - ) - ) + freq = stg.frequency_for_inversion[1] + for j in range(len(stg.time_sand)): + time_diff = np.abs(time_data[data_id][freq] - stg.time_sand[j]) + depth_diff = np.abs(depth_data[data_id][freq] - (-stg.depth_sand[j])) + + stg.sand_sample_position.append( + ( + np.where( + time_diff == np.nanmin(time_diff) + )[0][0], + np.where( + depth_diff == np.nanmin(depth_diff) + )[0][0] ) + ) def plot_measured_vs_inverted_SSC_sand(self):