91 lines
2.8 KiB
Python
91 lines
2.8 KiB
Python
import traceback
|
|
|
|
is_panel = get_exec_pars().source != CommandSource.ui #Must be checked before callin "run"
|
|
|
|
run("Devices/Elements")
|
|
run("Devices/WireScanner")
|
|
|
|
|
|
#Paramter parsing
|
|
prefix = args[0] if is_panel else "S30CB09-DWSC440" #"SINDI01-DWSC090"
|
|
scan_type = args[1] if is_panel else WireScanner.BackGarage
|
|
blms = args[2] if is_panel else get_wire_scanners_blms(prefix)
|
|
bkgrd = args[3] if is_panel else 50
|
|
plt = args[4] if is_panel else plot(None, title = "Wire Scan")[0]
|
|
do_elog = True if is_panel else True
|
|
print "WireScan parameters: ", prefix, scan_type, blms, bkgrd, plt, do_elog
|
|
|
|
|
|
#Plot setup
|
|
plt.clear()
|
|
plt.removeMarker(None)
|
|
plt.getAxis(plt.AxisId.X).setLabel("Sample");
|
|
plt.getAxis(plt.AxisId.Y).setLabel("");
|
|
plt.getAxis(plt.AxisId.Y2).setLabel("");
|
|
plt.setLegendVisible(True);
|
|
plt.getAxis(plt.AxisId.X).setRange(0, bkgrd-1)
|
|
snapshots = []
|
|
|
|
#Creating WireScanner object
|
|
print "Creating scanner..."
|
|
if prefix not in get_wire_scanners():
|
|
raise Exception("Invalid wire scan: " + prefix)
|
|
scanner = WireScanner(prefix, None)
|
|
|
|
if scan_type == WireScanner.BackFoil:
|
|
scanner.set_selection(WireScanner.Foil)
|
|
scanner.init(True)
|
|
else:
|
|
scanner.park(True)
|
|
|
|
|
|
#Metadata
|
|
set_attribute("/", "Wire Scanner", prefix)
|
|
set_attribute("/", "Scan Type", scan_type)
|
|
set_attribute("/", "Background Measures", bkgrd)
|
|
|
|
#Stream creation
|
|
print "Starting stream..."
|
|
st = Stream("pulse_id", dispatcher)
|
|
for i in range (len(blms)):
|
|
series = LinePlotSeries(blms[i], None, min(i+1, 2))
|
|
plt.addSeries(series)
|
|
series.setLinesVisible(True)
|
|
series.setPointSize(1)
|
|
st.addScalar("blm" + str(i+1), blms[i] + ":B1_LOSS", 10, 0)
|
|
st.initialize()
|
|
st.start()
|
|
|
|
def after_sample(record, scan):
|
|
for i in range (len(blms)):
|
|
plt.getSeries(i).appendData(record.index, record[i])
|
|
|
|
print "Starting scan..."
|
|
|
|
class Timestamp(Readable):
|
|
def read(self):
|
|
return st.getTimestamp()
|
|
|
|
|
|
try:
|
|
r = mscan (st, st.getReadables()[1:] + [Timestamp(),], bkgrd, after_read = after_sample)
|
|
finally:
|
|
print "Closing scanner"
|
|
scanner.close()
|
|
print "Closing stream"
|
|
st.close()
|
|
|
|
# save the entry in the logbook
|
|
if do_elog:
|
|
if get_option("Generated data file:\n" + get_exec_pars().path + "\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 + "\nBackground Measures: " + str(bkgrd)
|
|
|
|
|
|
img_file = os.path.abspath(get_exec_pars().path + ".png")
|
|
plt.saveSnapshot(img_file, "png")
|
|
elog("Wire Scan", gsa_log_msg, [img_file,])
|
|
|