Commit 8ecef216 authored by Nick Sauerwein's avatar Nick Sauerwein
Browse files

spectrometer setup to be implemented

parent b6f3b2da
...@@ -18,7 +18,7 @@ pos_L: radius of blade set by linear stage [mm] ...@@ -18,7 +18,7 @@ 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} default_config = {'pos_R': 20, 'pos_L':0}
class BladePositioning: class BladePositioning:
def __init__(self, config): def __init__(self, config):
...@@ -32,7 +32,7 @@ class BladePositioning: ...@@ -32,7 +32,7 @@ class BladePositioning:
return config return config
@config.setter @config.setter
def set_config(self, config): def 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()))
......
...@@ -61,11 +61,11 @@ def getposL(): ...@@ -61,11 +61,11 @@ def getposL():
return ret return ret
def maaR(angle): def maaR(angle):
rev=-1 rev=0
#print (angle) #print (angle)
cmd("MAA0,"+str(int(angle*1000000))+","+str(rev)+",60000") cmd("MAA0,"+str(int(angle*1000000))+","+str(rev)+",0")
while cmd("GS0",output=True)[-2]!=str(3): while cmd("GS0",output=True)[-2]!=str(3):
#print(cmd("GS0",output=True)[-2]) #print(cmd("GS0",output=True)[-2])
if cmd("GS0",output=True)[-2] == str(0): if cmd("GS0",output=True)[-2] == str(0):
...@@ -83,11 +83,11 @@ def maaR(angle): ...@@ -83,11 +83,11 @@ def maaR(angle):
def mpaL(pos): def mpaL(pos):
print ('desired position: ',pos) #print ('desired position: ',pos)
assert (not(pos < -5.3507 or pos > 0.522162)) assert (not(pos < -5.3507 or pos > 0.522162))
cmd("MPA1,"+str(int(pos*1e6))+",60000") cmd("MPA1,"+str(int(pos*1e6))+",0")
# while cmd("GS1",output=True)[-2]!=str(3): # while cmd("GS1",output=True)[-2]!=str(3):
# time.sleep(0.2) # time.sleep(0.2)
while cmd("GS1",output=True)[-2]!=str(3): while cmd("GS1",output=True)[-2]!=str(3):
...@@ -129,7 +129,8 @@ def init(): ...@@ -129,7 +129,8 @@ def init():
moverelR(-1) moverelR(-1)
time.sleep(1) time.sleep(1)
frmR("fwd") frmR("bwd")
while cmd("GS0",output=True)[-2]!=str(3): while cmd("GS0",output=True)[-2]!=str(3):
if cmd("GS0",output=True)[-2] == str(0): if cmd("GS0",output=True)[-2] == str(0):
print ('reference not found, stage probably to far from reference ') print ('reference not found, stage probably to far from reference ')
...@@ -138,13 +139,17 @@ def init(): ...@@ -138,13 +139,17 @@ def init():
#print(cmd("GS0",output=True)[-2]) #print(cmd("GS0",output=True)[-2])
time.sleep(1) time.sleep(1)
#set limit for rot. Positioner (5,-200) #set limit for rot. Positioner (5,-200)
cmd("SAL0,160000000,-1,5000000,0") cmd("SAL0,0, 0,"+str(270e6)+",0")
print("R",getposR()) print("R",getposR())
print("rot. ref. done") print("rot. ref. done")
print("find lin. ref.") print("find lin. ref.")
moverelL(-0.1) moverelL(-0.1)
time.sleep(3) time.sleep(3)
frmL("fwd") frmL("bwd")
while cmd("GS1",output=True)[-2]!=str(3): while cmd("GS1",output=True)[-2]!=str(3):
#print(cmd("GS0",output=True)[-2]) #print(cmd("GS0",output=True)[-2])
time.sleep(1) time.sleep(1)
...@@ -154,7 +159,7 @@ def init(): ...@@ -154,7 +159,7 @@ def init():
print("L",getposL()) print("L",getposL())
print("lin. ref. done") print("lin. ref. done")
cmd("SPL1,"+str(-3e4)+","+str(3e6))
#if reboot: init() #if reboot: init()
#time.sleep(2) #time.sleep(2)
#moverelR(-5) #moverelR(-5)
......
...@@ -29,15 +29,10 @@ class DelayGenerator: ...@@ -29,15 +29,10 @@ class DelayGenerator:
self.jet = self.ddg.Output(self.ddg,3) self.jet = self.ddg.Output(self.ddg,3)
self.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 @property
def get_config(self): def config(self):
config = {} config = {}
config['mode'] = self.getMode() config['mode'] = self.getMode()
config['jet_triggered'] = self.getJet() config['jet_triggered'] = self.getJet()
...@@ -45,7 +40,12 @@ class DelayGenerator: ...@@ -45,7 +40,12 @@ class DelayGenerator:
config['t_sleep'] = self.t_sleep config['t_sleep'] = self.t_sleep
return config return config
@config.setter
def 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':
......
...@@ -53,6 +53,11 @@ class FaradayCup: ...@@ -53,6 +53,11 @@ class FaradayCup:
import datetime import datetime
time = datetime.datetime.now() time = datetime.datetime.now()
measurement = {} measurement = {}
v_calib = np.mean(sig_uvolt[:,100])
sig_uvolt = sig_uvolt - v_calib
charge = np.trapz(sig_uvolt, x = np.array(sig_time)*1e-9)*1e-6/self.R/self.amplification*1e15 charge = np.trapz(sig_uvolt, x = np.array(sig_time)*1e-9)*1e-6/self.R/self.amplification*1e15
measurement = {'time': time,'sig_time': sig_time, 'sig_uvolt': sig_uvolt, 'peak_uvolt': np.min(sig_uvolt),'charge': charge } measurement = {'time': time,'sig_time': sig_time, 'sig_uvolt': sig_uvolt, 'peak_uvolt': np.min(sig_uvolt),'charge': charge }
return measurement return measurement
......
...@@ -56,7 +56,7 @@ class FocusCamera: ...@@ -56,7 +56,7 @@ class FocusCamera:
return config return config
@config.setter @config.setter
def set_config(self,config): def config(self,config):
self.min_intensity = config['min_intensity'] self.min_intensity = config['min_intensity']
self.cam.properties['ExposureTimeAbs']=config['ExposureTimeAbs'] self.cam.properties['ExposureTimeAbs']=config['ExposureTimeAbs']
...@@ -82,12 +82,12 @@ class FocusCamera: ...@@ -82,12 +82,12 @@ class FocusCamera:
comment = 'beam detected' comment = 'beam detected'
else: else:
comment = 'No beam detected' comment = 'No beam detected'
FWHMx = 20 FWHMx = 100
FWHMy = 20 FWHMy = 100
cxmm = None cxum = None
cymm = None cyum = None
measurement['comment'], measurement['FWHMx'], measurement['FWHMy'], measurement['cxum'], measurement['cyum'] = (comment, FWHMx, FWHMy, cxmm, cymm) measurement['comment'], measurement['FWHMx'], measurement['FWHMy'], measurement['cxum'], measurement['cyum'] = (comment, FWHMx, FWHMy, cxum, cyum)
measurement['maxit'] = max_int measurement['maxit'] = max_int
return measurement return measurement
...@@ -95,7 +95,7 @@ class FocusCamera: ...@@ -95,7 +95,7 @@ class FocusCamera:
def plot_measure(self, measurement, config = None): def plot_measure(self, measurement, config = None):
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':'x [um]', 'ylabel': 'y [um]', 'image': True})
im = measurement['im'].astype('float32') im = measurement['im'].astype('float32')
...@@ -110,11 +110,11 @@ class FocusCamera: ...@@ -110,11 +110,11 @@ class FocusCamera:
FWHMx = measurement['FWHMx'] FWHMx = measurement['FWHMx']
FWHMy = measurement['FWHMy'] FWHMy = measurement['FWHMy']
if cxum: if type(cxum) != type(None):
xminum, xmaxum = np.min(cxum) - nFWHM * FWHMx, np.max(cxum) + nFWHM * FWHMx xminum, xmaxum = np.min(cxum) - nFWHM * FWHMx, np.max(cxum) + nFWHM * FWHMx
yminum, ymaxum = np.min(cyum) - nFWHM * FWHMy, np.max(cyum) + nFWHM * FWHMy yminum, ymaxum = np.min(cyum) - nFWHM * FWHMy, np.max(cyum) + nFWHM * FWHMy
im = im[xminum/self.psize:xmaxum/self.psize, yminum/self.psize:ymaxum/self.psize] im = im[int(yminum/self.psize):int(ymaxum/self.psize),int(xminum/self.psize):int(xmaxum/self.psize)]
else: else:
xminum = 0 xminum = 0
...@@ -129,7 +129,7 @@ class FocusCamera: ...@@ -129,7 +129,7 @@ class FocusCamera:
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)
self.plot_server_im.update(np.flipud(im),extent=(yminum,ymaxum, yminum, ymaxum)) self.plot_server_im.update(np.flipud(im),extent=(xminum,xmaxum, yminum, ymaxum))
......
...@@ -37,39 +37,32 @@ def find_beam(im, plot = True, nFWHM = 2, axis = None): ...@@ -37,39 +37,32 @@ def find_beam(im, plot = True, nFWHM = 2, axis = None):
itmaxypx, itmaxxpx = np.unravel_index(im.argmax(), im.shape) itmaxypx, itmaxxpx = np.unravel_index(im.argmax(), im.shape)
itmax = im[itmaxypx, itmaxxpx] itmax = im[itmaxypx, itmaxxpx]
itmaxxum, itmaxyum = px2mm(itmaxxpx, itmaxypx) itmaxxum, itmaxyum = px2um(itmaxxpx, itmaxypx)
px_box = 100
im_reduced = im[itmaxypx-px_box:itmaxypx+px_box, itmaxxpx-px_box:itmaxxpx+px_box]
#filter
from skimage.filters import gaussian
im_reduced = gaussian(im_reduced, sigma = 1)
itmax = np.max(im_reduced)
from skimage.measure import find_contours from skimage.measure import find_contours
cs = find_contours(im, itmax/2) cs = find_contours(im_reduced, itmax/2)
#print ('# of contours: ',len(cs)) #print ('# of contours: ',len(cs))
clens = [len(con[0]) for con in cs] clens = [len(con[0]) for con in cs]
arg = np.argmax(clens) arg = np.argmax(clens)
c = cs[arg] c = cs[arg]
cxpx = c.T[1] #+ itmaxxpx-framepx cxpx = c.T[1] + itmaxxpx-px_box#+ itmaxxpx-framepx
cypx = c.T[0] #+ itmaxypx-framepx cypx = c.T[0] + itmaxypx-px_box#+ itmaxypx-framepx
cxum, cyum = px2um(cxpx, cypx) cxum, cyum = px2um(cxpx, cypx)
FWHMx = np.max(cxum) - np.min(cxum)
FWHMy = np.max(cyum) - np.min(cyum)
if plot:
showimage(im, axis = axis)
axis.plot(cxum, cyum, 'g')
FWHMx = np.max(cxum) - np.min(cxum)
FWHMy = np.max(cyum) - np.min(cymm)
axis.set_xlim(np.min(cxum) - nFWHM * FWHMx, np.max(cxum) + nFWHM * FWHMx)
axis.set_ylim(np.min(cyum) - nFWHM * FWHMy, np.max(cyum) + nFWHM * FWHMy)
axis.set_xlabel('x [mm]')
axis.set_ylabel('y [mm]')
axis.set_title('Center: ('+str(itmaxxum)+', '+str(itmaxyum)+'), Intensity: '+str(itmax))
return (itmax, itmaxxum, itmaxyum),(cxum, cyum) return (itmax, itmaxxum, itmaxyum),(cxum, cyum)
\ No newline at end of file
...@@ -77,7 +77,7 @@ modei = {'Off': False, 'On': True} ...@@ -77,7 +77,7 @@ modei = {'Off': False, 'On': True}
class Interferometer: class Interferometer:
#mendatory functions #mendatory functions
def __init__(self, config, blade = None, delay = None): def __init__(self, config, BladePositioning, DelayGenerator):
#fixed variables #fixed variables
self.X_nozzle=1300 self.X_nozzle=1300
...@@ -94,8 +94,8 @@ class Interferometer: ...@@ -94,8 +94,8 @@ class Interferometer:
self.config = config self.config = config
self.blade = blade self.blade = BladePositioning
self.delay = delay self.delay = DelayGenerator
self.plot_server_im = None self.plot_server_im = None
self.plot_server_ph = None self.plot_server_ph = None
...@@ -170,7 +170,7 @@ class Interferometer: ...@@ -170,7 +170,7 @@ class Interferometer:
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})
blade_config0 = self.blade.get_config() blade_config0 = self.blade.config
global t_begin global t_begin
t_begin = t.time() t_begin = t.time()
...@@ -217,7 +217,6 @@ class Interferometer: ...@@ -217,7 +217,6 @@ class Interferometer:
def plot_measure(self, measurement, config = None): def plot_measure(self, measurement, config = None):
if self.Tomography: if self.Tomography:
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})
...@@ -254,7 +253,6 @@ class Interferometer: ...@@ -254,7 +253,6 @@ class Interferometer:
x0 = self.x0 x0 = self.x0
z0 = self.z0 z0 = self.z0
from PlottingServers import Plot2DServer
if self.plot_server_im == None: if self.plot_server_im == None:
self.plot_server_im = Plot2DServer({'title':'Interferometer Image', 'xlabel':'z [mm]', 'ylabel': 'x [mm]','image': True}) self.plot_server_im = Plot2DServer({'title':'Interferometer Image', 'xlabel':'z [mm]', 'ylabel': 'x [mm]','image': True})
...@@ -364,7 +362,7 @@ class Interferometer: ...@@ -364,7 +362,7 @@ class Interferometer:
print ('Angle ',angle) print ('Angle ',angle)
blade_config1['pos_R'] = blade_config0['pos_R'] + angle blade_config1['pos_R'] = blade_config0['pos_R'] + angle
self.blade.set_config(blade_config1) self.blade.config = blade_config1
print ('Time [Drive to angle ',angle,'] = ', t.time() - t_begin) print ('Time [Drive to angle ',angle,'] = ', t.time() - t_begin)
if p: if p:
p.join() p.join()
...@@ -396,7 +394,7 @@ class Interferometer: ...@@ -396,7 +394,7 @@ class Interferometer:
np.save("Data/Interferometer/images_angles.npy", {'images_angles': images_angles, 'angles': angles}) np.save("Data/Interferometer/images_angles.npy", {'images_angles': images_angles, 'angles': angles})
self.blade.set_config(blade_config0) self.blade.config = blade_config0
print ('Time [Drive to angle 0] = ', t.time() - t_begin) print ('Time [Drive to angle 0] = ', t.time() - t_begin)
......
...@@ -59,7 +59,7 @@ class Laser: ...@@ -59,7 +59,7 @@ class Laser:
return 100 * np.cos((phi - self.max_angle)/90*np.pi) return 100 * np.cos((phi - self.max_angle)/90*np.pi)
def set_lin_comp(self, pos): def set_lin_comp(self, pos):
print (self.old_comp_lin, pos) #print (self.old_comp_lin, pos)
if self.old_comp_lin == pos: if self.old_comp_lin == pos:
return return
caput('F10HU-LMOT705:MOT.VAL', pos) caput('F10HU-LMOT705:MOT.VAL', pos)
......
...@@ -10,12 +10,20 @@ config file: ...@@ -10,12 +10,20 @@ config file:
pos_Pay: current position of motor Pay pos_Pay: current position of motor Pay
pos_Paz: current position of motor Paz pos_Paz: current position of motor Paz
home_on_connect: boolean
n_av: number of focus measurements per iteration
maxiter: maximal number of iterations
minint: minimal intensity to search for beam
measurement file (n.a) measurement file (n.a)
''' '''
default_config = {'pos_Pay': 3.99396444, default_config = {'pos_Pay': 3.99396444,
'pos_Paz': 5.16051188} 'pos_Paz': 5.16051188,
'home_on_connect':True,
'n_av': 10,
'maxiter':20}
class ParabolicMirror: class ParabolicMirror:
def __init__(self, config, FocusCamera, Periscope, Laser): def __init__(self, config, FocusCamera, Periscope, Laser):
...@@ -33,8 +41,8 @@ class ParabolicMirror: ...@@ -33,8 +41,8 @@ class ParabolicMirror:
except: except:
print ('Connection to motors failed. Close all programs that'+' use the motors or restart the controllers') print ('Connection to motors failed. Close all programs that'+' use the motors or restart the controllers')
raise raise
if home: if config['home_on_connect']:
self.home() self.home()
self.config = config self.config = config
...@@ -44,7 +52,10 @@ class ParabolicMirror: ...@@ -44,7 +52,10 @@ class ParabolicMirror:
config = {} config = {}
config['pos_Pay'] = float(self.Pay.position()) config['pos_Pay'] = float(self.Pay.position())
config['pos_Paz'] = float(self.Paz.position()) config['pos_Paz'] = float(self.Paz.position())
config['home_on_connect'] = self.home_on_connect
config['n_av'] = self.n_av
config['maxiter'] = self.maxiter
return config return config
@config.setter @config.setter
...@@ -52,7 +63,9 @@ class ParabolicMirror: ...@@ -52,7 +63,9 @@ class ParabolicMirror:
self.Pay.goto(config['pos_Pay']) self.Pay.goto(config['pos_Pay'])
self.Paz.goto(config['pos_Paz']) self.Paz.goto(config['pos_Paz'])
self.n_av = config['n_av']
self.maxiter = config['maxiter']
self.home_on_connect = config['home_on_connect']
def connect_motors(self): def connect_motors(self):
...@@ -70,11 +83,16 @@ class ParabolicMirror: ...@@ -70,11 +83,16 @@ class ParabolicMirror:
self.optimize() self.optimize()
def optimize(self, wanted_focus_um = 8, n_av = 1, sleep_time = 0.2, output = True, maxiter = 100): def optimize(self, wanted_focus_um = 8, sleep_time = 0.2, output = True):
#this variable is necessary to compensate the attenuation of the laser #this variable is necessary to compensate the attenuation of the laser
global intmult global intmult
intmult = 1. intmult = 1.
maxiter = self.maxiter
n_av = self.n_av
global reduce_int global reduce_int
reduce_int = False reduce_int = False
def to_min(): def to_min():
...@@ -84,14 +102,14 @@ class ParabolicMirror: ...@@ -84,14 +102,14 @@ class ParabolicMirror:
FWHMys = [] FWHMys = []
maxints = [] maxints = []
for i in range(n_av): for i in range(n_av):
measurement = focus.measure() measurement = self.focus.measure()
FWHMxs.append(measurement['FWHMx']) FWHMxs.append(measurement['FWHMx'])
FWHMys.append(measurement['FWHMy']) FWHMys.append(measurement['FWHMy'])
maxints.append(measurement['maxit']) maxints.append(measurement['maxit'])
#if output: if output:
# focus.plot_measure(measurement) self.focus.plot_measure(measurement)
# plt.pause(0.01)
del measurement del measurement
if output: if output:
print ('FWHMxs: ',FWHMxs) print ('FWHMxs: ',FWHMxs)
...@@ -99,7 +117,7 @@ class ParabolicMirror: ...@@ -99,7 +117,7 @@ class ParabolicMirror:
print ('maxints: ',maxints) print ('maxints: ',maxints)
print ('mean(maxits): ',np.mean(maxints)) print ('mean(maxits): ',np.mean(maxints))
res = (np.array(FWHMxs)**2 + np.array(FWHMys)**2)/2#*4096/np.array(maxints)*intmult res = np.sqrt((np.array(FWHMxs)**2 + np.array(FWHMys)**2)/2)#*4096/np.array(maxints)*intmult
mean, error = np.mean(res), np.std(res, ddof = -1)/np.sqrt(len(res)) mean, error = np.mean(res), np.std(res, ddof = -1)/np.sqrt(len(res))
global reduce_int global reduce_int
if np.mean(maxints) > 4e3: if np.mean(maxints) > 4e3:
...@@ -109,7 +127,7 @@ class ParabolicMirror: ...@@ -109,7 +127,7 @@ class ParabolicMirror:
if output: if output:
print ('mean: ',mean,'error: ', error) print ('mean: ',mean,'error: ', error)
if mean*1e3 < wanted_focus_um: