From e41a3ed7ed148b1585e4ea3d664b7c483a4e59ca Mon Sep 17 00:00:00 2001 From: Thierry Zamofing Date: Tue, 12 Dec 2023 14:17:07 +0100 Subject: [PATCH] fixing coordinate transformation --- app_config.py | 13 ++++++++----- pyqtUsrObj.py | 10 +++++++--- swissmx.py | 28 ++++++++++++++-------------- 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/app_config.py b/app_config.py index 9e8239b..b2f406e 100644 --- a/app_config.py +++ b/app_config.py @@ -95,7 +95,7 @@ class AppCfg(QSettings): dflt=[] if AppCfg.GBL_MISC not in keys: - dflt.append((AppCfg.GBL_MISC,{'img_trace_len':4})) + dflt.append((AppCfg.GBL_MISC,{'live_on_collect':False,'img_trace_len':8})) if AppCfg.GBL_DEV_PREFIX not in keys: dflt.append((AppCfg.GBL_DEV_PREFIX, ['SAR-EXPMX','SARES30-ESBMX'])) if AppCfg.GEO_BEAM_SZ not in keys: @@ -111,14 +111,14 @@ class AppCfg(QSettings): if AppCfg.GEO_CAM_TRF not in keys: dflt.append((AppCfg.GEO_CAM_TRF, np.array(((-1, 0, 0), (0, -1, 0), (0, 0, 1))) )) if AppCfg.GEO_PIX2POS not in keys: - # rough data for binning=1,1 + # rough data z=np.array((1.0, 200.0, 400.0, 600.0, 800.0, 1000.0)) t1=np.array(([1, 0.0000], [0.0000, -1])).reshape(1, -1) - t2=np.array((0.001214,0.000821,0.000495,0.000299,0.000182,0.000108)).reshape(-1, 1) + #t2=np.array((0.001214,0.000821,0.000495,0.000299,0.000182,0.000108)).reshape(-1, 1) # for binning=1,1 + t2=np.array((0.002413,0.001632,0.000994,0.000594,0.000363,0.000205)).reshape(-1, 1) # for binning=2,2 trf=(t1*t2).reshape((-1, 2, 2)) lut_pix2pos=(z, trf) dflt.append((AppCfg.GEO_PIX2POS, lut_pix2pos)) - if AppCfg.DT_HOST not in keys: dflt.append((AppCfg.DT_HOST, 'SAR-CPPM-EXPMX1')) if AppCfg.DT_MISC not in keys: @@ -176,6 +176,8 @@ class AppCfg(QSettings): dflt.append((AppCfg.DFT_POS_GONIO, {'pos_mount':(0.,0.,0.,0.),'pos_align':(0.,0.,0.,0.)}))#default positions if AppCfg.DFT_POS_BKLGT not in keys: dflt.append((AppCfg.DFT_POS_BKLGT, {'pos_in': -30000.0, 'pos_out': 1000.0, 'pos_diode': -30000.0}))#default positions + if AppCfg.DFT_POS_PST not in keys: + dflt.append((AppCfg.DFT_POS_PST, {'x_in_us': 0.0, 'y_in_us': 0.0, 'x_in_ds': 0.0, 'y_in_ds': 0.0, 'x_out_delta': 0.0, 'y_out_delta': 0.0, 'z_in': 0.0, 'z_out': 0.0}))#default positions for k,v in dflt: _log.warning(f'{k} not defined. use default') @@ -327,7 +329,8 @@ verbose bits: {'name':'smaract motors', 'value':gbl_dev_prefix[1], 'type':'str'}, ]}, {'name':AppCfg.GBL_MISC, 'title':'miscellaneous', 'type':'group', 'children':[ - {'name':'img_trace_len', 'value':gbl_misc['img_trace_len'], 'type':'int', 'tip':tip_sync_flag}, + {'name':'live_on_collect', 'value':gbl_misc['live_on_collect'], 'type':'bool','tip':'live view update during collection (may crash if on)'}, + {'name':'img_trace_len', 'value':gbl_misc['img_trace_len'], 'type':'int'}, #{'name':'verbose', 'value':gbl_misc['verbose'], 'type':'int', 'tip':tip_verbose}, ]}, # {'name':AppCfg.GEO_CAM_TRF, 'value':cfg.value(AppCfg.GEO_CAM_TRF), 'type':'str'}, diff --git a/pyqtUsrObj.py b/pyqtUsrObj.py index 952d6d8..83ee2de 100644 --- a/pyqtUsrObj.py +++ b/pyqtUsrObj.py @@ -575,22 +575,26 @@ class FixTargetFrame(UsrROI): param={'grid':grid, 'points':pts, 'code_gen': self.code_gen} # TODO: simplify !!! - t=self.transform() + t=self.transform() #obj_info(t) 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,:]=(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))) + 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 + # 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) + #np.array((161,0,1))*trf # grid 161,0 (top right) + #np.array((161,161,1))*trf # grid 161,161 (bottom right) return param diff --git a/swissmx.py b/swissmx.py index bceb178..8458b56 100755 --- a/swissmx.py +++ b/swissmx.py @@ -887,10 +887,7 @@ class WndSwissMx(QMainWindow, Ui_MainWindow): app=QApplication.instance() bl=app._backlight # any move of backlight requires post sample tube out - try: - self.assert_post_tube_position(pos="out") - except: - self.move_post_tube("out") + self.move_post_tube("out") bl.move(pos) def get_tweaker(self, rec, mtype=0, **kwargs): @@ -995,7 +992,7 @@ class WndSwissMx(QMainWindow, Ui_MainWindow): else: _log.warning(f'{e},{w},{pv}') sim=app._args.sim - assert(sim&0x10,'assuming simulated motors') + assert sim&0x10,'assuming simulated motors' def build_group_faststage(self, toolbox): @@ -2290,9 +2287,10 @@ Author Thierry Zamofing (thierry.zamofing@psi.ch) sp.meta['sync_flag']=dt_misc['sync_flag'] #pv-monitor-func: stop monitors - pv_mon_lst=app._pv_mon_lst - for pv in pv_mon_lst: - pv.auto_monitor=False + if not cfg.value(AppCfg.GBL_MISC)['live_on_collect']: + pv_mon_lst=app._pv_mon_lst + for pv in pv_mon_lst: + pv.auto_monitor=False with pg.ProgressDialog('Progress', 0, 100) as dlg: dlg.setWindowModality(Qt.WindowModal) @@ -2320,7 +2318,7 @@ Author Thierry Zamofing (thierry.zamofing@psi.ch) # 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}' - t=p*np.array((1,-1,-1000)) + t=p*np.array((-1,-1,-1000)) cz=f'{t[0]:+.18g}X{t[1]:+.18g}Y{t[2]:+.18g}' else: trf=kwargs['trf'] # grid-coord -> motor-um @@ -2329,7 +2327,7 @@ Author Thierry Zamofing (thierry.zamofing@psi.ch) trf2=np.asmatrix(np.identity(3)) trf2[:, :2]=trf #p1=(0,0,1)*trf2 # =matrix([[-2376.8, 1376.8, 1. ]]) um - trf3=np.matrix( ((p[0],0,0),(-p[1],0,0),(-1000*p[2],0,1)) ) + trf3=np.matrix( ((-p[0],0,0),(-p[1],0,0),(-1000*p[2],0,1)) ) #(0, 0, 1)*trf2*trf3 t=(trf2*trf3)[:,0].A.ravel() cz=f'{t[0]:+.18g}X{t[1]:+.18g}Y{t[2]:+.18g}' @@ -2358,8 +2356,9 @@ Author Thierry Zamofing (thierry.zamofing@psi.ch) if dlg.wasCanceled(): # pv-monitor-func: start monitors - for pv in pv_mon_lst: - pv.auto_monitor=True + if not cfg.value(AppCfg.GBL_MISC)['live_on_collect']: + for pv in pv_mon_lst: + pv.auto_monitor=True return dlg.setLabelText("Homing and get ready");dlg+=5 sp.homing() # homing if needed @@ -2401,8 +2400,9 @@ Author Thierry Zamofing (thierry.zamofing@psi.ch) shutter.close() # pv-monitor-func: start monitors - for pv in pv_mon_lst: - pv.auto_monitor=True + if not cfg.value(AppCfg.GBL_MISC)['live_on_collect']: + for pv in pv_mon_lst: + pv.auto_monitor=True def esc_run_steps(self, steps, title, esc_state): self._esc_state ="busy"