Script execution
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import ch.psi.pshell.epics.ControlledVariable as ControlledVariable
|
||||
|
||||
dry_run = True
|
||||
do_elog = False
|
||||
if get_exec_pars().source == CommandSource.ui:
|
||||
start = -30.0
|
||||
stop = 30.0
|
||||
@@ -15,47 +17,61 @@ else:
|
||||
lat = args[4]
|
||||
plt = args[5]
|
||||
|
||||
phase = ControlledVariable("Phase", "SINEG01-RSYS:SET-VSUM-PHASE", "SINEG01-RSYS:GET-VSUM-PHASE")
|
||||
phase.config.minValue =-180.0
|
||||
phase.config.maxValue = 360.0
|
||||
phase.config.precision = 3
|
||||
phase.config.resolution = 1.0
|
||||
phase.config.save()
|
||||
phase.initialize()
|
||||
st = Stream("ICTstream", dispatcher)
|
||||
q = st.addScalar("Charge", "SINEG01-DICT215:B1_CHARGE", 1, 0)
|
||||
st.initialize()
|
||||
st.start()
|
||||
st.waitValueChange(10000)
|
||||
phase0 = phase.read()
|
||||
if dry_run:
|
||||
bph = ControlledVariable("Beam phase", "SINEG01-RSYS:SET-BEAM-PHASE-SIM", "SINEG01-RSYS:SET-BEAM-PHASE-SIM")
|
||||
q = Channel("SINEG01-DICT215:B1_CHARGE-SIM", type = 'd', alias = 'ICT-Q')
|
||||
else:
|
||||
bph = ControlledVariable("Beam phase", "SINEG01-RSYS:SET-VSUM-PHASE", "SINEG01-RSYS:GET-VSUM-PHASE")
|
||||
st = Stream("ICTstream", dispatcher)
|
||||
q = st.addScalar("Charge", "SINEG01-DICT215:B1_CHARGE", 1, 0)
|
||||
st.initialize()
|
||||
st.start()
|
||||
st.waitValueChange(10000)
|
||||
|
||||
bph.config.minValue =-180.0
|
||||
bph.config.maxValue = 360.0
|
||||
bph.config.precision = 3
|
||||
bph.config.resolution = 1.0
|
||||
bph.config.save()
|
||||
bph.initialize()
|
||||
rph = Channel("SINEG01-RSYS:SET-VSUM-PHASE-SIM", type = 'd', alias = 'RF phase')
|
||||
|
||||
try:
|
||||
qb = create_averager(q, nb, 0.100)
|
||||
r = lscan(phase, (qb), start, stop, step, latency=lat)
|
||||
rf_phase = r.getPositions(0)
|
||||
charge = [val.mean for val in r.getReadable(0)]
|
||||
chargerms = [val.stdev for val in r.getReadable(0)]
|
||||
rph0 = rph.read()
|
||||
|
||||
try:
|
||||
rph_averager = create_averager(rph, nb, -1)
|
||||
q_averager = create_averager(q, nb, -1)
|
||||
q_averager.monitored=True
|
||||
r = lscan(bph, (rph_averager, q_averager), start, stop, step, latency=lat)
|
||||
beamphase = r.getPositions(0)
|
||||
rfphase = [val.mean for val in r.getReadable(0)]
|
||||
rfphaserms = [val.stdev for val in r.getReadable(0)]
|
||||
charge = [val.mean for val in r.getReadable(1)]
|
||||
chargerms = [val.stdev for val in r.getReadable(1)]
|
||||
finally:
|
||||
phase.write(phase0)
|
||||
phase.close()
|
||||
st.close()
|
||||
rph.write(rph0)
|
||||
bph.close()
|
||||
rph.close()
|
||||
q.close()
|
||||
|
||||
#Setting the return value
|
||||
x = rf_phase
|
||||
y = charge
|
||||
index_max = y.index(max(y))
|
||||
phase_ref = x[index_max] - 80
|
||||
index_max = charge.index(max(charge))
|
||||
bph_ref = beamphase[index_max] - 80
|
||||
rph_ref = rfphase[index_max] - 80
|
||||
|
||||
print "Beam phase reference = ", bph_ref
|
||||
print "RF phase reference = ", rph_ref
|
||||
|
||||
if do_elog:
|
||||
if get_option("Generated data file:\n" + get_exec_pars().path +"\n\n" + "Save to ELOG?", "YesNo") == "Yes":
|
||||
log_msg = "Start: %0.1f" % start + "deg\n"
|
||||
log_msg = log_msg + "Stop: %0.1f" % stop + "deg\n"
|
||||
log_msg = log_msg + "Step: %0.1f" % step + "deg\n"
|
||||
log_msg = log_msg + "Nb samples: %0.0f" % nb + "\n"
|
||||
log_msg = log_msg + "Latency: %0.3f" % lat + "s\n"
|
||||
log_msg = log_msg + "Data file: " + get_exec_pars().path
|
||||
elog("Schottky Scan", log_msg, get_plot_snapshots())
|
||||
|
||||
set_return(bph_ref, rph_ref)
|
||||
|
||||
"""
|
||||
# save the entry in the logbook
|
||||
if get_option("Generated data file:\n" + get_exec_pars().path +"\n\n" + "Save to ELOG?", "YesNo") == "Yes":
|
||||
log_msg = "Start: %0.1f" % start + "deg\n"
|
||||
log_msg = log_msg + "Stop: %0.1f" % stop + "deg\n"
|
||||
log_msg = log_msg + "Step: %0.1f" % step + "deg\n"
|
||||
log_msg = log_msg + "Nb samples: %0.0f" % nb + "\n"
|
||||
log_msg = log_msg + "Latency: %0.3f" % lat + "s\n"
|
||||
log_msg = log_msg + "Data file: " + get_exec_pars().path
|
||||
elog("Schottky Scan", log_msg, get_plot_snapshots())
|
||||
"""
|
||||
|
||||
set_return(phase_ref)
|
||||
Reference in New Issue
Block a user