Files
x11ma/script/EnergyScan.py
2015-12-03 03:25:22 +01:00

114 lines
2.5 KiB
Python

import os
import traceback
file_prefix = time.strftime("%y%m%d")
input_path = "/sls/X11MA/Data1/public/X11MA/temp/"+file_prefix+"/"
output_path = input_path #+file_prefix+"/" #"/sls/X11MA/Data1/public/e10989/"+file_prefix+"/"
#Parameters
"""
E1 = 680
E2 = 750
TIME = 2 #min
DELAY = 10.0 #s
OFFSET1 = 1.0 #eV
OFFSET2 = -1.0 #eV
PREFIX = 'Data'
RUNTYPE = "+/-"
ROUNDS = 1
"""
print "\nStarting energy scan - Parameters: ",
print E1,E2,TIME,DELAY,OFFSET1,OFFSET2,RUNTYPE #,ALPHA
#fid = caget(OTF_FID, 'i')
def switchpol(activeID):
global pol_str
if activeID == 1:
caput(OTF_OFF1,OFFSET1)
caput(OTF_OFF2,OFFSET2-40) #detune ID2
pol_str = "circ +"
elif activeID == 2:
caput(OTF_OFF1,OFFSET1-40) #detune ID1
caput(OTF_OFF2,OFFSET2)
pol_str = "circ -"
else:
raise Exception("Invalid parameter")
pol_str = None
polswitch = 1
fid = get_next_fid(input_path, "o" + file_prefix)
#Prepare scan
number_of_scans = 1
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
else:
raise Exception("Invalid run type: " + RUNTYPE)
if RUNTYPE == "-":
switchpol(2) # tune ID2 --> polarization: C-
else:
switchpol(1) # tune ID1 --> polarization: C+
time.sleep(1.0)
wait_channel(OTF_DONE, 1, type = 'i')
open_vg10()
open_vg13()
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)
#Start the OTF scan
caput(OTF_START, 'GO')
#Wait until scan is done
wait_channel(OTF_START, 'STOP', type = 's')
time.sleep(3.0)
#Convert file
output_file = output_path+"os"+file_prefix+"_" + suffix + ".dat"
print("Converting data file: " + output_file);
convert_file(input_file, output_file, pol_str)
plot_file(output_file, file_prefix+"_" + suffix) #"Scan " + str(scan_no+1))
if polswitch == 1:
switchpol(2) # tune ID2 --> polarization:C-
polswitch = 0
else:
polswitch = 1
time.sleep(3.0)
fid = fid + 1
close_vg13()
print "Finished Energy scan"
print("Success")