Files
x11ma/script/templates/EnergyScan_v2.py
gac-x11ma 5225f36124 Tilt scan
2021-04-27 10:47:50 +02:00

101 lines
2.6 KiB
Python
Executable File

#Parameters
"""
E1 = 800
E2 = 820
TIME = 1 #min
DELAY = 0.1 #s
MODE = 'LINEAR'
OFFSET = 0.0
FOLDER = 'XAS/2020/11/SL-IN/'
FILE = 'test'
ALPHA=0.0
"""
print "\nStart energy scan..."
#print E1,E2,TIME,DELAY,str(MODE) ,str(OFFSET) ,str(FOLDER) ,str(FILE) ,str(ALPHA)
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)
folder = os.path.expanduser("~/Data1/") + FOLDER + "/";
set_exec_pars(name= FILE)
#Pre-actions
#if NO_BEAM_CHECK == False:
# print "Wait beam"
# wait_beam()
if MODE is not None:
pol_mode.write(MODE)
if MODE == 'LINEAR':
if ALPHA is not None:
pol_angle.write(ALPHA)
time.sleep(0.5)
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(DELAY)
caput('START', '1')
#Pseudo-devices
class Time(Readable):
def __init__(self):
self.start = time.time()
def read(self):
return time.time()-self.start
class NORMtey(Readable):
def read(self):
return float(CADC2.take())/float(CADC1.take())
class NORMdiode(Readable):
def read(self):
return float(CADC3.take())/float(CADC1.take())
scan_completed = False
try:
caput('START', '1')
sensors = [Ecrbk, CADC1, CADC2, CADC3, NORMtey(), NORMdiode()]
def monitoring_task():
global scan_completed
time.sleep(1.0)
try:
plot_titles = [ "I0", "TEYraw", "TFYraw", "TEY", "TFY"]
for index, title in enumerate(plot_titles, start=0): get_plots()[index].title = title
except:
pass
wait_channel('START', 'STOP', type = 's')
scan_completed = True
get_exec_pars().currentScan.abort()
ret = fork(monitoring_task)
print "Scanning...",
try:
mscan(Ecrbk, sensors, -1, None, range="auto", domain_axis="Ecrbk", enabled_plots = ["NORMtey", "NORMdiode", CADC1,CADC3, CADC2], )
finally:
ret[0].cancel(True)
print "Finished Energy scan."
except:
if not scan_completed:
print sys.exc_info()
print("Aborting...")
while caget('START') == 'START':
caput('START', '0')
time.sleep(0.1)
raise
after_sample() #To call check_id_error()