Update correlation plot and screen panel

This commit is contained in:
root
2018-07-25 17:14:25 +02:00
parent 82306b88b4
commit b9115c90b8
29 changed files with 1734 additions and 118 deletions
+45
View File
@@ -0,0 +1,45 @@
import ch.psi.pshell.epics.ChannelDouble as ChannelDouble
A1 = ChannelDouble("x", "SARUN13-DBPM070:X-REF-FB")
A2 = ChannelDouble("y", "SARUN13-DBPM070:Y-REF-FB")
camera_name = "SARBD01-DSCR110"
cam_server.start(camera_name+"_sp1", True) #True for shared pipeline
wait_cam_server_message()
S1 = cam_server.stream.getChild("intensity")
A1.initialize()
A2.initialize()
S1.initialize()
A1_init = A1.read()
A2_init = A2.read()
A1i = A1_init-0.1
A1f = A1_init+0.1
A2i = A2_init-0.1
A2f = A2_init+0.1
nstep = 11
lat = 5.0
nav = 10
def data_ok():
return (mps_beam_ok.read() == 1)
#def before_sample(record, scan):
# while not data_ok():
# time.sleep(1.0)
def after_sample(record, scan):
if not data_ok():
time.sleep(1.0)
record.invalidate()
print "Invalidating record: " + str(record)
try:
S1_averager = create_averager(S1, nav, 0.1)
r = ascan((A1,A2), (S1_averager), (A1i,A2i), (A1f,A2f), (nstep,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)]
finally:
A1.write(A1_init)
A1.close()
S1.close()
#S2.close()
+30 -1
View File
@@ -33,7 +33,9 @@ print dy, dytype
corr = None
pars_lin = None
pars_quad = None
pos_peak = None
neg_peak = None
stop_exec = None
bs = TYPE_STREAM in [dxtype, dytype]
@@ -134,7 +136,10 @@ try:
if get_exec_pars().source == CommandSource.ui:
if globals().has_key("marker"):
p.removeMarker(marker)
if globals().has_key("peak_marker"):
p.removeMarker(peak_marker)
marker=None
peak_marker=None
while(True):
@@ -190,6 +195,30 @@ try:
fitted_quad_function = PolynomialFunction(pars_quad)
ax = frange(x1, x2, res, True)
plot_function(p, fitted_quad_function, "Fit Quadratic", ax, color=Color.GREEN)
peak = None
peaks = calculate_peaks(fitted_quad_function, x1, x2, positive=True)
if len(peaks)>0:
peak = peaks[0]
pos_peak = str(round(peak,4))
peak_str = "Positive peak: " + pos_peak
else:
peaks = calculate_peaks(fitted_quad_function, x1, x2, positive=False)
if len(peaks)>0:
peak = peaks[0]
neg_peak = str(round(peak,4))
peak_str = "Negative peak: " + neg_peak
else:
pos_peak = neg_peak = None
if get_exec_pars().source == CommandSource.ui:
if peak_marker is not None:
p.removeMarker(peak_marker)
if peak is not None:
peak_marker = p.addMarker(peak, p.AxisId.X, peak_str, Color(0,128,0))
if stop_exec == True:
stop_exec = False
break
if bs != True:
time.sleep(interval)
finally:
+41 -73
View File
@@ -11,21 +11,23 @@ run("Diagnostics/sig_process_wrapper")
# Arguments and constants
###################################################################################################
ws_prefix = args[0] if is_panel else "SINDI01-DWSC090" #"S10DI01-DWSC010" #"S10CB07-DWSC440" #"SINDI01-DWSC090" \\
plt = args[1] if is_panel else plot(None, title = "Wire Scan Calibration")[0]
ws_wire = args[2] if is_panel else WireScanner.WireX1
cal_range = args[3] if is_panel else True
cal_gain = args[4] if is_panel else True
ws_prefix = args[0] if is_panel else "SINDI01-DWSC090" #"S10DI01-DWSC010" #"S10CB07-DWSC440" #"SINDI01-DWSC090" \\
plt = args[1] if is_panel else plot(None, title = "Wire Scan Calibration")[0]
ws_wire = args[2] if is_panel else WireScanner.WireX1
range_start = args[3] if is_panel else -2000
range_end = args[4] if is_panel else 2000
n_shot = args[5] if is_panel else 200
saturation = args[6] if is_panel else 19950 / 10 #S10DI01-DBLM113:AL1-WS-PMT-GAIN
scan_range_factor = args[7] if is_panel else 6.0
initial_gain = args[8] if is_panel else 0.6
ws_blm = get_wire_scanners_blms(ws_prefix )[0]
#S10DI01-DBLM113:AL1-WS-PMT-GAIN
SATURATION = 19950 / 10
MIN_GAIN, MAX_GAIN = 0.5, 1.1
OPT_STEP = 0.02
SCAN_RANGE_FACTOR = 6.0
DEFAULT_RANGE = [-2000.0, 2000.0]
print "WireScanCalibration parameters: ", ws_prefix, ws_wire, range_start, range_end, n_shot, saturation, scan_range_factor, initial_gain
###################################################################################################
@@ -56,18 +58,15 @@ def set_wire_scan_range(wire, start, end):
# Find COM
###################################################################################################
print "--------------- Find COM --------------- "
set_status("Performing wire scan to find initial COM...")
#2) Set the number of RF shots (N_shot) to be acquired during a single cycle WSC measurement (e.g.,N_shot=50)
n_shot = 200
set_gain(initial_gain)
print "Setting gain=", initial_gain
#3) Set a test scanning range (e.g.,Xmin=-1000,Xmax=+1000um)
x_min, x_max = DEFAULT_RANGE[0], DEFAULT_RANGE[1]
#4) For a given machine repetition-rate (RR), the scan speed is automatically set to WSC_speed=(Xmax- Xmin)*RR/N_shot
#Calculate speed
x_min, x_max = range_start, range_end
rr = get_repetition_rate()
ws_speed = (x_max- x_min)*rr/n_shot
#5) Proceed with a test scan (1 cycle) according to the above defined motor settings
args = [ ws_prefix , ws_wire, [x_min, x_max, x_min, x_max], 1, ws_speed, [], [ws_blm], 10, plt, False,1]
ret = run("Diagnostics/WireScan", args)
[rms_com, rms_sigma, com, sigma, pos_path, path] = ret
@@ -81,27 +80,18 @@ ret = run("Diagnostics/WireScan", args)
print "--------------- Optimize gain --------------- "
#1) Select a BLM to be used in the WSC measurement and enable the WS_START so that it can be extracted out of the MPS and PMT-Gain and attenuation can be adjusted
start_blm_ws(ws_blm, 600.0)
#6) Apply a gauss fit to the obtained WSC profile in order to determine X_CoM and standard deviation (sigma_Gauss)
#7) Move the wire to the X_CoM position and optimize the PMT-Gain so that the time-integral of the BLM voltage reaches a value equal to 90% of the Σsat level
#offset = caget(ws_prefix + ":W1X_U0_SP")
#motor_pos=offset - com * math.sqrt(2)
ws_info = WireScanInfo("ws_info", ws_prefix )
#self.wire_velocity = Channel(self.prefix + ":SCAN_VELO_SP")
motor_pos= ws_info.get_motor_pos(com, ws_wire)
caput(ws_prefix+":MOTOR_1.VAL", motor_pos) #DVAL?
#LOPR:0.5 HOPR:1.1
set_status("Setting motor position to COM...")
caput(ws_prefix+":MOTOR_1.VAL", motor_pos) #DVAL?
print "Starting stream..."
set_status("Creating stream for gain search..." )
st = Stream("blm_stream", dispatcher)
ch = ws_blm + ":B1_LOSS"
st.addScalar(ch, ch, int(100.0 / get_repetition_rate()), 0)
@@ -124,11 +114,12 @@ def get_loss():
start_gain = get_gain()
pos = start_val = get_loss()
loss = get_loss()
target = SATURATION * 0.8
target = saturation * 0.8
print "Start Gain = ", start_gain
print "Start Loss = ", start_val
print "Target = ", target
set_status("Searching gain to match peak losses of " + str(target) + "...")
def change_blm_ws_gain(gain):
set_gain(gain)
@@ -151,35 +142,20 @@ try:
finally:
stop_blm_ws(ws_blm)
"""
if start_val>target:
for pos in frange(start_gain, MIN_GAIN, -OPT_STEP, True):
change_blm_ws_gain(pos)
loss = get_loss()
print "Pos = ", pos, " Loss = ", loss
if loss<=target:
break
stop_blm_ws(ws_blm)
elif start_val<target:
for pos in frange(start_gain, MAX_GAIN, OPT_STEP, True):
change_blm_ws_gain(pos)
loss = get_loss()
print "Pos = ", pos, " Loss = ", loss
if loss>=target:
break
stop_blm_ws(ws_blm)
"""
print "Final Gain = ", pos
print "Final Loss = ", loss
print get_gain()
print get_loss()
#set_gain(0.6)
#set_gain(0.5)
print "Final Gain: ", pos
print "Final Loss: ", loss
result = "Loss value for final gain: " + str(loss) + " - Target value: " + str(target) + "\n"
if loss<target:
result = result + "Cannot reach target value. Setting gain to " + str(pos) + "\n"
else:
result = result + "Optimized gain: " + str(pos) + "\n"
st.close()
write_ws_gain(pos)
time.sleep(1.0)
###################################################################################################
@@ -189,27 +165,19 @@ time.sleep(1.0)
set_exec_pars(reset=True, defaults=True)
print "--------------- Optimize scan range --------------- "
set_status("Performing scan with optimal gain to define optimal range..." )
#caget(ws_blm+":SAT_RAW_SUM")
args = [ ws_prefix , ws_wire, [x_min, x_max, x_min, x_max], 1, ws_speed, [], [ws_blm], 10, plt, False,1]
ret = run("Diagnostics/WireScan", args)
[rms_com, rms_sigma, com, sigma, pos_path, path] = ret
[rms_com, rms_sigma, com, sigma, pos_path, path] = run("Diagnostics/WireScan", args)
x_range_min, x_range_max = com - SCAN_RANGE_FACTOR * sigma, com + SCAN_RANGE_FACTOR * sigma
print "Optimized range = ", x_range_min , " to " , x_range_max
x_range_min, x_range_max = com - scan_range_factor * sigma, com + scan_range_factor * sigma
print "Optimized range: " , x_range_min , " to " , x_range_max
set_wire_scan_range(ws_wire, x_range_min, x_range_max)
result = result + "Optimized range: " + str(x_range_min) + " to " + str(x_range_max)
#Att: caget(ws_blm + ":WS_PMT_ATT_VOLTS")
#8) Optimization of the scan interval: compare (Xmin, Xmax) with (X_CoM-N*sigma_Gauss , X_CoM+N*sigma_Gauss) where N is an integer value: N=5,6.
#9) Increase or decrease Xmin and/or Xmax by 10% and repeat the scan until the conditions [abs(Xmin)-abs(X_CoM- N*sigma_Gauss)]/abs(X_CoM-N*sigma_Gauss)<=0.1 and [abs(Xmax) - abs(X_CoM+N*sigma_Gauss)]/abs(X_CoM+N*sigma_Gauss) <=0.1 is reached
#10)Once condition 9) is reached, the flag: VALID_SCAN should be enabled and a WSC measurement can be performed according to the number of Cycles set in the control-panel and the optimized values of the scan interval and scan speed.
st.close()
set_return(result)
+1
View File
@@ -66,6 +66,7 @@ else:
wait_cam_server_message()
x = cam_server.stream.getChild("x_center_of_mass")
dx = cam_server.stream.getChild("x_rms")
cam_server.setThreshold(750)
#Creating averagers
x_averager = create_averager(x, nb, -1) # -1 event based, waits for the next value
+10 -10
View File
@@ -1,15 +1,15 @@
import ch.psi.pshell.epics.ChannelDouble as ChannelDouble
A1 = ChannelDouble("Offset", "SARUN11-DBPM070:Y-REF-FB")
S1 = ChannelDouble("Intensity", "SARFE10-PBPG050:HAMP-INTENSITY")
S2 = ChannelDouble("Intensity", "SARFE10-PBPG050:HAMP-INTENSITY")
A1 = ChannelDouble("K", "SARUN12-UIND030:K_SET")
S1 = ChannelDouble("hamp", "SARFE10-PBPG050:HAMP-INTENSITY")
S2 = ChannelDouble("Intensity", "SARFE10-PBPG050:PHOTON-ENERGY-PER-PULSE-DS")
A1.initialize()
S1.initialize()
S2.initialize()
A1_init = A1.read()
A1i = A1_init - 0.100
A1f = A1_init + 0.100
nstep = 21
lat = 0.2
A1i = A1_init - 0.020
A1f = A1_init + 0.020
nstep = 11
lat = 10.0
nav = 10
plt = plot(None, title="Output")[0]
plt.clear()
@@ -18,10 +18,10 @@ 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)
S1_averager = create_averager(S1, nav, 0.2)
S2_averager = create_averager(S2, nav, 0.2)
S2_averager.monitored=True
time.sleep(1.0)
time.sleep(3.0)
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)]
+48
View File
@@ -0,0 +1,48 @@
import ch.psi.pshell.epics.ChannelDouble as ChannelDouble
A1 = ChannelDouble("x", "SARUN14-DBPM070:X-REF-FB")
A2 = ChannelDouble("y", "SARUN14-DBPM070:Y-REF-FB")
S1 = ChannelDouble("hamp", "SARFE10-PBPG050:HAMP-INTENSITY")
S2 = ChannelDouble("slow", "SARFE10-PBPG050:PHOTON-ENERGY-PER-PULSE-DS")
A1.initialize()
A2.initialize()
S1.initialize()
S2.initialize()
A1_init = A1.read()
A2_init = A2.read()
A1i = A1_init-0.1
A1f = A1_init+0.1
A2i = A2_init-0.1
A2f = A2_init+0.1
nstep = 21
lat = 10.0
nav = 10
plt = plot(None, title="Output")[0]
plt.clear()
plt.setStyle(plt.Style.ErrorY)
plt.addSeries(LinePlotErrorSeries("Sensor1", Color.red))
def data_ok():
return (mps_beam_ok.read() == 1)
def after_sample(record, scan):
if not data_ok():
time.sleep(1.0)
record.invalidate()
print "Invalidating record: " + str(record)
else:
plt.getSeries(0).appendData(record.positions[0], record.values[0].mean, record.values[0].stdev)
try:
S1_averager = create_averager(S1, nav, 0.1)
S2_averager = create_averager(S2, nav, 0.1)
S2_averager.monitored=True
r = ascan((A1,A2), (S1_averager, S2_averager), (A1i,A2i), (A1f,A2f), (nstep,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()
+36
View File
@@ -0,0 +1,36 @@
import ch.psi.pshell.epics.ChannelDouble as ChannelDouble
A1 = ChannelDouble("x", "SARUN13-DBPM070:X-REF-FB")
A2 = ChannelDouble("y", "SARUN13-DBPM070:Y-REF-FB")
camera_name = "SARBD01-DSCR110"
cam_server.start(camera_name+"_sp1", True) #True for shared pipeline
wait_cam_server_message()
S1 = cam_server.stream.getChild("intensity")
A1.initialize()
A2.initialize()
S1.initialize()
A1_init = A1.read()
A2_init = A2.read()
A1i = A1_init-0.1
A1f = A1_init+0.1
A2i = A2_init-0.1
A2f = A2_init+0.1
nstep = 11
lat = 1.0
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, 0.1)
r = ascan((A1,A2), (S1_averager), (A1i,A2i), (A1f,A2f), (nstep,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)]
finally:
A1.write(A1_init)
A1.close()
S1.close()
S2.close()
+4
View File
@@ -0,0 +1,4 @@
xxx = create_device("cs://sf-daqsync-01:8889/SLG-LCAM-C041_sp1?channel=intensity&samples=-10&interval=-1")
add_device(xxx, True)
show_panel(xxx)