This commit is contained in:
root
2018-05-15 10:29:52 +02:00
parent 1bcb32c8f2
commit dcdb3ee2ac
76 changed files with 3068 additions and 829 deletions
+99
View File
@@ -0,0 +1,99 @@
import mathutils
from mathutils import *
from plotutils import *
#f = "2018/03/12/20180312_231754_WireScan.h5|"
#f = "2018/03/12/20180312_233008_WireScan.h5|"
f = "2018/03/12/20180312_234230_WireScan.h5|"
#p = f + "/x_000"
p = f + "/y_000"
def gd(i):
global p
return load_data(p+str(i)+"/blm1")
def gt(i):
global p
return load_data(p+str(i)+"/Time")
def gp(i):
global p
return load_data(p+str(i)+"/w_pos")
def bg(i):
global f
return load_data(f+"/background/blm" + str(i))
def bga(blm):
global f
return get_attributes(f+"/background/blm" + str(blm))["Mean"]
def sig(i):
bg = bga(1)
ret = gd(i)
#ret = blm_remove_spikes(ret)
ret = [v-bg for v in ret]
return ret
epsilon = 1e-10
def make_monotonic(x):
for i in range(len(x)-1):
if x[i+1]<= x[i]:
x[i+1] = x[i] + epsilon
return x
x = [x1,x2,x3,x4,x5,x6]= [gp(1), gp(2), gp(3), gp(4), gp(5), gp(6)]
#plot(x, ["1", "2", "3", "4", "5", "6"], xdata = x)
s = [s1, s1, s3, s4, s5, s6] = [sig(1), sig(2), sig(3), sig(4), sig(5), sig(6)]
p=plot(s, ["1", "2", "3", "4", "5", "6"], xdata = x)
#print call_jep(MODULE, "profile_rms_stats", [to_npa(x), to_npa(y), 0, 3.5])
run("Diagnostics/sig_process_wrapper")
print "------------------ Gauss ---------------------------"
sum_mean=0.0
sum_sigma=0.0
sum_norm=0.0
mathutils.MAX_EVALUATIONS = mathutils.MAX_EVALUATIONS*10
for i in range(6):
[off, amp, com, sigma] = profile_gauss_stats(x[i], s[i], off=None, amp=None, com=None, sigma=None)
#[amp, com, sigma] = profile_gauss_stats(x[i], s[i], off=None, amp=None, com=None, sigma=None, with_offset=False)
"""
if i%2 == 0:
(amp, com, sigma) = fit_gaussian(s[i], make_monotonic(x[i]))
else :
(amp, com, sigma) = fit_gaussian(s[i][::-1], make_monotonic(x[i][::-1]))
"""
#print "Pass " , (i+1) ,": " , [off, amp, com, sigma]
sum_mean = sum_mean + com
sum_sigma = sum_sigma + sigma
sum_norm = sum_norm + amp
plot_function(p[i], Gaussian(amp, com, sigma), "Fit",x[i], show_points = False, show_lines = True, color = Color.BLUE)
ave_mean, ave_sigma = sum_mean/6, sum_sigma/6
print "Average: mean=" , ave_mean, ave_sigma
print "------------------ RMS ---------------------------"
sum_com=0.0
sum_sigma=0.0
for i in range(6):
#[rms_com, rms_sigma] = profile_rms_stats(x[i], s[i],noise_std=0, n_sigma=3.5)
[off, amp, com, sigma] = profile_gauss_stats(x[i], s[i], off=None, amp=None, com=None, sigma=None)
[rms_com, rms_sigma] = profile_rms_stats_with_estimate(x[i], s[i], com_estimate = com, window_size = sigma *3.5)
print "Pass " , (i+1) ,": " , [rms_com, rms_sigma]
sum_com = sum_com+ rms_com
sum_sigma = sum_sigma + rms_sigma
print "Average: mean=" , sum_com/6, " sigma=", sum_sigma/6
-172
View File
@@ -1,172 +0,0 @@
import ch.psi.pshell.epics.Positioner as Positioner
from mathutils import PolynomialFunction
dry_run = True
do_elog = True
is_panel = get_exec_pars().source != CommandSource.ui #must be check before run
def quadfit(xdata, ydata):
"""
Quadratic fit
"""
p = (a0, a1, a2) = fit_polynomial(ydata, xdata, 2)
f = PolynomialFunction(p)
if a1 != 0:
x_ext = -a1 / (2 * a0)
y_ext = f.value(x_ext)
else:
x_ext = None
y_ext = None
yhat = [f.value(val) for val in xdata]
ybar = sum(ydata)/len(ydata)
ssreg = sum([(val - ybar)**2 for val in yhat])
sstot = sum([(val - ybar)**2 for val in ydata])
R2 = ssreg / sstot
x1 = min(xdata)
x2 = max(xdata)
x_fit = frange(x1, x2, (x2-x1)/100, True)
y_fit = [f.value(val) for val in x_fit]
return (p, x_ext, y_ext, R2, x_fit, y_fit)
#Parameters
if is_panel:
start = args[0]
stop = args[1]
step = args[2]
nb = int(args[3])
lat = args[4]
disp = args[5]
p0 = args[6]
plt = args[7]
else:
start = 44.0
stop = 65.0
step = 1.0
nb = 3
lat = 0.3
disp = -0.387
p0 = 7.1
plt = plot(None, title="Output")[0]
A = p0 / disp / 1e6
B = p0
#Plot setup
plt.clear()
plt.removeMarker(None)
plt.setStyle(plt.Style.ErrorY)
plt.addSeries(LinePlotErrorSeries("Momentum", Color.red))
plt.addSeries(LinePlotErrorSeries("Momentum Spread", Color.yellow, 2))
plt.getAxis(plt.AxisId.X).setLabel("Gun Beam Phase (deg)")
plt.getAxis(plt.AxisId.Y).setLabel("Momentum (MeV/c)")
plt.getAxis(plt.AxisId.Y2).setLabel("Momentum Spread (MeV/c)")
plt.setLegendVisible(True)
#Creating Phase positioner
if dry_run:
phase = Positioner("Beam phase", "SINEG01-RSYS:SET-BEAM-PHASE-SIM", "SINEG01-RSYS:SET-BEAM-PHASE-SIM")
camera_name = "simulation"
else:
phase = Positioner("Beam phase", "SINEG01-RSYS:SET-BEAM-PHASE", "SINEG01-RSYS:GET-BEAM-PHASE")
camera_name = "SINBD01-DSCR010"
phase.config.minValue = -360.0
phase.config.maxValue = 360.0
phase.config.precision = 3
phase.config.resolution = 0.1
phase.config.rotation = False
phase.config.save()
phase.initialize()
phase0 = phase.read()
#Camera setup
cam_server.start(camera_name)
wait_cam_server_message()
x = cam_server.stream.getChild("x_fit_mean")
dx = cam_server.stream.getChild("x_fit_standard_deviation")
#Creating averagers
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 A, B, plt
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
p_mean, p_stdev = A * x_pos_mean + B, abs(A) * x_pos_stdev
dp_mean, dp_stdev = abs(A) * x_width_mean, abs(A) * x_width_stdev
plt.getSeries(0).appendData(record.positions[0], p_mean, p_stdev)
plt.getSeries(1).appendData(record.positions[0], dp_mean, dp_stdev)
#The scan loop
try:
phase.write(start)
time.sleep(2.0)
r = lscan(phase, [x_averager, dx_averager], start, stop, step , latency=lat, after_read = after_sample)
finally:
phase.write(phase0)
phase.close()
cam_server.stop() # stops cam_server but does not close it cam_server is a global object
ph = r.getPositions(0)
p = [A * val.mean + B for val in r.getReadable(0)]
dp = [abs(A) * val.mean for val in r.getReadable(1)]
#Fitting and plotting
try:
i_max = p.index(max(p))
i_min = dp.index(min(dp))
a,b = max(i_max-5, 0), min(i_max+6, len(p))
Xdat = ph[a:b]
Ydat = p[a:b]
(p_poly, ph_p_max, p_max, p_R2, ph_p_fit, p_fit) = quadfit(Xdat, Ydat)
a,b = max(i_min-5, 0), min(i_min+6, len(dp))
Xdat = ph[a:b]
Ydat = dp[a:b]
(dp_poly, ph_dp_min, dp_min, dp_R2, ph_dp_fit, dp_fit) = quadfit(Xdat, Ydat)
plt.addSeries(LinePlotErrorSeries("Momentum Fit", plt.getSeries(0).color))
plt.addSeries(LinePlotErrorSeries("Momentum Spread Fit", plt.getSeries(1).color, 2))
plt.getSeries(2).setData(ph_p_fit, p_fit)
plt.getSeries(3).setData(ph_dp_fit, dp_fit)
plt.getSeries(2).setPointsVisible(False)
plt.getSeries(3).setPointsVisible(False)
plt.addMarker(ph_p_max, plt.AxisId.X, "%3.2f" % ph_p_max, plt.getSeries(0).color)
plt.addMarker(ph_dp_min, plt.AxisId.X, "%3.2f" % ph_dp_min, plt.getSeries(1).color)
except:
raise Exception("Fit failure")
#Setting the return value
set_return([ph_dp_min])
#Saving metadata
save_dataset(get_exec_pars().group + "/p", p)
set_attribute(get_exec_pars().group + "/p", "p max", p_max)
set_attribute(get_exec_pars().group + "/p", "p max phase", ph_p_max)
set_attribute(get_exec_pars().group + "/p", "p fit R2", p_R2)
save_dataset(get_exec_pars().group + "/dp", dp)
set_attribute(get_exec_pars().group + "/dp", "dp min", dp_min)
set_attribute(get_exec_pars().group + "/dp", "dp min phase", ph_dp_min)
set_attribute(get_exec_pars().group + "/dp", "dp fit R2", dp_R2)
#Elog entry
if do_elog:
if get_option("Generated data file:\n" + get_exec_pars().path +"\n\n" + "Save to ELOG?", "YesNo") == "Yes":
Laser = str(caget("SLGTV-LMTO-M055:MOT-KNOWN-POS"))
log_msg = "Data file: " + get_exec_pars().path + "\n\n"
log_msg = log_msg + "Laser: " + Laser + "\n"
if Laser == "Alcor":
log_msg = log_msg + "Energy plate: %0.2f" % caget("SLGTH01-LMRM-M074:MOT.RBV") + " deg \n"
else:
log_msg = log_msg + "Energy plate: %0.2f" % caget("SLGJG-LMRM-M031:MOT.RBV") + " deg \n"
if caget("SLGTV-LMTO-M053:MOT-ACT-POS") == "IRIS":
log_msg = log_msg + "Collimator: IRIS %0.2f" % caget("SLGTV-LAPP:SIZE-GET") + " mm \n"
else:
log_msg = log_msg + "Collimator: " + str(caget("SLGTV-LMTO-M053:MOT-ACT-POS")) + "\n"
log_msg = log_msg + "Charge: %0.2f" % caget("SINEG01-DICT215:B1_CHARGE-OP") + " pC at %0.2f" % phase0 + " deg beam phase\n"
log_msg = log_msg + "p-max: %0.2f" % p_max + " MeV/c at %0.2f" % ph_p_max + " deg beam phase\n"
log_msg = log_msg + "dp-min: %0.2f" % dp_min + " MeV/c at %0.2f" % ph_dp_min + " deg beam phase\n"
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() + "/GunEnergyScanPlot.png")
plt.saveSnapshot(file_name , "png")
elog("Gun Energy Scan", log_msg, [file_name,])
-24
View File
@@ -1,24 +0,0 @@
dry_run = True
do_elog = True
if get_exec_pars().source == CommandSource.ui:
bph_ref_user = 19.0
plt = None
else:
bph_ref_user = args[0]
plt = args[1]
phaseOffset_old = caget("SINEG01-RSYS:SET-VSUM-PHASE-OFFSET-BASE")
phaseOffset_new = 90 - bph_ref_user + phaseOffset_old
if not dry_run:
caput("SINEG01-RSYS:SET-VSUM-PHASE-OFFSET-BASE", phaseOffset_new)
caput("SINEG01-RSYS:CMD-LOAD-CALIB-BEAM", 1)
if do_elog:
log_msg = "SINEG01-RSYS:SET-VSUM-PHASE-OFFSET-BASE: %0.2f" % phase_offset_new + " deg (was %0.2f" % phase_offset_old + " 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() + "/GunEnergyScanSet.png")
plt.saveSnapshot(file_name , "png")
attachments = [file_name]
elog("Set gun phase", log_msg, attachments)
show_message("Success setting phase reference")
-140
View File
@@ -1,140 +0,0 @@
import ch.psi.pshell.epics.Positioner as Positioner
import ch.psi.pshell.epics.Camtool as Camtool
dry_run = False
do_elog = True
is_panel = get_exec_pars().source != CommandSource.ui #must be check before run
run("CPython/wrapper")
#Parameters
if is_panel:
start = args[0]
stop = args[1]
step = args[2]
nb = int(args[3])
lat = args[4]
disp = args[5]
p0 = args[6]
plt = args[7]
else:
start = 44.0
stop = 65.0
step = 1.0
nb = 3
lat = 0.3
disp = -0.387
p0 = 7.1
plt = plot(None, title="Output")[0]
A = p0 / disp / 1e6
B = p0
#Plot setup
plt.clear()
plt.setStyle(plt.Style.ErrorY)
plt.addSeries(LinePlotErrorSeries("Momentum"))
plt.addSeries(LinePlotErrorSeries("Momentum Spread", None, 2))
plt.getAxis(plt.AxisId.X).setLabel("Gun Beam Phase (deg)")
plt.getAxis(plt.AxisId.Y).setLabel("Momentum (MeV/c)")
plt.getAxis(plt.AxisId.Y2).setLabel("Momentum Spread (MeV/c)")
plt.setLegendVisible(True)
#Creating Phase positioner
if dry_run:
phase = Positioner("Beam phase", "SINEG01-RSYS:SET-BEAM-PHASE-SIM", "SINEG01-RSYS:SET-BEAM-PHASE-SIM")
camera_name = "simulation"
else:
phase = Positioner("Beam phase", "SINEG01-RSYS:SET-BEAM-PHASE", "SINEG01-RSYS:GET-BEAM-PHASE")
camera_name = "SINBD01-DSCR010"
phase.config.minValue = -360.0
phase.config.maxValue = 360.0
phase.config.precision = 3
phase.config.resolution = 0.1
phase.config.rotation = False
phase.config.save()
phase.initialize()
phase0 = phase.read()
#Camera setup
cam_server.start(camera_name)
wait_cam_server_message()
x = cam_server.stream.getChild("x_fit_mean")
dx = cam_server.stream.getChild("x_fit_standard_deviation")
#Creating averagers
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 A, B, plt
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
p_mean, p_stdev = A * x_pos_mean + B, abs(A) * x_pos_stdev
dp_mean, dp_stdev = abs(A) * x_width_mean, abs(A) * x_width_stdev
plt.getSeries(0).appendData(record.positions[0], p_mean, p_stdev)
plt.getSeries(1).appendData(record.positions[0], dp_mean, dp_stdev)
#The scan loop
try:
phase.write(start)
time.sleep(1.0)
r = lscan(phase, [x_averager, dx_averager], start, stop, step , latency=lat, after_read = after_sample)
finally:
phase.write(phase0)
phase.close()
cam_server.stop() # stops cam_server but does not close it cam_server is a global object
ph = r.getPositions(0)
p = [A * val.mean + B for val in r.getReadable(0)]
dp = [abs(A) * val.mean for val in r.getReadable(1)]
#Fitting and plotting
try:
i_max = p.index(max(p))
i_min = dp.index(min(dp))
min_i, max_i = max(i_max-5, 0), min(i_max+6, len(p))
(ph_p_max, p_max, ph_p_fit, p_fit) = extremum(ph[min_i:max_i], p[min_i:max_i])
min_i, max_i = max(i_min-5, 0), min(i_min+6, len(dp))
(ph_dp_min, dp_min, ph_dp_fit, dp_fit) = extremum(ph[min_i:max_i], dp[min_i:max_i])
plt.addSeries(LinePlotErrorSeries("Momentum Fit", plt.getSeries(0).color))
plt.addSeries(LinePlotErrorSeries("Momentum Spread Fit", plt.getSeries(1).color, 2))
plt.getSeries(2).setData(ph_p_fit, p_fit)
plt.getSeries(3).setData(ph_dp_fit, dp_fit)
plt.getSeries(2).setPointsVisible(False)
plt.getSeries(3).setPointsVisible(False)
plt.addMarker(ph_p_max, plt.AxisId.X, "%3.2f" % ph_p_max, plt.getSeries(0).color)
plt.addMarker(ph_dp_min, plt.AxisId.X, "%3.2f" % ph_dp_min, plt.getSeries(1).color)
except:
raise Exception("Fit failure")
#Saving metadata
save_dataset(get_exec_pars().group + "/p", p)
set_attribute(get_exec_pars().group + "/p", "ph_p_max", ph_p_max)
set_attribute(get_exec_pars().group + "/p", "p_max", p_max)
save_dataset(get_exec_pars().group + "/dp", dp)
set_attribute(get_exec_pars().group + "/dp", "ph_dp_min", ph_dp_min)
set_attribute(get_exec_pars().group + "/dp", "dp_min", dp_min)
#Elog entry
if do_elog:
if get_option("Generated data file:\n" + get_exec_pars().path +"\n\n" + "Save to ELOG?", "YesNo") == "Yes":
Laser = str(caget("SLGTV-LMTO-M055:MOT-KNOWN-POS"))
log_msg = "Data file: " + get_exec_pars().path + "\n\n"
log_msg = log_msg + "Laser: " + Laser + "\n"
if Laser == "Alcor":
log_msg = log_msg + "Energy plate: %0.2f" % caget("SLGTH01-LMRM-M074:MOT.RBV") + " deg \n"
else:
log_msg = log_msg + "Energy plate: %0.2f" % caget("SLGJG-LMRM-M031:MOT.RBV") + " deg \n"
if caget("SLGTV-LMTO-M053:MOT-ACT-POS") == "IRIS":
log_msg = log_msg + "Collimator: IRIS %0.2f" % caget("SLGTV-LAPP:SIZE-GET") + " mm \n"
else:
log_msg = log_msg + "Collimator: " + str(caget("SLGTV-LMTO-M053:MOT-ACT-POS")) + "\n"
log_msg = log_msg + "Charge: %0.2f" % caget("SINEG01-DICT215:B1_CHARGE-OP") + " pC at %0.2f" % phase0 + " deg beam phase\n"
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() + "/GunEnergyScanPlot.png")
plt.saveSnapshot(file_name , "png")
elog("Gun Energy Scan", log_msg, [file_name,])
+21
View File
@@ -0,0 +1,21 @@
SAMPLES = 20
TOLERANCE = 0.01
TIMEOUT = 10.0
intensity = ChannelDouble("intensity", "SARFE10-PBPG050:PHOTON-ENERGY-PER-PULSE-US")
intensity.initialize()
gap = Channel(GAP + ":GAP_SP", alias = "gap")
readout = Channel(GAP + ":GAP")
av = create_averager(intensity, SAMPLES, interval = -1, name = None)
def before(position, scan):
caput(GAP + ":GO", 1)
start = time.time()
while abs(readout.read() - gap.read()) > TOLERANCE:
time.sleep(0.1)
if time.time() - start > TIMEOUT:
raise Exception ("Timeout waiting gap change")
ret = lscan (gap, av, 17.5, 19.5, 40, latency=10.0, before_read=before)
+1
View File
@@ -0,0 +1 @@
ascan([Test, 'ca://SWISSFEL-STYLE-GUIDE:AMPLITUDE-SIN'], ['ca://SWISSFEL-STYLE-GUIDE:SIGNAL1?monitored=true&samples=4&interval=-1', 'ca://SWISSFEL-STYLE-GUIDE:SIGNAL2?monitored=true'], [0.0, 10.0], [4.0, 20.0], [1, 1.0], latency=0.5, relative=False, passes=1, zigzag=True, name='Test2DScan2', layout='sf')
+1
View File
@@ -0,0 +1 @@
[ "Multidimensional", [ [ "Channel", " SWISSFEL-STYLE-GUIDE:AMPLITUDE-SIN", 12.0, 14.0, 1.0 ], [ "Channel", "SWISSFEL-STYLE-GUIDE:SET-PRESSURE", 0.09, 0.1, 0.001 ] ], [ [ "CamServer", "http://sf-daqsync-01:8889/SARBD02-DSCR050_sp1?channel=gr_intensity", 3, -1.0, "Enabled" ], [ "CamServer", "http://sf-daqsync-01:8889/SARBD02-DSCR050_sp1?channel=intensity", 1, 0, "Enabled" ], [ "CamServer", "http://sf-daqsync-01:8889/SARBD02-DSCR050_sp1?channel=y_profile", 1, -1.0, "Line" ] ], false, [ ], "", 10, 0.0, 0.2, false, false, true, true, "TestScanEditor", "", "SF", " ", 0, null, null, "Positioner", false ]
+1
View File
@@ -0,0 +1 @@
[ "Multidimensional", [ [ "Device", "Test", 0.0, 4.0, 1 ], [ "Channel", "SWISSFEL-STYLE-GUIDE:AMPLITUDE-SIN", 10.0, 20.0, 1.0 ] ], [ [ "Channel", "SWISSFEL-STYLE-GUIDE:SIGNAL1?monitored=true", 4, -1.0, "Enabled" ], [ "Channel", "SWISSFEL-STYLE-GUIDE:SIGNAL2?monitored=true", 1, 0, "Enabled" ] ], false, [ ], "", 1, 1.0, 0.5, false, true, true, true, "", "", "SF", " ", 0, null, null, "Sensor 2", false ]
+1
View File
@@ -0,0 +1 @@
[ "Change event series", [ ], [ [ "Channel", "SINEG01-RSYS:GET-BEAM-PHASE?monitored=true", 5, -1.0, "Enabled" ] ], false, [ ], "", 10, 0.0, 0.0, false, false, true, true, "", "", "Default", "h5", 0, null, null, "Positioner", false ]
+10
View File
@@ -0,0 +1,10 @@
import ch.psi.pshell.epics.ChannelDoubleArray as ChannelDoubleArray
d = ChannelDoubleArray("test", "SINLH02-DBLM230:LOSS_SIGNAL_RAW", -1, False)
add_device(d,True)
print len(test.read())
+1
View File
@@ -0,0 +1 @@
[ "Change event series", [ ], [ [ "Channel", "SINLH02-DBLM230:LOSS_SIGNAL_RAW?monitored=True", 2, -1.0, "Enabled" ] ], true, [ ], "", 10, 0.0, 0.5, false, true, true, true, "", "", "SF", "", 0, null, null, "Time", false ]
+1
View File
@@ -0,0 +1 @@
[ "Change event series", [ ], [ [ "Channel", "SWISSFEL-STYLE-GUIDE:SIGNAL2?monitored=true", 1, -1.0, "Enabled" ], [ "Channel", "SWISSFEL-STYLE-GUIDE:SIGNAL1", 1, 0, "Enabled" ] ], false, [ ], "", 10, 0.0, 0.5, false, true, false, true, "", "", "SF", "", 0, null, null, "Positioner", false ]
+19
View File
@@ -0,0 +1,19 @@
def create_device(url, parent=None):
"""Create a device form a definition string(see URLDevice)
Args:
url(str or list of string): the device definition string (or list of strings)
parent(bool, optional): parent device
Returns:
The created device (or list of devices)
"""
return ch.psi.pshell.core.UrlDevice.create(url, parent)
devices = create_device(["ca://SINDI02-DBLM025:LOSS_SIGNAL_RAW?monitored=true&op=sum" ]) #SINDI02-DBLM025:LOSS_SIGNAL_RAW
try:
mscan([], devices , 10, -1, persist=False) #ar is ony updated on read
#tscan( devices , 5, 0.1)
finally:
devices[0].parent.close()
+58
View File
@@ -0,0 +1,58 @@
#ws = "SARUN20-DWSC010"
#ws = "SINDI01-DWSC090"
#ws = "SARMA02-DWSC060"
#ws = "S10DI01-DWSC010"
ws = "SARMA02-DWSC060"
print caget(ws + ":VALID")
print "COM:" , caget(ws + ":B1_X_CENTER_OF_MASS")
print "RMS:" , caget(ws + ":B1_X_RMS")
print "AMP:" , caget(ws + ":B1_X_FIT_AMPLITUDE")
print "MEAN:" , caget(ws + ":B1_X_FIT_MEAN")
print "OFF:" , caget(ws + ":B1_X_FIT_OFFSET")
print "SIGMA:" , caget(ws + ":B1_X_FIT_STANDARD_DEVIATION")
plot([caget(ws + ":B1_X_AMPLITUDE"), caget(ws + ":B1_X_FIT_GAUSS_FUNCTION")], ["data", "fit"], xdata = caget(ws + ":B1_X_POSITION"))
"""
print caget(ws + ":B1_Y_CENTER_OF_MASS")
print caget(ws + ":B1_Y_RMS")
print caget(ws + ":B1_Y_FIT_AMPLITUDE")
print caget(ws + ":B1_Y_FIT_MEAN")
print caget(ws + ":B1_Y_FIT_OFFSET")
print caget(ws + ":B1_Y_FIT_STANDARD_DEVIATION")
print len(caget(ws + ":B1_Y_POSITION"))
print len(caget(ws + ":B1_Y_AMPLITUDE"))
print caget(ws + ":B2_X_CENTER_OF_MASS")
print caget(ws + ":B2_X_RMS")
print caget(ws + ":B2_X_FIT_AMPLITUDE")
print caget(ws + ":B2_X_FIT_MEAN")
print caget(ws + ":B2_X_FIT_OFFSET")
print caget(ws + ":B2_X_FIT_STANDARD_DEVIATION")
print len(caget(ws + ":B2_X_POSITION"))
print len(caget(ws + ":B2_X_AMPLITUDE"))
print caget(ws + ":B2_Y_CENTER_OF_MASS")
print caget(ws + ":B2_Y_RMS")
print caget(ws + ":B2_Y_FIT_AMPLITUDE")
print caget(ws + ":B2_Y_FIT_MEAN")
print caget(ws + ":B2_Y_FIT_OFFSET")
print caget(ws + ":B2_Y_FIT_STANDARD_DEVIATION")
print len(caget(ws + ":B2_Y_POSITION"))
print len(caget(ws + ":B2_Y_AMPLITUDE"))
"""
#print len(caget(ws + ":B1_X_FIT_GAUSS_FUNCTION"))
#print len(caget(ws + ":B1_Y_FIT_GAUSS_FUNCTION"))
#print len(caget(ws + ":B2_X_FIT_GAUSS_FUNCTION"))
#print len(caget(ws + ":B2_Y_FIT_GAUSS_FUNCTION"))
+20
View File
@@ -0,0 +1,20 @@
run("Devices/WireScanner")
#ws = "SARUN20-DWSC010"
ws = "S10DI01-DWSC010"
dev = WireScanInfo("wscn", ws)
print dev.is_valid()
dev.set_out_com(1,'x',1)
dev.set_out_rms(1,'x',2)
dev.set_out_amp(1,'x',3)
dev.set_out_mean(1,'x',4)
dev.set_out_off(1,'x',5)
dev.set_out_sigma(1,'x',6)
dev.set_out_pos(1,'x',[1,2,3])
dev.set_out_samples(1,'x',[4,5,6])
dev.set_out_gauss(1,'x',[7,8,9])
-149
View File
@@ -1,149 +0,0 @@
import ch.psi.pshell.epics.Positioner as Positioner
import ch.psi.pshell.epics.ChannelDouble as ChannelDouble
dry_run = True
do_elog = False
is_panel = get_exec_pars().source != CommandSource.ui
if is_panel:
station = args[0]
bpm_ch = args[1]
else:
station = "STEST01"
bpm_ch = "SINBC02-DBPM140"
start = caget(station + "-RSYS:SET-SCAN-START")
stop = caget(station + "-RSYS:SET-SCAN-STOP")
step = caget(station + "-RSYS:SET-SCAN-STEP")
lat = caget(station + "-RSYS:SET-SCAN-WAIT-TIME")
nb = caget(station + "-RSYS:SET-NUM-AVERAGE")
disp = caget(bpm_ch + ":DISPERSION-OP")
def mbnd(bpm_ch):
return {
'SINLH02-DBPM210': 'SINLH02-MBND100',
'SINLH02-DBPM240': 'SINLH02-MBND100',
'SINBC02-DBPM140': 'SINBC02-MBND100',
'SINBC02-DBPM320': 'SINBC02-MBND100',
'S10DI01-DBPM020': 'S10DI01-MBND100',
'S10BC02-DBPM140': 'S10BC02-MBND100',
'S10BC02-DBPM320': 'S10BC02-MBND100',
'SARCL02-DBPM110': 'SARCL02-MBND100',
'SARCL02-DBPM220': 'SARCL02-MBND100',
'SARCL02-DBPM260': 'SARCL02-MBND100',
'SARCL02-DBPM330': 'SARCL02-MBND100',
'SARCL02-DBPM470': 'SARCL02-MBND100'
}[bpm_ch]
p0 = caget(mbnd(bpm_ch) + ":P-READ")
energy0 = p0 - 0.511
A = energy0 / (disp * 1000)
B = energy0
phase = Positioner("Phase", station + "-RSYS:SET-VSUM-PHASE", station + "-RSYS:GET-VSUM-PHASE")
phase.config.minValue =-90.0
phase.config.maxValue = 360.0
phase.config.precision = 4
phase.config.rotation = True
phase.config.resolution = 0.1
phase.initialize()
V = ChannelDouble("Amplitude Readback", station + "-RSYS:GET-VSUM-AMPLT")
P = ChannelDouble("Power Readback", station + "-RSYS:GET-KLY-POWER")
V.initialize()
P.initialize()
if dry_run:
x = ChannelDouble("BPM-X", bpm_ch + ":X1-SIMU")
else:
x = ChannelDouble("BPM-X", bpm_ch + ":X1")
x.initialize()
phase0 = phase.read() % 360
caput(station + "-RSYS:GET-FIT-PHASE-ARRAY", to_array([0.0],'d'))
caput(station + "-RSYS:GET-FIT-ENERGY-ARRAY", to_array([0.0],'d'))
caput(station + "-RSYS:GET-ONCREST-VSUM-PHASE", float('nan'))
caput(station + "-RSYS:GET-ONCREST-VSUM-AMPLT", float('nan'))
caput(station + "-RSYS:GET-ONCREST-E-GAIN", float('nan'))
caput(station + "-RSYS:GET-ONCREST-KLY-POWER", float('nan'))
#update the plot dynamically
arr_phase,arr_energy = [],[]
def after(rec):
global A, B
arr_phase.append(rec.positions[0])
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'))
#scan and plot
try:
phase.write(start)
time.sleep(1.0)
x_averager = create_averager(x, nb, lat)
r = lscan(phase, x_averager, start, stop, step, latency=lat, after_read = after)
rf_phase = r.getPositions(0)
if start < 0:
rf_phase = [((ph + 90) % 360) -90 for ph in rf_phase ]
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:
run("CPython/wrapper")
(fit_amplitude, fit_phase_deg, fit_offset, ph_crest, fit_x, fit_y) = hfitoff(energy , rf_phase)
except:
raise Exception("Fit failure")
plt = plot(None,name="phase scan")[0]
if plt is not None:
plt.getSeries(0).setData(to_array(rf_phase,'d'), to_array(energy,'d'))
plt.getSeries(0).setPointSize(6)
plt.getSeries(0).setLinesVisible(False)
plt.addSeries(LinePlotSeries("fit"))
plt.getSeries(1).setData(fit_x, fit_y)
plt.getSeries(1).setPointsVisible(False)
plt.setLegendVisible(True)
ph_crest = ph_crest % 360
phase.write(ph_crest)
time.sleep(lat)
Ampl = V.read()
Power = P.read()
caput(station + "-RSYS:GET-ONCREST-VSUM-PHASE", ph_crest)
caput(station + "-RSYS:GET-ONCREST-E-GAIN", fit_amplitude)
caput(station + "-RSYS:GET-ONCREST-VSUM-AMPLT", Ampl)
caput(station + "-RSYS:GET-ONCREST-KLY-POWER", Power)
caput(station + "-RSYS:GET-FIT-PHASE-ARRAY", fit_x)
caput(station + "-RSYS:GET-FIT-ENERGY-ARRAY", fit_y)
finally:
phase.write(phase0)
phase.close()
V.close()
P.close()
x.close()
phase_corr = caget(station + "-RSYS:GET-VSUM-PHASE-OFFSET-CORR")
phase_offset = 90.0 - ph_crest - phase_corr
amplitude_scale = fit_amplitude / Ampl if Ampl != 0 else 0.0
power_scale = Power / fit_amplitude**2 if fit_amplitude != 0 else 0.0
caput(station + "-RSYS:SET-VSUM-PHASE-OFFSET-BASE-CALC", phase_offset)
caput(station + "-RSYS:SET-VSUM-AMPLT-SCALE-CALC", amplitude_scale)
caput(station + "-RSYS:SET-VOLT-POWER-SCALE-CALC", power_scale)
#Saving metadata
save_dataset (get_exec_pars().group + "/Station" , station )
save_dataset (get_exec_pars().group + "/Energy" , energy )
save_dataset (get_exec_pars().group + "/Energy gain" , fit_amplitude )
save_dataset (get_exec_pars().group + "/On-crest VS-phase" , ph_crest )
save_dataset (get_exec_pars().group + "/VS-phase offset" , phase_offset )
save_dataset (get_exec_pars().group + "/Amplitude scale" , amplitude_scale )
save_dataset (get_exec_pars().group + "/Power scale" , power_scale )
set_attribute(get_exec_pars().group + "/Energy" , "Unit", "MeV" )
set_attribute(get_exec_pars().group + "/Energy gain" , "Unit", "MeV" )
set_attribute(get_exec_pars().group + "/On-crest VS-phase" , "Unit", "deg" )
set_attribute(get_exec_pars().group + "/VS-phase offset" , "Unit", "deg" )
set_attribute(get_exec_pars().group + "/Amplitude scale" , "Unit", "MV" )
set_attribute(get_exec_pars().group + "/Power scale" , "Unit", "MW/MV^2" )
set_attribute(get_exec_pars().group + "/Phase" , "Unit", "deg" )
set_attribute(get_exec_pars().group + "/BPM-X averager" , "Unit", "mm" )
#Elog entry
if do_elog:
title = "Phase scan " + station
log_msg = "Data file: " + get_exec_pars().path + "\n"
log_msg = log_msg + "On-crest VS phase: %0.2f" % ph_crest + " deg \n"
log_msg = log_msg + "Energy gain: %0.3f" % fit_amplitude + " MeV \n"
log_msg = log_msg + "VS-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.6f" % power_scale + " MW/MV^2"
attachments = get_plot_snapshots(size=(600,400))
elog(title, log_msg, attachments)
-40
View File
@@ -1,40 +0,0 @@
do_elog = False
if get_exec_pars().source == CommandSource.ui:
station = "STEST01"
else:
station = args[0]
phase_set = caget(station + "-RSYS:PHASE-SET")
ampli_set = caget(station + "-RSYS:AMPLT-SET")
power_set = caget(station + "-RSYS:POWER-SET")
n = 0
if (phase_set == 'True'):
phase_offset = caget(station + "-RSYS:SET-VSUM-PHASE-OFFSET-BASE-CALC")
phase_offset_old = caget(station + "-RSYS:SET-VSUM-PHASE-OFFSET-BASE")
caput(station + "-RSYS:SET-VSUM-PHASE-OFFSET-BASE", phase_offset)
print phase_set
n = n + 1
if (ampli_set == 'True'):
amplitude_scale = caget(station + "-RSYS:SET-VSUM-AMPLT-SCALE-CALC")
amplitude_scale_old = caget(station + "-RSYS:SET-VSUM-AMPLT-SCALE")
caput(station + "-RSYS:SET-VSUM-AMPLT-SCALE", amplitude_scale)
print ampli_set
n = n + 1
if (power_set == 'True'):
power_scale = caget(station + "-RSYS:SET-VOLT-POWER-SCALE-CALC")
power_scale_old = caget(station + "-RSYS:SET-VOLT-POWER-SCALE")
caput(station + "-RSYS:SET-VOLT-POWER-SCALE", power_scale)
print power_set
n = n + 1
caput(station + "-RSYS:CMD-LOAD-CALIB-BEAM", 1)
if do_elog == True and n > 0:
title = "Set RF calibration:" + station
log_msg = ""
if (phase_set == 'True'): log_msg = log_msg + station + "-RSYS:SET-VSUM-PHASE-OFFSET-BASE: %0.2f" % phase_offset + " deg (was %0.2f" % phase_offset_old + " deg)\n"
if (ampli_set == 'True'): log_msg = log_msg + station + "-RSYS:SET-VSUM-AMPLT-SCALE: %0.3f" % amplitude_scale + " MV (was %0.3f" % amplitude_scale_old + " MV)\n"
if (power_set == 'True'): log_msg = log_msg + station + "-RSYS:SET-VOLT-POWER-SCALE: %0.5f" % power_scale + " MW/MV^2 (was %0.5f" % power_scale_old + " MW/MV^2)"
attachments = []
elog(title, log_msg, attachments)
+34
View File
@@ -0,0 +1,34 @@
import ch.psi.pshell.epics.ChannelDouble as ChannelDouble
A1 = ChannelDouble("Actuator1", "SINEG01-RSYS:SET-BEAM-PHASE-SIM")
S1 = ChannelDouble("Sensor1", "SARFE10-PBPG050:PHOTON-ENERGY-PER-PULSE-US")
S2 = ChannelDouble("Sensor2", "SARFE10-PBPG050:PHOTON-ENERGY-PER-PULSE-DS")
A1.initialize()
S1.initialize()
S2.initialize()
A1_init = A1.read()
A1i = -10.0
A1f = 150.0
nstep = 10
lat = 0.150
nav = 10
plt = plot(None, title="Output")[0]
plt.clear()
plt.setStyle(plt.Style.ErrorY)
plt.addSeries(LinePlotErrorSeries("Sensor1", Color.red))
def after_sample(record, scan):
plt.getSeries(0).appendData(record.positions[0], record.values[0].mean, record.values[0].stdev)
try:
S1_averager = create_averager(S1, nav, lat)
S2_averager = create_averager(S2, nav, lat)
S2_averager.monitored=True
r = lscan(A1, (S1_averager, S2_averager), A1i, A1f, nstep, latency=lat, after_read = after_sample)
Act1 = r.getPositions(0)
S1mean = [val.mean for val in r.getReadable(0)]
S1rms = [val.stdev for val in r.getReadable(0)]
S2mean = [val.mean for val in r.getReadable(1)]
S2rmsn = [val.stdev for val in r.getReadable(1)]
finally:
A1.write(A1_init)
A1.close()
S1.close()
S2.close()
+28
View File
@@ -0,0 +1,28 @@
import ch.psi.pshell.epics.ChannelDouble as ChannelDouble
A1 = ChannelDouble("Actuator1", "SARUN07-UIND030:I-SET")
S1 = ChannelDouble("Sensor1", "SARFE10-PBPG050:PHOTON-ENERGY-PER-PULSE-US")
A1.initialize()
S1.initialize()
A1_init = A1.read()
A1i = -1.0
A1f = 1.2
nstep = 22
lat = 0.11
nav = 50
plt = plot(None, title="Output")[0]
plt.clear()
plt.setStyle(plt.Style.ErrorY)
plt.addSeries(LinePlotErrorSeries("Sensor1", Color.red))
def after_sample(record, scan):
plt.getSeries(0).appendData(record.positions[0], record.values[0].mean, record.values[0].stdev)
try:
S1_averager = create_averager(S1, nav, lat)
time.sleep(1.0)
r = lscan(A1, S1_averager, A1i, A1f, nstep, latency=2.0, after_read = after_sample)
Act1 = r.getPositions(0)
S1mean = [val.mean for val in r.getReadable(0)]
S1rms = [val.stdev for val in r.getReadable(0)]
finally:
A1.write(A1_init)
A1.close()
S1.close()
+2 -2
View File
@@ -1,8 +1,8 @@
import ch.psi.pshell.epics.ChannelDouble as ChannelDouble
A1 = ChannelDouble("Actuator1", "SINEG01-RSYS:SET-BEAM-PHASE-SIM")
A2 = ChannelDouble("Actuator2", "SINEG01-RSYS:SET-BEAM-PHASE-SIM")
S1 = ChannelDouble("Sensor1", "SINEG01-DICT215:B1_CHARGE-SIM")
S2 = ChannelDouble("Sensor2", "SINEG01-RSYS:SET-VSUM-PHASE-SIM")
S1 = ChannelDouble("Sensor1", "SARFE10-PBPG050:PHOTON-ENERGY-PER-PULSE-US")
S2 = ChannelDouble("Sensor2", "SARFE10-PBPG050:PHOTON-ENERGY-PER-PULSE-DS")
A1.initialize()
A2.initialize()
S1.initialize()