Files
x11ma/script/DelayScan.py
2016-02-09 11:05:41 +01:00

151 lines
5.1 KiB
Python

import os
import traceback
import math
print "\nStarting delay scan - Parameters: ",
print START,END,SIZE,ENERGIES
###############################################################################
# Plotting
###############################################################################
"""
task = None
running = False
MCP1 = []
MCP2 = []
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)
while running:
try:
if otf_start.read() == 0:
break
e = energy.read()
if (MCP_1 == 1 or MCP_2 == 1):
aK1=keithley_1a.read()
aP=FillingPattern.read()
aPr = []
for z in aP:
aPr.append(z)
SumaP=0
CamaP=0
for z in xrange(0,480):
SumaP = SumaP + aPr[z]
for z in xrange(460,470):
CamaP = CamaP + aPr[z]
aK1norm = aK1 * CamaP / SumaP
if MCP_1 == 1:
a1=MCPArray1.read()
a1r = []
for i in a1:
a1r.append(i)
Sum1a1 = 0
Cam1a1 = 0
Sum2a1 = 0
Cam2a1 = 0
MCP1.append(line_sep)
MCP1.append(e)
for i in xrange(0,480):
Sum1a1 = Sum1a1 + a1r[i]
for i in xrange(Cam_start,Cam_end+1):
Cam1a1 = Cam1a1 + a1r[i]
MCP1.append(Sum1a1)
MCP1.append(Cam1a1)
MCP1.append(aK1norm)
if NrCounters.read() > 460:
for i in xrange(480,960):
Sum2a1 = Sum2a1 + a1r[i]
for i in xrange(Cam_start+480,Cam_end+481):
Cam2a1 = Cam2a1 + a1r[i]
MCP1.append(Sum2a1)
MCP1.append(Cam2a1)
if Save_array_data == 1:
MCP1.append(a1r)
if MCP_2 == 1:
a2=MCPArray2.read()
a2r = []
for j in a2:
a2r.append(j)
Sum1a2 = 0
Cam1a2 = 0
Sum2a2 = 0
Cam2a2 = 0
MCP2.append(line_sep)
MCP2.append(e)
for j in xrange(0,480):
Sum1a2 = Sum1a2 + a2r[j]
for j in xrange(Cam_start,Cam_end+1):
Cam1a2 = Cam1a2 + a2r[j]
MCP2.append(Sum1a2)
MCP2.append(Cam1a2)
MCP2.append(aK1norm)
if NrCounters.read() > 460:
for j in xrange(480,960):
Sum2a2 = Sum2a2 + a2r[j]
for j in xrange(Cam_start+480,Cam_end+481):
Cam2a2 = Cam2a2 + a2r[j]
MCP2.append(Sum2a2)
MCP2.append(Cam2a2)
if Save_array_data == 1:
MCP2.append(a2r)
time.sleep(SamplingTime.read()*0.001)
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
# time.sleep(0.2)
except:
pass
print "Done Plotting"
if MCP_1 == 1:
output_file_MCP1 = output_path+"MCP_1_"+file_prefix+"_" + suffix + ".dat"
MCP1out = open(output_file_MCP1, "a+")
sMCP1 = sep.join(str(x) for x in MCP1) + line_sep # MCP1.write("%s" + sep % i)
sMCP1out = sep + "rbkenergy" + sep + "Sum1" + sep + "Cam1" + sep + "Keithley1_norm"
if NrCounters.read() > 460:
sMCP1out = sMCP1out + sep + "Sum2" + sep + "Cam2"
if Save_array_data == 1:
sMCP1out = sMCP1out + sep + "Array"
sMCP1out = sMCP1out + line_sep + sMCP1
MCP1out.write(sMCP1out)
MCP1out.close()
print "Saved MCP signal data"
if MCP_2 == 1:
output_file_MCP2 = output_path+"MCP_2_"+file_prefix+"_" + suffix + ".dat"
MCP2out = open(output_file_MCP2, "a+")
sMCP2 = sep.join(str(y) for y in MCP2) + line_sep
sMCP2out = sep + "rbkenergy" + sep + "Sum1" + sep + "Cam1" + sep + "Keithley1_norm"
if NrCounters.read() > 460:
sMCP2out = sMCP2out + sep + "Sum2" + sep + "Cam2"
if Save_array_data == 1:
sMCP2out = sMCP2out + sep + "Array"
sMCP2out = sMCP2out + line_sep + sMCP2
MCP2out.write(sMCP2out)
MCP2out.close()
print "Saved MCP I_0 data"
def startPlot(type = 1):
global task
task = fork((_startPlot,(type,)),)
def stopPlot():
global task, running
running = False
ret = join(task)
"""
print "Finished Delay scan"
print("Success")