Commit 6a07bd76 authored by Nick Sauerwein's avatar Nick Sauerwein
Browse files

before change from multiprocessing to threading in measurement

parent 75c2d3ab
...@@ -18,23 +18,28 @@ pos_L: radius of blade set by linear stage [mm] ...@@ -18,23 +18,28 @@ pos_L: radius of blade set by linear stage [mm]
measurement file (n.a) measurement file (n.a)
''' '''
default_config = {'pos_R': 329, 'pos_L':-1.6}
class BladePositioning: class BladePositioning:
def __init__(self, config, init = 1): def __init__(self, config, init = 1):
if init: if init:
s.init() s.init()
self.set_config(config) self.config = config
@property
def config(self):
config = {}
config['pos_R'] = s.getposR()
config['pos_L'] = s.getposL() - cor(s.getposR())
return config
@config.setter
def set_config(self, config): def set_config(self, config):
s.maaR(config['pos_R']) s.maaR(config['pos_R'])
s.mpaL(config['pos_L']+cor(s.getposR())) s.mpaL(config['pos_L']+cor(s.getposR()))
print ('cor: ', cor(s.getposR())) print ('cor: ', cor(s.getposR()))
def get_config(self):
config = {}
config['pos_R'] = s.getposR()
config['pos_L'] = s.getposL() - cor(s.getposR())
return config
# -*- coding: utf-8 -*-
"""
Created on Sat Feb 25 17:33:30 2017
@author: nicks
"""
from instruments.srs import SRSDG645
import quantities as pq
'''
config file:
jet_triggered: boolean, true if jet opens on fire
mode: 'one shot' or 'continuous'
rate: float, maximal possible rate (single shot) or rate of trigger (continuous)
t_sleep: time that the program sleeps until measurement finished
measurement file (n.a)
'''
class CameraDelay:
def __init__(self, config):
self.ddg = SRSDG645.open_tcpip('172.21.11.124',5025)
self.ddg.trigger_source = 3
self.jet = self.ddg.Output(self.ddg,3)
self.set_config(config)
def get_config(self):
config = {}
config['mode'] = self.getMode()
config['jet_triggered'] = self.getJet()
config['rate'] = self.getRate()
config['t_sleep'] = self.t_sleep
return config
def set_config(self, config):
self.setMode(config['mode'])
self.setJet(config['jet_triggered'])
self.setRate(config['rate'])
self.t_sleep = config['t_sleep']
def setMode(self, mode):
if mode == 'single shot':
self.ddg.trigger_source = 3
return
if mode == 'continuous':
self.ddg.trigger_source = 1
return
print ('mode: '+mode+' unknown')
raise
def getMode(self):
mode = {3: 'single shot', 1: 'continuous'}
return mode[self.ddg.trigger_source]
def setRate(self, rate):
self.ddg.holdoff = pq.sec*1/rate - pq.sec*1e-3
def getRate(self):
return 1/float(self.ddg.holdoff)
def singleMode(self):
self.ddg.trigger_source = 3
def setJet(self, On):
if On:
self.jet.level_amplitude = pq.volt*5
else:
self.jet.level_amplitude = pq.volt*0.51
def getJet(self):
if self.jet.level_amplitude == pq.volt*5:
return True
else:
return False
def measure(self):
import datetime
import time
from threading import Thread
def trigger():
time.sleep(self.t_sleep)
self.ddg.trigger()
t1 = Thread(target = trigger)
t1.start()
time = str(datetime.datetime.now()).replace(':','-').replace(' ','_')
measurement = {'time': time}
return measurement
from epics import PV, caput, caget from epics import PV, caput, caget
import time import time
import socket
Channels_Sign = {0 :'A', 1:'B', 2:'C', 3:'D', 4:'E', 5:'F', 6:'G', 7:'H', Channels_Sign = {0 :'A', 1:'B', 2:'C', 3:'D', 4:'E', 5:'F', 6:'G', 7:'H',
8:'I', 9:'J', 10: 'L', 11:'M', 12:'N', 13:'O', 14:'P', 15:'Q'} 8:'I', 9:'J', 10: 'L', 11:'M', 12:'N', 13:'O', 14:'P', 15:'Q'}
...@@ -16,19 +17,19 @@ delay: time to wait before trigger send ...@@ -16,19 +17,19 @@ delay: time to wait before trigger send
measure file: (measurements of channels are part of devices, i.e. FaradayCup, Laser) measure file: (measurements of channels are part of devices, i.e. FaradayCup, Laser)
time: time of tigger send time: time of tigger send
''' '''
import socket
default_config = {'trigger_level_CH0': 100,
'trigger_mode':2,
'delay': 0.0}
class DRS4: class DRS4:
def __init__(self, config): def __init__(self, config):
caput('FIN-LSCP-DRS1:FLAG_GAIN',1) caput('FIN-LSCP-DRS1:FLAG_GAIN',1)
self.set_config(config) self.config = config
def set_config(self, config):
self.setTriggerMode(config['trigger_mode']) @property
self.setTriggerLevel( 0, config['trigger_level_CH0']) def config(self):
self.delay = config['delay']
def get_config(self):
config = {} config = {}
config['trigger_mode'] = self.getTriggerMode() config['trigger_mode'] = self.getTriggerMode()
config['trigger_level_CH0'] = self.getTriggerLevel(0) config['trigger_level_CH0'] = self.getTriggerLevel(0)
...@@ -36,6 +37,12 @@ class DRS4: ...@@ -36,6 +37,12 @@ class DRS4:
return config return config
@config.setter
def config(self, config):
self.setTriggerMode(config['trigger_mode'])
self.setTriggerLevel( 0, config['trigger_level_CH0'])
self.delay = config['delay']
def VoltageCalibration(self): def VoltageCalibration(self):
caput('FIN-LSCP-DRS1:START_GAIN_CAL.PROC',1) caput('FIN-LSCP-DRS1:START_GAIN_CAL.PROC',1)
......
...@@ -17,7 +17,10 @@ t_sleep: time that the program sleeps until measurement finished ...@@ -17,7 +17,10 @@ t_sleep: time that the program sleeps until measurement finished
measurement file (n.a) measurement file (n.a)
''' '''
default_config = {'jet_triggered': True,
'mode': 'single shot',
'rate': 10.,
't_sleep': 0.05}
class DelayGenerator: class DelayGenerator:
def __init__(self, config): def __init__(self, config):
...@@ -25,8 +28,15 @@ class DelayGenerator: ...@@ -25,8 +28,15 @@ class DelayGenerator:
self.ddg.trigger_source = 3 self.ddg.trigger_source = 3
self.jet = self.ddg.Output(self.ddg,3) self.jet = self.ddg.Output(self.ddg,3)
self.set_config(config) self.config = config
@property
def config(self, config):
self.setMode(config['mode'])
self.setJet(config['jet_triggered'])
self.setRate(config['rate'])
self.t_sleep = config['t_sleep']
@config.setter
def get_config(self): def get_config(self):
config = {} config = {}
config['mode'] = self.getMode() config['mode'] = self.getMode()
...@@ -35,11 +45,7 @@ class DelayGenerator: ...@@ -35,11 +45,7 @@ class DelayGenerator:
config['t_sleep'] = self.t_sleep config['t_sleep'] = self.t_sleep
return config return config
def set_config(self, config):
self.setMode(config['mode'])
self.setJet(config['jet_triggered'])
self.setRate(config['rate'])
self.t_sleep = config['t_sleep']
def setMode(self, mode): def setMode(self, mode):
if mode == 'single shot': if mode == 'single shot':
......
import numpy as np import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from Scripts.PlottingServers import Plot1DServer
''' '''
config file: config file:
channel: channel on DRS4 where Cup is connected to channel: channel on DRS4 where Cup is connected to
...@@ -16,24 +18,33 @@ peak_uvolt: negative peak voltage [uV] ...@@ -16,24 +18,33 @@ peak_uvolt: negative peak voltage [uV]
charge: charge [fC] charge: charge [fC]
''' '''
default_config = {'channel':2,
'R': 50.,
'amplification': 316}
class FaradayCup: class FaradayCup:
#mendatory functions #mendatory functions
def __init__(self, config, DRS4): def __init__(self, config, DRS4):
self.drs = DRS4 self.drs = DRS4
self.set_config(config) self.config = config
self.plot_server = None self.plot_server = None
def set_config(self,config):
self.channel = config['channel'] @property
self.R = config['R'] def config(self):
self.amplification = config['amplification']
def get_config(self):
config = {} config = {}
config['channel'] = self.channel config['channel'] = self.channel
config['amplification'] = self.amplification config['amplification'] = self.amplification
config['R'] = self.R config['R'] = self.R
return config return config
@config.setter
def config(self,config):
self.channel = config['channel']
self.R = config['R']
self.amplification = config['amplification']
def measure(self): def measure(self):
import time as ttime import time as ttime
...@@ -47,9 +58,6 @@ class FaradayCup: ...@@ -47,9 +58,6 @@ class FaradayCup:
return measurement return measurement
def plot_measure(self, measurement, config = None): def plot_measure(self, measurement, config = None):
from PlottingServers import Plot1DServer
if self.plot_server == None: if self.plot_server == None:
self.plot_server = Plot1DServer({'title':'FaradayCup', 'xlabel':'Time [ns]', 'ylabel': 'Signal [uV]'}) self.plot_server = Plot1DServer({'title':'FaradayCup', 'xlabel':'Time [ns]', 'ylabel': 'Signal [uV]'})
......
...@@ -6,7 +6,8 @@ import matplotlib.pyplot as plt ...@@ -6,7 +6,8 @@ import matplotlib.pyplot as plt
import numpy as np import numpy as np
from Devices.CameraTools import binArray from Devices.CameraTools.binning import binArray
from Scripts.PlottingServers import Plot2DServer
''' '''
config file: config file:
...@@ -25,6 +26,11 @@ cymm: y coordinate of contour [mm] ...@@ -25,6 +26,11 @@ cymm: y coordinate of contour [mm]
maxit: maximal intensity [0 - 4096] maxit: maximal intensity [0 - 4096]
''' '''
default_config = {'ExposureTimeAbs': 10000,
'camera_serial_number':22005848,
'min_intensity': 2000,
'measure_full' : True}
class FocusCamera: class FocusCamera:
...@@ -37,10 +43,19 @@ class FocusCamera: ...@@ -37,10 +43,19 @@ class FocusCamera:
self.connect_camera() self.connect_camera()
self.set_config(config) self.config = config
self.plot_server_im = None self.plot_server_im = None
@property
def config(self):
config = {}
config['ExposureTimeAbs'] = self.cam.properties['ExposureTimeAbs']
config['min_intensity'] = self.min_intensity
config['measure_full'] = self.measure_full
return config
@config.setter
def set_config(self,config): def set_config(self,config):
self.min_intensity = config['min_intensity'] self.min_intensity = config['min_intensity']
...@@ -48,12 +63,7 @@ class FocusCamera: ...@@ -48,12 +63,7 @@ class FocusCamera:
self.min_intensity = config['min_intensity'] self.min_intensity = config['min_intensity']
self.measure_full = config['measure_full'] self.measure_full = config['measure_full']
def get_config(self):
config = {}
config['ExposureTimeAbs'] = self.cam.properties['ExposureTimeAbs']
config['min_intensity'] = self.min_intensity
config['measure_full'] = self.measure_full
return config
def measure(self): def measure(self):
import datetime import datetime
...@@ -84,8 +94,6 @@ class FocusCamera: ...@@ -84,8 +94,6 @@ class FocusCamera:
def plot_measure(self, measurement, config = None): def plot_measure(self, measurement, config = None):
from PlottingServers import Plot2DServer
if self.plot_server_im == None: if self.plot_server_im == None:
self.plot_server_im = Plot2DServer({'title':'FocusCamera', 'xlabel':'y [um]', 'ylabel': 'x [um]', 'image': True}) self.plot_server_im = Plot2DServer({'title':'FocusCamera', 'xlabel':'y [um]', 'ylabel': 'x [um]', 'image': True})
...@@ -118,12 +126,9 @@ class FocusCamera: ...@@ -118,12 +126,9 @@ class FocusCamera:
#autobinning #autobinning
n_binning = math.ceil(((xmaxum - xminum)/self.psize)/500) n_binning = math.ceil(((xmaxum - xminum)/self.psize)/500)
print (n_binning)
im = binArray(im, 0, n_binning, n_binning, np.mean) im = binArray(im, 0, n_binning, n_binning, np.mean)
im = binArray(im, 1, n_binning, n_binning, np.mean) im = binArray(im, 1, n_binning, n_binning, np.mean)
print ('bla')
self.plot_server_im.update(np.flipud(im),extent=(yminum,ymaxum, yminum, ymaxum)) self.plot_server_im.update(np.flipud(im),extent=(yminum,ymaxum, yminum, ymaxum))
......
...@@ -10,7 +10,9 @@ import pypylon ...@@ -10,7 +10,9 @@ import pypylon
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import Devices.InterferometerTools.routines as r import Devices.InterferometerTools.routines as r
from Devices.CameraTools import binArray from Devices.CameraTools.binning import binArray
from Scripts.PlottingServers import Plot2DServer
import time as t import time as t
# camera setup # camera setup
...@@ -49,6 +51,27 @@ time: time (datetime object) ...@@ -49,6 +51,27 @@ time: time (datetime object)
im1: first image im1: first image
im2: second image im2: second image
''' '''
default_config = inter_config = {'xmax':4.,
'xmin':0.,
'zmin':-7.,
'zmax':7.,
'x0': 4.,
'z0': 10.5,
'ExposureTimeAbs':35,
'BitsOfImage':12,
'TriggerMode':False,
'binning':10,
'Tomography':False,
'num_av': 9,
'num_dir': 2,
'take_data': True,
'Ly': 11.,
'x_tomo': 0.4,
'shift':209,
'y_calib': 1.,
'live_preview':True}
mode = {False: 'Off', True: 'On'} mode = {False: 'Off', True: 'On'}
modei = {'Off': False, 'On': True} modei = {'Off': False, 'On': True}
...@@ -69,7 +92,7 @@ class Interferometer: ...@@ -69,7 +92,7 @@ class Interferometer:
self.connect_camera() self.connect_camera()
print ('done') print ('done')
self.set_config(config) self.config = config
self.blade = blade self.blade = blade
self.delay = delay self.delay = delay
...@@ -77,8 +100,31 @@ class Interferometer: ...@@ -77,8 +100,31 @@ class Interferometer:
self.plot_server_im = None self.plot_server_im = None
self.plot_server_ph = None self.plot_server_ph = None
self.plot_server_tomo = None self.plot_server_tomo = None
@property
def config(self):
config = {}
config['ExposureTimeAbs'] = self.cam.properties['ExposureTimeAbs']
config['TriggerMode'] = modei[self.cam.properties['TriggerMode']]
config['BitsOfImage'] = int(self.cam.properties['PixelFormat'][4:])
config['binning'] = self.n_binning
def set_config(self,config): config['xmin'], config['xmax'],config['zmin'], config['zmax']= (self.xmin, self.xmax, self.zmin, self.zmax)
config['x0'], config['z0'] = (self.x0, self.z0)
config['Tomography'] = self.Tomography
config['num_dir'] = self.num_dir
config['num_av'] = self.num_av
config['take_data'] = self.take_data
config['Ly'] = self.Ly
config['x_tomo'] = self.x_tomo
config['shift'] = self.shift
config['live_preview'] = self.live_preview
config['y_calib'] = self.y_calib
return config
@config.setter
def config(self,config):
self.take_data = config['take_data'] self.take_data = config['take_data']
self.cam.properties['PixelFormat'] = 'Mono'+str(config['BitsOfImage']) self.cam.properties['PixelFormat'] = 'Mono'+str(config['BitsOfImage'])
self.cam.properties['ExposureTimeAbs']=config['ExposureTimeAbs'] self.cam.properties['ExposureTimeAbs']=config['ExposureTimeAbs']
...@@ -102,27 +148,6 @@ class Interferometer: ...@@ -102,27 +148,6 @@ class Interferometer:
self.live_preview = config['live_preview'] self.live_preview = config['live_preview']
self.y_calib = config['y_calib'] self.y_calib = config['y_calib']
def get_config(self):
config = {}
config['ExposureTimeAbs'] = self.cam.properties['ExposureTimeAbs']
config['TriggerMode'] = modei[self.cam.properties['TriggerMode']]
config['BitsOfImage'] = int(self.cam.properties['PixelFormat'][4:])
config['binning'] = self.n_binning
config['xmin'], config['xmax'],config['zmin'], config['zmax']= (self.xmin, self.xmax, self.zmin, self.zmax)
config['x0'], config['z0'] = (self.x0, self.z0)
config['Tomography'] = self.Tomography
config['num_dir'] = self.num_dir
config['num_av'] = self.num_av
config['take_data'] = self.take_data
config['Ly'] = self.Ly
config['x_tomo'] = self.x_tomo
config['shift'] = self.shift
config['live_preview'] = self.live_preview
config['y_calib'] = self.y_calib
return config
def measure(self): def measure(self):
import datetime import datetime
...@@ -141,8 +166,6 @@ class Interferometer: ...@@ -141,8 +166,6 @@ class Interferometer:
return measurement return measurement
else: else:
from PlottingServers import Plot2DServer
if self.plot_server_tomo == None: if self.plot_server_tomo == None:
self.plot_server_tomo = Plot2DServer({'title':'Tomography live', 'xlabel':'z [mm]', 'ylabel': 'x [mm]','image': True}) self.plot_server_tomo = Plot2DServer({'title':'Tomography live', 'xlabel':'z [mm]', 'ylabel': 'x [mm]','image': True})
......