Script execution

This commit is contained in:
gobbo_a
2017-05-05 16:40:13 +02:00
parent fe15cb87ea
commit 0f58da669b

View File

@@ -1,3 +1,5 @@
import traceback
is_panel = get_exec_pars().source != CommandSource.ui #Must be checked before callin "run"
run("Devices/Elements")
@@ -42,8 +44,8 @@ for i in range (len(blms)):
channels.append (("blm" + str(i+1), blms[i] + ":B1_LOSS"))
series = LinePlotSeries(blms[i], None, min(i+1, 2))
plt.addSeries(series)
#series.setLinesVisible(False)
#series.setPointSize(3)
series.setLinesVisible(False)
series.setPointSize(2)
for i in range (len(bpms)):
for sensor in BPM_SENSORS:
channels.append (("bpm" + str(i+1) + "_" + sensor[0], bpms[i] + ":" + sensor[1]))
@@ -147,46 +149,51 @@ def do_scan(index):
msg = ""
def calculate():
global msg
stats = []
for i in range(len(blms)):
path_back = "background/blm" + str(i+1)
bg = get_attributes(path_back)["Mean"]
samples = [[], [], [], []]
for cycle in range (cycles):
pos = load_data(wire+"_" + ("%04d" % (cycle+1)) + "/w_pos")
path = wire+"_" + ("%04d" % (cycle+1)) + "/blm" + str(i+1)
data = load_data(path)
sp = blm_remove_spikes(data)
sig = sp if bg is None else [v-bg for v in sp]
[com, rms] = profile_rms_stats(pos, sig,noise_std=0, n_sigma=3.5)
set_attribute(path, "RMS", float("nan") if (rms is None) else rms)
set_attribute(path, "RMS centroid", float("nan") if (com is None) else com)
#print [com, rms]
[off, amp, com, sigma] = profile_gauss_stats(pos, sig, off=None, amp=None, com=None, sigma=None)
set_attribute(path, "Gauss COM", float("nan") if (com is None) else com)
set_attribute(path, "Gauss Sigma", float("nan") if (sigma is None) else sigma)
samples[0].append(rms_com);samples[1].append(rms);samples[2].append(com);samples[3].append(sigma)
#print [off, amp, com, sigma]
#from mathutils import Gaussian
#g = Gaussian(amp, com, sigma)
#gauss = [g.value(v)+off for v in pos]
#plot([data, sp, sig, gauss], ["data", "sp", "signal", "gauss", ], xdata = pos, title="Fit blm" + str(i+1) + " - " + str(cycle+1))
stats.append([])
for sample in samples:
sample = [v for v in sample if v is not None]
stats[i].append( (mean(sample), stdev(sample)) if len(sample)>0 else (float("nan"), float("nan")) )
global msg
stats = []
for i in range(len(blms)):
msg += "Wire " + wire + " - BLM " + str(i+1) + ":\n"
try:
bg = get_attributes("background/blm" + str(i+1))["Mean"] if bkgrd>0 else 0.0
samples = [[], [], [], []]
for cycle in range (cycles):
pos = load_data(wire+"_" + ("%04d" % (cycle+1)) + "/w_pos")
path = wire+"_" + ("%04d" % (cycle+1)) + "/blm" + str(i+1)
data = load_data(path)
sp = blm_remove_spikes(data)
sig = sp if bg is None else [v-bg for v in sp]
[com, rms] = profile_rms_stats(pos, sig,noise_std=0, n_sigma=3.5)
set_attribute(path, "RMS", float("nan") if (rms is None) else rms)
set_attribute(path, "RMS centroid", float("nan") if (com is None) else com)
#print [com, rms]
[off, amp, com, sigma] = profile_gauss_stats(pos, sig, off=None, amp=None, com=None, sigma=None)
set_attribute(path, "Gauss COM", float("nan") if (com is None) else com)
set_attribute(path, "Gauss Sigma", float("nan") if (sigma is None) else sigma)
for i in range(len(blms)):
msg += "Wire " + wire + " - BLM " + str(i+1) + ":\n"
msg += " RMS: " + "%.4f" % stats[i][0][0] + " " + unichr(0x03C3) + "=" + "%.4f" % stats[i][0][1] + "\n"
msg += " RMS COM: " + "%.4f" % stats[i][1][0] + " " + unichr(0x03C3) + "=" + "%.4f" % stats[i][1][1] + "\n"
msg += " Gauss COM: " + "%.4f" % stats[i][2][0] + " " + unichr(0x03C3) + "=" + "%.4f" % stats[i][2][1] + "\n"
msg += " Gauss Sigma: " + "%.4f" % stats[i][3][0] + " " + unichr(0x03C3) + "=" + "%.4f" % stats[i][3][1] + "\n"
samples[0].append(rms_com);samples[1].append(rms);samples[2].append(com);samples[3].append(sigma)
#print [off, amp, com, sigma]
#from mathutils import Gaussian
#g = Gaussian(amp, com, sigma)
#gauss = [g.value(v)+off for v in pos]
#plot([data, sp, sig, gauss], ["data", "sp", "signal", "gauss", ], xdata = pos, title="Fit blm" + str(i+1) + " - " + str(cycle+1))
stats.append([])
for sample in samples:
sample = [v for v in sample if v is not None]
stats[i].append( (mean(sample), stdev(sample)) if len(sample)>0 else (float("nan"), float("nan")) )
plt.addMarker(stats[i][2][0], None, "Gcom=" + "%.2f" % stats[i][2][0], plt.getSeries(i).color)
plt.addMarker(stats[i][1][0], None, "Rcom=" + "%.2f" % stats[i][1][0], plt.getSeries(i).color)
msg += " RMS: " + "%.4f" % stats[i][0][0] + " " + unichr(0x03C3) + "=" + "%.4f" % stats[i][0][1] + "\n"
msg += " RMS COM: " + "%.4f" % stats[i][1][0] + " " + unichr(0x03C3) + "=" + "%.4f" % stats[i][1][1] + "\n"
msg += " Gauss COM: " + "%.4f" % stats[i][2][0] + " " + unichr(0x03C3) + "=" + "%.4f" % stats[i][2][1] + "\n"
msg += " Gauss Sigma: " + "%.4f" % stats[i][3][0] + " " + unichr(0x03C3) + "=" + "%.4f" % stats[i][3][1] + "\n"
except Exception, e:
print >> sys.stderr, traceback.format_exc()
msg += str(e)+ "\n"
print "Starting scan..."
try:
@@ -200,8 +207,7 @@ finally:
scanner.close()
print "Closing stream"
st.close()
print msg
# save the entry in the logbook