Files
sf-ph/script/PbpgPosYScan.py
follath_r f673dda85e Startup
2017-09-01 16:21:37 +02:00

36 lines
1.1 KiB
Python

from mathutils import fit_polynomial
from mathutils import PolynomialFunction
import math
from plotutils import plot_function
print "Starting"
#Creating averaging devices
av_hamp_y = create_averager(hamp_y, count = 10, interval = -1, name = "av_hamp_y")
av_xbpm_y = create_averager(xbpm_y, count = 10, interval = -1, name = "av_xbpm_y")
av_xbpm_y.monitored = True
#The actuals scan
r=lscan(pbpg_my, [av_hamp_y, av_xbpm_y], -0.5, 0.5, 20, latency = 0.0)
#Fitting
values = to_array(r.getReadable(0), 'd')
positions = r.getPositions(0)
pars_polynomial = (a0, a1) = fit_polynomial(values, positions, 1)
#Writing metadata to data file
path = get_exec_pars().scanPath
set_attribute(path, "a0", a0)
set_attribute(path, "a1", a1)
#et_attribute(path, "a2", a2)
#Plotting fit and writing fitting parameters
outp = "a0="+ ("%0.4f" % a0) + "a1="+ ("%0.4f" % a1) # "a2="+ ("%0.4f" % a2)
print outp
p = get_plots()[0]
p.addText((min(positions) + max(positions))/2, max(values), outp, Color.BLACK)
plot_function(p, PolynomialFunction(pars_polynomial), "Fit",positions, show_points = False, show_lines = True, color = Color.BLUE)