fixing coordinate transformation

This commit is contained in:
2023-12-12 14:17:07 +01:00
parent 9e63ff0718
commit e41a3ed7ed
3 changed files with 29 additions and 22 deletions

View File

@@ -95,7 +95,7 @@ class AppCfg(QSettings):
dflt=[] dflt=[]
if AppCfg.GBL_MISC not in keys: 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: if AppCfg.GBL_DEV_PREFIX not in keys:
dflt.append((AppCfg.GBL_DEV_PREFIX, ['SAR-EXPMX','SARES30-ESBMX'])) dflt.append((AppCfg.GBL_DEV_PREFIX, ['SAR-EXPMX','SARES30-ESBMX']))
if AppCfg.GEO_BEAM_SZ not in keys: if AppCfg.GEO_BEAM_SZ not in keys:
@@ -111,14 +111,14 @@ class AppCfg(QSettings):
if AppCfg.GEO_CAM_TRF not in keys: 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))) )) dflt.append((AppCfg.GEO_CAM_TRF, np.array(((-1, 0, 0), (0, -1, 0), (0, 0, 1))) ))
if AppCfg.GEO_PIX2POS not in keys: 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)) 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) 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)) trf=(t1*t2).reshape((-1, 2, 2))
lut_pix2pos=(z, trf) lut_pix2pos=(z, trf)
dflt.append((AppCfg.GEO_PIX2POS, lut_pix2pos)) dflt.append((AppCfg.GEO_PIX2POS, lut_pix2pos))
if AppCfg.DT_HOST not in keys: if AppCfg.DT_HOST not in keys:
dflt.append((AppCfg.DT_HOST, 'SAR-CPPM-EXPMX1')) dflt.append((AppCfg.DT_HOST, 'SAR-CPPM-EXPMX1'))
if AppCfg.DT_MISC not in keys: 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 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: 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 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: for k,v in dflt:
_log.warning(f'{k} not defined. use default') _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':'smaract motors', 'value':gbl_dev_prefix[1], 'type':'str'},
]}, ]},
{'name':AppCfg.GBL_MISC, 'title':'miscellaneous', 'type':'group', 'children':[ {'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':'verbose', 'value':gbl_misc['verbose'], 'type':'int', 'tip':tip_verbose},
]}, ]},
# {'name':AppCfg.GEO_CAM_TRF, 'value':cfg.value(AppCfg.GEO_CAM_TRF), 'type':'str'}, # {'name':AppCfg.GEO_CAM_TRF, 'value':cfg.value(AppCfg.GEO_CAM_TRF), 'type':'str'},

View File

@@ -575,22 +575,26 @@ class FixTargetFrame(UsrROI):
param={'grid':grid, 'points':pts, 'code_gen': self.code_gen} param={'grid':grid, 'points':pts, 'code_gen': self.code_gen}
# TODO: simplify !!! # TODO: simplify !!!
t=self.transform() t=self.transform() #obj_info(t)
p=np.array(self.pos()) p=np.array(self.pos())
s=self.size()/self._dscr['size'] s=self.size()/self._dscr['size']
trf=np.array(((t.m11(),t.m12()),(t.m21(),t.m22()),(0,0))) trf=np.array(((t.m11(),t.m12()),(t.m21(),t.m22()),(0,0)))
trf[2,:]=p # shift origin 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[: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 pos=np.array(param['grid']['pos']) # in um
pitch=np.array(param['grid']['pitch']) # in um pitch=np.array(param['grid']['pitch']) # in um
trf2=np.asmatrix(np.identity(3)) trf2=np.asmatrix(np.identity(3))
trf2[:, :2]=trf 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))) trf3=np.asmatrix(((pitch[0], 0, 0), (0, pitch[1], 0), (pos[0], pos[1], 1)))
trf=(trf3*trf2)[:, :2] trf=(trf3*trf2)[:, :2]
param['trf']=trf 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 return param

View File

@@ -887,10 +887,7 @@ class WndSwissMx(QMainWindow, Ui_MainWindow):
app=QApplication.instance() app=QApplication.instance()
bl=app._backlight bl=app._backlight
# any move of backlight requires post sample tube out # any move of backlight requires post sample tube out
try: self.move_post_tube("out")
self.assert_post_tube_position(pos="out")
except:
self.move_post_tube("out")
bl.move(pos) bl.move(pos)
def get_tweaker(self, rec, mtype=0, **kwargs): def get_tweaker(self, rec, mtype=0, **kwargs):
@@ -995,7 +992,7 @@ class WndSwissMx(QMainWindow, Ui_MainWindow):
else: else:
_log.warning(f'{e},{w},{pv}') _log.warning(f'{e},{w},{pv}')
sim=app._args.sim sim=app._args.sim
assert(sim&0x10,'assuming simulated motors') assert sim&0x10,'assuming simulated motors'
def build_group_faststage(self, toolbox): 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'] sp.meta['sync_flag']=dt_misc['sync_flag']
#pv-monitor-func: stop monitors #pv-monitor-func: stop monitors
pv_mon_lst=app._pv_mon_lst if not cfg.value(AppCfg.GBL_MISC)['live_on_collect']:
for pv in pv_mon_lst: pv_mon_lst=app._pv_mon_lst
pv.auto_monitor=False for pv in pv_mon_lst:
pv.auto_monitor=False
with pg.ProgressDialog('Progress', 0, 100) as dlg: with pg.ProgressDialog('Progress', 0, 100) as dlg:
dlg.setWindowModality(Qt.WindowModal) dlg.setWindowModality(Qt.WindowModal)
@@ -2320,7 +2318,7 @@ Author Thierry Zamofing (thierry.zamofing@psi.ch)
# X has inverted sign ! # X has inverted sign !
# Z is in um -> therefore the offset must be multiplied with 1000 ! Z motor has opposite 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}' #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}' cz=f'{t[0]:+.18g}X{t[1]:+.18g}Y{t[2]:+.18g}'
else: else:
trf=kwargs['trf'] # grid-coord -> motor-um 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=np.asmatrix(np.identity(3))
trf2[:, :2]=trf trf2[:, :2]=trf
#p1=(0,0,1)*trf2 # =matrix([[-2376.8, 1376.8, 1. ]]) um #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 #(0, 0, 1)*trf2*trf3
t=(trf2*trf3)[:,0].A.ravel() t=(trf2*trf3)[:,0].A.ravel()
cz=f'{t[0]:+.18g}X{t[1]:+.18g}Y{t[2]:+.18g}' 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(): if dlg.wasCanceled():
# pv-monitor-func: start monitors # pv-monitor-func: start monitors
for pv in pv_mon_lst: if not cfg.value(AppCfg.GBL_MISC)['live_on_collect']:
pv.auto_monitor=True for pv in pv_mon_lst:
pv.auto_monitor=True
return return
dlg.setLabelText("Homing and get ready");dlg+=5 dlg.setLabelText("Homing and get ready");dlg+=5
sp.homing() # homing if needed sp.homing() # homing if needed
@@ -2401,8 +2400,9 @@ Author Thierry Zamofing (thierry.zamofing@psi.ch)
shutter.close() shutter.close()
# pv-monitor-func: start monitors # pv-monitor-func: start monitors
for pv in pv_mon_lst: if not cfg.value(AppCfg.GBL_MISC)['live_on_collect']:
pv.auto_monitor=True for pv in pv_mon_lst:
pv.auto_monitor=True
def esc_run_steps(self, steps, title, esc_state): def esc_run_steps(self, steps, title, esc_state):
self._esc_state ="busy" self._esc_state ="busy"