From 69b31e44747a57a5fe9a85d73d91c20da52e01fb Mon Sep 17 00:00:00 2001 From: Thierry Zamofing Date: Mon, 3 Dec 2018 16:33:38 +0100 Subject: [PATCH] wip --- python/PBMotionAnalyzer/MAxyPlot.py | 1 + python/shapepath.py | 75 +++++++++++++++++++++++++++-- 2 files changed, 71 insertions(+), 5 deletions(-) diff --git a/python/PBMotionAnalyzer/MAxyPlot.py b/python/PBMotionAnalyzer/MAxyPlot.py index 77f8e51..4f24402 100644 --- a/python/PBMotionAnalyzer/MAxyPlot.py +++ b/python/PBMotionAnalyzer/MAxyPlot.py @@ -36,6 +36,7 @@ class MPLCanvasImg(FigureCanvas): self.SetStatusCB=SetStatusCB fig = mpl.figure.Figure() ax = fig.add_axes([0.075,0.075,0.85,0.85]) + ax.invert_xaxis();ax.invert_yaxis() FigureCanvas.__init__(self,parent, -1, fig) self.mpl_connect('motion_notify_event', self.OnMotion) self.mpl_connect('button_press_event', self.OnBtnPress) diff --git a/python/shapepath.py b/python/shapepath.py index c925133..73e4f62 100755 --- a/python/shapepath.py +++ b/python/shapepath.py @@ -106,11 +106,12 @@ class ShapePath(MotionBase): self.plot_points(pts) plt.show() - def gen_rand_points(self,n=107,scale=1000): + def gen_rand_points(self,n=107,scale=1000,ofs=(0,0)): 'generate random distributed points' np.random.seed(0) #data=np.random.randint(0,1000,(30,2)) pts=np.random.rand(n,2)*scale + pts+=ofs self.points=pts def gen_grid_points(self,w=10,h=10,pitch=100,rnd=.2,ofs=(0,0)): @@ -123,6 +124,50 @@ class ShapePath(MotionBase): pts+=ofs self.points=pts + def gen_closed_shifted(self,pitch=100,shift=5,mult=3): + 'from the given points, close the path, and runs 9 times with small pitch' + + pts=self.points + pts = np.vstack((pts, pts[-1]+(0,-50)))#add a new point outside of the grid + mn=pts.min(0) + mx=pts.max(0) + d=pts[0,:]-pts[-1,:] + l=np.sum(d) + bk=[] + if abs(d[1])>pitch: #make a vertical back move + s=np.sign(d[1]) + n=np.ceil(np.abs(d[1])/pitch) + p=np.ndarray((n,2)) + p[:,0]=pts[-1, 0] + p[:,1]=pts[-1, 1]+np.arange(1,n+1)*s*pitch + pts=np.vstack((pts,p)) + + if abs(d[0])>pitch: #make a horizonlat back move + s=np.sign(d[0]) + n=np.ceil(np.abs(d[0])/pitch) + p=np.ndarray((n,2)) + p[:,0]=pts[-1, 0]+np.arange(1,n+1)*s*pitch + p[:,1]=pts[-1, 1] + pts[-1, :] + pts=np.vstack((pts,p)) + + stack=[] + for y in np.arange(mult)*shift: + for x in np.arange(mult)*shift: + stack.append(pts+(x,y)) + pts=np.vstack(stack) + + + #xx,yy=np.meshgrid(range(w), range(h)) + #pts=np.array([xx.reshape(-1),yy.reshape(-1)],dtype=np.float).transpose()*pitch + #if xy: + #else: + + # smlpitch + #pts+=ofs + self.points=pts + + def opt_pts(self,fn): ''' trial to optimize path by mofing trajectory, uload real path and move the points @@ -378,6 +423,7 @@ class ShapePath(MotionBase): def plot_points(self,pts): fig=plt.figure() ax = fig.add_subplot(1,1,1) + ax.invert_xaxis();ax.invert_yaxis() #hl=ax[0].plot(x, y, color=col) hl=ax.plot(pts[:,0],pts[:,1],'r.') hl=ax.plot(pts[:,0],pts[:,1],'y--') @@ -400,6 +446,7 @@ class ShapePath(MotionBase): if mode&1: fig=plt.figure('trajectory') ax = fig.add_subplot(1,1,1) + ax.invert_xaxis();ax.invert_yaxis() #hl=ax[0].plot(x, y, color=col) hl=ax.plot(pts[:,0],pts[:,1],'r.') hl=ax.plot(pts[:,0],pts[:,1],'y--') @@ -606,6 +653,9 @@ if __name__=='__main__': #sp.plot_gather() #return fn='/tmp/shapepath' + fn='/home/zamofing_t/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/python/record/grid_delay_0002' + # /home/zamofing_t/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/python/record/chip000_sortedXXXX_9x9' + #fn='/sf/bernina/data/p17592/res/20181203/imprints/chip000_preloc_min10um_sortedX_refs_goaround/chip000_sortedY_9x9.npz' #fn='PBMotionAnalyzer/records/rand50um_25Hz' #sp.setup_coord_trf() @@ -621,6 +671,17 @@ if __name__=='__main__': #sp.points = np.array([[100,523],[635,632],[756,213]]) #sp.points = np.array([[0, 0],[100, 0],[200, 0],[300, 0],[400, 0],[400, 100],[300, 100],[200, 100],[100, 100],[0, 100],[10, 200],[100, 200],[200, 200],[300, 200],[400, 200],[410, 300],[300, 300],[200, 300],[100, 300],[0, 300],[0, 400],[100, 400],[200, 400],[300, 400],[400, 400]]) #sp.gen_rand_points(n=107, scale=1000);sp.sort_points(xy=xy) + #sp.gen_rand_points(n=107, scale=1000);sp.sort_points(xy=xy) + #fh=np.load('/sf/bernina/data/p17592/res/20181203/imprints/chip000_preloc_min10um_sortedX_refs_goaround/chip000_preloc_min10um_sortedX_refs_goaround_0529.npz') + #sp.points=fh['pts'] + sp.gen_grid_points(w=6,h=6,pitch=100,rnd=0,ofs=(0,0));sp.sort_points(False); + sp.gen_closed_shifted() + sp.points=sp.points-+sp.points[0,:]+(-967,1446) + #1412.33 -2862.37 + #1446.62 -967.7128125 + + #sp.plot_points(sp.points);plt.show() + #sp.gen_grid_points(w=100,h=100,pitch=10,rnd=.2) #sp.gen_swissfel_points(width=1000,ofs=(-500,0));sp.sort_points(xy=xy) #sp.gen_grid_points(w=10,h=10,pitch=50,rnd=.2) @@ -634,7 +695,7 @@ if __name__=='__main__': #sp.setup_sync(mode=1) #sync with timing system (PROG) sp.setup_sync(mode=2) #sync with timing system and PLC to sync speed (PROG) sp.setup_coord_trf() # reset to shape path system - + sp.setup_motion(fnPrg=fn + '.prg', mode=1, pt2pt_time=40) #sp.gen_grid_points(w=2,h=2,pitch=50,rnd=.2);sp.sort_points(xy);sp.setup_motion(fnPrg=fn+'.prg',mode=1,pt2pt_time=10,acq_per=1) #sp.gen_swissmx_points(width=1000,ofs=(-500,0));sp.setup_motion(fnPrg=fn+'.prg',mode=1,pt2pt_time=40,acq_per=1) @@ -648,9 +709,13 @@ if __name__=='__main__': #sp.gen_rand_points(n=400, scale=1000);sp.sort_points(xy);sp.setup_motion(fnPrg=fn+'.prg',mode=1,pt2pt_time=10) - #sp.gen_swissmx_points(width=500,flipx=True,flipy=True,ofs=(-380,3980));sp.setup_motion(fnPrg=fn+'.prg',mode=1,pt2pt_time=40,acq_per=1) + #sp.gen_swissmx_points(width=2000,flipx=True,flipy=True,ofs=(1014,-281));sp.setup_motion(fnPrg=fn+'.prg',mode=1,pt2pt_time=40,acq_per=1) #sp.gen_grid_points(w=20,h=20,pitch=20,rnd=0,ofs=(-464,1754));sp.sort_points(True);sp.setup_motion(fnPrg=fn+'.prg',mode=1,pt2pt_time=40) - sp.gen_grid_points(w=20,h=20,pitch=20,rnd=0,ofs=(-160,3700));sp.sort_points(False);sp.setup_motion(fnPrg=fn+'.prg',mode=1,pt2pt_time=40) + #sp.gen_grid_points(w=20,h=20,pitch=20,rnd=0,ofs=(-160,3700));sp.sort_points(False);sp.setup_motion(fnPrg=fn+'.prg',mode=1,pt2pt_time=40) + #sp.gen_grid_points(w=5,h=5,pitch=100,rnd=0,ofs=(-1590,-1070));sp.sort_points(False);sp.setup_motion(fnPrg=fn+'.prg',mode=1,pt2pt_time=40) + #sp.gen_grid_points(w=5,h=5,pitch=100,rnd=0,ofs=(-1580,-1070));sp.sort_points(False);sp.setup_motion(fnPrg=fn+'.prg',mode=1,pt2pt_time=40) + #sp.gen_grid_points(w=5,h=5,pitch=100,rnd=0,ofs=(-1580,-1060));sp.sort_points(False);sp.setup_motion(fnPrg=fn+'.prg',mode=1,pt2pt_time=40) + #sp.gen_grid_points(w=5,h=5,pitch=100,rnd=0,ofs=(-1590,-1060));sp.sort_points(False);sp.setup_motion(fnPrg=fn+'.prg',mode=1,pt2pt_time=40) #>>>setup gather and sync<<< #sp.setup_gather() @@ -662,7 +727,7 @@ if __name__=='__main__': #>>>run gather and plot trajectory<<< #return sp.run() - trigger(0.5) + #trigger(0.5) sp.gather_upload(fnRec=fn+'.npz') sp.plot_gather(mode=11)