Commit 9fdb42e2 authored by JosefBrandt's avatar JosefBrandt

Load TrueMatchResult Works
parent 1c6ae7e5
......@@ -31,7 +31,7 @@ from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as Navigatio
from .analysiswidgets import ExpExcelDialog
from .analysisplots import TypeHistogramView, SpectraPlot
from .loadresults import LoadWITecResults
from .loadresults import LoadTrueMatchResults
from .particleeditor import ParticleEditor
from .database import DataBaseWindow
from .colorlegend import ColorHandler
......@@ -152,7 +152,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
viewLayout.addWidget(splitter2)
viewLayout.setStretch(1, 1)
self.optionsGroup = QtWidgets.QGroupBox('Further Options')
self.optionsGroup = QtWidgets.QGroupBox('Set HQI Threshold')
optionsLayout = QtWidgets.QFormLayout()
self.hqiSpinBox = QtWidgets.QDoubleSpinBox()
......@@ -162,7 +162,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self.hqiSpinBox.setMaximum(100)
self.hqiSpinBox.setMaximumWidth(100)
self.hqiSpinBox.valueChanged.connect(self.applyHQIThresholdToResults)
optionsLayout.addRow(QtWidgets.QLabel('min HQI:'), self.hqiSpinBox)
optionsLayout.addRow(QtWidgets.QLabel('minimum HQI:'), self.hqiSpinBox)
# self.compHqiSpinBox = QtWidgets.QDoubleSpinBox()
# self.compHqiSpinBox.setValue(30.0)
......@@ -171,14 +171,6 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
# self.compHqiSpinBox.setDisabled(True)
# optionsLayout.addRow(QtWidgets.QLabel('min component HQI'), self.compHqiSpinBox)
self.dispResultSpinBox = QtWidgets.QSpinBox()
self.dispResultSpinBox.setValue(20)
self.dispResultSpinBox.setMinimum(1)
self.dispResultSpinBox.setMaximumWidth(100)
self.dispResultSpinBox.valueChanged.connect(self.updateHistograms)
optionsLayout.addRow(QtWidgets.QLabel('Max. items in display:'), self.dispResultSpinBox)
self.optionsGroup.setLayout(optionsLayout)
self.optionsGroup.setMinimumWidth(175)
# self.optionsGroup.setDisabled(True)
......@@ -309,7 +301,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self.refSelector.setDisabled(False)
def importTrueMatchResults(self):
self.importWindow = LoadWITecResults(self.particleContainer, self)
self.importWindow = LoadTrueMatchResults(self.particleContainer, self)
self.importWindow.exec()
# @QtCore.pyqtSlot(int)
......@@ -414,14 +406,9 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
# print('displaying new type with resetting index')
# self.displayNewPolymerType()
def exportToExcel(self):
expWin = ExpExcelDialog(self.particleContainer, self)
expWin.exec()
def exportToSQL(self):
sqlexp = SQLExport(self.particleContainer, self)
sqlexp.exec()
def updateHistograms(self):
self.updateTypeHistogram()
self.updateSizeHistogram()
def initializeSpecPlot(self):
self.specPlot.loadSpectraAndInitializeSpecPlot()
......@@ -525,10 +512,6 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
particleIndicesOfType = self.particleContainer.getIndicesOfParticleType(self.typeSelectorCombo.currentText())
return particleIndicesOfType[self.particleSelector.value()-1]
def updateHistograms(self):
self.updateTypeHistogram()
self.updateSizeHistogram()
def updateTypeHistogram(self):
#draw the general histogram
colorList = []
......@@ -655,7 +638,14 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
for scanIndicator in self.parent.ramanscanitems:
scanIndicator.hidden = hidden
scanIndicator.update()
def exportToExcel(self):
expWin = ExpExcelDialog(self.particleContainer, self)
expWin.exec()
def exportToSQL(self):
sqlexp = SQLExport(self.particleContainer, self)
sqlexp.exec()
def closeEvent(self, event):
for window in [self.importWindow, self.dbWin]:
......
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu May 31 10:07:45 2018
GEPARD - Gepard-Enabled PARticle Detection
Copyright (C) 2018 Lars Bittrich and Josef Brandt, Leibniz-Institut für
Polymerforschung Dresden e. V. <bittrich-lars@ipfdd.de>
@author: brandt
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program, see COPYING.
If not, see <https://www.gnu.org/licenses/>.
"""
import numpy as np
from PyQt5 import QtWidgets
import sys
from os import chdir, getcwd
class LoadWITecResults(QtWidgets.QDialog):
def __init__(self, particleContainer, parent):
......@@ -28,43 +40,34 @@ class LoadWITecResults(QtWidgets.QDialog):
self.hqis = None
self.addhqis = None
self.btn1 = QtWidgets.QPushButton('LoadTrueMatchResults')
self.btn1.resize(self.btn1.sizeHint())
self.btn1.clicked.connect(self.loadFileManually)
self.loadBtn = QtWidgets.QPushButton('LoadTrueMatchResults')
self.loadBtn.resize(self.loadBtn.sizeHint())
self.loadBtn.clicked.connect(self.loadFileManually)
optionsLayout = QtWidgets.QFormLayout()
self.optionsGroup = QtWidgets.QGroupBox('Compute Options')
self.optionsGroup.setDisabled(True)
self.btn3 = QtWidgets.QPushButton('Compute')
self.btn3.clicked.connect(self.runCalculations)
self.label1 = QtWidgets.QLabel('HQI-Threshold:')
self.spinbox1 = QtWidgets.QDoubleSpinBox(self)
self.spinbox1.valueChanged.connect(self.updateParentSpinboxes)
optionsLayout.addRow(self.label1, self.spinbox1)
# optionsLayout = QtWidgets.QFormLayout()
# self.optionsGroup = QtWidgets.QGroupBox('Compute Options')
# self.optionsGroup.setDisabled(True)
#
# self.label1 = QtWidgets.QLabel('HQI-Threshold:')
# self.spinbox1 = QtWidgets.QDoubleSpinBox(self)
# self.spinbox1.valueChanged.connect(self.runCalculations)
# optionsLayout.addRow(self.label1, self.spinbox1)
self.label2 = QtWidgets.QLabel('ComponentThreshold:')
self.spinbox2 = QtWidgets.QDoubleSpinBox(self)
self.spinbox2.valueChanged.connect(self.updateParentSpinboxes)
optionsLayout.addRow(self.label2, self.spinbox2)
self.label3 = QtWidgets.QLabel('Max Items in Display:')
self.numDispSpinbox = QtWidgets.QSpinBox(self)
self.numDispSpinbox.setValue(20)
self.numDispSpinbox.setMinimum(1)
self.numDispSpinbox.setMaximum(40)
self.numDispSpinbox.valueChanged.connect(self.updateParentSpinboxes)
optionsLayout.addRow(self.label3, self.numDispSpinbox)
optionsLayout.addRow(self.btn3)
# self.label2 = QtWidgets.QLabel('ComponentThreshold:')
# self.spinbox2 = QtWidgets.QDoubleSpinBox(self)
# self.spinbox2.valueChanged.connect(self.updateParentSpinboxes)
# optionsLayout.addRow(self.label2, self.spinbox2)
for box in [self.spinbox1, self.spinbox2]:
box.setValue(50)
box.setDecimals(1)
box.setSingleStep(5)
box.setMinimum(0)
box.setMaximum(100)
self.spinbox2.setValue(30) #more reasonable...
self.optionsGroup.setLayout(optionsLayout)
# for box in [self.spinbox1, self.spinbox2]:
# for box in [self.spinbox1]:
# box.setValue(50)
# box.setDecimals(1)
# box.setSingleStep(5)
# box.setMinimum(0)
# box.setMaximum(100)
## self.spinbox2.setValue(30) #more reasonable...
#
# self.optionsGroup.setLayout(optionsLayout)
self.reviewGroup = QtWidgets.QGroupBox('Review Changes')
self.reviewGroup.setDisabled(True)
......@@ -76,8 +79,8 @@ class LoadWITecResults(QtWidgets.QDialog):
reviewLayout.addStretch()
self.reviewGroup.setLayout(reviewLayout)
self.layout.addWidget(self.btn1, 0, 0)
self.layout.addWidget(self.optionsGroup, 1, 0)
self.layout.addWidget(self.loadBtn, 0, 0)
# self.layout.addWidget(self.optionsGroup, 1, 0)
self.layout.addWidget(self.reviewGroup, 2, 0)
self.manualPolymers = {}
......@@ -90,11 +93,6 @@ class LoadWITecResults(QtWidgets.QDialog):
self.numFlagForSetUnknown = 2
self.numFlagForPrompt = 3
def updateParentSpinboxes(self):
self.parent.hqiSpinBox.setValue(self.spinbox1.value())
self.parent.compHqiSpinBox.setValue(self.spinbox2.value())
self.parent.dispResultSpinBox.setValue(self.numDispSpinbox.value())
def show3FlagsReview(self):
self.editEntryWindow = ModifyManualEdits(self, self.manualPolymers, self.manualAdditives)
self.editEntryWindow.show()
......@@ -114,18 +112,14 @@ class LoadWITecResults(QtWidgets.QDialog):
for lineindex, line in enumerate(file):
if lineindex > 0:
self.trueMatchResults.append(line)
self.btn1.setText('Data loaded')
self.optionsGroup.setDisabled(False)
self.runCalculations()
def formatResults(self, rawResults): #get rid of header line, first data interpretation
results = []
for index,line in enumerate(rawResults):
for index, line in enumerate(rawResults):
if index == 0:
line = line.strip().split(';')[:-1] #disregard the last entry of each line, as each line ends with ; <- that produces an empty entry...
if line[0] != 'Search Spectrum Name':
print('incompatible data format')
break
assert line[0] == 'Search Spectrum Name', 'Assertion Error in loadTrueMatchResults'
#detect, whether one- or multicomponent-search was done
if line[-1] == 'IsMarked':
numhits = np.int(line[-2].split(' ')[-1])
......@@ -142,38 +136,29 @@ class LoadWITecResults(QtWidgets.QDialog):
return results, numspectra, numcomps, numhits
def interpretEntry(self, index, entry, numhits, numcomps):
def interpretEntry(self, entry, numhits, numcomps):
entry = entry.split(';')
polymertype, additive, hqi, addhqi = None, None, None, None #assign default None
specIndex, polymertype, additive, hqi, addhqi = None, None, None, None, 0 #assign defaults
#specNameFormat is: SampleName_000_Spec.Data 1 (SpecIndex)
specName = entry[0]
indexOpenBracket = specName.find('(')
indexCloseBracket = specName.find(')')
specIndex = int(specName[indexOpenBracket+1:indexCloseBracket])
#find yes-flags
flags = np.where(np.array(entry) == 'yes')[0]
if len(flags) == 0:
#take highest HQI entry
if numcomps == 1:
if float(entry[1]) > self.spinbox1.value():
polymertype = entry[2]
hqi = entry[1]
else:
polymertype = 'unknown'
hqi = 0
polymertype = entry[2]
hqi = entry[1]
else:
if float(entry[1]) > self.spinbox1.value():
polymertype = entry[5]
hqi = entry[1]
if float(entry[6]) > self.spinbox2.value():
additive = entry[7]
addhqi = entry[6]
else:
additive = 'none'
addhqi = 0
else:
polymertype = 'unknown'
additive = 'none'
hqi = 0
addhqi = 0
polymertype = entry[5]
hqi = entry[1]
additive = entry[7]
addhqi = entry[6]
elif len(flags) == 1:
#exactly one flag was placed, take this entry
if numcomps == 1:
......@@ -193,78 +178,68 @@ class LoadWITecResults(QtWidgets.QDialog):
addhqi = 0
elif len(flags) == 3:
hqi = 100
if index not in self.manualPolymers:
polymertype, ok = QtWidgets.QInputDialog.getText(self, 'Name of main component', 'Spectrum at index {} is:'.format(index))
self.manualPolymers[index] = polymertype
if specIndex not in self.manualPolymers:
polymertype, ok = QtWidgets.QInputDialog.getText(self, 'Name of main component', 'Spectrum at index {} is:'.format(specIndex))
self.manualPolymers[specIndex] = polymertype
else:
polymertype = self.manualPolymers[index]
polymertype = self.manualPolymers[specIndex]
if numcomps > 1:
addhqi = 100
if entry[0] not in self.manualAdditives:
additive, ok = QtWidgets.QInputDialog.getText(self, 'Name of additive', 'Additive at index {} is:'.format(index))
self.manualAdditives[index] = additive
additive, ok = QtWidgets.QInputDialog.getText(self, 'Name of additive', 'Additive at index {} is:'.format(specIndex))
self.manualAdditives[specIndex] = additive
else:
additive = self.manualAdditives[index]
additive = self.manualAdditives[specIndex]
else:
QtWidgets.QMessageBox.about(self, 'Error!', 'No rule for {} flags, found at spectrum index {}'.format(len(flags), index))
QtWidgets.QMessageBox.about(self, 'Error!', 'No rule for {} flags, found at spectrum index {}'.format(len(flags), specIndex))
if addhqi is None:
addhqi = 0
return polymertype, additive, float(hqi), float(addhqi)
return specIndex, polymertype, additive, float(hqi), float(addhqi)
def runCalculations(self):
def runCalculations(self):
self.resultList, numspectra, numcomps, numhits = self.formatResults(self.trueMatchResults)
self.dispresults = self.numDispSpinbox.value()
self.polymertypes =[]
self.hqis = []
self.polymertypes = [None]*numspectra
self.hqis = [None]*numspectra
if numcomps == 1: #####SINGLE COMPONENT SEARCH
self.additives = None
self.addhqis = None
self.spinbox2.setEnabled(False)
# self.spinbox2.setEnabled(False)
for index, entry in enumerate(self.resultList):
if len(entry) == 0:
del self.resultList[index]
else:
polymertype, additive, hqi, addhqi = self.interpretEntry(index, entry, numhits, numcomps)
self.polymertypes.append(polymertype)
self.hqis.append(hqi)
specIndex, polymertype, additive, hqi, addhqi = self.interpretEntry(entry, numhits, numcomps)
self.polymertypes[specIndex] = polymertype
self.hqis[specIndex] = hqi
else: #####MULTI-COMPONENT SEARCH
self.additives = []
self.addhqis = []
self.additives = [None]*numspectra
self.addhqis = [None]*numspectra
for index, entry in enumerate(self.resultList):
if len(entry) > 0:
polymertype, additive, hqi = self.interpretEntry(index, entry, numhits, numcomps)
self.polymertypes.append(polymertype)
self.hqis.append(hqi)
self.additives.append(additive)
self.addhqis.append(addhqi)
specIndex, polymertype, additive, hqi = self.interpretEntry(entry, numhits, numcomps)
self.polymertypes[specIndex] = polymertype
self.hqis[specIndex] = hqi
self.additives[specIndex] = additive
self.addhqis[specIndex] = addhqi
assert len(self.polymertypes) == len(self.resultList), 'incorrect number of polymer types added...'
assert not None in self.polymertypes, 'wrong assignments in loadResults'
assert not None in self.hqis, 'wrong assignments in loadResults'
self.particleContainer.applyAssignmentListToParticleMeasurements(self.polymertypes)
self.particleContainer.applyHQIListToParticleMeasurements(self.hqis)
self.parent.formatResults()
if len(self.manualPolymers) > 0:
self.reviewGroup.setDisabled(False)
self.parent.applyHQIThresholdToResults()
self.loadBtn.setText('Data loaded')
QtWidgets.QMessageBox.about(self, 'Success', 'Results were imported successfully.\nYou can close this window or modify manual edits.')
def closeEvent(self, event):
# self.datastats.resetResults(self.polymertypes, self.additives,
# self.hqis, self.addhqis)
self.parent.updateBtn.clicked.connect(self.parent.formatResults)
self.parent.formatResults()
self.parent.show_hide_labels()
# minHQI = self.parent.hqiSpinBox.value()
# compHQI = self.parent.compHqiSpinBox.value()
self.parent.dataset.save()
#TODO: SANITY CHECK FOR DATA CONSISTENCY!!
# if not self.parent.datastats.saveAnalysisResults(minHQI, compHQI):
......@@ -331,21 +306,4 @@ class ModifyManualEdits(QtWidgets.QWidget):
self.parent.manualPolymers, self.parent.manualAdditives = self.polymerEdits, self.additiveEdits
self.parent.runCalculations()
self.close()
if __name__ == "__main__":
wd=getcwd()
chdir(wd)
try:
del(app)
except:
pass
app = QtWidgets.QApplication(sys.argv)
mainWin = LoadWITecResults(None)
mainWin.show()
app.exec_()
......@@ -72,22 +72,24 @@ class ParticleContainer(object):
particle.applyHQITresholdToMeasurements(minHQI)
def applyAssignmentListToParticleMeasurements(self, assignmentList):
indicesOfTransferredAssignments = []
'''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.append(scanIndex)
assert np.unique(indicesOfTransferredAssignments) == np.unique((range(len(assignmentList))))
indicesOfTransferredAssignments[scanIndex] = scanIndex
assert not None in indicesOfTransferredAssignments
def applyHQIListToParticleMeasurements(self, hqiList):
indicesOfTransferredAssignments = []
'''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.setAssignment(hqiList[scanIndex])
indicesOfTransferredAssignments.append(scanIndex)
assert np.unique(indicesOfTransferredAssignments) == np.unique((range(len(hqiList))))
meas.setHQI(hqiList[scanIndex])
indicesOfTransferredHQIs[scanIndex] = scanIndex
assert not None in indicesOfTransferredHQIs
def getParticleOfIndex(self, index):
particle = self.particles[index]
......
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