Commit bddc18b2 authored by Raman's avatar Raman

RamanScanUI also works with the more stable dataqueue setup.

parent 26ef709d
...@@ -208,8 +208,9 @@ class WITecCOM(RamanBase): ...@@ -208,8 +208,9 @@ class WITecCOM(RamanBase):
while distance > epsxy:# and (lastpos is None or lastpos!=curpos): while distance > epsxy:# and (lastpos is None or lastpos!=curpos):
curpos = self.getPosition() curpos = self.getPosition()
distance = max(abs(curpos[0]-x), abs(curpos[1]-y)) distance = max(abs(curpos[0]-x), abs(curpos[1]-y))
if ((time()-t0>0.5) and max(abs(curpos[0]-initpos[0]), abs(curpos[1]-initpos[1]))<epsxy) or (time()-t0>10.): # if ((time()-t0>0.5) and max(abs(curpos[0]-initpos[0]), abs(curpos[1]-initpos[1]))<epsxy) or (time()-t0>10.):
print("WARNING: signal ignored:", time()-t0, x, y, curpos, initpos) if ((time()-t0>2) and max(abs(curpos[0]-initpos[0]), abs(curpos[1]-initpos[1]))<epsxy) or (time()-t0>10.):
print("WARNING: signal ignored; time: {} s, x, y: {}, {}, curPos: {}, initPos: {}".format((time()-t0), x, y, curpos, initpos))
sys.stdout.flush() sys.stdout.flush()
break break
sleep(.01) sleep(.01)
......
...@@ -24,6 +24,10 @@ import cv2 ...@@ -24,6 +24,10 @@ import cv2
import os import os
def cv2imread_fix(fname, flags=cv2.IMREAD_COLOR): def cv2imread_fix(fname, flags=cv2.IMREAD_COLOR):
if not os.path.exists(fname): #This seems to be a source of potential errors. Having these lines here probably aids finding errors for other groups?
print('Error, image file not found\Please check if the used save-Image command returns before the image was fully written to disk.')
return
with open(fname, "rb") as fp: with open(fname, "rb") as fp:
cont = fp.read() cont = fp.read()
img = cv2.imdecode(np.fromstring(cont, dtype=np.uint8), flags) img = cv2.imdecode(np.fromstring(cont, dtype=np.uint8), flags)
......
...@@ -21,10 +21,11 @@ If not, see <https://www.gnu.org/licenses/>. ...@@ -21,10 +21,11 @@ If not, see <https://www.gnu.org/licenses/>.
from PyQt5 import QtCore, QtWidgets from PyQt5 import QtCore, QtWidgets
import numpy as np import numpy as np
from multiprocessing import Process, Pipe from multiprocessing import Process, Queue, Event
from time import sleep, time import queue
from externalmodules import tsp from time import sleep, time, localtime, strftime
import datetime import datetime
from externalmodules import tsp
import sys import sys
def reorder(points, N=20): def reorder(points, N=20):
...@@ -45,7 +46,8 @@ def reorder(points, N=20): ...@@ -45,7 +46,8 @@ def reorder(points, N=20):
assert np.unique(newind).shape[0]==allind.shape[0] assert np.unique(newind).shape[0]==allind.shape[0]
return newind return newind
def scan(name, accu, inttime, positions, controlclass, connection): def scan(name, accu, inttime, positions, controlclass, dataqueue, stopevent):
with open("ramanscanlog.txt", "a") as fp: with open("ramanscanlog.txt", "a") as fp:
sys.stderr = fp sys.stderr = fp
sys.stdout = fp sys.stdout = fp
...@@ -53,22 +55,20 @@ def scan(name, accu, inttime, positions, controlclass, connection): ...@@ -53,22 +55,20 @@ def scan(name, accu, inttime, positions, controlclass, connection):
ramanctrl = controlclass() ramanctrl = controlclass()
ramanctrl.connect() ramanctrl.connect()
ramanctrl.initiateTimeSeriesScan(name, len(positions), accu, inttime) ramanctrl.initiateTimeSeriesScan(name, len(positions), accu, inttime)
print("starting Raman Scan at: " + strftime("%d %b %Y %H:%M:%S", localtime()))
for i, p in enumerate(positions): for i, p in enumerate(positions):
x, y, z = p x, y, z = p
print("time:", time())
print("position:", x, y, z) print('Measuring particle index {} at location {}, time = {}'.format(i, (x, y, z), strftime("%H:%M:%S", localtime())))
sys.stdout.flush() #remove after testing
ramanctrl.moveToAbsolutePosition(x, y, z) ramanctrl.moveToAbsolutePosition(x, y, z)
ramanctrl.nextTimeSeriesScan(i) ramanctrl.nextTimeSeriesScan(i)
if connection.poll():
instruction = connection.recv() if stopevent.is_set():
if instruction=="stop":
ramanctrl.disconnect() ramanctrl.disconnect()
return return
connection.send(i) dataqueue.put(i)
ramanctrl.disconnect() ramanctrl.disconnect()
while not connection.poll():
sleep(.1)
connection.recv()
class RamanScanUI(QtWidgets.QWidget): class RamanScanUI(QtWidgets.QWidget):
imageUpdate = QtCore.pyqtSignal(name='imageUpdate') imageUpdate = QtCore.pyqtSignal(name='imageUpdate')
...@@ -148,8 +148,11 @@ class RamanScanUI(QtWidgets.QWidget): ...@@ -148,8 +148,11 @@ class RamanScanUI(QtWidgets.QWidget):
QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.No) QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.No)
if reply == QtWidgets.QMessageBox.Yes: if reply == QtWidgets.QMessageBox.Yes:
self.timer.stop() self.timer.stop()
self.connection.send("stop") # self.connection.send("stop")
self.processstopevent.set()
self.process.join() self.process.join()
self.dataqueue.close()
self.dataqueue.join_thread()
self.view.unblockUI() self.view.unblockUI()
else: else:
return return
...@@ -205,9 +208,9 @@ class RamanScanUI(QtWidgets.QWidget): ...@@ -205,9 +208,9 @@ class RamanScanUI(QtWidgets.QWidget):
self.progressbar.setRange(0, len(scanpoints)) self.progressbar.setRange(0, len(scanpoints))
self.progressbar.setValue(0) self.progressbar.setValue(0)
self.ramanctrl.disconnect() self.ramanctrl.disconnect()
parent_conn, child_conn = Pipe() self.processstopevent = Event()
self.connection = parent_conn self.dataqueue = Queue()
self.process = Process(target=scan, args=(self.dataset.name, accu, inttime, scanpoints, self.ramanctrl.__class__, child_conn)) self.process = Process(target=scan, args=(self.dataset.name, accu, inttime, scanpoints, self.ramanctrl.__class__, self.dataqueue, self.processstopevent))
self.process.start() self.process.start()
self.starttime = time() self.starttime = time()
self.timer = QtCore.QTimer(self) self.timer = QtCore.QTimer(self)
...@@ -217,8 +220,11 @@ class RamanScanUI(QtWidgets.QWidget): ...@@ -217,8 +220,11 @@ class RamanScanUI(QtWidgets.QWidget):
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def checkOnScan(self): def checkOnScan(self):
if self.connection.poll(): try:
i = self.connection.recv() i = self.dataqueue.get_nowait()
except queue.Empty:
i = -1
if i >= 0:
self.progressbar.setValue(i+1) self.progressbar.setValue(i+1)
self.view.highLightRamanIndex(i+1) self.view.highLightRamanIndex(i+1)
Npoints = len(self.dataset.ramanpoints) Npoints = len(self.dataset.ramanpoints)
...@@ -228,9 +234,9 @@ class RamanScanUI(QtWidgets.QWidget): ...@@ -228,9 +234,9 @@ class RamanScanUI(QtWidgets.QWidget):
time2go = ttot - timerunning time2go = ttot - timerunning
self.progresstime.setText(self.timelabeltext + str(datetime.timedelta(seconds=round(time2go)))) self.progresstime.setText(self.timelabeltext + str(datetime.timedelta(seconds=round(time2go))))
if i==Npoints-1: if i==Npoints-1:
self.connection.send("stop")
self.process.join() self.process.join()
self.connection.close() self.dataqueue.close()
self.dataqueue.join_thread()
self.dataset.ramanscandone = True self.dataset.ramanscandone = True
self.view.saveDataSet() self.view.saveDataSet()
self.view.unblockUI() self.view.unblockUI()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment