From d19b7add9f85e398d505ba6825f674b4e8be2817 Mon Sep 17 00:00:00 2001 From: brahim Date: Tue, 1 Aug 2023 16:10:02 +0200 Subject: [PATCH] Button Class PSD and Cumulative PSD work : plots are updated pushing button and/or selecting checkboxes in sample table --- View/sample_data_tab.py | 163 +++++++++++++++++++++++----------------- 1 file changed, 93 insertions(+), 70 deletions(-) diff --git a/View/sample_data_tab.py b/View/sample_data_tab.py index b9d29c7..3bab249 100644 --- a/View/sample_data_tab.py +++ b/View/sample_data_tab.py @@ -224,6 +224,8 @@ class SampleDataTab(QWidget): self.pushbutton_class_PSD.setText("Class PSD") self.horizontalLayout_groupbox_option_PSD_plot.addWidget(self.pushbutton_class_PSD) + self.pushbutton_class_PSD.clicked.connect(self.update_plot_fine_and_sand_sediments_PSD_class) + # self.pushbutton_class_PSD.clicked_signal[str].connect(self.on_clicked) # if self.tableWidget_sample.columnCount() == 10: @@ -235,6 +237,8 @@ class SampleDataTab(QWidget): self.pushbutton_cumulative_PSD.setText("Cumulative PSD") self.horizontalLayout_groupbox_option_PSD_plot.addWidget(self.pushbutton_cumulative_PSD) + self.pushbutton_cumulative_PSD.clicked.connect(self.update_plot_fine_and_sand_sediments_PSD_cumul) + # if self.tableWidget_sample.columnCount() == 10: # self.pushbutton_cumulative_PSD.clicked.connect(self.empty_field_to_plot_fine_sediment_distribution) # else: @@ -799,97 +803,116 @@ class SampleDataTab(QWidget): # self.canvas_plot_PSD.draw() def update_plot_fine_and_sand_sediments_PSD_class(self): - position_list, color_list = self.extract_position_list_and_color_list_from_table_checkboxes() + if self.tableWidget_sample.columnCount() > 15: - granulo_data = deepcopy( - GranuloLoader(self.lineEdit_fine_sediment.toolTip() + "/" + self.lineEdit_fine_sediment.text(), - self.lineEdit_sand.toolTip() + "/" + self.lineEdit_sand.text())) + # --- Read sample data --- + granulo_data = deepcopy( + GranuloLoader(self.lineEdit_fine_sediment.toolTip() + "/" + self.lineEdit_fine_sediment.text(), + self.lineEdit_sand.toolTip() + "/" + self.lineEdit_sand.text())) - if self.canvas_plot_PSD == None: + # --- Read selected samples (checkboxes) --- + position_list, color_list = self.extract_position_list_and_color_list_from_table_checkboxes() - self.figure_plot_PSD, self.axis_plot_PSD = plt.subplots(nrows=1, ncols=2, layout="constrained") - self.canvas_plot_PSD = FigureCanvas(self.figure_plot_PSD) - self.verticalLayout_plot_PSD.addWidget(self.canvas_plot_PSD) + if position_list == []: - for profil_position_num, color_plot in zip(position_list, color_list): - self.axis_plot_PSD[0].plot(granulo_data._r_grain, - granulo_data._frac_vol_fine[profil_position_num, :], - color=color_plot) - self.axis_plot_PSD[0].set_xscale('log') - self.axis_plot_PSD[0].set_xlabel('Radius ($\mu m$)') - self.axis_plot_PSD[0].set_ylabel('Size class volume fraction') + msgBox = QMessageBox() + msgBox.setWindowTitle("Axis choice Error") + msgBox.setIcon(QMessageBox.Warning) + msgBox.setText("Select sample(s) before changing axis") + msgBox.setStandardButtons(QMessageBox.Ok) + msgBox.exec() - self.axis_plot_PSD[1].plot(granulo_data._r_grain, - granulo_data._frac_vol_sand[profil_position_num, :], - color=color_plot) - self.axis_plot_PSD[1].set_xscale('log') - self.axis_plot_PSD[1].set_xlabel('Radius ($\mu m$)') - self.axis_plot_PSD[1].set_ylabel('Size class volume fraction') + else: - self.canvas_plot_PSD.draw() + # --- Create canvas of Matplotlib figure --- + if self.canvas_plot_PSD == None: + self.figure_plot_PSD, self.axis_plot_PSD = plt.subplots(nrows=1, ncols=2, layout="constrained") + self.canvas_plot_PSD = FigureCanvas(self.figure_plot_PSD) + self.verticalLayout_plot_PSD.addWidget(self.canvas_plot_PSD) + else: + self.axis_plot_PSD[0].cla() + self.axis_plot_PSD[1].cla() - else: - self.axis_plot_PSD[0].cla() - self.axis_plot_PSD[1].cla() - - for profil_position_num, color_plot in zip(position_list, color_list): - self.axis_plot_PSD[0].plot(granulo_data._r_grain, - granulo_data._frac_vol_fine[profil_position_num, :], - color=color_plot) - self.axis_plot_PSD[0].set_xscale('log') - self.axis_plot_PSD[0].set_xlabel('Radius ($\mu m$)') - self.axis_plot_PSD[0].set_ylabel('Size class volume fraction') - - self.axis_plot_PSD[1].plot(granulo_data._r_grain, - granulo_data._frac_vol_sand[profil_position_num, :], - color=color_plot) - self.axis_plot_PSD[1].set_xscale('log') - self.axis_plot_PSD[1].set_xlabel('Radius ($\mu m$)') - self.axis_plot_PSD[1].set_ylabel('Size class volume fraction') - - self.canvas_plot_PSD.draw() - - - def update_plot_fine_and_sand_sediments_PSD_cumul(self): - granulo_data = deepcopy( - GranuloLoader(self.lineEdit_fine_sediment.toolTip() + "/" + self.lineEdit_fine_sediment.text(), - self.lineEdit_sand.toolTip() + "/" + self.lineEdit_sand.text())) - - if self.canvas_plot_PSD == None: - self.figure_plot_PSD, self.axis_plot_PSD = plt.subplots(nrows=1, ncols=2, layout="constrained") - self.canvas_plot_PSD = FigureCanvas(self.figure_plot_PSD) - self.verticalLayout_plot_PSD.addWidget(self.canvas_plot_PSD) - - if self.pushbutton_class_PSD.sender(): - if self.tableWidget_sample.columnCount() > 10: - position_list, color_list = self.extract_position_list_and_color_list_from_table_checkboxes() - self.axis_plot_PSD[0].cla() for profil_position_num, color_plot in zip(position_list, color_list): self.axis_plot_PSD[0].plot(granulo_data._r_grain, granulo_data._frac_vol_fine[profil_position_num, :], color=color_plot) self.axis_plot_PSD[0].set_xscale('log') self.axis_plot_PSD[0].set_xlabel('Radius ($\mu m$)') - self.axis_plot_PSD[0].set_ylabel('Size class volume fraction') + self.axis_plot_PSD[0].set_ylabel('Class size volume fraction') + + self.axis_plot_PSD[1].plot(granulo_data._r_grain, + granulo_data._frac_vol_sand[profil_position_num, :], + color=color_plot) + self.axis_plot_PSD[1].set_xscale('log') + self.axis_plot_PSD[1].set_xlabel('Radius ($\mu m$)') + self.axis_plot_PSD[1].set_ylabel('Class size volume fraction') + self.canvas_plot_PSD.draw() + + else: + msgBox = QMessageBox() + msgBox.setWindowTitle("Plot PSD Error") + msgBox.setIcon(QMessageBox.Warning) + msgBox.setText("Fill table and select sample(s) before plotting PSD") + msgBox.setStandardButtons(QMessageBox.Ok) + msgBox.exec() + + def update_plot_fine_and_sand_sediments_PSD_cumul(self): + if self.tableWidget_sample.columnCount() > 15: + + # --- Read sample data --- + granulo_data = deepcopy( + GranuloLoader(self.lineEdit_fine_sediment.toolTip() + "/" + self.lineEdit_fine_sediment.text(), + self.lineEdit_sand.toolTip() + "/" + self.lineEdit_sand.text())) + + # --- Read selected samples (checkboxes) --- + position_list, color_list = self.extract_position_list_and_color_list_from_table_checkboxes() + + if position_list == []: + + msgBox = QMessageBox() + msgBox.setWindowTitle("Axis choice Error") + msgBox.setIcon(QMessageBox.Warning) + msgBox.setText("Select sample(s) before changing axis") + msgBox.setStandardButtons(QMessageBox.Ok) + msgBox.exec() + else: - self.empty_field_for_plot_fine_PSD_class() - self.empty_field_for_plot_sand_PSD_class() - elif self.pushbutton_cumulative_PSD.sender(): - if self.tableWidget_sample.columnCount() > 10: - position_list, color_list = self.extract_position_list_and_color_list_from_table_checkboxes() - self.axis_plot_PSD[0].cla() + + # --- Create canvas of Matplotlib figure --- + if self.canvas_plot_PSD == None: + self.figure_plot_PSD, self.axis_plot_PSD = plt.subplots(nrows=1, ncols=2, layout="constrained") + self.canvas_plot_PSD = FigureCanvas(self.figure_plot_PSD) + self.verticalLayout_plot_PSD.addWidget(self.canvas_plot_PSD) + else: + self.axis_plot_PSD[0].cla() + self.axis_plot_PSD[1].cla() + for profil_position_num, color_plot in zip(position_list, color_list): self.axis_plot_PSD[0].plot(granulo_data._r_grain, granulo_data._frac_vol_fine_cumul[profil_position_num, :], color=color_plot) self.axis_plot_PSD[0].set_xscale('log') self.axis_plot_PSD[0].set_xlabel('Radius ($\mu m$)') - self.axis_plot_PSD[0].set_ylabel('Cumulated size volume fraction') - self.canvas_plot_PSD.draw() - # else: - # self.empty_field_for_plot_fine_PSD_cumul() - # self.empty_field_for_plot_sand_PSD_cumul() + self.axis_plot_PSD[0].set_ylabel('Cumulative size volume fraction') + + self.axis_plot_PSD[1].plot(granulo_data._r_grain, + granulo_data._frac_vol_sand_cumul[profil_position_num, :], + color=color_plot) + self.axis_plot_PSD[1].set_xscale('log') + self.axis_plot_PSD[1].set_xlabel('Radius ($\mu m$)') + self.axis_plot_PSD[1].set_ylabel('Cumulative size volume fraction') + + self.canvas_plot_PSD.draw() + + else: + msgBox = QMessageBox() + msgBox.setWindowTitle("Plot PSD Error") + msgBox.setIcon(QMessageBox.Warning) + msgBox.setText("Fill table and select sample(s) before plotting PSD") + msgBox.setStandardButtons(QMessageBox.Ok) + msgBox.exec() # def update_plot_fine_PSD_class(self, profil_position, color_list): # granulo_data = deepcopy(