Commit 86522ed2 authored by Hackmet's avatar Hackmet

Several Bugfixes

parent 8e5899e5
......@@ -336,9 +336,9 @@ class ParticleAnalysis(QtWidgets.QWidget):
self.specCanvas.draw()
####fake data!!!
if self.spectraResults is None:
self.spectraResults = ['empty']*(self.spectra.shape[1]-1)
self.hqis = [100]*(self.spectra.shape[1]-1)
# if self.spectraResults is None:
# self.spectraResults = ['empty']*(self.spectra.shape[1]-1)
# self.hqis = [100]*(self.spectra.shape[1]-1)
self.loadParticleData()
......@@ -362,7 +362,16 @@ class ParticleAnalysis(QtWidgets.QWidget):
#check, if dataset already contains results. Otherwise load them...
if self.spectraResults is None or (len(self.spectraResults) != len(sortindices)):
QtWidgets.QMessageBox.about(self, 'Info', 'No (or inconsistent) spectra results found, please run import dialog.')
self.show()
# QtWidgets.QMessageBox.about(self, 'Info', 'No (or inconsistent) spectra results found, please run import dialog.')
answer = QtWidgets.QMessageBox.question(self, 'Warning', 'No (or inconsistent) spectra results found, please run import dialog.\nPress OK to import or cancel to set to empty.', QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel)
if answer == QtWidgets.QMessageBox.Ok:
self.importResults()
elif answer == QtWidgets.QMessageBox.Cancel:
self.spectraResults = ['empty']*(self.spectra.shape[1]-1)
self.hqis = [100]*(self.spectra.shape[1]-1)
self.updateBtn.clicked.connect(self.formatResults)
self.formatResults()
else:
self.updateBtn.clicked.connect(self.formatResults)
self.formatResults()
......@@ -383,27 +392,28 @@ class ParticleAnalysis(QtWidgets.QWidget):
self.additivePlot.show()
def formatResults(self):
print('formatResults')
self.updateBtn.setDisabled(False)
self.optionsGroup.setDisabled(False)
del self.currentPolymers, self.currentAdditives
#convert to arrays (makes indexing easier...)
self.currentPolymers, self.hqis = np.array(self.spectraResults), np.array(self.hqis)
if self.additiveResults is not None:
self.currentAdditives, self.addhqis = np.array(self.additiveResults), np.array(self.addhqis)
self.compHqiSpinBox.setDisabled(False)
else:
self.currentAdditives = None
#set poor HQI results to unknown
self.currentPolymers[self.hqis < self.hqiSpinBox.value()] = 'unknown'
if self.currentAdditives is not None:
self.currentAdditives[self.addhqis < self.compHqiSpinBox.value()] = 'unknown'
self.createHistogramData()
if self.spectraResults is not None:
print('formatResults')
self.updateBtn.setDisabled(False)
self.optionsGroup.setDisabled(False)
del self.currentPolymers, self.currentAdditives
#convert to arrays (makes indexing easier...)
self.currentPolymers, self.hqis = np.array(self.spectraResults), np.array(self.hqis)
if self.additiveResults is not None:
self.currentAdditives, self.addhqis = np.array(self.additiveResults), np.array(self.addhqis)
self.compHqiSpinBox.setDisabled(False)
else:
self.currentAdditives = None
#set poor HQI results to unknown
self.currentPolymers[self.hqis < self.hqiSpinBox.value()] = 'unknown'
if self.currentAdditives is not None:
self.currentAdditives[self.addhqis < self.compHqiSpinBox.value()] = 'unknown'
self.createHistogramData()
def createHistogramData(self):
self.uniquePolymers = np.unique(self.currentPolymers)
......
......@@ -77,7 +77,7 @@ class ParticleEditor(object):
cv2.drawContours(img, [cnt], 0, 1, 1)
img = np.uint8(cv2.morphologyEx(img, cv2.MORPH_CLOSE, np.ones((3, 3))))
temp, contours, hierarchy = cv2.findContours(img, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
temp, contours, hierarchy = cv2.findContours(img, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_NONE)
newContour = contours[0]
stats = self.characterizeParticle(newContour)
......
......@@ -75,6 +75,7 @@ class DataSet(object):
# parameters specifically for raman scan
self.pshift = None # shift of raman scan position relative to image center
self.coordOffset = [0, 0] #offset of entire coordinate system
self.seedpoints = np.array([])
self.seeddeletepoints = np.array([])
self.detectParams = {'points': np.array([[50,0],[100,200],[200,255]]),
......@@ -230,6 +231,9 @@ class DataSet(object):
if not force:
assert not self.readin
p0 = copy(self.lastpos)
p0[0] += self.coordOffset[0]
p0[1] += self.coordOffset[1]
if mode == 'df':
p0[0] -= self.imagedim_df[0]/2
p0[1] += self.imagedim_df[1]/2
......
......@@ -173,6 +173,14 @@ class MeasureParticleWindow(QtWidgets.QMainWindow):
self.snapshotAct.triggered.connect(self.view.takeScreenshot)
self.snapshotAct.setDisabled(True)
self.checkCoordsAct = QtWidgets.QAction("Check Coordinate System", self)
self.checkCoordsAct.triggered.connect(self.view.checkCoords)
self.checkCoordsAct.setDisabled(True)
self.configCoordsAct = QtWidgets.QAction("Reconfigure Coordinate System", self)
self.configCoordsAct.triggered.connect(self.view.configureCoords)
self.configCoordsAct.setDisabled(True)
self.configRamanCtrlAct = QtWidgets.QAction("Configure Raman Control", self)
self.configRamanCtrlAct.triggered.connect(self.view.configureRamanControl)
if self.view.simulatedRaman:
......@@ -254,6 +262,9 @@ class MeasureParticleWindow(QtWidgets.QMainWindow):
self.toolsMenu = QtWidgets.QMenu("Tools")
self.toolsMenu.addAction(self.snapshotAct)
self.toolsMenu.addAction(self.configRamanCtrlAct)
self.toolsMenu.addSeparator()
self.toolsMenu.addAction(self.checkCoordsAct)
self.toolsMenu.addAction(self.configCoordsAct)
self.helpMenu = QtWidgets.QMenu("&Help", self)
self.helpMenu.addAction(self.aboutAct)
......
......@@ -86,6 +86,7 @@ class SampleView(QtWidgets.QGraphicsView):
self.setMinimumSize(600,600)
self.darkenPixmap = False
self.microscopeMode = None
self.coordTestMode = False
def takeScreenshot(self):
#TODO:
......@@ -210,8 +211,14 @@ class SampleView(QtWidgets.QGraphicsView):
def open(self, fname):
self.saveDataSet()
if self.dataset is not None: #####TODO: properly close and delete all widget instances for avoiding that data from a currently opened dataset is saved into the new...
if self.dataset is not None:
self.dataset.save()
#close all widgets
for widget in [self.detectionwidget, self.ramanwidget, self.oscanwidget, self.analysiswidget]:
widget.close()
widget.destroy()
self.contouritem.resetContours()
self.dataset = loadData(fname)
self.setMicroscopeMode()
self.imparent.setWindowTitle(self.dataset.name + (" SIMULATION" if simulatedRaman else ""))
......@@ -470,7 +477,11 @@ class SampleView(QtWidgets.QGraphicsView):
self.analysiswidget.currentSpectrumIndex = specIndex
selectedPolymer = self.analysiswidget.currentPolymers[specIndex]
self.analysiswidget.polymerIndex = self.analysiswidget.uniquePolymers.index(selectedPolymer)
try:
self.analysiswidget.polymerIndex = self.analysiswidget.uniquePolymers.index(selectedPolymer)
except:
print(selectedPolymer)
raise
#subparticleIndex
partIndicesOfThatPolymer = self.analysiswidget.indices[self.analysiswidget.polymerIndex]
......@@ -544,4 +555,19 @@ class SampleView(QtWidgets.QGraphicsView):
for item in self.ramanscanitems:
self.scene().removeItem(item)
self.ramanscanitems = []
def checkCoords(self):
if not os.path.exists(self.dataset.getImageName):
QtWidgets.QMessageBox.about(self, 'No Fullimage found', 'Optical scan was not complete.\nPlease acquire fullimage first with newly defined border points.')
else:
self.coordTestMode = True
QtWidgets.QMessageBox.about(self, 'Check Coordinate System', 'Microscope is moving to 5 positions.\nFirst, only x and y are moved, z only if x,y positions are confirmed')
points = (self.dataset.fitpoints if len(self.dataset.ramanpoints) == 0 else self.dataset.ramanpoints)
for i in range(5):
#get random scanindex:
point = points[np.random.randint(len(points))]
def configureCoords(self):
pass
\ No newline at end of file
......@@ -36,7 +36,7 @@ class SegmentationContours(QtWidgets.QGraphicsItem):
def boundingRect(self):
return self.brect
def resetContours(self, contours):
def resetContours(self, contours=[]):
cp = []
x0 = None
for c in contours:
......
Markdown is supported
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