Startup
This commit is contained in:
@@ -87,7 +87,7 @@ def get_scan_selection(scan_type, index = 0):
|
||||
|
||||
class WireScanner(WireScanInfo):
|
||||
|
||||
ScanType = [WireX1, WireY1, WireX2, WireY2, Set1, Set2] = ['X1', 'Y1', 'X2', 'Y2', 'Set1', 'Set2']
|
||||
ScanType = [WireX1, WireY1, WireX2, WireY2, Set1, Set2, BackGarage, BackFoil] = ['X1', 'Y1', 'X2', 'Y2', 'Set1', 'Set2', 'BackgroundGarage', 'BackgroundFoil']
|
||||
Selection = [Garage, W1X, W1Y, W2X, W2Y, Foil] = "GARAGE", "W1X", "W1Y", "W2X", "W2Y", "FOIL"
|
||||
|
||||
def __init__(self, prefix, scan_range, cycles=None, velocity=None, continuous = None):
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
#import ch.psi.pshell.epics.ChannelDouble as ChannelDouble
|
||||
import ch.psi.pshell.bs.Scalar as Scalar
|
||||
import ch.psi.pshell.epics.DiscretePositioner as DiscretePositioner
|
||||
|
||||
|
||||
#Arguments
|
||||
SAMPLES = 10
|
||||
GAINS = ["SINDI02-DBLM084:M06-1-CH03-V-MM","SINDI02-DBLM084:M06-1-CH03-V-MM2",]
|
||||
BLMS = ["SINDI02-DBLM025", "SINDI02-DBLM085", "S10DI01-DBLM045"]
|
||||
ATTENUATORS = ["SINDI02-DBLM084:M06-1-ATT2-VAL", "SINDI02-DBLM084:M06-2-ATT2-VAL", "S10DI01-DBLM113:M06-1-ATT2-VAL"]
|
||||
RANGE = [0.5, 1.1]
|
||||
STEP_SIZE = 0.01
|
||||
SETTLING_TIME = 0.5
|
||||
|
||||
|
||||
gain_positioners = []
|
||||
for i in range(len(GAINS)):
|
||||
#gain_positioners.append(Channel(GAINS[i], alias = "gain " + str(i+1)))
|
||||
gain_positioners.append( DummyPositioner("gain " + str(i+1)))
|
||||
|
||||
attenuators = []
|
||||
for i in range(len(ATTENUATORS)):
|
||||
att = DiscretePositioner("Att"+str(i+1), ATTENUATORS[i])
|
||||
att.initialize()
|
||||
attenuators.append(att)
|
||||
|
||||
|
||||
#Channel-based
|
||||
#blm1 = ChannelDouble("blm1", "SINDI02-DBLM025:B1_LOSS"); blm1.setMonitored(True); blm1.initialize()
|
||||
#blm2 = ChannelDouble("blm2", "SINDI02-DBLM085:B1_LOSS"); blm2.setMonitored(True); blm2.initialize()
|
||||
|
||||
#Stream creation
|
||||
|
||||
sensors = []
|
||||
line_plots = []
|
||||
st = Stream("pulse_id", dispatcher)
|
||||
for i in range(len(BLMS)):
|
||||
blm = Scalar("blm" + str(i+1), st, BLMS[i] + ":B1_LOSS", 10, 0)
|
||||
av = create_averager(blm, SAMPLES, interval = -1)
|
||||
av.setMonitored(i>0)
|
||||
sensors.append(av)
|
||||
sensors.append(av.stdev)
|
||||
sensors.append(av.samples)
|
||||
line_plots.append(av.samples)
|
||||
st.initialize()
|
||||
st.start()
|
||||
st.waitCacheChange(10000) #Wait stream be running before starting scan
|
||||
|
||||
"""
|
||||
#Averaging
|
||||
ablm1 = create_averager(blm1, SAMPLES, interval = -1)
|
||||
ablm2 = create_averager(blm2, SAMPLES, interval = -1)
|
||||
ablm2.setMonitored(True)
|
||||
"""
|
||||
|
||||
#Plot setup
|
||||
setup_plotting( line_plots = line_plots)
|
||||
|
||||
|
||||
#Metadata
|
||||
set_attribute("/", "BLM" , BLMS)
|
||||
set_attribute("/", "Gain" , GAINS)
|
||||
for att in attenuators:
|
||||
set_attribute("/", att.setpoint.channelName, att.read())
|
||||
|
||||
try:
|
||||
r=lscan(gain_positioners, sensors, [RANGE[0],] * len(gain_positioners), [RANGE[1],] * len(gain_positioners), [STEP_SIZE,] * len(gain_positioners), latency = SETTLING_TIME)
|
||||
finally:
|
||||
st.close()
|
||||
|
||||
@@ -69,6 +69,13 @@ st.initialize()
|
||||
st.start()
|
||||
st.waitCacheChange(10000) #Wait stream be running before starting scan
|
||||
|
||||
|
||||
class Timestamp(Readable):
|
||||
def read(self):
|
||||
return st.getTimestamp()
|
||||
|
||||
|
||||
|
||||
|
||||
#Pseudo-device returning the wire position
|
||||
class w_pos(Readable):
|
||||
@@ -106,7 +113,7 @@ def do_background():
|
||||
path = get_exec_pars().group + "/"+ r.getReadables()[i].name
|
||||
set_attribute(path, "Mean", mean(d))
|
||||
set_attribute(path, "Sigma", stdev(d) )
|
||||
|
||||
|
||||
#Scan
|
||||
def do_scan(index):
|
||||
global scan_complete, cur_cycle, wire
|
||||
@@ -127,7 +134,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() + [Timestamp(),], -1, -1, take_initial = True, after_read = check_end_scan)
|
||||
except:
|
||||
if not scanner.isReady():
|
||||
print "Aborting scan"
|
||||
@@ -162,15 +169,16 @@ def calculate():
|
||||
sp = blm_remove_spikes(data)
|
||||
sig = sp if bg is None else [v-bg for v in sp]
|
||||
|
||||
[rms_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 (rms_com is None) else rms_com)
|
||||
[rms_com, rms_sigma] = profile_rms_stats(pos, sig,noise_std=0, n_sigma=3.5)
|
||||
set_attribute(path, "RMS COM", float("nan") if (rms_com is None) else rms_com)
|
||||
set_attribute(path, "RMS Sigma", float("nan") if (rms_sigma is None) else rms_sigma)
|
||||
|
||||
#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)
|
||||
samples[0].append(rms_com);samples[1].append(rms_sigma);samples[2].append(com);samples[3].append(sigma)
|
||||
#print [off, amp, com, sigma]
|
||||
|
||||
#from mathutils import Gaussian
|
||||
@@ -185,10 +193,10 @@ def calculate():
|
||||
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.brighter())
|
||||
|
||||
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"
|
||||
msg += " RMS COM: " + "%.4f" % stats[i][0][0] + " +- " +"%.4f" % stats[i][0][1] + "\n" #unichr(0x03C3) + "="
|
||||
msg += " RMS Sigma: " + "%.4f" % stats[i][1][0] + " +- " + "%.4f" % stats[i][1][1] + "\n"
|
||||
msg += " Gauss COM: " + "%.4f" % stats[i][2][0] + " +- " + "%.4f" % stats[i][2][1] + "\n"
|
||||
msg += " Gauss Sigma: " + "%.4f" % stats[i][3][0] + " +- " + "%.4f" % stats[i][3][1] + "\n"
|
||||
except Exception, e:
|
||||
print >> sys.stderr, traceback.format_exc()
|
||||
msg += str(e)+ "\n"
|
||||
@@ -218,6 +226,7 @@ if do_elog:
|
||||
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
|
||||
gsa_log_msg = gsa_log_msg + "\nBackground Measures: " + str(bkgrd)
|
||||
gsa_log_msg = gsa_log_msg + "\n" + msg
|
||||
elog("Wire Scan", gsa_log_msg, snapshots)
|
||||
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
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,])
|
||||
|
||||
Reference in New Issue
Block a user