Source code for gui.core.Unmixing

import pandas as pd
from PyQt5 import QtWidgets

import gui.core.unmixingMethods as um
from gui.ui.Unmixing import Ui_Form
from gui.util import Qtickle
from gui.util.Modules import Modules


# import mesma

[docs] class Unmixing(Ui_Form, Modules):
[docs] def setupUi(self, Form): self.Form = Form super().setupUi(Form) Modules.setupUi(self, Form) self.unmixingMethods()
[docs] def get_widget(self): return self.formGroupBox
[docs] def connectWidgets(self): self.algorithm_list = ['Choose an algorithm', 'NNLS', 'FCLS', 'UCLS', 'LMM', 'GBM'] self.setComboBox(self.chooseDataComboBox, self.datakeys) self.setComboBox(self.endmemberscomboBox, self.datakeys) self.setComboBox(self.chooseMethodComboBox, self.algorithm_list) self.chooseMethodComboBox.currentIndexChanged.connect( lambda: self.make_unmix_widget( self.chooseMethodComboBox.currentText() ) )
[docs] def getGuiParams(self): """ Overriding Modules' getGuiParams, because I'll need to do a list of lists in order to obtain the regressionMethods' parameters """ self.qt = Qtickle.Qtickle(self) s = [] s.append(self.qt.guiSave()) for items in self.alg: s.append(items.getGuiParams()) return s
[docs] def setGuiParams(self, dict): """ Overriding Modules' setGuiParams, because we are accessing a list of lists And each submodule contains its own `setGuiParams` """ self.qt = Qtickle.Qtickle(self) self.qt.guiRestore(dict[0]) for i in range(len(dict)): self.alg[i - 1].setGuiParams(dict[i])
[docs] def selectiveSetGuiParams(self, dict): """ Override Modules' selective Restore function Setup Qtickle selectively restore the UI, the data to do that will be in the 0th element of the dictionary We will then iterate through the rest of the dictionary Will now restore the parameters for the algorithms in the list, Each of the algs have their own selectiveSetGuiParams :param dict: :return: """ self.qt = Qtickle.Qtickle(self) self.qt.selectiveGuiRestore(dict[0]) for i in range(len(dict)): self.alg[i - 1].selectiveSetGuiParams(dict[i])
[docs] def run(self): pyspmethods = ['FCLS', 'UCLS', 'NNLS'] normalize = False params = None method = self.chooseMethodComboBox.currentText() datakey = self.chooseDataComboBox.currentText() endmembers = self.endmemberscomboBox.currentText() if method in pyspmethods: normalize = self.getMethodParams( self.chooseMethodComboBox.currentIndex() ) else: params = self.getMethodParams( self.chooseMethodComboBox.currentIndex() ) results = self.data[datakey].unmix( self.data[endmembers].df, method, params=params, normalize=normalize ) if results.columns[0] in self.data[datakey].df.columns: print( 'Identical column names detected! Cannot add unmixing ' 'results to data frame.' ) else: self.data[datakey].df = pd.concat( ( self.data[datakey].df, results), axis=1 )
[docs] def make_unmix_widget(self, alg, params=None): self.hideAll() # print(alg) for i in range(len(self.algorithm_list)): if alg == self.algorithm_list[i]: self.alg[i - 1].setHidden(False)
[docs] def hideAll(self): for a in self.alg: a.setHidden(True)
[docs] def unmixingMethods(self): self.alg = [] list_forms = [um.unmix_NNLS, um.unmix_FCLS, um.unmix_UCLS, um.unmix_LMM, um.unmix_GBM] for items in list_forms: self.alg.append(items.Ui_Form()) self.alg[-1].setupUi(self.Form) self.dim_reduction_vlayout.addWidget(self.alg[-1].get_widget()) self.alg[-1].setHidden(True)
[docs] def getMethodParams(self, index): return self.alg[index - 1].run()
if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) Form = QtWidgets.QWidget() ui = Unmixing() ui.setupUi(Form) Form.show() sys.exit(app.exec_())