From abce4bac071476baace3730a3f8dbd1a11bb471f Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby Date: Wed, 7 May 2025 14:44:29 +0200 Subject: [PATCH] Acoustic inversion: Fix fine plot and minor change sand plot. --- View/acoustic_inversion_tab.py | 213 ++++++++++++++++----------------- 1 file changed, 106 insertions(+), 107 deletions(-) diff --git a/View/acoustic_inversion_tab.py b/View/acoustic_inversion_tab.py index 099eb38..44c38b8 100644 --- a/View/acoustic_inversion_tab.py +++ b/View/acoustic_inversion_tab.py @@ -1035,7 +1035,7 @@ class AcousticInversionTab(QWidget): self.verticalLayout_groupbox_plot_measured_vs_inverted_SSC_fine\ .addWidget(self.canvas_inverted_vs_measured_SSC_fine) - if stg.SSC_fine[data_id].shape == (0,): + if stg.SSC_fine[data_id].shape != (0,): fine_id = self.combobox_fine_sample_choice.currentData() self.fine_sample_to_plot = [ @@ -1551,124 +1551,123 @@ class AcousticInversionTab(QWidget): ) def plot_measured_vs_inverted_SSC_sand(self): + if self.combobox_acoustic_data_choice.count() <= 0: + return - if self.combobox_acoustic_data_choice.count() > 0: + if stg.SSC_sand[self.combobox_acoustic_data_choice.currentIndex()].shape == (0,): + self.verticalLayout_groupbox_plot_measured_vs_inverted_SSC_sand.removeWidget( + self.toolbar_inverted_vs_measured_SSC_sand) + self.verticalLayout_groupbox_plot_measured_vs_inverted_SSC_sand.removeWidget( + self.canvas_inverted_vs_measured_SSC_sand) - if stg.SSC_sand[self.combobox_acoustic_data_choice.currentIndex()].shape == (0,): + self.canvas_inverted_vs_measured_SSC_sand = FigureCanvas() + self.toolbar_inverted_vs_measured_SSC_sand = NavigationToolBar( + self.canvas_inverted_vs_measured_SSC_sand, self) - self.verticalLayout_groupbox_plot_measured_vs_inverted_SSC_sand.removeWidget( - self.toolbar_inverted_vs_measured_SSC_sand) - self.verticalLayout_groupbox_plot_measured_vs_inverted_SSC_sand.removeWidget( - self.canvas_inverted_vs_measured_SSC_sand) + self.verticalLayout_groupbox_plot_measured_vs_inverted_SSC_sand.addWidget( + self.toolbar_inverted_vs_measured_SSC_sand) + self.verticalLayout_groupbox_plot_measured_vs_inverted_SSC_sand.addWidget( + self.canvas_inverted_vs_measured_SSC_sand) - self.canvas_inverted_vs_measured_SSC_sand = FigureCanvas() - self.toolbar_inverted_vs_measured_SSC_sand = NavigationToolBar( - self.canvas_inverted_vs_measured_SSC_sand, self) + else: - self.verticalLayout_groupbox_plot_measured_vs_inverted_SSC_sand.addWidget( - self.toolbar_inverted_vs_measured_SSC_sand) - self.verticalLayout_groupbox_plot_measured_vs_inverted_SSC_sand.addWidget( - self.canvas_inverted_vs_measured_SSC_sand) + self.verticalLayout_groupbox_plot_measured_vs_inverted_SSC_sand.removeWidget( + self.toolbar_inverted_vs_measured_SSC_sand) + self.verticalLayout_groupbox_plot_measured_vs_inverted_SSC_sand.removeWidget( + self.canvas_inverted_vs_measured_SSC_sand) + + if self.figure_measured_vs_inverted_sand is not None: + self.figure_measured_vs_inverted_sand.clear() + plt.close(fig=self.figure_measured_vs_inverted_sand) + + fig, ax = plt.subplots(nrows=1, ncols=1, layout="constrained") + self.figure_measured_vs_inverted_sand = fig + self.axis_measured_vs_inverted_sand = ax + + + self.canvas_inverted_vs_measured_SSC_sand = FigureCanvas(self.figure_measured_vs_inverted_sand) + self.toolbar_inverted_vs_measured_SSC_sand = NavigationToolBar(self.canvas_inverted_vs_measured_SSC_sand, self) + + self.verticalLayout_groupbox_plot_measured_vs_inverted_SSC_sand.addWidget( + self.toolbar_inverted_vs_measured_SSC_sand) + self.verticalLayout_groupbox_plot_measured_vs_inverted_SSC_sand.addWidget( + self.canvas_inverted_vs_measured_SSC_sand) + + self.sand_sample_to_plot = [int(f[1:]) - 1 for f in self.combobox_sand_sample_choice.currentData()] + + if self.sand_sample_to_plot: + + self.axis_measured_vs_inverted_sand.plot( + [stg.Ctot_sand[k] for k in self.sand_sample_to_plot], + [stg.SSC_sand[self.combobox_acoustic_data_choice.currentIndex()][ + stg.sand_sample_position[k][1], + stg.sand_sample_position[k][0]] for k in + self.sand_sample_to_plot], + ls=" ", marker='o', ms=5, mec='black', mfc="black" + ) + + self.axis_measured_vs_inverted_sand.plot( + [0, np.nanmax([np.nanmax([stg.Ctot_sand[c] for c in self.sand_sample_to_plot]), + np.nanmax([stg.SSC_sand[self.combobox_acoustic_data_choice.currentIndex()][ + stg.sand_sample_position[i][1], + stg.sand_sample_position[i][0]] + for i in self.sand_sample_to_plot])]) + 1], + [0, np.nanmax([np.nanmax([stg.Ctot_sand[c] for c in self.sand_sample_to_plot]), + np.nanmax([stg.SSC_sand[self.combobox_acoustic_data_choice.currentIndex()][ + stg.sand_sample_position[i][1], + stg.sand_sample_position[i][0]] + for i in self.sand_sample_to_plot])]) + 1], + ls="solid", linewidth=1, color="k" + ) + + # --- Display sample label on plot --- + for i in self.sand_sample_to_plot: + self.axis_measured_vs_inverted_sand.text( + stg.Ctot_sand[i], + stg.SSC_sand[self.combobox_acoustic_data_choice.currentIndex()][ + stg.sand_sample_position[i][1], + stg.sand_sample_position[i][0]], + stg.sample_sand[i][0], + fontstyle="normal", fontweight="light", fontsize=10) else: - self.verticalLayout_groupbox_plot_measured_vs_inverted_SSC_sand.removeWidget( - self.toolbar_inverted_vs_measured_SSC_sand) - self.verticalLayout_groupbox_plot_measured_vs_inverted_SSC_sand.removeWidget( - self.canvas_inverted_vs_measured_SSC_sand) + self.axis_measured_vs_inverted_sand.plot( + [stg.Ctot_sand[k] for k in range(len(stg.sample_sand))], + [stg.SSC_sand[self.combobox_acoustic_data_choice.currentIndex()][ + stg.sand_sample_position[k][1], + stg.sand_sample_position[k][0]] for k in + range(len(stg.sample_sand))], + ls=" ", marker='o', ms=5, mec='black', mfc="black" + ) - if self.figure_measured_vs_inverted_sand is not None: - self.figure_measured_vs_inverted_sand.clear() - plt.close(fig=self.figure_measured_vs_inverted_sand) + self.axis_measured_vs_inverted_sand.plot( + [0, np.nanmax([np.nanmax([stg.Ctot_sand[c] for c in range(len(stg.sample_sand))]), + np.nanmax([stg.SSC_sand[self.combobox_acoustic_data_choice.currentIndex()][ + stg.sand_sample_position[i][1], + stg.sand_sample_position[i][0]] + for i in range(len(stg.sample_sand))])]) + 1], + [0, np.nanmax([np.nanmax([stg.Ctot_sand[c] for c in range(len(stg.sample_sand))]), + np.nanmax([stg.SSC_sand[self.combobox_acoustic_data_choice.currentIndex()][ + stg.sand_sample_position[i][1], + stg.sand_sample_position[i][0]] + for i in range(len(stg.sample_sand))])]) + 1], + ls="solid", linewidth=1, color="k" + ) - fig, ax = plt.subplots(nrows=1, ncols=1, layout="constrained") - self.figure_measured_vs_inverted_sand = fig - self.axis_measured_vs_inverted_sand = ax + for j in range(len(stg.sample_sand)): + self.axis_measured_vs_inverted_sand.text( + stg.Ctot_sand[j], + stg.SSC_sand[self.combobox_acoustic_data_choice.currentIndex()][ + stg.sand_sample_position[j][1], + stg.sand_sample_position[j][0]], + stg.sample_sand[j][0], + fontstyle="normal", fontweight="light", fontsize=10) + self.axis_measured_vs_inverted_sand.set_xlabel("Measured SSC sand (g/L)") + self.axis_measured_vs_inverted_sand.set_ylabel("Inverted SSC sand (g/L)") - self.canvas_inverted_vs_measured_SSC_sand = FigureCanvas(self.figure_measured_vs_inverted_sand) - self.toolbar_inverted_vs_measured_SSC_sand = NavigationToolBar(self.canvas_inverted_vs_measured_SSC_sand, self) - - self.verticalLayout_groupbox_plot_measured_vs_inverted_SSC_sand.addWidget( - self.toolbar_inverted_vs_measured_SSC_sand) - self.verticalLayout_groupbox_plot_measured_vs_inverted_SSC_sand.addWidget( - self.canvas_inverted_vs_measured_SSC_sand) - - self.sand_sample_to_plot = [int(f[1:]) - 1 for f in self.combobox_sand_sample_choice.currentData()] - - if self.sand_sample_to_plot: - - self.axis_measured_vs_inverted_sand.plot( - [stg.Ctot_sand[k] for k in self.sand_sample_to_plot], - [stg.SSC_sand[self.combobox_acoustic_data_choice.currentIndex()][ - stg.sand_sample_position[k][1], - stg.sand_sample_position[k][0]] for k in - self.sand_sample_to_plot], - ls=" ", marker='o', ms=5, mec='black', mfc="black" - ) - - self.axis_measured_vs_inverted_sand.plot( - [0, np.nanmax([np.nanmax([stg.Ctot_sand[c] for c in self.sand_sample_to_plot]), - np.nanmax([stg.SSC_sand[self.combobox_acoustic_data_choice.currentIndex()][ - stg.sand_sample_position[i][1], - stg.sand_sample_position[i][0]] - for i in self.sand_sample_to_plot])]) + 1], - [0, np.nanmax([np.nanmax([stg.Ctot_sand[c] for c in self.sand_sample_to_plot]), - np.nanmax([stg.SSC_sand[self.combobox_acoustic_data_choice.currentIndex()][ - stg.sand_sample_position[i][1], - stg.sand_sample_position[i][0]] - for i in self.sand_sample_to_plot])]) + 1], - ls="solid", linewidth=1, color="k" - ) - - # --- Display sample label on plot --- - for i in self.sand_sample_to_plot: - self.axis_measured_vs_inverted_sand.text( - stg.Ctot_sand[i], - stg.SSC_sand[self.combobox_acoustic_data_choice.currentIndex()][ - stg.sand_sample_position[i][1], - stg.sand_sample_position[i][0]], - stg.sample_sand[i][0], - fontstyle="normal", fontweight="light", fontsize=10) - - else: - - self.axis_measured_vs_inverted_sand.plot( - [stg.Ctot_sand[k] for k in range(len(stg.sample_sand))], - [stg.SSC_sand[self.combobox_acoustic_data_choice.currentIndex()][ - stg.sand_sample_position[k][1], - stg.sand_sample_position[k][0]] for k in - range(len(stg.sample_sand))], - ls=" ", marker='o', ms=5, mec='black', mfc="black" - ) - - self.axis_measured_vs_inverted_sand.plot( - [0, np.nanmax([np.nanmax([stg.Ctot_sand[c] for c in range(len(stg.sample_sand))]), - np.nanmax([stg.SSC_sand[self.combobox_acoustic_data_choice.currentIndex()][ - stg.sand_sample_position[i][1], - stg.sand_sample_position[i][0]] - for i in range(len(stg.sample_sand))])]) + 1], - [0, np.nanmax([np.nanmax([stg.Ctot_sand[c] for c in range(len(stg.sample_sand))]), - np.nanmax([stg.SSC_sand[self.combobox_acoustic_data_choice.currentIndex()][ - stg.sand_sample_position[i][1], - stg.sand_sample_position[i][0]] - for i in range(len(stg.sample_sand))])]) + 1], - ls="solid", linewidth=1, color="k" - ) - - for j in range(len(stg.sample_sand)): - self.axis_measured_vs_inverted_sand.text( - stg.Ctot_sand[j], - stg.SSC_sand[self.combobox_acoustic_data_choice.currentIndex()][ - stg.sand_sample_position[j][1], - stg.sand_sample_position[j][0]], - stg.sample_sand[j][0], - fontstyle="normal", fontweight="light", fontsize=10) - - self.axis_measured_vs_inverted_sand.set_xlabel("Measured SSC sand (g/L)") - self.axis_measured_vs_inverted_sand.set_ylabel("Inverted SSC sand (g/L)") - - self.figure_measured_vs_inverted_sand.canvas.draw_idle() + self.figure_measured_vs_inverted_sand.canvas.draw_idle() def save_result(self): if self.combobox_acoustic_data_choice.count() <= 0: