Files
x11ma/script/old_scripts/EnergyScanID2only_XMLD.py
gac-x11ma 329ac0a48f Startup
2019-05-09 15:35:32 +02:00

163 lines
4.5 KiB
Python

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 = 520
E2 = 530
TIME = 0.5 #min
DELAY = 1.0 #s
#PREFIX = 'Data'
RUNTYPE = "LV"
ROUNDS = 1
OFFSETH = -4
OFFSETV = -5
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/fechner_beamtime/"+file_prefix+"/"
input_path = "/sls/X11MA/data/X11MA/fechner_beamtime/"
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')/sls/X11MA/datmokuser/
if RUNTYPE in ["LH", "LV"]:
if RUNTYPE == "LH":
caput(OTF_MODE2,0)
wait_channel(OTF_DONE, 1, type = 'i')
caput(OTF_ALPHA2, 0.0) # LH in ID1
caput(OTF_OFF2,OFFSETH)
number_of_scans = ROUNDS
elif RUNTYPE == "LV":
caput(OTF_MODE2,0) # circ- in ID2
wait_channel(OTF_DONE, 1, type = 'i')
caput(OTF_ALPHA2, 90.0) # LH in ID1
caput(OTF_OFF2,OFFSETV)
number_of_scans = ROUNDS
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"
pol_str = caget(OTF_MODE2)+" "+str(caget(OTF_ALPHA2))
print("Converting data file: " + output_file);
mag_str = caget(MAG)
#convert_file(input_file, output_file, mag_str, pol_str)
convert_file(input_file, output_file, mag_str, pol_str,keithley_3=1) # tey and tfy saved - not normalized
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")