This commit is contained in:
8
script/Tools/BucketAlcorDown.py
Normal file
8
script/Tools/BucketAlcorDown.py
Normal file
@@ -0,0 +1,8 @@
|
||||
MO_FREQ = 142.8e6 # MO = 142.8 MHz
|
||||
rf_period = 1 / MO_FREQ / 21 / 1e-12 # ps
|
||||
delay = caget("SLGOS01-TSPL-ALC:NEW_DELTA_T")
|
||||
delay = delay + rf_period
|
||||
print("SLGOS01-TSPL-ALC:NEW_DELTA_T", delay)
|
||||
print("SLGOS01-TSPL-ALC:SET_NEW_PHASE.PROC", 1)
|
||||
caput("SLGOS01-TSPL-ALC:NEW_DELTA_T", delay)
|
||||
caput("SLGOS01-TSPL-ALC:SET_NEW_PHASE.PROC", 1)
|
||||
8
script/Tools/BucketAlcorUp.py
Normal file
8
script/Tools/BucketAlcorUp.py
Normal file
@@ -0,0 +1,8 @@
|
||||
MO_FREQ = 142.8e6 # MO = 142.8 MHz
|
||||
rf_period = 1 / MO_FREQ / 21 / 1e-12 # ps
|
||||
delay = caget("SLGOS01-TSPL-ALC:NEW_DELTA_T")
|
||||
delay = delay - rf_period
|
||||
print("SLGOS01-TSPL-ALC:NEW_DELTA_T", delay)
|
||||
print("SLGOS01-TSPL-ALC:SET_NEW_PHASE.PROC", 1)
|
||||
caput("SLGOS01-TSPL-ALC:NEW_DELTA_T", delay)
|
||||
caput("SLGOS01-TSPL-ALC:SET_NEW_PHASE.PROC", 1)
|
||||
8
script/Tools/BucketMizarDown.py
Normal file
8
script/Tools/BucketMizarDown.py
Normal file
@@ -0,0 +1,8 @@
|
||||
MO_FREQ = 142.8e6 # MO = 142.8 MHz
|
||||
rf_period = 1 / MO_FREQ / 21 / 1e-12 # ps
|
||||
delay = caget("SLGOS01-TSPL-MIZ:NEW_DELTA_T")
|
||||
delay = delay + rf_period
|
||||
print("SLGOS01-TSPL-MIZ:NEW_DELTA_T", delay)
|
||||
print("SLGOS01-TSPL-MIZ:SET_NEW_PHASE.PROC", 1)
|
||||
caput("SLGOS01-TSPL-MIZ:NEW_DELTA_T", delay)
|
||||
caput("SLGOS01-TSPL-MIZ:SET_NEW_PHASE.PROC", 1)
|
||||
8
script/Tools/BucketMizarUp.py
Normal file
8
script/Tools/BucketMizarUp.py
Normal file
@@ -0,0 +1,8 @@
|
||||
MO_FREQ = 142.8e6 # MO = 142.8 MHz
|
||||
rf_period = 1 / MO_FREQ / 21 / 1e-12 # ps
|
||||
delay = caget("SLGOS01-TSPL-MIZ:NEW_DELTA_T")
|
||||
delay = delay - rf_period
|
||||
print("SLGOS01-TSPL-MIZ:NEW_DELTA_T", delay)
|
||||
print("SLGOS01-TSPL-MIZ:SET_NEW_PHASE.PROC", 1)
|
||||
caput("SLGOS01-TSPL-MIZ:NEW_DELTA_T", delay)
|
||||
caput("SLGOS01-TSPL-MIZ:SET_NEW_PHASE.PROC", 1)
|
||||
29
script/Tools/BunchLengthPrep.py
Normal file
29
script/Tools/BunchLengthPrep.py
Normal file
@@ -0,0 +1,29 @@
|
||||
#Parameters
|
||||
is_panel = get_exec_pars().source != CommandSource.ui # run from panel
|
||||
if is_panel:
|
||||
tds = args[0]
|
||||
else:
|
||||
tds = "S30CB14"
|
||||
run("Tools/BunchLengthTDSdata.py")
|
||||
|
||||
# stop the beam
|
||||
caput("SIN-TIMAST-TMA:Beam-RF-OnDelay-Sel", 1)
|
||||
caput("SIN-TIMAST-TMA:Beam-Apply-Cmd.PROC", 1)
|
||||
caput("SIN-TIMAST-TMA:Bunch-1-Freq-Sel", 10)
|
||||
caput("SIN-TIMAST-TMA:Bunch-2-Freq-Sel", 10)
|
||||
|
||||
# beam stopper and coll.
|
||||
if tds == "SINDI01":
|
||||
caput("S10CB01-RSYS:REQUIRED-OP", 0)
|
||||
caput("S10CB02-RSYS:REQUIRED-OP", 0)
|
||||
caput("S10DI01-MBND100:P-SET", 297.0)
|
||||
if tds == "S30CB14":
|
||||
caput("SARMA02-MBNP100:REQUEST", 1)
|
||||
#caput("SARCL01-DCOL030:GAP", 5.0)
|
||||
caput("SARCL02-VCOL290:GAP", 8.0)
|
||||
|
||||
# set optics
|
||||
quads = tds_data[tds]["quads"]
|
||||
k1l = tds_data[tds]["K1L-meas"]
|
||||
for i in range(len(quads)):
|
||||
caput(quads[i] + ":K1L-SET", k1l[i])
|
||||
26
script/Tools/BunchLengthRestore.py
Normal file
26
script/Tools/BunchLengthRestore.py
Normal file
@@ -0,0 +1,26 @@
|
||||
#Parameters
|
||||
is_panel = get_exec_pars().source != CommandSource.ui # run from panel
|
||||
if is_panel:
|
||||
tds = args[0]
|
||||
else:
|
||||
tds = "S30CB14"
|
||||
run("Tools/BunchLengthTDSdata.py")
|
||||
|
||||
# stop the beam
|
||||
caput("SIN-TIMAST-TMA:Beam-RF-OnDelay-Sel", 1)
|
||||
caput("SIN-TIMAST-TMA:Beam-Apply-Cmd.PROC", 1)
|
||||
caput("SIN-TIMAST-TMA:Bunch-1-Freq-Sel", 10)
|
||||
caput("SIN-TIMAST-TMA:Bunch-2-Freq-Sel", 10)
|
||||
|
||||
# beam stopper and coll.
|
||||
if tds == "S30CB14":
|
||||
#caput("SARCL01-DCOL030:GAP", 5.0)
|
||||
caput("SARCL02-VCOL290:GAP", 5.0)
|
||||
|
||||
# restore nominal optics
|
||||
quads = tds_data[tds]["quads"]
|
||||
k1l = tds_data[tds]["K1L-nom"]
|
||||
for i in range(len(quads)):
|
||||
caput(quads[i] + ":K1L-SET", k1l[i])
|
||||
|
||||
# show message: restore optics and coll.
|
||||
261
script/Tools/BunchLengthScan.py
Normal file
261
script/Tools/BunchLengthScan.py
Normal file
@@ -0,0 +1,261 @@
|
||||
import ch.psi.pshell.epics.Positioner as Positioner
|
||||
from mathutils import fit_polynomial
|
||||
|
||||
#Parameters
|
||||
dry_run = False
|
||||
do_elog = True
|
||||
USE_SCREEN_PANEL = True
|
||||
MO_FREQ = 142.8e6 # MO = 142.8 MHz
|
||||
is_panel = get_exec_pars().source != CommandSource.ui # run from panel
|
||||
if is_panel:
|
||||
start = args[0]
|
||||
stop = args[1] + 0.001 # needed to get the last point
|
||||
step = args[2]
|
||||
nb = int(args[3])
|
||||
lat = args[4]
|
||||
thr = args[5]
|
||||
tds = args[6]
|
||||
bunch = args[7]
|
||||
plt11 = args[8]
|
||||
plt12 = args[9]
|
||||
plt21 = args[10]
|
||||
plt22 = args[11]
|
||||
else:
|
||||
start = -0.1
|
||||
stop = 0.1 + 0.001
|
||||
step = 0.05
|
||||
nb = 5
|
||||
lat = 2.0
|
||||
thr = 250
|
||||
tds = "S30CB14"
|
||||
bunch = "Bunch1"
|
||||
plt11 = plot(None, title="Output")[0]
|
||||
plt12 = plot(None, title="Output")[0]
|
||||
plt21 = plot(None, title="Output")[0]
|
||||
plt22 = plot(None, title="Output")[0]
|
||||
run("Tools/BunchLengthTDSdata.py")
|
||||
|
||||
#Record callback: update of output plot
|
||||
def update_plot(record, scan, plt):
|
||||
com_mean, com_stdev = record[0].mean, record[0].stdev
|
||||
rms_mean, rms_stdev = record[1].mean, record[1].stdev
|
||||
fw_mean, fw_stdev = record[2].mean, record[2].stdev
|
||||
fit_mean, fit_stdev = record[3].mean, record[3].stdev
|
||||
phase = record.positions[0]
|
||||
plt.getSeries(0).appendData(phase, com_mean, com_stdev)
|
||||
plt.getSeries(1).appendData(phase, rms_mean, rms_stdev)
|
||||
plt.getSeries(2).appendData(phase, fw_mean, fw_stdev)
|
||||
plt.getSeries(3).appendData(phase, fit_mean, fit_stdev)
|
||||
|
||||
def update_plot_1(record, scan):
|
||||
global plt11
|
||||
update_plot(record, scan, plt11)
|
||||
|
||||
def update_plot_2(record, scan):
|
||||
global plt12
|
||||
update_plot(record, scan, plt12)
|
||||
|
||||
#Plot setup
|
||||
def init_plots(plt1, plt2):
|
||||
plt1.clear()
|
||||
plt1.removeMarker(None)
|
||||
plt1.setStyle(plt1.Style.ErrorY)
|
||||
plt1.addSeries(LinePlotErrorSeries("Bunch center of mass", Color.red))
|
||||
plt1.addSeries(LinePlotErrorSeries("Bunch length rms", Color.yellow, 2))
|
||||
plt1.addSeries(LinePlotErrorSeries("Bunch length fw", Color.green, 2))
|
||||
plt1.addSeries(LinePlotErrorSeries("Bunch length gauss fit", Color.blue, 2))
|
||||
plt1.getAxis(plt1.AxisId.X).setLabel("TDS Phase (deg)")
|
||||
plt1.getAxis(plt1.AxisId.Y).setLabel("Bunch center of mass (um)")
|
||||
plt1.getAxis(plt1.AxisId.Y2).setLabel("Bunch length (um)")
|
||||
plt1.setLegendVisible(True)
|
||||
plt2.clear()
|
||||
plt2.removeMarker(None)
|
||||
plt2.setStyle(plt2.Style.Normal)
|
||||
plt2.getAxis(plt2.AxisId.X).setLabel("Time (fs)")
|
||||
plt2.getAxis(plt2.AxisId.Y).setLabel("Current (kA)")
|
||||
plt2.setLegendVisible(False)
|
||||
|
||||
init_plots(plt11, plt21)
|
||||
init_plots(plt12, plt22)
|
||||
|
||||
#Creating Phase positioner
|
||||
if dry_run:
|
||||
phase = DummyPositioner("TDS Phase")
|
||||
camera_name = "simulation"
|
||||
else:
|
||||
phase = Positioner("TDS Phase", tds + "-RSYS:SET-BEAM-PHASE", tds + "-RSYS:SET-BEAM-PHASE")
|
||||
camera_name = tds_data[tds]["screen"]
|
||||
phase.config.minValue = -90.0
|
||||
phase.config.maxValue = 270.0
|
||||
phase.config.precision = 4
|
||||
phase.config.resolution = 0.05
|
||||
phase.config.rotation = True
|
||||
phase.config.save()
|
||||
phase.initialize()
|
||||
phase0 = phase.read() % 360
|
||||
|
||||
#Camera setup
|
||||
if USE_SCREEN_PANEL:
|
||||
cam_server.start(camera_name+"_sp1", True) # shared pipeline
|
||||
else:
|
||||
cam_server.start(camera_name) # generic pipeline
|
||||
cam_server.setFunction("beam_full_width")
|
||||
cam_server.setInstanceConfigValue("fw_threshold", 0.3)
|
||||
cam_server.setThreshold(thr)
|
||||
cam_server.setBackgroundSubtraction(False)
|
||||
cam_server.setGoodRegion(0.1, 3.0)
|
||||
print "Waiting for y_fw and y_fit"
|
||||
timeout = 1.0
|
||||
start_time = time.time()
|
||||
while (True):
|
||||
wait_cam_server_message()
|
||||
y_fw = cam_server.stream.getChild("y_fw")
|
||||
y_fit = cam_server.stream.getChild("gr_y_fit_standard_deviation")
|
||||
if (y_fw is not None) and (y_fit is not None):
|
||||
break
|
||||
if time.time() - start_time > timeout:
|
||||
if y_fw is None:
|
||||
raise Exception("y_fw not in camera stream")
|
||||
if y_fit is None:
|
||||
raise Exception("y_fit not in camera stream")
|
||||
y_center_of_mass = cam_server.stream.getChild("y_center_of_mass")
|
||||
y_rms = cam_server.stream.getChild("y_rms")
|
||||
y_profile = cam_server.stream.getChild("y_profile")
|
||||
y_axis = cam_server.stream.getChild("y_axis")
|
||||
|
||||
#Creating averagers
|
||||
com_averager = create_averager(y_center_of_mass, nb, -1) # -1 event based, waits for the next value
|
||||
rms_averager = create_averager(y_rms, nb, -1)
|
||||
fw_averager = create_averager(y_fw, nb, -1)
|
||||
fit_averager = create_averager(y_fit, nb, -1)
|
||||
rms_averager.monitored = True # not blocking, will return last nb values
|
||||
fw_averager.monitored = True
|
||||
fit_averager.monitored = True
|
||||
|
||||
#switch BLMs off
|
||||
blm = tds_data[tds]["BLM"]
|
||||
strg = ":B1_ROI_ACTIVE_OP" if bunch == "Bunch1" else ":B2_ROI_ACTIVE_OP"
|
||||
for i in range(len(blm)):
|
||||
if dry_run:
|
||||
print(blm[i] + strg, 0)
|
||||
else:
|
||||
caput(blm[i] + strg, 0)
|
||||
|
||||
#The scan loop
|
||||
try:
|
||||
bunch1_charge = caget("SINEG01-DBPM340:Q1")
|
||||
bunch2_charge = caget("SINEG01-DBPM340:Q2")
|
||||
bunch_charge = bunch1_charge if bunch == "Bunch1" else bunch2_charge
|
||||
sensor_list = [com_averager, rms_averager, fw_averager, fit_averager, y_axis, y_profile, y_center_of_mass]
|
||||
phase.write(start)
|
||||
time.sleep(1.0)
|
||||
# get bs phase-jitter / screen position data for SATMA02 calib
|
||||
r1 = lscan(phase, sensor_list, start, stop, step , latency=lat, after_read = update_plot_1)
|
||||
start, stop = start + 180.0, stop + 180.0
|
||||
phase.write(start)
|
||||
time.sleep(10.0)
|
||||
r2 = lscan(phase, sensor_list, start, stop, step , latency=lat, after_read = update_plot_2)
|
||||
finally:
|
||||
phase.write(phase0)
|
||||
phase.close()
|
||||
cam_server.stop() # stops cam_server but does not close it cam_server is a global object
|
||||
|
||||
# stop the beam
|
||||
if dry_run:
|
||||
print("SIN-TIMAST-TMA:Beam-RF-OnDelay-Sel", 1)
|
||||
print("SIN-TIMAST-TMA:Beam-Apply-Cmd.PROC", 1)
|
||||
else:
|
||||
caput("SIN-TIMAST-TMA:Beam-RF-OnDelay-Sel", 1)
|
||||
caput("SIN-TIMAST-TMA:Beam-Apply-Cmd.PROC", 1)
|
||||
|
||||
#switch BLMs on
|
||||
for i in range(len(blm)):
|
||||
if dry_run:
|
||||
print(blm[i] + strg, 1)
|
||||
else:
|
||||
caput(blm[i] + strg, 1)
|
||||
|
||||
#output
|
||||
def write_output(r, plt):
|
||||
phase_pos = r.getPositions(0)
|
||||
rf_period = 1 / MO_FREQ / tds_data[tds]["harm"]
|
||||
time_pos = [val / 360.0 * rf_period * 1e15 for val in phase_pos] # in fs
|
||||
bunch_center = [val.mean for val in r.getReadable(0)]
|
||||
bunch_center_stdev = [val.stdev for val in r.getReadable(0)]
|
||||
a0, a1 = fit_polynomial(time_pos, bunch_center, 1)
|
||||
calib = abs(a1) # in fs/um
|
||||
#calib = 1
|
||||
bunch_length_rms = [val.mean * calib for val in r.getReadable(1)]
|
||||
bunch_length_rms_average = sum(bunch_length_rms) / len(bunch_length_rms)
|
||||
bunch_length_fw = [val.mean * calib for val in r.getReadable(2)]
|
||||
bunch_length_fw_average = sum(bunch_length_fw) / len(bunch_length_fw)
|
||||
bunch_length_fit = [val.mean * calib for val in r.getReadable(3)]
|
||||
bunch_length_fit_average = sum(bunch_length_fit) / len(bunch_length_fit)
|
||||
profiles_um = r[y_axis]
|
||||
profiles_dig = r[y_profile]
|
||||
profiles_com = r[y_center_of_mass]
|
||||
com = sum(profiles_com) / len(profiles_com)
|
||||
profiles_fs = []
|
||||
profiles_kA = []
|
||||
for i in range(len(r[y_axis])):
|
||||
delta_um = profiles_com[i] - com
|
||||
profiles_fs.append([(val - delta_um) * calib for val in profiles_um[i]])
|
||||
step_fs = (max(profiles_fs[i]) - min(profiles_fs[i])) / (len(profiles_fs[i]) - 1)
|
||||
total_dig = float(sum(profiles_dig[i]))
|
||||
profiles_kA.append([val / total_dig * bunch_charge / step_fs for val in profiles_dig[i]]) # pC / fs = kA
|
||||
for i in range(len(profiles_um)):
|
||||
plt.addSeries(LinePlotSeries("Bunch current " + str(i), Color.red))
|
||||
plt.getSeries(i).setData(profiles_fs[i], profiles_kA[i])
|
||||
return bunch_length_rms_average, bunch_length_fw_average, bunch_length_fit_average, calib
|
||||
|
||||
bunch_length_rms_average1, bunch_length_fw_average1, bunch_length_fit_average1, calib1 = write_output(r1, plt21)
|
||||
bunch_length_rms_average2, bunch_length_fw_average2, bunch_length_fit_average2, calib2 = write_output(r2, plt22)
|
||||
bunch_length_rms = (bunch_length_rms_average1 + bunch_length_rms_average2) / 2
|
||||
bunch_length_fw = (bunch_length_fw_average1 + bunch_length_fw_average2) / 2
|
||||
bunch_length_fit = (bunch_length_fit_average1 + bunch_length_fit_average2) / 2
|
||||
calib = (calib1 + calib2) / 2
|
||||
|
||||
#archiver channels
|
||||
if bunch == "Bunch1":
|
||||
caput(tds + "-RTDS100:BD-BUNCH1-DURATION", bunch_length_fw)
|
||||
caput(tds + "-RTDS100:BD-BUNCH1-CALIBRATION", 1 / calib)
|
||||
else:
|
||||
caput(tds + "-RTDS100:BD-BUNCH2-DURATION", bunch_length_fw)
|
||||
caput(tds + "-RTDS100:BD-BUNCH2-CALIBRATION", 1 / calib)
|
||||
|
||||
#Elog entry
|
||||
if do_elog:
|
||||
if get_option("Generated data file:\n" + get_exec_pars().path +"\n\n" + "Save to ELOG?", "YesNo") == "Yes":
|
||||
title = "Bunch length Scan"
|
||||
log_msg = "Data file: " + get_exec_pars().path + "\n\n"
|
||||
log_msg = log_msg + "TDS: " + tds + "\n"
|
||||
log_msg = log_msg + "Bunch: " + bunch + "\n\n"
|
||||
log_msg = log_msg + "#### 0 deg ####\n"
|
||||
log_msg = log_msg + "Bunch length rms: %0.1f" % bunch_length_rms_average1 + " fs\n"
|
||||
log_msg = log_msg + "Bunch length fw: %0.1f" % bunch_length_fw_average1 + " fs\n"
|
||||
log_msg = log_msg + "Bunch length fit: %0.1f" % bunch_length_fit_average1 + " fs\n"
|
||||
log_msg = log_msg + "Calibration: %0.4f" % calib1 + " fs/um\n\n"
|
||||
log_msg = log_msg + "#### 180 deg ####\n"
|
||||
log_msg = log_msg + "Bunch length rms: %0.1f" % bunch_length_rms_average2 + " fs\n"
|
||||
log_msg = log_msg + "Bunch length fw: %0.1f" % bunch_length_fw_average2 + " fs\n"
|
||||
log_msg = log_msg + "Bunch length fit: %0.1f" % bunch_length_fit_average2 + " fs\n"
|
||||
log_msg = log_msg + "Calibration: %0.4f" % calib2 + " fs/um\n\n"
|
||||
log_msg = log_msg + "#### mean ####\n"
|
||||
log_msg = log_msg + "Bunch length rms: %0.1f" % bunch_length_rms + " fs\n"
|
||||
log_msg = log_msg + "Bunch length fw: %0.1f" % bunch_length_fw + " fs\n"
|
||||
log_msg = log_msg + "Bunch length fit: %0.1f" % bunch_length_fit + " fs\n"
|
||||
log_msg = log_msg + "Calibration: %0.4f" % calib + " fs/um"
|
||||
sleep(0.1) #Give some time to plot to be finished - it is not sync with acquisition
|
||||
file_name1 = os.path.abspath(get_context().setup.getContextPath() + "/BunchLengthScanPlot1.png")
|
||||
plt11.saveSnapshot(file_name1, "png")
|
||||
file_name2 = os.path.abspath(get_context().setup.getContextPath() + "/BunchLengthCurrent1.png")
|
||||
plt21.saveSnapshot(file_name2, "png")
|
||||
file_name3 = os.path.abspath(get_context().setup.getContextPath() + "/BunchLengthScanPlot2.png")
|
||||
plt12.saveSnapshot(file_name3, "png")
|
||||
file_name4 = os.path.abspath(get_context().setup.getContextPath() + "/BunchLengthCurrent2.png")
|
||||
plt22.saveSnapshot(file_name4, "png")
|
||||
elog(title, log_msg, [file_name1, file_name2, file_name3, file_name4])
|
||||
|
||||
set_return([bunch_length_rms_average1, bunch_length_fw_average1, bunch_length_fit_average1, calib1,
|
||||
bunch_length_rms_average2, bunch_length_fw_average2, bunch_length_fit_average2, calib2,
|
||||
bunch_length_rms, bunch_length_fw, bunch_length_fit, calib])
|
||||
47
script/Tools/BunchLengthTDSdata.py
Normal file
47
script/Tools/BunchLengthTDSdata.py
Normal file
@@ -0,0 +1,47 @@
|
||||
#tds config
|
||||
tds_data = {'SINDI01': {"harm": 21, "screen": "SINDI02-DSCR075",
|
||||
"quads":
|
||||
["SINDI02-MQUA020", "SINDI02-MQUA030", "SINDI02-MQUA050",
|
||||
"SINDI02-MQUA060"],
|
||||
"K1L-nom":
|
||||
[-0.020000, 0.050000, -0.165000,
|
||||
0.200000],
|
||||
"K1L-meas":
|
||||
[-0.389776, 0.324016, 0.067305,
|
||||
0.174710],
|
||||
"BLM": []},
|
||||
'S30CB14': {"harm": 40, "screen": "SARCL01-DSCR170",
|
||||
"quads":
|
||||
["S30CB10-MQUA430", "S30CB11-MQUA430", "S30CB12-MQUA430",
|
||||
"S30CB13-MQUA430", "S30CB14-MQUA430", "S30CB15-MQUA430",
|
||||
"SARCL01-MQUA020", "SARCL01-MQUA050", "SARCL01-MQUA080",
|
||||
"SARCL01-MQUA100", "SARCL01-MQUA140", "SARCL01-MQUA190"],
|
||||
"K1L-nom":
|
||||
[-0.125000, 0.125000, -0.125000,
|
||||
0.125000, -0.125000, 0.125000,
|
||||
-0.070000, 0.010000, -0.145000,
|
||||
0.155000, 0.415000, -0.490000],
|
||||
"K1L-meas":
|
||||
[-0.102751, -0.014919, 0.112685,
|
||||
-0.064000, -0.053854, 0.048777,
|
||||
0.104904, -0.039548, -0.005735,
|
||||
0.005119, -0.027870, -0.011176],
|
||||
"BLM":
|
||||
["SARCL02-DBLM135", "SARCL02-DBLM355", "SARUN01-DBLM065",
|
||||
"SARUN03-DBLM030", "SARUN04-DBLM030", "SARUN05-DBLM030",
|
||||
"SARUN06-DBLM030", "SARUN07-DBLM030", "SARUN08-DBLM030",
|
||||
"SARUN09-DBLM030", "SARUN10-DBLM030", "SARUN11-DBLM030",
|
||||
"SARUN12-DBLM030", "SARUN13-DBLM030", "SARUN14-DBLM030",
|
||||
"SARUN15-DBLM030", "SARUN15-DBLM035", "SARUN20-DBLM035"]},
|
||||
'SATMA02': {"harm": 84, "screen": "SATBD01-DSCR120",
|
||||
"quads":
|
||||
["SATBD01-MQUA010", "SATBD01-MQUA030", "SATBD01-MQUA050",
|
||||
"SATBD01-MQUA070", "SATBD01-MQUA090"],
|
||||
"K1L-nom":
|
||||
[ 0.150000, -0.185000, 0.040000,
|
||||
0.140000, -0.225000],
|
||||
"K1L-meas":
|
||||
[-0.090111, 0.108271, 0.025250,
|
||||
-0.072006, -0.382500],
|
||||
"BLM": []}}
|
||||
|
||||
119
script/Tools/CameraCorrelation.py
Normal file
119
script/Tools/CameraCorrelation.py
Normal file
@@ -0,0 +1,119 @@
|
||||
import math
|
||||
import sys, traceback
|
||||
from mathutils import fit_polynomial, PolynomialFunction
|
||||
from plotutils import plot_line, plot_function
|
||||
from ch.psi.pshell.swing.Shell import getColorStdout
|
||||
import org.apache.commons.math3.stat.correlation.PearsonsCorrelation as PearsonsCorrelation
|
||||
import ch.psi.pshell.bs.StreamMerger as StreamMerger
|
||||
|
||||
|
||||
_stop_exec = False
|
||||
_task = None
|
||||
_dispatcher_stream = None
|
||||
|
||||
def start_camera_correlation(dispatcer_channel, camera_channel, samples=50, modulo=1, offset=0, plt=None):
|
||||
global _stop_exec, _task, _dispatcher_stream
|
||||
stop_camera_correlation()
|
||||
|
||||
if plt:
|
||||
for s in plt.getAllSeries():
|
||||
plt.removeSeries(s)
|
||||
|
||||
class LinearFit(ReadonlyAsyncRegisterBase, ReadonlyRegisterArray):
|
||||
def getSize(self):
|
||||
return 2
|
||||
def set(self, pars):
|
||||
self.onReadout(to_array(pars, 'd'))
|
||||
|
||||
class Correlation(ReadonlyAsyncRegisterBase):
|
||||
def set(self, val):
|
||||
self.onReadout(val)
|
||||
|
||||
add_device(LinearFit("linear_fit"), True)
|
||||
add_device(Correlation("correlation"), True)
|
||||
|
||||
|
||||
|
||||
try:
|
||||
_dispatcher_stream = Stream("corr_stream", dispatcher)
|
||||
_dispatcher_stream.addScalar(dispatcer_channel, dispatcer_channel, modulo, offset)
|
||||
_dispatcher_stream.initialize()
|
||||
_dispatcher_stream.start(True)
|
||||
_dispatcher_stream.setBufferCapacity(500)
|
||||
|
||||
camera_name, camera_channel = camera_channel.split(" ")
|
||||
shared = camera_name.endswith("_sp1")
|
||||
cam_server.start(camera_name, shared )
|
||||
camera_stream = cam_server.stream
|
||||
camera_stream.setBufferCapacity(500)
|
||||
camera_stream.waitCacheChange(10000);
|
||||
|
||||
def merger_task():
|
||||
merger = StreamMerger("stream", _dispatcher_stream, camera_stream)
|
||||
try:
|
||||
if plt:
|
||||
sd = LinePlotSeries("Data")
|
||||
plt.addSeries(sd)
|
||||
sd.setLinesVisible(False)
|
||||
sd.setPointSize(4)
|
||||
else:
|
||||
ax,ay = [],[]
|
||||
merger.monitored=True
|
||||
merger.start()
|
||||
merger.waitCacheChange(5000)
|
||||
|
||||
dx=merger.getChild(dispatcer_channel)
|
||||
dy=merger.getChild(camera_channel)
|
||||
|
||||
while(not _stop_exec):
|
||||
merger.waitCacheChange(10000)
|
||||
x=dx.read()
|
||||
y=dy.read()
|
||||
|
||||
if plt:
|
||||
sd.appendData(x, y)
|
||||
while len(sd.x) > samples:
|
||||
sd.token.remove(0) #Remove First Element
|
||||
ax,ay = sd.x,sd.y
|
||||
else:
|
||||
ax.append(x); ay.append(y)
|
||||
while len(ax) > samples:
|
||||
ax.pop(0); ay.pop(0)
|
||||
|
||||
if len(ax)>2:
|
||||
x1, x2 = min(ax), max(ax)
|
||||
if x1!=x2:
|
||||
#Display correlation
|
||||
corr= PearsonsCorrelation().correlation(to_array(ax,'d'), to_array(ay,'d'))
|
||||
correlation.set(corr)
|
||||
pars_lin = (a0,a1) = fit_polynomial(ay, ax, 1)
|
||||
linear_fit.set(pars_lin)
|
||||
y1,y2 = poly(x1, pars_lin), poly(x2, pars_lin)
|
||||
if plt:
|
||||
invoke((plot_line,(plt, x1, y1, x2, y2, 2, Color.BLUE, "Fit Linear")), False)
|
||||
finally:
|
||||
merger.close()
|
||||
_task = fork(merger_task)
|
||||
except:
|
||||
stop_camera_correlation()
|
||||
raise
|
||||
|
||||
def stop_camera_correlation():
|
||||
global _stop_exec, _task, _dispatcher_stream
|
||||
_stop_exec = True
|
||||
if _task:
|
||||
join(_task)
|
||||
cam_server.stop()
|
||||
if _dispatcher_stream:
|
||||
_dispatcher_stream.close()
|
||||
_stop_exec = False
|
||||
_task = None
|
||||
_dispatcher_stream = None
|
||||
|
||||
|
||||
#Testing
|
||||
start_camera_correlation("SINEG01-DICT215:B1_CHARGE", "SATES31-CAMS187-RIXS1_sp1 intensity", samples = 40, plt=plot(None)[0])
|
||||
try:
|
||||
time.sleep(10.0)
|
||||
finally:
|
||||
stop_camera_correlation()
|
||||
15
script/Tools/SetTdsBeamPhase.py
Normal file
15
script/Tools/SetTdsBeamPhase.py
Normal file
@@ -0,0 +1,15 @@
|
||||
#Parameters
|
||||
is_panel = get_exec_pars().source != CommandSource.ui # run from panel
|
||||
if is_panel:
|
||||
tds = args[0]
|
||||
phase = args[1]
|
||||
else:
|
||||
tds = "S30CB14"
|
||||
phase = 0.0
|
||||
|
||||
# set beam phase offset
|
||||
phase_rf = caget(tds + "-RSYS:GET-VSUM-PHASE")
|
||||
phase_corr = caget(tds + "-RSYS:GET-VSUM-PHASE-OFFSET-CORR")
|
||||
phase_offset = phase - phase_rf - phase_corr
|
||||
print(tds + "-RSYS:SET-VSUM-PHASE-OFFSET-BASE", phase_offset)
|
||||
caput(tds + "-RSYS:SET-VSUM-PHASE-OFFSET-BASE", phase_offset)
|
||||
15
script/Tools/TestBsCamera.py
Normal file
15
script/Tools/TestBsCamera.py
Normal file
@@ -0,0 +1,15 @@
|
||||
print "Connecting to camera: " + str(CAMERA)
|
||||
|
||||
CAMERA_URL = caget(CAMERA + ":BSREADCONFIG").replace("tcp://daq", "tcp://")
|
||||
print "Url: " + str(CAMERA_URL)
|
||||
|
||||
st1 = Stream("st1", CAMERA_URL, SocketType.PULL)
|
||||
st1.initialize()
|
||||
st1.start()
|
||||
st1.waitCacheChange(3000)
|
||||
|
||||
try:
|
||||
r=bscan (st1, records=10, timeout =10.0, save=False, enabled_plots=[st1,])
|
||||
v= st1.getValues()
|
||||
finally:
|
||||
st1.close()
|
||||
45
script/Tools/dispatcher.py
Normal file
45
script/Tools/dispatcher.py
Normal file
@@ -0,0 +1,45 @@
|
||||
import requests
|
||||
import json
|
||||
|
||||
dispatcher_url = "https://dispatcher-api.psi.ch/sf"
|
||||
|
||||
def get_dispatcher(path):
|
||||
response = requests.get(url=dispatcher_url+path)
|
||||
if response.status_code != 200:
|
||||
raise Exception(response.text)
|
||||
return json.loads(response.text)
|
||||
|
||||
def post_dispatcher(path, data):
|
||||
response = requests.post(url=dispatcher_url+path, json=data)
|
||||
if response.status_code != 200:
|
||||
raise Exception(response.text)
|
||||
return json.loads(response.text)
|
||||
|
||||
|
||||
def get_dispatcher_info(regex):
|
||||
return post_dispatcher("/channels/live",{"regex": regex})[0]
|
||||
|
||||
def get_dispatcher_channels(regex):
|
||||
return get_dispatcher_info(regex)["channels"]
|
||||
|
||||
def get_dispatcher_channel_info(channel_name):
|
||||
return get_dispatcher_info(channel_name)["channels"][0]
|
||||
|
||||
def get_dispatcher_channel_modulo(channel_name):
|
||||
return get_dispatcher_channel_info(channel_name)
|
||||
|
||||
def get_dispatcher_channel_modulo(channel_name):
|
||||
return get_dispatcher_channel_info(channel_name).get("modulo", 1)
|
||||
|
||||
def get_dispatcher_channel_offset(channel_name):
|
||||
return get_dispatcher_channel_info(channel_name).get("offset", 0)
|
||||
|
||||
def get_dispatcher_stream(channel_names):
|
||||
channels = []
|
||||
for channel_name in channel_names:
|
||||
#info = get_dispatcher_channel_info(channel_name)
|
||||
#channels.append({"name":channel_name,"backend":"sf-databuffer","modulo":info.get("modulo", 1), "offset":info.get("offset", 0)})
|
||||
channels.append({"name":channel_name,"backend":"sf-databuffer","modulo":None, "offset":None})
|
||||
return post_dispatcher("/stream",{"channels": channels})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user