119 lines
4.1 KiB
Python
Executable File
119 lines
4.1 KiB
Python
Executable File
|
|
##################### Convert_File function #############################
|
|
"""
|
|
def convert_file(input_file_name, output_file_name):
|
|
sep = "\t"
|
|
line_sep = "\r\n"
|
|
field = caget('X11MA-XMCD:Ireadout')
|
|
with open(input_file_name) as inp:
|
|
lines = inp.readlines()
|
|
with open(output_file_name, "wb") as out:
|
|
out.write("Energy" + sep + "Io" + sep + "CADC2" + sep + "CADC3" + sep + "Mag" + 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 + s + CADC1 + s + CADC2 + s + CADC3 + s + str(field) +line_sep)
|
|
except:
|
|
traceback.print_exc()
|
|
|
|
def convert_file(input_file_name, output_file_name, pol = None):
|
|
print "Converting data file: " + input_file_name + " to " + output_file_name
|
|
#print "File converted to: ",output_file_name
|
|
sep = "\t"
|
|
line_sep = "\n"
|
|
MODE = pol_mode.read()
|
|
if pol is None:
|
|
pol = pol_angle.read() if (MODE == "LINEAR") else pol_mode.readback.read()
|
|
with open(input_file_name) as inp:
|
|
lines = inp.readlines()
|
|
with open(output_file_name, "wb") as out:
|
|
(db, st) = ("java.lang.Double", "java.lang.String")
|
|
out.write("#Energy" + sep + "CADC1" + sep + "CADC2" + sep + "CADC3" + sep + "NORMtey" + "Pol" + line_sep)
|
|
out.write("#"+ db + sep + db + sep + db + sep + db + sep + db + line_sep)
|
|
s = sep
|
|
for line in lines[1:]:
|
|
line = line.strip()
|
|
if line=="": break
|
|
try:
|
|
(Ecrbk, CADC1, CADC2, CADC3, CADC4, MCurr, cffrbk, IDErbk, time) = line.split(" ")
|
|
normtey=repr( float(CADC2)/float(CADC1))
|
|
# normdiode=repr(float(CADC3)/float(CADC2))
|
|
out.write(Ecrbk + s + CADC1 + s + CADC2 + s + CADC3 + s + normtey + s + str(pol) + line_sep)
|
|
except:
|
|
traceback.print_exc()
|
|
os.rename(input_file_name, get_context().setup.expandPath("{data}/OTF/" + ntpath.basename(input_file_name)))
|
|
"""
|
|
##################### Plotting function #############################
|
|
"""
|
|
task = None
|
|
running = False
|
|
|
|
|
|
def _startPlot(type):
|
|
global running
|
|
sep = "\t"
|
|
line_sep = "\r\n"
|
|
print "Starting plot: type " + str(type)
|
|
running = True
|
|
p = plot(None,name="Energy")[0]
|
|
s = p.getSeries(0)
|
|
cur = 0
|
|
time.sleep(3.0)
|
|
t_start = time.time()
|
|
t_end = time.time() + TIME*60.0
|
|
while running:
|
|
try:
|
|
if (otf_start.read() == 0 or time.time() > t_end):
|
|
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
|
|
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)
|
|
|
|
"""
|
|
##################### Switch Polarization function #############################
|
|
"""
|
|
|
|
def switchpol(activeID, runtype):
|
|
global pol_str
|
|
if activeID == 1:
|
|
caput(ID1_OFF,OFFSET1)
|
|
caput(ID2_OFF,OFFSET2-40) #detune ID2
|
|
if runtype in ["+/-", "+"]:
|
|
pol_str = "circ +"
|
|
elif runtype in ["LH/LV", "LH"]:
|
|
pol_str = "Lin. Horizontal"
|
|
elif activeID == 2:
|
|
caput(ID1_OFF,OFFSET1-40) #detune ID1
|
|
caput(ID2_OFF,OFFSET2)
|
|
if runtype in ["+/-", "-"]:
|
|
pol_str = "circ -"
|
|
elif runtype in ["LH/LV", "LV"]:
|
|
pol_str = "Lin. Vertical"
|
|
else:
|
|
raise Exception("Invalid parameter")
|
|
|
|
pol_str = None
|
|
|
|
def get_pol_str():
|
|
return pol_str
|
|
"""
|
|
|