Commit 530dc6cb authored by JosefBrandt's avatar JosefBrandt

Tidying up

parent d6af372b
......@@ -41,7 +41,6 @@ class ParticleIndicator(QtWidgets.QPushButton):
qp = QtGui.QPainter()
qp.begin(self)
#qp.fillRect(self.rect(), QtCore.Qt.white)
qp.setBrush(QtCore.Qt.white)
qp.drawRoundedRect(0, 0, width, height, 5. ,5.)
qp.setPen(self.color)
......@@ -116,7 +115,11 @@ class SpectraPlot(QtWidgets.QGroupBox):
layout = QtWidgets.QHBoxLayout()
self.canvas = FigureCanvas(Figure())
self.spec_axis = self.canvas.figure.subplots()
self.spec_axis.axis("off")
self.spec_axis.tick_params(axis='both', which='both', labelsize=15)
self.spec_axis.set_xlabel('Wavenumber (cm-1)', fontsize = 15)
self.spec_axis.set_ylabel('Counts', fontsize = 15)
self.reference_ax = self.spec_axis.twinx()
self.canvas.figure.subplots_adjust(left=0.1, top=0.93, bottom=0.15, right=0.9)
specNavigation = NavigationToolbar(self.canvas, self)
......@@ -127,21 +130,18 @@ class SpectraPlot(QtWidgets.QGroupBox):
layout.addWidget(self.canvas)
self.setLayout(layout)
def loadSpectraAndInitializeSpecPlot(self): #formerly updateData(self)....
self.spectra = self.dataset.particleContainer.spectra
assert self.spectra is not None
def loadSpectraAndInitializeSpecPlot(self):
self.spectra = self.dataset.particleContainer.getSpectraFromDisk()
self.canvas.draw()
def updateParticleSpectrum(self, specIndex, particleSize, hqi):
def updateParticleSpectrum(self, specIndex, assignment, particleSize, hqi):
#draw Sample Spectrum
self.spec_axis.axis("on")
self.spec_axis.clear()
self.spec_axis.set_title('{}, ScanPoint Number {}, Size = {} µm, HQI = {}'.format(assignment, specIndex+1, particleSize, hqi))
if self.spectra is not None:
#draw Sample Spectrum
self.spec_axis.axis("on")
self.spec_axis.clear()
self.spec_axis.plot(self.spectra[:, 0], self.spectra[:, specIndex+1])
self.spec_axis.tick_params(axis='both', which='both', labelsize=15)
self.spec_axis.set_xlabel('Wavenumber (cm-1)', fontsize = 15)
self.spec_axis.set_ylabel('Counts', fontsize = 15)
self.spec_axis.set_title('ScanPoint Number {}, Size = {} µm, HQI = {}'.format(specIndex+1, particleSize, hqi))
self.spec_axis.set_xbound(100, (3400 if self.spectra[-1, 0] > 3400 else self.spectra[-1, 0]))
wavenumber_diff = list(self.spectra[:, 0]-100)
y_start = wavenumber_diff.index(min(wavenumber_diff))
......@@ -159,10 +159,6 @@ class SpectraPlot(QtWidgets.QGroupBox):
self.reference_axis.set_ylabel('Ref. Intensity', fontsize = 15, color = 'r')
self.reference_axis.tick_params('y', colors = 'r')
self.reference_axis.set_xbound(100, (3400 if self.spectra[-1, 0] > 3400 else self.spectra[-1, 0]))
# wavenumber_diff = list(ref[:, 0]-100)
# y_start = wavenumber_diff.index(min(wavenumber_diff))
# y_min = min(ref[y_start:, specIndex+1])
# y_max = max(ref[y_start:, specIndex+1])
self.canvas.draw()
......
......@@ -29,7 +29,7 @@ from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
from .analysiswidgets import ExpExcelDialog
from .excelexport import ExpExcelDialog
from .analysisplots import TypeHistogramView, SpectraPlot
from .loadresults import LoadTrueMatchResults
from .database import DataBaseWindow
......@@ -45,7 +45,7 @@ except:
class ParticleAnalysis(QtWidgets.QMainWindow):
def __init__(self, dataset, viewparent=None):
super(ParticleAnalysis, self).__init__(viewparent)
self.setGeometry(100, 100, 1680, 1050)
self.resize(1680, 1050)
self.setWindowTitle('Results of polymer analysis')
self.layout = QtWidgets.QHBoxLayout()
self.widget = QtWidgets.QWidget()
......@@ -56,7 +56,6 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self.dataset = dataset
self.particleContainer = dataset.particleContainer
# self.additivePlot = None
self.importWindow = None
self.polymerCheckBoxes = []
......@@ -64,10 +63,8 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self.currentParticleIndex = 0
self.currentSpectrumIndex = 0
# self.lastSpectrumInFocus = None
self.typeHistogramPlot = TypeHistogramView(self)
# self.typeHistogramPlot.indexClicked.connect(self.getAdditivePlot)
self.sizeHistogramCanvas = FigureCanvas(Figure())
sizeHistGroup = QtWidgets.QGroupBox()
......@@ -171,16 +168,8 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self.hqiSpinBox.valueChanged.connect(self.applyHQIThresholdToResults)
optionsLayout.addRow(QtWidgets.QLabel('minimum HQI:'), self.hqiSpinBox)
# self.compHqiSpinBox = QtWidgets.QDoubleSpinBox()
# self.compHqiSpinBox.setValue(30.0)
# self.compHqiSpinBox.setDecimals(1)
# self.compHqiSpinBox.setMinimum(0)
# self.compHqiSpinBox.setDisabled(True)
# optionsLayout.addRow(QtWidgets.QLabel('min component HQI'), self.compHqiSpinBox)
self.optionsGroup.setLayout(optionsLayout)
self.optionsGroup.setMinimumWidth(175)
# self.optionsGroup.setDisabled(True)
self.resultScrollarea = QtWidgets.QScrollArea(self)
self.resultScrollarea.setFixedWidth(250)
......@@ -210,16 +199,13 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self.layout.addLayout(viewLayout)
minHQI = self.dataset.resultParams['minHQI']
# compHQI = self.dataset.resultParams['compHQI']
if minHQI is not None:
self.hqiSpinBox.setValue(minHQI)
# self.compHqiSpinBox.setValue(compHQI)
self.createActions()
self.createMenus()
self.applyHQIThresholdToResults()
self.createHistogramData()
self.particleContainer.loadSpectra()
self.initializeSpecPlot()
self.setTypeSelector()
self.updateHistogramsAndContours()
......@@ -228,8 +214,8 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self.loadTrueMatchAct = QtWidgets.QAction("Load &TrueMatch Results", self)
self.loadTrueMatchAct.triggered.connect(self.importTrueMatchResults)
self.loadTextFileAct = QtWidgets.QAction("Load &ordered Text File", self)
self.loadTextFileAct.setDisabled(True)
self.loadSpectraAct = QtWidgets.QAction("Load &Spectra", self)
self.loadSpectraAct.triggered.connect(self.initializeSpecPlot)
self.noOverlayAct = QtWidgets.QAction("&No Overlay", self)
self.selOverlayAct = QtWidgets.QAction("&Selected Overlay", self)
......@@ -250,7 +236,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self.seedAct = QtWidgets.QAction("&Set Color Seed", self)
self.seedAct.triggered.connect(self.updateColorSeed)
self.removeTinyParticlesAct = QtWidgets.QAction("&Remove not unknown Particles < 1 µm")
self.removeTinyParticlesAct.triggered.connect(self.removeTinyParticles)
......@@ -266,8 +252,8 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self.expSQLAct.triggered.connect(self.exportToSQL)
def createMenus(self):
self.importMenu = QtWidgets.QMenu("&Import Results")
self.importMenu.addActions([self.loadTrueMatchAct, self.loadTextFileAct])
self.importMenu = QtWidgets.QMenu("&Import Spectra and Results")
self.importMenu.addActions([self.loadSpectraAct, self.loadTrueMatchAct])
self.dispMenu = QtWidgets.QMenu("&Display", self)
self.overlayActGroup = QtWidgets.QActionGroup(self.dispMenu)
......@@ -294,7 +280,11 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self.menuBar().addMenu(self.dispMenu)
self.menuBar().addMenu(self.toolMenu)
self.menuBar().addMenu(self.exportMenu)
def keyPressEvent(self, event):
if event.key() in [QtCore.Qt.Key_Return, QtCore.Qt.Key_Enter]:
self.jumpToIndicatedSpectrum()
def launchDBManager(self):
if self.dbWin.isHidden():
self.dbWin.show()
......@@ -313,16 +303,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
def importTrueMatchResults(self):
self.importWindow = LoadTrueMatchResults(self.particleContainer, self)
self.importWindow.exec()
# @QtCore.pyqtSlot(int)
# def getAdditivePlot(self, clickedindex):
# polymer = self.datastats.typehistogram[clickedindex][0] #get the polymer name, that was clicked on
#
# if self.datastats.sorted_additives is not None and \
# len(self.datastats.sorted_additives[clickedindex]) > 0:
# self.additivePlot = AdditiveViewer(polymer, self.datastats.sorted_additives[clickedindex])
# self.additivePlot.show()
@QtCore.pyqtSlot()
def applyHQIThresholdToResults(self):
hqi = self.hqiSpinBox.value()
......@@ -409,14 +390,6 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
numParticles = self.particleContainer.getNumberOfParticles()
self.specNumberSelector.setMaximum(numParticles)
# if self.lastSpectrumInFocus is not None:
# self.currentSpectrumIndex = self.lastSpectrumInFocus
# self.displayNewPolymerType(resetCurrentIndex=False)
# print('displaying new type without resetting index')
# else:
# print('displaying new type with resetting index')
# self.displayNewPolymerType()
def initializeSpecPlot(self):
self.specPlot.loadSpectraAndInitializeSpecPlot()
self.updateSpecPlot()
......@@ -475,8 +448,8 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
def updateSpecPlot(self):
particleSize = np.round(self.particleContainer.getSizeOfParticleByIndex(self.currentParticleIndex))
hqi = self.particleContainer.getHQIOfSpectrumIndex(self.currentSpectrumIndex)
self.specPlot.updateParticleSpectrum(self.currentSpectrumIndex, particleSize, hqi)
# self.lastSpectrumInFocus = self.currentSpectrumIndex
assignment = self.particleContainer.getParticleAssignmentByIndex(self.currentParticleIndex)
self.specPlot.updateParticleSpectrum(self.currentSpectrumIndex, assignment, particleSize, hqi)
if self.refSelector.isEnabled() and self.refSelector.currentText() != '':
refID = self.dbWin.activeDatabase.spectraNames.index(self.refSelector.currentText())
......@@ -540,14 +513,13 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self.updateSpecPlot()
self.jumpToIndicatedSpectrum()
def setWidgetsToNewParticleIndex(self, particleIndex): #TODO: Probably refactor. Its basically a combination of the above methods... Just a bit different to avoid directly jumping to the particle in sampleview
def setWidgetsToNewParticleIndex(self, particleIndex):
try:
self.particleSelector.valueChanged.disconnect()
self.spectrumSelector.valueChanged.disconnect()
self.typeSelectorCombo.currentIndexChanged.disconnect()
except TypeError:
pass #signals were not connected...
pass #signals were not connected, nothing to disconnect...
assignment = self.particleContainer.getParticleAssignmentByIndex(particleIndex)
self.typeSelectorCombo.setCurrentText(assignment)
......@@ -573,7 +545,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self.spectrumSelector.valueChanged.connect(self.setSpecSelector)
self.particleSelector.valueChanged.connect(self.setParticleSelector)
def jumpToIndicatedSpectrum(self): #TODO: This should be transferred to sampleview...
def jumpToIndicatedSpectrum(self):
self.currentSpectrumIndex = self.specNumberSelector.value()-1
self.currentParticleIndex = self.particleContainer.getParticleIndexContainingSpecIndex(self.currentSpectrumIndex)
self.centerOnSpecIndex(self.currentSpectrumIndex)
......@@ -639,7 +611,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
scanIndicator.update()
def exportToExcel(self):
expWin = ExpExcelDialog(self.dataset, self.particleContainer)
expWin = ExpExcelDialog(self.dataset)
expWin.exec()
def exportToSQL(self):
......
......@@ -19,27 +19,21 @@ along with this program, see COPYING.
If not, see <https://www.gnu.org/licenses/>.
"""
from PyQt5 import QtWidgets, QtGui, QtCore
from PyQt5 import QtWidgets
import numpy as np
import pandas as pd
import os
import sys
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
class ExpExcelDialog(QtWidgets.QDialog):
def __init__(self, dataset, particleContainer):
def __init__(self, dataset):
super(ExpExcelDialog, self).__init__()
self.setWindowTitle('Export Options')
self.setGeometry(200, 200, 300, 300)
self.dataset = dataset
self.particleContainer = particleContainer
self.polymers = self.particleContainer.getListOfParticleAssignments
# self.additives = self.datastats.currentAdditives
self.hqis = self.particleContainer.getListOfHighestHQIs
self.particleContainer = dataset.particleContainer
self.layout = QtWidgets.QHBoxLayout()
self.setLayout(self.layout)
......@@ -48,7 +42,7 @@ class ExpExcelDialog(QtWidgets.QDialog):
excelvbox.addWidget(QtWidgets.QLabel('Select Parameters for Export'))
excelgroup = QtWidgets.QGroupBox("Export to Excel", self)
self.exportOptions = ['Polymer Type (mandatory)', 'Additives', 'Long Size (µm)', 'Short Size (µm)', 'Area (µm²)', 'HQI', 'Size Classes']
self.exportOptions = ['Polymer Type (mandatory)', 'Long Size (µm)', 'Short Size (µm)', 'Area (µm²)', 'HQI', 'Size Classes']
self.checkBoxes = []
self.sizeClasses = [5, 10, 20, 50, 100, 1e6]
self.directory = self.dataset.path
......@@ -60,11 +54,6 @@ class ExpExcelDialog(QtWidgets.QDialog):
if option == 'Polymer Type (mandatory)':
self.checkBoxes[-1].setEnabled(False) #is mandatory!!!
# if option == 'Additives':
# if self.additives is None:
# self.checkBoxes[-1].setEnabled(False)
# self.checkBoxes[-1].setChecked(False)
excelvbox.addWidget(self.checkBoxes[-1])
......@@ -85,19 +74,24 @@ class ExpExcelDialog(QtWidgets.QDialog):
self.show()
def toExcel(self):
requiredcolumns = []
self.sizes = self.particleContainer.getSizesOfAllParticles()
requiredcolumns = []
uniquePolymers = self.particleContainer.getUniquePolymers()
polymers = self.particleContainer.getListOfParticleAssignments()
sizes = self.particleContainer.getSizesOfAllParticles()
for box in self.checkBoxes:
if box.isChecked() == True:
if box.text() != 'Size Classes':
requiredcolumns.append(box.text())
if box.text() == 'Long Size (µm)':
longSize = self.sizes
longSizes = sizes
elif box.text() == 'Short Size (µm)':
self.shortSizes = self.particleContainer.getShortSizesOfAllParticles()
shortSizes = self.particleContainer.getShortSizesOfAllParticles()
elif box.text() == 'HQI':
hqis = self.particleContainer.getListOfHighestHQIs()
elif box.text() == 'Area (µm²)':
area = np.array([np.round(float(entry[4]), 1) for entry in self.particles])
areas = self.particleContainer.getAreasOfAllParticles()
else:
requiredcolumns.append('0 - 5 µm')
......@@ -107,28 +101,26 @@ class ExpExcelDialog(QtWidgets.QDialog):
requiredcolumns.append('50 - 100 µm')
requiredcolumns.append('> 100 µm')
finalData = np.zeros((self.polymers.shape[0],len(requiredcolumns)-1))
polymertypes = [""]*self.polymers.shape[0]
finalData = np.zeros((polymers.shape[0],len(requiredcolumns)-1))
polymertypes = [""]*polymers.shape[0]
rowindex = 0
for polymer in np.unique(self.polymers):
indices = self.polymers == polymer
for polymer in uniquePolymers:
indices = self.particleContainer.getgetIndicesOfParticleType(polymer)
numentries = int(np.sum(indices))
print("Num:", numentries)
sys.stdout.flush()
for colindex, column in enumerate(requiredcolumns):
if column == 'Polymer Type (mandatory)':
polymertypes[rowindex:rowindex+numentries] = self.polymers[indices]
# if column == 'Additives':
# finalData[rowindex:rowindex+numentries, colindex-1] = self.additives[indices]
polymertypes[rowindex:rowindex+numentries] = polymers[indices]
if column == 'Long Size (µm)':
finalData[rowindex:rowindex+numentries, colindex-1] = longSize[indices]
finalData[rowindex:rowindex+numentries, colindex-1] = longSizes[indices]
if column == 'Short Size (µm)':
finalData[rowindex:rowindex+numentries, colindex-1] = self.shortSizes[indices]
finalData[rowindex:rowindex+numentries, colindex-1] = shortSizes[indices]
if column == 'Area (µm²)':
finalData[rowindex:rowindex+numentries, colindex-1] = area[indices]
finalData[rowindex:rowindex+numentries, colindex-1] = areas[indices]
if column == 'HQI':
finalData[rowindex:rowindex+numentries, colindex-1] = self.hqis[indices]
finalData[rowindex:rowindex+numentries, colindex-1] = hqis[indices]
if '> 100 µm' in requiredcolumns:
##append size classes
......@@ -183,25 +175,4 @@ class ExpExcelDialog(QtWidgets.QDialog):
report.insert(len(report.columns), 'Sum total', particleclasses.sum(axis=1))
report.to_excel(writer, sheet_name = 'Particle Statistics', index=False)
writer.save()
self.accept()
class AdditiveViewer(QtWidgets.QWidget):
def __init__(self, polymername, sortedAdditives):
super(AdditiveViewer, self).__init__()
self.setGeometry(200,200, 800, 600)
self.setWindowTitle('Additives of {}'.format(polymername))
self.layout = QtWidgets.QGridLayout()
self.setLayout(self.layout)
self.canvas = FigureCanvas(Figure(figsize=(5, 3)))
self.ax = self.canvas.figure.subplots()
self.layout.addWidget(self.canvas, 0, 0)
self.ax.hist(sortedAdditives)
self.ax.set_ylabel('Number', fontsize = 15)
self.ax.tick_params(axis='both', which='both', labelsize=15)
\ No newline at end of file
self.accept()
\ No newline at end of file
......@@ -74,7 +74,7 @@ class Particle(object):
assignments.append(meas.getAssignment())
indexOfHighestHQI = hqis.index(max(hqis))
return assignments[indexOfHighestHQI]
def getParticleSize(self):
if not np.isnan(self.longSize_ellipse):
size = self.longSize_ellipse
......@@ -98,6 +98,9 @@ class Particle(object):
def getNumberOfMeasurements(self):
return len(self.measurements)
def getArea(self):
return np.round(self.area)
def measurementsHaveSameOrigAssignment(self):
allResults = [meas.getOrigAssignment() for meas in self.measurements]
if len(np.unique(allResults)) == 1:
......@@ -126,7 +129,7 @@ class Measurement(object):
self.assignment_orig = 'Not Evaluated'
self.assignment_afterHQI = None
self.hqi = None
self.hqi = 0
self.assignedParticle = None
......
......@@ -56,31 +56,34 @@ class ParticleContainer(object):
self.measurements[indexOfMeasurment].pixelcoord_x = x
self.measurements[indexOfMeasurment].pixelcoord_y = y
def loadSpectra(self):
def tryLoadingNumpySpecFile():
specPath = self.datasetParent.getSpectraFileName()
if os.path.exists(specPath):
return np.load(specPath)
else:
raise ImportError
try:
self.spectra = tryLoadingNumpySpecFile()
except ImportError:
def getMeasurementScanindex(self, indexOfMeasurement):
return self.measurements[indexOfMeasurement].ramanScanIndex
def getSpectraFromDisk(self):
spectra = None
specPath = self.datasetParent.getSpectraFileName()
if os.path.exists(specPath):
spectra = np.load(specPath)
else:
fname = QtWidgets.QFileDialog.getOpenFileName(QtWidgets.QWidget(), 'Select Spectra File', self.datasetParent.path, 'text file (*.txt)')[0]
try:
self.spectra, spectraNames = importSpectra.importWITecSpectra(fname)
except ImportError:
if fname:
#TODO: implement a more elegant way of testing through the individual imports...
try:
self.spectra, spectraNames = importSpectra.importRenishawSpectra(fname)
self.spectra, spectraNames = importSpectra.importWITecSpectra(fname)
except ImportError:
self.spectra, spectraNames = importSpectra.importPerkinElmerSpectra(fname)
try:
self.spectra, spectraNames = importSpectra.importRenishawSpectra(fname)
except ImportError:
try:
self.spectra, spectraNames = importSpectra.importPerkinElmerSpectra(fname)
except ImportError:
pass
if self.spectra is None:
raise ImportError
else:
np.save(self.datasetParent.getSpectraFileName(), self.spectra)
if spectra is not None:
np.save(self.datasetParent.getSpectraFileName(), spectra)
return spectra
def initializeParticles(self, numParticles):
self.particles = []
......@@ -155,7 +158,12 @@ class ParticleContainer(object):
particle.setAllSpectraToNewAssignment(newAssignment)
def getParticleOfIndex(self, index):
particle = self.particles[index]
try:
particle = self.particles[index]
except:
print('failed getting particle')
print('requested Index:', index)
print('len particles', len(self.particles))
assert particle.index == index, f'particle.index ({particle.index}) does match requested index in particleList ({index})'
return particle
......@@ -229,9 +237,15 @@ class ParticleContainer(object):
def getShortSizesOfAllParticles(self):
shortSizes = []
for particle in self.particles:
shortSizes.append(particle.getShortParticleSize())#
shortSizes.append(particle.getShortParticleSize())
return shortSizes
def getAreasOfAllParticles(self):
areas = []
for particle in self.particles:
areas.append(particle.getArea())
return areas
def getSizesOfParticleType(self, assignment):
particleSizes = []
for particle in self.particles:
......
......@@ -95,7 +95,7 @@ class ParticlePainter(QtWidgets.QGraphicsItem):
def keyPressEvent(self, event):
if event.key() == QtCore.Qt.Key_Escape:
self.editorParent.destroyParticlePainter()
elif event.key() == QtCore.Qt.Key_Return:
elif event.key() in [QtCore.Qt.Key_Return, QtCore.Qt.Key_Enter]:
self.editorParent.acceptPaintedResult()
def drawParticle(self, pixelPos):
......
......@@ -20,14 +20,9 @@ class SQLExport(QtWidgets.QDialog):
self.setWindowTitle('Export to SQL Database')
self.particleContainer = particleContainer
# self.polymerList = self.datastats.particleContainer
# particlestats = self.datastats.getParticleStats()
self.longSizes = self.particleContainer.getSizesOfAllParticles()
self.shortSize = self.particleContainer.getShortSizesOfAllParticles()
# self.longSizes = np.round(np.array([i[0] if np.isnan(i[2]) else i[2] for i in particlestats]), 1)
# self.shortSize = np.round(np.array([i[1] if np.isnan(i[3]) else i[3] for i in particlestats]), 1)
#spectra can be quite some data size, they are not copied here but referenced later on...
self.spectra = self.particleContainer.spectra
self.particleImages = None
self.log = []
......@@ -110,8 +105,7 @@ class SQLExport(QtWidgets.QDialog):
for index, entry in enumerate(['Detected Result*', 'DB Polymer Category*', 'DB Categorized Result', 'DB Paint Remark', 'Comment']):
typeLayout.addWidget(QtWidgets.QLabel(entry), 0, index+1)
# self.polymerTypes = np.unique(self.polymerList)
self.polymerTypes = self.particleContainer.getUniquePolymers()
self.polymerCheckboxes = []
self.db_polyms = []
......@@ -180,9 +174,8 @@ class SQLExport(QtWidgets.QDialog):
currentAnalysisInd = self.getAnalyisIndicesOfMethod(self.methodIndices[self.methodSelector.currentIndex()])
sizeCategories = self.getEntireTable('size_fraction')[1]
for index, polymerType in enumerate(self.polymerTypes):
if self.polymerCheckboxes[index].isChecked():
# polymIndices = np.where(self.polymerList == polymerType)[0]
for polymerIndex, polymerType in enumerate(self.polymerTypes):
if self.polymerCheckboxes[polymerIndex].isChecked():
polymIndices = self.particleContainer.getIndicesOfParticleType(polymerType)
particleCols = self.getEntireTable('particles')[0]
......@@ -203,9 +196,9 @@ class SQLExport(QtWidgets.QDialog):
usedCols[sizeCols[1]] = str(self.shortSize[polymInd])
if self.particleImages is not None:
usedCols['Image'] = self.particleImages[polymInd]
usedCols['Categorised_result'] = self.db_categs[index].currentText()
if self.p_remarks[index].currentText() != '':
usedCols['Indication_paint'] = self.p_remarks[index].currentText()
usedCols['Categorised_result'] = self.db_categs[polymerIndex].currentText()
if self.p_remarks[polymerIndex].currentText() != '':
usedCols['Indication_paint'] = self.p_remarks[polymerIndex].currentText()
requiredColumns = '(`'+'`,`'.join(list(usedCols.keys())) + '`'
vals = '","'.join(list(usedCols.values()))
......@@ -228,15 +221,15 @@ class SQLExport(QtWidgets.QDialog):
method = self.methodIndices[self.methodSelector.currentIndex()]
lib = polymerType
hqi = str(0)
specIDs = self.datastats.particles2spectra[polymInd]
specIDs = self.particleContainer.getgetSpectraIndicesOfParticle()
for specID in specIDs:
spec = self.datastats.spectra[:, [0, specID+1]]
spec = self.spectra[:, [0, specID+1]]
fp = StringIO()
np.savetxt(fp, spec)
fp.seek(0)
spec = fp.read()
res = self.dbPolymResultsIndices[self.db_polyms[index].currentIndex()]
com = self.comments[index].text()
res = self.dbPolymResultsIndices[self.db_polyms[polymerIndex].currentIndex()]
com = self.comments[polymerIndex].text()
format_str = """INSERT INTO analysis (Method, Library_entry, Spectrum, Result, Comment)
VALUES ("{method}", "{lib}", "{spec}", "{res}", "{com}");"""
......
......@@ -45,15 +45,14 @@ def loadData(fname):
return retds
def saveData(dataset, fname):
pass
# with open(fname, "wb") as fp:
# # zvalimg is rather large and thus it is saved separately in a tif file
# # only onces after its creation
# zvalimg = dataset.zvalimg
# if zvalimg is not None:
# dataset.zvalimg = "saved"
# pickle.dump(dataset, fp, protocol=-1)
# dataset.zvalimg = zvalimg
with open(fname, "wb") as fp:
# zvalimg is rather large and thus it is saved separately in a tif file
# only onces after its creation
zvalimg = dataset.zvalimg
if zvalimg is not None:
dataset.zvalimg = "saved"
pickle.dump(dataset, fp, protocol=-1)
dataset.zvalimg = zvalimg
def arrayCompare(a1, a2):
if a1.shape!=a2.shape:
......@@ -143,24 +142,12 @@ class DataSet(object):
'measurefrac': 1,
'compactness': 0.1,
'seedRad': 3}
# self.ramanpoints = []
# self.particlecontours = []
# self.particlestats = []
# self.ramanscansortindex = None
self.particleContainer = ParticleContainer(self)
self.particleDetectionDone = False
self.ramanscandone = False
# self.results = {'polymers': None,
# 'hqis': None,
# 'additives': None,
# 'additive_hqis': None}
self.resultParams = {'minHQI': None,
'compHQI': None}
# self.spectraPath = None
# self.particles2spectra = None #links idParticle to corresponding idSpectra (i.e., first measured particle (ID=0) is linked to spectra indices 0 and 1)
self.resultParams = {'minHQI': 5}
self.colorSeed = 'default'
self.resultsUploadedToSQL = []
......@@ -263,11 +250,12 @@ class DataSet(object):
self.particleContainer.applyPixelScaleToParticleStats(self.getPixelScale())
if len(self.particlestats) > 0: #i.e., particle detection was completed and particle data is there
self.particleDetectionDone = True
for particleIndex, listOfScanIndices in enumerate(self.particles2spectra):
curParticle = self.particleContainer.getParticleOfIndex(particleIndex)
for scanIndex in listOfScanIndices:
indexOfNewMeas = self.particleContainer.addEmptyMeasurement()
x, y = self.ramanpoints[particleIndex][0], self.ramanpoints[particleIndex][1]
x, y = self.ramanpoints[indexOfNewMeas ][0], self.ramanpoints[indexOfNewMeas][1]
self.particleContainer.setMeasurementPixelCoords(indexOfNewMeas, x, y)
self.particleContainer.setMeasurementScanIndex(indexOfNewMeas, scanIndex)
curParticle.addMeasurement(self.particleContainer.measurements[indexOfNewMeas])
......@@ -280,7 +268,7 @@ class DataSet(object):
self.particleContainer.testForInconsistentParticles()
# self.version = 3
self.version = 3
# add later conversion for higher version numbers here
def getSubImage(self, img, index, draw=True):
......
......@@ -491,7 +491,6 @@ class ParticleDetectionView(QtWidgets.QWidget):
def closeEvent(self, event):
self.detectionFinished.emit()
# self.destroy()
def mousePressEvent(self, event):
if event.button()==QtCore.Qt.RightButton:
......@@ -635,7 +634,7 @@ class ParticleDetectionView(QtWidgets.QWidget):
self.pdetectall.setText("Detect all")
self.imageUpdate.emit(self.view.microscopeMode)
if self.dataset is not None:
self.setWindowTitle(str(len(self.dataset.ramanpoints)) + " Particles")
self.setWindowTitle(str(self.dataset.particleContainer.getNumberOfParticles()) + " Particles")
else:
self.timer.start(100.)
......@@ -665,23 +664,16 @@ class ParticleDetectionView(QtWidgets.QWidget):
particleContainer.setParticleStats(particlestats)
particleContainer.applyPixelScaleToParticleStats(self.dataset.getPixelScale())
for particleIndex in measurementPoints:
for particleIndex in measurementPoints.keys():
measPoints = measurementPoints[particleIndex]
for index, point in enumerate(measPoints):
# curParticle = particleContainer.particles[point.particleIndex]
# curParticle.addEmptyMeasurement()
# curParticle.setMeasurementPixelCoords(index, point.x, point.y)
curParticle = particleContainer.getParticleOfIndex(point.particleIndex)
curParticle = particleContainer.getParticleOfIndex(particleIndex)
indexOfNewMeas = particleContainer.addEmptyMeasurement()
particleContainer.setMeasurementPixelCoords(index, point.x, point.y)
particleContainer.setMeasurementPixelCoords(indexOfNewMeas, point.x, point.y)
curParticle.addMeasurement(particleContainer.measurements[indexOfNewMeas])
self.dataset.particleDetectionDone = True
# self.dataset.ramanpoints = measurementPoints #consider moving that to particleContainer
# self.dataset.particlecontours = contours
# self.dataset.particlestats = particlestats
# self.dataset.ramanscansortindex = []
self.dataset.mode = "prepareraman"
self.dataset.save()