From 76ec68450f4b5d04308e35b3a9de116978aaf583 Mon Sep 17 00:00:00 2001 From: panepucci Date: Fri, 18 Dec 2015 11:10:52 +0100 Subject: [PATCH] Closedown --- script/local.py | 57 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/script/local.py b/script/local.py index f4ca0ed..b529d1c 100644 --- a/script/local.py +++ b/script/local.py @@ -64,10 +64,59 @@ def fit(ydata, xdata = None): #fit([1,2,3, 3,3,3,4,5,6,12,33,23,15,3,2,1, 1, 1, 1, 1]) -def rock(axis = None): - from rock import rock - rock() - #run("rock", {"rock_axis":None}) +#def rock(axis = None): +# from rock import rock +# rock() +# #run("rock", {"rock_axis":None}) + + +def rock(axis = th1, ffail = False, tt = 0.2, seti0 = False, dx = None, noref = False): + """ + """ + if axis is None: + axis = th1 + if noref == False: + caput('X06DA-OP-MO:MONOBEAM', -1 ) + e = get_energy() + if dx is None: + dx = 7.5e-2/e + + # reinforce theta1 and 2 setting (setting could be RDBD 0.0001 and RTRY 1 when seteq does not finish nicely) + # put 'Retry deadband' to 0.00004 and 'Retries Max' to 5 + time.sleep(0.2) + caput('X06DA-OP-MO1:ROX1.RDBD',0.00004) + caput('X06DA-OP-MO1:ROX2.RDBD',0.00004) + caput('X06DA-OP-MO1:ROX1.RTRY',5) + caput('X06DA-OP-MO1:ROX2.RTRY',5) + + #time stamp + print time.strftime('%X %x') + + #MVR,axis,-dx + #SCAN,axis,0,2*dx,20,/fit,/centre,SILENT = silent,FFAIL = ffail,time=tt,/deriv,$ + #data=d + axis_pos = axis.read() + result = lscan(axis, mono_beam, -dx, dx, 20, latency = 0.3, relative = True, context = None, before_read = None, after_read = None) + (ydata, xdata) = (result.getReadable(0), result.getPositions(0)) + (norm, mean, sigma) = fit(ydata, xdata) + if (mean is not None) and (mean <= (axis_pos + dx)) and (mean >= (axis_pos - dx)): + axis.move(mean) + else: + print 'fit failed - centering on maximum' + max_x= xdata[ydata.index(max(ydata))] + axis.move(max_x) + + if seti0 and not ffail: + time.sleep(2) + run("setI0") + #add after_rock BPM1:SUM as reference for monitoring monochromator thermal drift + if (noref==False) and not ffail: + time.sleep(3) # wait a bit until mono theta finish moving + br = mono_beam.read() + caput('X06DA-OP-MO:MONOBEAM', br) + print 'rock_success new mono beam at ' + str(br) + ' at' + str(e) + ' keV' + + #from rock import rock