Commit 16751ee9 authored by Hackmet's avatar Hackmet

Added database support,

several bugfixes
parent 86522ed2
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
"""
Created on Thu May 31 10:07:45 2018
@author: brandt
"""
""" """
GEPARD - Gepard-Enabled PARticle Detection GEPARD - Gepard-Enabled PARticle Detection
Copyright (C) 2018 Lars Bittrich and Josef Brandt, Leibniz-Institut für Copyright (C) 2018 Lars Bittrich and Josef Brandt, Leibniz-Institut für
...@@ -41,6 +35,7 @@ from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as Navigatio ...@@ -41,6 +35,7 @@ from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as Navigatio
import pandas as pd import pandas as pd
from analysis.loadresults import LoadWITecResults from analysis.loadresults import LoadWITecResults
from analysis.editParticles import ParticleEditor from analysis.editParticles import ParticleEditor
from analysis.database import DataBaseWindow
try: try:
from analysis.sqlexport import SQLExport from analysis.sqlexport import SQLExport
sqlEnabled = True sqlEnabled = True
...@@ -48,19 +43,22 @@ except: ...@@ -48,19 +43,22 @@ except:
sqlEnabled = False sqlEnabled = False
class ParticleAnalysis(QtWidgets.QWidget): class ParticleAnalysis(QtWidgets.QMainWindow):
def __init__(self, parent): def __init__(self, parent):
super(ParticleAnalysis, self).__init__() super(ParticleAnalysis, self).__init__()
self.setGeometry(100, 100, 1680, 1050) self.setGeometry(100, 100, 1680, 1050)
self.setWindowTitle('Results of polymer analysis') self.setWindowTitle('Results of polymer analysis')
self.layout = QtWidgets.QHBoxLayout() self.layout = QtWidgets.QHBoxLayout()
self.setLayout(self.layout) self.widget = QtWidgets.QWidget()
self.widget.setLayout(self.layout)
self.setCentralWidget(self.widget)
self.parent = parent self.parent = parent
if self.parent is not None: if self.parent is not None:
self.config = self.parent.dataset.resultParams self.config = self.parent.dataset.resultParams
self.editor = ParticleEditor(self) self.editor = ParticleEditor(self)
self.expWin = None
self.spectraResults = None #entire List of all spectra assignments self.spectraResults = None #entire List of all spectra assignments
self.additiveResults = None #entire List of all additives self.additiveResults = None #entire List of all additives
...@@ -98,8 +96,7 @@ class ParticleAnalysis(QtWidgets.QWidget): ...@@ -98,8 +96,7 @@ class ParticleAnalysis(QtWidgets.QWidget):
self.sizeHistogramCanvas.figure.subplots_adjust(left=0.1, top=0.93, bottom=0.15, right=0.995) self.sizeHistogramCanvas.figure.subplots_adjust(left=0.1, top=0.93, bottom=0.15, right=0.995)
histNavigation = NavigationToolbar(self.sizeHistogramCanvas, self) histNavigation = NavigationToolbar(self.sizeHistogramCanvas, self)
histNavigation.setOrientation(QtCore.Qt.Vertical) histNavigation.setOrientation(QtCore.Qt.Vertical)
histNavigation.setMinimumWidth(50) histNavigation.setFixedWidth(50)
histNavigation.setMaximumWidth(50)
sizeHistLayout.addWidget(histNavigation) sizeHistLayout.addWidget(histNavigation)
sizeHistLayout.addWidget(self.sizeHistogramCanvas) sizeHistLayout.addWidget(self.sizeHistogramCanvas)
sizeHistGroup.setLayout(sizeHistLayout) sizeHistGroup.setLayout(sizeHistLayout)
...@@ -109,11 +106,11 @@ class ParticleAnalysis(QtWidgets.QWidget): ...@@ -109,11 +106,11 @@ class ParticleAnalysis(QtWidgets.QWidget):
self.specCanvas = FigureCanvas(Figure()) self.specCanvas = FigureCanvas(Figure())
self.spec_ax = self.specCanvas.figure.subplots() self.spec_ax = self.specCanvas.figure.subplots()
self.spec_ax.axis("off") self.spec_ax.axis("off")
self.specCanvas.figure.subplots_adjust(left=0.1, top=0.93, bottom=0.15, right=0.995) self.ref_ax = self.spec_ax.twinx()
self.specCanvas.figure.subplots_adjust(left=0.1, top=0.93, bottom=0.15, right=0.9)
specNavigation = NavigationToolbar(self.specCanvas, self) specNavigation = NavigationToolbar(self.specCanvas, self)
specNavigation.setOrientation(QtCore.Qt.Vertical) specNavigation.setOrientation(QtCore.Qt.Vertical)
specNavigation.setMinimumWidth(50) specNavigation.setFixedWidth(50)
specNavigation.setMaximumWidth(50)
specLayout.addWidget(specNavigation) specLayout.addWidget(specNavigation)
specLayout.addWidget(self.specCanvas) specLayout.addWidget(self.specCanvas)
...@@ -145,42 +142,6 @@ class ParticleAnalysis(QtWidgets.QWidget): ...@@ -145,42 +142,6 @@ class ParticleAnalysis(QtWidgets.QWidget):
spinbox.setSingleStep(1) spinbox.setSingleStep(1)
spinbox.setValue(1) spinbox.setValue(1)
self.overlayGroup = QtWidgets.QGroupBox('Color Overlay')
self.overlayLayout = QtWidgets.QHBoxLayout()
self.noOverlayBtn = QtWidgets.QRadioButton('None')
self.selOverlayBtn = QtWidgets.QRadioButton('Selected')
self.fullOverlayBtn = QtWidgets.QRadioButton('Full')
for index, button in enumerate([self.noOverlayBtn, self.selOverlayBtn, self.fullOverlayBtn]):
if index == 2:
button.setChecked(True)
else:
button.setChecked(False)
button.released.connect(self.createPolymerOverlay)
button.released.connect(self.updateHistogram)
self.overlayLayout.addWidget(button)
self.seedBtn = QtWidgets.QPushButton('Set Color Seed')
self.seedBtn.released.connect(self.updateColorSeed)
self.overlayLayout.addWidget(self.seedBtn)
self.hideLabelBtn = QtWidgets.QCheckBox('Hide Polymer Numbers')
self.hideLabelBtn.stateChanged.connect(self.show_hide_labels)
self.hideLabelBtn.setChecked(False)
# self.hideLabelBtn.setChecked(True) #change twice in order to run the connected function...
self.overlayLayout.addWidget(self.hideLabelBtn)
self.transpBtn = QtWidgets.QCheckBox('Transparent')
self.transpBtn.setChecked(False)
self.transpBtn.stateChanged.connect(self.createPolymerOverlay)
self.overlayLayout.addWidget(self.transpBtn)
self.darkenBtn = QtWidgets.QCheckBox('Darken Image')
self.darkenBtn.setChecked(False)
self.darkenBtn.stateChanged.connect(self.darkenBackground)
self.overlayLayout.addWidget(self.darkenBtn)
self.overlayGroup.setLayout(self.overlayLayout)
navigationLayout.addWidget(QtWidgets.QLabel('Select Polymer Type:')) navigationLayout.addWidget(QtWidgets.QLabel('Select Polymer Type:'))
navigationLayout.addWidget(self.polymerComboBox) navigationLayout.addWidget(self.polymerComboBox)
navigationLayout.addStretch() navigationLayout.addStretch()
...@@ -192,25 +153,39 @@ class ParticleAnalysis(QtWidgets.QWidget): ...@@ -192,25 +153,39 @@ class ParticleAnalysis(QtWidgets.QWidget):
self.navigationGroup.setLayout(navigationLayout) self.navigationGroup.setLayout(navigationLayout)
referenceGroup = QtWidgets.QGroupBox('Reference Spectra')
referenceLayout = QtWidgets.QHBoxLayout()
self.refSelector = QtWidgets.QComboBox()
self.refSelector.setDisabled(True)
self.dbWin = DataBaseWindow(self)
self.dbWin.selectDataBase(refreshParent=True) #this includes updating the refSelector
self.refSelector.currentIndexChanged.connect(self.updateSpecPlot)
referenceLayout.addWidget(QtWidgets.QLabel('Select Reference'))
referenceLayout.addWidget(self.refSelector)
referenceGroup.setLayout(referenceLayout)
topLayout = QtWidgets.QHBoxLayout() topLayout = QtWidgets.QHBoxLayout()
topLayout.addWidget(self.navigationGroup) topLayout.addWidget(self.navigationGroup)
topLayout.addWidget(self.overlayGroup) topLayout.addWidget(referenceGroup)
topLayout.addStretch()
viewLayout.addLayout(topLayout) viewLayout.addLayout(topLayout)
viewLayout.addWidget(splitter2) viewLayout.addWidget(splitter2)
viewLayout.setStretch(1, 1) viewLayout.setStretch(1, 1)
reloadGroup = QtWidgets.QGroupBox('Reload Results from:') # reloadGroup = QtWidgets.QGroupBox('Reload Results from:')
reloadLayout = QtWidgets.QVBoxLayout() # reloadLayout = QtWidgets.QVBoxLayout()
self.reloadWITec = QtWidgets.QRadioButton('WITec True Match') # self.reloadWITec = QtWidgets.QRadioButton('WITec True Match')
self.reloadWITec.setChecked(True) # self.reloadWITec.setChecked(True)
self.reloadTxt = QtWidgets.QRadioButton('Ordered text file') # self.reloadTxt = QtWidgets.QRadioButton('Ordered text file')
reloadBtn = QtWidgets.QPushButton('reload Results') # reloadBtn = QtWidgets.QPushButton('reload Results')
reloadBtn.clicked.connect(self.importResults) # reloadBtn.clicked.connect(self.importResults)
reloadLayout.addWidget(self.reloadWITec) # reloadLayout.addWidget(self.reloadWITec)
reloadLayout.addWidget(self.reloadTxt) # reloadLayout.addWidget(self.reloadTxt)
reloadLayout.addWidget(reloadBtn) # reloadLayout.addWidget(reloadBtn)
reloadGroup.setLayout(reloadLayout) # reloadGroup.setLayout(reloadLayout)
self.optionsGroup = QtWidgets.QGroupBox('Further Options') self.optionsGroup = QtWidgets.QGroupBox('Further Options')
optionsLayout = QtWidgets.QFormLayout() optionsLayout = QtWidgets.QFormLayout()
...@@ -266,15 +241,10 @@ class ParticleAnalysis(QtWidgets.QWidget): ...@@ -266,15 +241,10 @@ class ParticleAnalysis(QtWidgets.QWidget):
self.layout_SArea.addWidget(self.resultCheckBoxes) self.layout_SArea.addWidget(self.resultCheckBoxes)
# self.layout_SArea.addStretch(1) # self.layout_SArea.addStretch(1)
self.exportbtn= QtWidgets.QPushButton('Export Results')
self.exportbtn.clicked.connect(self.exportData)
self.exportbtn.setDisabled(True)
self.menuLayout.addWidget(reloadGroup) # self.menuLayout.addWidget(reloadGroup)
self.menuLayout.addWidget(self.optionsGroup) self.menuLayout.addWidget(self.optionsGroup)
self.menuLayout.addWidget(self.resultScrollarea) self.menuLayout.addWidget(self.resultScrollarea)
self.menuLayout.addWidget(self.exportbtn)
self.layout.addLayout(self.menuLayout) self.layout.addLayout(self.menuLayout)
self.layout.addLayout(viewLayout) self.layout.addLayout(viewLayout)
...@@ -284,31 +254,128 @@ class ParticleAnalysis(QtWidgets.QWidget): ...@@ -284,31 +254,128 @@ class ParticleAnalysis(QtWidgets.QWidget):
if self.config['minHQI'] is not None: if self.config['minHQI'] is not None:
self.hqiSpinBox.setValue(self.config['minHQI']) self.hqiSpinBox.setValue(self.config['minHQI'])
self.compHqiSpinBox.setValue(self.config['compHQI']) self.compHqiSpinBox.setValue(self.config['compHQI'])
self.updateData()
self.createActions()
self.createMenus()
self.updateData()
def createActions(self):
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.noOverlayAct = QtWidgets.QAction("&No Overlay", self)
self.selOverlayAct = QtWidgets.QAction("&Selected Overlay", self)
self.fullOverlayAct = QtWidgets.QAction("&Full Overlay", self)
self.transpAct = QtWidgets.QAction("&Transparent Overlay")
self.transpAct.triggered.connect(self.createPolymerOverlay)
self.hideLabelAct = QtWidgets.QAction('&Hide Polymer Numbers', self)
self.hideLabelAct.triggered.connect(self.show_hide_labels)
self.darkenAct = QtWidgets.QAction("&Darken Image", self)
self.darkenAct.triggered.connect(self.darkenBackground)
for act in [self.noOverlayAct, self.selOverlayAct, self.fullOverlayAct, self.hideLabelAct, self.transpAct, self.darkenAct]:
act.setCheckable(True)
self.fullOverlayAct.setChecked(True)
self.seedAct = QtWidgets.QAction("&Set Color Seed", self)
self.seedAct.triggered.connect(self.updateColorSeed)
self.databaseAct = QtWidgets.QAction("&ManageDatabase", self)
self.databaseAct.triggered.connect(self.launchDBManager)
self.expExcelAct= QtWidgets.QAction("Export &Excel List", self)
self.expExcelAct.setDisabled(True)
self.expExcelAct.triggered.connect(self.exportToExcel)
self.expSQLAct = QtWidgets.QAction("Export to &SQL Database", self)
self.expSQLAct.setDisabled(True)
self.expSQLAct.triggered.connect(self.exportToSQL)
def createMenus(self):
self.importMenu = QtWidgets.QMenu("&Import Results")
self.importMenu.addActions([self.loadTrueMatchAct, self.loadTextFileAct])
self.dispMenu = QtWidgets.QMenu("&Display", self)
self.overlayActGroup = QtWidgets.QActionGroup(self.dispMenu)
self.overlayActGroup.setExclusive(True)
self.overlayActGroup.triggered.connect(self.createPolymerOverlay)
self.overlayActGroup.triggered.connect(self.updateHistogram)
for act in [self.noOverlayAct, self.selOverlayAct, self.fullOverlayAct]:
self.dispMenu.addAction(act)
self.overlayActGroup.addAction(act)
self.dispMenu.addSeparator()
self.dispMenu.addActions([self.transpAct, self.hideLabelAct, self.darkenAct, self.seedAct])
self.refMenu = QtWidgets.QMenu("&References")
self.refMenu.addAction(self.databaseAct)
self.exportMenu = QtWidgets.QMenu("&Export", self)
self.exportMenu.addAction(self.expExcelAct)
self.exportMenu.addAction(self.expSQLAct)
self.menuBar().addMenu(self.importMenu)
self.menuBar().addMenu(self.dispMenu)
self.menuBar().addMenu(self.refMenu)
self.menuBar().addMenu(self.exportMenu)
def launchDBManager(self):
if self.dbWin.isHidden():
self.dbWin.show()
def populateRefSelector(self):
#delete all present entries:
self.refSelector.clear()
if self.dbWin.activeDatabase is None:
self.refSelector.setDisabled(True)
else:
self.refSelector.addItems(self.dbWin.activeDatabase.spectraNames)
self.refSelector.setDisabled(False)
def loadSpectra(self, fname): def loadSpectra(self, fname):
try: import time
specs = np.loadtxt(fname) t0 = time.time()
#if spectra are already in correct format (WITec, first column: wavenumbers, other columns, intensities), specfilename = self.parent.dataset.fname.split('.pkl')[0] + '_spectra.npy'
#we take them, otherwise we have to convert from Renishaw export format... if os.path.exists(specfilename):
if len(np.unique(specs[:, 0])) == len(specs[:, 0]): #--> only unique numbers -> this is the wavenumber column, we have the witec format return np.load(specfilename)
else:
try:
specs = np.loadtxt(fname)
#if spectra are already in correct format (WITec, first column: wavenumbers, other columns, intensities),
#we take them, otherwise we have to convert from Renishaw export format...
if not len(np.unique(specs[:, 0])) == len(specs[:, 0]): #--> only unique numbers -> this is the wavenumber column, we have the witec format
#Renishaw Convert
#columns 0 and 1 are x and y coordinates. We dont need them...
startWavenumber = specs[0, 2]
startIndices = np.where(specs[:, 2] == startWavenumber)[0]
spectra = np.zeros((startIndices[1], len(startIndices)+1)) #create array with shape (numWavenumbers, numSpectra+1) (first column holds wavenumbers)
spectra[:, 0] = specs[startIndices[0]:startIndices[1], 2]
for i in range(len(startIndices)-1):
spectra[:, i+1] = specs[startIndices[i]:startIndices[i+1], 3]
#aaand the last spectrum:
spectra[:, -1] = specs[startIndices[-1]:, 3]
specs = np.flip(spectra, 0) #Renishaw goes from highest to lowest wavenumber, out of whatever reason...
#write spectra to binary file, that makes reloading them in future significantly faster
np.save(specfilename, specs)
print('loading specs:', time.time()-t0)
return specs return specs
else:
#columns 0 and 1 are x and y coordinates. We dont need them...
startWavenumber = specs[0, 2]
startIndices = np.where(specs[:, 2] == startWavenumber)[0]
spectra = np.zeros((startIndices[1], len(startIndices)+1)) #create array with shape (numWavenumbers, numSpectra+1) (first column holds wavenumbers) except:
spectra[:, 0] = specs[startIndices[0]:startIndices[1], 2] raise
for i in range(len(startIndices)-1): return None
spectra[:, i+1] = specs[startIndices[i]:startIndices[i+1], 3]
#aaand the last spectrum:
spectra[:, -1] = specs[startIndices[-1]:, 3]
return np.flip(spectra, 0) #Renishaw goes from highest to lowest wavenumber, out of whatever reason...
except:
return None
def updateData(self): def updateData(self):
self.spectraResults = self.parent.dataset.results['polymers'] self.spectraResults = self.parent.dataset.results['polymers']
self.additiveResults = self.parent.dataset.results['additives'] self.additiveResults = self.parent.dataset.results['additives']
...@@ -332,7 +399,7 @@ class ParticleAnalysis(QtWidgets.QWidget): ...@@ -332,7 +399,7 @@ class ParticleAnalysis(QtWidgets.QWidget):
QtWidgets.QMessageBox.critical(self, 'ERROR!', 'spectra file could not be opened with np.loadtxt...') QtWidgets.QMessageBox.critical(self, 'ERROR!', 'spectra file could not be opened with np.loadtxt...')
return return
self.parent.dataset.spectraPath = fname self.parent.dataset.spectraPath = fname
self.spec_ax.set_xbound(100, (3400 if self.spectra[-1, 0] > 3400 else self.spectra[-1, 0])) # self.spec_ax.set_xbound(100, (3400 if self.spectra[-1, 0] > 3400 else self.spectra[-1, 0]))
self.specCanvas.draw() self.specCanvas.draw()
####fake data!!! ####fake data!!!
...@@ -376,12 +443,9 @@ class ParticleAnalysis(QtWidgets.QWidget): ...@@ -376,12 +443,9 @@ class ParticleAnalysis(QtWidgets.QWidget):
self.updateBtn.clicked.connect(self.formatResults) self.updateBtn.clicked.connect(self.formatResults)
self.formatResults() self.formatResults()
def importResults(self): def importTrueMatchResults(self):
if self.reloadWITec.isChecked(): self.importWindow = LoadWITecResults(self)
self.importWindow = LoadWITecResults(self) self.importWindow.show()
self.importWindow.show()
elif self.reloadTxt.isChecked():
QtWidgets.QMessageBox.about(self, 'sorry...', 'Ordered Text import not yet implemented...')
def getAdditivePlot(self, event): def getAdditivePlot(self, event):
clickedindex = int(np.round(event.xdata)) clickedindex = int(np.round(event.xdata))
...@@ -505,33 +569,42 @@ class ParticleAnalysis(QtWidgets.QWidget): ...@@ -505,33 +569,42 @@ class ParticleAnalysis(QtWidgets.QWidget):
self.typeHistogramCanvas.setCursor(QtGui.QCursor(QtCore.Qt.WhatsThisCursor)) self.typeHistogramCanvas.setCursor(QtGui.QCursor(QtCore.Qt.WhatsThisCursor))
self.typeHistogramCanvas.mpl_connect('button_press_event', self.getAdditivePlot) self.typeHistogramCanvas.mpl_connect('button_press_event', self.getAdditivePlot)
self.exportbtn.setDisabled(False) self.expExcelAct.setDisabled(False)
if sqlEnabled:
self.expSQLAct.setDisabled(False)
self.navigationGroup.setEnabled(True) self.navigationGroup.setEnabled(True)
self.polymerComboBox.currentIndexChanged.disconnect() self.polymerComboBox.currentIndexChanged.disconnect()
self.polymerComboBox.clear() self.polymerComboBox.clear()
self.polymerComboBox.addItems(self.uniquePolymers) self.polymerComboBox.addItems(self.uniquePolymers)
self.polymerComboBox.currentIndexChanged.connect(self.displayNewPolymerType) self.polymerComboBox.currentIndexChanged.connect(self.displayNewPolymerType)
self.polymerIndex = self.polymerComboBox.currentIndex() self.polymerIndex = self.polymerComboBox.currentIndex()
if self.lastSpectrumInFocus is not None: if self.lastSpectrumInFocus is not None:
self.currentSpectrumIndex = self.lastSpectrumInFocus self.currentSpectrumIndex = self.lastSpectrumInFocus
self.displayNewPolymerType(resetCurrentIndex=False) self.displayNewPolymerType(resetCurrentIndex=False)
else: else:
self.displayNewPolymerType() self.displayNewPolymerType()
self.updateHistogram() self.updateHistogram()
self.createPolymerOverlay() self.createPolymerOverlay()
def exportData(self): def exportToExcel(self):
if self.expWindow is None: if self.expWin is not None:
self.expWindow = ExportDialog(self) self.expWin.close()
self.expWindow.show() self.expWin.destroy()
else: self.expWin = ExpExcelDialog(self)
self.expWindow.__init__(self) self.expWin.show()
self.expWindow.show()
def exportToSQL(self):
if self.expWin is not None:
self.expWin.close()
self.expWin.destroy()
self.expWin = SQLExport(self)
self.expWin.show()
def updatePolymerSpectrum(self, centerOn=True, highlightContour=True): def updateSpecPlot(self, centerOn=True, highlightContour=True):
#draw Sample Spectrum
specIndex = self.currentSpectrumIndex specIndex = self.currentSpectrumIndex
self.spec_ax.axis("on") self.spec_ax.axis("on")
self.spec_ax.clear() self.spec_ax.clear()
...@@ -541,6 +614,29 @@ class ParticleAnalysis(QtWidgets.QWidget): ...@@ -541,6 +614,29 @@ class ParticleAnalysis(QtWidgets.QWidget):
self.spec_ax.set_ylabel('Counts', fontsize = 15) self.spec_ax.set_ylabel('Counts', fontsize = 15)
self.spec_ax.set_title('ScanPoint Number {}, Size = {} µm'.format(specIndex+1, np.round(self.particlestats[self.currentParticleIndex][2], 1))) self.spec_ax.set_title('ScanPoint Number {}, Size = {} µm'.format(specIndex+1, np.round(self.particlestats[self.currentParticleIndex][2], 1)))
self.spec_ax.set_xbound(100, (3400 if self.spectra[-1, 0] > 3400 else self.spectra[-1, 0])) self.spec_ax.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))
y_min = min(self.spectra[y_start:, specIndex+1])
y_max = max(self.spectra[y_start:, specIndex+1])
self.spec_ax.set_ybound(0.9*y_min, 1.1*y_max)
#draw Reference
self.ref_ax.clear()
if self.refSelector.isEnabled() and self.refSelector.currentText() != '':
self.ref_ax.tick_params(axis='both', which='both', labelsize=15)
refID = self.dbWin.activeDatabase.spectraNames.index(self.refSelector.currentText())
ref = self.dbWin.activeDatabase.spectra[refID]
self.ref_ax.plot(ref[:, 0], ref[:, 1], color = 'r')
self.ref_ax.set_ylabel('Ref. Intensity', fontsize = 15, color = 'r')
self.ref_ax.tick_params('y', colors = 'r')
self.ref_ax.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.spec_ax.figure.canvas.draw() self.spec_ax.figure.canvas.draw()
self.parent.centerOnRamanIndex(specIndex, centerOn=centerOn, highlightContour=highlightContour) self.parent.centerOnRamanIndex(specIndex, centerOn=centerOn, highlightContour=highlightContour)
self.parent.highLightRamanIndex(specIndex) self.parent.highLightRamanIndex(specIndex)
...@@ -555,11 +651,11 @@ class ParticleAnalysis(QtWidgets.QWidget): ...@@ -555,11 +651,11 @@ class ParticleAnalysis(QtWidgets.QWidget):
self.spectrumSelector.setMaximum(len(self.particles2spectra[self.currentParticleIndex])) self.spectrumSelector.setMaximum(len(self.particles2spectra[self.currentParticleIndex]))
self.currentParticleIndex = self.indices[self.polymerIndex][self.particleSelector.value()-1] self.currentParticleIndex = self.indices[self.polymerIndex][self.particleSelector.value()-1]
self.currentSpectrumIndex = self.particles2spectra[self.currentParticleIndex][self.spectrumSelector.value()-1] self.currentSpectrumIndex = self.particles2spectra[self.currentParticleIndex][self.spectrumSelector.value()-1]
self.updatePolymerSpectrum(centerOn=True) self.updateSpecPlot(centerOn=True)
else: else:
self.currentParticleIndex = self.indices[self.polymerIndex][self.particleSelector.value()-1] self.currentParticleIndex = self.indices[self.polymerIndex][self.particleSelector.value()-1]
self.currentSpectrumIndex = self.particles2spectra[self.currentParticleIndex][self.spectrumSelector.value()-1] self.currentSpectrumIndex = self.particles2spectra[self.currentParticleIndex][self.spectrumSelector.value()-1]
self.updatePolymerSpectrum(centerOn=False) self.updateSpecPlot(centerOn=False)
def selectParticle(self, resetSpectrumCount=True): def selectParticle(self, resetSpectrumCount=True):
if self.particles2spectra is not None: if self.particles2spectra is not None:
...@@ -568,14 +664,14 @@ class ParticleAnalysis(QtWidgets.QWidget): ...@@ -568,14 +664,14 @@ class ParticleAnalysis(QtWidgets.QWidget):
if resetSpectrumCount: if resetSpectrumCount:
self.spectrumSelector.setValue(1) self.spectrumSelector.setValue(1)
self.currentSpectrumIndex = self.particles2spectra[self.currentParticleIndex][self.spectrumSelector.value()-1] self.currentSpectrumIndex = self.particles2spectra[self.currentParticleIndex][self.spectrumSelector.value()-1]
self.updatePolymerSpectrum() self.updateSpecPlot()
else: else:
print('no spectrum assignment found...') print('no spectrum assignment found...')
def selectSpectrum(self): def selectSpectrum(self):
if self.particles2spectra is not None: if self.particles2spectra is not None:
self.currentSpectrumIndex = self.particles2spectra[self.currentParticleIndex][self.spectrumSelector.value()-1] self.currentSpectrumIndex = self.particles2spectra[self.currentParticleIndex][self.spectrumSelector.value()-1]
self.updatePolymerSpectrum() self.updateSpecPlot()
def updateHistogram(self): def updateHistogram(self):
self.sizeHist_ax.clear() self.sizeHist_ax.clear()
...@@ -586,7 +682,7 @@ class ParticleAnalysis(QtWidgets.QWidget): ...@@ -586,7 +682,7 @@ class ParticleAnalysis(QtWidgets.QWidget):
#draw the general histogram #draw the general histogram
colorList = [] colorList = []
if self.selOverlayBtn.isChecked(): if self.selOverlayAct.isChecked():
abundancyList = [] abundancyList = []
for index, checkbox in enumerate(self.polymerCheckBoxes): for index, checkbox in enumerate(self.polymerCheckBoxes):
if checkbox.isChecked(): if checkbox.isChecked():
...@@ -608,7 +704,7 @@ class ParticleAnalysis(QtWidgets.QWidget): ...@@ -608,7 +704,7 @@ class ParticleAnalysis(QtWidgets.QWidget):
self.histPlotTextLabels = [] self.histPlotTextLabels = []
y_label_position = 0 y_label_position = 0
for index, i in enumerate(self.typehistogram): for index, i in enumerate(self.typehistogram):
if not self.selOverlayBtn.isChecked() or self.polymerCheckBoxes[index].isChecked(): if not self.selOverlayAct.isChecked() or self.polymerCheckBoxes[index].isChecked():
if self.sorted_additives is None: if self.sorted_additives is None:
numads = '' numads = ''
else: else:
...@@ -698,9 +794,9 @@ class ParticleAnalysis(QtWidgets.QWidget): ...@@ -698,9 +794,9 @@ class ParticleAnalysis(QtWidgets.QWidget):
def darkenBackground(self): def darkenBackground(self):
self.parent.darkenPixmap = self.darkenBtn.isChecked() self.parent.darkenPixmap = self.darkenAct.isChecked()
if self.darkenBtn.isChecked(): if self.darkenAct.isChecked():
self.parent.scene().setBackgroundBrush(QtGui.QColor(5, 5, 5)) self.parent.scene().setBackgroundBrush(QtGui.QColor(5, 5, 5))
self.parent.item.setOpacity(0.2) self.parent.item.setOpacity(0.2)
else: else:
...@@ -731,22 +827,20 @@ class ParticleAnalysis(QtWidgets.QWidget): ...@@ -731,22 +827,20 @@ class ParticleAnalysis(QtWidgets.QWidget):
return color return color
def createPolymerOverlay(self): def createPolymerOverlay(self):
if not self.noOverlayBtn.isChecked() and self.indices is not None: if not self.noOverlayAct.isChecked() and self.indices is not None:
if len(self.indices) > 0: if len(self.indices) > 0:
# ramansortindices = self.parent.dataset.ramanscansortindex
alpha = (128 if self.transpBtn.isChecked() else 255) alpha = (128 if self.transpAct.isChecked() else 255)
#get colors for each polymer type #get colors for each polymer type
colorList = [QtGui.QColor(255, 255, 255, alpha=50)]*len(self.particleResults) colorList = [QtGui.QColor(255, 255, 255, alpha=50)]*len(self.particleResults)
legendItems = [] legendItems = []
for index, indexList in enumerate(self.indices): for index, indexList in enumerate(self.indices):
if self.fullOverlayBtn.isChecked() or (self.selOverlayBtn.isChecked() and self.polymerCheckBoxes[index].isChecked()): if self.fullOverlayAct.isChecked() or (self.selOverlayAct.isChecked() and self.polymerCheckBoxes[index].isChecked()):
color = self.getColorFromName(self.uniquePolymers[index], base255=True) color = self.getColorFromName(self.uniquePolymers[index], base255=True)
color = QtGui.QColor(color[0], color[1], color[2], alpha=alpha) color = QtGui.QColor(color[0], color[1], color[2], alpha=alpha)
legendItems.append((self.uniquePolymers[index], color)) legendItems.append((self.uniquePolymers[index], color))
for i in indexList: for i in indexList:
# colorList[ramansortindices[i]] = color
colorList[i] = color colorList[i] = color
self.parent.contouritem.colorList = colorList self.parent.contouritem.colorList = colorList
...@@ -764,7 +858,7 @@ class ParticleAnalysis(QtWidgets.QWidget): ...@@ -764,7 +858,7 @@ class ParticleAnalysis(QtWidgets.QWidget):
self.parent.imparent.legend.hide() self.parent.imparent.legend.hide()
def show_hide_labels(self): def show_hide_labels(self):
hidden = self.hideLabelBtn.isChecked() hidden = self.hideLabelAct.isChecked()
for scanIndicator in self.parent.ramanscanitems: for scanIndicator in self.parent.ramanscanitems:
scanIndicator.hidden = hidden scanIndicator.hidden = hidden
scanIndicator.update() scanIndicator.update()
...@@ -777,22 +871,21 @@ class ParticleAnalysis(QtWidgets.QWidget): ...@@ -777,22 +871,21 @@ class ParticleAnalysis(QtWidgets.QWidget):
self.parent.dataset.resultParams = {'minHQI': self.hqiSpinBox.value(), self.parent.dataset.resultParams = {'minHQI': self.hqiSpinBox.value(),
'compHQI': self.compHqiSpinBox.value()} 'compHQI': self.compHqiSpinBox.value()}
# 'dispResults': self.dispResultSpinBox.value()}
self.parent.dataset.save() self.parent.dataset.save()
print('saved dataset') print('saved dataset')
def closeEvent(self, event): def closeEvent(self, event):
for window in [self.expWindow, self.additivePlot, self.importWindow]: for window in [self.expWindow, self.additivePlot, self.importWindow, self.dbWin]:
try: window.close() try: window.close()
except: pass except: pass
self.saveAnalysisResults() self.saveAnalysisResults()
event.accept() event.accept()
class ExportDialog(QtWidgets.QWidget): class ExpExcelDialog(QtWidgets.QWidget):
def __init__(self, parent): def __init__(self, parent):
super(ExportDialog, self).__init__() super(ExpExcelDialog, self).__init__()
self.setWindowTitle('Export Options') self.setWindowTitle('Export Options')