diff --git a/pyqtUsrObj.py b/pyqtUsrObj.py index 67cb8fe..aa2f476 100644 --- a/pyqtUsrObj.py +++ b/pyqtUsrObj.py @@ -450,7 +450,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) - pg.ROI.__init__(self, pos, size, **kwargs) + assert(kwargs==dict()) + pg.ROI.__init__(self, pos, size)#, **kwargs) if trf is not None: t=self.transform() t.setMatrix(trf[0][0], trf[0][1], 0, @@ -552,7 +553,7 @@ class FixTargetFrame(UsrROI): def get_scan_param(self): 'returns scan parameters for scanning with deltatau. the format is as used for shapepath' - mode=0x2 #default fast y axis + scan=0x2 #default fast y axis grid=self._dscr['grid'] self._dscr['size'] #pos=np.array(self.pos()) @@ -560,10 +561,10 @@ class FixTargetFrame(UsrROI): #pos =np.array(grid['pos'],np.float) #pitch=np.array(grid['pitch'],np.float) xx, yy=np.meshgrid(range(cnt[0]), range(cnt[1])) - if mode&0x01: #modify x scaning forward backward each line + if scan&0x01: #modify x scaning forward backward each line for i in range(1,cnt[1],2): xx[i]=xx[i][::-1] - if mode&0x02: # modify y scaning forward backward each line + if scan&0x02: # modify y scaning forward backward each line xx=xx.T yy=yy.T for i in range(1, cnt[0], 2): @@ -573,15 +574,22 @@ class FixTargetFrame(UsrROI): param={'grid':grid, 'points':pts, 'code_gen': self.code_gen} + # TODO: simplify !!! t=self.transform() p=np.array(self.pos()) s=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, 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*'gridpos in um' -> motor pos in mm + pos=np.array(param['grid']['pos']) # in um + pitch=np.array(param['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 return param diff --git a/swissmx.py b/swissmx.py index 038d91d..f420002 100755 --- a/swissmx.py +++ b/swissmx.py @@ -1430,30 +1430,10 @@ class WndSwissMx(QMainWindow, Ui_MainWindow): except AttributeError as e: _log.warning(f'no scan parameters for object->skipped:{go}') continue + trf=np.asmatrix(param['trf']) p=param['points'] - trf=np.asmatrix(param['trf']*1000) #fix shear/rotation mm->um - trf[:,0]*=-1 #X axis has inverted sign ! - if t==UsrGO.FixTargetFrame: - pos=np.array(param['grid']['pos']) #in um - pitch=np.array(param['grid']['pitch']) #in um - #TODO !!! - #input grid coordinate output um - trf2=np.asmatrix(np.identity(3)) - trf2[:, :2]=param['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))) - trf2=(trf3*trf2)[:,:2] - p2=(np.asmatrix((0,0,1))*trf2).A - p2=(np.hstack((param['points'],np.ones((p.shape[0],1))))*trf2).A - - m=np.hstack((p*pitch+pos,np.ones((p.shape[0],1)))) - p=(np.asmatrix(m)*trf).A - param['pts_trf']=p # transformed points - else: - m=np.hstack((p,np.ones((p.shape[0],1)))) - p=(np.asmatrix(m)*trf).A - param['pts_trf']=p # transformed points - + p=(np.hstack((p,np.ones((p.shape[0],1))))*trf).A + param['pts_trf']=p # transformed points in um motor coordinates param['num_pts']=p.shape[0] vb=self.vb grp=self._goTracked @@ -2017,7 +1997,20 @@ Author Thierry Zamofing (thierry.zamofing@psi.ch) #mft._cbType.addItems(["Fiducial", "FixTarget(12.5x12.5)", "FixTarget(23.0x23.0)", "FixTarget()", "Grid()", "SwissMX-path"]) #bm_pos_eu=self._goBeamMarker._pos_eu #bm_size_eu=self._goBeamMarker._size_eu - + try: + pLst=param.split(',') + pStr='{' + for p in pLst: + if not p: continue + m=re.match('\s*(.*?)\s*[=:]\s*(.*)\s*', p) + k, v=m.groups() + v=v.replace('(', '[').replace(')', ']') + pStr+=f'"{k}":{v}' + pStr+='}' + param=json.loads(pStr) # "ofs":[10, 5],"width":200,"fidScl":0.5,"fiducial":[[18,7],[25,16],[70, 20]] + except json.decoder.JSONDecodeError as e: + _log.error(f'{e}:{param}') + param=dict() if idx==0: #go=UsrGO.Fiducial(bm_pos+bm_sz/2-(20, 20), (40, 40),(fx,fy,bz)) l=.120 @@ -2028,36 +2021,36 @@ Author Thierry Zamofing (thierry.zamofing@psi.ch) l=np.linalg.norm(v) l=12.5 #ctr=bm_pos+bm_sz/2 - go=UsrGO.FixTargetFrame((fx-l/2,fy-l/2), (l, l), tpl='12.5x12.5') + go=UsrGO.FixTargetFrame((fx-l/2,fy-l/2), (l, l), tpl='12.5x12.5',**param) elif idx==2: v=geo.pos2pix((23, 0)) l=np.linalg.norm(v) l=23 - go=UsrGO.FixTargetFrame((fx-l/2,fy-l/2), (l, l), tpl='23.0x23.0') + go=UsrGO.FixTargetFrame((fx-l/2,fy-l/2), (l, l), tpl='23.0x23.0',**param) elif idx==3: w,h=(.120*12, .120*8) - go=UsrGO.FixTargetFrame((fx-w/2,fy-h/2), (w, h), tpl='test') + go=UsrGO.FixTargetFrame((fx-w/2,fy-h/2), (w, h), tpl='test',**param) elif idx==4: - w,h=(30, 22) - go=UsrGO.Grid((fx-w/2,fy-h/2), (w, h), (30, 22), .1) + w,h=size=param.pop('size',(30, 20)) + cnt=param.pop('cnt',(30, 22)) + fiducialSize=param.pop('fiducialSize',.1) + go=UsrGO.Grid((fx-w/2,fy-h/2), size, cnt, fiducialSize,**param) elif idx==5: - ofs=(.2, .2); width=10; fidScl=.02 - fiducial=((.1, .1), (.1, 2.7), (10.3, .1), (10.3, 2.7)) - if param: - p=json.loads('{'+param+'}') # "ofs":[10, 5],"width":200,"fidScl":0.5,"fiducial":[[18,7],[25,16],[70, 20]] - locals().update(p) + ofs=param.pop('ofs',(.2, .2)) + width=param.pop('width',10) + fidScl=param.pop('fidScl',.02) + fiducial=param.pop('fiducial',((.1, .1), (.1, 2.7), (10.3, .1), (10.3, 2.7))) fiducial=np.array(fiducial) gp=psi_device.shapepath.GenPath(); gp.swissmx_points(ofs=ofs, width=width, flipy=True) sz=gp.points.max(0)+np.array(ofs)*2 - go=UsrGO.Path((fx-sz[0]/2, fy-sz[1]/2), sz, gp.points, fiducial, fidScl) + go=UsrGO.Path((fx-sz[0]/2, fy-sz[1]/2), sz, gp.points, fiducial, fidScl,**param) elif idx==6: - ofs=(.2, .2); width=10; fidScl=.02 - fiducial=((.1, .1), (.1, 2.2), (10.3, .1), (10.3, 2.2)) - if param: - p=json.loads('{'+param+'}') # "ofs":[10, 5],"width":200,"fidScl":0.5,"fiducial":[[18,7],[25,16],[70, 20]] - locals().update(p) + ofs=param.pop('ofs',(.2, .2)) + width=param.pop('width',10) + fidScl=param.pop('fidScl',.02) + fiducial=param.pop('fiducial',((.1, .1), (.1, 2.2), (10.3, .1), (10.3, 2.2))) fiducial=np.array(fiducial) - gp=psi_device.shapepath.GenPath(); gp.swissfel_points(ofs=ofs, width=width,flipy=True) + gp=psi_device.shapepath.GenPath(); gp.swissfel_points(ofs=ofs, width=width,flipy=True,**param) sz=gp.points.max(0)+np.array(ofs)*2 go=UsrGO.Path((fx-sz[0]/2, fy-sz[1]/2), sz, gp.points, fiducial, fidScl) else: @@ -2187,19 +2180,20 @@ Author Thierry Zamofing (thierry.zamofing@psi.ch) #dlg.setAutoClose(True) #dlg.show() dlg.setLabelText("Setup Gather/Sync");dlg+=5 - sp.setup_gather(kwargs['num_pts']) + num_pts=kwargs['num_pts'] + code_gen=kwargs['code_gen'] + sp.setup_gather(num_pts) sp.setup_sync(verbose=sp.verbose&0x40, timeOfs=dt_misc['time_ofs'], timeCor=dt_misc['time_cor']) dlg.setLabelText("Download motion program");dlg+=5 - codeGen=kwargs['code_gen'] - if codeGen==0: + if code_gen==0: sp.setup_motion(fnPrg=fn+'.prg', mode=3, scale=1., dwell=10, points=kwargs['pts_trf']) - elif codeGen==1: - sp.setup_motion(fnPrg=fn+'.prg', mode=3, scale=1., dwell=10, points=kwargs['points']) - elif codeGen==2: - sp.setup_motion(fnPrg=fn+'.prg', mode=4, scale=1., dwell=10, grid=kwargs['grid']) + elif code_gen==1: + sp.setup_motion(fnPrg=fn+'.prg', mode=3, scale=1., dwell=10, points=kwargs['points'],trf=kwargs['trf']) + elif code_gen==2: + sp.setup_motion(fnPrg=fn+'.prg', mode=4, scale=1., dwell=10, grid=kwargs['grid'],trf=kwargs['trf']) try: p=geo._fitPlane - if codeGen==0: + if code_gen==0: # X has inverted sign ! # Z is in um -> therefore the offset must be multiplied with 1000 ! Z motor has opposite sign ! cz=f'{+p[0]:+.18g}X{-p[1]:+.18g}Y{-p[2]*1000:+.18g}' @@ -2209,17 +2203,16 @@ Author Thierry Zamofing (thierry.zamofing@psi.ch) cz='0' _log.warning('no plane fitting done. z does not move') - trf=kwargs['trf']*1000 # fix shear/rotation mm->um - trf[:, 0]*=-1 # X axis has inverted sign ! - if codeGen==0: + trf=kwargs['trf'] + if code_gen==0: fx='X';fy='Y' else: fx=f'{trf[0,0]:+.18g}X{trf[1,0]:+.18g}Y{trf[2,0]:+.18g}' fy=f'{trf[0,1]:+.18g}X{trf[1,1]:+.18g}Y{trf[2,1]:+.18g}' - print(f'pts_trf[0,:]={kwargs["pts_trf"][0, :]}') - print(f'points[0,:]={kwargs["points"][0, :]}') - print(f'trf=\n{trf}') + _log.debug(f'pts_trf[0,:]={kwargs["pts_trf"][0, :]}') + _log.debug((f'points[0,:]={kwargs["points"][0, :]}') + _log.debug((f'trf=\n{trf}') sp.setup_coord_trf(fx, fy, cz) # reset to shape path system @@ -2245,7 +2238,7 @@ Author Thierry Zamofing (thierry.zamofing@psi.ch) sp.run() # start motion program sp.wait_armed() # wait until motors are at first position #time.sleep(1.0) # wait armed does not wor yet ?!? - jf.acquire(sp.points.shape[0]) + jf.acquire(num_pts) sp.trigger(0.5) # send a start trigger (if needed) after given time if not dt._comm is None: dlg.setLabelText("run motion/acquisition")