80 lines
2.6 KiB
Python
80 lines
2.6 KiB
Python
slits = ['Primaries horizontal','Primaries Vertical',
|
|
'ExpBox Tert. horizontal ','ExpBox Tert. vertical',
|
|
'ExpBox Quart. horizontal','ExpBox Quart. vertical']
|
|
|
|
ev = get_string('Please select slits', None, slits)
|
|
if ev is None:
|
|
raise Exception("Aborted")
|
|
|
|
elif ev == slits[0]: #Primaries-Horizontal after collimating mirror and before mono
|
|
mmot = phs # slit size
|
|
smot = phc # slit centre
|
|
r = 10.0 # scan half range
|
|
pclose = r/10. # slit size for scan
|
|
popen = 12.0 # slit size in open position
|
|
detector = mono_beam
|
|
#MESSAGE,'Not ready yet',/cont
|
|
elif ev == slits[0]: #Primaries-Vertical before collimating mirror
|
|
mmot = pvs
|
|
smot = pvc
|
|
r = 2.0
|
|
pclose = r/10.
|
|
popen = 2.0
|
|
detector = mono_beam
|
|
#MESSAGE,'Not ready yet',/cont
|
|
elif ev == slits[2]: #Exposure box Tertiary slits-Horizontal before IO
|
|
mmot = ths
|
|
smot = thc
|
|
r = 1.0
|
|
pclose = r/10.0
|
|
popen = 1.0
|
|
detector = Channel('X06DA-ES-BM:I0', 'd')
|
|
elif ev == slits[0]: #Exposure box Tertiary slits-Vertical
|
|
mmot = tvs
|
|
smot = tvc
|
|
r = 0.4
|
|
pclose = r/4.
|
|
popen = .4
|
|
detector = Channel('X06DA-ES-BM:I0', 'd')
|
|
elif ev == slits[0]: #Exposure box Quartenary slits-Horizontal after I0
|
|
mmot = qhs
|
|
smot = qhc
|
|
r = 0.4
|
|
pclose = r/8.
|
|
popen = .40
|
|
detector = marcover
|
|
#MESSAGE,'To make sure the diode is connected',/cont
|
|
elif ev == slits[5]: #Exposure box Quartenary slits-Vertical
|
|
mmot = qvs
|
|
smot = qvc
|
|
r = 0.3
|
|
pclose = r/6.
|
|
popen = .20
|
|
detector = mono_beam
|
|
#MESSAGE,'To make sure the diode is connected',/cont
|
|
|
|
mmot.write(pclose)
|
|
result = lscan(smot, detector, -r,r, 20, latency = 0.5, relative = True) #SCAN,smot,-r,r,20,data=d,gfit=a,time=.5,detec=detector
|
|
(ydata, xdata) = (result.getReadable(0), result.getPositions(0))
|
|
|
|
ydata = [x*1e6 for x in ydata]
|
|
maxy = max(ydata) #MAX(y,im)
|
|
cen =sum([ydata[i] * xdata[i] for i in range(len(ydata))]) / sum(ydata) #TOTAL(x*y) / TOTAL(y) #TODO: is right?
|
|
|
|
|
|
|
|
#OPLOT,x,GAUSSFIT(x,y,a,ESTIMATES = [maxy,cen,pclose,0,0,0],nterms=6)*1e-6, color=240,psym=6
|
|
(n, m, s) = fit(ydata, xdata)
|
|
|
|
#help,mmot
|
|
mmot.write(popen)
|
|
|
|
if abs(m) < 1 and abs(m-cen) < 0.5: #TODO: is a(1) the mean?
|
|
print 'moving centre of slits to: ', m
|
|
smot.mov(m)
|
|
else:
|
|
#PLOTS,cen,[0,maxy]*1e6,color=240,linestyle=1 : #TODO ?
|
|
msg='fit failed - do you want to drive to centre of mass position: '+ cen +' ?'
|
|
if get_option(msg, 'YesNo') == 'Yes':
|
|
smot.mov(cen)
|