SFELPHOTON-927: Beamtime Feb24

This commit is contained in:
2024-01-10 16:19:30 +01:00
parent e41a3ed7ed
commit 681d42dc2e
3 changed files with 75 additions and 53 deletions

View File

@@ -203,7 +203,7 @@ class Fiducial(UsrROI):
def __repr__(self):
ctr=self.ctr()
s=f'{self.__class__.__name__}:(ctr:{itr2str(ctr)}, size:{itr2str(self.size())}}}'
s=f'{self.__class__.__name__}:(ctr:{itr2str(ctr)}, size:{itr2str(self.size())})'
return s
def obj2json(self,encoder):
@@ -219,8 +219,9 @@ class Fiducial(UsrROI):
class Grid(UsrROI):
'''a grid'''
def __init__( self, pos=(0,0), size=(30,20), cnt=(6,4), fiducialSize=.2, **kargs):
pg.ROI.__init__(self, pos, size, **kargs)
def __init__( self, pos=(0,0), size=(30,20), cnt=(6,4), fiducialSize=.2, **kwargs):
self._param=kwargs
pg.ROI.__init__(self, pos, size)#, **kwargs)
self._cnt=cnt
self._fidSz=fiducialSize
self.addScaleHandle([1, 1], [0, 0])
@@ -258,7 +259,7 @@ class Grid(UsrROI):
#p.drawRect(0, 0, 1, 1)
def __repr__(self):
s=f'{self.__class__.__name__}:(pos:{itr2str(self.pos())}, size:{itr2str(self.size())}, cnt:{self._cnt}, fidSize:{self._fidSz}}}'
s=f'{self.__class__.__name__}:(pos:{itr2str(self.pos())}, size:{itr2str(self.size())}, cnt:{self._cnt}, fidSize:{self._fidSz}, param:{self._param})'
return s
def obj2json(self,encoder):
@@ -269,27 +270,33 @@ class Grid(UsrROI):
'cnt':self._cnt,
'fiducialSize':self._fidSz
}
jsn.update(self._param)
return jsn
def get_scan_param(self,mode=0x2):
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)
#pos=np.array(self.pos())
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 mode&0x01: #modify x scaning forward backward each line
if scan==0: # snake motion X fast, Y slow
for i in range(1,cnt[1],2):
xx[i]=xx[i][::-1]
if mode&0x02: # modify y scaning forward backward each line
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
#pts+=pos
return pts
param={'points':pts}
param.update(self._param)
assert(param.get('code_gen',0)==0) # this provides fully x,y motor coordinates
return param
class Path(UsrROI):
@@ -302,9 +309,9 @@ class Path(UsrROI):
a cross is plot at the fiducial positions
'''
def __init__( self, pos=(0,0), size=(30,20), path=np.array(((6,4),(16,24),(-5,7),(3,12))), fiducial=None, ficucialScale=5, **kwargs):
self.code_gen=kwargs.pop('code_gen',0)
trf=kwargs.pop('trf',None)
pg.ROI.__init__(self, pos, size, **kwargs)
self._param=kwargs
pg.ROI.__init__(self, pos, size)#, **kwargs)
self.szOrig=size
if type(path)==list:
path=np.array(path)
@@ -365,8 +372,7 @@ class Path(UsrROI):
p.drawLines(lh,lv)
def __repr__(self):
s=f'{self.__class__.__name__}:(pos:{itr2str(self.pos())}, size:{itr2str(self.size())}, numFid:{self._fiducial.shape[0]}, numPts:{self._path.shape[0]}, ficucialScale:{self._fidScl}}}'
s=f'{self.__class__.__name__}:(pos:{itr2str(self.pos())}, size:{itr2str(self.size())}, numFid:{self._fiducial.shape[0]}, numPts:{self._path.shape[0]}, ficucialScale:{self._fidScl}, param:{self._param})'
return s
def obj2json(self,encoder):
@@ -374,11 +380,11 @@ class Path(UsrROI):
'__class__':self.__class__.__name__,
'pos':tuple(self.pos()),
'size':tuple(self.szOrig),
'code_gen':self.code_gen,
'fiducial': self._fiducial.tolist(),
'ficucialScale':self._fidScl,
'path':self._path.tolist(),
}
jsn.update(self._param)
trf=self.transform()
if not trf.isIdentity():
#obj_info(trf)
@@ -386,12 +392,8 @@ class Path(UsrROI):
jsn['trf']=trf
return jsn
def get_scan_param(self,mode=0x2):
def get_scan_param(self):
'returns scan parameters for scanning with deltatau. the format is as used for shapepath'
#mode=pvt
#param={'points':pts, 'mode':mode}
param={'points':self._path, 'code_gen': self.code_gen}
t=self.transform()
p=np.array(self.pos())
s=self.size()/self.szOrig
@@ -401,7 +403,8 @@ class Path(UsrROI):
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*'gridpos in um' -> motor pos in mm
param['trf']=trf
param={'points':self._path,'trf':trf}
param.update(self._param)
return param
class FixTargetFrame(UsrROI):
@@ -448,9 +451,8 @@ class FixTargetFrame(UsrROI):
}
def __init__( self, pos=(0,0), size=(100,100), tpl='test', dscr=None, **kwargs):
self.code_gen=kwargs.pop('code_gen',0)
trf=kwargs.pop('trf',None)
assert(kwargs==dict())
self._param=kwargs
pg.ROI.__init__(self, pos, size)#, **kwargs)
if trf is not None:
t=self.transform()
@@ -533,7 +535,7 @@ class FixTargetFrame(UsrROI):
assert('unknown feducial type')
def __repr__(self):
s=f'{self.__class__.__name__}:(pos:{itr2str(self.pos())}, size:{itr2str(self.size())}, dscr:{self._dscr}}}'
s=f'{self.__class__.__name__}:(pos:{itr2str(self.pos())}, size:{itr2str(self.size())}, dscr:{self._dscr}, param:{self._param})'
return s
def obj2json(self,encoder):
@@ -541,9 +543,9 @@ class FixTargetFrame(UsrROI):
'__class__':self.__class__.__name__,
'pos':tuple(self.pos()),
'size':tuple(self.size()),
'code_gen':self.code_gen,
'dscr': self._dscr
'dscr': self._dscr,
}
jsn.update(self._param)
trf=self.transform()
if not trf.isIdentity():
#obj_info(trf)
@@ -553,7 +555,7 @@ class FixTargetFrame(UsrROI):
def get_scan_param(self):
'returns scan parameters for scanning with deltatau. the format is as used for shapepath'
scan=0x2 #default fast y axis
scan=1 # snake motion Y fast, X slow (default)
grid=self._dscr['grid']
self._dscr['size']
#pos=np.array(self.pos())
@@ -561,10 +563,10 @@ class FixTargetFrame(UsrROI):
#pos =np.array(grid['pos'],np.float64)
#pitch=np.array(grid['pitch'],np.float64)
xx, yy=np.meshgrid(range(cnt[0]), range(cnt[1]))
if scan&0x01: #modify x scaning forward backward each line
if scan==0: # snake motion X fast, Y slow
for i in range(1,cnt[1],2):
xx[i]=xx[i][::-1]
if scan&0x02: # modify y scaning forward backward each line
else: # scan==1 # snake motion Y fast, X slow (default)
xx=xx.T
yy=yy.T
for i in range(1, cnt[0], 2):
@@ -572,8 +574,6 @@ class FixTargetFrame(UsrROI):
pts=np.array([xx.reshape(-1), yy.reshape(-1)], dtype=np.float64).transpose() #*pitch
param={'grid':grid, 'points':pts, 'code_gen': self.code_gen}
# TODO: simplify !!!
t=self.transform() #obj_info(t)
p=np.array(self.pos())
@@ -582,14 +582,16 @@ class FixTargetFrame(UsrROI):
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(param['grid']['pos']) # in um
pitch=np.array(param['grid']['pitch']) # in um
pos=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]
param['trf']=trf
param={'grid':grid, 'points':pts, 'trf':trf}
param.update(self._param)
# trf*'gridpos' -> motor pos in mm
# {'pos': [2080, 2080], 'pitch': [120, 120], 'count': [162, 162]}
#np.array((0,0,1))*trf grid 0,0 (top left)