Commit 3a33998f authored by Martin Drechsler's avatar Martin Drechsler

Tested with zyla connected, it works. Also, saving and loading added to controlGui.

parent 75027243
...@@ -17,9 +17,6 @@ from zylaCameraWorker import CameraWorker ...@@ -17,9 +17,6 @@ from zylaCameraWorker import CameraWorker
from subclasses.cameraParameterTree import CameraParameterTree from subclasses.cameraParameterTree import CameraParameterTree
from subclasses.controllayouts import LaserControlLayout, LaserScanLayout from subclasses.controllayouts import LaserControlLayout, LaserScanLayout
from resources.scanFunctions import create_measurement_array from resources.scanFunctions import create_measurement_array
#from drivers.andorzyla import AndorZyla
from drivers.dummyAndor import AndorZyla
from measurement import MeasurementFrame from measurement import MeasurementFrame
import sys import sys
import numpy as np import numpy as np
...@@ -71,6 +68,7 @@ class CameraGuiMainWindow(QMainWindow): ...@@ -71,6 +68,7 @@ class CameraGuiMainWindow(QMainWindow):
self.measurementFrame = MeasurementFrame() self.measurementFrame = MeasurementFrame()
self.dMeasurement.addWidget(self.measurementFrame) self.dMeasurement.addWidget(self.measurementFrame)
# button spinbox and label # button spinbox and label
self.cameraButton = QPushButton("Start Acquisition") self.cameraButton = QPushButton("Start Acquisition")
self.isCameraAcquiring = False self.isCameraAcquiring = False
...@@ -136,7 +134,8 @@ class CameraGuiMainWindow(QMainWindow): ...@@ -136,7 +134,8 @@ class CameraGuiMainWindow(QMainWindow):
self.cameraButton.clicked.connect(self.camera_button_pressed) self.cameraButton.clicked.connect(self.camera_button_pressed)
self.console = console.ConsoleWidget( self.console = console.ConsoleWidget(
namespace = {'np': np, 'cam': backend.cam, 'roi': self.rois[0]} namespace = {'np': np, 'cam': backend.cam, 'roi': self.rois[0], 'storage': backend.storage
}
) )
self.dConsole.addWidget(self.console) self.dConsole.addWidget(self.console)
...@@ -146,9 +145,10 @@ class CameraGuiMainWindow(QMainWindow): ...@@ -146,9 +145,10 @@ class CameraGuiMainWindow(QMainWindow):
self.measurementFrame.startValue.valueChanged.connect(self.measurementFrame.update_tree) self.measurementFrame.startValue.valueChanged.connect(self.measurementFrame.update_tree)
self.measurementFrame.endValue.valueChanged.connect(self.measurementFrame.update_tree) self.measurementFrame.endValue.valueChanged.connect(self.measurementFrame.update_tree)
self.measurementFrame.stepsNum.valueChanged.connect(self.measurementFrame.update_tree) self.measurementFrame.stepsNum.valueChanged.connect(self.measurementFrame.update_tree)
self.measurementFrame.saveMeasureButton.clicked.connect(
lambda: self.measurementFrame.saveMeasureButton.setEnabled(False)
)
def camera_button_pressed(self): def camera_button_pressed(self):
if self.isCameraAcquiring: if self.isCameraAcquiring:
...@@ -208,7 +208,9 @@ class CameraGuiMainWindow(QMainWindow): ...@@ -208,7 +208,9 @@ class CameraGuiMainWindow(QMainWindow):
new_sx, new_sy = new_size/old_size * sx, new_size/old_size * sy new_sx, new_sy = new_size/old_size * sx, new_size/old_size * sy
roi.setPos([new_x, new_y]) roi.setPos([new_x, new_y])
roi.setSize([new_sx, new_sy]) roi.setSize([new_sx, new_sy])
self.current_image_size = new_size
@QtCore.pyqtSlot(np.ndarray, int) @QtCore.pyqtSlot(np.ndarray, int)
def updateImage(self, image, acq_index): def updateImage(self, image, acq_index):
if self.frame_index is not 0 and not self.frame_index == acq_index: if self.frame_index is not 0 and not self.frame_index == acq_index:
...@@ -220,7 +222,7 @@ class CameraGuiMainWindow(QMainWindow): ...@@ -220,7 +222,7 @@ class CameraGuiMainWindow(QMainWindow):
self.img.setImage(image, autoDownsample=True) self.img.setImage(image, autoDownsample=True)
self.updatePlots() self.updatePlots()
self.frame_index = self.frame_index + 1 self.frame_index = self.frame_index + 1
self.current_image_size = image.shape[0]
def frame_counter(self): def frame_counter(self):
self.counter = self.counter + 1 self.counter = self.counter + 1
...@@ -257,6 +259,7 @@ class CameraGuiMainWindow(QMainWindow): ...@@ -257,6 +259,7 @@ class CameraGuiMainWindow(QMainWindow):
def measurement_ending(self): def measurement_ending(self):
self.cameraButton.setEnabled(True) self.cameraButton.setEnabled(True)
self.measurementFrame.startMeasureButton.setEnabled(True) self.measurementFrame.startMeasureButton.setEnabled(True)
self.measurementFrame.saveMeasureButton.setEnabled(True)
self.isMeasuring = False self.isMeasuring = False
for l in LaserControlLayout._registry + LaserScanLayout._registry : for l in LaserControlLayout._registry + LaserScanLayout._registry :
l.unfreeze() l.unfreeze()
......
...@@ -10,123 +10,133 @@ import sys ...@@ -10,123 +10,133 @@ import sys
from PyQt5 import QtGui, QtCore from PyQt5 import QtGui, QtCore
import qdarkstyle import qdarkstyle
import os import os
from PyQt5.QtWidgets import QLabel
os.environ['PYQTGRAPH_QT_LIB'] = 'PyQt5' os.environ['PYQTGRAPH_QT_LIB'] = 'PyQt5'
from subclasses.controllayouts import LaserControlLayout from subclasses.controllayouts import LaserControlLayout
from subclasses.controllayouts import LaserScanLayout from subclasses.controllayouts import LaserScanLayout
from resources.myToolbar import myToolbarMenu
from pyqtgraph import dockarea from pyqtgraph import dockarea
from MCDAQcontrolsignals import anal_control_signal from MCDAQcontrolsignals import anal_control_signal
from MCDAQcontrolsignals import digital_control_signal from MCDAQcontrolsignals import digital_control_signal
class ControlGui(QtGui.QFrame): class ControlGui(QtGui.QFrame):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self.initUI() self.initUI()
def initUI(self): def initUI(self):
self.area = dockarea.DockArea() self.menuBar = QtGui.QMenuBar(self)
self.grid = QtGui.QGridLayout() self.area = dockarea.DockArea()
self.grid.addWidget(self.area, 0, 0) self.grid = QtGui.QGridLayout()
self.setLayout(self.grid) self.grid.addWidget(QLabel(' '), 0, 1)
self.grid.addWidget(self.area, 1, 0)
self.dock_397 = dockarea.Dock('397', (100, 100)) self.grid.setSpacing(0)
self.dock_866 = dockarea.Dock('866', (100, 100)) self.setLayout(self.grid)
self.dock_423 = dockarea.Dock('423', (100, 100))
self.dock_397_scan = dockarea.Dock('397 scan', (100, 100)) self.dock_397 = dockarea.Dock('397', (100, 100))
self.dock_866_scan = dockarea.Dock('866 scan', (100, 100)) self.dock_866 = dockarea.Dock('866', (100, 100))
self.dock_423_scan = dockarea.Dock('423 scan', (100, 100)) self.dock_423 = dockarea.Dock('423', (100, 100))
self.dock_397_scan = dockarea.Dock('397 scan', (100, 100))
self.dock_electrodes = dockarea.Dock('dcElectrodes', (100, 100)) self.dock_866_scan = dockarea.Dock('866 scan', (100, 100))
self.dock_423_scan = dockarea.Dock('423 scan', (100, 100))
self.area.addDock(self.dock_electrodes)
self.area.addDock(self.dock_397, 'bottom', self.dock_electrodes) self.dock_electrodes = dockarea.Dock('dcElectrodes', (100, 100))
self.area.addDock(self.dock_866, 'bottom', self.dock_397)
self.area.addDock(self.dock_423, 'bottom', self.dock_866) self.area.addDock(self.dock_electrodes)
self.area.addDock(self.dock_397_scan, 'right', self.dock_397) self.area.addDock(self.dock_397, 'bottom', self.dock_electrodes)
self.area.addDock(self.dock_866_scan, 'right', self.dock_866) self.area.addDock(self.dock_866, 'bottom', self.dock_397)
self.area.addDock(self.dock_423_scan, 'right', self.dock_423) self.area.addDock(self.dock_423, 'bottom', self.dock_866)
self.area.addDock(self.dock_397_scan, 'right', self.dock_397)
self.area.addDock(self.dock_866_scan, 'right', self.dock_866)
self.area.addDock(self.dock_423_scan, 'right', self.dock_423)
self.laser397_control_layout = LaserControlLayout('397', checkboxes=['shutter397'], spinboxes = ['piezoA397', 'piezoB397'])
self.laser397_scan_layout = LaserScanLayout(name='piezoA397', signal_to_scan_layout=self.laser397_control_layout)
self.dock_397.addWidget(self.laser397_control_layout, 0, 0)
self.dock_397_scan.addWidget(self.laser397_scan_layout, 0, 1) self.laser397_control_layout = LaserControlLayout('397', checkboxes=['shutter397'], spinboxes = ['piezoA397', 'piezoB397'])
self.laser397_scan_layout = LaserScanLayout(name='piezoA397', signal_to_scan_layout=self.laser397_control_layout)
self.laser866_control_layout = LaserControlLayout('866', checkboxes=['shutter866', 'shuter866WM'], spinboxes = ['piezoA866', 'piezoB866']) self.dock_397.addWidget(self.laser397_control_layout, 0, 0)
self.laser866_scan_layout = LaserScanLayout(name='piezoA866', signal_to_scan_layout=self.laser866_control_layout) self.dock_397_scan.addWidget(self.laser397_scan_layout, 0, 1)
self.dock_866.addWidget(self.laser866_control_layout)
self.dock_866_scan.addWidget(self.laser866_scan_layout) self.laser866_control_layout = LaserControlLayout('866', checkboxes=['shutter866', 'shuter866WM'], spinboxes = ['piezoA866', 'piezoB866'])
self.laser866_scan_layout = LaserScanLayout(name='piezoA866', signal_to_scan_layout=self.laser866_control_layout)
self.laser423_control_layout = LaserControlLayout('423', checkboxes=['shutter423'], spinboxes = ['piezo423']) self.dock_866.addWidget(self.laser866_control_layout)
self.laser423_scan_layout = LaserScanLayout(name='piezo423', signal_to_scan_layout=self.laser423_control_layout) self.dock_866_scan.addWidget(self.laser866_scan_layout)
self.dock_423.addWidget(self.laser423_control_layout)
self.dock_423_scan.addWidget(self.laser423_scan_layout) self.laser423_control_layout = LaserControlLayout('423', checkboxes=['shutter423'], spinboxes = ['piezo423'])
self.laser423_scan_layout = LaserScanLayout(name='piezo423', signal_to_scan_layout=self.laser423_control_layout)
self.electrodes_control_layout = LaserControlLayout('electrodes', checkboxes=[], spinboxes = ['dcA', 'dcB', 'compC', 'compD', 'compOven', 'compExYb'], custom_geometry=True) self.dock_423.addWidget(self.laser423_control_layout)
self.dock_electrodes.addWidget(self.electrodes_control_layout) self.dock_423_scan.addWidget(self.laser423_scan_layout)
self.electrodes_control_layout.addWidget(QtGui.QLabel('dcA'), 0, 0) self.electrodes_control_layout = LaserControlLayout('electrodes', checkboxes=[], spinboxes = ['dcA', 'dcB', 'compC', 'compD', 'compOven', 'compExYb'], custom_geometry=True)
self.electrodes_control_layout.addWidget(self.electrodes_control_layout.spinboxes['dcA'], 0, 1) self.dock_electrodes.addWidget(self.electrodes_control_layout)
self.electrodes_control_layout.addWidget(QtGui.QLabel('dcB'), 1, 0)
self.electrodes_control_layout.addWidget(self.electrodes_control_layout.spinboxes['dcB'], 1, 1) self.electrodes_control_layout.addWidget(QtGui.QLabel('dcA'), 0, 0)
self.electrodes_control_layout.addWidget(QtGui.QLabel('compC'), 0, 2) self.electrodes_control_layout.addWidget(self.electrodes_control_layout.spinboxes['dcA'], 0, 1)
self.electrodes_control_layout.addWidget(self.electrodes_control_layout.spinboxes['compC'], 0, 3) self.electrodes_control_layout.addWidget(QtGui.QLabel('dcB'), 1, 0)
self.electrodes_control_layout.addWidget(QtGui.QLabel('compD'), 1, 2) self.electrodes_control_layout.addWidget(self.electrodes_control_layout.spinboxes['dcB'], 1, 1)
self.electrodes_control_layout.addWidget(self.electrodes_control_layout.spinboxes['compD'], 1, 3) self.electrodes_control_layout.addWidget(QtGui.QLabel('compC'), 0, 2)
self.electrodes_control_layout.addWidget(QtGui.QLabel('compOven'), 0, 4) self.electrodes_control_layout.addWidget(self.electrodes_control_layout.spinboxes['compC'], 0, 3)
self.electrodes_control_layout.addWidget(self.electrodes_control_layout.spinboxes['compOven'], 0, 5) self.electrodes_control_layout.addWidget(QtGui.QLabel('compD'), 1, 2)
self.electrodes_control_layout.addWidget(QtGui.QLabel('compExYb'), 1, 4) self.electrodes_control_layout.addWidget(self.electrodes_control_layout.spinboxes['compD'], 1, 3)
self.electrodes_control_layout.addWidget(self.electrodes_control_layout.spinboxes['compExYb'], 1, 5) self.electrodes_control_layout.addWidget(QtGui.QLabel('compOven'), 0, 4)
self.electrodes_control_layout.addWidget(self.electrodes_control_layout.spinboxes['compOven'], 0, 5)
self.electrodes_control_layout.addWidget(QtGui.QLabel('compExYb'), 1, 4)
self.electrodes_control_layout.addWidget(self.electrodes_control_layout.spinboxes['compExYb'], 1, 5)
self.show()
self.toolbar = myToolbarMenu(self)
def make_connections(self, backend): self.toolbar.load('config.ini')
# external connections self.autosave_timer = QtCore.QTimer()
scan_layout_list = [scan_layout for scan_layout in LaserScanLayout._registry if scan_layout.name == backend.name] self.autosave_timer.timeout.connect(lambda: self.toolbar.save('config.ini'))
for scan_layout in scan_layout_list: self.autosave_timer.start(10000)
scan_layout.scanActionSignal.connect(backend.scan_action)
backend.scanStepSignal.connect(scan_layout.scan_step) self.show()
backend.scanEndSignal.connect(scan_layout.scan_end)
def make_connections(self, backend):
# external connections
scan_layout_list = [scan_layout for scan_layout in LaserScanLayout._registry if scan_layout.name == backend.name]
for scan_layout in scan_layout_list:
scan_layout.scanActionSignal.connect(backend.scan_action)
backend.scanStepSignal.connect(scan_layout.scan_step)
backend.scanEndSignal.connect(scan_layout.scan_end)
if __name__ == '__main__': if __name__ == '__main__':
app = QtGui.QApplication([]) app = QtGui.QApplication([])
controlGui = ControlGui() controlGui = ControlGui()
piezoA397 = anal_control_signal('piezoA397', channel=0, ao_type='cavity_piezo', out_minimum = 0, out_maximum = 4) piezoA397 = anal_control_signal('piezoA397', channel=0, ao_type='cavity_piezo', out_minimum = 0, out_maximum = 4)
piezoB397 = anal_control_signal('piezoB397', channel=1, ao_type='cavity_piezo') piezoB397 = anal_control_signal('piezoB397', channel=1, ao_type='cavity_piezo')
piezoA866 = anal_control_signal('piezoA866', channel=2, ao_type='cavity_piezo', out_minimum = 0, out_maximum = 4) piezoA866 = anal_control_signal('piezoA866', channel=2, ao_type='cavity_piezo', out_minimum = 0, out_maximum = 4)
piezoB866 = anal_control_signal('piezoB866', channel=3, ao_type='cavity_piezo') piezoB866 = anal_control_signal('piezoB866', channel=3, ao_type='cavity_piezo')
piezo423 = anal_control_signal('piezo423', channel=4, ao_type='laser_piezo') piezo423 = anal_control_signal('piezo423', channel=4, ao_type='laser_piezo')
trapDCA = anal_control_signal('dcA', channel = 5, ao_type='electrode') trapDCA = anal_control_signal('dcA', channel = 5, ao_type='electrode')
trapDCB = anal_control_signal('dcB', channel = 6, ao_type='electrode') trapDCB = anal_control_signal('dcB', channel = 6, ao_type='electrode')
trapCOMPC = anal_control_signal('compC', channel = 7, ao_type='electrode') trapCOMPC = anal_control_signal('compC', channel = 7, ao_type='electrode')
trapCOMPD = anal_control_signal('compD', channel = 8, ao_type='electrode') trapCOMPD = anal_control_signal('compD', channel = 8, ao_type='electrode')
trapOven = anal_control_signal('compOven', channel = 9, ao_type='electrode') trapOven = anal_control_signal('compOven', channel = 9, ao_type='electrode')
trapExYb = anal_control_signal('compExYb', channel = 10, ao_type='electrode') trapExYb = anal_control_signal('compExYb', channel = 10, ao_type='electrode')
shutter866 = digital_control_signal('shutter866', channel = 0) shutter866 = digital_control_signal('shutter866', channel = 0)
shutter397 = digital_control_signal('shutter397', channel = 1) shutter397 = digital_control_signal('shutter397', channel = 1)
shutter423 = digital_control_signal('shutter423', channel = 2) shutter423 = digital_control_signal('shutter423', channel = 2)
shutter866WM = digital_control_signal('shutter866WM', channel = 3) shutter866WM = digital_control_signal('shutter866WM', channel = 3)
mcDAQthread = QtCore.QThread() mcDAQthread = QtCore.QThread()
for ao in anal_control_signal._registry: for ao in anal_control_signal._registry:
controlGui.make_connections(ao) controlGui.make_connections(ao)
ao.make_connections(controlGui) ao.make_connections(controlGui)
ao.moveToThread(mcDAQthread) ao.moveToThread(mcDAQthread)
ao.scanTimer.moveToThread(mcDAQthread) ao.scanTimer.moveToThread(mcDAQthread)
ao.scanTimer.timeout.connect(ao.scan_event) ao.scanTimer.timeout.connect(ao.scan_event)
for do in digital_control_signal._registry: for do in digital_control_signal._registry:
do.make_connections(controlGui) do.make_connections(controlGui)
do.moveToThread(mcDAQthread) do.moveToThread(mcDAQthread)
mcDAQthread.start() mcDAQthread.start()
sys.exit(app.exec_()) sys.exit(app.exec_())
\ No newline at end of file \ No newline at end of file
...@@ -792,7 +792,7 @@ class AndorBase(SDK3Camera): ...@@ -792,7 +792,7 @@ class AndorBase(SDK3Camera):
self.acq_index_i = self.acq_index_i + 1 self.acq_index_i = self.acq_index_i + 1
print('stopping acq loop thread') print('stopping acq loop thread')
def _convert_buffer_12(self, buf): def _convert_buffer_12(self, buf):
import itertools import itertools
xs, ys = self.GetPicWidth(), self.GetPicHeight() xs, ys = self.GetPicWidth(), self.GetPicHeight()
...@@ -843,6 +843,10 @@ class AndorZyla(AndorBase): ...@@ -843,6 +843,10 @@ class AndorZyla(AndorBase):
AndorBase.__init__(self,camNum) AndorBase.__init__(self,camNum)
def trigger(self):
self.SoftwareTrigger()
class AndorSim(AndorBase): class AndorSim(AndorBase):
def __init__(self, camNum): def __init__(self, camNum):
#define properties #define properties
......
from PyQt5 import QtGui, QtCore from PyQt5 import QtGui, QtCore
#from drivers.andorzyla import AndorZyla #from drivers.andorzyla import AndorZyla
#from drivers.andorzyla import AndorZyla
from drivers.dummyAndor import AndorZyla from drivers.dummyAndor import AndorZyla
from cameraGui import CameraGuiMainWindow from cameraGui import CameraGuiMainWindow
......
...@@ -13,127 +13,126 @@ from PyQt5.QtCore import QSettings ...@@ -13,127 +13,126 @@ from PyQt5.QtCore import QSettings
from PyQt5.QtWidgets import QAction, QFileDialog, QInputDialog, QWidget from PyQt5.QtWidgets import QAction, QFileDialog, QInputDialog, QWidget
from measurement_ui import Ui_Frame from measurement_ui import Ui_Frame
from MCDAQcontrolsignals import anal_control_signal from MCDAQcontrolsignals import anal_control_signal
from subclasses.controllayouts import LaserControlLayout, LaserScanLayout
from resources.scanFunctions import create_measurement_array, yield_array
import time
class MeasurementFrame(QtWidgets.QFrame, Ui_Frame): class MeasurementFrame(QtWidgets.QFrame, Ui_Frame):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self.setupUi(self) self.setupUi(self)
for ao in anal_control_signal._registry: for ao in anal_control_signal._registry:
self.selectScanSignal.addItem(ao.name) self.selectScanSignal.addItem(ao.name)
try: try:
self.configure_spinBoxes(anal_control_signal._registry[0].name) self.configure_spinBoxes(anal_control_signal._registry[0].name)
except IndexError: except IndexError:
print('No analog control signals defined. ') print('No analog control signals defined. ')
self.treeModel = QtGui.QStandardItemModel() self.treeModel = QtGui.QStandardItemModel()
self.treeView.setAlternatingRowColors(True) self.treeView.setAlternatingRowColors(True)
self.treeView.setSortingEnabled(True) self.treeView.setSortingEnabled(True)
self.treeView.setHeaderHidden(False) self.treeView.setHeaderHidden(False)
self.treeView.setSelectionBehavior(QtGui.QAbstractItemView.SelectItems) self.treeView.setSelectionBehavior(QtGui.QAbstractItemView.SelectItems)
self.treeView.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers) self.treeView.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)
self.treeModel.setHorizontalHeaderLabels(['Parameter', 'Value']) self.treeModel.setHorizontalHeaderLabels(['Parameter', 'Value'])
self.treeView.setModel(self.treeModel) self.treeView.setModel(self.treeModel)
self.treeModel.insertRow(0) self.treeModel.insertRow(0)
self.treeModel.setData(self.treeModel.index(0, 0), r'dV') self.treeModel.setData(self.treeModel.index(0, 0), r'dV')
self.treeModel.setData(self.treeModel.index(0, 1), '?') self.treeModel.setData(self.treeModel.index(0, 1), '?')
self.saveMeasureButton.setEnabled(False)
def select_folder(self):
directory = QFileDialog.getExistingDirectory(self, 'Choose directory')
self.folderBrowser.setText(directory) def select_folder(self):
directory = QFileDialog.getExistingDirectory(self, 'Choose directory')
@QtCore.pyqtSlot(str) self.folderBrowser.setText(directory)
def configure_spinBoxes(self, ao_name):
ao = self.get_selected_ao() @QtCore.pyqtSlot(str)
self.startValue.setMinimum(ao.min) def configure_spinBoxes(self, ao_name):
self.startValue.setMaximum(ao.max) ao = self.get_selected_ao()
self.startValue.setMinimum(ao.min)
self.endValue.setMinimum(ao.min) self.startValue.setMaximum(ao.max)
self.endValue.setMaximum(ao.max) self.startValue.setSingleStep(0.1)
def get_selected_ao(self): self.endValue.setMinimum(ao.min)
try: self.endValue.setMaximum(ao.max)
return [ao for ao in anal_control_signal._registry if ao.name == self.selectScanSignal.currentText()][0] self.endValue.setSingleStep(0.1)
except IndexError:
print('No analog control signals defined. ') self.stepsNum.setMaximum(1000000)
def get_selected_ao(self):
def update_tree(self): try:
try: return [ao for ao in anal_control_signal._registry if ao.name == self.selectScanSignal.currentText()][0]
self.treeModel.setData(self.treeModel.index(0, 1), (self.endValue.value()-self.startValue.value())/self.stepsNum.value() ) except IndexError:
except: print('No analog control signals defined. ')
self.treeModel.setData(self.treeModel.index(0, 1), '?')
def update_tree(self):
try:
self.treeModel.setData(self.treeModel.index(0, 1), (self.endValue.value()-self.startValue.value())/self.stepsNum.value() )
except:
self.treeModel.setData(self.treeModel.index(0, 1), '?')
""" """
class MeasurementWorker(QtCore.QObject): class MeasurementWorker(QtCore.QObject):
Backend for the measurement frame. Backend for the measurement frame.
Simple scan measurement: for scanning a spinbox. Simple scan measurement: for scanning a spinbox.
External scan measurement: scans an external object. For example, the rigol function generator. External scan measurement: scans an external object. For example, the rigol function generator.
def __init__(self): def __init__(self):
super().__init__() super().__init__()
def make_connections(self, frontend, camera): def make_connections(self, frontend, camera):
frontend.startMeasureButton.clicked.connect(self.simple_scan_measurement) frontend.startMeasureButton.clicked.connect(self.simple_scan_measurement)
def simple_scan_measurement(self): def simple_scan_measurement(self):
for l in LaserControlLayout._registry + LaserScanLayout._registry : for l in LaserControlLayout._registry + LaserScanLayout._registry :
l.freeze() l.freeze()
scanSignal = self.get_scan_signal() scanSignal = self.get_scan_signal()
scan_array = create_measurement_array() # aca necesito parametros de los spinboxes de la measurementGUi scan_array = create_measurement_array() # aca necesito parametros de los spinboxes de la measurementGUi
prepare_camara_to_triggered_acq() #includes stopping acquisition if it is in acq live prepare_camara_to_triggered_acq() #includes stopping acquisition if it is in acq live
create_temporary_data_files create_temporary_data_files
measurement loop: measurement loop:
set_scan_signal set_scan_signal
wait_predefined_time wait_predefined_time
take_and_recibe_image take_and_recibe_image
process_image_to_get_data process_image_to_get_data
save_data save_data
update_camera_gui_with_image_and_data update_camera_gui_with_image_and_data
update_measurement_gui update_measurement_gui
for l in LaserControlLayout._registry + LaserScanLayout._registry : for l in LaserControlLayout._registry + LaserScanLayout._registry :
l.unfreeze() l.unfreeze()
""" """
if __name__ == '__main__': if __name__ == '__main__':
import sys import sys
from PyQt5 import QtWidgets from PyQt5 import QtWidgets
from measurement_ui import Ui_Frame from measurement_ui import Ui_Frame
piezoA397 = anal_control_signal('piezoA397', channel=0, ao_type='cavity_piezo', out_minimum = 0, out_maximum = 4) piezoA397 = anal_control_signal('piezoA397', channel=0, ao_type='cavity_piezo', out_minimum = 0, out_maximum = 4)
piezoB397 = anal_control_signal('piezoB397', channel=1, ao_type='cavity_piezo') piezoB397 = anal_control_signal('piezoB397', channel=1, ao_type='cavity_piezo')
piezoA866 = anal_control_signal('piezoA866', channel=2, ao_type='cavity_piezo', out_minimum = 0, out_maximum = 4) piezoA866 = anal_control_signal('piezoA866', channel=2, ao_type='cavity_piezo', out_minimum = 0, out_maximum = 4)
piezoB866 = anal_control_signal('piezoB866', channel=3, ao_type='cavity_piezo') piezoB866 = anal_control_signal('piezoB866', channel=3, ao_type='cavity_piezo')
piezo423 = anal_control_signal('piezo423', channel=4, ao_type='laser_piezo') piezo423 = anal_control_signal('piezo423', channel=4, ao_type='laser_piezo')
trapDCA = anal_control_signal('dcA', channel = 5, ao_type='electrode') trapDCA = anal_control_signal('dcA', channel = 5, ao_type='electrode')
trapDCB = anal_control_signal('dcB', channel = 6, ao_type='electrode') trapDCB = anal_control_signal('dcB', channel = 6, ao_type='electrode')
trapCOMPC = anal_control_signal('compC', channel = 7, ao_type='electrode') trapCOMPC = anal_control_signal('compC', channel = 7, ao_type='electrode')
trapCOMPD = anal_control_signal('compD', channel = 8, ao_type='electrode') trapCOMPD = anal_control_signal('compD', channel = 8, ao_type='electrode')
trapOven = anal_control_signal('compOven', channel = 9, ao_type='electrode') trapOven = anal_control_signal('compOven', channel = 9, ao_type='electrode')
trapExYb = anal_control_signal('compExYb', channel = 10, ao_type='electrode') trapExYb = anal_control_signal('compExYb', channel = 10, ao_type='electrode')
app = QtWidgets.QApplication(sys.argv) app = QtWidgets.QApplication(sys.argv)
gui = MeasurementGui() gui = MeasurementFrame()
measurementWorker = MeasurementWorker() gui.show()
measurementWorker.make_connections(gui, 0) sys.exit(app.exec_())
gui.make_connections(measurementWorker)
gui.show()
sys.exit(app.exec_())
......
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon May 6 12:35:37 2019
@author: martindrech
"""
import numpy as np
import pylab as plt
data = np.loadtxt('./20190506/s02.dat', skiprows=1)
t = data[:, 0]
v = data[:, 1]
signal = data[:, 2]
#%%
plt.figure('some data')
plt.clf()
plt.plot(np.diff(t), 'o')
print(np.mean(np.diff(t)))
\ No newline at end of file
...@@ -7,9 +7,10 @@ Created on Thu Jul 5 12:17:30 2018 ...@@ -7,9 +7,10 @@ Created on Thu Jul 5 12:17:30 2018
from PyQt5.QtCore import QSettings from PyQt5.QtCore import QSettings
from PyQt5 import QtGui
from PyQt5.QtWidgets import QAction, QFileDialog, QInputDialog, QWidget from PyQt5.QtWidgets import QAction, QFileDialog, QInputDialog, QWidget
from threading import Thread from threading import Thread
#from webcamROI import roiWindow from subclasses.controllayouts import LaserControlLayout
#%% #%%
class myToolbarMenu(QWidget): class myToolbarMenu(QWidget):
...@@ -17,38 +18,47 @@ class myToolbarMenu(QWidget): ...@@ -17,38 +18,47 @@ class myToolbarMenu(QWidget):
This will create a toolbar menu This will create a toolbar menu
""" """
def __init__(self, win, analog_control_signals): def __init__(self, win):
super().__init__() super().__init__()
self.MainGuiWindow = win self.MainGuiWindow = win
self.aos = analog_control_signals self.sbsDicc = dict()
self.first_load(self.aos) self.first_load()
self.incorporate_toolbar(self.MainGuiWindow, self.aos) self.incorporate_toolbar(self.MainGuiWindow)
self.createAosDict() self.fillSpinBoxesDict()
def createAosDict(self): def fillSpinBoxesDict(self):
analogs = self.aos
self.aosDicc = {}
for i in range(len(analogs)):
self.aosDicc[analogs[i].name] = analogs[i]
def incorporate_toolbar(self, win, analog_control_signals): for l in LaserControlLayout._registry:
for sb_name in l.spinboxes:
self.sbsDicc[sb_name] = l.spinboxes[sb_name]
def createElectrodesDict(self):
d = dict()
for l in LaserControlLayout._registry:
if l.name == 'electrodes':
for sb_name in l.spinboxes:
d[sb_name] = l.spinboxes[sb_name]
return d
def incorporate_toolbar(self, win):
menubar = win.menuBar() menuBar = win.menuBar
#statusBar = QtGui.QStatusBar(self)
# saveAct = QAction('Save', win) saveAct = QAction('Save', win)
loadAct = QAction('Load', win) loadAct = QAction('Load', win)
saveAsAct = QAction('Save as' , win) saveAsAct = QAction('Save as' , win)
openFromAct = QAction('open from', win) openFromAct = QAction('open from', win)
loadElectrodesAct = QAction('Load electrodes', win) loadElectrodesAct = QAction('Load electrodes', win)
win.statusBar()
menubar = win.menuBar() menubar = menuBar
fileMenu = menubar.addMenu('&File') fileMenu = menubar.addMenu('&File')
#fileMenu.addAction(saveAct) fileMenu.addAction(saveAct)
fileMenu.addAction(loadAct) fileMenu.addAction(loadAct)
fileMenu.addAction(saveAsAct) fileMenu.addAction(saveAsAct)
fileMenu.addAction(openFromAct) fileMenu.addAction(openFromAct)
...@@ -61,94 +71,95 @@ class myToolbarMenu(QWidget): ...@@ -61,94 +71,95 @@ class myToolbarMenu(QWidget):
viewWebcams.setChecked(False) viewWebcams.setChecked(False)
viewMenu.addAction(viewWebcams) viewMenu.addAction(viewWebcams)
roiMenu = menubar.addMenu('Roi') saveAct.triggered.connect(lambda: self.save('config.ini'))
plotRoi = QAction('Open roi plot', win) loadAct.triggered.connect(lambda: self.load('config.ini'))
roiMenu.addAction(plotRoi) loadElectrodesAct.triggered.connect(lambda: self.load_electrodes(win))
saveAsAct.triggered.connect(lambda: self.save_as(win))
#☺saveAct.triggered.connect(lambda: self.save(analog_control_signals)) openFromAct.triggered.connect(lambda: self.open_from(win))
loadAct.triggered.connect(lambda: self.load(analog_control_signals))
loadElectrodesAct.triggered.connect(lambda: self.open_from([ao for ao in analog_control_signals if ao.ao_type == 'electrode'], win))
saveAsAct.triggered.connect(lambda: self.save_as(analog_control_signals, win))
openFromAct.triggered.connect(lambda: self.open_from(analog_control_signals, win))
viewWebcams.toggled.connect(lambda: self.putWebcams(viewWebcams.isChecked()) ) viewWebcams.toggled.connect(lambda: self.putWebcams(viewWebcams.isChecked()) )
plotRoi.triggered.connect(self.openRoi)
def save(self, aos):
settings = QSettings('C:\\Users\\Usuario\\Documents\\control_app\\config.ini', QSettings.IniFormat) def save(self, location):
settings = QSettings(str(location), QSettings.IniFormat)
settings.beginGroup('Ventana') settings.beginGroup('Ventana')
for ao in aos:
spin_boxes = ao.spin_boxes for text, spinb in self.sbsDicc.items():
settings.setValue(text, spinb.value())
for text, spinb in spin_boxes:
settings.setValue(str(ao.name) + '_' + text, spinb.value())
#print(spinb.value() )
settings.endGroup() settings.endGroup()
#print('saving')
def load(self, aos): def load(self, location):
settings = QSettings('C:\\Users\\Usuario\\Documents\\control_app\\config.ini', QSettings.IniFormat)
settings = QSettings(location, QSettings.IniFormat)
settings.beginGroup('Ventana') settings.beginGroup('Ventana')
for ao in aos:
spin_boxes = ao.spin_boxes for text, spinb in self.sbsDicc.items():
for text, spinb in spin_boxes: spinbox_saved_value = settings.value(text)
spin = settings.value(str(ao.name) + '_' + text) try:
try: spinb.setValue( float(spinbox_saved_value) )
spinb.setValue( float(spin) ) except TypeError:
except TypeError: spinb.setValue( float(spinb.value()) )
spinb.setValue( float(ao.initial_value) )
settings.endGroup() settings.endGroup()
def first_load(self, aos): def first_load(self):
settings = QSettings('C:\\Users\\Usuario\\Documents\\control_app\\config.ini', QSettings.IniFormat) settings = QSettings('.\config.ini', QSettings.IniFormat)
if not settings: if not settings:
print('Warning: no config.ini file in control_app folder. Pleace, be kindful and create one') print('Warning: no config.ini file in control_app folder. Pleace, be kindful and create one')
return 0 return 0
settings.beginGroup('Ventana') settings.beginGroup('Ventana')
for ao in aos: for text, spinb in self.sbsDicc.items():
spin_boxes = ao.spin_boxes spinbox_saved_value = settings.value(text)
for text, spinb in spin_boxes: try:
spin = settings.value(str(ao.name) + '_' + text) spinb.setValue( float(spinbox_saved_value) )
spinb.setValue( float(spin) ) except TypeError:
spinb.setValue( float(spinb.initial_value) )
settings.endGroup() settings.endGroup()
def save_as(self, aos, window): def save_as(self, window):
name = QFileDialog.getSaveFileName(window, 'Save File') name = QFileDialog.getSaveFileName(window, 'Save File')
if not name[0]: if not name[0]:
print('Saving was canceled') print('Saving was canceled')
return 0 return 0
filename = name[0]+'.ini'
file = open(name[0], 'w+') file = open(filename, 'w+')
file.close() file.close()
settings = QSettings(name[0], QSettings.IniFormat) self.save( filename )
settings.beginGroup('Ventana') print('saving to %s' % filename)
for ao in aos:
spin_boxes = ao.spin_boxes
for text, spinb in spin_boxes:
settings.setValue(str(ao.name) + '_' + text, spinb.value())
#print(spinb.value() )
settings.endGroup()
print('saving to %s' % name[0])
def open_from(self, aos, window): def open_from(self, window):
name = QFileDialog.getOpenFileName(window, 'Save File') name = QFileDialog.getOpenFileName(window, 'Open File')
if not name[0]:
print('Opening was canceled')
return 0
self.load(name[0])
def load_electrodes(self, window):
name = QFileDialog.getOpenFileName(window, 'Open File')
if not name[0]: if not name[0]:
print('Opening was canceled') print('Opening was canceled')
return 0 return 0
settings = QSettings(name[0], QSettings.IniFormat) settings = QSettings(name[0], QSettings.IniFormat)
settings.beginGroup('Ventana') settings.beginGroup('Ventana')
for ao in aos:
spin_boxes = ao.spin_boxes for text, spinb in self.createElectrodesDict().items():
for text, spinb in spin_boxes: spinbox_saved_value = settings.value(text)
spin = settings.value(str(ao.name) + '_' + text) try:
spinb.setValue( float(spin) ) spinb.setValue( float(spinbox_saved_value) )
except TypeError:
spinb.setValue( float(spinb.value()) )
settings.endGroup() settings.endGroup()
def startWebcamsThread(self): def startWebcamsThread(self):
exec(open('C:\\Users\\Usuario\\Documents\\control_app\\webcams.py').read()) exec(open('C:\\Users\\Usuario\\Documents\\control_app\\webcams.py').read())
...@@ -160,25 +171,5 @@ class myToolbarMenu(QWidget): ...@@ -160,25 +171,5 @@ class myToolbarMenu(QWidget):
else: else:
pass pass
def openRoi(self):
print('opening roi window')
items = self.aosDicc.keys()
item, okPressed = QInputDialog.getItem(self, "Get item","Color:", items, 0, False)
if okPressed and item:
ao = self.aosDicc[item]
self.roiW = roiWindow(ao)
self.roiW.w.show()
else:
print('Roi canceled')
def startRoiThread(self, ao):
self.roiW = roiWindow(ao)
self.roiW.w.show()
def getChoiceForRoi(self):
items = self.aosDicc.keys()
item, okPressed = QInputDialog.getItem(self, "Get item","Color:", items, 0, False)
if okPressed and item:
self.startRoiThread(item)
return self.aosDicc[item]
\ No newline at end of file
...@@ -23,7 +23,7 @@ class Storage(object): ...@@ -23,7 +23,7 @@ class Storage(object):
""" """
def __init__(self): def __init__(self):
self.directory = '' self.directory = '.'
def set_directory(self, directory): def set_directory(self, directory):
self.directory = directory self.directory = directory
...@@ -41,13 +41,13 @@ class Storage(object): ...@@ -41,13 +41,13 @@ class Storage(object):
with open(filename, 'wb') as f: with open(filename, 'wb') as f:
f.write(header.encode('utf-8')) f.write(header.encode('utf-8'))
self.delete_temporary()
def append_data_to_current_file(self, *args): def append_data_to_current_file(self, row):
with open(self.get_current_filename(), 'ab') as f: with open(self.get_current_filename(), 'ab') as f:
#data = np.column_stack(args) #data = np.column_stack(args)
data = [arg for arg in args] np.savetxt(f, [row])
np.savetxt(f, data)
f.flush() f.flush()
def get_date_string(self): def get_date_string(self):
...@@ -72,20 +72,30 @@ class Storage(object): ...@@ -72,20 +72,30 @@ class Storage(object):
if len(savings_number_list) == 0: if len(savings_number_list) == 0:
return 1 return 1
if len(savings_number_list) == 3 and not permanent_saving: #removes the last of the last 10 files
return max(savings_number_list)+1
def delete_temporary(self):
"""
Deletes old temporary files.
"""
savings_number_list = []
suffix = '.temp'
saving_directory = "/".join([self.directory, self.get_date_string(), 'dump'])
for s in [dat_file for dat_file in os.listdir(saving_directory) if dat_file.endswith(suffix)]:
savings_number_list.append(int(s[1:].split('.')[0]))
if len(savings_number_list) > 3: #removes the last of the last 10 files
file_to_remove = "/".join([saving_directory, 's' + str(min(savings_number_list)).zfill(2)])+'.temp' file_to_remove = "/".join([saving_directory, 's' + str(min(savings_number_list)).zfill(2)])+'.temp'
os.remove(file_to_remove) os.remove(file_to_remove)
return max(savings_number_list)+1
def get_current_filename(self): def get_current_filename(self):
s_num = self.get_saving_number(True)-1 s_num = self.get_saving_number()-1
saving_directory = "/".join([self.directory, self.get_date_string()]) saving_directory = "/".join([self.directory, self.get_date_string()])
filename = "/".join([saving_directory, 'dump', 's' + str(s_num).zfill(2)]) + '.temp' filename = "/".join([saving_directory, 'dump', 's' + str(s_num).zfill(2)]) + '.temp'
return filename return filename
def permanent_save_current_data(self): def permanent_save_current_data(self):
oldfile = self.get_current_filename() oldfile = self.get_current_filename()
saving_directory = "/".join([self.directory, self.get_date_string()]) saving_directory = "/".join([self.directory, self.get_date_string()])
...@@ -95,13 +105,13 @@ class Storage(object): ...@@ -95,13 +105,13 @@ class Storage(object):
#%% #%%
import time
if __name__ == '__main__': if __name__ == '__main__':
storage = Storage() storage = Storage()
storage.set_directory('./')
storage.create_data_file('col1', 'col2')
storage.create_data_file('col1', 'col2') storage.create_data_file('col1', 'col2')
storage.create_data_file('col1', 'col2') storage.create_data_file('col1', 'col2')
storage.create_data_file('col1', 'col2') storage.create_data_file('col1', 'col2')
storage.create_data_file('col1', 'col2') storage.create_data_file('col1', 'col2')
storage.create_data_file('col1', 'col2', 'col3')
storage.append_data_to_current_file([1.0,2.5,time.time()])
storage.permanent_save_current_data() storage.permanent_save_current_data()
...@@ -41,6 +41,8 @@ class CameraWorker(QtCore.QObject): ...@@ -41,6 +41,8 @@ class CameraWorker(QtCore.QObject):
frontend.cameraButton.clicked.connect(lambda: self.run(live_acq_params)) frontend.cameraButton.clicked.connect(lambda: self.run(live_acq_params))
frontend.signalWithMeasurementParameters.connect(self.simple_scan_measurement_start) frontend.signalWithMeasurementParameters.connect(self.simple_scan_measurement_start)
frontend.roiDataReadySignal.connect(self.save_data_from_scan_step) frontend.roiDataReadySignal.connect(self.save_data_from_scan_step)
frontend.measurementFrame.saveMeasureButton.clicked.connect(
self.storage.permanent_save_current_data)
# internal connections # internal connections
self.cam.helper.imageAquiredSignal.connect(self.new_image_acquired) self.cam.helper.imageAquiredSignal.connect(self.new_image_acquired)
...@@ -171,9 +173,8 @@ class CameraWorker(QtCore.QObject): ...@@ -171,9 +173,8 @@ class CameraWorker(QtCore.QObject):
@QtCore.pyqtSlot(float) @QtCore.pyqtSlot(float)
def save_data_from_scan_step(self, roiData): def save_data_from_scan_step(self, roiData):
self.storage.append_data_to_current_file([ row = [time.time(), self.ao_to_scan.AO.current_value, roiData]
time.time(), self.ao_to_scan.AO.current_value, roiData self.storage.append_data_to_current_file(row)
])
self.simple_scan_measurement_step() self.simple_scan_measurement_step()
......
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