ScreenPanel

This commit is contained in:
sfop
2017-06-19 11:07:40 +02:00
parent 3524af3ca1
commit 060f262a5a
27 changed files with 666 additions and 178 deletions
+139
View File
@@ -0,0 +1,139 @@
#import ch.psi.pshell.epics.ChannelDouble as ChannelDouble
import ch.psi.pshell.bs.Scalar as Scalar
import ch.psi.pshell.bs.Waveform as Waveform
import ch.psi.pshell.epics.DiscretePositioner as DiscretePositioner
import ch.psi.pshell.epics.ChannelDouble as ChannelDouble
#Arguments
SAMPLES = 100
GAINS = ["SINDI02-DBLM084:M06-1-CH03-V-MM","SINDI02-DBLM084:M06-2-CH03-V-MM","S10DI01-DBLM113:M06-1-CH03-V-MM"] #, "SINDI02-DBLM084:M06-0-CH03-V-MM"]
BLMS = ["SINDI02-DBLM025", "SINDI02-DBLM085", "S10DI01-DBLM045"]
LLM = ["SINDI01-DLLM105"]
BPMS = ["SINDI01-DBPM060:Q1", "SINDI02-DBPM010:Q1"]
ATTENUATORS = ["SINDI02-DBLM084:M06-1-ATT2-VAL", "SINDI02-DBLM084:M06-2-ATT2-VAL", "S10DI01-DBLM113:M06-1-ATT2-VAL"] #,"SINDI02-DBLM084:M06-0-ATT2-VAL"]
ATT_SP = 15.0 #3.0,6.0,9.0,12.0,15.0
RANGE = [0.5, 1.1]
STEP_SIZE = 0.05
SETTLING_TIME = 3
SIMULATION = False
do_elog = True
gain_positioners = []
for i in range(len(GAINS)):
gain_positioners.append( DummyPositioner("gain " + str(i+1)) if SIMULATION else Channel(GAINS[i], alias = "gain " + str(i+1)))
attenuators = []
for i in range(len(ATTENUATORS)):
att = ChannelDouble("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
for att in attenuators:
att.write(ATT_SP)
sensors = []
line_plots = []
st = Stream("pulse_id", dispatcher)
st.setFilter("SIN-CVME-TIFGUN-EVR0:BEAMOK == 1")
for i in range(len(BLMS)):
blm = Scalar("blm" + str(i+1), st, BLMS[i] + ":B1_LOSS", 1, 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)
blmw = Waveform("blmw" + str(i+1), st, BLMS[i] + ":LOSS_SIGNAL_RAW", 1, 0)
sensors.append(blmw)
#for i in range(len(LLMS)):
# llm = Scalar("llm" + str(i+1), st, LLMS[i] + ":XX_LOSS", 1, 0)
# avl = create_averager(llm, SAMPLES, interval = -1)
# avl.setMonitored(i>0)
# sensors.append(avl)
# sensors.append(avl.stdev)
# sensors.append(avl.samples)
# line_plots.append(avl.samples)
for i in range(len(BPMS)):
bpm = Scalar("bpm" + str(i+1), st, BPMS[i], 1, 0)
av1 = create_averager(bpm, SAMPLES, interval = -1)
av1.setMonitored((i>0) or (len(BLMS)>0))
sensors.append(av1)
sensors.append(av1.stdev)
sensors.append(av1.samples)
line_plots.append(av1.samples)
#Scalar("beam_ok" , st, "SIN-CVME-TIFGUN-EVR0:BEAMOK" , 1, 0)
st.initialize()
st.start()
st.waitCacheChange(5000) #Wait stream be running before starting scan
"""
#Averaging
ablm1 = create_averager(blm1, SAMPLES, interval = -1)
ablm2 = create_averager(blm2, SAMPLES, interval = -1)
ablm3 = create_averager(blm3, SAMPLES, interval = -1)
ablm2.setMonitored(True)
ablm3.setMonitored(True)
"""
#Plot setup
setup_plotting( line_plots = line_plots)
#Metadata
set_attribute("/", "Samples" , SAMPLES)
set_attribute("/", "StepSize" , STEP_SIZE)
set_attribute("/", "SamplingTime" , SETTLING_TIME)
set_attribute("/", "Range" , RANGE)
set_attribute("/", "BLM" , BLMS)
#set_attribute("/", "BLMW" , BLMW)
set_attribute("/", "Gain" , GAINS)
set_attribute("/", "Attenuators" , ATTENUATORS)
set_attribute("/", "BPM" , BPMS)
for att in attenuators:
set_attribute("/", att.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)
#r=bscan(st, 10)
finally:
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 + "\nSamples = " + str(SAMPLES)
gsa_log_msg = gsa_log_msg + "\nStepSize = " + str(STEP_SIZE)
gsa_log_msg = gsa_log_msg + "\nSamplingTime = " + str(SETTLING_TIME)
gsa_log_msg = gsa_log_msg + "\nRange = " + str(RANGE)
gsa_log_msg = gsa_log_msg + "\nBLM = " + str(BLMS)
#gsa_log_msg = gsa_log_msg + "\nBLMW = " + str(BLMW)
gsa_log_msg = gsa_log_msg + "\nBPM = " + str(BPMS)
gsa_log_msg = gsa_log_msg + "\nGain = " + str(GAINS)
gsa_log_msg = gsa_log_msg + "\nAttenuators:" # " + str(ATTENUATORS)
for att in attenuators:
gsa_log_msg = gsa_log_msg + "\n " + att.setpoint.channelName + " = " + str(att.read())
plots = get_plot_snapshots()
save=[]
for i in range(len(BLMS)):
save.append(plots[3*i])
for i in range(len(BPMS)):
save.append(plots[3*i])
elog("BLM Gain scan", gsa_log_msg, save)
+124
View File
@@ -0,0 +1,124 @@
#import ch.psi.pshell.epics.ChannelDouble as ChannelDouble
import ch.psi.pshell.bs.Scalar as Scalar
import ch.psi.pshell.epics.DiscretePositioner as DiscretePositioner
import ch.psi.pshell.epics.ChannelDouble as ChannelDouble
#Arguments
SAMPLES = 100
ICTS = ["SINEG01-DICT215", "S10DI01-DICT025", "SARMA01-DICT090", "SARBD01-DICT030"]
ICTV = ["SINEG01-DICT009:AL1-ICT-VOLTAGE", "S10DI01-DICT113:AL0-ICT-VOLTAGE", "SARMA01-DICT482:AL0-ICT-VOLTAGE","SARBD01-DICT599:AL0-ICT-VOLTAGE"]
BPMS = ["SINEG01-DBPM340:Q1", "S10DI01-DBPM110:Q1", "SARMA01-DBPM100:Q1", "SARBD01-DBPM040:Q1", "SARUN20-DBPM070:Q1"]
#ROT = ["SLGJG-LMRM-M031:MOT.VAL"] # Polarizer
ROT = ["SLGTV-LAPP:SIZE-SET"] # IRIS
#RANGE = [50.0, 15.0]
#STEP_SIZE = 5.0
RANGE = [4.4, 2.0] # IRIS range
STEP_SIZE = 0.1 # IRIS Step size
SETTLING_TIME = 3
SIMULATION = False
do_elog = True
rot_positioners = []
for i in range(len(ROT)):
rot_positioners.append( DummyPositioner("rot " + str(i+1)) if SIMULATION else Channel(ROT[i], alias = "rot" + str(i+1)))
#Stream creation
sensors = []
line_plots = []
st = Stream("pulse_id", dispatcher)
st.setFilter("SIN-CVME-TIFGUN-EVR0:BEAMOK == 1")
for i in range(len(ICTS)):
ict = Scalar("ict" + str(i+1), st, ICTS[i] + ":B1_CHARGE", 1, 0)
av = create_averager(ict, SAMPLES, interval = -1)
av.setMonitored(i>0)
sensors.append(av)
sensors.append(av.stdev)
sensors.append(av.samples)
line_plots.append(av.samples)
for i in range(len(BPMS)):
bpm = Scalar("bpm" + str(i+1), st, BPMS[i], 1, 0)
av1 = create_averager(bpm, SAMPLES, interval = -1)
av1.setMonitored((i>0) or (len(ICTS)>0))
sensors.append(av1)
sensors.append(av1.stdev)
sensors.append(av1.samples)
line_plots.append(av1.samples)
for i in range(len(ICTV)):
"""
ictv = Scalar("ictv" + str(i+1), st, ICTV[i], 1, 0)
av2 = create_averager(ictv, SAMPLES, interval = -1)
av2.setMonitored((i>0) or (len(ICTS)>0))
sensors.append(av2)
sensors.append(av2.stdev)
sensors.append(av2.samples)
"""
ictv = ChannelDouble("ictv" + str(i+1), ICTV[i])
add_device(ictv, True)
ictv.monitored = True
ictv.initialize()
av2 = create_averager(ictv, SAMPLES/2 , interval = -1)
av2.setMonitored(True)
sensors.append(av2)
add_device(av2, True)
#sensors.append(ictv)
#Scalar("beam_ok" , st, "SIN-CVME-TIFGUN-EVR0:BEAMOK" , 1, 0)
st.initialize()
st.start()
st.waitCacheChange(5000) #Wait stream be running before starting scan
"""
#Averaging
aict1 = create_averager(ict1, SAMPLES, interval = -1)
aict2 = create_averager(ict2, SAMPLES, interval = -1)
aict3 = create_averager(ict3, SAMPLES, interval = -1)
aict2.setMonitored(True)
aict3.setMonitored(True)
"""
#Plot setup
setup_plotting( line_plots = line_plots)
#Metadata
set_attribute("/", "Samples" , SAMPLES)
set_attribute("/", "StepSize" , STEP_SIZE)
set_attribute("/", "SamplingTime" , SETTLING_TIME)
set_attribute("/", "Range" , RANGE)
set_attribute("/", "ICTS" , ICTS)
set_attribute("/", "ICTV" , ICTV)
set_attribute("/", "Rot" , ROT)
set_attribute("/", "BPM" , BPMS)
try:
r=lscan(rot_positioners, sensors, [RANGE[0],] * len(rot_positioners), [RANGE[1],] * len(rot_positioners), [STEP_SIZE,] * len(rot_positioners), latency = SETTLING_TIME)
#r=bscan(st, 10)
finally:
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 + "\nSamples = " + str(SAMPLES)
gsa_log_msg = gsa_log_msg + "\nStepSize = " + str(STEP_SIZE)
gsa_log_msg = gsa_log_msg + "\nSamplingTime = " + str(SETTLING_TIME)
gsa_log_msg = gsa_log_msg + "\nRange = " + str(RANGE)
gsa_log_msg = gsa_log_msg + "\nICTS = " + str(ICTS)
gsa_log_msg = gsa_log_msg + "\nBPM = " + str(BPMS)
plots = get_plot_snapshots()
save=[]
for i in range(len(ICTS)):
save.append(plots[3*i])
for i in range(len(BPMS)):
save.append(plots[3*i])
elog("Charge scan", gsa_log_msg, save)
+23 -29
View File
@@ -2,9 +2,8 @@ import ch.psi.pshell.epics.Positioner as Positioner
import ch.psi.pshell.epics.Camtool as Camtool
#Parameters
dry_run = False
dry_run = True
do_elog = True
camera_name = "SINBD01-DSCR010"
if get_exec_pars().source == CommandSource.ui:
start = 45.0
stop = 55.0
@@ -24,26 +23,27 @@ else:
energy0 = args[6]
plt = args[7]
A = energy0 / disp / 1e6
B = energy0
#Plot setup
plt.clear()
plt.setStyle(plt.Style.ErrorY)
plt.addSeries(LinePlotErrorSeries("Energy"))
plt.addSeries(LinePlotErrorSeries("Energy Spread", None, 2))
plt.getAxis(plt.AxisId.X).setLabel("Gun Phase")
plt.getAxis(plt.AxisId.X).setLabel("Gun Beam Phase (deg)")
plt.getAxis(plt.AxisId.Y).setLabel("Energy (MeV)")
plt.getAxis(plt.AxisId.Y2).setLabel("Energy Spread (MeV)")
plt.setLegendVisible(True)
#Creating Phase positioner
if dry_run:
phase = Positioner("Phase", "SINEG01-RSYS:SET-BEAM-PHASE-SIM", "SINEG01-RSYS:SET-BEAM-PHASE-SIM")
#phase = DummyPositioner("Phase")
camera_name = "SLG-LCAM-C041"
do_elog = False
else:
phase = Positioner("Phase", "SINEG01-RSYS:SET-BEAM-PHASE", "SINEG01-RSYS:GET-BEAM-PHASE")
phase = Positioner("Phase", "SINEG01-RSYS:SET-BEAM-PHASE", "SINEG01-RSYS:GET-BEAM-PHASE")
camera_name = "SINBD01-DSCR010"
phase.config.minValue = -180.0
phase.config.maxValue = 180.0
phase.config.precision = 3
@@ -58,47 +58,41 @@ phase0 = phase.read()
check_camtool()
camtool.start(camera_name)
wait_camtool_message()
x = camtool.stream.getChild("x_fit_mean")
dx = camtool.stream.getChild("x_fit_standard_deviation")
x = camtool.stream.getChild("x_center_of_mass")
dx = camtool.stream.getChild("x_rms")
#Creating averagers
xb = create_averager(x, nb, -1) # -1 event based, waits for the next value
dxb = create_averager(dx, nb, -1)
dxb.monitored=True # not blocking, will return last nb values
x_averager = create_averager(x, nb, -1) # -1 event based, waits for the next value
dx_averager = create_averager(dx, nb, -1)
dx_averager.monitored=True # not blocking, will return last nb values
#Record callback: uptate of output plot
def after_sample(record, scan):
global energy0, disp
x_fit_mean, x_fit_mean_sigma, = record.values[0].mean, record.values[0].stdev
x_fit_std, x_fit_std_sigma = record.values[1].mean, record.values[1].stdev
E_mean, E_std = energy0 * (1 + x_fit_mean / 1e6 / disp), abs(energy0 * (x_fit_mean_sigma / 1e6 / disp))
dE_mean, dE_std = abs(energy0 * (x_fit_std / 1e6 / disp)), abs(energy0 * (x_fit_std_sigma / 1e6 / disp))
plt.getSeries(0).appendData(record.positions[0], E_mean, E_std)
plt.getSeries(1).appendData(record.positions[0], dE_mean, dE_std)
global A, B
x_pos_mean, x_pos_stdev = record.values[0].mean, record.values[0].stdev
x_width_mean, x_width_stdev = record.values[1].mean, record.values[1].stdev
E_mean, E_stdev = A * x_pos_mean + B, abs(A) * x_pos_stdev
dE_mean, dE_stdev = abs(A) * x_width_mean, abs(A) * x_width_stdev
plt.getSeries(0).appendData(record.positions[0], E_mean, E_stdev)
plt.getSeries(1).appendData(record.positions[0], dE_mean, dE_stdev)
#The scan loop
try:
r = lscan(phase, [xb, dxb], start, stop, step , latency=lat, after_read = after_sample)
r = lscan(phase, [x_averager, dx_averager], start, stop, step , latency=lat, after_read = after_sample)
finally:
phase.write(phase0)
phase.close()
camtool.stop() # stops camtool but does not close it camtool is a global object
#Saving metadata
E = [energy0 * (1 + val.mean / 1e6 / disp) for val in r.getReadable(0)]
dE = [abs(energy0 * (val.mean / 1e6 / disp)) for val in r.getReadable(1)]
E = [A * val.mean + B for val in r.getReadable(0)]
dE = [abs(A) * val.mean for val in r.getReadable(1)]
save_dataset(get_exec_pars().group + "/E", E)
save_dataset(get_exec_pars().group + "/dE", dE)
if do_elog:
if get_option("Generated data file:\n" + get_exec_pars().path +"\n\n" + "Save to ELOG?", "YesNo") == "Yes":
log_msg = "Data file: " + get_exec_pars().path
#log_msg = log_msg + "\n\n" + r.print()
log_msg = "Data file: " + get_exec_pars().path
sleep(0.1) #Give some time to plot to be finished - it is not sync with acquisition
file_name = os.path.abspath(get_context().setup.getContextPath() + "/GunScanPlot.png")
plt.saveSnapshot(file_name , "png")
+23 -28
View File
@@ -1,15 +1,16 @@
import ch.psi.pshell.epics.Positioner as Positioner
import ch.psi.pshell.epics.ChannelDouble as ChannelDouble
dry_run = True
do_elog = False
dry_run = False
do_elog = True
if get_exec_pars().source == CommandSource.ui:
start = -30.0
stop = 30.0
start = -180.0
stop = 180.0
step = 5.0
nb = 1
lat = 0.100
plt = None
plt = None
else:
start = args[0]
stop = args[1]
@@ -21,43 +22,42 @@ else:
if plt is not None:
plt.setStyle(plt.Style.ErrorY)
plt.addSeries(LinePlotErrorSeries("Values"))
plt.getAxis(plt.AxisId.X).setLabel("RF Gun Phase")
plt.getAxis(plt.AxisId.X).setLabel("Gun Beam Phase (deg)")
plt.getAxis(plt.AxisId.Y).setLabel("SINEG01-DICT215:B1_CHARGE")
if dry_run:
bph = Positioner("Beam phase", "SINEG01-RSYS:SET-BEAM-PHASE-SIM", "SINEG01-RSYS:SET-BEAM-PHASE-SIM")
q = ChannelDouble('ICT-Q', "SINEG01-DICT215:B1_CHARGE-SIM")
rph = ChannelDouble('RF phase', "SINEG01-RSYS:SET-VSUM-PHASE-SIM")
q = ChannelDouble('ICT-Q', "SINEG01-DICT215:B1_CHARGE-SIM")
q.initialize()
q.monitored=True
else:
bph = Positioner("Beam phase", "SINEG01-RSYS:SET-BEAM-PHASE", "SINEG01-RSYS:SET-BEAM-PHASE")
bph = Positioner("Beam phase", "SINEG01-RSYS:SET-BEAM-PHASE", "SINEG01-RSYS:GET-BEAM-PHASE")
rph = ChannelDouble('RF phase', "SINEG01-RSYS:SET-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.maxValue = 180.0
bph.config.precision = 3
bph.config.rotation = True
bph.config.rotation = True
bph.config.resolution = 1.0
bph.config.save()
bph.initialize()
rph = ChannelDouble('RF phase', "SINEG01-RSYS:SET-VSUM-PHASE-SIM")
rph.initialize()
rph.monitored=True
rph0 = rph.read()
#Record callback: uptate of output plot
def after_sample(record, scan):
if plt is not None:
plt.getSeries(0).appendData(record.positions[0], record.values[1].mean, record.values[1].stdev)
try:
try:
rph_averager = create_averager(rph, nb, 0.1) # Set polling time to -1 for BS data to get all messages
q_averager = create_averager(q, nb, 0.1)
q_averager.monitored=True
@@ -75,25 +75,20 @@ finally:
#Setting the return value
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
bph_ref_guess = beamphase[index_max] - 80
rph_ref_guess = rfphase[index_max] - 80
if do_elog:
if get_option("Generated data file:\n" + get_exec_pars().path +"\n\n" + "Save to ELOG?", "YesNo") == "Yes":
log_msg = "Data file: " + get_exec_pars().path + "\n"
log_msg = log_msg + "Beam phase reference: %0.1f" % bph_ref + "\n"
log_msg = log_msg + "RF phase reference: %0.1f" % rph_ref + "\n"
log_msg = "Data file: " + get_exec_pars().path + "\n"
log_msg = log_msg + "Beam phase reference: %0.1f" % bph_ref_guess + "deg \n"
log_msg = log_msg + "RF phase reference: %0.1f" % rph_ref_guess + "deg \n"
attachments = []
if plt is not None:
sleep(0.1) #Give some time to plot to be finished - it is not sync with acquisition
file_name = os.path.abspath(get_context().setup.getContextPath() + "/SchottkyScanPlot.png")
plt.saveSnapshot(file_name , "png")
plt.saveSnapshot(file_name, "png")
attachments = [file_name,]
elog("Gun scan", log_msg, attachments)
set_return([bph_ref, rph_ref])
elog("Schottky scan", log_msg, attachments)
set_return([bph_ref_guess, rph_ref_guess])
+15 -16
View File
@@ -1,32 +1,31 @@
dry_run = True
dry_run = False
do_elog = True
if get_exec_pars().source == CommandSource.ui:
phaseOffset = rph_ref
plt = None
do_elog = False
bph_ref_user = 0.0
plt = None
else:
phaseOffset = args[0]
plt = args[1]
bph_ref_user = args[0]
plt = args[1]
rph_ref_new = rph_ref_guess + (bph_ref_guess - bph_ref_user)
phaseOffset = -rph_ref_new
bph_ref_new = rph_ref_new + phaseOffset
print "Setting phase offset: ", phaseOffset
phaseOffset = -phaseOffset
if not dry_run:
caput('SINEG01-RSYS:SET-VSUM-PHASE-OFFSET-BASE', phaseOffset)
caput('SINEG01-RSYS:CMD-LOAD-CALIB-BEAM', 1)
if do_elog:
log_msg = "Phase offset: %0.1f" % bph_ref + "\n"
log_msg = "RF phase reference: %0.1f" % rph_ref_new + "deg \n"
log_msg = log_msg + "Phase offset: %0.1f" % phaseOffset + "deg \n"
log_msg = log_msg + "Beam phase reference: %0.1f" % bph_ref_new + "deg \n"
attachments = []
if plt is not None:
sleep(0.1) #Give some time to plot to be finished - it is not sync with acquisition
file_name = os.path.abspath(get_context().setup.getContextPath() + "/SchottkyScanSetPlot.png")
plt.saveSnapshot(file_name , "png")
attachments = [file_name,]
plt.saveSnapshot(file_name , "png")
attachments = [file_name]
elog("SchottkyScanSet", log_msg, attachments)
show_message("Success setting phase reference")
show_message("Success setting phase reference")
+37 -19
View File
@@ -1,4 +1,8 @@
import ch.psi.pshell.epics.ControlledVariable as ControlledVariable
import ch.psi.pshell.epics.Positioner as Positioner
import ch.psi.pshell.epics.ChannelDouble as ChannelDouble
dry_run = True
do_elog = False
if get_exec_pars().source == CommandSource.ui:
station = "STEST01"
@@ -15,15 +19,25 @@ nb = caget(station + "-RSYS:SET-NUM-AVERAGE")
disp = caget(bpm_ch + ":DISPERSION")
energy0 = caget(bpm_ch + ":ENERGY")
phase = ControlledVariable("Phase", station + "-RSYS:SET-VSUM-PHASE", station + "-RSYS:GET-VSUM-PHASE")
A = energy0 / disp / 1e3
B = energy0
phase = Positioner("Phase", station + "-RSYS:SET-VSUM-PHASE", station + "-RSYS:GET-VSUM-PHASE")
phase.config.minValue =-180.0
phase.config.maxValue = 360.0
phase.config.maxValue = 180.0
phase.config.precision = 4
phase.config.rotation = True
phase.config.resolution = 0.5
phase.initialize()
V = Channel(station + "-RSYS:GET-VSUM-AMPLT", type = 'd', alias='Amplitude Readback')
P = Channel(station + "-RSYS:GET-KLY-POWER", type = 'd', alias='Power Readback')
x = Channel(bpm_ch + ":X1", type = 'd', alias='BPM-X')
V = ChannelDouble("Amplitude Readback", station + "-RSYS:GET-VSUM-AMPLT")
P = ChannelDouble("Power Readback", station + "-RSYS:GET-KLY-POWER")
if dry_run:
x = ChannelDouble("BPM-X", bpm_ch + ":X1-SIMU")
else:
x = ChannelDouble("BPM-X", bpm_ch + ":X1")
V.initialize()
P.initialize()
x.initialize()
phase0 = phase.read()
@@ -37,9 +51,9 @@ caput(station + "-RSYS:GET-ONCREST-KLY-POWER", float('nan'))
#update the plot dynamically
arr_phase,arr_energy = [],[]
def after(rec):
global disp, energy0
global A, B
arr_phase.append(rec.positions[0])
arr_energy.append(energy0 * (1 + rec.values[0].mean / 1000.0 / disp))
arr_energy.append(A * rec.values[0].mean + B)
caput(station + "-RSYS:GET-PHASE-ARRAY", to_array(arr_phase, 'd'))
caput(station + "-RSYS:GET-ENERGY-ARRAY", to_array(arr_energy,'d'))
@@ -47,7 +61,7 @@ try:
x_averager = create_averager(x, nb, 0.100)
r = lscan(phase, x_averager, start, stop, step, latency=lat, after_read = after)
rf_phase = r.getPositions(0)
energy = [energy0 * (1 + val.mean / 1000.0 / disp) for val in r.getReadable(0)]
energy = [A * val.mean + B for val in r.getReadable(0)]
caput(station + "-RSYS:GET-ENERGY-ARRAY", to_array(energy, 'd'))
caput(station + "-RSYS:GET-PHASE-ARRAY", to_array(rf_phase,'d'))
try:
@@ -78,15 +92,19 @@ finally:
phase_offset = 90 - ph_crest
amplitude_scale = fit_amplitude / Ampl
power_scale = Power / math.pow(Ampl,2)
power_scale = Power / math.pow(fit_amplitude,2)
caput(station + "-RSYS:SET-VSUM-PHASE-OFFSET-BASE", phase_offset)
#caput(station + "-RSYS:SET-VSUM-AMPLT-SCALE", amplitude_scale)
#caput(station + "-RSYS:SET-VOLT-POWER-SCALE", power_scale)
caput(station + "-RSYS:SET-VSUM-AMPLT-SCALE", amplitude_scale)
caput(station + "-RSYS:SET-VOLT-POWER-SCALE", power_scale)
#title="Phase scan "+str(station)
#message=("Energy Gain: %0.3f" % energy_gain + "MeV\n" +
# "Phase Offset: %0.2f" % phase_offset + "deg\n" +
# "Amplitude Scale: %0.3f" % amplitude_scale + "MV\n" +
# "Power Scale: %0.3f" % power_scale) + "1/ohm"
#elog(title, message)
if do_elog:
if get_option("Generated data file:\n" + get_exec_pars().path +"\n\n" + "Save to ELOG?", "YesNo") == "Yes":
title = "Phase scan" + station
log_msg = "Data file: " + get_exec_pars().path + "\n"
log_msg = log_msg + "Energy Gain: %0.3f" % energy_gain + "MeV\n"
log_msg = log_msg + "Phase Offset: %0.2f" % phase_offset + "deg\n"
log_msg = log_msg + "Amplitude Scale: %0.3f" % amplitude_scale + "MV\n"
log_msg = log_msg + "Power Scale: %0.3f" % power_scale + "MW/MV^2"
attachments = []
elog(title, log_msg, attachments)
+14
View File
@@ -0,0 +1,14 @@
import ch.psi.pshell.imaging.Data as Data
d = load_data("2017/06/16/20170616_122305_snapshot.h5|/data")
atts = get_attributes("2017/06/16/20170616_122305_snapshot.h5|/data")
data = Data(d)
iv = data.integrateVertically(False)
ih = data.integrateHorizontally(False)
xp = atts["x_profile"]
yp = atts["y_profile"]
p1, p2 = plot([xp, yp], ["X profile", "Y profile"])
p1.addSeries(LinePlotSeries("d"))
p2.addSeries(LinePlotSeries("d"))
p1.getSeries(1).setData(iv)
p2.getSeries(1).setData(ih)
+33
View File
@@ -0,0 +1,33 @@
#import ch.psi.pshell.epics.ChannelDouble as ChannelDouble
import ch.psi.pshell.bs.Scalar as Scalar
import ch.psi.pshell.bs.Waveform as Waveform
dispatcher.config.disableCompression = False
set_exec_pars(persist = False)
#Arguments
SAMPLES = 5
BLMS = ["SINDI02-DBLM025", ] #"SINDI02-DBLM085", "S10DI01-DBLM045"]
sensors = []
st = Stream("pulse_id", dispatcher)
#st.setFilter("SIN-CVME-TIFGUN-EVR0:BEAMOK == 1")
for i in range(len(BLMS)):
blm = Scalar("blm" + str(i+1), st, BLMS[i] + ":B1_LOSS", 1, 0)
av = create_averager(blm, SAMPLES, interval = -1)
av.setMonitored(i>0)
sensors.append(av)
sensors.append(av.stdev)
sensors.append(av.samples)
bpmw = Waveform("blmw" + str(i+1), st, BLMS[i] + ":LOSS_SIGNAL_RAW", 1, 0)
sensors.append(bpmw)
st.initialize()
st.start()
if not st.waitCacheChange(3000): #Wait stream be running before starting scan
raise Exception("Stream timeout")
bscan(st, 10)
+100
View File
@@ -0,0 +1,100 @@
#import ch.psi.pshell.epics.ChannelDouble as ChannelDouble
import ch.psi.pshell.bs.Scalar as Scalar
import ch.psi.pshell.bs.Waveform as Waveform
import ch.psi.pshell.epics.DiscretePositioner as DiscretePositioner
dispatcher.config.disableCompression = True
#set_exec_pars(persist = False)
#Arguments
SAMPLES = 2
GAINS = ["SINDI02-DBLM084:M06-1-CH03-V-MM","SINDI02-DBLM084:M06-2-CH03-V-MM","S10DI01-DBLM113:M06-1-CH03-V-MM"]
BLMS = ["SINDI02-DBLM025", "SINDI02-DBLM085", "S10DI01-DBLM045"]
BLMW = ["SINDI02-DBLM025:LOSS_SIGNAL_RAW", "SINDI02-DBLM085:LOSS_SIGNAL_RAW", "S10DI01-DBLM045:LOSS_SIGNAL_RAW"]
BPMS = ["SINDI01-DBPM060:Q1", "SINDI02-DBPM010:Q1"]
ATTENUATORS = ["SINDI02-DBLM084:M06-1-ATT2-VAL", "SINDI02-DBLM084:M06-2-ATT2-VAL", "S10DI01-DBLM113:M06-1-ATT2-VAL"]
ATT_SP = 0 #3,6,9,12,15
RANGE = [0.5, 1.1]
STEP_SIZE = 0.1
SETTLING_TIME = 0.5
SIMULATION = False
do_elog = True
gain_positioners = []
for i in range(len(GAINS)):
gain_positioners.append( DummyPositioner("gain " + str(i+1)) if SIMULATION else Channel(GAINS[i], alias = "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
class ListenerBpmw (DeviceListener):
def onValueChanged(self, device, value, former):
if sampling and (get_exec_pars().scan is not None):
path = get_exec_pars().group + "rec " + str(get_exec_pars().scan.recordIndex) + "/" + device.name
if "Exception" in get_attributes(path).keys(): #If file does not exist
create_dataset(path, 'd', False, (0, len(value)))
append_dataset(path,value)
sampling = False
def before():
global sampling
sampling = True
def after():
global sampling
sampling = False
sensors = []
line_plots = []
st = Stream("pulse_id", dispatcher)
st.setFilter("SIN-CVME-TIFGUN-EVR0:BEAMOK == 1")
for i in range(len(BLMS)):
blm = Scalar("blm" + str(i+1), st, BLMS[i] + ":B1_LOSS", 1, 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)
bpmw = Waveform("blmw" + str(i+1), st, BLMS[i] + ":LOSS_SIGNAL_RAW", 1, 0)
#sensors.append(bpmw)
bpmw.addListener(ListenerBpmw())
#st.initialize()
#st.start()
#st.waitCacheChange(10000) #Wait stream be running before starting scan
for i in range(len(BPMS)):
bpm = Scalar("bpm" + str(i+1), st, BPMS[i], 1, 0)
av1 = create_averager(bpm, SAMPLES, interval = -1)
av1.setMonitored(i>0 or (len(BLMS) > 0))
sensors.append(av1)
sensors.append(av1.stdev)
sensors.append(av1.samples)
line_plots.append(av1.samples)
#Scalar("beam_ok" , st, "SIN-CVME-TIFGUN-EVR0:BEAMOK" , 1, 0)
try:
st.initialize()
st.start()
if not st.waitCacheChange(10000): #Wait stream be running before starting scan
raise Exception("Stream timeout")
tscan(sensors, 5, 0.5, before_read=before, after_read=after)
finally:
st.close()
@@ -1,4 +1,8 @@
import ch.psi.pshell.epics.ControlledVariable as ControlledVariable
import ch.psi.pshell.epics.Positioner as Positioner
import ch.psi.pshell.epics.ChannelDouble as ChannelDouble
dry_run = True
do_elog = False
if get_exec_pars().source == CommandSource.ui:
station = "STEST01"
@@ -15,15 +19,22 @@ nb = caget(station + "-RSYS:SET-NUM-AVERAGE")
disp = caget(bpm_ch + ":DISPERSION")
energy0 = caget(bpm_ch + ":ENERGY")
phase = ControlledVariable("Phase", station + "-RSYS:SET-VSUM-PHASE", station + "-RSYS:GET-VSUM-PHASE")
phase = Positioner("Phase", station + "-RSYS:SET-VSUM-PHASE", station + "-RSYS:GET-VSUM-PHASE")
phase.config.minValue =-180.0
phase.config.maxValue = 360.0
phase.config.maxValue = 180.0
phase.config.precision = 3
phase.config.rotation = True
phase.config.resolution = 0.5
phase.initialize()
V = Channel(station + "-RSYS:GET-VSUM-AMPLT", type = 'd', alias='Amplitude Readback')
P = Channel(station + "-RSYS:GET-KLY-POWER", type = 'd', alias='Power Readback')
x = Channel(bpm_ch + ":X1-SIMU", type = 'd', alias='BPM-X')
V = ChannelDouble("Amplitude Readback", station + "-RSYS:GET-VSUM-AMPLT")
P = ChannelDouble("Power Readback", station + "-RSYS:GET-KLY-POWER")
if dry_run:
x = ChannelDouble("BPM-X", bpm_ch + ":X1-SIMU")
else:
x = ChannelDouble("BPM-X", bpm_ch + ":X1")
V.initialize()
P.initialize()
x.initialize()
phase0 = phase.read()
@@ -84,9 +95,18 @@ caput(station + "-RSYS:SET-VSUM-PHASE-OFFSET-BASE", phase_offset)
caput(station + "-RSYS:SET-VSUM-AMPLT-SCALE", amplitude_scale)
caput(station + "-RSYS:SET-VOLT-POWER-SCALE", power_scale)
#title="Phase scan "+str(station)
#message=("Energy Gain: %0.3f" % energy_gain + "MeV\n" +
# "Phase Offset: %0.2f" % phase_offset + "deg\n" +
# "Amplitude Scale: %0.3f" % amplitude_scale + "MV\n" +
# "Power Scale: %0.3f" % power_scale) + "1/ohm"
#elog(title, message)
if do_elog:
if get_option("Generated data file:\n" + get_exec_pars().path +"\n\n" + "Save to ELOG?", "YesNo") == "Yes":
title = "Phase scan" + station
log_msg = "Data file: " + get_exec_pars().path + "\n"
log_msg = log_msg + "Energy Gain: %0.3f" % energy_gain + "MeV\n"
log_msg = log_msg + "Phase Offset: %0.2f" % phase_offset + "deg\n"
log_msg = log_msg + "Amplitude Scale: %0.3f" % amplitude_scale + "MV\n"
log_msg = log_msg + "Power Scale: %0.3f" % power_scale + "MW/MV^2"
attachments = []
if plt is not None:
sleep(0.1) #Give some time to plot to be finished - it is not sync with acquisition
file_name = os.path.abspath(get_context().setup.getContextPath() + "/SchottkyScanPlot.png")
plt.saveSnapshot(file_name, "png")
attachments = [file_name,]
elog(title, log_msg, attachments)