diff --git a/script/Diagnostics/WireScan.py b/script/Diagnostics/WireScan.py index 27aba89..5c4ca6d 100644 --- a/script/Diagnostics/WireScan.py +++ b/script/Diagnostics/WireScan.py @@ -16,7 +16,7 @@ bpms = args[5] if is_panel else get_wire_scanners_bpms(prefix) blms = args[6] if is_panel else get_wire_scanners_blms(prefix) bkgrd = args[7] if is_panel else 10 plt = args[8] if is_panel else plot(None, title = "Wire Scan")[0] -do_elog = True if is_panel else False +do_elog = True if is_panel else True print "WireScan parameters: ", prefix, scan_type, scan_range, cycles, cycles, bpms @@ -42,8 +42,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(3) for i in range (len(bpms)): for sensor in BPM_SENSORS: channels.append (("bpm" + str(i+1) + "_" + sensor[0], bpms[i] + ":" + sensor[1])) @@ -87,7 +87,8 @@ def check_end_scan(record, scan): if record[3] != cur_cycle: cur_cycle = record[3] get_context().dataManager.splitScanData(scan) - for s in plt.getAllSeries(): s.clear() + #for s in plt.getAllSeries(): s.clear() + for s in plt.getAllSeries(): s. for i in range (len(blms)): plt.getSeries(i).appendData(position, record[5 + i]) @@ -124,7 +125,7 @@ def do_scan(index): try: scanner.scan() #scanner.waitState(State.Busy, 60000) Not needed as stream filter will make the wait st.getChild("scanning").waitValue(1.0, 10000) - mscan (st, [w_pos()] + st.getReadables(), -1, -1, take_initial = True, after_read = check_end_scan) + mscan (st, [w_pos()] + st.getReadables(), -1, -1, take_initial = True, after_read = check_end_scan) except: if not scanner.isReady(): print "Aborting scan" @@ -139,28 +140,15 @@ def do_scan(index): #indexes = sorted(range(len(s.x)),key=lambda x:s.x[x]) #x,y = [s.x[x] for x in indexes], [s.y[x] for x in indexes] #plot(y, xdata = x) + calculate() img_file = os.path.abspath(get_exec_pars().path + "_" + get_exec_pars().group[0:1] + ".png") time.sleep(0.1) #Give some time to plot finish (async) plt.saveSnapshot(img_file, "png") - snapshots.append(img_file) + snapshots.append(img_file) -print "Starting scan..." -try: - do_background() - st.setFilter(scanner.curr_cycl.get_name() + ">0") #scanner.status_channels[0].get_name() + ">0" not used because we must the transition to know when the finished - do_scan(0) - if scan_type in [WireScanner.Set1, WireScanner.Set2]: - do_scan(1) -finally: - print "Closing scanner" - scanner.close() - print "Closing stream" - st.close() - - - - -for i in range(len(blms)): +msg = "" +def calculate(): + for i in range(len(blms)): path_back = "background/blm" + str(i+1) bg = get_attributes(path_back)["Mean"] for cycle in range (cycles): @@ -179,20 +167,44 @@ for i in range(len(blms)): set_attribute(path, "Gauss Sigma", float("nan") if (sigma is None) else 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)) - + #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)) + + for i in range(len(blms)): + msg += "Wire " + wire + " - BLM " + str(i) + ":\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" + + +print "Starting scan..." +try: + do_background() + st.setFilter(scanner.curr_cycl.get_name() + ">0") #scanner.status_channels[0].get_name() + ">0" not used because we must the transition to know when the finished + do_scan(0) + if scan_type in [WireScanner.Set1, WireScanner.Set2]: + do_scan(1) +finally: + print "Closing scanner" + scanner.close() + print "Closing stream" + st.close() + + +print msg # save the entry in the logbook if do_elog: - if get_option("Generated data file:\n" + get_exec_pars().path +"\n\nSave to ELOG?", "YesNo") == "Yes": + if get_option("Generated data file:\n" + get_exec_pars().path +"\n\n" + msg + "\n\n" + "Save to ELOG?", "YesNo") == "Yes": gsa_log_msg = "Data file: " + get_exec_pars().path gsa_log_msg = gsa_log_msg + "\nWire Scanner: " + prefix gsa_log_msg = gsa_log_msg + "\nScan Type: " + str(scan_type) gsa_log_msg = gsa_log_msg + "\nRange: " + str(scan_range) gsa_log_msg = gsa_log_msg + "\nCycles: " + str(cycles) gsa_log_msg = gsa_log_msg + "\nWire Velocity: " + str(velocity) + gsa_log_msg = gsa_log_msg + msg elog("Wire Scan", gsa_log_msg, snapshots)