Loading analysis/analysisWidgets.py +2 −2 Original line number Diff line number Diff line Loading @@ -63,7 +63,7 @@ class Legend(QtWidgets.QMdiSubWindow): font.setPixelSize(fontSize) fm = QtGui.QFontMetrics(font) pixelwidth = fm.width(text) width, height = pixelwidth + tileSize + 3*spacer, numEntries * (tileSize+1*spacer) + 2*spacer width, height = pixelwidth + tileSize + 4*spacer, numEntries * (fontSize+1*spacer) + spacer return width, height fontSize, tileSize, spacer = self.fontSize, self.tileSize, self.spacer Loading analysis/analysisview.py +8 −25 Original line number Diff line number Diff line Loading @@ -175,18 +175,6 @@ class ParticleAnalysis(QtWidgets.QMainWindow): viewLayout.addWidget(splitter2) viewLayout.setStretch(1, 1) # reloadGroup = QtWidgets.QGroupBox('Reload Results from:') # reloadLayout = QtWidgets.QVBoxLayout() # self.reloadWITec = QtWidgets.QRadioButton('WITec True Match') # self.reloadWITec.setChecked(True) # self.reloadTxt = QtWidgets.QRadioButton('Ordered text file') # reloadBtn = QtWidgets.QPushButton('reload Results') # reloadBtn.clicked.connect(self.importResults) # reloadLayout.addWidget(self.reloadWITec) # reloadLayout.addWidget(self.reloadTxt) # reloadLayout.addWidget(reloadBtn) # reloadGroup.setLayout(reloadLayout) self.optionsGroup = QtWidgets.QGroupBox('Further Options') optionsLayout = QtWidgets.QFormLayout() Loading Loading @@ -338,6 +326,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow): if self.dbWin.activeDatabase is None: self.refSelector.setDisabled(True) else: self.refSelector.addItem('') self.refSelector.addItems(self.dbWin.activeDatabase.spectraNames) self.refSelector.setDisabled(False) Loading Loading @@ -373,10 +362,10 @@ class ParticleAnalysis(QtWidgets.QMainWindow): return specs except: raise return None def updateData(self): print('updating data from', self.parent.dataset.name) self.spectraResults = self.parent.dataset.results['polymers'] self.additiveResults = self.parent.dataset.results['additives'] self.hqis = self.parent.dataset.results['hqis'] Loading @@ -399,13 +388,8 @@ class ParticleAnalysis(QtWidgets.QMainWindow): QtWidgets.QMessageBox.critical(self, 'ERROR!', 'spectra file could not be opened with np.loadtxt...') return self.parent.dataset.spectraPath = fname # self.spec_ax.set_xbound(100, (3400 if self.spectra[-1, 0] > 3400 else self.spectra[-1, 0])) self.specCanvas.draw() ####fake data!!! # if self.spectraResults is None: # self.spectraResults = ['empty']*(self.spectra.shape[1]-1) # self.hqis = [100]*(self.spectra.shape[1]-1) self.loadParticleData() Loading @@ -430,10 +414,9 @@ class ParticleAnalysis(QtWidgets.QMainWindow): #check, if dataset already contains results. Otherwise load them... if self.spectraResults is None or (len(self.spectraResults) != len(sortindices)): self.show() # QtWidgets.QMessageBox.about(self, 'Info', 'No (or inconsistent) spectra results found, please run import dialog.') 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: self.importResults() self.importTrueMatchResults() elif answer == QtWidgets.QMessageBox.Cancel: self.spectraResults = ['empty']*(self.spectra.shape[1]-1) self.hqis = [100]*(self.spectra.shape[1]-1) Loading Loading @@ -879,7 +862,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow): for window in [self.expWindow, self.additivePlot, self.importWindow, self.dbWin]: try: window.close() except: pass self.saveAnalysisResults() self.parent.imparent.particelAnalysisAct.setChecked(False) event.accept() Loading Loading @@ -1054,8 +1037,8 @@ class ExpExcelDialog(QtWidgets.QWidget): QtWidgets.QMessageBox.about(self, 'Done!', 'Particle Data exported') def closeEvent(self, event): if self.sqlExport is not None: self.sqlExport.close() if self.expWin is not None: self.expWin.close() event.accept() Loading analysis/database.py +13 −12 Original line number Diff line number Diff line Loading @@ -144,7 +144,6 @@ class DataBaseWindow(QtWidgets.QMainWindow): self.activeDatabase = self.databases[-1] self.updateDBSelectorList() def addWITecSpectra(self): fnames = QtWidgets.QFileDialog.getOpenFileNames(self, "Select Spectrum File", self.importPath, "*.txt")[0] if fnames: Loading @@ -170,6 +169,7 @@ class DataBaseWindow(QtWidgets.QMainWindow): self.includeSpectrum(addSpectrum, specName) self.updateDBInspector() self.parent.populateRefSelector() def addReniSpectra(self): pass Loading Loading @@ -330,6 +330,8 @@ class DataBaseWindow(QtWidgets.QMainWindow): self.db_selector.setCurrentText(self.activeDatabase.title) def selectDataBase(self, refreshParent=False): # if not self.noDBFound: if len(self.databases) > 0: self.activeDatabaseIndex = self.db_selector.currentIndex() self.activeDatabase = self.databases[self.activeDatabaseIndex] if len(self.activeDatabase.spectra) > 0: Loading Loading @@ -547,7 +549,6 @@ def main(): #start Application app = QtWidgets.QApplication(sys.argv) dbWin = DataBaseWindow(None) # dbWin.showMaximized() app.exec_() Loading analysis/editParticles.py +16 −12 Original line number Diff line number Diff line Loading @@ -39,8 +39,8 @@ class ParticleEditor(object): def createSafetyBackup(self): self.actionCounter += 1 if self.actionCounter == self.backupFreq-1 or self.neverBackedUp: print('backing up') self.parent.parent.dataset.saveBackup() backupname = self.parent.parent.dataset.saveBackup() print('backing up as', backupname) self.neverBackedUp = False self.actionCounter = 0 Loading @@ -54,7 +54,7 @@ class ParticleEditor(object): new_assignment = self.getNewEntry() contourIndices = sorted(contourIndices) #we want to keep the contour with lowest index print('selected contours:', contourIndices) print('merging contours:', contourIndices) self.createSafetyBackup() #get contours: contours = [self.parent.parent.dataset.particlecontours[i] for i in contourIndices] Loading @@ -68,13 +68,16 @@ class ParticleEditor(object): rangex = int(np.round((xmax-xmin)+2*padding)) rangey = int(np.round((ymax-ymin)+2*padding)) for i in range(len(cnt)): cnt[i][0][0] -= xmin-padding cnt[i][0][1] -= ymin-padding img = np.zeros((rangey, rangex)) cv2.drawContours(img, [cnt], 0, 1, -1) cv2.drawContours(img, [cnt], 0, 1, 1) for i in contourIndices: curCnt = self.parent.parent.dataset.particlecontours[i] for i in range(len(curCnt)): curCnt[i][0][0] -= xmin-padding curCnt[i][0][1] -= ymin-padding cv2.drawContours(img, [curCnt], -1, 1, -1) cv2.drawContours(img, [curCnt], -1, 1, 1) img = np.uint8(cv2.morphologyEx(img, cv2.MORPH_CLOSE, np.ones((3, 3)))) temp, contours, hierarchy = cv2.findContours(img, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_NONE) Loading Loading @@ -138,6 +141,7 @@ class ParticleEditor(object): new_assignment = self.getNewEntry() self.createSafetyBackup() print(f'reassigning indices {contourindices} into {new_assignment}') for partIndex in contourindices: for specIndex in self.parent.particles2spectra[partIndex]: self.parent.currentPolymers[specIndex] = new_assignment Loading Loading @@ -176,5 +180,5 @@ class ParticleEditor(object): return long, short, longellipse, shortellipse, cv2.contourArea(cnt) #if __name__ == '__main__': # import No newline at end of file No newline at end of file dataset.py +7 −5 Original line number Diff line number Diff line Loading @@ -295,7 +295,7 @@ class DataSet(object): return os.path.join(self.path, "tmp.bmp") def saveParticleData(self): print('not saving ParticleData into text file..\nThe current output format might be wrong, if multiple spectra per particle are present...') print('Not saving ParticleData into text file...:\nThe current output format might be wrong, if multiple spectra per particle are present...') # if len(self.ramanscansortindex)>0: # data = [] # pixelscale = (self.pixelscale_df if self.imagescanMode == 'df' else self.pixelscale_bf) Loading @@ -315,9 +315,10 @@ class DataSet(object): saveData(self, self.fname) def saveBackup(self): backupNameNotFound = True # backupNameNotFound = True inc = 0 while backupNameNotFound: # while backupNameNotFound: while True: directory = os.path.dirname(self.fname) filename = self.name + '_backup_' + str(inc) + '.pkl' path = os.path.join(directory, filename) Loading @@ -325,7 +326,8 @@ class DataSet(object): inc += 1 else: saveData(self, path) backupNameNotFound = False return filename # backupNameNotFound = False if __name__ == '__main__': Loading Loading
analysis/analysisWidgets.py +2 −2 Original line number Diff line number Diff line Loading @@ -63,7 +63,7 @@ class Legend(QtWidgets.QMdiSubWindow): font.setPixelSize(fontSize) fm = QtGui.QFontMetrics(font) pixelwidth = fm.width(text) width, height = pixelwidth + tileSize + 3*spacer, numEntries * (tileSize+1*spacer) + 2*spacer width, height = pixelwidth + tileSize + 4*spacer, numEntries * (fontSize+1*spacer) + spacer return width, height fontSize, tileSize, spacer = self.fontSize, self.tileSize, self.spacer Loading
analysis/analysisview.py +8 −25 Original line number Diff line number Diff line Loading @@ -175,18 +175,6 @@ class ParticleAnalysis(QtWidgets.QMainWindow): viewLayout.addWidget(splitter2) viewLayout.setStretch(1, 1) # reloadGroup = QtWidgets.QGroupBox('Reload Results from:') # reloadLayout = QtWidgets.QVBoxLayout() # self.reloadWITec = QtWidgets.QRadioButton('WITec True Match') # self.reloadWITec.setChecked(True) # self.reloadTxt = QtWidgets.QRadioButton('Ordered text file') # reloadBtn = QtWidgets.QPushButton('reload Results') # reloadBtn.clicked.connect(self.importResults) # reloadLayout.addWidget(self.reloadWITec) # reloadLayout.addWidget(self.reloadTxt) # reloadLayout.addWidget(reloadBtn) # reloadGroup.setLayout(reloadLayout) self.optionsGroup = QtWidgets.QGroupBox('Further Options') optionsLayout = QtWidgets.QFormLayout() Loading Loading @@ -338,6 +326,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow): if self.dbWin.activeDatabase is None: self.refSelector.setDisabled(True) else: self.refSelector.addItem('') self.refSelector.addItems(self.dbWin.activeDatabase.spectraNames) self.refSelector.setDisabled(False) Loading Loading @@ -373,10 +362,10 @@ class ParticleAnalysis(QtWidgets.QMainWindow): return specs except: raise return None def updateData(self): print('updating data from', self.parent.dataset.name) self.spectraResults = self.parent.dataset.results['polymers'] self.additiveResults = self.parent.dataset.results['additives'] self.hqis = self.parent.dataset.results['hqis'] Loading @@ -399,13 +388,8 @@ class ParticleAnalysis(QtWidgets.QMainWindow): QtWidgets.QMessageBox.critical(self, 'ERROR!', 'spectra file could not be opened with np.loadtxt...') return self.parent.dataset.spectraPath = fname # self.spec_ax.set_xbound(100, (3400 if self.spectra[-1, 0] > 3400 else self.spectra[-1, 0])) self.specCanvas.draw() ####fake data!!! # if self.spectraResults is None: # self.spectraResults = ['empty']*(self.spectra.shape[1]-1) # self.hqis = [100]*(self.spectra.shape[1]-1) self.loadParticleData() Loading @@ -430,10 +414,9 @@ class ParticleAnalysis(QtWidgets.QMainWindow): #check, if dataset already contains results. Otherwise load them... if self.spectraResults is None or (len(self.spectraResults) != len(sortindices)): self.show() # QtWidgets.QMessageBox.about(self, 'Info', 'No (or inconsistent) spectra results found, please run import dialog.') 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: self.importResults() self.importTrueMatchResults() elif answer == QtWidgets.QMessageBox.Cancel: self.spectraResults = ['empty']*(self.spectra.shape[1]-1) self.hqis = [100]*(self.spectra.shape[1]-1) Loading Loading @@ -879,7 +862,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow): for window in [self.expWindow, self.additivePlot, self.importWindow, self.dbWin]: try: window.close() except: pass self.saveAnalysisResults() self.parent.imparent.particelAnalysisAct.setChecked(False) event.accept() Loading Loading @@ -1054,8 +1037,8 @@ class ExpExcelDialog(QtWidgets.QWidget): QtWidgets.QMessageBox.about(self, 'Done!', 'Particle Data exported') def closeEvent(self, event): if self.sqlExport is not None: self.sqlExport.close() if self.expWin is not None: self.expWin.close() event.accept() Loading
analysis/database.py +13 −12 Original line number Diff line number Diff line Loading @@ -144,7 +144,6 @@ class DataBaseWindow(QtWidgets.QMainWindow): self.activeDatabase = self.databases[-1] self.updateDBSelectorList() def addWITecSpectra(self): fnames = QtWidgets.QFileDialog.getOpenFileNames(self, "Select Spectrum File", self.importPath, "*.txt")[0] if fnames: Loading @@ -170,6 +169,7 @@ class DataBaseWindow(QtWidgets.QMainWindow): self.includeSpectrum(addSpectrum, specName) self.updateDBInspector() self.parent.populateRefSelector() def addReniSpectra(self): pass Loading Loading @@ -330,6 +330,8 @@ class DataBaseWindow(QtWidgets.QMainWindow): self.db_selector.setCurrentText(self.activeDatabase.title) def selectDataBase(self, refreshParent=False): # if not self.noDBFound: if len(self.databases) > 0: self.activeDatabaseIndex = self.db_selector.currentIndex() self.activeDatabase = self.databases[self.activeDatabaseIndex] if len(self.activeDatabase.spectra) > 0: Loading Loading @@ -547,7 +549,6 @@ def main(): #start Application app = QtWidgets.QApplication(sys.argv) dbWin = DataBaseWindow(None) # dbWin.showMaximized() app.exec_() Loading
analysis/editParticles.py +16 −12 Original line number Diff line number Diff line Loading @@ -39,8 +39,8 @@ class ParticleEditor(object): def createSafetyBackup(self): self.actionCounter += 1 if self.actionCounter == self.backupFreq-1 or self.neverBackedUp: print('backing up') self.parent.parent.dataset.saveBackup() backupname = self.parent.parent.dataset.saveBackup() print('backing up as', backupname) self.neverBackedUp = False self.actionCounter = 0 Loading @@ -54,7 +54,7 @@ class ParticleEditor(object): new_assignment = self.getNewEntry() contourIndices = sorted(contourIndices) #we want to keep the contour with lowest index print('selected contours:', contourIndices) print('merging contours:', contourIndices) self.createSafetyBackup() #get contours: contours = [self.parent.parent.dataset.particlecontours[i] for i in contourIndices] Loading @@ -68,13 +68,16 @@ class ParticleEditor(object): rangex = int(np.round((xmax-xmin)+2*padding)) rangey = int(np.round((ymax-ymin)+2*padding)) for i in range(len(cnt)): cnt[i][0][0] -= xmin-padding cnt[i][0][1] -= ymin-padding img = np.zeros((rangey, rangex)) cv2.drawContours(img, [cnt], 0, 1, -1) cv2.drawContours(img, [cnt], 0, 1, 1) for i in contourIndices: curCnt = self.parent.parent.dataset.particlecontours[i] for i in range(len(curCnt)): curCnt[i][0][0] -= xmin-padding curCnt[i][0][1] -= ymin-padding cv2.drawContours(img, [curCnt], -1, 1, -1) cv2.drawContours(img, [curCnt], -1, 1, 1) img = np.uint8(cv2.morphologyEx(img, cv2.MORPH_CLOSE, np.ones((3, 3)))) temp, contours, hierarchy = cv2.findContours(img, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_NONE) Loading Loading @@ -138,6 +141,7 @@ class ParticleEditor(object): new_assignment = self.getNewEntry() self.createSafetyBackup() print(f'reassigning indices {contourindices} into {new_assignment}') for partIndex in contourindices: for specIndex in self.parent.particles2spectra[partIndex]: self.parent.currentPolymers[specIndex] = new_assignment Loading Loading @@ -176,5 +180,5 @@ class ParticleEditor(object): return long, short, longellipse, shortellipse, cv2.contourArea(cnt) #if __name__ == '__main__': # import No newline at end of file No newline at end of file
dataset.py +7 −5 Original line number Diff line number Diff line Loading @@ -295,7 +295,7 @@ class DataSet(object): return os.path.join(self.path, "tmp.bmp") def saveParticleData(self): print('not saving ParticleData into text file..\nThe current output format might be wrong, if multiple spectra per particle are present...') print('Not saving ParticleData into text file...:\nThe current output format might be wrong, if multiple spectra per particle are present...') # if len(self.ramanscansortindex)>0: # data = [] # pixelscale = (self.pixelscale_df if self.imagescanMode == 'df' else self.pixelscale_bf) Loading @@ -315,9 +315,10 @@ class DataSet(object): saveData(self, self.fname) def saveBackup(self): backupNameNotFound = True # backupNameNotFound = True inc = 0 while backupNameNotFound: # while backupNameNotFound: while True: directory = os.path.dirname(self.fname) filename = self.name + '_backup_' + str(inc) + '.pkl' path = os.path.join(directory, filename) Loading @@ -325,7 +326,8 @@ class DataSet(object): inc += 1 else: saveData(self, path) backupNameNotFound = False return filename # backupNameNotFound = False if __name__ == '__main__': Loading