Commit 90287adf authored by JosefBrandt's avatar JosefBrandt

Excel and SQL Export working (hotfix)

parent 8e7707c0
......@@ -160,11 +160,13 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
optionsLayout = QtWidgets.QFormLayout()
self.hqiSpinBox = QtWidgets.QDoubleSpinBox()
self.hqiSpinBox.setValue(self.dataset.resultParams['minHQI'])
self.hqiSpinBox.setDecimals(1)
self.hqiSpinBox.setMinimum(0)
self.hqiSpinBox.setMaximum(100)
self.hqiSpinBox.setMaximumWidth(100)
minHQI = self.dataset.resultParams['minHQI']
if minHQI is not None:
self.hqiSpinBox.setValue(minHQI)
self.hqiSpinBox.valueChanged.connect(self.applyHQIThresholdToResults)
optionsLayout.addRow(QtWidgets.QLabel('minimum HQI:'), self.hqiSpinBox)
......@@ -198,9 +200,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self.layout.addLayout(self.menuLayout)
self.layout.addLayout(viewLayout)
minHQI = self.dataset.resultParams['minHQI']
if minHQI is not None:
self.hqiSpinBox.setValue(minHQI)
self.createActions()
self.createMenus()
......@@ -611,8 +611,14 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
expWin.exec()
def exportToSQL(self):
sqlexp = SQLExport(self.particleContainer, self)
sqlexp.exec()
if len(self.dataset.resultsUploadedToSQL) > 0:
reply = QtWidgets.QMessageBox.question(self, 'Warning!',
"The following results were already uploaded:\n\n{}\n\nContinue?".format('\n'.join(self.dataset.resultsUploadedToSQL)),
QtWidgets.QMessageBox.Yes |
QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.No)
if reply == QtWidgets.QMessageBox.Yes:
sqlexp = SQLExport(self.dataset)
sqlexp.exec()
def closeEvent(self, event):
for window in [self.importWindow, self.dbWin]:
......
......@@ -45,7 +45,6 @@ class ExpExcelDialog(QtWidgets.QDialog):
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
for index, option in enumerate(self.exportOptions):
self.checkBoxes.append(QtWidgets.QCheckBox(self))
......@@ -76,8 +75,8 @@ class ExpExcelDialog(QtWidgets.QDialog):
def toExcel(self):
requiredcolumns = []
uniquePolymers = self.particleContainer.getUniquePolymers()
polymers = self.particleContainer.getListOfParticleAssignments()
sizes = self.particleContainer.getSizesOfAllParticles()
polymers = np.array(self.particleContainer.getListOfParticleAssignments())
sizes = np.array(self.particleContainer.getSizesOfAllParticles())
for box in self.checkBoxes:
......@@ -85,13 +84,13 @@ class ExpExcelDialog(QtWidgets.QDialog):
if box.text() != 'Size Classes':
requiredcolumns.append(box.text())
if box.text() == 'Long Size (µm)':
longSizes = sizes
longSizes = np.round(sizes)
elif box.text() == 'Short Size (µm)':
shortSizes = self.particleContainer.getShortSizesOfAllParticles()
shortSizes = np.round(np.array(self.particleContainer.getShortSizesOfAllParticles()))
elif box.text() == 'HQI':
hqis = self.particleContainer.getListOfHighestHQIs()
hqis = np.array(self.particleContainer.getListOfHighestHQIs())
elif box.text() == 'Area (µm²)':
areas = self.particleContainer.getAreasOfAllParticles()
areas = np.array(self.particleContainer.getAreasOfAllParticles())
else:
requiredcolumns.append('0 - 5 µm')
......@@ -101,13 +100,12 @@ class ExpExcelDialog(QtWidgets.QDialog):
requiredcolumns.append('50 - 100 µm')
requiredcolumns.append('> 100 µm')
finalData = np.zeros((polymers.shape[0],len(requiredcolumns)-1))
polymertypes = [""]*polymers.shape[0]
finalData = np.zeros((len(polymers),len(requiredcolumns)-1))
polymertypes = [""]*len(polymers)
rowindex = 0
for polymer in uniquePolymers:
indices = self.particleContainer.getgetIndicesOfParticleType(polymer)
indices = polymers == polymer
numentries = int(np.sum(indices))
print("Num:", numentries)
sys.stdout.flush()
for colindex, column in enumerate(requiredcolumns):
......@@ -130,7 +128,7 @@ class ExpExcelDialog(QtWidgets.QDialog):
upLimit = self.sizeClasses[classindex]
if classindex == 0: lowLimit = 0
else: lowLimit = self.sizeClasses[classindex-1]
curSize = self.sizes[dataindex]
curSize = sizes[dataindex]
if curSize > lowLimit and curSize <= upLimit:
finalData[rowindex+tableindex, numPrevCols + classindex] = np.int(1)
......@@ -140,17 +138,13 @@ class ExpExcelDialog(QtWidgets.QDialog):
rowindex = rowindex + numentries
#dump into excel file
xlsname = self.directory + '//' + self.xlsFileName.text() + '.xlsx'
print('exporting excel to:\n file name: {} in directory: {}'.format(self.xlsFileName.text(), self.directory))
validFileName = False
xlsname = os.path.join(self.dataset.path, f'{self.xlsFileName.text()}.xlsx')
print('exporting excel to:\n file name: {} in directory: {}'.format(self.xlsFileName.text(), self.dataset.path))
incr = 1
while not validFileName:
if not os.path.exists(xlsname):
validFileName = True
else:
xlsname = self.directory + '//' + self.xlsFileName.text() + ' {}.xlsx'.format(incr)
incr += 1
while os.path.exists(xlsname):
xlsname = os.path.join(self.dataset.path, f'{self.xlsFileName.text()} {incr}.xlsx')
incr += 1
writer = pd.ExcelWriter(xlsname, engine = 'xlsxwriter')
df = pd.DataFrame(finalData, columns=requiredcolumns[1:])
......@@ -159,20 +153,20 @@ class ExpExcelDialog(QtWidgets.QDialog):
if '> 100 µm' in requiredcolumns:
#generate particle statistics report
header = ['0 - 5 µm', '5 - 10 µm', '10 - 20 µm', '20 - 50 µm', '50 - 100 µm', '> 100 µm']
index = np.unique(self.polymers)
particleclasses = []
for polymer in index:
indices = np.where(self.polymers == polymer)[0]
sortind = np.searchsorted([5,10,20,50,100], self.sizes[indices], 'right')
for polymer in uniquePolymers:
indices = self.particleContainer.getIndicesOfParticleType(polymer)
sortind = np.searchsorted([5,10,20,50,100], sizes[indices], 'right')
classes = np.bincount(sortind, minlength=6)
particleclasses.append(classes)
particleclasses = np.array(particleclasses)
report = pd.DataFrame(np.array(particleclasses), columns=header,
dtype=int)
report.insert(0, 'Polymer Type', index)
report.insert(0, 'Polymer Type', uniquePolymers)
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()
\ No newline at end of file
self.accept()
QtWidgets.QMessageBox.about(self, 'Particles succesfully exported', 'List saved to\n' + str(xlsname))
\ No newline at end of file
......@@ -43,31 +43,6 @@ class LoadTrueMatchResults(QtWidgets.QDialog):
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.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)
# 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)
......@@ -80,7 +55,6 @@ class LoadTrueMatchResults(QtWidgets.QDialog):
self.reviewGroup.setLayout(reviewLayout)
self.layout.addWidget(self.loadBtn, 0, 0)
# self.layout.addWidget(self.optionsGroup, 1, 0)
self.layout.addWidget(self.reviewGroup, 2, 0)
self.manualPolymers = {}
......@@ -144,7 +118,12 @@ class LoadTrueMatchResults(QtWidgets.QDialog):
specName = entry[0]
indexOpenBracket = specName.find('(')
indexCloseBracket = specName.find(')')
specIndex = int(specName[indexOpenBracket+1:indexCloseBracket])
inbrackets = specName[indexOpenBracket+1:indexCloseBracket]
try:
specIndex = int(inbrackets)
except:
print(inbrackets)
raise
#find yes-flags
flags = np.where(np.array(entry) == 'yes')[0]
......@@ -204,7 +183,6 @@ class LoadTrueMatchResults(QtWidgets.QDialog):
if numcomps == 1: #####SINGLE COMPONENT SEARCH
self.additives = None
self.addhqis = None
# self.spinbox2.setEnabled(False)
for index, entry in enumerate(self.resultList):
if len(entry) == 0:
del self.resultList[index]
......@@ -241,11 +219,6 @@ class LoadTrueMatchResults(QtWidgets.QDialog):
def closeEvent(self, event):
#TODO: SANITY CHECK FOR DATA CONSISTENCY!!
# if not self.parent.datastats.saveAnalysisResults(minHQI, compHQI):
# QtWidgets.QMessageBox.warning(self.parent, 'Error!',
# 'Data inconsistency after saving!',
# QtWidgets.QMessageBox.Ok, QtWidgets.QMessageBox.Ok)
self.parent.setEnabled(True)
event.accept()
......
......@@ -83,17 +83,19 @@ class Particle(object):
else:
print(f'Error, particle size requested, but not yet set.\nParticle Index is {self.index}')
raise ValueError
assert size is not None, f'Error, size or particle {self.index} is None'
return round(size)
assert size is not None, f'Error, size of particle {self.index} is None'
return size
def getShortParticleSize(self):
if not np.isnan(self.shortSize_ellipse):
return self.shortSize_ellipse
size = self.shortSize_ellipse
elif not np.isnan(self.shortSize_box):
return self.shortSize_box
size = self.shortSize_box
else:
print(f'Error, particle size requested, but not yet set.\nParticle Index is {self.index}')
raise ValueError
assert size is not None, f'Error, short size of particle {self.index} is None'
return size
def getNumberOfMeasurements(self):
return len(self.measurements)
......
......@@ -33,7 +33,6 @@ class ParticleContainer(object):
self.datasetParent = datasetParent
self.particles = []
self.measurements = []
self.spectra = None
self.inconsistentParticles = []
self.typeHistogram = None
......@@ -83,7 +82,6 @@ class ParticleContainer(object):
if spectra is not None:
np.save(self.datasetParent.getSpectraFileName(), spectra)
return spectra
def initializeParticles(self, numParticles):
......
......@@ -142,7 +142,7 @@ class ParticlePainter(QtWidgets.QGraphicsItem):
elif y_shift == 0:
newImg[:, :self.img.shape[1]] = self.img
elif y_shift > 0:
newImg[:y_shift, :self.img.shape[1]] = self.img
newImg[:self.img.shape[0], :self.img.shape[1]] = self.img
self.img = np.uint8(newImg)
self.setBrect()
......
This diff is collapsed.
......@@ -252,7 +252,7 @@ class DataSet(object):
self.particleContainer.clearMeasurements()
if self.particles2spectra is None:
if not hasattr(self, 'particles2spectra') or self.particles2spectra is None:
self.particles2spectra = [[int(np.where(self.ramanscansortindex == i)[0])] for i in range(len(self.ramanscansortindex))]
if len(self.particlestats) > 0: #i.e., particle detection was completed and particle data is there
......@@ -268,11 +268,12 @@ class DataSet(object):
self.particleContainer.setMeasurementScanIndex(indexOfNewMeas, scanIndex)
curParticle.addMeasurement(self.particleContainer.measurements[indexOfNewMeas])
for particle in self.particleContainer.particles:
for meas in particle.measurements:
specIndex = meas.getScanIndex()
meas.setAssignment(self.results['polymers'][specIndex])
meas.setHQI(self.results['hqis'][specIndex])
if hasattr(self, 'results') and self.results['polymers'] is not None: #transfer results
for particle in self.particleContainer.particles:
for meas in particle.measurements:
specIndex = meas.getScanIndex()
meas.setAssignment(self.results['polymers'][specIndex])
meas.setHQI(self.results['hqis'][specIndex])
self.particleContainer.testForInconsistentParticles()
......
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