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
from subclasses.cameraParameterTree import CameraParameterTree
from subclasses.controllayouts import LaserControlLayout, LaserScanLayout
from resources.scanFunctions import create_measurement_array
#from drivers.andorzyla import AndorZyla
from drivers.dummyAndor import AndorZyla
from measurement import MeasurementFrame
import sys
import numpy as np
......@@ -71,6 +68,7 @@ class CameraGuiMainWindow(QMainWindow):
self.measurementFrame = MeasurementFrame()
self.dMeasurement.addWidget(self.measurementFrame)
# button spinbox and label
self.cameraButton = QPushButton("Start Acquisition")
self.isCameraAcquiring = False
......@@ -136,7 +134,8 @@ class CameraGuiMainWindow(QMainWindow):
self.cameraButton.clicked.connect(self.camera_button_pressed)
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)
......@@ -146,8 +145,9 @@ class CameraGuiMainWindow(QMainWindow):
self.measurementFrame.startValue.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.saveMeasureButton.clicked.connect(
lambda: self.measurementFrame.saveMeasureButton.setEnabled(False)
)
def camera_button_pressed(self):
......@@ -209,6 +209,8 @@ class CameraGuiMainWindow(QMainWindow):
roi.setPos([new_x, new_y])
roi.setSize([new_sx, new_sy])
self.current_image_size = new_size
@QtCore.pyqtSlot(np.ndarray, int)
def updateImage(self, image, acq_index):
if self.frame_index is not 0 and not self.frame_index == acq_index:
......@@ -220,7 +222,7 @@ class CameraGuiMainWindow(QMainWindow):
self.img.setImage(image, autoDownsample=True)
self.updatePlots()
self.frame_index = self.frame_index + 1
self.current_image_size = image.shape[0]
def frame_counter(self):
self.counter = self.counter + 1
......@@ -257,6 +259,7 @@ class CameraGuiMainWindow(QMainWindow):
def measurement_ending(self):
self.cameraButton.setEnabled(True)
self.measurementFrame.startMeasureButton.setEnabled(True)
self.measurementFrame.saveMeasureButton.setEnabled(True)
self.isMeasuring = False
for l in LaserControlLayout._registry + LaserScanLayout._registry :
l.unfreeze()
......
......@@ -10,10 +10,13 @@ import sys
from PyQt5 import QtGui, QtCore
import qdarkstyle
import os
from PyQt5.QtWidgets import QLabel
os.environ['PYQTGRAPH_QT_LIB'] = 'PyQt5'
from subclasses.controllayouts import LaserControlLayout
from subclasses.controllayouts import LaserScanLayout
from resources.myToolbar import myToolbarMenu
from pyqtgraph import dockarea
from MCDAQcontrolsignals import anal_control_signal
from MCDAQcontrolsignals import digital_control_signal
......@@ -25,9 +28,12 @@ class ControlGui(QtGui.QFrame):
self.initUI()
def initUI(self):
self.menuBar = QtGui.QMenuBar(self)
self.area = dockarea.DockArea()
self.grid = QtGui.QGridLayout()
self.grid.addWidget(self.area, 0, 0)
self.grid.addWidget(QLabel(' '), 0, 1)
self.grid.addWidget(self.area, 1, 0)
self.grid.setSpacing(0)
self.setLayout(self.grid)
self.dock_397 = dockarea.Dock('397', (100, 100))
......@@ -80,7 +86,11 @@ class ControlGui(QtGui.QFrame):
self.electrodes_control_layout.addWidget(QtGui.QLabel('compExYb'), 1, 4)
self.electrodes_control_layout.addWidget(self.electrodes_control_layout.spinboxes['compExYb'], 1, 5)
self.toolbar = myToolbarMenu(self)
self.toolbar.load('config.ini')
self.autosave_timer = QtCore.QTimer()
self.autosave_timer.timeout.connect(lambda: self.toolbar.save('config.ini'))
self.autosave_timer.start(10000)
self.show()
......
......@@ -843,6 +843,10 @@ class AndorZyla(AndorBase):
AndorBase.__init__(self,camNum)
def trigger(self):
self.SoftwareTrigger()
class AndorSim(AndorBase):
def __init__(self, camNum):
#define properties
......
from PyQt5 import QtGui, QtCore
#from drivers.andorzyla import AndorZyla
#from drivers.andorzyla import AndorZyla
from drivers.dummyAndor import AndorZyla
from cameraGui import CameraGuiMainWindow
......
......@@ -13,9 +13,6 @@ from PyQt5.QtCore import QSettings
from PyQt5.QtWidgets import QAction, QFileDialog, QInputDialog, QWidget
from measurement_ui import Ui_Frame
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):
......@@ -45,6 +42,8 @@ class MeasurementFrame(QtWidgets.QFrame, Ui_Frame):
self.treeModel.setData(self.treeModel.index(0, 0), r'dV')
self.treeModel.setData(self.treeModel.index(0, 1), '?')
self.saveMeasureButton.setEnabled(False)
def select_folder(self):
directory = QFileDialog.getExistingDirectory(self, 'Choose directory')
......@@ -55,9 +54,13 @@ class MeasurementFrame(QtWidgets.QFrame, Ui_Frame):
ao = self.get_selected_ao()
self.startValue.setMinimum(ao.min)
self.startValue.setMaximum(ao.max)
self.startValue.setSingleStep(0.1)
self.endValue.setMinimum(ao.min)
self.endValue.setMaximum(ao.max)
self.endValue.setSingleStep(0.1)
self.stepsNum.setMaximum(1000000)
def get_selected_ao(self):
try:
......@@ -127,11 +130,7 @@ if __name__ == '__main__':
trapExYb = anal_control_signal('compExYb', channel = 10, ao_type='electrode')
app = QtWidgets.QApplication(sys.argv)
gui = MeasurementGui()
measurementWorker = MeasurementWorker()
measurementWorker.make_connections(gui, 0)
gui.make_connections(measurementWorker)
gui = MeasurementFrame()
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
from PyQt5.QtCore import QSettings
from PyQt5 import QtGui
from PyQt5.QtWidgets import QAction, QFileDialog, QInputDialog, QWidget
from threading import Thread
#from webcamROI import roiWindow
from subclasses.controllayouts import LaserControlLayout
#%%
class myToolbarMenu(QWidget):
......@@ -17,38 +18,47 @@ class myToolbarMenu(QWidget):
This will create a toolbar menu
"""
def __init__(self, win, analog_control_signals):
def __init__(self, win):
super().__init__()
self.MainGuiWindow = win
self.aos = analog_control_signals
self.sbsDicc = dict()
self.first_load(self.aos)
self.incorporate_toolbar(self.MainGuiWindow, self.aos)
self.first_load()
self.incorporate_toolbar(self.MainGuiWindow)
self.createAosDict()
self.fillSpinBoxesDict()
def createAosDict(self):
analogs = self.aos
self.aosDicc = {}
for i in range(len(analogs)):
self.aosDicc[analogs[i].name] = analogs[i]
def fillSpinBoxesDict(self):
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]
menubar = win.menuBar()
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
# saveAct = QAction('Save', win)
def incorporate_toolbar(self, win):
menuBar = win.menuBar
#statusBar = QtGui.QStatusBar(self)
saveAct = QAction('Save', win)
loadAct = QAction('Load', win)
saveAsAct = QAction('Save as' , win)
openFromAct = QAction('open from', win)
loadElectrodesAct = QAction('Load electrodes', win)
win.statusBar()
menubar = win.menuBar()
menubar = menuBar
fileMenu = menubar.addMenu('&File')
#fileMenu.addAction(saveAct)
fileMenu.addAction(saveAct)
fileMenu.addAction(loadAct)
fileMenu.addAction(saveAsAct)
fileMenu.addAction(openFromAct)
......@@ -61,95 +71,96 @@ class myToolbarMenu(QWidget):
viewWebcams.setChecked(False)
viewMenu.addAction(viewWebcams)
roiMenu = menubar.addMenu('Roi')
plotRoi = QAction('Open roi plot', win)
roiMenu.addAction(plotRoi)
#☺saveAct.triggered.connect(lambda: self.save(analog_control_signals))
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))
saveAct.triggered.connect(lambda: self.save('config.ini'))
loadAct.triggered.connect(lambda: self.load('config.ini'))
loadElectrodesAct.triggered.connect(lambda: self.load_electrodes(win))
saveAsAct.triggered.connect(lambda: self.save_as(win))
openFromAct.triggered.connect(lambda: self.open_from(win))
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')
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() )
for text, spinb in self.sbsDicc.items():
settings.setValue(text, spinb.value())
settings.endGroup()
#print('saving')
def load(self, aos):
settings = QSettings('C:\\Users\\Usuario\\Documents\\control_app\\config.ini', QSettings.IniFormat)
def load(self, location):
settings = QSettings(location, QSettings.IniFormat)
settings.beginGroup('Ventana')
for ao in aos:
spin_boxes = ao.spin_boxes
for text, spinb in spin_boxes:
spin = settings.value(str(ao.name) + '_' + text)
for text, spinb in self.sbsDicc.items():
spinbox_saved_value = settings.value(text)
try:
spinb.setValue( float(spin) )
spinb.setValue( float(spinbox_saved_value) )
except TypeError:
spinb.setValue( float(ao.initial_value) )
spinb.setValue( float(spinb.value()) )
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:
print('Warning: no config.ini file in control_app folder. Pleace, be kindful and create one')
return 0
settings.beginGroup('Ventana')
for ao in aos:
spin_boxes = ao.spin_boxes
for text, spinb in spin_boxes:
spin = settings.value(str(ao.name) + '_' + text)
spinb.setValue( float(spin) )
for text, spinb in self.sbsDicc.items():
spinbox_saved_value = settings.value(text)
try:
spinb.setValue( float(spinbox_saved_value) )
except TypeError:
spinb.setValue( float(spinb.initial_value) )
settings.endGroup()
def save_as(self, aos, window):
def save_as(self, window):
name = QFileDialog.getSaveFileName(window, 'Save File')
if not name[0]:
print('Saving was canceled')
return 0
file = open(name[0], 'w+')
filename = name[0]+'.ini'
file = open(filename, 'w+')
file.close()
settings = QSettings(name[0], QSettings.IniFormat)
settings.beginGroup('Ventana')
for ao in aos:
spin_boxes = ao.spin_boxes
self.save( filename )
print('saving to %s' % filename)
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, window):
name = QFileDialog.getOpenFileName(window, 'Open File')
if not name[0]:
print('Opening was canceled')
return 0
self.load(name[0])
def open_from(self, aos, window):
name = QFileDialog.getOpenFileName(window, 'Save File')
def load_electrodes(self, window):
name = QFileDialog.getOpenFileName(window, 'Open File')
if not name[0]:
print('Opening was canceled')
return 0
settings = QSettings(name[0], QSettings.IniFormat)
settings.beginGroup('Ventana')
for ao in aos:
spin_boxes = ao.spin_boxes
for text, spinb in spin_boxes:
spin = settings.value(str(ao.name) + '_' + text)
spinb.setValue( float(spin) )
for text, spinb in self.createElectrodesDict().items():
spinbox_saved_value = settings.value(text)
try:
spinb.setValue( float(spinbox_saved_value) )
except TypeError:
spinb.setValue( float(spinb.value()) )
settings.endGroup()
def startWebcamsThread(self):
exec(open('C:\\Users\\Usuario\\Documents\\control_app\\webcams.py').read())
......@@ -160,25 +171,5 @@ class myToolbarMenu(QWidget):
else:
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):
"""
def __init__(self):
self.directory = ''
self.directory = '.'
def set_directory(self, directory):
self.directory = directory
......@@ -41,13 +41,13 @@ class Storage(object):
with open(filename, 'wb') as f:
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:
#data = np.column_stack(args)
data = [arg for arg in args]
np.savetxt(f, data)
np.savetxt(f, [row])
f.flush()
def get_date_string(self):
......@@ -72,20 +72,30 @@ class Storage(object):
if len(savings_number_list) == 0:
return 1
if len(savings_number_list) == 3 and not permanent_saving: #removes the last of the last 10 files
file_to_remove = "/".join([saving_directory, 's' + str(min(savings_number_list)).zfill(2)])+'.temp'
os.remove(file_to_remove)
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'
os.remove(file_to_remove)
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()])
filename = "/".join([saving_directory, 'dump', 's' + str(s_num).zfill(2)]) + '.temp'
return filename
def permanent_save_current_data(self):
oldfile = self.get_current_filename()
saving_directory = "/".join([self.directory, self.get_date_string()])
......@@ -95,13 +105,13 @@ class Storage(object):
#%%
import time
if __name__ == '__main__':
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', 'col3')
storage.append_data_to_current_file([1.0,2.5,time.time()])
storage.permanent_save_current_data()
......@@ -41,6 +41,8 @@ class CameraWorker(QtCore.QObject):
frontend.cameraButton.clicked.connect(lambda: self.run(live_acq_params))
frontend.signalWithMeasurementParameters.connect(self.simple_scan_measurement_start)
frontend.roiDataReadySignal.connect(self.save_data_from_scan_step)
frontend.measurementFrame.saveMeasureButton.clicked.connect(
self.storage.permanent_save_current_data)
# internal connections
self.cam.helper.imageAquiredSignal.connect(self.new_image_acquired)
......@@ -171,9 +173,8 @@ class CameraWorker(QtCore.QObject):
@QtCore.pyqtSlot(float)
def save_data_from_scan_step(self, roiData):
self.storage.append_data_to_current_file([
time.time(), self.ao_to_scan.AO.current_value, roiData
])
row = [time.time(), self.ao_to_scan.AO.current_value, roiData]
self.storage.append_data_to_current_file(row)
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