This commit is contained in:
X11MA
2015-12-02 18:23:59 +01:00
commit a294078e3f
19 changed files with 1495 additions and 0 deletions
+104
View File
@@ -0,0 +1,104 @@
import os
import traceback
#Parameters
"""
E1 = 680
E2 = 750
TIME = 2 #min
DELAY = 10.0 #s
OFFSET1 = 1.0 #eV
OFFSET2 = -1.0 #eV
PREFIX = 'Data'
RUNTYPE = "+/-"
"""
print "\nStarting energy scan - Parameters: ",
print E1,E2,TIME,DELAY,OFFSET1,OFFSET2,PREFIX,RUNTYPE #,ALPHA
#fid = caget(OTF_FID, 'i')
def switchpol(activeID):
global pol_str
if activeID == 1:
caput(OTF_OFF1,OFFSET1)
caput(OTF_OFF2,OFFSET2-40) #detune ID2
pol_str = "circ +"
elif activeID == 2:
caput(OTF_OFF1,OFFSET1-40) #detune ID1
caput(OTF_OFF2,OFFSET2)
pol_str = "circ -"
else:
raise Exception("Invalid parameter")
pol_str = None
polswitch = 1
input_path = "/sls/X11MA/Data1/public/X11MA/temp/"
output_path = input_path
file_prefix = time.strftime("%y%m%d")
fid = get_next_fid(input_path, "o" + file_prefix)
suffix = ("%03d" % fid)
input_file = input_path + "o" + file_prefix + "_" + suffix + ".dat"
#Prepare scan
if RUNTYPE == "+/-":
caput(OTF_MODE1,1) # circ + in ID1
caput(OTF_MODE2,2) # circ - in ID2
wait_channel(OTF_DONE, 1, type = 'i')
else:
raise Exception("Invalid run type: " + RUNTYPE)
switchpol(1) # tune ID1 --> polarization: C+
time.sleep(1.0)
wait_channel(OTF_DONE, 1, type = 'i')
open_vg10()
for rounds in [1,2]:
caput(OTF_E1, E1)
caput(OTF_E2, E2)
caput(OTF_TIME, TIME)
#fid = fid + 1
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)
#Start the OTF scan
caput(OTF_START, 'GO')
#Wait until scan is done
wait_channel(OTF_START, 'STOP', type = 's')
time.sleep(3.0)
#Convert file
output_file = output_path+"os"+file_prefix+"_" + suffix + ".dat"
print("Converting data file: " + output_file);
convert_file(input_file, output_file, pol_str)
plot_file(output_file, "Scan " + str(rounds))
if polswitch == 1:
switchpol(2) # tune ID2 --> polarization:C-
polswitch = 0
else:
polswitch = 1
time.sleep(3.0)
close_vg10()
print "Finished Energy scan"
print("Success")
+3
View File
@@ -0,0 +1,3 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// Deployment specific global definitions - executed after startup.groovy
///////////////////////////////////////////////////////////////////////////////////////////////////
+4
View File
@@ -0,0 +1,4 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// Deployment specific global definitions - executed after startup.js
///////////////////////////////////////////////////////////////////////////////////////////////////
+88
View File
@@ -0,0 +1,88 @@
###################################################################################################
# Deployment specific global definitions - executed after startup.py
###################################################################################################
OTF_START = "X11MA-OTF:GO"
OTF_E1 = "X11MA-OTF:E1"
OTF_E2 = "X11MA-OTF:E2"
OTF_TIME = "X11MA-OTF:TIME"
OTF_FID = "X11MA-OTF:FID"
OTF_FTS = "X11MA-OTF:FTSTAMP"
OTF_FILE = "X11MA-OTF:FNAME"
OTF_MODE1 = "X11MA-ID1:MODE"
OTF_MODE2 = "X11MA-ID2:MODE"
OTF_ALPHA1 = "X11MA-ID1:ALPHA"
OTF_ALPHA2 = "X11MA-ID2:ALPHA"
OTF_OFF1 = "X11MA-ID1:ENERGY-OFFS"
OTF_OFF2 = "X11MA-ID2:ENERGY-OFFS"
OTF_OPT = "X11PHS-E:OPT"
OTF_ERBK = "X11MA-PGM:CERBK"
OTF_DONE = "X11MA-PHS:ALL-DONE"
OTF_ESET = "X11MA-PHS:E_SP"
VG10 = "X11MA-EPS-VG10:SET"
FST = time.strftime("%y%m%d")
FID = 0
"""
X11PHS-E:OPT
"""
def get_next_fid(folder, prefix):
try:
import glob
files = glob.glob(folder + prefix + '*_*.dat')
last = max(files)
index = int (last[last.rfind('_')+1 : last.rfind('.')]) + 1
return index
except:
return 0
def wait_channel(name, value, type):
print "Waiting " + str(name) + " = " + str(value)
cawait(name, value, type = type)
print "Done"
def convert_file(input_file_name, output_file_name, field = 0, pol = 0, keithley_3 = False):
sep = "\t"
line_sep = "\r\n"
with open(input_file_name) as inp:
lines = inp.readlines()
with open(output_file_name, "wb") as out:
out.write("Energy" + sep + "rbkenergy" + sep + "Mag" + sep + "Pol" + sep + "Io" + sep + "TEY" + sep + "Norm" + line_sep)
s = sep + " " #File format has a space before numeric values
for line in lines[1:]:
line = line.strip()
if line=="": break
try:
(Ecrbk,CADC1, CADC2, NORM, CADC3, CADC4, MCurr, cffrbk, ID1Erbk, ID2Erbk, vTime) = line.split(" ")
#out.write(Ecrbk + sep + Ecrbk + sep + str(field) + sep + str(pol) + sep + CADC1 + sep + CADC2 + sep + (CADC3 if keithley_3 else NORM) + line_sep)
out.write(" " + Ecrbk + s + Ecrbk + s + str(field) + s + str(pol) + s + CADC1 + s + CADC2 + s + (CADC3 if keithley_3 else NORM) + line_sep)
except:
traceback.print_exc()
def open_vg10():
if caget ("X11MA-OP-VG10:OPEN",'i') != 1:
caput(VG10, 0)
time.sleep(0.1)
caput(VG10, 1)
def close_vg10():
if caget ("X11MA-OP-VG10:OPEN",'i') == 1:
caput(VG10, 0)
time.sleep(0.1)
caput(VG10, 1)
def plot_file(file, ctxt = None):
"""
"""
sep = "\t"
table = Table.load(file, sep, '#')
plots = plot(table, context = ctxt)
+59
View File
@@ -0,0 +1,59 @@
E1 = 710
E2 = 720
TIME = 1 #min
DELAY = 10.0 #s
MODE = 'CIRC +'
OFFSET = -9.0
FOLDER = '2015_04/20150417'
FILE = 'Fe_plus'
OPT = 'PCM+ID1'
ALPHA=0
print "\nStarting energy scan - Parameters: ",
print E1,E2,TIME,DELAY,MODE ,OFFSET ,FOLDER ,FILE ,ALPHA
def wait_channel(name, value, type):
print "Waiting " + str(name) + " = " + str(value)
cawait(name, value, type = type)
print "Done"
#Prepare scan
caput(OTF_MODE1, MODE)
#TODO: MODE2
time.sleep(1.0)
if MODE == 'LINEAR':
caput(OTF_ALPHA1, ALPHA)
#TODO: ALPHA2
#wait_channel('X07MA-ID:DONE', 'DONE', type = 's')
#caput('X07MA-ID:ENERGY-OFFS', OFFSET) #???
#wait_channel('X07MA-ID:DONE', 'DONE', type = 's')
caput (OTF_OPT, OPT)
caput(OTF_E1, E1)
caput(OTF_E2, E2)
caput(OTF_TIME, TIME)
caput('FOLDER', FOLDER) #????
#caputq('X07MA-PHS-E:GO.A', E1)
#wait_channel('X07MA-PHS:alldone', '1', type = 's') #???
time.sleep(0.5)
caput('FILE', FILE) #???
time.sleep(0.1)
#caput('X07MA-OP-VG13:WT_SET', 'Try open') #???
#time.sleep(5.0)
#caput('X07MA-OP-VG13:WT_SET', 'Try open')
#time.sleep(DELAY)
#Start the OTF scan
caput(OTF_START, 'START', type = 's')
#Wait until scan is done
wait_channel(OTF_START, 'STOP', type = 's')
time.sleep(2.0)
print "Finished Energy scan"
#TODO: plot file
print("Success")