diff --git a/analysis/particleCharacterization.py b/analysis/particleCharacterization.py index 5cadb33f4a1a97387e5b891576870af04cb549d4..7922ea3832c82042df74204e6b91a3b7882f9a03 100644 --- a/analysis/particleCharacterization.py +++ b/analysis/particleCharacterization.py @@ -74,10 +74,7 @@ def getParticleColor(imgRGB, colorClassifier=None): def getParticleShape(contour, particleHeight, shapeClassifier=None): if shapeClassifier is None: shapeClassifier = ShapeClassifier() - try: - shape = shapeClassifier.classifyShape(contour, particleHeight) - except InvalidParticleError: - raise + shape = shapeClassifier.classifyShape(contour, particleHeight) return shape def getParticleHeight(contour, dataset): diff --git a/analysis/particleClassification/shapeClassification.py b/analysis/particleClassification/shapeClassification.py index a6c9fe9de17725112a9b07776438b7bbbd7ffd1d..f5e528a2345db7cc64da8da97c5bf4724ee15e2e 100644 --- a/analysis/particleClassification/shapeClassification.py +++ b/analysis/particleClassification/shapeClassification.py @@ -50,10 +50,7 @@ class BaseShape(object): self.solidity = area/hull_area - try: - long, short = self.getEllipseOrBoxLongAndShortSize() - except InvalidParticleError: - raise InvalidParticleError + long, short = self.getEllipseOrBoxLongAndShortSize() self.aspectRatio = long/short avgLength = (long+short)/2 @@ -138,10 +135,7 @@ class ShapeClassifier(object): newShape = BaseShape() newShape.contour = contour newShape.height = particleHeight - try: - newShape.getParticleCharacteristics() - except InvalidParticleError: - raise InvalidParticleError + newShape.getParticleCharacteristics() mostFittingCriteria = 0 bestFittingShape = 'unknown' diff --git a/analysis/particleContainer.py b/analysis/particleContainer.py index 43acc08bc7879ffdb137c59fc192d25dca6f93d2..8875f289d5c952ebcf3b76a7395ed6dc3a8c7e4d 100644 --- a/analysis/particleContainer.py +++ b/analysis/particleContainer.py @@ -134,23 +134,17 @@ class ParticleContainer(object): def applyAssignmentListToParticleMeasurements(self, assignmentList): '''AssignmentList is list of spectra assignments in order of spectra indices''' - indicesOfTransferredAssignments = [None]*len(assignmentList) - for particle in self.particles: - for meas in particle.getMeasurements(): - scanIndex = meas.getScanIndex() - meas.setAssignment(assignmentList[scanIndex]) - indicesOfTransferredAssignments[scanIndex] = scanIndex - assert not None in indicesOfTransferredAssignments + assert len(assignmentList) == len(self.measurements), f'assertion error in assignment of results: {len(assignmentList)} results for {len(self.measurements)} spectra...' + for meas in self.measurements: + scanIndex = meas.getScanIndex() + meas.setAssignment(assignmentList[scanIndex]) def applyHQIListToParticleMeasurements(self, hqiList): '''HQI-List is list of spectra hqis in order of spectra indices''' - indicesOfTransferredHQIs = [None]*len(hqiList) - for particle in self.particles: - for meas in particle.getMeasurements(): - scanIndex = meas.getScanIndex() - meas.setHQI(hqiList[scanIndex]) - indicesOfTransferredHQIs[scanIndex] = scanIndex - assert not None in indicesOfTransferredHQIs + assert len(hqiList) == len(self.measurements), f'assertion error in assignment of hqis: {len(hqiList)} results for {len(self.measurements)} spectra...' + for meas in self.measurements: + scanIndex = meas.getScanIndex() + meas.setHQI(hqiList[scanIndex]) def reassignParticleToAssignment(self, particleIndex, newAssignment): particle = self.getParticleOfIndex(particleIndex) diff --git a/sampleview.py b/sampleview.py index af29d9b7ff5fe8f6138f096b38bdda514468d5e2..89116fb22d16dea08119173647e3ecb19fde7254 100644 --- a/sampleview.py +++ b/sampleview.py @@ -81,7 +81,7 @@ class SampleView(QtWidgets.QGraphicsView): self.boundaryitems = [[],[]] self.scanitems = [] self.ramanscanitems = [] - self.particleInfoBoxes = [] + self.particleInfoBox = None self.imgdata = None self.isblocked = False self.contourItems = [] @@ -387,26 +387,19 @@ class SampleView(QtWidgets.QGraphicsView): cnt.update() if cnt.particleIndex not in self.selectedParticleIndices: self.selectedParticleIndices.append(cnt.particleIndex) - addParticleInfoBox(cnt.particleIndex) +# addParticleInfoBox(cnt.particleIndex) def removeContourFromSelection(cnt): cnt.isSelected = False cnt.update() self.selectedParticleIndices.remove(cnt.particleIndex) - removeParticleInfoBox(cnt.particleIndex) +# removeParticleInfoBox(cnt.particleIndex) - def addParticleInfoBox(index): - newInfoBox = ParticleInfo(self.dataset.particleContainer.getParticleOfIndex(cnt.particleIndex)) - self.particleInfoBoxes.append(newInfoBox) - self.scene().addItem(newInfoBox) - self.update() - - def removeParticleInfoBox(index): - for infoBox in self.particleInfoBoxes: - if infoBox.particle.index == index: - self.scene().removeItem(infoBox) - self.particleInfoBoxes.remove(infoBox) - self.update() + def updateParticleInfoBox(index): + if self.particleInfoBox is not None: + self.scene().removeItem(self.particleInfoBox) + self.particleInfoBox = ParticleInfo(self.dataset.particleContainer.getParticleOfIndex(index)) + self.scene().addItem(self.particleInfoBox) p = self.mapToScene(event.pos()) p = QtCore.QPointF(p.x(), p.y()) @@ -428,8 +421,13 @@ class SampleView(QtWidgets.QGraphicsView): cnt.update() if cnt.particleIndex in self.selectedParticleIndices: self.selectedParticleIndices.remove(cnt.particleIndex) - removeParticleInfoBox(cnt.particleIndex) - + + if len(self.selectedParticleIndices) > 0: + updateParticleInfoBox(self.selectedParticleIndices[-1]) + else: + self.scene().removeItem(self.particleInfoBox) + self.particleInfoBox = None + self.update() def scaleImage(self, factor): @@ -499,7 +497,7 @@ class SampleView(QtWidgets.QGraphicsView): self.item.setOpacity(1) else: - self.item.setPiparticleInfoBoxesxmap(QtGui.QPixmap()) + self.item.setPiparticleInfoBoxxmap(QtGui.QPixmap()) if self.mode == "OpticalScan": for i, p in zip(self.dataset.fitindices, self.dataset.fitpoints): p = self.dataset.mapToPixel(p, mode=microscope_mode, force=True) @@ -616,12 +614,11 @@ class SampleView(QtWidgets.QGraphicsView): self.contourItems[index].isSelected = True self.selectedParticleIndices =[index] - for infoBox in self.particleInfoBoxes: - self.scene().removeItem(infoBox) + if self.particleInfoBox is not None: + self.scene().removeItem(self.particleInfoBox) - newInfoBox = ParticleInfo(self.dataset.particleContainer.getParticleOfIndex(index)) - self.particleInfoBoxes = [newInfoBox] - self.scene().addItem(newInfoBox) + self.particleInfoBox = ParticleInfo(self.dataset.particleContainer.getParticleOfIndex(index)) + self.scene().addItem(self.particleInfoBox) self.update() def centerOnRamanIndex(self, index, centerOn=True, highlightIndex=True):