Commit 2c03c3ce authored by Josef Brandt's avatar Josef Brandt

Preparation for reorganizing contours and scanIndices

Have it managed by the particle!
parent ca5e6bad
...@@ -23,10 +23,6 @@ from PyQt5 import QtWidgets, QtGui, QtCore ...@@ -23,10 +23,6 @@ from PyQt5 import QtWidgets, QtGui, QtCore
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure from matplotlib.figure import Figure
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
import os
import numpy as np
from analysis import importSpectra
class ParticleIndicator(QtWidgets.QPushButton): class ParticleIndicator(QtWidgets.QPushButton):
...@@ -132,31 +128,8 @@ class SpectraPlot(QtWidgets.QGroupBox): ...@@ -132,31 +128,8 @@ class SpectraPlot(QtWidgets.QGroupBox):
self.setLayout(layout) self.setLayout(layout)
def loadSpectraAndInitializeSpecPlot(self): #formerly updateData(self).... def loadSpectraAndInitializeSpecPlot(self): #formerly updateData(self)....
# def tryLoadingNumpySpecFile(): self.spectra = self.dataset.particleContainer.spectra
# specPath = self.dataset.getSpectraFileName() assert self.spectra is not None
# if os.path.exists(specPath):
# return np.load(specPath)
# else:
# raise ImportError
# try:
# self.spectra = tryLoadingNumpySpecFile()
# except ImportError:
#
# fname = QtWidgets.QFileDialog.getOpenFileName(QtWidgets.QWidget(), 'Select Spectra File', self.dataset.path, 'text file (*.txt)')[0]
#
# try:
# self.spectra, spectraNames = importSpectra.importWITecSpectra(fname)
# except ImportError:
# try:
# self.spectra, spectraNames = importSpectra.importRenishawSpectra(fname)
# except ImportError:
# self.spectra, spectraNames = importSpectra.importPerkinElmerSpectra(fname)
#
# if self.spectra is None:
# raise ImportError
# else:
# np.save(self.dataset.getSpectraFileName(), self.spectra)
self.canvas.draw() self.canvas.draw()
def updateParticleSpectrum(self, specIndex, particleSize, hqi): def updateParticleSpectrum(self, specIndex, particleSize, hqi):
......
...@@ -32,7 +32,6 @@ from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as Navigatio ...@@ -32,7 +32,6 @@ from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as Navigatio
from .analysiswidgets import ExpExcelDialog from .analysiswidgets import ExpExcelDialog
from .analysisplots import TypeHistogramView, SpectraPlot from .analysisplots import TypeHistogramView, SpectraPlot
from .loadresults import LoadTrueMatchResults from .loadresults import LoadTrueMatchResults
from .particleeditor import ParticleEditor
from .database import DataBaseWindow from .database import DataBaseWindow
from .colorlegend import getColorFromNameWithSeed from .colorlegend import getColorFromNameWithSeed
...@@ -56,7 +55,6 @@ class ParticleAnalysis(QtWidgets.QMainWindow): ...@@ -56,7 +55,6 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self.viewparent = viewparent self.viewparent = viewparent
self.dataset = dataset self.dataset = dataset
self.particleContainer = dataset.particleContainer self.particleContainer = dataset.particleContainer
self.editor = ParticleEditor(self.particleContainer, self)
# self.additivePlot = None # self.additivePlot = None
self.importWindow = None self.importWindow = None
...@@ -221,6 +219,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow): ...@@ -221,6 +219,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self.createMenus() self.createMenus()
self.applyHQIThresholdToResults() self.applyHQIThresholdToResults()
self.createHistogramData() self.createHistogramData()
self.particleContainer.loadSpectra()
self.initializeSpecPlot() self.initializeSpecPlot()
self.setTypeSelector() self.setTypeSelector()
self.updateHistogramsAndContours() self.updateHistogramsAndContours()
...@@ -556,7 +555,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow): ...@@ -556,7 +555,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self.currentParticleIndex = particleIndex self.currentParticleIndex = particleIndex
partIndices = self.particleContainer.getIndicesOfParticleType(assignment) partIndices = self.particleContainer.getIndicesOfParticleType(assignment)
self.particleSelector.setMaximum(len(partIndices)) self.particleSelector.setMaximum(len(partIndices))
self.particleNumberLabel.setText(f'of {len(partIndices)} particles; ')
self.particleSelector.setValue(partIndices.index(particleIndex)+1) self.particleSelector.setValue(partIndices.index(particleIndex)+1)
......
...@@ -19,7 +19,7 @@ along with this program, see COPYING. ...@@ -19,7 +19,7 @@ along with this program, see COPYING.
If not, see <https://www.gnu.org/licenses/>. If not, see <https://www.gnu.org/licenses/>.
""" """
import numpy as np import numpy as np
from viewitems import SegmentationContour, RamanScanIndicator
class Particle(object): class Particle(object):
def __init__(self): def __init__(self):
...@@ -35,23 +35,9 @@ class Particle(object): ...@@ -35,23 +35,9 @@ class Particle(object):
self.viewItem = None self.viewItem = None
def addMeasurement(self, refToMeasurement): def addMeasurement(self, refToMeasurement):
refToMeasurement.assignedParticle = self
self.measurements.append(refToMeasurement) self.measurements.append(refToMeasurement)
# def addExistingMeasurement(self, meas):
# self.measurements.append(meas)
#
# def addEmptyMeasurement(self):
# self.measurements.append(Measurement())
# indexOfNewMeasurment = len(self.measurements)-1
# return indexOfNewMeasurment
# def setMeasurementScanIndex(self, indexOfMeasurment, scanIndex):
# self.measurements[indexOfMeasurment].ramanScanIndex = scanIndex
#
# def setMeasurementPixelCoords(self, indexOfMeasurment, x, y):
# self.measurements[indexOfMeasurment].pixelcoord_x= x
# self.measurements[indexOfMeasurment].pixelcoord_y = y
#
def setAllSpectraToNewAssignment(self, newAssignment): def setAllSpectraToNewAssignment(self, newAssignment):
for meas in self.measurements: for meas in self.measurements:
meas.setAssignment(newAssignment) meas.setAssignment(newAssignment)
...@@ -127,8 +113,8 @@ class Particle(object): ...@@ -127,8 +113,8 @@ class Particle(object):
for measurement in self.measurements: for measurement in self.measurements:
measurement.applyHQIThreshold(minHQI) measurement.applyHQIThreshold(minHQI)
# def recreateViewItem(self): def recreateViewItem(self):
# pass self.viewItem = SegmentationContour()
class Measurement(object): class Measurement(object):
...@@ -141,6 +127,8 @@ class Measurement(object): ...@@ -141,6 +127,8 @@ class Measurement(object):
self.assignment_orig = 'Not Evaluated' self.assignment_orig = 'Not Evaluated'
self.assignment_afterHQI = None self.assignment_afterHQI = None
self.hqi = None self.hqi = None
self.assignedParticle = None
def setAssignment(self, assignment): def setAssignment(self, assignment):
self.assignment_orig = assignment self.assignment_orig = assignment
......
...@@ -178,9 +178,10 @@ class ParticleContainer(object): ...@@ -178,9 +178,10 @@ class ParticleContainer(object):
def getMeasurementPixelCoords(self): def getMeasurementPixelCoords(self):
coords = [] coords = []
for particle in self.particles: # for particle in self.particles:
for measurement in particle.getMeasurements(): # for measurement in particle.getMeasurements():
coords.append([measurement.pixelcoord_x, measurement.pixelcoord_y]) for meas in self.measurements:
coords.append([meas.pixelcoord_x, meas.pixelcoord_y])
return coords return coords
def getNumberOfParticlesOfAssignment(self, assignment): def getNumberOfParticlesOfAssignment(self, assignment):
...@@ -269,7 +270,7 @@ class ParticleContainer(object): ...@@ -269,7 +270,7 @@ class ParticleContainer(object):
if newAssignment is not None: if newAssignment is not None:
meas.setAssignment(newAssignment) meas.setAssignment(newAssignment)
meas.setHQI(100) meas.setHQI(100)
newParticle.addExistingMeasurement(meas) newParticle.addMeasurement(meas)
#set Particle Stats #set Particle Stats
long, short, longellipse, shortellipse, area = newStats long, short, longellipse, shortellipse, area = newStats
......
...@@ -24,7 +24,7 @@ import numpy as np ...@@ -24,7 +24,7 @@ import numpy as np
import cv2 import cv2
from helperfunctions import cv2imread_fix, cv2imwrite_fix from helperfunctions import cv2imread_fix, cv2imwrite_fix
from copy import copy from copy import copy
from analysis.particleInfo import ParticleContainer from analysis.particleContainer import ParticleContainer
currentversion = 3 currentversion = 3
......
...@@ -677,7 +677,7 @@ class ParticleDetectionView(QtWidgets.QWidget): ...@@ -677,7 +677,7 @@ class ParticleDetectionView(QtWidgets.QWidget):
self.dataset.ramanpoints = measurementPoints #consider moving that to particleContainer # self.dataset.ramanpoints = measurementPoints #consider moving that to particleContainer
# self.dataset.particlecontours = contours # self.dataset.particlecontours = contours
# self.dataset.particlestats = particlestats # self.dataset.particlestats = particlestats
# self.dataset.ramanscansortindex = [] # self.dataset.ramanscansortindex = []
......
...@@ -100,13 +100,23 @@ class GEPARDMainWindow(QtWidgets.QMainWindow): ...@@ -100,13 +100,23 @@ class GEPARDMainWindow(QtWidgets.QMainWindow):
fileName = QtWidgets.QFileDialog.getSaveFileName(self, "Create New Project", fileName = QtWidgets.QFileDialog.getSaveFileName(self, "Create New Project",
defaultPath, "*.pkl")[0] defaultPath, "*.pkl")[0]
if fileName: if fileName:
# if fileName.find(' ') < 0: isValid, msg = self.testFilename(fileName)
self.fname = str(fileName) #TODO: No spaces for Renishaw Interface!! if isValid:
self.view.new(self.fname) self.fname = str(fileName) #TODO: No spaces for Renishaw Interface!!
self.scalingChanged(1.) self.view.new(self.fname)
# else: self.scalingChanged(1.)
# QtWidgets.QMessageBox.critical(self, "Error", "File path must not contain spaces.") else:
QtWidgets.QMessageBox.critical(self, "Error", msg)
def testFilename(self, fileName):
if self.view.ramanctrl.name == 'RenishawCOM': #the renishawCom does not allow Spaces within filePath
if fileName.find(' ') == 0:
return False, "File path must not contain spaces."
else:
return True, ""
else:
return True, ""
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def about(self): def about(self):
QtWidgets.QMessageBox.about(self, 'GEPARD', QtWidgets.QMessageBox.about(self, 'GEPARD',
......
...@@ -47,6 +47,7 @@ class WITecCOM(RamanBase): ...@@ -47,6 +47,7 @@ class WITecCOM(RamanBase):
def __init__(self, hostname=None): def __init__(self, hostname=None):
super().__init__() super().__init__()
self.name = 'WITecCOM'
if hostname is None: if hostname is None:
hostname = gethostname() hostname = gethostname()
self.IBUCSAccess = win32com.client.DispatchEx(self.CLSID, machine=hostname, self.IBUCSAccess = win32com.client.DispatchEx(self.CLSID, machine=hostname,
......
...@@ -21,6 +21,7 @@ If not, see <https://www.gnu.org/licenses/>. ...@@ -21,6 +21,7 @@ If not, see <https://www.gnu.org/licenses/>.
class RamanBase(object): class RamanBase(object):
def __init__(self): def __init__(self):
self.name = None
self.connected = False self.connected = False
self.timeseries = False self.timeseries = False
......
...@@ -32,6 +32,7 @@ class SimulatedRaman(RamanBase): ...@@ -32,6 +32,7 @@ class SimulatedRaman(RamanBase):
ramanParameters = {} ramanParameters = {}
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self.name = 'SimulatedRaman'
self.currentpos = None, 0., 0. self.currentpos = None, 0., 0.
self.currentZ = 0. self.currentZ = 0.
# some plausible data to simulate consecutively changing positions # some plausible data to simulate consecutively changing positions
......
...@@ -232,16 +232,8 @@ class RamanScanUI(QtWidgets.QWidget): ...@@ -232,16 +232,8 @@ class RamanScanUI(QtWidgets.QWidget):
if reply == QtWidgets.QMessageBox.Yes: if reply == QtWidgets.QMessageBox.Yes:
self.dataset.mode = "ramanscan" self.dataset.mode = "ramanscan"
measurements2particles = [[int(np.where(cmin == i)[0])] for i in range(len(cmin))] #i.e., list of scanIndicesPerParticle for measIndex, ramanScanIndex in enumerate(cmin):
for particleIndex, listOfScanIndices in enumerate(measurements2particles): self.particleContainer.setMeasurementScaneIndex(measIndex, ramanScanIndex)
# curParticle = self.particleContainer.getParticleOfIndex(particleIndex)
for scanIndex in listOfScanIndices:
self.particleContainer.setMeasurementScanIndex(indexOfNewMeas, scanIndex)
# self.dataset.ramanscansortindex = cmin # self.dataset.ramanscansortindex = cmin
self.dataset.saveParticleData() self.dataset.saveParticleData()
......
...@@ -34,9 +34,8 @@ from zeissimporter import ZeissImporter ...@@ -34,9 +34,8 @@ from zeissimporter import ZeissImporter
from viewitems import FitPosIndicator, Node, Edge, ScanIndicator, RamanScanIndicator, SegmentationContour from viewitems import FitPosIndicator, Node, Edge, ScanIndicator, RamanScanIndicator, SegmentationContour
from analysis.colorlegend import getColorFromNameWithSeed from analysis.colorlegend import getColorFromNameWithSeed
from helperfunctions import polygoncovering, cv2imread_fix from helperfunctions import polygoncovering, cv2imread_fix
from ramancom.configRaman import RamanConfigWin from ramancom.configRaman import RamanConfigWin
from analysis.particleeditor import ParticleEditor from analysis.particleEditor import ParticleEditor
class SampleView(QtWidgets.QGraphicsView): class SampleView(QtWidgets.QGraphicsView):
...@@ -412,6 +411,7 @@ class SampleView(QtWidgets.QGraphicsView): ...@@ -412,6 +411,7 @@ class SampleView(QtWidgets.QGraphicsView):
p = QtCore.QPointF(p.x(), p.y()) p = QtCore.QPointF(p.x(), p.y())
for index, cnt in enumerate(self.contourItems): for index, cnt in enumerate(self.contourItems):
if cnt.polygon.containsPoint(p, QtCore.Qt.OddEvenFill): #clicked on particle if cnt.polygon.containsPoint(p, QtCore.Qt.OddEvenFill): #clicked on particle
if not event.modifiers()==QtCore.Qt.ShiftModifier: if not event.modifiers()==QtCore.Qt.ShiftModifier:
acceptSelection(cnt) acceptSelection(cnt)
......
...@@ -20,7 +20,7 @@ If not, see <https://www.gnu.org/licenses/>. ...@@ -20,7 +20,7 @@ If not, see <https://www.gnu.org/licenses/>.
""" """
#import numpy as np #import numpy as np
from PyQt5 import QtCore, QtWidgets, QtGui from PyQt5 import QtCore, QtWidgets, QtGui
from analysis.particleeditor import ParticleContextMenu from analysis.particleEditor import ParticleContextMenu
class SegmentationContour(QtWidgets.QGraphicsItem): class SegmentationContour(QtWidgets.QGraphicsItem):
def __init__(self, viewparent, contourData, pos=(0,0)): def __init__(self, viewparent, contourData, pos=(0,0)):
...@@ -128,15 +128,15 @@ class FitPosIndicator(QtWidgets.QGraphicsItem): ...@@ -128,15 +128,15 @@ class FitPosIndicator(QtWidgets.QGraphicsItem):
class RamanScanIndicator(QtWidgets.QGraphicsItem): class RamanScanIndicator(QtWidgets.QGraphicsItem):
def __init__(self, view, number, radius, pos=(0,0)): def __init__(self, view, number, radius, pos=(0,0)):
super().__init__() super().__init__()
# self.setFlag(QtWidgets.QGraphicsItem.ItemIsSelectable)
self.setAcceptedMouseButtons(QtCore.Qt.NoButton) self.setAcceptedMouseButtons(QtCore.Qt.NoButton)
self.setZValue(100) #higher numbers will be in foreground. Shall always be in foreground! self.setZValue(100) #higher zValues will be in foreground. Shall always be in foreground!
self.view = view self.view = view
self.number = number self.number = number
self.radius = radius self.radius = radius
self.highlight = False self.highlight = False
self.hidden = False self.hidden = False
self.setPos(pos[0], pos[1]) self.setPos(pos[0], pos[1])
self.hasNoParticleAssigned = False
def setHighLight(self, highlight): def setHighLight(self, highlight):
if highlight!=self.highlight: if highlight!=self.highlight:
...@@ -157,6 +157,9 @@ class RamanScanIndicator(QtWidgets.QGraphicsItem): ...@@ -157,6 +157,9 @@ class RamanScanIndicator(QtWidgets.QGraphicsItem):
if self.highlight: if self.highlight:
painter.setPen(QtCore.Qt.red) painter.setPen(QtCore.Qt.red)
painter.setBrush(QtGui.QColor(100,250,100,150)) painter.setBrush(QtGui.QColor(100,250,100,150))
elif self.hasNoParticleAssigned:
painter.setPen(QtCore.Qt.black)
painter.setBrush(QtCore.Qt.red)
else: else:
painter.setPen(QtCore.Qt.green) painter.setPen(QtCore.Qt.green)
painter.setBrush(QtGui.QColor(50,50,250,150)) painter.setBrush(QtGui.QColor(50,50,250,150))
......
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