167 lines
3.9 KiB
Python
167 lines
3.9 KiB
Python
#Script imported and adopted from: XTREME beamline
|
|
import time
|
|
|
|
#Parameters
|
|
"""
|
|
E1 = 800
|
|
E2 = 590
|
|
TIME = 1 #min
|
|
DELAY = 2.0 #s
|
|
MODE = 'CIRC +'
|
|
OFFSET = -9.0
|
|
FOLDER = '/sls/X11MA/data/X11MA/XAS/20190930/o_XAS_NCM111'
|
|
FILE = 'pshell-test'
|
|
ALPHA=0
|
|
"""
|
|
|
|
count.initialize()
|
|
data.initialize()
|
|
fdata.initialize()
|
|
idata.initialize()
|
|
edata.initialize()
|
|
|
|
p=None
|
|
def start_plot():
|
|
global p
|
|
p = plot([None, None, None,None, None], ["TEY", "TFY", "TEYraw", "TFYraw", "I0"])
|
|
|
|
def update_plot():
|
|
global p
|
|
c = count.take()
|
|
if c is None:
|
|
for i in range(len(p)):
|
|
p[i].getSeries(0).clear()
|
|
else:
|
|
data.setSize(c)
|
|
fdata.setSize(c)
|
|
idata.setSize(c)
|
|
edata.setSize(c)
|
|
teyr= idata.read()
|
|
tfyr= fdata.read()
|
|
i0 = data.read()
|
|
x = edata.read()
|
|
#from operator import truediv
|
|
l = lambda x,y: (0.0 if (y==0.0) else x/y) #truediv
|
|
tey=map(l, teyr, i0)
|
|
tfy=map(l, tfyr, i0)
|
|
p[0].getSeries(0).setData(x, to_array(tey,'d'))
|
|
p[1].getSeries(0).setData(x, to_array(tfy,'d'))
|
|
p[2].getSeries(0).setData(x, to_array(teyr,'d'))
|
|
p[3].getSeries(0).setData(x, to_array(tfyr,'d'))
|
|
p[4].getSeries(0).setData(x, to_array(i0,'d'))
|
|
|
|
|
|
print "\nStart energy scan..."
|
|
|
|
if MODE == "LINEAR":
|
|
print E1,"eV ->",E2,"eV,",TIME,"min duration,",DELAY,"sec delay,",str(MODE),str(ALPHA),"deg"
|
|
else:
|
|
print E1,"eV ->",E2,"eV,",TIME,"min duration,",DELAY,"sec delay,",str(MODE)
|
|
|
|
start = time.localtime()
|
|
|
|
folder = os.path.expanduser("~/Data1/") + FOLDER + "/";
|
|
|
|
#print "folder = ",folder
|
|
|
|
def getNewestFile():
|
|
global folder
|
|
import glob
|
|
try:
|
|
return max(glob.glob(folder+'/*.txt'), key=os.path.getctime)
|
|
except:
|
|
return None
|
|
newest = getNewestFile()
|
|
|
|
#Checking the beam
|
|
#if not has_beam():
|
|
# print "Maintenence mode: end of scan"
|
|
# sys.exit()
|
|
|
|
|
|
if MODE is not None:
|
|
pol_mode.write(MODE)
|
|
if MODE == 'LINEAR':
|
|
if ALPHA is not None:
|
|
pol_angle.write(ALPHA)
|
|
|
|
if OFFSET is not None:
|
|
pol_offset.write(OFFSET)
|
|
|
|
wait_device(pol_done, "DONE")
|
|
|
|
#################
|
|
energy.write(float(E1))
|
|
wait_channel(ALL_DONE, 1, type = 'i')
|
|
|
|
|
|
caput('E1', E1)
|
|
caput('E2', E2)
|
|
caput('TIME', TIME)
|
|
caput('FOLDER', FOLDER)
|
|
caput('FILE', FILE)
|
|
time.sleep(0.1)
|
|
|
|
time.sleep(DELAY)
|
|
|
|
caput('START', '1')
|
|
|
|
try:
|
|
|
|
waiting = True
|
|
def plot_task():
|
|
global waiting
|
|
pos=count.take()
|
|
start_plot()
|
|
while waiting:
|
|
if count.take() != pos:
|
|
update_plot()
|
|
pos = count.take()
|
|
time.sleep(2.0)
|
|
|
|
ret = fork(plot_task)
|
|
try:
|
|
print "Scanning...",
|
|
#Post-actions
|
|
wait_channel('START', 'STOP', type = 's')
|
|
after_sample() #To call check_id_error()
|
|
time.sleep(2.0)
|
|
print "Finished Energy scan."
|
|
finally:
|
|
waiting = False
|
|
join(ret)
|
|
|
|
|
|
#File convertion
|
|
#newName = folder + time.strftime("%Y%m%d_%H%M_", start) + FILE + "_0000.txt";
|
|
#newName = get_exec_pars().path + "/" + time.strftime("%Y%m%d_%H%M_", start) + FILE + ".txt";
|
|
|
|
import time
|
|
try:
|
|
os.makedirs(get_exec_pars().path)
|
|
except:
|
|
pass
|
|
newName = get_exec_pars().path + "/" + time.strftime("%Y%m%d_%H%M_", start) + FILE + ".txt";
|
|
|
|
name = getNewestFile()
|
|
|
|
if name == newest:
|
|
print "Risk of overwriting. " + name + " same as " + newest
|
|
raise Exception("Data file not created.")
|
|
|
|
if not os.path.isfile(name):
|
|
raise Exception("Data file not found: " + name)
|
|
|
|
convert_file(name, newName)
|
|
|
|
plot_file(newName)
|
|
print("Success")
|
|
|
|
except:
|
|
print("Aborting...")
|
|
while caget('START') == 'START':
|
|
caput('START', '0')
|
|
time.sleep(0.1)
|
|
raise
|
|
|