Commit 0b768ad2 authored by JosefBrandt's avatar JosefBrandt

First phase of refactoring

parent 8fc15b1e
...@@ -53,11 +53,12 @@ class ParticleAnalysis(QtWidgets.QMainWindow): ...@@ -53,11 +53,12 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self.setCentralWidget(self.widget) self.setCentralWidget(self.widget)
self.parent = parent self.parent = parent
self.dataset = dataset
self.particleContainer = dataset.particleContainer
self.datastats = DataStats(dataset) self.datastats = DataStats(dataset)
self.editor = ParticleEditor(self.datastats, self) self.editor = ParticleEditor(self.datastats, self)
self.additivePlot = None # self.additivePlot = None
self.importWindow = None self.importWindow = None
self.polymerCheckBoxes = [] self.polymerCheckBoxes = []
...@@ -67,8 +68,8 @@ class ParticleAnalysis(QtWidgets.QMainWindow): ...@@ -67,8 +68,8 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self.currentSpectrumIndex = 0 self.currentSpectrumIndex = 0
self.lastSpectrumInFocus = None self.lastSpectrumInFocus = None
self.typeHistogram = ParticleTypeView(self) self.typeHistogramPlot = ParticleTypeView(self)
self.typeHistogram.indexClicked.connect(self.getAdditivePlot) # self.typeHistogramPlot.indexClicked.connect(self.getAdditivePlot)
self.sizeHistogramCanvas = FigureCanvas(Figure()) self.sizeHistogramCanvas = FigureCanvas(Figure())
sizeHistGroup = QtWidgets.QGroupBox() sizeHistGroup = QtWidgets.QGroupBox()
...@@ -106,7 +107,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow): ...@@ -106,7 +107,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
splitter1.addWidget(sizeHistGroup) splitter1.addWidget(sizeHistGroup)
splitter2 = QtWidgets.QSplitter(QtCore.Qt.Horizontal) splitter2 = QtWidgets.QSplitter(QtCore.Qt.Horizontal)
splitter2.addWidget(splitter1) splitter2.addWidget(splitter1)
splitter2.addWidget(self.typeHistogram) splitter2.addWidget(self.typeHistogramPlot)
splitter2.setSizes([300, 150]) splitter2.setSizes([300, 150])
self.navigationGroup = QtWidgets.QGroupBox('Navigate through polymers') self.navigationGroup = QtWidgets.QGroupBox('Navigate through polymers')
...@@ -164,32 +165,31 @@ class ParticleAnalysis(QtWidgets.QMainWindow): ...@@ -164,32 +165,31 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self.hqiSpinBox.setValue(75.0) self.hqiSpinBox.setValue(75.0)
self.hqiSpinBox.setDecimals(1) self.hqiSpinBox.setDecimals(1)
self.hqiSpinBox.setMinimum(0) self.hqiSpinBox.setMinimum(0)
self.hqiSpinBox.setMaximum(100)
self.hqiSpinBox.setMaximumWidth(45)
optionsLayout.addRow(QtWidgets.QLabel('min HQI:'), self.hqiSpinBox) optionsLayout.addRow(QtWidgets.QLabel('min HQI:'), self.hqiSpinBox)
self.compHqiSpinBox = QtWidgets.QDoubleSpinBox() # self.compHqiSpinBox = QtWidgets.QDoubleSpinBox()
self.compHqiSpinBox.setValue(30.0) # self.compHqiSpinBox.setValue(30.0)
self.compHqiSpinBox.setDecimals(1) # self.compHqiSpinBox.setDecimals(1)
self.compHqiSpinBox.setMinimum(0) # self.compHqiSpinBox.setMinimum(0)
self.compHqiSpinBox.setDisabled(True) # self.compHqiSpinBox.setDisabled(True)
optionsLayout.addRow(QtWidgets.QLabel('min component HQI'), self.compHqiSpinBox) # optionsLayout.addRow(QtWidgets.QLabel('min component HQI'), self.compHqiSpinBox)
self.dispResultSpinBox = QtWidgets.QSpinBox() self.dispResultSpinBox = QtWidgets.QSpinBox()
self.dispResultSpinBox.setValue(20) self.dispResultSpinBox.setValue(20)
self.dispResultSpinBox.setMinimum(1) self.dispResultSpinBox.setMinimum(1)
self.dispResultSpinBox.valueChanged.connect(self.updateHistogram) self.dispResultSpinBox.valueChanged.connect(self.updateHistograms)
optionsLayout.addRow(QtWidgets.QLabel('Max. items in display:'), self.dispResultSpinBox) optionsLayout.addRow(QtWidgets.QLabel('Max. items in display:'), self.dispResultSpinBox)
for spinbox in [self.hqiSpinBox, self.compHqiSpinBox]:
spinbox.setMaximum(100)
spinbox.setMaximumWidth(45)
self.updateBtn = QtWidgets.QPushButton('Update Results') self.updateBtn = QtWidgets.QPushButton('Update Results')
self.updateBtn.setDisabled(True) self.updateBtn.clicked.connect(self.applyHQIThresholdToResults)
# self.updateBtn.setDisabled(True)
optionsLayout.addRow(self.updateBtn) optionsLayout.addRow(self.updateBtn)
self.optionsGroup.setLayout(optionsLayout) self.optionsGroup.setLayout(optionsLayout)
self.optionsGroup.setMinimumWidth(175) self.optionsGroup.setMinimumWidth(175)
self.optionsGroup.setDisabled(True) # self.optionsGroup.setDisabled(True)
self.resultScrollarea = QtWidgets.QScrollArea(self) self.resultScrollarea = QtWidgets.QScrollArea(self)
self.resultScrollarea.setFixedWidth(250) self.resultScrollarea.setFixedWidth(250)
...@@ -210,25 +210,24 @@ class ParticleAnalysis(QtWidgets.QMainWindow): ...@@ -210,25 +210,24 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self.resultCheckBoxes.setLayout(self.resultCheckBoxesLayout) self.resultCheckBoxes.setLayout(self.resultCheckBoxesLayout)
self.layout_SArea.addWidget(self.resultCheckBoxes) self.layout_SArea.addWidget(self.resultCheckBoxes)
# self.layout_SArea.addStretch(1)
# 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.layout.addLayout(self.menuLayout) self.layout.addLayout(self.menuLayout)
self.layout.addLayout(viewLayout) self.layout.addLayout(viewLayout)
minHQI = self.datastats.dataset.resultParams['minHQI'] minHQI = self.dataset.resultParams['minHQI']
compHQI = self.datastats.dataset.resultParams['compHQI'] # compHQI = self.dataset.resultParams['compHQI']
if minHQI is not None: if minHQI is not None:
self.hqiSpinBox.setValue(minHQI) self.hqiSpinBox.setValue(minHQI)
self.compHqiSpinBox.setValue(compHQI) # self.compHqiSpinBox.setValue(compHQI)
self.createActions() self.createActions()
self.createMenus() self.createMenus()
self.updateData() self.initializeSpectraPlot()
self.applyHQIThresholdToResults()
def createActions(self): def createActions(self):
self.loadTrueMatchAct = QtWidgets.QAction("Load &TrueMatch Results", self) self.loadTrueMatchAct = QtWidgets.QAction("Load &TrueMatch Results", self)
...@@ -241,7 +240,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow): ...@@ -241,7 +240,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self.selOverlayAct = QtWidgets.QAction("&Selected Overlay", self) self.selOverlayAct = QtWidgets.QAction("&Selected Overlay", self)
self.fullOverlayAct = QtWidgets.QAction("&Full Overlay", self) self.fullOverlayAct = QtWidgets.QAction("&Full Overlay", self)
self.transpAct = QtWidgets.QAction("&Transparent Overlay") self.transpAct = QtWidgets.QAction("&Transparent Overlay", self)
self.transpAct.triggered.connect(self.createPolymerOverlay) self.transpAct.triggered.connect(self.createPolymerOverlay)
self.hideLabelAct = QtWidgets.QAction('&Hide Polymer Numbers', self) self.hideLabelAct = QtWidgets.QAction('&Hide Polymer Numbers', self)
...@@ -276,7 +275,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow): ...@@ -276,7 +275,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self.overlayActGroup = QtWidgets.QActionGroup(self.dispMenu) self.overlayActGroup = QtWidgets.QActionGroup(self.dispMenu)
self.overlayActGroup.setExclusive(True) self.overlayActGroup.setExclusive(True)
self.overlayActGroup.triggered.connect(self.createPolymerOverlay) self.overlayActGroup.triggered.connect(self.createPolymerOverlay)
self.overlayActGroup.triggered.connect(self.updateHistogram) self.overlayActGroup.triggered.connect(self.updateHistograms)
for act in [self.noOverlayAct, self.selOverlayAct, self.fullOverlayAct]: for act in [self.noOverlayAct, self.selOverlayAct, self.fullOverlayAct]:
self.dispMenu.addAction(act) self.dispMenu.addAction(act)
...@@ -312,63 +311,62 @@ class ParticleAnalysis(QtWidgets.QMainWindow): ...@@ -312,63 +311,62 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self.refSelector.addItems(self.dbWin.activeDatabase.spectraNames) self.refSelector.addItems(self.dbWin.activeDatabase.spectraNames)
self.refSelector.setDisabled(False) self.refSelector.setDisabled(False)
def updateData(self): def initializeSpectraPlot(self): #formerly updateData(self)....
spectra = self.datastats.update() self.particleContainer.loadSpectraFromDisk()
if spectra is None:
fname = QtWidgets.QFileDialog.getOpenFileName(self, 'Select Spectra File', self.datastats.dataset.path, 'text file (*.txt)')[0]
spectra = self.datastats.loadSpectra(fname)
if spectra is None:
QtWidgets.QMessageBox.critical(self, 'ERROR!', 'spectra file could not be opened with np.loadtxt...')
return
self.specCanvas.draw() self.specCanvas.draw()
self.loadParticleData() # self.loadParticleData()
def loadParticleData(self): # def loadParticleData(self):
#check, if dataset already contains results. Otherwise load them... # #check, if dataset already contains results. Otherwise load them...
if not self.datastats.loadParticleData(): # if not self.datastats.loadParticleData():
self.show() # self.show()
answer = QtWidgets.QMessageBox.question(self, 'Warning', 'No (or inconsistent) spectra results found, please run import dialog.\nPress OK to import or cancel to set to empty.', QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel) # answer = QtWidgets.QMessageBox.question(self, 'Warning', 'No (or inconsistent) spectra results found, please run import dialog.\nPress OK to import or cancel to set to empty.', QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel)
if answer == QtWidgets.QMessageBox.Ok: # if answer == QtWidgets.QMessageBox.Ok:
self.importTrueMatchResults() # self.importTrueMatchResults()
elif answer == QtWidgets.QMessageBox.Cancel: # elif answer == QtWidgets.QMessageBox.Cancel:
self.datastats.invalidateSpectra() # self.datastats.invalidateSpectra()
self.updateBtn.clicked.connect(self.formatResults) # self.updateBtn.clicked.connect(self.formatResults)
self.formatResults() # self.formatResults()
else: # else:
self.updateBtn.clicked.connect(self.formatResults) # self.updateBtn.clicked.connect(self.formatResults)
self.formatResults() # self.formatResults()
def importTrueMatchResults(self): def importTrueMatchResults(self):
self.importWindow = LoadWITecResults(self.datastats, self) self.importWindow = LoadWITecResults(self.datastats, self)
self.importWindow.exec() self.importWindow.exec()
@QtCore.pyqtSlot(int) # @QtCore.pyqtSlot(int)
def getAdditivePlot(self, clickedindex): # def getAdditivePlot(self, clickedindex):
polymer = self.datastats.typehistogram[clickedindex][0] #get the polymer name, that was clicked on # polymer = self.datastats.typehistogram[clickedindex][0] #get the polymer name, that was clicked on
#
if self.datastats.sorted_additives is not None and \ # if self.datastats.sorted_additives is not None and \
len(self.datastats.sorted_additives[clickedindex]) > 0: # len(self.datastats.sorted_additives[clickedindex]) > 0:
self.additivePlot = AdditiveViewer(polymer, self.datastats.sorted_additives[clickedindex]) # self.additivePlot = AdditiveViewer(polymer, self.datastats.sorted_additives[clickedindex])
self.additivePlot.show() # self.additivePlot.show()
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def formatResults(self): def applyHQIThresholdToResults(self):
if self.datastats.spectraResults is not None: self.particleContainer.applyHQITresholdToParticles(self.hqiSpinBox.value())
print('formatResults') self.createHistogramData()
self.updateBtn.setDisabled(False)
self.optionsGroup.setDisabled(False) # def formatResults(self):
# if self.datastats.spectraResults is not None:
self.datastats.formatResults(self.hqiSpinBox.value(), self.compHqiSpinBox.value()) # print('formatResults')
# self.updateBtn.setDisabled(False)
# self.optionsGroup.setDisabled(False)
#
# self.datastats.formatResults(self.hqiSpinBox.value(), self.compHqiSpinBox.value())
#
# if self.datastats.additiveResults is not None:
# self.compHqiSpinBox.setDisabled(False)
if self.datastats.additiveResults is not None:
self.compHqiSpinBox.setDisabled(False)
self.createHistogramData()
def createHistogramData(self): def createHistogramData(self):
if not self.datastats.createHistogramData(): # if not self.datastats.createHistogramData():
QtWidgets.QMessageBox.critical(self, 'Error', 'Inconsistent particle data. Please restore backup!') # QtWidgets.QMessageBox.critical(self, 'Error', 'Inconsistent particle data. Please restore backup!')
return # return
# self.particleContainer.updateTypeHistogram()
###Handle Checkboxes for all polymers... ###Handle Checkboxes for all polymers...
self.menuLayout.removeWidget(self.resultScrollarea) self.menuLayout.removeWidget(self.resultScrollarea)
...@@ -381,7 +379,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow): ...@@ -381,7 +379,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
del i del i
self.showTotalSelector.setParent(None) self.showTotalSelector.setParent(None)
self.showTotalSelector.setDisabled(False) self.showTotalSelector.setDisabled(False)
self.showTotalSelector.stateChanged.connect(self.updateHistogram) self.showTotalSelector.stateChanged.connect(self.updateHistograms)
del self.resultCheckBoxes del self.resultCheckBoxes
del self.resultCheckBoxesLayout del self.resultCheckBoxesLayout
...@@ -391,17 +389,16 @@ class ParticleAnalysis(QtWidgets.QMainWindow): ...@@ -391,17 +389,16 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self.resultScrollarea = QtWidgets.QScrollArea(self) self.resultScrollarea = QtWidgets.QScrollArea(self)
self.resultScrollarea.setFixedWidth(250) self.resultScrollarea.setFixedWidth(250)
self.resultScrollarea.setWidgetResizable(True) self.resultScrollarea.setWidgetResizable(True)
widget = QtWidgets.QWidget() widget = QtWidgets.QWidget()
self.resultScrollarea.setWidget(widget) self.resultScrollarea.setWidget(widget)
self.layout_SArea = QtWidgets.QVBoxLayout(widget) self.layout_SArea = QtWidgets.QVBoxLayout(widget)
self.resultCheckBoxes = QtWidgets.QGroupBox('Show Polymer Types:') self.resultCheckBoxes = QtWidgets.QGroupBox('Show Polymer Types:')
self.resultCheckBoxesLayout = QtWidgets.QVBoxLayout() self.resultCheckBoxesLayout = QtWidgets.QVBoxLayout()
self.resultCheckBoxesLayout.addWidget(self.showTotalSelector) self.resultCheckBoxesLayout.addWidget(self.showTotalSelector)
#generate new checkboxes #generate new checkboxes
self.polymerCheckBoxes = [] self.polymerCheckBoxes = []
uniquePolymers = self.datastats.getUniquePolymers() uniquePolymers = self.particleContainer.getUniquePolymers()
for index, polymer in enumerate(uniquePolymers): for index, polymer in enumerate(uniquePolymers):
self.polymerCheckBoxes.append(QtWidgets.QCheckBox(self)) self.polymerCheckBoxes.append(QtWidgets.QCheckBox(self))
self.polymerCheckBoxes[index].setText(polymer) self.polymerCheckBoxes[index].setText(polymer)
...@@ -409,14 +406,12 @@ class ParticleAnalysis(QtWidgets.QMainWindow): ...@@ -409,14 +406,12 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
if polymer in self.lastSelectedCheckBoxNames: if polymer in self.lastSelectedCheckBoxNames:
self.polymerCheckBoxes[index].setChecked(True) self.polymerCheckBoxes[index].setChecked(True)
self.polymerCheckBoxes[index].stateChanged.connect(self.updateHistogram) self.polymerCheckBoxes[index].stateChanged.connect(self.updateHistograms)
self.polymerCheckBoxes[index].stateChanged.connect(self.createPolymerOverlay) self.polymerCheckBoxes[index].stateChanged.connect(self.createPolymerOverlay)
self.resultCheckBoxesLayout.addStretch() self.resultCheckBoxesLayout.addStretch()
self.resultCheckBoxes.setLayout(self.resultCheckBoxesLayout) self.resultCheckBoxes.setLayout(self.resultCheckBoxesLayout)
self.layout_SArea.addWidget(self.resultCheckBoxes) self.layout_SArea.addWidget(self.resultCheckBoxes)
self.menuLayout.addWidget(self.resultScrollarea) self.menuLayout.addWidget(self.resultScrollarea)
self.expExcelAct.setDisabled(False) self.expExcelAct.setDisabled(False)
...@@ -436,7 +431,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow): ...@@ -436,7 +431,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
else: else:
self.displayNewPolymerType() self.displayNewPolymerType()
self.updateHistogram() self.updateHistograms()
self.createPolymerOverlay() self.createPolymerOverlay()
def exportToExcel(self): def exportToExcel(self):
...@@ -451,7 +446,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow): ...@@ -451,7 +446,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
def updateSpecPlot(self, centerOn=True, highlightContour=True): def updateSpecPlot(self, centerOn=True, highlightContour=True):
#draw Sample Spectrum #draw Sample Spectrum
specIndex = self.currentSpectrumIndex specIndex = self.currentSpectrumIndex
spectra = self.datastats.spectra spectra = self.particleContainer.spectra
particlestats = self.datastats.getParticleStats() particlestats = self.datastats.getParticleStats()
self.spec_ax.axis("on") self.spec_ax.axis("on")
self.spec_ax.clear() self.spec_ax.clear()
...@@ -563,33 +558,29 @@ class ParticleAnalysis(QtWidgets.QMainWindow): ...@@ -563,33 +558,29 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self.currentSpectrumIndex = self.datastats.particles2spectra[self.currentParticleIndex][self.spectrumSelector.value()-1] self.currentSpectrumIndex = self.datastats.particles2spectra[self.currentParticleIndex][self.spectrumSelector.value()-1]
self.updateSpecPlot() self.updateSpecPlot()
def updateHistogram(self): def updateHistograms(self):
self.updateTypeHistogram()
self.updateSizeHistogram()
def updateTypeHistogram(self):
#draw the general histogram #draw the general histogram
colorList = [] colorList = []
abundancyList = [] abundancyList = []
labelList = [] labelList = []
for index, i in enumerate(self.datastats.typehistogram): typeHistogram = self.particleContainer.getTypeHistogram()
for index, polymType in enumerate(typeHistogram):
if not self.selOverlayAct.isChecked() or self.polymerCheckBoxes[index].isChecked(): if not self.selOverlayAct.isChecked() or self.polymerCheckBoxes[index].isChecked():
abundancyList.append(self.datastats.typehistogram[index][1]) abundancyList.append(typeHistogram[polymType])
curColor = self.getColorFromName(self.datastats.typehistogram[index][0]) curColor = self.getColorFromName(polymType)
colorList.append(QtGui.QColor(*curColor)) colorList.append(QtGui.QColor(*curColor))
if self.datastats.sorted_additives is None:
numads = ''
else:
numads = len(np.unique(self.datastats.sorted_additives[index]))
if numads == 0:
numads = ''
else:
numads = '(' + str(numads) + ')'
numpolymers = i[1]
label = ('{} x ' + self.datastats.typehistogram[index][0] + ' {}').format(numpolymers, numads)
labelList.append(label)
print("abundancyList:", abundancyList) # print("abundancyList:", abundancyList)
print("labelList:", labelList) # print("labelList:", labelList)
print("colorList:", colorList) # print("colorList:", colorList)
self.typeHistogram.updateTypes(list(zip(abundancyList, labelList, colorList))) self.typeHistogramPlot.updateTypeHistogram(list(zip(abundancyList, labelList, colorList)))
def updateSizeHistogram(self):
#general size histogram #general size histogram
self.sizeHist_ax.clear() self.sizeHist_ax.clear()
self.sizeHist_ax.axis('on') self.sizeHist_ax.axis('on')
...@@ -648,7 +639,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow): ...@@ -648,7 +639,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
if ok: if ok:
self.datastats.colorSeed = text self.datastats.colorSeed = text
self.datastats.dataset.colorSeed = text self.datastats.dataset.colorSeed = text
self.updateHistogram() self.updateHistograms()
self.createPolymerOverlay() self.createPolymerOverlay()
def getColorFromName(self, name, base255=True): def getColorFromName(self, name, base255=True):
...@@ -673,7 +664,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow): ...@@ -673,7 +664,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
alpha = (128 if self.transpAct.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.datastats.particleResults) colorList = [QtGui.QColor(255, 255, 255, alpha=50)]*len(self.datastats.particleContainer)
legendItems = [] legendItems = []
for index, indexList in enumerate(self.datastats.indices): for index, indexList in enumerate(self.datastats.indices):
......
...@@ -37,7 +37,7 @@ class ExpExcelDialog(QtWidgets.QDialog): ...@@ -37,7 +37,7 @@ class ExpExcelDialog(QtWidgets.QDialog):
self.datastats = datastats self.datastats = datastats
self.particles = self.datastats.getParticleStats() self.particles = self.datastats.getParticleStats()
self.polymers = self.datastats.particleResults self.polymers = self.datastats.particleContainer
self.additives = self.datastats.currentAdditives self.additives = self.datastats.currentAdditives
self.hqis = self.datastats.hqis self.hqis = self.datastats.hqis
...@@ -262,8 +262,8 @@ class ParticleTypeView(QtWidgets.QScrollArea): ...@@ -262,8 +262,8 @@ class ParticleTypeView(QtWidgets.QScrollArea):
self.setAlignment(QtCore.Qt.AlignHCenter) self.setAlignment(QtCore.Qt.AlignHCenter)
self.widgets = [] self.widgets = []
def updateTypes(self, types): def updateTypeHistogram(self, types):
print("Updating polymer type view", flush=True) # print("Updating polymer type view", flush=True)
for pi in self.widgets: for pi in self.widgets:
self.indicatorbox.removeWidget(pi) self.indicatorbox.removeWidget(pi)
pi.setParent(None) pi.setParent(None)
...@@ -277,7 +277,7 @@ class ParticleTypeView(QtWidgets.QScrollArea): ...@@ -277,7 +277,7 @@ class ParticleTypeView(QtWidgets.QScrollArea):
for index, entry in enumerate(types): for index, entry in enumerate(types):
num, text, color = entry num, text, color = entry
print("num, text, color:", num, text, color, flush=True) # print("num, text, color:", num, text, color, flush=True)
pi = ParticleIndicator(num, numtotal, color, text) pi = ParticleIndicator(num, numtotal, color, text)
self.indicatorbox.addWidget(pi) self.indicatorbox.addWidget(pi)
pi.clicked.connect(getIndexFunction(index)) pi.clicked.connect(getIndexFunction(index))
......
...@@ -35,13 +35,16 @@ from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as Navigatio ...@@ -35,13 +35,16 @@ from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as Navigatio
from matplotlib.figure import Figure from matplotlib.figure import Figure
import functools import functools
from scipy.linalg import solveh_banded from scipy.linalg import solveh_banded
from pathlib import Path
class DataBaseWindow(QtWidgets.QMainWindow): class DataBaseWindow(QtWidgets.QMainWindow):
def __init__(self, parent): def __init__(self, parent):
super(DataBaseWindow, self).__init__() super(DataBaseWindow, self).__init__()
self.parent = parent self.parent = parent
self.path = os.path.join(Path.home(), 'gepard', 'databases')
logpath = QtCore.QStandardPaths.writableLocation(
QtCore.QStandardPaths.AppLocalDataLocation)
self.path = os.path.join(logpath, 'databases')
self.importPath = self.path self.importPath = self.path
if not os.path.exists(self.path): if not os.path.exists(self.path):
os.mkdir(self.path) os.mkdir(self.path)
......
...@@ -21,9 +21,186 @@ If not, see <https://www.gnu.org/licenses/>. ...@@ -21,9 +21,186 @@ If not, see <https://www.gnu.org/licenses/>.
import os import os
import numpy as np import numpy as np
import operator import operator
from dataset import loadData, recursiveDictCompare from PyQt5 import QtWidgets
import importSpectra
try:
from dataset import loadData, recursiveDictCompare
print('exported dataset methods from datastats')
except:
print('failed exported dataset methods from datastats')
class ParticleContainer(object):
def __init__(self, parent):
self.parent = parent
self.particles = []
self.spectra = None
self.typeHistogram = None
def initializeParticles(self, numParticles):
self.particles = []
for i in range(numParticles):
self.particles.append(Particle(i))
def loadSpectraFromDisk(self, fname):
try:
self.spectra = self.tryLoadingNumpySpecFile()
except ImportError:
fname = QtWidgets.QFileDialog.getOpenFileName(self.parent, '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
def tryLoadingNumpySpecFile(self):
specPath = self.parent.getSpectraFileName()
if os.path.exists(specPath):