Startup
This commit is contained in:
38
script/PbpgSlowXScan.py
Normal file
38
script/PbpgSlowXScan.py
Normal file
@@ -0,0 +1,38 @@
|
||||
from mathutils import fit_polynomial
|
||||
from mathutils import PolynomialFunction
|
||||
import math
|
||||
from plotutils import plot_function
|
||||
print "Starting"
|
||||
|
||||
|
||||
#Creating averaging devices
|
||||
avg_x = create_averager(pbpg_slow_x, count = 30, interval = 1, name = "avg_x")
|
||||
|
||||
#The actuals scan
|
||||
r=lscan(pbpg_mx, avg_x, -1.5, 1.5, 30, latency = 0.0)
|
||||
|
||||
#Fitting
|
||||
values = to_array(r.getReadable(0), 'd')
|
||||
positions = r.getPositions(0)
|
||||
try:
|
||||
pars_polynomial = fit_polynomial(values, positions, 1)
|
||||
except:
|
||||
print "Fit error"
|
||||
raise
|
||||
|
||||
print "Plolynomial pars: ", pars_polynomial
|
||||
(a0, a1) = pars_polynomial
|
||||
#Writing metadata to data file
|
||||
path = get_exec_pars().scanPath
|
||||
print "Scn path: ", path
|
||||
set_attribute(path, "a0", a0)
|
||||
set_attribute(path, "a1", a1)
|
||||
#set_attribute(path, "a2", a2)
|
||||
|
||||
#Plotting fit and writing fitting parameters
|
||||
outp = "a0="+ ("%0.4f" % a0) + "a1="+ ("%0.4f" % a1)
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user