try to cleanup stuff(3)

This commit is contained in:
2024-12-11 15:26:01 +01:00
parent 71a473d25d
commit 0fe59e9ad6
4 changed files with 195 additions and 58 deletions

View File

@@ -251,25 +251,55 @@ class Grid(UsrROI):
def get_scan_param(self):
'returns scan parameters for scanning with deltatau. the format is as used for shapepath'
scan=1 # snake motion Y fast, X slow (default)
cnt=np.array(self._cnt,np.int32)
sz=np.array(self.size())
pitch=sz/cnt
xx, yy=np.meshgrid(range(cnt[0]), range(cnt[1]))
if scan==0: # snake motion X fast, Y slow
for i in range(1,cnt[1],2):
xx[i]=xx[i][::-1]
else: # scan==1 # snake motion Y fast, X slow (default)
xx=xx.T
yy=yy.T
for i in range(1, cnt[0], 2):
yy[i]=yy[i][::-1]
pts=np.array([xx.reshape(-1), yy.reshape(-1)], dtype=np.float64).transpose()*pitch
param={'points':pts}
cnt=np.array(self._cnt, np.int32)
grid={'pos':tuple(self.pos()), 'pitch':tuple(np.array(self.size())/cnt), 'count':self._cnt}
use_trf=self._param.get('use_trf', True) # do not use coordinate transformation
mode=self._param.get('mode',1)
num_pts=np.array(self._cnt, np.int32).prod()
param={'num_pts':num_pts}
param.update(self._param)
assert(param.get('code_gen',0)==0) # this provides fully x,y motor coordinates
# TODO: simplify !!!
t=self.transform() #obj_info(t)
p=np.array(self.pos())
s=1#self.size()/self._dscr['size']
trf=np.array(((t.m11(),t.m12()),(t.m21(),t.m22()),(0,0)))
trf[2,:]=p # shift origin
trf[:2,:]=(trf[:2,:].T*s).T # same as np.asmatrix(np.diag(s))*trf[:2,:], trf[:2,:]*=s not working, scale before rot / shear
pos=np.array((0,0)) #np.array(grid['pos']) # in um
pitch=np.array(grid['pitch']) # in um
trf2=np.asmatrix(np.identity(3))
trf2[:, :2]=trf
trf2*=np.asmatrix(((1000, 0, 0), (0, 1000, 0), (0, 0, 1)))
trf3=np.asmatrix(((pitch[0], 0, 0), (0, pitch[1], 0), (pos[0], pos[1], 1)))
trf=(trf3*trf2)[:, :2]
if mode in (1,3): # needs all points, not grid
scan=1 # snake motion Y fast, X slow (default)
xx, yy=np.meshgrid(range(cnt[0]), range(cnt[1]))
if scan==0: # snake motion X fast, Y slow
for i in range(1,cnt[1],2):
xx[i]=xx[i][::-1]
else: # scan==1 # snake motion Y fast, X slow (default)
xx=xx.T
yy=yy.T
for i in range(1, cnt[0], 2):
yy[i]=yy[i][::-1]
pts=np.array([xx.reshape(-1), yy.reshape(-1)], dtype=np.float64).transpose() #*pitch
if not use_trf:
pts=(np.hstack((pts, np.ones((pts.shape[0], 1))))*trf).A
param['trf']=trf
param['points']=pts
else:
if use_trf:
param.update({'grid':grid, 'trf':trf})
else:
g=grid.copy() #has not be tested !
g['pos']=tuple((np.array((0,0,1))*trf).A.reshape(-1).tolist())
param.update({'grid':p, 'trf':trf})
return param
@@ -371,11 +401,9 @@ class Path(UsrROI):
s=self.size()/self.szOrig
trf=np.array(((t.m11(),t.m12()),(t.m21(),t.m22()),(0,0)))
trf[2,:]=p # shift origin
#trf[:2, 0]*=s[0];trf[:2, 1]*=s[1] #scaling (before rotation shear)
trf[:2,:]=(trf[:2,:].T*s).T # same as np.asmatrix(np.diag(s))*trf[:2,:], trf[:2,:]*=s not working, scale before rot / shear
trf[:2,:]=(trf[:2,:].T*s).T
# trf*'gridpos in um' -> motor pos in mm
param={'points':self._path,'trf':trf}
param={'num_pts':len(self._path),'trf':trf,'points':self._path}
param.update(self._param)
return param