Script execution
This commit is contained in:
182
script/EnergyScanID2andID2only.py
Normal file
182
script/EnergyScanID2andID2only.py
Normal file
@@ -0,0 +1,182 @@
|
||||
import os
|
||||
import traceback
|
||||
import thread
|
||||
|
||||
###############################################################################
|
||||
# Plotting
|
||||
###############################################################################
|
||||
|
||||
task = None
|
||||
running = False
|
||||
|
||||
|
||||
def _startPlot(type):
|
||||
global running
|
||||
print "Starting plot: type " + str(type)
|
||||
running = True
|
||||
p = plot(None,name="Energy")[0]
|
||||
s = p.getSeries(0)
|
||||
cur = 0
|
||||
time.sleep(3.0)
|
||||
while running:
|
||||
try:
|
||||
if otf_start.read() == 0:
|
||||
break
|
||||
e = energy.read()
|
||||
if (abs(e-cur)) > 0.1:
|
||||
v = abs((keithley_2a.read() / ((keithley_1a if (type==1) else keithley_3a).read() )))
|
||||
s.appendData(e,v)
|
||||
cur = e
|
||||
time.sleep(0.2)
|
||||
except:
|
||||
pass
|
||||
print "Done Plotting"
|
||||
|
||||
def startPlot(type = 1):
|
||||
global task
|
||||
task = fork((_startPlot,(type,)),)
|
||||
|
||||
def stopPlot():
|
||||
global task, running
|
||||
running = False
|
||||
ret = join(task)
|
||||
|
||||
###############################################################################
|
||||
# Parameters
|
||||
###############################################################################
|
||||
|
||||
|
||||
E1 = 770
|
||||
E2 = 815
|
||||
TIME = 4.0 #min
|
||||
DELAY = 20.0 #s
|
||||
#PREFIX = 'Data'
|
||||
RUNTYPE = "+"
|
||||
ROUNDS = 1
|
||||
OFFSETp = -12.5
|
||||
OFFSETm = -12.5
|
||||
OFFSETp_ID1 = -0.4
|
||||
PLOT_TYPE = 1
|
||||
|
||||
|
||||
print "\nStarting energy scan - Parameters: ",
|
||||
print E1,E2,TIME,DELAY,RUNTYPE
|
||||
|
||||
file_prefix = time.strftime("%y%m%d")
|
||||
input_path = "/sls/X11MA/data/X11MA/beamtime_oct2017/"+file_prefix+"/"
|
||||
output_path = input_path #+file_prefix+"/" #"/sls/X11MA/Data1/public/e10989/"+file_prefix+"/"
|
||||
pol_str = None
|
||||
mag_str = None
|
||||
fid = get_next_fid(input_path, "o" + file_prefix)
|
||||
number_of_scans = 1
|
||||
|
||||
###############################################################################
|
||||
#Prepare scan for PGM+ID2
|
||||
###############################################################################
|
||||
|
||||
caput ("X11PHS-E:OPT","PGM+ID2")
|
||||
#caput(OTF_OFF1,-40) #detune ID2
|
||||
#wait_channel(OTF_DONE, 1, type = 'i')
|
||||
|
||||
if RUNTYPE in ["+/-", "+", "-"]:
|
||||
if RUNTYPE == "+":
|
||||
caput(OTF_MODE2,1) # circ+ in ID2
|
||||
caput(OTF_MODE1,1) # circ+ in ID1
|
||||
caput(OTF_OFF2,OFFSETp) #offet of ID2 may be same or different for C+ and C-
|
||||
caput(OTF_OFF1,OFFSETp_ID1) #offset for ID1 may be same or different for C+ and C-
|
||||
number_of_scans = ROUNDS
|
||||
|
||||
elif RUNTYPE == "-":
|
||||
caput(OTF_MODE2,2) # circ- in ID2
|
||||
caput(OTF_OFF2,OFFSETm)
|
||||
number_of_scans = ROUNDS
|
||||
elif RUNTYPE == "+/-":
|
||||
caput(OTF_MODE2,1) # circ+ in ID2
|
||||
caput(OTF_OFF2,OFFSETp)
|
||||
number_of_scans = 2 * ROUNDS
|
||||
wait_channel(OTF_DONE, 1, type = 'i')
|
||||
|
||||
elif RUNTYPE in ["LH/LV", "LH", "LV"]:
|
||||
print "Wrong polarization selected!"
|
||||
|
||||
|
||||
else:
|
||||
raise Exception("Invalid run type: " + RUNTYPE)
|
||||
|
||||
open_vg10()
|
||||
time.sleep(0.5)
|
||||
open_vg11()
|
||||
time.sleep(0.5)
|
||||
open_vg12()
|
||||
time.sleep(0.5)
|
||||
open_vg13()
|
||||
|
||||
###############################################################################
|
||||
#Main scan loop
|
||||
###############################################################################
|
||||
|
||||
for scan_no in range(number_of_scans):
|
||||
suffix = ("%03d" % fid)
|
||||
input_file = input_path + "o" + file_prefix + "_" + suffix + ".dat"
|
||||
|
||||
caput(OTF_E1, E1)
|
||||
caput(OTF_E2, E2)
|
||||
caput(OTF_TIME, TIME)
|
||||
caput(OTF_FTS,file_prefix)
|
||||
caput(OTF_FID,fid)
|
||||
time.sleep(2.0)
|
||||
caput(OTF_ESET, E1)
|
||||
wait_channel(OTF_DONE, 1, type = 'i')
|
||||
time.sleep(DELAY)
|
||||
time.sleep(2.0)
|
||||
|
||||
startPlot(PLOT_TYPE)
|
||||
otf_start.write(1) #Start the OTF scan
|
||||
time.sleep(3.0)
|
||||
print "Running scan " + str(scan_no+1) + " out of " + str(number_of_scans)
|
||||
try:
|
||||
#wait_channel(OTF_START, 'STOP', timeout = int(TIME*60), type = 's')
|
||||
otf_start.waitValue(0, (15 + int(TIME*60)) *1000)
|
||||
except:
|
||||
print "******** OTF STOP TIMEOUT **********"
|
||||
otf_start.write(0)
|
||||
finally:
|
||||
stopPlot()
|
||||
|
||||
time.sleep(5.0)
|
||||
#TODO: wait for file instead of sleep
|
||||
#Convert file
|
||||
output_file = output_path + "os" + file_prefix + "_" + suffix + ".dat"
|
||||
|
||||
|
||||
|
||||
if RUNTYPE in ["+/-"]:
|
||||
pol_str = caget(OTF_MODE2)
|
||||
if pol_str == "CIRC +":
|
||||
caput(OTF_MODE2,2) # circ- in ID2
|
||||
caput(OTF_OFF2,OFFSETm)
|
||||
elif pol_str == "CIRC -":
|
||||
caput(OTF_MODE2,1) # circ+ in ID2
|
||||
caput(OTF_OFF2,OFFSETp)
|
||||
else: print "Check pol. change"
|
||||
wait_channel(OTF_DONE, 1, type = 'i')
|
||||
else:
|
||||
print "running in one polarization mode, no switching"
|
||||
pol_str = caget(OTF_MODE2)
|
||||
|
||||
print("Converting data file: " + output_file);
|
||||
mag_str = caget(MAG)
|
||||
convert_file(input_file, output_file, mag_str, pol_str)
|
||||
plot_file(output_file, file_prefix+"_" + suffix) #"Scan " + str(scan_no+1))
|
||||
print "Finished scan " + str(scan_no+1) + " out of " + str(number_of_scans)
|
||||
|
||||
time.sleep(3.0)
|
||||
fid = fid + 1
|
||||
|
||||
caput(OTF_ESET, E1)
|
||||
close_vg13()
|
||||
|
||||
print "Finished Energy scan"
|
||||
|
||||
print("Success")
|
||||
|
||||
Reference in New Issue
Block a user