Mars 2022
This commit is contained in:
@@ -0,0 +1,248 @@
|
||||
#Script imported from: MgE_plus.xml
|
||||
INVOKE_PLOT_UPDATES = True
|
||||
|
||||
#Parameters
|
||||
"""
|
||||
E1 = 710
|
||||
E2 = 720
|
||||
TIME = 1 #min
|
||||
DELAY = 10.0 #s
|
||||
MODE = 'CIRC +'
|
||||
OFFSET = -9.0
|
||||
FOLDER = '2015_04/20150417'
|
||||
FILE = 'Fe_plus'
|
||||
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_norm", "diode_norm", "TEY_raw", "diode_raw", "I0"])
|
||||
|
||||
def _update_plots(p, x, s0, s1, s2, s3, s4):
|
||||
p[0].getSeries(0).setData(x, s0)
|
||||
p[1].getSeries(0).setData(x, s1)
|
||||
p[2].getSeries(0).setData(x, s2)
|
||||
p[3].getSeries(0).setData(x, s3)
|
||||
p[4].getSeries(0).setData(x, s4)
|
||||
|
||||
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= data.read()
|
||||
tfyr= fdata.read()
|
||||
i0 = idata.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)
|
||||
|
||||
args = [ p, x, to_array(tey,'d'),
|
||||
to_array(tfy,'d'),
|
||||
to_array(teyr,'d'),
|
||||
to_array(tfyr,'d'),
|
||||
to_array(i0,'d')]
|
||||
if INVOKE_PLOT_UPDATES:
|
||||
invoke([_update_plots, args])
|
||||
else:
|
||||
_update_plots(*args)
|
||||
|
||||
"""
|
||||
#open shutter
|
||||
print "\n try open shutter"
|
||||
caput('X07MA-FE-PH1:CLOSE4BL',1)
|
||||
cawait('X07MA-FE-PH1:MS2', 1)
|
||||
print "\n shutter is open"
|
||||
"""
|
||||
|
||||
#print "\nCheck temperature"
|
||||
#wait_temp()
|
||||
|
||||
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)
|
||||
|
||||
start = time.localtime()
|
||||
|
||||
folder = os.path.expanduser("~/Data1/") + FOLDER + "/";
|
||||
|
||||
#print "folder = ",folder
|
||||
|
||||
def getNewestFile():
|
||||
global folder
|
||||
import glob
|
||||
try:
|
||||
# print glob.glob(folder+'/*.txt')
|
||||
# print max(glob.glob(folder+'/*.txt'), key=os.path.getctime)
|
||||
return max(glob.glob(folder+'/*.txt'), key=os.path.getctime)
|
||||
except:
|
||||
return None
|
||||
newest = getNewestFile()
|
||||
print "former newest = ",newest
|
||||
|
||||
#Pre-actions
|
||||
if NO_BEAM_CHECK == False:
|
||||
print "Wait beam"
|
||||
wait_beam()
|
||||
|
||||
time.sleep(0.5) # Nov. 2021 added wait to try avoid taper error
|
||||
|
||||
if MODE is not None:
|
||||
print "Set polarization"
|
||||
pol_mode.write(MODE)
|
||||
if MODE == 'LINEAR':
|
||||
if ALPHA is not None:
|
||||
pol_angle.write(ALPHA)
|
||||
time.sleep(0.5) # TIME SLEEP IS NECESSARY. OTHERWISE NEXT COMMAND WILL NOT WAIT FOR POLARIZATION SETTING. ADDED BY CP ON 07.02.2020
|
||||
pol_done.update()
|
||||
wait_device(pol_done, "DONE") # Oct. 2019 added wait to try avoid taper error
|
||||
print "Polarization setting done"
|
||||
|
||||
print "Set Energy"
|
||||
if OFFSET is not None:
|
||||
time.sleep(0.5) # Nov. 2021 added wait to try avoid taper error
|
||||
pol_offset.write(OFFSET) #TODO: CAPUT
|
||||
time.sleep(0.5) # Nov. 2021 added wait to try avoid taper error
|
||||
pol_done.update()
|
||||
wait_device(pol_done, "DONE") # Nov. 2021 added wait to try avoid taper error
|
||||
|
||||
time.sleep(0.5) # Nov. 2021 added wait to try avoid taper error
|
||||
energy.write(float(E1)) # no need to add wait command. This commands sets and waits.
|
||||
|
||||
time.sleep(0.5) # Nov. 2021 added wait to try avoid taper error
|
||||
pol_done.update()
|
||||
wait_device(pol_done, "DONE") # Nov. 2021 added wait to try avoid taper error
|
||||
print "Energy setting done"
|
||||
#################
|
||||
"""
|
||||
print "Moving down energy in steps."
|
||||
|
||||
while True:
|
||||
en = caget("X07MA-PGM:CERBK")
|
||||
if en > 350.0:
|
||||
estep = 20.0
|
||||
else:
|
||||
estep = 5.0
|
||||
|
||||
if abs(en - E1) < estep:
|
||||
estep = abs(en - E1)
|
||||
|
||||
if en > float(E1):
|
||||
set_energy( en - estep )
|
||||
else:
|
||||
break
|
||||
|
||||
print "It is done."
|
||||
############
|
||||
"""
|
||||
caput('X07MA-PGM:CERBK.N',10) # set energy readback averaging to 10 pts
|
||||
|
||||
caput('E1', E1)
|
||||
#print "caput E1" #add for debug
|
||||
caput('E2', E2)
|
||||
#print "caput E2" #add for debug
|
||||
caput('TIME', TIME)
|
||||
#print "caput TIME" #add for debug
|
||||
caput('FOLDER', FOLDER)
|
||||
#print "caput FOLDER" #add for debug
|
||||
#set_energy (E1)
|
||||
caput('FILE', FILE)
|
||||
#print "caput FILE" #add for debug
|
||||
time.sleep(0.1)
|
||||
|
||||
#open_valve()
|
||||
#open_valve(0.0) #TODO: WHY WRITING AGAIN???
|
||||
#print "before delay" #add for debug
|
||||
time.sleep(DELAY)
|
||||
#print "after delay" #add for debug
|
||||
|
||||
#print 'ldfkj;fjk'
|
||||
#if WAIT_STABLE_TEMPERATURE == True:
|
||||
# wait_temp()
|
||||
|
||||
print "\nStart otf" # for debug
|
||||
|
||||
try:
|
||||
while True: # if ABORT_ON_ID_ERROR == False, waits reading with no ID error
|
||||
caput('START', '1')
|
||||
#print "caput START" #add for debug
|
||||
|
||||
write_logs()
|
||||
|
||||
waiting = True
|
||||
def plot_task():
|
||||
global waiting
|
||||
pos=count.take()
|
||||
start_plot()
|
||||
#print "start_plot" # added for debug
|
||||
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')
|
||||
time.sleep(2.0)
|
||||
print "Finished Energy scan."
|
||||
finally:
|
||||
waiting = False
|
||||
join(ret)
|
||||
#print "Joined "
|
||||
if after_sample(): #Repeat if id error
|
||||
break
|
||||
|
||||
#File convertion
|
||||
#newName = folder + time.strftime("%Y%m%d_%H%M%S_", start) + FILE + "_0000.txt";
|
||||
newName = folder + time.strftime("%Y%m%d_%H%M_", start) + FILE + "_0000.txt";
|
||||
name = getNewestFile()
|
||||
print "new file: ", name
|
||||
|
||||
# print "newest file:"
|
||||
# print name
|
||||
# print "newest variable"
|
||||
# print newName
|
||||
|
||||
#if name == newest:#TODO: WHY WRITING AGAIN??? # commented on June 20th 2019
|
||||
#print "Risk of overwriting. " + name + " same as " + newest
|
||||
#raise Exception("Data file not created.")
|
||||
|
||||
if (name is None) or (not os.path.isfile(name)):
|
||||
raise Exception("Data file not found: " + name)
|
||||
|
||||
convert_file(name, newName)
|
||||
log_scan_filename(newName)
|
||||
#mail
|
||||
#plot_file(newName)
|
||||
#print("Success")
|
||||
#"PlotDomain", "Ecrbk"
|
||||
except:
|
||||
print sys.exc_info()
|
||||
print("Aborting...")
|
||||
while caget('START') == 'START':
|
||||
caput('START', '0')
|
||||
time.sleep(0.1)
|
||||
#if get_exec_pars().source != CommandSource.plugin:
|
||||
# show_message(str(ex))
|
||||
raise
|
||||
Reference in New Issue
Block a user