further cleanup

This commit is contained in:
2018-10-17 15:42:23 +02:00
parent de93205e64
commit 18521d9191
3 changed files with 296 additions and 240 deletions

View File

@@ -1097,13 +1097,11 @@ Software esbMX deploy
```
zamofing_t@ganymede:~$ ll /sf/bernina/config/swissmx/zamofing_t/
/sf/bernina/config/swissmx/
ssh sf-cons-01
ssh saresb-cons-01
ssh sf-cons-01
source /opt/gfa/python
source activate /sf/bernina/config/swissmx/conda/envs/b440_clone
zamofing_t@ganymede:~/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/python$
cp *.py /sf/bernina/config/swissmx/zamofing_t
cp ~/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/python/*.py ~/Documents/prj/SwissFEL/PBTools/ /sf/bernina/config/swissmx/zamofing_t
cp -rL ~/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/python/*.py ~/Documents/prj/SwissFEL/PBTools/pbtools/ /sf/bernina/config/swissmx/zamofing_t/

View File

@@ -80,92 +80,12 @@ class Trf:
m[0:3, 3] =(x,y,z)
return m
class HelicalScan(MotionBase):
def __init__(self,comm, gather, verbose):
MotionBase.__init__(self,comm, gather, verbose)
@staticmethod
def test_find_rot_ctr(n=3.,per=1.,bias=4.1,ampl=2.4,phi=37):
# find the rotation center, amplitude out of n (niminum 3) measurements
# n number of equidistant measurements
# per number of periods (full rotation of all measurements nut be a interger value for precise measurements)
# phi phase
# bias bias value
# ampl amplitude
t = np.arange(n)
w=2*np.pi*per/n*t
y=ampl*np.cos(w+phi*d2r)+bias
plt.figure(1)
plt.subplot(311)
plt.plot(t,y,'b.-')
plt.subplot(312)
f = np.fft.fft(y)
plt.step(t, f.real,'b.-', t, f.imag,'r.-', where='mid')
(bias,ampl,phase)=HelicalScan.meas_rot_ctr(y, per)
print('bias: '+str(bias))
print('amplitude: '+str(ampl))
print('phase: '+str(phase*360./2/np.pi))
plt.subplot(313)
t2 = np.linspace(0,2*np.pi,64)
y2=ampl*np.cos(t2+phase)+bias
plt.plot(t2,y2,'g-')
plt.stem(w,y,'b-')
plt.show()
pass
def test_coord_trf(self):
param = self.param
cx, cz, w, fy, = (0.2,0.3,0.1,0.4)
#cx, cz, w, fy, = (10.,20,3.,40)
print('input : cx:%.6g cz:%.6g w:%.6g fy:%.6g' % (cx,cz,w/d2r*1000.,fy))
(dx,dz,w,y) = self.fwd_transform(cx,cz,w,fy)
print('fwd_trf: dx:%.6g dz:%.6g w:%.6g fy:%.6g' % (dx,dz,w/d2r*1000.,y))
(cx,cz,w,fy) = self.inv_transform(dx,dz,w,y)
print('inv_trf: cx:%.6g cz:%.6g w:%.6g fy:%.6g' % (cx,cz,w/d2r*1000.,fy))
dx, dz, w, y, = (0.2,0.3,0.1,0.4)
#dx, dz, w, y, = (10.,20,3.,40)
print('input : dx:%.6g dz:%.6g w:%.6g fy:%.6g' % (dx,dz,w/d2r*1000.,y))
(cx,cz,w,fy) = self.inv_transform(dx,dz,w,y)
print('inv_trf: cx:%.6g cz:%.6g w:%.6g fy:%.6g' % (cx,cz,w/d2r*1000.,fy))
(dx,dz,w,y) = self.fwd_transform(cx,cz,w,fy)
print('fwd_trf: dx:%.6g dz:%.6g w:%.6g fy:%.6g' % (dx,dz,w/d2r*1000.,y))
def mpl_test(self):
plt.ion()
fig = plt.figure()
ax = fig.add_axes([.2, .05, .75, .90])
x=np.arange(0,2*np.pi,.1)
y=np.sin(x)
h=ax.plot(x,y)
# ax.set_position([.2,.05,.75,.90])
#ax2 = ax.twinx()
ax2 = fig.add_axes([.2, .05, .75, .90],sharex=ax)
ax2.set_position([.1,.05,.75,.90])
ax2.spines['top'].set_visible(False)
ax2.spines['bottom'].set_visible(False)
ax2.xaxis.set_visible(False)
ax2.patch.set_visible(False)
y2=y+.1*np.random.random(y.shape)
h+=ax2.plot(x,y2,'g')
ax2.set_position(ax.get_position())
ax2.set_ylabel('mylbl', color='r')
ax2.tick_params(axis='y', colors='b')
ax2.spines['left'].set_position(('axes',-.1))
plt.legend(handels=h)
pass
class HelicalScanGui():
def __init__(self,helicalScan):
self.helScn=helicalScan
def show_vel(self):
rec=self.rec
rec=self.helScn.rec
fig = plt.figure()
#y = np.diff(rec[:, 2])
y = np.diff(rec,axis=0)
@@ -184,7 +104,7 @@ class HelicalScan(MotionBase):
plt.legend()
def show_pos(self):
rec=self.rec
rec=self.helScn.rec
y = rec
#plt.ion()
fig = plt.figure(figsize=(20,6))
@@ -228,12 +148,12 @@ class HelicalScan(MotionBase):
event.canvas.toolbar.set_message(msg)
def interactive_cx_cz_w_fy(self):
param=self.helScn.param
fig = plt.figure()
self.manip=False#True#False
self.ax=ax=plt3d.Axes3D(fig,[0.02, 0.15, 0.96, 0.83])
ax.set_xlabel('Z');ax.set_ylabel('X');ax.set_zlabel('Y')
ax.view_init(elev=14., azim=10)
param=self.param
# param[i]=(z_i, y_i, x_i, r_i,phi_i)
ctr=param[:,0:3].mean(0)[::-1]
self.axSetCenter(ctr,param[0,3]+param[1,3])
@@ -280,7 +200,7 @@ class HelicalScan(MotionBase):
w = self.sldW.val
fy = self.sldFy.val
if self.manip:
param = self.param
param = self.helScn.param
# param[i]=(z_i, y_i, x_i, r_i,phi_i)
p = np.ndarray((param.shape[0], 3))
for i in range(2):
@@ -300,11 +220,11 @@ class HelicalScan(MotionBase):
self.fig.canvas.draw_idle()
def interactive_dx_dz_w_y(self):
param=self.helScn.param
fig = plt.figure()
self.ax=ax=plt3d.Axes3D(fig,[0.02, 0.15, 0.96, 0.83])
ax.set_xlabel('Z');ax.set_ylabel('X');ax.set_zlabel('Y')
ax.view_init(elev=14., azim=10)
param=self.param
# param[i]=(z_i, y_i, x_i, r_i,phi_i)
ctr=(0,0,0)
@@ -344,22 +264,24 @@ class HelicalScan(MotionBase):
plt.show()
def update_dx_dz_w_y(self,val):
helScn=self.helScn
dx = self.sldDx.val
dz = self.sldDz.val
w = self.sldW.val
y = self.sldY.val
w=w*d2r
(cx,cz,w,fy)=self.inv_transform(dx,dz,w,y)
(cx,cz,w,fy)=helScn.inv_transform(dx,dz,w,y)
#print (cx,cz,w,fy)
self.hCrist,pt=self.pltCrist(-cx,-cz,w,-fy,self.hCrist)
self.fig.canvas.draw_idle()
def interactive_anim(self):
param=self.helScn.param
rec=self.helScn.rec
fig = plt.figure()
self.ax=ax=plt3d.Axes3D(fig,[0.02, 0.15, 0.96, 0.83])
ax.set_xlabel('Z');ax.set_ylabel('X');ax.set_zlabel('Y')
ax.view_init(elev=14., azim=10)
param=self.param
# param[i]=(z_i, y_i, x_i, r_i,phi_i)
ctr=(0,0,0)
@@ -369,21 +291,23 @@ class HelicalScan(MotionBase):
lx=[-1,1];ly=[0,1];lz=[-1,1]
ly = param[:,1]
self.sldFrm=sFrm=Slider(axFrm, 'frm', 0, self.rec.shape[0]-1, valinit=0)
self.sldFrm=sFrm=Slider(axFrm, 'frm', 0, rec.shape[0]-1, valinit=0)
sFrm.on_changed(self.update_anim)
m=Trf.trans(0,0,0); self.hOrig=self.pltOrig(m)
self.hCrist=None
self.fig=fig
animCnt=100
self.step=self.rec.shape[0]/animCnt
self.step=rec.shape[0]/animCnt
#a = anim.FuncAnimation(fig, self.anim_gather_data, animCnt, fargs=(), interval=20, repeat=False, blit=False)
self.update_anim(0)
plt.show()
pass
def update_anim(self,frm):
(cx, cz, w, fy)=self.rec[int(frm),:]
print(frm)
rec=self.helScn.rec
(cx, cz, w, fy)=rec[int(frm),:]
#data/=. #scale from um to mm
w*=d2r/1000 # scale from deg to rad
#print (cx,cz,w,fy)
@@ -391,12 +315,234 @@ class HelicalScan(MotionBase):
self.fig.canvas.draw_idle()
def anim_gather_data(self,idx):
(cx, cz, w, fy)=self.rec[int(idx*self.step),:]
rec=self.helScn.rec
(cx, cz, w, fy)=rec[int(idx*self.step),:]
w*=d2r/1000 # scale from deg to rad
self.hCrist,pt=self.pltCrist(-cx,-cz,w,-fy,self.hCrist)
#data=self.rec[int(idx*self.step),:]
#self.hCrist,pt=self.pltCrist(*data,h=self.hCrist)
def pltOrig(self,m,h=None):
ax=self.ax
# m is a 4x4 matrix. the transformed matrix
idx=(2,0,1)
r=m[idx,0] #1st
g=m[idx,1] #2nd
b=m[idx,2] #3rd
o=m[idx,3] #origin
lines = np.ndarray((3, 2, 3)) # numlines, points, xyz
lines[:, 0, :] = o
lines[0, 1, :] = o + r
lines[1, 1, :] = o + g
lines[2, 1, :] = o + b
if h is None:
lseg = tuple(lines)
col=('r','g','b')
hlc = plt3d.art3d.Line3DCollection(lseg, colors=col, linewidths=2) # , *args[argi:], **kwargs)
ax.add_collection(hlc)
return hlc
else:
h.set_segments(lines)
return h
def pltCrist(self,cx=0,cz=0,w=0,fy=0,h=None):
#h are the handles
ax = self.ax
helScn = self.helScn
param = helScn.param
pt = np.ndarray((4, 3))
if h is None:
h=[] #handels
for i in range(2):
(z, y, x, r, phi) = param[i]
x+=cx;y+=fy;z+=cz;phi+=w
pt[i] = (z, x, y)
pt[i + 2] = (z + r * np.cos(phi), x + r * np.sin(phi), y)
obj = mpl.patches.Circle((z, x), r, facecolor=mpl.colors.colorConverter.to_rgba('y', alpha=0.2))
h1=ax.add_patch(obj)
h2=plt3d.art3d.pathpatch_2d_to_3d(obj, z=y, zdir="z")
#print h1._segment3d
h.append(obj)
#hs=ax.scatter(pt[:, 2], pt[:, 0], pt[:, 1])
hs=ax.plot(pt[:, 0], pt[:, 1], pt[:, 2],'.')
hp=ax.plot(pt[2:, 0], pt[2:, 1], pt[2:, 2])
h+=(hs[0],hp[0])
if hasattr(helScn,'points'):
lines = self.get_meas_lines(pt,cx,cz,fy,w)
p=tuple(lines[:,0,:].T)
hl =plt3d.art3d.Line3D(*p,color='r',marker='.')#, *args[argi:], **kwargs)
ax.add_artist(hl);h.append(hl)
lseg=tuple(lines)
col=(mpl.colors.colorConverter.to_rgba('r'),)*len(lseg)
hlc=plt3d.art3d.Line3DCollection(lseg,colors=col)#, *args[argi:], **kwargs)
ax.add_collection(hlc);h.append(hlc)
else:
for i in range(2):
(z, y, x, r, phi) = param[i]
x+=cx;y+=fy;z+=cz;phi+=w
pt[i] = (z, x, y)
pt[i + 2] = (z + r * np.cos(phi), x + r * np.sin(phi), y)
h[i].remove()
obj = mpl.patches.Circle((z, x), r, facecolor=mpl.colors.colorConverter.to_rgba('y', alpha=0.2))
ax.add_patch(obj)
plt3d.art3d.pathpatch_2d_to_3d(obj, z=y, zdir="z")
h[i]=obj
h[2].set_data(pt[:, 0], pt[:, 1])#, pt[:, 1]))
h[2].set_3d_properties(pt[:, 2])
h[3].set_data(pt[2:, 0], pt[2:, 1])#, pt[:, 1]))
h[3].set_3d_properties(pt[2:, 2])
if hasattr(helScn,'points'):
lines = self.get_meas_lines(pt,cx,cz,fy,w)
hl=h[4]
#hl.set_data(lines[:,0,0], lines[:,0,1]) # , pt[:, 1]))
#hl.set_3d_properties(lines[:,0,2])
p=tuple(lines[:,0,:].T)
hl._verts3d=p;hl.stale=True
hlc=h[5]
hlc.set_segments(lines)
return (h,pt)
def get_meas_lines(self,pt,cx,cz,fy,w):
param = self.helScn.param
pts = self.helScn.points
dx_ = pts[:, 0] # add 0.2 to test
dz_ = pts[:, 1] # add 0.2 to test
w_ = pts[:, 2] * (d2r / 1000.)
y_ = pts[:, 3]
# self.inv_transform(self, dx, dz, w, y):
f = (pts[:, 3] - param[0, 1]) / (param[1, 1] - param[0, 1])
lines = np.ndarray((pts.shape[0], 2, 3))
ofx=dx_*-np.sin(w-w_)+dz_*np.cos(w-w_) # 0.2=dx
ofy=dx_*np.cos(w-w_)+dz_*np.sin(w-w_)
lines[:, 0, 0] = pt[2, 0] + (pt[3, 0] - pt[2, 0]) * f +ofx # z data
lines[:, 0, 1] = pt[2, 1] + (pt[3, 1] - pt[2, 1]) * f +ofy # x data
lines[:, 0, 2] = pts[:, 3] + fy # y data
lines[:, 1, 0] = lines[:, 0, 0] + np.cos(w-w_)*.1
lines[:, 1, 1] = lines[:, 0, 1] + np.sin(w-w_)*.1
lines[:, 1, 2] = lines[:, 0, 2]
return lines
def axSetCenter(self,v,l):
ax=self.ax
#v=center vector, l= length of each axis
l2=l/2.
ax.set_xlim(v[2]-l2, v[2]+l2);
ax.set_ylim(v[0]-l2, v[0]+l2);
ax.set_zlim(v[1]-l2, v[1]+l2)
class HelicalScanTests():
@staticmethod
def test_find_rot_ctr(n=3.,per=1.,bias=4.1,ampl=2.4,phi=37):
# find the rotation center, amplitude out of n (niminum 3) measurements
# n number of equidistant measurements
# per number of periods (full rotation of all measurements nut be a interger value for precise measurements)
# phi phase
# bias bias value
# ampl amplitude
t = np.arange(n)
w=2*np.pi*per/n*t
y=ampl*np.cos(w+phi*d2r)+bias
plt.figure(1)
plt.subplot(311)
plt.plot(t,y,'b.-')
plt.subplot(312)
f = np.fft.fft(y)
plt.step(t, f.real,'b.-', t, f.imag,'r.-', where='mid')
(bias,ampl,phase)=HelicalScan.meas_rot_ctr(y, per)
print('bias: '+str(bias))
print('amplitude: '+str(ampl))
print('phase: '+str(phase*360./2/np.pi))
plt.subplot(313)
t2 = np.linspace(0,2*np.pi,64)
y2=ampl*np.cos(t2+phase)+bias
plt.plot(t2,y2,'g-')
plt.stem(w,y,'b-')
plt.show()
pass
@staticmethod
def test_coord_trf(helScn):
param = helScn.param
cx, cz, w, fy, = (0.2,0.3,0.1,0.4)
#cx, cz, w, fy, = (10.,20,3.,40)
print('input : cx:%.6g cz:%.6g w:%.6g fy:%.6g' % (cx,cz,w/d2r*1000.,fy))
(dx,dz,w,y) = helScn.fwd_transform(cx,cz,w,fy)
print('fwd_trf: dx:%.6g dz:%.6g w:%.6g fy:%.6g' % (dx,dz,w/d2r*1000.,y))
(cx,cz,w,fy) = helScn.inv_transform(dx,dz,w,y)
print('inv_trf: cx:%.6g cz:%.6g w:%.6g fy:%.6g' % (cx,cz,w/d2r*1000.,fy))
dx, dz, w, y, = (0.2,0.3,0.1,0.4)
#dx, dz, w, y, = (10.,20,3.,40)
print('input : dx:%.6g dz:%.6g w:%.6g fy:%.6g' % (dx,dz,w/d2r*1000.,y))
(cx,cz,w,fy) = helScn.inv_transform(dx,dz,w,y)
print('inv_trf: cx:%.6g cz:%.6g w:%.6g fy:%.6g' % (cx,cz,w/d2r*1000.,fy))
(dx,dz,w,y) = helScn.fwd_transform(cx,cz,w,fy)
print('fwd_trf: dx:%.6g dz:%.6g w:%.6g fy:%.6g' % (dx,dz,w/d2r*1000.,y))
@staticmethod
def mpl_test():
plt.ion()
fig = plt.figure()
ax = fig.add_axes([.2, .05, .75, .90])
x=np.arange(0,2*np.pi,.1)
y=np.sin(x)
h=ax.plot(x,y)
# ax.set_position([.2,.05,.75,.90])
#ax2 = ax.twinx()
ax2 = fig.add_axes([.2, .05, .75, .90],sharex=ax)
ax2.set_position([.1,.05,.75,.90])
ax2.spines['top'].set_visible(False)
ax2.spines['bottom'].set_visible(False)
ax2.xaxis.set_visible(False)
ax2.patch.set_visible(False)
y2=y+.1*np.random.random(y.shape)
h+=ax2.plot(x,y2,'g')
ax2.set_position(ax.get_position())
ax2.set_ylabel('mylbl', color='r')
ax2.tick_params(axis='y', colors='b')
ax2.spines['left'].set_position(('axes',-.1))
plt.legend(handels=h)
pass
def calcParamSim(helScn):
#simulated test values
n = 3.;
per = 1.;
w = 2 * np.pi * per / n * np.arange(n)
#p = ((2.3, .71, 4.12, 10.6 * d2r),(6.2, .45, 3.2, 45.28 * d2r)) # (y, bias, ampl, phi)
p = ((2.3, -100., 10, 10. * d2r),(6.2, 100., 10., -10. * d2r)) # (y, bias, ampl, phi)
helScn.param = param = np.ndarray((len(p), 5))
z = 14.5 # fix z position
for i in range(2):
(y, bias, ampl, phi) = p[i]
x = ampl * np.cos(w + phi) + bias
print('yMeas_%d=' % i + str(y) + ' xMeas_%d=' % i + str(x))
# param[i]=(z_i, y_i, x_i, r_i,phi_i)
param[i, 0] = z
param[i, 1] = y
param[i, 2:] = HelicalScan.meas_rot_ctr(x) # (bias,ampl,phase)
(bias, ampl, phase) = param[i][2:]
print(param)
class HelicalScan(MotionBase):
def __init__(self,comm, gather, verbose):
MotionBase.__init__(self,comm, gather, verbose)
def load_rec(self,fn_npz='/tmp/helicalscan.npz'):
try:
fh=np.load(fn_npz)
@@ -405,7 +551,7 @@ class HelicalScan(MotionBase):
else:
pass
s='content of numpy file: '+fn_npz+'\n'
for k,v in fh.iteritems():
for k,v in fh.items():
s+=' '+k+': '+str(v.dtype)+' '+str(v.shape)+'\n'
setattr(self,k,v)
print(s)
@@ -460,26 +606,6 @@ class HelicalScan(MotionBase):
res=(cx,cz,w,fy)
return res
def calcParamSim(self):
#simulated test values
n = 3.;
per = 1.;
w = 2 * np.pi * per / n * np.arange(n)
#p = ((2.3, .71, 4.12, 10.6 * d2r),(6.2, .45, 3.2, 45.28 * d2r)) # (y, bias, ampl, phi)
p = ((2.3, -100., 10, 10. * d2r),(6.2, 100., 10., -10. * d2r)) # (y, bias, ampl, phi)
self.param = param = np.ndarray((len(p), 5))
z = 14.5 # fix z position
for i in range(2):
(y, bias, ampl, phi) = p[i]
x = ampl * np.cos(w + phi) + bias
print('yMeas_%d=' % i + str(y) + ' xMeas_%d=' % i + str(x))
# param[i]=(z_i, y_i, x_i, r_i,phi_i)
param[i, 0] = z
param[i, 1] = y
param[i, 2:] = HelicalScan.meas_rot_ctr(x) # (bias,ampl,phase)
(bias, ampl, phase) = param[i][2:]
print(param)
def calcParam(self,x=((-241.,96.,-53.),(-162.,-293.,246.)),
y=(575.,175.),
z=((-1401.,-1401.,-1802.),(-1802.,-1303.,-1402.))):
@@ -526,109 +652,6 @@ class HelicalScan(MotionBase):
print(param)
def pltOrig(self,m,h=None):
ax=self.ax
# m is a 4x4 matrix. the transformed matrix
idx=(2,0,1)
r=m[idx,0] #1st
g=m[idx,1] #2nd
b=m[idx,2] #3rd
o=m[idx,3] #origin
lines = np.ndarray((3, 2, 3)) # numlines, points, xyz
lines[:, 0, :] = o
lines[0, 1, :] = o + r
lines[1, 1, :] = o + g
lines[2, 1, :] = o + b
if h is None:
lseg = tuple(lines)
col=('r','g','b')
hlc = plt3d.art3d.Line3DCollection(lseg, colors=col, linewidths=2) # , *args[argi:], **kwargs)
ax.add_collection(hlc)
return hlc
else:
h.set_segments(lines)
return h
def pltCrist(self,cx=0,cz=0,w=0,fy=0,h=None):
#h are the handles
ax = self.ax
param = self.param
pt = np.ndarray((4, 3))
if h is None:
h=[] #handels
for i in range(2):
(z, y, x, r, phi) = param[i]
x+=cx;y+=fy;z+=cz;phi+=w
pt[i] = (z, x, y)
pt[i + 2] = (z + r * np.cos(phi), x + r * np.sin(phi), y)
obj = mpl.patches.Circle((z, x), r, facecolor=mpl.colors.colorConverter.to_rgba('y', alpha=0.2))
h1=ax.add_patch(obj)
h2=plt3d.art3d.pathpatch_2d_to_3d(obj, z=y, zdir="z")
#print h1._segment3d
h.append(obj)
#hs=ax.scatter(pt[:, 2], pt[:, 0], pt[:, 1])
hs=ax.plot(pt[:, 0], pt[:, 1], pt[:, 2],'.')
hp=ax.plot(pt[2:, 0], pt[2:, 1], pt[2:, 2])
h+=(hs[0],hp[0])
if hasattr(self,'points'):
lines = self.get_meas_lines(pt,cx,cz,fy,w)
p=tuple(lines[:,0,:].T)
hl =plt3d.art3d.Line3D(*p,color='r',marker='.')#, *args[argi:], **kwargs)
ax.add_artist(hl);h.append(hl)
lseg=tuple(lines)
col=(mpl.colors.colorConverter.to_rgba('r'),)*len(lseg)
hlc=plt3d.art3d.Line3DCollection(lseg,colors=col)#, *args[argi:], **kwargs)
ax.add_collection(hlc);h.append(hlc)
else:
for i in range(2):
(z, y, x, r, phi) = param[i]
x+=cx;y+=fy;z+=cz;phi+=w
pt[i] = (z, x, y)
pt[i + 2] = (z + r * np.cos(phi), x + r * np.sin(phi), y)
h[i].remove()
obj = mpl.patches.Circle((z, x), r, facecolor=mpl.colors.colorConverter.to_rgba('y', alpha=0.2))
ax.add_patch(obj)
plt3d.art3d.pathpatch_2d_to_3d(obj, z=y, zdir="z")
h[i]=obj
h[2].set_data(pt[:, 0], pt[:, 1])#, pt[:, 1]))
h[2].set_3d_properties(pt[:, 2])
h[3].set_data(pt[2:, 0], pt[2:, 1])#, pt[:, 1]))
h[3].set_3d_properties(pt[2:, 2])
if hasattr(self,'points'):
lines = self.get_meas_lines(pt,cx,cz,fy,w)
hl=h[4]
#hl.set_data(lines[:,0,0], lines[:,0,1]) # , pt[:, 1]))
#hl.set_3d_properties(lines[:,0,2])
p=tuple(lines[:,0,:].T)
hl._verts3d=p;hl.stale=True
hlc=h[5]
hlc.set_segments(lines)
return (h,pt)
def get_meas_lines(self,pt,cx,cz,fy,w):
param = self.param
pts = self.points
dx_ = pts[:, 0] # add 0.2 to test
dz_ = pts[:, 1] # add 0.2 to test
w_ = pts[:, 2] * (d2r / 1000.)
y_ = pts[:, 3]
# self.inv_transform(self, dx, dz, w, y):
f = (pts[:, 3] - param[0, 1]) / (param[1, 1] - param[0, 1])
lines = np.ndarray((pts.shape[0], 2, 3))
ofx=dx_*-np.sin(w-w_)+dz_*np.cos(w-w_) # 0.2=dx
ofy=dx_*np.cos(w-w_)+dz_*np.sin(w-w_)
lines[:, 0, 0] = pt[2, 0] + (pt[3, 0] - pt[2, 0]) * f +ofx # z data
lines[:, 0, 1] = pt[2, 1] + (pt[3, 1] - pt[2, 1]) * f +ofy # x data
lines[:, 0, 2] = pts[:, 3] + fy # y data
lines[:, 1, 0] = lines[:, 0, 0] + np.cos(w-w_)*.1
lines[:, 1, 1] = lines[:, 0, 1] + np.sin(w-w_)*.1
lines[:, 1, 2] = lines[:, 0, 2]
return lines
@staticmethod
def meas_rot_ctr(y,per=1):
@@ -645,14 +668,6 @@ class HelicalScan(MotionBase):
ampl=np.absolute(f[idx])*2/n
return (bias,ampl,phase)
def axSetCenter(self,v,l):
ax=self.ax
#v=center vector, l= length of each axis
l2=l/2.
ax.set_xlim(v[2]-l2, v[2]+l2);
ax.set_ylim(v[0]-l2, v[0]+l2);
ax.set_zlim(v[1]-l2, v[1]+l2)
def setup_gather(self,acq_per=1):
'''
setup the channels to gather
@@ -843,7 +858,7 @@ close
channels=["Motor[4].ActPos","Motor[5].ActPos","Motor[3].ActPos","Motor[1].ActPos"]
prg.append('Gather.Enable=0')
prg.append('Gather.Items=%d'%len(channels))
for k,v in gather.iteritems():
for k,v in gather.items():
prg.append('Gather.%s=%d'%(k,v))
for i,c in enumerate(channels):
prg.append('Gather.Addr[%d]=%s.a'%(i,c))
@@ -1011,11 +1026,44 @@ if __name__=='__main__':
gather = Gather(comm)
gpascii = comm.gpascii
hs=HelicalScan(comm, gather, args.verbose)
hs.host=args.host # temporary
hsg=HelicalScanGui(hs)
#hs.test_find_rot_ctr()
#hs.test_find_rot_ctr(n=5. ,per=1.,bias=2.31,ampl=4.12,phi=24.6)
fn='/tmp/helicalscan'
hs.calcParam()
#TODO: move the graphic part in a separate class
#TODO: FE Digitizers PBPS117 timing not working!
#hs.calcParam()
#gpasci: #1,4,5p // y,-x ,-z
# 0deg 256.7 -762.5 -396.4
#120deg 258.5 731.7 -1896.9
#240deg 256.2 -1282.8 -2496.5
# 0deg 586.5 -1023.4 -696.8
# 120deg 574.8 619.8 -1797.5
# 240deg 580.0 -900.0 -2496.3
hs.calcParam(x = ((-762.5, 731.7, -1282.8), (-1023.4, 619.8, -900.0)),
y = (258.5,580.0),
z = (( -396.4,-1896.9,-2496.5),(-696.8,-1797.5,-2496.3)))
#&1p
#B0.3504637004225515 X5.101934282692127 Y586.5400000000002 Z96.49435276710267
#cpx X0 Z0 B0 Y258
#cpx X0 Z0 B120000 Y258
#cpx X0 Z0 B240000 Y258
#cpx X0 Z0 B0 Y580
#cpx X0 Z0 B120000 Y580
#cpx X0 Z0 B240000 Y580
#cpx X-100Z0B0Y258.5
#hs.calcParamSim()
#hs.param[0]=(15,2,0,3,0)#(z_i, y_i, x_i, r_i,phi_i)
#hs.param[1]=(15,4,0,3,0)#(z_i, y_i, x_i, r_i,phi_i)
@@ -1057,7 +1105,7 @@ if __name__=='__main__':
#hs.gen_prog(mode=0,cntHor=3,cntVert=10,hRng=(-5,5),wRng=(0,120000))
#hs.gen_prog(mode=0,cntHor=3,cntVert=25,hRng=(-5,5),wRng=(0,120000))
#hs.gen_prog(mode=1,cntHor=3,cntVert=25,hRng=(-5,5),wRng=(0,120000),smt=0,pt2pt_time=300)
hs.setup_motion(mode=1,cntHor=5,cntVert=25,hRng=(-100,100),wRng=(0,120000),smt=0,pt2pt_time=300)
hs.setup_motion(mode=1,cntHor=5,cntVert=25,hRng=(-10,10),wRng=(0,120000),smt=0,pt2pt_time=300)
#hs.gen_prog(mode=1,cntHor=5,cntVert=25,hRng=(-100,100),wRng=(0,120000),smt=0,pt2pt_time=40)
#hs.gen_prog(mode=1,cntHor=3,cntVert=20,hRng=(-5,5),wRng=(0,1200),smt=0,pt2pt_time=200)
#hs.gen_prog(mode=1, cntHor=2, cntVert=2, wRng=(0, 360000), smt=0)
@@ -1073,9 +1121,9 @@ if __name__=='__main__':
hs.gather_upload(fn+'.npz')
hs.load_rec(fn+'.npz')
hs.show_pos()
hs.show_vel()
hs.interactive_anim()
hsg.show_pos()
hsg.show_vel()
hsg.interactive_anim()
#hs.show_vel(); plt.show()
#hs.show_pos(); plt.show()

View File

@@ -314,14 +314,19 @@ class ShapePath(MotionBase):
if fnRec:
np.savez_compressed(fnRec, rec=rec, pts=pts, meta=self.meta)
def sort_points(self,xy=False):
def sort_points(self,xy=False,grp_sz=None):
pts=self.points
verb=self.verbose
cnt=pts.shape[0]
idx=np.ndarray(cnt,dtype=np.int32)
grp_cnt=int(np.sqrt(cnt))
grp_sz=int(np.ceil(float(cnt)/grp_cnt))
if grp_sz is None:
grp_cnt=int(np.sqrt(cnt))
grp_sz=int(np.ceil(float(cnt)/grp_cnt))
else:
grp_sz=int(grp_sz)
grp_cnt=int(np.ceil(float(cnt)/grp_sz))
if xy==True:
idxA=1;idxB=0
else:
@@ -418,9 +423,14 @@ if __name__=='__main__':
comm = PPComm(host=args.host)
gather = Gather(comm)
sp = ShapePath(comm, gather, args.verbose)
sp.setup_coord_trf()
#sp.setup_coord_trf()
fn='/tmp/shapepath'
#sp.points=np.zeros((2,2))
#sp.meta={'timebase':.2}
#sp.gather_upload(fnRec=fn+'.npz')
#sp.plot_gather()
#return
xy=False
# fn='/home/zamofing_t/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/python/data/'+time.strftime('%y-%m-%d-%H_%M_%S')