Commit e04bce3d authored by Julia Garriga Ferrer's avatar Julia Garriga Ferrer
Browse files

[gui][pca] Set max number of components and compute button

parent 5f658653
......@@ -26,7 +26,7 @@
__authors__ = ["J. Garriga"]
__license__ = "MIT"
__date__ = "04/12/2019"
__date__ = "30/01/2020"
import numpy
......@@ -38,7 +38,7 @@ from darfix.core.blindSourceSeparation import BSS
from .operationThread import OperationThread
class PCAWidget(qt.QWidget):
class PCAWidget(qt.QMainWindow):
"""
Widget to apply PCA to a set of images and plot the eigenvalues found.
"""
......@@ -47,35 +47,57 @@ class PCAWidget(qt.QWidget):
def __init__(self, parent=None):
qt.QWidget.__init__(self, parent)
self.setLayout(qt.QVBoxLayout())
self._plot = Plot1D()
self.layout().addWidget(self._plot)
maxNComponentsLabel = qt.QLabel("Max number of components:")
self.maxNumComp = qt.QLineEdit("")
self.maxNumComp.setToolTip("Maximum number of components to compute")
self.maxNumComp.setValidator(qt.QDoubleValidator())
self.computeB = qt.QPushButton("Compute")
widget = qt.QWidget(parent=self)
layout = qt.QGridLayout()
layout.addWidget(maxNComponentsLabel, 0, 0, 1, 1)
layout.addWidget(self.maxNumComp, 0, 1, 1, 1)
layout.addWidget(self.computeB, 0, 2, 1, 1)
layout.addWidget(self._plot, 1, 0, 1, 3)
widget.setLayout(layout)
self.setCentralWidget(widget)
self._plot.hide()
def _computePCA(self):
self.computeB.setEnabled(False)
try:
txt = self.maxNumComp.text()
if txt != "":
maxNumComp = float(self.maxNumComp.text())
else:
maxNumComp = None
self._thread = OperationThread(self.BSS.PCA)
self._thread.setArgs(None, maxNumComp)
self._thread.finished.connect(self._updateData)
self._thread.start()
except Exception as e:
self.computeB.setEnabled(True)
raise e
def setDataset(self, dataset):
"""
Dataset setter. Starts BSS class and initalizes thread.
Dataset setter. Starts BSS class and initializes thread.
:param Dataset dataset: dataset
"""
self.dataset = dataset
self.BSS = BSS(self.dataset.hi_data)
self._thread = OperationThread(self.BSS.PCA)
self._computePCA()
def _computePCA(self):
"""
Slot that starts the thread to compute PCA.
"""
self._thread.finished.connect(self._updateData)
self._thread.start()
self.computeB.pressed.connect(self._computePCA)
def _updateData(self):
"""
Plots the eigenvalues.
"""
self._thread.finished.disconnect(self._updateData)
self.computeB.setEnabled(True)
mean, vecs, vals = self._thread.data
vals = [item for sublist in vals for item in sublist]
self._plot.show()
self._plot.addCurve(numpy.arange(len(vals)), vals, symbol='.', linestyle=' ')
self.signalComputed.emit()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment