From df53197d01834c86d3e8d4b110d39c63175e5077 Mon Sep 17 00:00:00 2001 From: Thierry Zamofing Date: Wed, 24 Aug 2022 08:53:54 +0200 Subject: [PATCH] wip --- Readme.md | 41 +++++++++++++++++++++++++++ camera.py | 4 ++- deltatau.py | 10 +++++-- pyqtUsrObj.py | 44 +++++++++++++++++++++++++---- swissmx.py | 77 +++++++++++++++++++++++++++++++++++++++++---------- zoom.py | 1 - 6 files changed, 153 insertions(+), 24 deletions(-) diff --git a/Readme.md b/Readme.md index ca8f8ba..2558926 100644 --- a/Readme.md +++ b/Readme.md @@ -76,6 +76,47 @@ pyqtgraph.examples.run() ``` +Deploy stuff (22.8.22) quick and dirty +---------------------- +``` +DST=/sf/cristallina/applications/mx/zamofing_t/ +# /sf/cristallina/applications/mx + +ssh saresc-cons-02 mkdir /tmp/zamofing_t/ +rsync -vai ~/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX saresc-cons-03:$DST +rsync -vai ~/Documents/prj/SwissFEL/PBTools saresc-cons-03:$DST + +cd /tmp/zamofing_t/ESB_MX/python/SwissMX/ +/opt/gfa/python-3.7/latest/bin/python swissmx.py + +/opt/gfa/python-3.8/latest/bin/pip install qtawesome --user +/opt/gfa/python-3.8/latest/bin/python swissmx.py + +cd $DST +/opt/gfa/python-3.8/latest/bin/python -m pdb swissmx.py + +``` + + + + +``` + + +cd /tmp/; git clone https://github.com/malcolmreynolds/transformations.git +cd /tmp/transformations.git +-> modify __init__.py -> .transformation (add dot) +setup.py install --user + + +cd /tmp/; git clone https://github.com/spyder-ide/qtawesome.git +cd /tmp/qtawesome + +#To have epics channels we must be connected to the ESC network +EPICS_CA_ADDR_LIST='129.129.244.255 sf-saresc-cagw.psi.ch:5062 sf-saresc-cagw.psi.ch:5066' +cd /home/zamofing_t/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/python/oldRepos/app/src +python swissmx.py +``` diff --git a/camera.py b/camera.py index 4ac339a..09e46dc 100755 --- a/camera.py +++ b/camera.py @@ -249,7 +249,8 @@ class epics_cam(object): imgSeq[:,0:hr,0:wr]+=np.random.randint(0,100,(t,hr,wr),dtype=np.uint16) elif mode==1: import glob,PIL.Image - path='/home/zamofing_t/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/python/SwissMX/simCamImg/*.png' + #path='/home/zamofing_t/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/python/SwissMX/simCamImg/*.png' + path='simCamImg/*.png' _log.info('generate simulation images:{}...'.format(path)) glb=glob.glob(path) img = PIL.Image.open(glb[0]) @@ -382,6 +383,7 @@ if __name__ == "__main__": (0,1,0,0,0), (0,0,0,0,0),),pic.dtype) pic[0:6,0:5]=f*pic.max() + _log.debug('avg {}'.format(pic.sum())) if args.ui==1: img.setImage(pic) else: diff --git a/deltatau.py b/deltatau.py index 7bbece0..6c97ee9 100644 --- a/deltatau.py +++ b/deltatau.py @@ -1,6 +1,12 @@ -import sys,os -sys.path.insert(0, os.path.expanduser('~/Documents/prj/SwissFEL/PBTools/')) +import sys,os,socket sys.path.insert(0, os.path.expanduser('..')) +hostname=socket.gethostname() +if hostname=='ganymede': + sys.path.insert(0, os.path.expanduser('~/Documents/prj/SwissFEL/PBTools/')) +else: + #sys.path.insert(0, os.path.expanduser('/tmp/zamofing_t/PBTools/')) + sys.path.insert(0, os.path.expanduser('/sf/cristallina/applications/mx/zamofing_t/PBTools/')) + import logging _log=logging.getLogger(__name__) diff --git a/pyqtUsrObj.py b/pyqtUsrObj.py index d15534e..c468014 100644 --- a/pyqtUsrObj.py +++ b/pyqtUsrObj.py @@ -149,8 +149,25 @@ class Grid(pg.ROI): self.addScaleHandle([0, 0], [1, 1]) self.addScaleRotateHandle([1, 0], [0, 0]) - def get_points(self): - return np.array(((1,2),(3,4),(5,6)),dtype=np.float) + def get_points(self,mode=0x2): + 'generates points of the roi for scanning with deltatau' + #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 + for i in range(1,cnt[1],2): + xx[i]=xx[i][::-1] + if mode&0x02: # modify y scaning forward backward each line + 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.float).transpose()*pitch + #pts+=pos + return pts def paint(self, p, *args): #pg.ROI.paint(self, p, *args) @@ -210,6 +227,7 @@ class Path(pg.ROI): for pt in path: qPth.append(QPointF(*pt)) + self.addFreeHandle([.1, .1]) self.addScaleHandle([1, 1], [0, 0]) self.addScaleHandle([0, 0], [1, 1]) self.addScaleRotateHandle([1, 0], [0, 0]) @@ -259,16 +277,30 @@ class FixTargetFrame(pg.ROI): 'count':(8, 6) } }, - '125x125':{ + '12.5x12.5':{ 'size':(12500+120*4, 12500+120*4), 'fiducial':{ 'type':0, 'pos':((240, 240), (240+12500, 240), (240, 240+12500), (240+12500, 240+12500)) }, 'grid':{ - 'pos':(1050, 1050), + # 240+(12500-78*120)/2=1810 + 'pos':(1810, 1810), 'pitch':(120, 120), - 'count':(90, 90) + 'count':(78, 78) #(84,84)... but sone covered + } + }, + '23.0x23.0':{ + 'size':(23000+120*4, 23000+120*4), + 'fiducial':{ + 'type':0, + 'pos':((240, 240), (240+23000, 240), (240, 240+23000), (240+23000, 240+23000)) + }, + 'grid':{ + # 240+(23000-162*120)/2+60?=2020+60? + 'pos':(2080, 2080), + 'pitch':(120, 120), + 'count':(162, 162) #(172,172)... but sone covered } } } @@ -489,7 +521,7 @@ if __name__=='__main__': vi=FixTargetFrame((100,300),(100,100),tpl='test') vb.addItem(vi) - vi=FixTargetFrame((400,-200),(400,400),tpl='125x125') + vi=FixTargetFrame((400,-200),(400,400),tpl='12.5x12.5') vb.addItem(vi) childTree(vb) diff --git a/swissmx.py b/swissmx.py index 51e2264..3ae63df 100755 --- a/swissmx.py +++ b/swissmx.py @@ -342,8 +342,12 @@ class Main(QMainWindow, Ui_MainWindow): #--- grid --- try: self._goGrid=grid=pg.GridItem(pen=(0,255,0),textPen=(0,255,0)) #green grid and labels - except: - self._goGrid=grid=pg.GridItem() + except NameError: + _log.debug('workaround for typo in pyqtgraph:0.11.0') + from PyQt5.QtGui import QPen,QColor + self._goGrid=grid=pg.GridItem() # green grid and labels + grid.opts['pen']=QPen(QColor(0, 255, 0)) + grid.opts['textPen']=QPen(QColor(0, 255, 0)) tr.reset() grid.setTransform(tr) # assign transform vb.addItem(grid) @@ -361,7 +365,8 @@ class Main(QMainWindow, Ui_MainWindow): #--- testing scan grid --- self.track_objects() # first call is needed to initialize the structure self._goTracked - go=UsrGO.Grid((120, -100), (200, 150), (30, 22), 2) + #go=UsrGO.Grid((120, -100), (200, 150), (30, 22), 2) + go=UsrGO.Grid((120, -100), (1000, 500), (10, 5), 2) go.setTransform(tr) # assign transform vb.addItem(go) self._goTracked['objLst'].append(go) @@ -2124,16 +2129,37 @@ class Main(QMainWindow, Ui_MainWindow): ystep = self._sb_grid_y_step.value() xoffset = self._sb_grid_x_offset.value() yoffset = self._sb_grid_y_offset.value() - grid = CstROI.Grid( x_step=xstep, y_step=ystep, x_offset=xoffset, y_offset=yoffset, gonio_xy=(gx, gy), grid_index=grid_index, parent=self,) - self._grids.append(grid) - grid.calculate_gonio_xy() - grid.sigRemoveRequested.connect(lambda g=grid: self.remove_grid(g)) - self.vb.addItem(grid) + + app=QApplication.instance() + geo=app._geometry + oc=geo._opt_ctr + if xstep==0: + go=UsrGO.Grid((120, -100), (200, 150), (30, 22), 2) + elif xstep==1: + go=UsrGO.FixTargetFrame((120, -100), (200, 150), tpl='test') + elif xstep==2: + v=geo.pos2pix((12.5, 0)) + l=np.linalg.norm(v) + go=UsrGO.FixTargetFrame(-oc, (l,l), tpl='12.5x12.5') + elif xstep==3: + v=geo.pos2pix((23, 0)) + l=np.linalg.norm(v) + go=UsrGO.FixTargetFrame(-oc, (l,l), tpl='23.0x23.0') + else: + _log.error('set xstep 0..2 for tests') + self.vb.addItem(go) + self._goTracked['objLst'].append(go) + + #grid = CstROI.Grid( x_step=xstep, y_step=ystep, x_offset=xoffset, y_offset=yoffset, gonio_xy=(gx, gy), grid_index=grid_index, parent=self,) + #self.vb.addItem(grid) + #grid.calculate_gonio_xy() + #grid.sigRemoveRequested.connect(lambda g=grid: self.remove_grid(g)) def daq_grid_remove_all(self): - for grid in self._grids: - grid.sigRemoveRequested.emit(grid) # ugly hack - self._grids = [] + vb=self.vb + for go in self._goTracked['objLst']: + vb.removeItem(go) + self._goTracked['objLst']=[] def grids_pause_stage_tracking(self): for grid in self._grids: @@ -2231,7 +2257,8 @@ class Main(QMainWindow, Ui_MainWindow): app._jungfrau=jf=detector.Jungfrau() sp=dt._shapepath - sp.gen_grid_points(w=15, h=15, pitch=3, rnd=0, ofs=(0, +2000)); + sp.gen_grid_points(w=15, h=15, pitch=3, rnd=0, ofs=(0, +2000)) + #sp.gen_grid_points(w=5, h=10, pitch=1, rnd=0, ofs=(0, 0));sp.sort_points(False, 10);sp.points sp.sort_points(False, 15); sp.meta['pt2pt_time']=10 sp.setup_gather() @@ -2754,6 +2781,8 @@ class Main(QMainWindow, Ui_MainWindow): self.re_connect_collect_button() def execute_collection(self): + app=QApplication.instance() + geo=app._geometry task = self.active_task() self._is_aborted = False method = self._tabs_daq_methods.currentWidget().accessibleName() @@ -2766,8 +2795,28 @@ class Main(QMainWindow, Ui_MainWindow): ) self._inspect = self._grid_inspect_area self._inspect.setPlainText("") - for fixTrg in self._goTracked['objLst']: - points=fixTrg.get_points() + + geo=app._geometry + zoom=app._zoom.get_val() + fast_x=self.tweakers["fast_x"]; + fast_y=self.tweakers["fast_y"] + fx=fast_x.get_val() + fy=fast_y.get_val() + opt_ctr=geo._opt_ctr + for go in self._goTracked['objLst']: + points=go.get_points() #points in coordinate system of ROI + # names consists of abrevations + # part 0: po=position sz=size dt=delta + # part 1: px=pixel eu=engineering units (e.g. mm) + po_px=go.pos() + sz_px=go.size() + tr=go.transform() # TODO: this is not yet used + UsrGO.obj_info(tr) + dt_px=-opt_ctr-po_px + dt_eu=geo.pix2pos(dt_px)+(fx,fy) + for i in range(points.shape[0]): + points[i,:]=dt_eu+geo.pix2pos(points[i,:])#*tr + method="grid" params=None #grid._grid_dimensions # params = ([grid._grid_dimensions[0]], [grid._grid_dimensions[1]]) # FIXME something wrong here< diff --git a/zoom.py b/zoom.py index 084c7f4..6015021 100755 --- a/zoom.py +++ b/zoom.py @@ -12,7 +12,6 @@ import json import logging _log=logging.getLogger(__name__) import os -import qtawesome from PyQt5 import QtWidgets, uic import PyQt5.QtWidgets as qtw from PyQt5.QtCore import pyqtSignal