This commit is contained in:
voulot_d
2017-08-15 15:11:45 +02:00
parent ef416da30d
commit 77efdf64fe
4 changed files with 48 additions and 33 deletions

View File

@@ -1,19 +1,12 @@
import ch.psi.pshell.epics.Positioner as Positioner
import ch.psi.pshell.epics.Camtool as Camtool
is_panel = get_exec_pars().source != CommandSource.ui #must be check before run
run("CPython/wrapper")
#Parameters
dry_run = True
do_elog = False
if get_exec_pars().source == CommandSource.ui:
start = 45.0
stop = 55.0
step = 1.0
nb = 3
lat = 0.3
disp = -0.387
p0 = 7.1
plt = plot(None, title="Output")[0]
else:
if is_panel:
start = args[0]
stop = args[1]
step = args[2]
@@ -22,6 +15,15 @@ else:
disp = args[5]
p0 = args[6]
plt = args[7]
else:
start = 45.0
stop = 55.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
@@ -67,7 +69,7 @@ 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
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
@@ -91,14 +93,26 @@ p = [A * val.mean + B for val in r.getReadable(0)]
dp = [abs(A) * val.mean for val in r.getReadable(1)]
save_dataset(get_exec_pars().group + "/p", p)
save_dataset(get_exec_pars().group + "/dp", dp)
try:
run("CPython/wrapper")
plt.addSeries(LinePlotErrorSeries("Momentum Fit", plt.getSeries(0).color))
plt.addSeries(LinePlotErrorSeries("Momentum Spread Fit", plt.getSeries(1).color, 2))
i_max = p.index(max(p))
i_min = dp.index(min(dp))
(ph_p_max, p_max, ph_p_fit, p_fit) = extremum(ph[i_max-5:i_max+6], p[i_max-5:i_max+6])
(ph_dp_min, dp_min, ph_dp_fit, dp_fit) = extremum(ph[i_min-5:i_min+6], dp[i_min-5:i_min+6])
plt.getSeries(2).appendData(ph_p_fit, p_fit)
plt.getSeries(3).appendData(ph_dp_fit, dp_fit)
min_i, max_i = max(i_max-5, 0), min(i_max+6, len(p))
print min_i, max_i
(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(p))
print min_i, max_i
(ph_dp_min, dp_min, ph_dp_fit, dp_fit) = extremum(ph[min_i:max_i], dp[min_i:max_i])
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, "%2.2f" % ph_p_max, plt.getSeries(0).color)
plt.addMarker(ph_dp_min, plt.AxisId.X, "%2.2f" % ph_dp_min, plt.getSeries(1).color)
except:
raise Exception("Fit failure")