212 lines
5.5 KiB
Python
Executable File
212 lines
5.5 KiB
Python
Executable File
file_prefix = time.strftime("%Y%m%d")
|
|
# CHANGE THE PATH IN THE OTH
|
|
input_path = "/sls/X11MA/data/X11MA/Data1/public/scans/1809_Armin/"
|
|
#input_path = "/sls/X11MA/data/X11MA/slsbl/x11ma/e17174/Data1/Aug_2018/sample02-LMNO_pristine/"
|
|
|
|
output_path = input_path
|
|
|
|
#Parameters
|
|
E1 = sys.argv[0]
|
|
E2 = sys.argv[1]
|
|
TIME = sys.argv[2]
|
|
DELAY = sys.argv[3]
|
|
|
|
number_of_scans = 1
|
|
ID1=0
|
|
ID2=1
|
|
OFFSET1 = -2.0 #eV
|
|
OFFSET2 = -2.9 #eV
|
|
PREFIX = 'Data'
|
|
RUNTYPE = "LH"
|
|
ROUNDS = 1
|
|
PLOT_TYPE = 1
|
|
|
|
print "\nStarting energy scan - Parameters: ",
|
|
print E1,E2,TIME,DELAY,OFFSET1,OFFSET2,RUNTYPE#,ALPHA1,ALPHA2
|
|
|
|
caput(OTF_ESET, E1)
|
|
|
|
###############################################################################
|
|
# Plotting
|
|
###############################################################################
|
|
|
|
task = None
|
|
running = False
|
|
|
|
|
|
def _startPlot(type):
|
|
global running
|
|
sep = "\t"
|
|
line_sep = "\r\n"
|
|
print "Starting plot: type " + str(type)
|
|
running = True
|
|
p = plot(None,name="Energy")[0]
|
|
s = p.getSeries(0)
|
|
cur = 0
|
|
time.sleep(3.0)
|
|
t_start = time.time()
|
|
t_end = time.time() + TIME*60.0
|
|
while running:
|
|
try:
|
|
#if otf_start.read() == 0:
|
|
if (otf_start.read() == 0 or time.time() > t_end):
|
|
break
|
|
e = energy.read()
|
|
|
|
if (abs(e-cur)) > 0.1:
|
|
v = abs((keithley_3a.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)
|
|
|
|
|
|
############################PGM+ID1+ID2###################################################
|
|
|
|
|
|
def switchpol(activeID, runtype):
|
|
global pol_str
|
|
if activeID == 1:
|
|
caput(OTF_OFF1,OFFSET1)
|
|
caput(OTF_OFF2,OFFSET2-40) #detune ID2
|
|
if runtype in ["+/-", "+"]:
|
|
pol_str = "circ +"
|
|
elif runtype in ["LH/LV", "LH"]:
|
|
pol_str = "Lin. Horizontal"
|
|
elif activeID == 2:
|
|
caput(OTF_OFF1,OFFSET1-40) #detune ID1
|
|
caput(OTF_OFF2,OFFSET2)
|
|
if runtype in ["+/-", "-"]:
|
|
pol_str = "circ -"
|
|
elif runtype in ["LH/LV", "LV"]:
|
|
pol_str = "Lin. Vertical"
|
|
else:
|
|
raise Exception("Invalid parameter")
|
|
|
|
mag_str = None
|
|
#mag_str = caget(MAG)
|
|
pol_str = None
|
|
polswitch = 1
|
|
|
|
fid = get_next_fid(input_path, "o" + file_prefix)
|
|
|
|
|
|
###############################################################################
|
|
#Prepare scan
|
|
###############################################################################
|
|
|
|
|
|
"""
|
|
if ID1 == 1:
|
|
caput ("X11PHS-E:OPT","PGM+ID1")
|
|
elif ID2 == 1:
|
|
caput ("X11PHS-E:OPT","PGM+ID2")
|
|
else:
|
|
caput ("X11PHS-E:OPT","PGM+ID1+ID2")
|
|
|
|
|
|
if RUNTYPE in ["+/-", "+", "-"]:
|
|
caput(OTF_MODE1,1) # circ + in ID1
|
|
caput(OTF_MODE2,2) # circ - in ID2
|
|
wait_channel(OTF_DONE, 1, type = 'i')
|
|
if RUNTYPE == "+/-":
|
|
number_of_scans = 2 * ROUNDS
|
|
else:
|
|
number_of_scans = ROUNDS
|
|
elif RUNTYPE in ["LH/LV", "LH", "LV"]:
|
|
caput(OTF_MODE1,0)
|
|
caput(OTF_MODE2,0)
|
|
wait_channel(OTF_DONE, 1, type = 'i')
|
|
caput(OTF_ALPHA1, 0.0) # LH in ID1
|
|
caput(OTF_ALPHA2, 90.0) # LV in ID2
|
|
wait_channel(OTF_DONE, 1, type = 'i')
|
|
if RUNTYPE == "LH/LV":
|
|
number_of_scans = 2 * ROUNDS
|
|
else:
|
|
number_of_scans = ROUNDS
|
|
else:
|
|
raise Exception("Invalid run type: " + RUNTYPE)
|
|
|
|
if RUNTYPE in ["-", "LV"]:
|
|
switchpol(2, RUNTYPE) # tune ID2 --> polarization: C- or LV
|
|
polswitch = 0
|
|
elif RUNTYPE in ["+/-", "+", "LH/LV", "LH"]:
|
|
switchpol(1, RUNTYPE) # tune ID1 --> polarization: C+ or LH
|
|
time.sleep(1.0)
|
|
|
|
wait_channel(OTF_DONE, 1, type = 'i')
|
|
"""
|
|
open_vg10()
|
|
time.sleep(0.5)
|
|
open_vg11()
|
|
time.sleep(0.5)
|
|
open_vg12()
|
|
time.sleep(0.5)
|
|
open_vg13()
|
|
|
|
for scan_no in range(number_of_scans):
|
|
suffix = ("%03d" % fid)
|
|
input_file = input_path + "o" + file_prefix + "_" + suffix + ".dat"
|
|
# Log.append(scan_no+1)
|
|
#Log.append(posX)
|
|
sep = "\t"
|
|
line_sep = "\r\n"
|
|
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)
|
|
T_start = Temp.getValue()
|
|
startPlot(PLOT_TYPE)
|
|
#Start the OTF scan
|
|
#caput(OTF_START, 'GO')
|
|
otf_start.write(1)
|
|
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()
|
|
# caput(OTF_ESET, E1)
|
|
T_end = Temp.getValue()
|
|
time.sleep(5.0)
|
|
#Convert file
|
|
output_file = output_path + "os" + file_prefix + "_" + suffix + ".dat"
|
|
|
|
print("Converting data file: " + output_file);
|
|
convert_file(input_file, output_file)
|
|
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")
|
|
|