Commit 75027243 authored by Martin Drechsler's avatar Martin Drechsler

Almost readt to measure (with the dummy at least). Some fixing in storage required.

parent f4cb859d
......@@ -2,7 +2,6 @@
"""
Here the class of control signals are created. There are two types: analog and digital.
"""
import numpy as np
from drivers.ADoutputs import daq_AO, daq_DO
from PyQt5 import QtCore
from subclasses.controllayouts import LaserControlLayout
......@@ -11,102 +10,104 @@ from subclasses.controllayouts import LaserScanLayout
AO_TYPES = ['cavity_piezo', 'electrode', 'laser_piezo']
class anal_control_signal(QtCore.QObject):
_registry = []
scanStepSignal = QtCore.pyqtSignal(float)
scanEndSignal = QtCore.pyqtSignal(float)
def __init__(self, name, channel, ao_type, out_minimum = -10, out_maximum = 10, out_step = 0.1, feedfoward = False):
super().__init__()
if name in [ao.name for ao in self._registry]:
raise ValueError('Two analog control signals cannot share the name: %s used already' % (name))
if channel in [ao.ch for ao in self._registry]:
raise ValueError('Two analog control signals cannot share the channel: channel %s used already' % (channel))
if ao_type not in AO_TYPES:
raise ValueError("Invalid ao type. Expected one of: %s" % AO_TYPES)
self._registry.append(self)
self.name = name
self.ch = channel
self.ao_type = ao_type
self.AO = daq_AO(self.ch)
self.is_feedwoward_enabled = feedfoward
self.initial_value = 0
self.max = out_maximum
self.min = out_minimum
self.step = out_step
self.siPrefix = True
self.suffix = 'V'
self.scanTimer = QtCore.QTimer()
self.current_scan_step = 0
self.scan_array_gen = None
def make_connections(self, frontend):
for layout in LaserControlLayout._registry:
if self.name in layout.spinboxes:
layout.spinboxes[self.name].setMinimum(self.min)
layout.spinboxes[self.name].setMaximum(self.max)
layout.spinboxes[self.name].setValue(self.initial_value)
layout.spinboxes[self.name].sigValueChanging.connect(self.sb_change)
scan_layouts = [l for l in LaserScanLayout._registry if l.name == self.name]
for scan_layout in scan_layouts:
scan_layout.spinboxes['start'].setMinimum(self.min)
scan_layout.spinboxes['start'].setMaximum(self.max)
scan_layout.spinboxes['stop'].setMinimum(self.min)
scan_layout.spinboxes['stop'].setMaximum(self.max)
def name(self):
return self.name
def scan_event(self):
self.current_scan_step = next(self.scan_array_gen)
self.AO.set_out(self.current_scan_step)
self.scanStepSignal.emit(self.current_scan_step)
@QtCore.pyqtSlot(object)
def scan_action(self, scan_array_gen):
print('action')
if self.scanTimer.isActive():
print('stop timer')
self.scanTimer.stop()
self.scanEndSignal.emit(self.current_scan_step)
else:
print('start timer')
self.scan_array_gen = scan_array_gen
self.scanTimer.start(5.0)
@QtCore.pyqtSlot(object, object)
def sb_change(self, sb, value):
self.AO.set_out(value)
_registry = []
scanStepSignal = QtCore.pyqtSignal(float)
scanEndSignal = QtCore.pyqtSignal(float)
def __init__(self, name, channel, ao_type, out_minimum = -10, out_maximum = 10, out_step = 0.1, feedfoward = False):
super().__init__()
if name in [ao.name for ao in self._registry]:
raise ValueError('Two analog control signals cannot share the name: %s used already' % (name))
if channel in [ao.ch for ao in self._registry]:
raise ValueError('Two analog control signals cannot share the channel: channel %s used already' % (channel))
if ao_type not in AO_TYPES:
raise ValueError("Invalid ao type. Expected one of: %s" % AO_TYPES)
self._registry.append(self)
self.name = name
self.ch = channel
self.ao_type = ao_type
self.AO = daq_AO(self.ch)
self.is_feedwoward_enabled = feedfoward
self.initial_value = 0
self.max = out_maximum
self.min = out_minimum
self.step = out_step
self.siPrefix = True
self.suffix = 'V'
self.scanTimer = QtCore.QTimer()
self.current_scan_step = 0
self.scan_array_gen = None
def make_connections(self, frontend):
for layout in LaserControlLayout._registry:
if self.name in layout.spinboxes:
layout.spinboxes[self.name].setMinimum(self.min)
layout.spinboxes[self.name].setMaximum(self.max)
layout.spinboxes[self.name].setValue(self.initial_value)
layout.spinboxes[self.name].sigValueChanging.connect(self.sb_change)
scan_layouts = [l for l in LaserScanLayout._registry if l.name == self.name]
for scan_layout in scan_layouts:
scan_layout.spinboxes['start'].setMinimum(self.min)
scan_layout.spinboxes['start'].setMaximum(self.max)
scan_layout.spinboxes['stop'].setMinimum(self.min)
scan_layout.spinboxes['stop'].setMaximum(self.max)
def name(self):
return self.name
def scan_event(self):
self.current_scan_step = next(self.scan_array_gen)
self.AO.set_out(self.current_scan_step)
self.scanStepSignal.emit(self.current_scan_step)
@QtCore.pyqtSlot(object)
def scan_action(self, scan_array_gen):
print('action')
if self.scanTimer.isActive():
print('stop timer')
self.scanTimer.stop()
self.scanEndSignal.emit(self.current_scan_step)
else:
print('start timer')
self.scan_array_gen = scan_array_gen
self.scanTimer.start(5.0)
@QtCore.pyqtSlot(object, object)
def sb_change(self, sb, value):
self.AO.set_out(value)
class digital_control_signal(QtCore.QObject):
_registry = []
_registry = []
def __init__(self, name, channel, inverse=False):
super().__init__()
self._registry.append(self)
def __init__(self, name, channel, inverse=False):
super().__init__()
self._registry.append(self)
self.name = name
self.ch = channel
self.initial_value = 0
self.DO = daq_DO(self.ch)
self.name = name
self.ch = channel
self.initial_value = 0
self.DO = daq_DO(self.ch)
def make_connections(self, frontend):
def make_connections(self, frontend):
for layout in LaserControlLayout._registry:
if self.name in layout.checkboxes:
layout.checkboxes[self.name].stateChanged.connect(self.when_change_digital)
for layout in LaserControlLayout._registry:
if self.name in layout.checkboxes:
layout.checkboxes[self.name].stateChanged.connect(self.when_change_digital)
@QtCore.pyqtSlot(int)
def when_change_digital(self, state):
if state == QtCore.Qt.Checked:
self.DO.set_out(True)
else:
self.DO.set_out(False)
\ No newline at end of file
@QtCore.pyqtSlot(int)
def when_change_digital(self, state):
if state == QtCore.Qt.Checked:
self.DO.set_out(True)
else:
self.DO.set_out(False)
\ No newline at end of file
......@@ -18,7 +18,6 @@ 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
......@@ -29,6 +28,7 @@ import numpy as np
class CameraGuiMainWindow(QMainWindow):
signalWithMeasurementParameters = QtCore.pyqtSignal(object)
roiDataReadySignal = QtCore.pyqtSignal(float)
def __init__(self):
super().__init__()
......@@ -37,7 +37,7 @@ class CameraGuiMainWindow(QMainWindow):
self.counter = 0
self.frames_checker_timer = QtCore.QTimer()
self.isMeasuring = False
self.initUI()
def initUI(self):
......@@ -183,7 +183,9 @@ class CameraGuiMainWindow(QMainWindow):
for roi in self.rois:
roiSlice = roi.getArrayRegion(self.img.image, img=self.img)
self.newData = roiSlice.sum()
self.newData = np.mean(roiSlice)
if self.isMeasuring:
self.roiDataReadySignal.emit(self.newData)
self.scanROIdataY[self.iROIdata] = self.newData
self.timeROIdataY[self.iROIdata] = self.newData
......@@ -235,8 +237,7 @@ class CameraGuiMainWindow(QMainWindow):
def measurement_starting(self):
self.cameraButton.setEnabled(False)
self.measurementFrame.startMeasureButton.setEnabled(False)
self.isMeasuring = True
start = self.measurementFrame.startValue.value()
end = self.measurementFrame.endValue.value()
steps = self.measurementFrame.stepsNum.value()
......@@ -256,6 +257,7 @@ class CameraGuiMainWindow(QMainWindow):
def measurement_ending(self):
self.cameraButton.setEnabled(True)
self.measurementFrame.startMeasureButton.setEnabled(True)
self.isMeasuring = False
for l in LaserControlLayout._registry + LaserScanLayout._registry :
l.unfreeze()
print('gui meas end')
......@@ -270,7 +272,6 @@ class CameraGuiMainWindow(QMainWindow):
measure_params['end'] = self.measurementFrame.endValue.value()
measure_params['steps'] = self.measurementFrame.stepsNum.value()
measure_params['directory'] = self.measurementFrame.folderBrowser.toPlainText()
self.signalWithMeasurementParameters.emit(measure_params)
###############################################################################
......
......@@ -76,7 +76,7 @@ class daq_AO(object):
self.out_num = out_num
self.board_num = board_num
self.output_range = output_range
self.current_value = None
if daqfound:
ul.set_config(InfoType.BOARDINFO, self.board_num, self.out_num, BoardInfo.DACRANGE, self.output_range)
......@@ -87,11 +87,13 @@ class daq_AO(object):
def set_out(self, value):
try:
ul.v_out(self.board_num, self.out_num, self.output_range, value)
self.current_value = value
except ULError as e:
self.show_ul_error(e)
else:
def set_out(self, value):
print('Analog out %i set to %f' % (self.out_num, value) )
self.current_value = value
return value, self.out_num
class daq_DO(object):
......
......@@ -21,8 +21,11 @@ class Storage(object):
"""
Class to handle data saving.
"""
def __init__(self, directory):
def __init__(self):
self.directory = ''
def set_directory(self, directory):
self.directory = directory
def create_data_file(self, *args):
......@@ -42,7 +45,8 @@ class Storage(object):
def append_data_to_current_file(self, *args):
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, data)
f.flush()
......@@ -75,10 +79,11 @@ class Storage(object):
return max(savings_number_list)+1
def get_current_filename(self):
s_num = self.get_saving_number()-1
s_num = self.get_saving_number(True)-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):
......@@ -88,8 +93,15 @@ class Storage(object):
shutil.move(oldfile, "/".join([saving_directory, newfilename]) )
print("/".join([saving_directory, newfilename]))
#%%
if __name__ == '__main__':
storage = Storage('/home/martindrech/Documents/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.permanent_save_current_data()
......@@ -14,14 +14,14 @@ import threading
import time
from MCDAQcontrolsignals import anal_control_signal
from resources.messages import show_warning
from resources.storage import Storage
from resources.scanFunctions import create_measurement_array, yield_array
from resources.storage import Storage
class CameraWorker(QtCore.QObject):
imageReadySignal = QtCore.pyqtSignal(np.ndarray, int)
measurementStartingSignal = QtCore.pyqtSignal()
measurementEndingSignal = QtCore.pyqtSignal()
def __init__(self, andor_camera):
super().__init__()
......@@ -31,6 +31,7 @@ class CameraWorker(QtCore.QObject):
self.cam.SensorCooling.setValue(True)
print("camera worker initialized")
self.storage = Storage()
self.ao_to_scan = None
self.scan_array_gen = None
......@@ -39,6 +40,7 @@ class CameraWorker(QtCore.QObject):
live_acq_params = frontend.param_tree.p
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)
# internal connections
self.cam.helper.imageAquiredSignal.connect(self.new_image_acquired)
......@@ -117,7 +119,6 @@ class CameraWorker(QtCore.QObject):
@QtCore.pyqtSlot(int)
def new_image_acquired_with_trigger(self, acq_index):
self.imageReadySignal.emit(self.cam.acq_queue.get(), acq_index)
self.simple_scan_measurement_step()
def simple_scan_measurement_start(self, measure_params):
......@@ -131,9 +132,11 @@ class CameraWorker(QtCore.QObject):
start = measure_params['start']
end = measure_params['end']
step_num = measure_params['steps']
directory = measure_params['directory']
self.scan_array_gen = yield_array(create_measurement_array(start, end, step_num))
storage = Storage(directory)
self.storage.set_directory(measure_params['directory'])
self.storage.create_data_file('Time', measure_params['signal_to_scan'], 'Roi data')
self.cam.TriggerMode.setString('Software')
self.cam.helper.imageAquiredSignal.disconnect(self.new_image_acquired)
......@@ -158,31 +161,24 @@ class CameraWorker(QtCore.QObject):
try:
value = next(self.scan_array_gen)
self.ao_to_scan.AO.set_out(value)
#aca puede esperar o chequear algo, por ahora nada
# aca puede esperar o chequear algo, por ahora nada
self.cam.trigger()
except StopIteration:
self.simple_scan_measurement_end()
def get_scan_signal(self, ao_name):
return [ao for ao in anal_control_signal._registry if ao.name == ao_name][0]
QtCore.QTimer.singleShot(5000, self.measurementEndingSignal.emit)
print('Ending measurement')
@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
])
self.simple_scan_measurement_step()
"""
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
create_temporary_data_files
measurement loop:
set_scan_signal
wait_predefined_time
take_and_recibe_image
process_image_to_get_data
save_data
update_camera_gui_with_image_and_data
update_measurement_gui
"""
\ No newline at end of file
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