Files
x11ma/script/templates/DelayScanBasic.py
2021-03-12 12:19:10 +01:00

127 lines
4.0 KiB
Python
Executable File

print "\nStarting delay scan - Parameters: ",
print START,END,STEP,ENERGIES,ROUNDS, RUNTYPE
run("utils")
polswitch = 1
####################### Set Delay and fine delay function #####################
LPP_DELAY_NEW = 0
LPP_FINE_DELAY_NEW = 0
def Convert_LPP_Delays(NewDelay):
global LPP_DELAY_NEW, LPP_FINE_DELAY_NEW
LPP_DELAY_NEW = math.trunc(((-NewDelay*100.0+DELAY*(1E9/SLS_freq.read())*100+FINEDELAY)/100.0)/(1E9/SLS_freq.read()))
LPP_FINE_DELAY_NEW = math.trunc(-NewDelay*100.0+DELAY*1E9/SLS_freq.read()*100+FINEDELAY-LPP_DELAY_NEW*(1E9/SLS_freq.read()*100.0))
def Timing(New_Time):
caput (TIME_DELAY_SET, New_Time)
caput (TIME_DELAY_START, 1)
Convert_LPP_Delays(New_Time)
caput (LPP_DELAY, LPP_DELAY_NEW)
caput (LPP_FINE_DELAY, LPP_FINE_DELAY_NEW)
wait_channel(TIME_DELAY_COMPLETE, 'SCAN Complete', timeout=10+abs((caget(TIME_DELAY_SET, type='d')-caget(TIME_DELAY_VAL, type='d')))*10)
##################### Setting filenames #######################################
file_prefix = time.strftime("%y%m%d")
sep = "\t"
line_sep = "\r\n"
input_path = PATH
output_path = input_path
###############################################################################
#Prepare scan
###############################################################################
x=ENERGIES
y = []
x=x.split(',')
for i in x:
y.append(float(i))
caput ("X11PHS-E:OPT","PGM+ID1+ID2")
if RUNTYPE in ["+/-", "+", "-"]:
caput(ID1_MODE,1) # circ + in ID1
caput(ID2_MODE,2) # circ - in ID2
wait_channel(All_DONE, 1, type = 'i')
if RUNTYPE == "+/-":
number_of_scans = 2 * ROUNDS
else:
number_of_scans = ROUNDS
elif RUNTYPE in ["LH/LV", "LH", "LV"]:
caput(ID1_MODE,0)
caput(ID2_MODE,0)
wait_channel(ALL_DONE, 1, type = 'i')
caput(ID1_ALPHA, 0.0) # LH in ID1
caput(ID2_ALPHA, 90.0) # LV in ID2
wait_channel(ALL_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)
caput (TIME_DELAY_SET, START)
caput (TIME_DELAY_START, 1)
if START == 0:
caput (LPP_DELAY, DELAY)
caput (LPP_FINE_DELAY, FINEDELAY)
wait_channel(TIME_DELAY_COMPLETE, 'SCAN Complete', timeout= 10)
else:
Convert_LPP_Delays(caget(TIME_DELAY_SET, type='d'))
caput (LPP_DELAY, LPP_DELAY_NEW)
caput (LPP_FINE_DELAY, LPP_FINE_DELAY_NEW)
wait_channel(TIME_DELAY_COMPLETE, 'SCAN Complete', timeout= abs((caget(TIME_DELAY_SET, type='d')-caget(TIME_DELAY_VAL, type='d')))*10)
###############################################################################
#DAQ function
###############################################################################
def Daq():
# Your Data Aquisition function
###############################################################################
# Scanning
###############################################################################
for scan_no in range(number_of_scans):
print "Running polarisation " + str(scan_no+1) + " out of " + str(number_of_scans)
Delay_Time = START
while Delay_Time <= END:
Timing(Delay_Time)
for en in y:
caput(ENERGY_SP,en)
wait_channel(ALL_DONE, 1, type = 'i')
Daq(Delay_Time)
Delay_Time += STEP
print "Finished polarisation " + str(scan_no+1) + " out of " + str(number_of_scans)
if RUNTYPE in ["+/-", "LH/LV"]:
if polswitch == 1:
switchpol(2, RUNTYPE) # tune ID2 --> polarization: C- or LV
polswitch = 0
else:
polswitch = 1
switchpol(1, RUNTYPE) # tune ID1 --> polarization: C+ or LH
else:
print "running in one polarization mode"
print "Finished Delay scan"