ramanscanui.py 11.6 KB
 Lars Bittrich committed Sep 24, 2018 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ``````# -*- coding: utf-8 -*- """ GEPARD - Gepard-Enabled PARticle Detection Copyright (C) 2018 Lars Bittrich and Josef Brandt, Leibniz-Institut für Polymerforschung Dresden e. V. 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 . """ from PyQt5 import QtCore, QtWidgets import numpy as np `````` Raman committed Dec 03, 2018 24 25 ``````from multiprocessing import Process, Queue, Event import queue `````` Lars Bittrich committed Mar 29, 2019 26 ``````from time import time `````` Hackmet committed Feb 03, 2019 27 ``````from external import tsp `````` Lars Bittrich committed Sep 24, 2018 28 29 ``````import datetime import sys `````` Hackmet committed Feb 06, 2019 30 ``````import os `````` Lars Bittrich committed Sep 24, 2018 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 `````` def reorder(points, N=20): y0, y1 = points[:,1].min(), points[:,1].max() y = np.linspace(y0,y1+.1,N+1) allind = np.arange(points.shape[0]) newind = [] for i, yi in enumerate(y[:-1]): yi1 = y[i+1] indy = allind[(points[:,1]>=yi)&(points[:,1]0: self.prun.setEnabled(True) self.setWindowTitle(str(len(ds.ramanpoints)) + " Particles") @QtCore.pyqtSlot() def stopScan(self): if self.process is not None and self.process.is_alive(): reply = QtWidgets.QMessageBox.question(self, 'Stop raman scan?', "Do you want to terminate the running scan?", QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.No) if reply == QtWidgets.QMessageBox.Yes: `````` Hackmet committed Feb 22, 2019 177 `````` self.ramanctrl.finishMeasurement() `````` Lars Bittrich committed Sep 24, 2018 178 `````` self.timer.stop() `````` Raman committed Dec 03, 2018 179 `````` self.processstopevent.set() `````` Lars Bittrich committed Sep 24, 2018 180 `````` self.process.join() `````` Raman committed Dec 03, 2018 181 182 `````` self.dataqueue.close() self.dataqueue.join_thread() `````` Lars Bittrich committed Sep 24, 2018 183 184 `````` self.view.unblockUI() else: `````` Hackmet committed Feb 26, 2019 185 `````` QtWidgets.QMessageBox.about(self, 'Stopping', 'Stopping without acive process...') `````` Lars Bittrich committed Sep 24, 2018 186 187 188 189 190 191 192 193 194 195 196 197 198 199 `````` return self.close() @QtCore.pyqtSlot() def run(self): if self.dataset.readin: reply = QtWidgets.QMessageBox.critical(self, 'Dataset is newly read from disk!', "Coordinate systems might have changed since. Do you want to continue with saved coordinates?", QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.No) if reply == QtWidgets.QMessageBox.Yes: self.dataset.readin = False else: return `````` Hackmet committed Feb 03, 2019 200 `````` self.view.imparent.ramanSwitch.hide() `````` Hackmet committed Feb 22, 2019 201 202 `````` self.view.setMicroscopeMode() `````` Lars Bittrich committed Sep 24, 2018 203 `````` points = np.asarray(self.dataset.ramanpoints) `````` Hackmet committed Feb 03, 2019 204 205 206 207 208 209 210 `````` ramanSettings = {'filename': self.dataset.name, 'numPoints': len(points), 'path': self.dataset.path} for index, param in enumerate(self.params): try: ramanSettings[self.ramanctrl.ramanParameters[index].name] = self.ramanctrl.ramanParameters[index].value_of(param) except: print(param) `````` Lars Bittrich committed Sep 24, 2018 211 212 213 214 215 216 217 218 219 220 `````` lmin = None for i in range(20,41): c = reorder(points, i) l = np.sum(np.sqrt(np.sum(np.diff(points[c,:],axis=0)**2,axis=1))) if lmin is None or l=0: `````` Lars Bittrich committed Sep 24, 2018 270 271 272 273 274 275 276 277 278 279 `````` self.progressbar.setValue(i+1) self.view.highLightRamanIndex(i+1) Npoints = len(self.dataset.ramanpoints) if i>3: timerunning = time()-self.starttime ttot = timerunning*Npoints/(i+1) time2go = ttot - timerunning self.progresstime.setText(self.timelabeltext + str(datetime.timedelta(seconds=round(time2go)))) if i==Npoints-1: self.process.join() `````` Raman committed Dec 03, 2018 280 281 `````` self.dataqueue.close() self.dataqueue.join_thread() `````` Lars Bittrich committed Sep 24, 2018 282 283 284 `````` self.dataset.ramanscandone = True self.view.saveDataSet() self.view.unblockUI() `````` Hackmet committed Feb 26, 2019 285 ``````# self.view.switchMode("ParticleAnalysis") #directly going to analysis is not feasible... We first have to export spectra etc... `````` Lars Bittrich committed Sep 24, 2018 286 287 288 289 290 `````` self.progressbar.setValue(0) self.progressbar.setEnabled(False) self.progresstime.setEnabled(False) self.close() return `````` Hackmet committed Feb 03, 2019 291 `````` self.timer.start(100.) `````` Lars Bittrich committed Sep 24, 2018 292 `` ``