# -*- 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 from multiprocessing import Process, Queue, Event import queue from time import sleep, time, localtime, strftime import datetime from externalmodules import tsp import sys 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: self.timer.stop() # self.connection.send("stop") self.processstopevent.set() self.process.join() self.dataqueue.close() self.dataqueue.join_thread() self.view.unblockUI() else: 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 accu = self.accumulationsedit.value() inttime = self.inttimeedit.value() points = np.asarray(self.dataset.ramanpoints) 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: 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() self.dataqueue.close() self.dataqueue.join_thread() self.dataset.ramanscandone = True self.view.saveDataSet() self.view.unblockUI() self.view.switchMode("ParticleAnalysis") self.progressbar.setValue(0) self.progressbar.setEnabled(False) self.progresstime.setEnabled(False) self.close() return self.timer.start(100.)