Source code for gui.core.Plot_ICA_PCA

from PyQt5 import QtWidgets

from gui.ui.Plot_ICA_PCA import Ui_Form
from gui.util.Modules import Modules
from gui.util.plots import pca_ica_plot


[docs] class Plot_ICA_PCA(Ui_Form, Modules):
[docs] def setupUi(self, Form): super().setupUi(Form) Modules.setupUi(self, Form)
[docs] def get_widget(self): return self.groupBox
[docs] def connectWidgets(self): alg_choices = ["Choose a method", "PCA", "FastICA", "JADE-ICA"] self.setComboBox(self.chooseDataComboBox, self.datakeys) self.setComboBox(self.chooseMethodComboBox, alg_choices) self.colorchoices_change_vars(self.colorCodedVariableComboBox) self.pushButton.clicked.connect(self.on_plotFilenamePushButton_clicked) self.chooseMethodComboBox.currentIndexChanged.connect( lambda: self.changeComboListVars( self.chooseXVariableComboBox, self.xychoices() ) ) self.chooseMethodComboBox.currentIndexChanged.connect( lambda: self.changeComboListVars( self.chooseYVariableComboBox, self.xychoices() ) ) self.chooseDataComboBox.currentIndexChanged.connect( lambda: self.colorchoices_change_vars(self.colorCodedVariableComboBox) )
[docs] def run(self): cmap = "viridis" datakey = self.chooseDataComboBox.currentText() method = self.chooseMethodComboBox.currentText() dimredkey = datakey + "-" + method try: dimred_obj = self.dimred[dimredkey] except: dimred_obj = None x_component = self.chooseXVariableComboBox.currentText() y_component = self.chooseYVariableComboBox.currentText() if self.colorCodedVariableComboBox.currentText() != "None": colorvar = self.colorCodedVariableComboBox.currentText() else: colorvar = None filename = self.plotFilenameLineEdit.text() figpath, figfile = "/".join(filename.split("/")[:-1]), filename.split("/")[-1] pca_ica_plot( self.data[datakey], x_component, y_component, dimred_obj, colorvar=colorvar, cmap=cmap, method=method + " (wvl)", figpath=figpath, figfile=figfile, )
[docs] def xychoices(self): try: method_tmp = self.chooseMethodComboBox.currentText() + " (wvl)" choices = [ str(i) for i in self.data[self.chooseDataComboBox.currentText()].df[method_tmp] ] except Exception as e: print(e) choices = ["-"] return choices
[docs] def on_plotFilenamePushButton_clicked(self): filename, _filter = QtWidgets.QFileDialog.getSaveFileName( None, "Save Plot", self.outpath, "(*.png)" ) self.plotFilenameLineEdit.setText(filename) if self.plotFilenameLineEdit.text() == "": self.plotFilenameLineEdit.setText("*.png")
[docs] def colorchoices_change_vars(self, obj): obj.clear() choices = ["None"] try: self.vars_level0 = self.data[ self.chooseDataComboBox.currentText() ].df.columns.get_level_values(0) self.vars_level1 = self.data[ self.chooseDataComboBox.currentText() ].df.columns.get_level_values(1) col = self.data[self.chooseDataComboBox.currentText()].spect_label self.vars_level1 = self.vars_level1[self.vars_level0 != col] self.vars_level0 = self.vars_level0[self.vars_level0 != col] self.vars_level1 = list(self.vars_level1[self.vars_level0 != "masked"]) self.vars_level0 = list(self.vars_level0[self.vars_level0 != "masked"]) try: self.vars_level0 = [ i for i in self.vars_level0 if "Unnamed" not in str(i) ] # remove unnamed columns from # choices except Exception as e: print(e) pass try: self.vars_level1 = [ i for i in self.vars_level1 if "Unnamed" not in str(i) ] # remove unnamed columns from # choices except Exception as e: print(e) pass for i in self.vars_level1: choices.append(str(i)) except Exception as e: print(e) try: temptext = self.chooseDataComboBox.currentText() choices.append(self.data[temptext].columns.values) except Exception as e: print(e) pass for i in choices: obj.addItem(str(i))
if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) Form = QtWidgets.QWidget() ui = Plot_ICA_PCA() ui.setupUi(Form) Form.show() sys.exit(app.exec_())