Commit eb5a3c56 authored by Lars Bittrich's avatar Lars Bittrich

new logpath handling; Qt AppLocalDataLocation is now used to obtain an OS...

new logpath handling; Qt AppLocalDataLocation is now used to obtain an OS independent standard path for such information; since this path is needed multiple times it is shared as parameter to all relevant modules and processes
parent 38d7b35f
...@@ -25,17 +25,16 @@ from ramancom.ramancontrol import defaultPath ...@@ -25,17 +25,16 @@ from ramancom.ramancontrol import defaultPath
from ramancom.ramanSwitch import RamanSwitch from ramancom.ramanSwitch import RamanSwitch
from colorlegend import ColorLegend from colorlegend import ColorLegend
import os import os
from pathlib import Path
class MeasureParticleWindow(QtWidgets.QMainWindow): class MeasureParticleWindow(QtWidgets.QMainWindow):
def __init__(self): def __init__(self, logpath):
super(MeasureParticleWindow, self).__init__() super(MeasureParticleWindow, self).__init__()
self.setWindowTitle("GEPARD") self.setWindowTitle("GEPARD")
self.resize(900, 700) self.resize(900, 700)
self.view = SampleView() self.view = SampleView(logpath)
self.view.imparent = self self.view.imparent = self
self.view.ScalingChanged.connect(self.scalingChanged) self.view.ScalingChanged.connect(self.scalingChanged)
self.scalebar = ScaleBar(self) self.scalebar = ScaleBar(self)
...@@ -288,10 +287,15 @@ class MeasureParticleWindow(QtWidgets.QMainWindow): ...@@ -288,10 +287,15 @@ class MeasureParticleWindow(QtWidgets.QMainWindow):
self.addToolBar(QtCore.Qt.LeftToolBarArea, self.toolbar) self.addToolBar(QtCore.Qt.LeftToolBarArea, self.toolbar)
if __name__ == '__main__': if __name__ == '__main__':
import sys import sys
from time import localtime, strftime from time import localtime, strftime
logpath = os.path.join(Path.home(),'gepard')
app = QtWidgets.QApplication(sys.argv)
app.setApplicationName("GEPARD") # appname needed for logpath
logpath = QtCore.QStandardPaths.writableLocation(
QtCore.QStandardPaths.AppLocalDataLocation)
if logpath != "":
if not os.path.exists(logpath): if not os.path.exists(logpath):
os.mkdir(logpath) os.mkdir(logpath)
logname = os.path.join(logpath, 'logfile.txt') logname = os.path.join(logpath, 'logfile.txt')
...@@ -300,9 +304,9 @@ if __name__ == '__main__': ...@@ -300,9 +304,9 @@ if __name__ == '__main__':
sys.stderr = fp sys.stderr = fp
sys.stdout = fp sys.stdout = fp
print("starting GEPARD at: " + strftime("%d %b %Y %H:%M:%S", localtime()), flush=True) print("starting GEPARD at: " + strftime("%d %b %Y %H:%M:%S", localtime()),
sys.stdout.flush() flush=True)
app = QtWidgets.QApplication(sys.argv)
meas = MeasureParticleWindow() meas = MeasureParticleWindow(logpath)
meas.showMaximized() meas.showMaximized()
ret = app.exec_() ret = app.exec_()
\ No newline at end of file
...@@ -27,22 +27,25 @@ from imagestitch import imageStacking ...@@ -27,22 +27,25 @@ from imagestitch import imageStacking
import os import os
import cv2 import cv2
from helperfunctions import cv2imread_fix, cv2imwrite_fix from helperfunctions import cv2imread_fix, cv2imwrite_fix
from time import sleep, time from time import time
import datetime import datetime
import sys import sys
from pathlib import Path
#def scan(path, sol, zpositions, grid, controlclass, connection, ishdr=False): def scan(path, sol, zpositions, grid, controlclass, dataqueue,
def scan(path, sol, zpositions, grid, controlclass, dataqueue, stopevent, ishdr=False): stopevent, logpath='', ishdr=False):
print('starting new optical scan')
sys.stdout.flush()
if ishdr: if ishdr:
merge_mertens = cv2.createMergeMertens() merge_mertens = cv2.createMergeMertens()
logpath = os.path.join(Path.home(),'gepard', 'scanlog.txt') fp = None
with open(logpath, "a") as fp: if logpath != '':
try:
fp = open(os.path.join(logpath, 'scanlog.txt'), 'a')
sys.stderr = fp sys.stderr = fp
sys.stdout = fp sys.stdout = fp
except IOError:
print('separate loging failed', flush=True)
pass
print('starting new optical scan', flush=True)
ramanctrl = controlclass() ramanctrl = controlclass()
ramanctrl.connect() ramanctrl.connect()
...@@ -52,10 +55,10 @@ def scan(path, sol, zpositions, grid, controlclass, dataqueue, stopevent, ishdr= ...@@ -52,10 +55,10 @@ def scan(path, sol, zpositions, grid, controlclass, dataqueue, stopevent, ishdr=
z = sol[0]*x + sol[1]*y + sol[2] z = sol[0]*x + sol[1]*y + sol[2]
for k, zk in (zlist if i%2==0 else zlist[::-1]): for k, zk in (zlist if i%2==0 else zlist[::-1]):
name = f"image_{i}_{k}.bmp" name = f"image_{i}_{k}.bmp"
print("time:", time()) print("time:", time(), flush=True)
zik = z+zk zik = z+zk
assert not np.isnan(zik) assert not np.isnan(zik)
print("moving to:", x, y, zik) print("moving to:", x, y, zik, flush=True)
ramanctrl.moveToAbsolutePosition(x, y, zik) ramanctrl.moveToAbsolutePosition(x, y, zik)
if ishdr: if ishdr:
img_list = [] img_list = []
...@@ -75,6 +78,8 @@ def scan(path, sol, zpositions, grid, controlclass, dataqueue, stopevent, ishdr= ...@@ -75,6 +78,8 @@ def scan(path, sol, zpositions, grid, controlclass, dataqueue, stopevent, ishdr=
return return
dataqueue.put(i) dataqueue.put(i)
ramanctrl.disconnect() ramanctrl.disconnect()
if fp is not None:
fp.close()
def loadAndPasteImage(srcnames, fullimage, fullzval, width, height, def loadAndPasteImage(srcnames, fullimage, fullzval, width, height,
...@@ -212,8 +217,9 @@ class OpticalScan(QtWidgets.QWidget): ...@@ -212,8 +217,9 @@ class OpticalScan(QtWidgets.QWidget):
imageUpdate = QtCore.pyqtSignal(str, name='imageUpdate') #str = 'df' (= darkfield) or 'bf' (=bright field) imageUpdate = QtCore.pyqtSignal(str, name='imageUpdate') #str = 'df' (= darkfield) or 'bf' (=bright field)
boundaryUpdate = QtCore.pyqtSignal() boundaryUpdate = QtCore.pyqtSignal()
def __init__(self, ramanctrl, dataset, parent=None): def __init__(self, ramanctrl, dataset, logpath='', parent=None):
super().__init__(parent, QtCore.Qt.Window) super().__init__(parent, QtCore.Qt.Window)
self.logpath = logpath
self.view = parent self.view = parent
vbox = QtWidgets.QVBoxLayout() vbox = QtWidgets.QVBoxLayout()
pointgroup = QtWidgets.QGroupBox("Point coordinates [µm]", self) pointgroup = QtWidgets.QGroupBox("Point coordinates [µm]", self)
...@@ -508,7 +514,7 @@ class OpticalScan(QtWidgets.QWidget): ...@@ -508,7 +514,7 @@ class OpticalScan(QtWidgets.QWidget):
A = np.ones((points.shape[0],3)) A = np.ones((points.shape[0],3))
A[:,:2] = points[:,:2] A[:,:2] = points[:,:2]
b = points[:,2] b = points[:,2]
sol = np.linalg.lstsq(A,b)[0] sol = np.linalg.lstsq(A, b, rcond=None)[0]
self.dataset.heightmap = sol self.dataset.heightmap = sol
print("Fit deviation:", sol[0]*points[:,0]+sol[1]*points[:,1]+sol[2] -points[:,2] ) print("Fit deviation:", sol[0]*points[:,0]+sol[1]*points[:,1]+sol[2] -points[:,2] )
...@@ -545,7 +551,8 @@ class OpticalScan(QtWidgets.QWidget): ...@@ -545,7 +551,8 @@ class OpticalScan(QtWidgets.QWidget):
self.dataqueue = Queue() self.dataqueue = Queue()
self.process = Process(target=scan, args=(path, sol, self.dataset.zpositions, self.process = Process(target=scan, args=(path, sol, self.dataset.zpositions,
self.dataset.grid, self.ramanctrl.__class__, self.dataset.grid, self.ramanctrl.__class__,
self.dataqueue, self.processstopevent, self.hdrcheck.isChecked())) self.dataqueue, self.processstopevent,
self.logpath, self.hdrcheck.isChecked()))
self.process.start() self.process.start()
self.starttime = time() self.starttime = time()
self.progresstime.setEnabled(True) self.progresstime.setEnabled(True)
...@@ -619,8 +626,10 @@ class OpticalScan(QtWidgets.QWidget): ...@@ -619,8 +626,10 @@ class OpticalScan(QtWidgets.QWidget):
if __name__ == "__main__": if __name__ == "__main__":
from ramancom.simulatedraman import SimulatedRaman from ramancom.simulatedraman import SimulatedRaman
from dataset import DataSet
app = QtWidgets.QApplication(sys.argv) app = QtWidgets.QApplication(sys.argv)
optscan = OpticalScan(SimulatedRaman()) ds = DataSet('Test')
optscan = OpticalScan(SimulatedRaman(), ds)
optscan.show() optscan.show()
sys.exit(app.exec_()) sys.exit(app.exec_())
\ No newline at end of file
...@@ -23,12 +23,11 @@ from PyQt5 import QtCore, QtWidgets ...@@ -23,12 +23,11 @@ from PyQt5 import QtCore, QtWidgets
import numpy as np import numpy as np
from multiprocessing import Process, Queue, Event from multiprocessing import Process, Queue, Event
import queue import queue
from time import sleep, time from time import time
from external import tsp from external import tsp
import datetime import datetime
import sys import sys
import os import os
from pathlib import Path
def reorder(points, N=20): def reorder(points, N=20):
y0, y1 = points[:,1].min(), points[:,1].max() y0, y1 = points[:,1].min(), points[:,1].max()
...@@ -48,27 +47,30 @@ def reorder(points, N=20): ...@@ -48,27 +47,30 @@ 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(ramanSettings, positions, controlclass, dataqueue, stopevent): def scan(ramanSettings, positions, controlclass, dataqueue, stopevent,
logpath = os.path.join(Path.home(),'gepard', 'ramanscanlog.txt') logpath=''):
with open(logpath, "a") as fp: fp = None
if logpath != '':
try:
fp = open(os.path.join(logpath, 'ramanscanlog.txt'), 'a')
sys.stderr = fp sys.stderr = fp
sys.stdout = fp sys.stdout = fp
except IOError:
print('separate loging failed', flush=True)
pass
ramanctrl = controlclass() ramanctrl = controlclass()
ramanctrl.connect() ramanctrl.connect()
print("connected:", time()) print("connected:", time(), flush=True)
ramanctrl.initiateMeasurement(ramanSettings) ramanctrl.initiateMeasurement(ramanSettings)
for i, p in enumerate(positions): for i, p in enumerate(positions):
x, y, z = p x, y, z = p
print("time:", time()) print("time:", time(), flush=True)
print("position:", x, y, z) print("position:", x, y, z, flush=True)
sys.stdout.flush() #remove this line after testing
ramanctrl.moveToAbsolutePosition(x, y, z, measurementRunning=True) ramanctrl.moveToAbsolutePosition(x, y, z, measurementRunning=True)
print("move done") print("move done", flush=True)
sys.stdout.flush()
ramanctrl.triggerMeasurement(i) ramanctrl.triggerMeasurement(i)
print("trigger done") print("trigger done", flush=True)
sys.stdout.flush()
if stopevent.is_set(): if stopevent.is_set():
ramanctrl.disconnect() ramanctrl.disconnect()
...@@ -77,15 +79,17 @@ def scan(ramanSettings, positions, controlclass, dataqueue, stopevent): ...@@ -77,15 +79,17 @@ def scan(ramanSettings, positions, controlclass, dataqueue, stopevent):
dataqueue.put(i) dataqueue.put(i)
ramanctrl.disconnect() ramanctrl.disconnect()
if fp is not None:
fp.close()
class RamanScanUI(QtWidgets.QWidget): class RamanScanUI(QtWidgets.QWidget):
imageUpdate = QtCore.pyqtSignal(str, name='imageUpdate') #str = 'df' (= darkfield) or 'bf' (=bright field) imageUpdate = QtCore.pyqtSignal(str, name='imageUpdate') #str = 'df' (= darkfield) or 'bf' (=bright field)
ramanscanUpdate = QtCore.pyqtSignal() ramanscanUpdate = QtCore.pyqtSignal()
def __init__(self, ramanctrl, dataset, parent=None): def __init__(self, ramanctrl, dataset, logpath='', parent=None):
super().__init__(parent, QtCore.Qt.Window) super().__init__(parent, QtCore.Qt.Window)
self.view = parent self.view = parent
self.logpath = logpath
self.ramanctrl = ramanctrl self.ramanctrl = ramanctrl
self.dataset = dataset self.dataset = dataset
self.process = None self.process = None
...@@ -242,7 +246,11 @@ class RamanScanUI(QtWidgets.QWidget): ...@@ -242,7 +246,11 @@ class RamanScanUI(QtWidgets.QWidget):
self.ramanctrl.disconnect() self.ramanctrl.disconnect()
self.processstopevent = Event() self.processstopevent = Event()
self.dataqueue = Queue() self.dataqueue = Queue()
self.process = Process(target=scan, args=(ramanSettings, scanpoints, self.ramanctrl.__class__, self.dataqueue, self.processstopevent)) self.process = Process(target=scan, args=(ramanSettings, scanpoints,
self.ramanctrl.__class__,
self.dataqueue,
self.processstopevent,
self.logpath))
self.process.start() self.process.start()
self.starttime = time() self.starttime = time()
self.timer = QtCore.QTimer(self) self.timer = QtCore.QTimer(self)
......
...@@ -35,9 +35,10 @@ from ramancom.configRaman import RamanConfigWin ...@@ -35,9 +35,10 @@ from ramancom.configRaman import RamanConfigWin
class SampleView(QtWidgets.QGraphicsView): class SampleView(QtWidgets.QGraphicsView):
ScalingChanged = QtCore.pyqtSignal(float) ScalingChanged = QtCore.pyqtSignal(float)
def __init__(self): def __init__(self, logpath):
super(SampleView, self).__init__() super(SampleView, self).__init__()
self.logpath = logpath
self.item = QtWidgets.QGraphicsPixmapItem() self.item = QtWidgets.QGraphicsPixmapItem()
self.item.setPos(0, 0) self.item.setPos(0, 0)
self.item.setAcceptedMouseButtons(QtCore.Qt.NoButton) self.item.setAcceptedMouseButtons(QtCore.Qt.NoButton)
...@@ -77,9 +78,9 @@ class SampleView(QtWidgets.QGraphicsView): ...@@ -77,9 +78,9 @@ class SampleView(QtWidgets.QGraphicsView):
self.contouritem = SegmentationContours(self) self.contouritem = SegmentationContours(self)
scene.addItem(self.contouritem) scene.addItem(self.contouritem)
self.detectionwidget = None self.detectionwidget = None
self.ramanwidget = RamanScanUI(self.ramanctrl, None, self) self.ramanwidget = RamanScanUI(self.ramanctrl, None, self.logpath, self)
self.ramanwidget.imageUpdate.connect(self.loadPixmap) self.ramanwidget.imageUpdate.connect(self.loadPixmap)
self.oscanwidget = OpticalScan(self.ramanctrl, None, self) self.oscanwidget = OpticalScan(self.ramanctrl, None, self.logpath, self)
self.oscanwidget.imageUpdate.connect(self.loadPixmap) self.oscanwidget.imageUpdate.connect(self.loadPixmap)
self.oscanwidget.boundaryUpdate.connect(self.resetBoundary) self.oscanwidget.boundaryUpdate.connect(self.resetBoundary)
self.analysiswidget = None self.analysiswidget = None
...@@ -194,7 +195,7 @@ class SampleView(QtWidgets.QGraphicsView): ...@@ -194,7 +195,7 @@ class SampleView(QtWidgets.QGraphicsView):
self.ramanwidget.setVisible(False) self.ramanwidget.setVisible(False)
if self.analysiswidget is None: if self.analysiswidget is None:
print('creating new analysiswidget') print('creating new analysiswidget')
self.analysiswidget = ParticleAnalysis(self) self.analysiswidget = ParticleAnalysis(self.dataset, self)
self.analysiswidget.showMaximized() self.analysiswidget.showMaximized()
else: else:
print('show maximized already exisiting analysiswidget') print('show maximized already exisiting analysiswidget')
...@@ -477,7 +478,7 @@ class SampleView(QtWidgets.QGraphicsView): ...@@ -477,7 +478,7 @@ class SampleView(QtWidgets.QGraphicsView):
self.boundaryitems = edges, nodes self.boundaryitems = edges, nodes
self.resetScanPositions() self.resetScanPositions()
@QtCore.pyqtSlot(int, float) @QtCore.pyqtSlot(int, bool)
def selectContour(self, index, centerOn=True): def selectContour(self, index, centerOn=True):
if self.analysiswidget is not None: if self.analysiswidget is not None:
if self.analysiswidget.uniquePolymers is not None: if self.analysiswidget.uniquePolymers is not None:
......
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