From 33ce6c99f34e54b34ae20137a6750513401ce27d Mon Sep 17 00:00:00 2001 From: Thierry Zamofing Date: Fri, 16 Sep 2022 17:04:04 +0200 Subject: [PATCH] various stuff update fiducial z when moved autofocus param camera settings --- ModuleFixTarget.py | 3 ++ Readme.md | 83 ++++++++++++++++++++++++++++++++++++++++++++-- app_config.py | 4 ++- camera.py | 14 ++++---- geometry.py | 2 +- swissmx.py | 12 +++++-- 6 files changed, 104 insertions(+), 14 deletions(-) diff --git a/ModuleFixTarget.py b/ModuleFixTarget.py index 18dfcdf..961827f 100644 --- a/ModuleFixTarget.py +++ b/ModuleFixTarget.py @@ -301,6 +301,7 @@ class WndFixTarget(QWidget): else: raise(IOError('unsupported file type')) + self._tree.setData(data) try: wnd=app._mainWnd @@ -311,6 +312,8 @@ class WndFixTarget(QWidget): grp=wnd._goTracked for go in data: grp.addItem(go) + if type(go)==UsrGO.Fiducial: + go.sigRegionChangeFinished.connect(wnd.cb_fiducial_update_z) data=grp.childItems() self._tree.setData(data) #wnd._goTracked['objLst']=self._data diff --git a/Readme.md b/Readme.md index 60f4f3c..4b240cc 100644 --- a/Readme.md +++ b/Readme.md @@ -82,22 +82,95 @@ 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 --delete ~/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX saresc-cons-03:$DST -rsync -vai --delete ~/Documents/prj/SwissFEL/PBTools saresc-cons-03:$DST +ssh saresc-cons-03 mkdir /tmp/zamofing_t/ +# add '--delete' if needed +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 /sf/cristallina/applications/mx/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/pip install opencv-python /opt/gfa/python-3.8/latest/bin/python swissmx.py cd $DST /opt/gfa/python-3.8/latest/bin/python -m pdb swissmx.py +rsync -vai saresc-cons-03:/tmp/image*.png ~/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/python/SwissMX/scratch/ + +/home/zamofing_t/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/python/SwissMX/scratch/autofocus2 +``` + +16.9.22 remote Deltatau test: +----------------------------- +``` +(s.a. /home/zamofing_t/Documents/prj/SwissFEL/PBTools/pbtools/gather/PBGatherPlot.py + +PPMAC=SAR-CPPM-EXPMX1 +rsync -va ~/Documents/prj/SwissFEL/PBTools/pbtools/gather/gather_server root@$PPMAC:/tmp/ + +ssh root@$PPMAC +LD_LIBRARY_PATH=/opt/ppmac/libppmac/ /tmp/gather_server +ssh -L 10001:localhost:22 root@$PPMAC 'uname -a' +ssh -L 10002:localhost:2332 root@$PPMAC 'uname -a' +Deltatau host in config: +localhost:10001:10002 (instead SAR-CPPM-EXPMX1) + ``` +14.9.22 external code: +---------------------- +``` + +ssh gac-cristall@saresc-cons-03 +pw: ValToira_2021 +cd Documents/swissmx_cristallina/scripts/ + +Jungfrau stuff: +https://docs.google.com/document/d/1892j2eMsoFmufg-gdXKcSbOLcTDxLHULiNw-iZWAIVc/edit +'Beam synchronous DAQ with run_control' + +Check: +~/Documents/swissmx_cristallina/scripts/Chip_align.py +sys.path.insert(0, os.path.expanduser("/photonics/home/gac-cristall/Documents/swissmx_cristallina/slic/")) +from slic.core.acquisition import SFAcquisition + + +# setup slic parameters +detectors = [ { "name" : "JF17T16V01", + "adc_to_energy" : True, + "compression" : True, + "factor" : 11.33, + "geometry" : True, + "double_pixel_action" : "mask", + "remove_raw_files" : False + } ] #["JF17T16V01"] +bs_channels = [ # have timing signitures + "SARES30-LSCP1-CRISTA1:CH0:1", +# "SARES30-CAMS156-SMX-OAV:FPICTURE" +] +epics_channels = [ # no time signitures +] + +daq = SFAcquisition( + "cristallina", "p20516", + default_detectors=detectors, default_channels=bs_channels, default_pvs=epics_channels, + rate_multiplicator=1, append_user_tag_to_data_dir=True +) + + +if acquire == "True": + daq.acquire( run_name, n_pulses=n_pulses, wait=False) + + + + +Beam synchronous DAQ with with daq_control (command line) +Python script: +> python /sf/jungfrau/applications/daq_client/daq_client.py -h +> python /sf/jungfrau/applications/daq_client/daq_client.py -p p19739 -t no_beam_test -c /sf/cristallina/config/channel_lists/channel_list_bs -e /sf/cristallina/config/channel_lists/channel_list_ca -f /sf/cristallina/config/jungfrau/jf_1d5M.json --start_pulseid 15382163895 --stop_pulseid 15382163905 ``` @@ -174,6 +247,10 @@ SARES30-CAMS156-SMX-OAV:HEIGHT 2048 caqtdm camsf caqtdm -macro 'NAME=SARES30-CAMS156-SMX-OAV,CAMNAME=SARES30-CAMS156-SMX-OAV' /sf/controls/config/qt/Camera/CameraMiniView_RF.ui caqtdm -macro 'NAME=SARES30-CAMS156-SMX-OAV,CAMNAME=SARES30-CAMS156-SMX-OAV' /sf/controls/config/qt/Camera/CameraExpert_RF.ui +caqtdm -macro'P=SAR-EXPMX' ESB_MX_exp.ui + + + 03 last file: /sf/controls/config/qt/Camera/CameraMiniView_RF.ui, macro: NAME=SARES30-CAMS156-SMX-OAV,CAMNAME=SARES30-CAMS156-SMX-OAV diff --git a/app_config.py b/app_config.py index 2036939..33b04c6 100644 --- a/app_config.py +++ b/app_config.py @@ -187,7 +187,7 @@ class AppCfg(QSettings): if key==AppCfg.DT_MISC: val={'show_plots': True, 'vel_scl': 1.0, 'pt2pt_time': 10.0,'sync_mode':1,'sync_flag':3,'verbose':0xff} elif key==AppCfg.GBL_MISC: - val={'img_trace_len':4} + val={'img_trace_len':4,'af_range':1,'af_steps':10} else: val={} elif key in (AppCfg.GEO_BEAM_SZ,AppCfg.GEO_BEAM_POS,): @@ -277,6 +277,8 @@ verbose bits: ]}, {'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':'af_range', 'value':gbl_misc['af_range'], 'type':'float', 'limits':(0 ,3 ),'step':0.05,'suffix':'mm','decimals':3,'tip':'autofocus range (-rng/2 mm..+rng/2 mm..'}, + {'name':'af_steps', 'value':gbl_misc['af_steps'], 'type':'int', 'limits':(0 ,50),'tip':'numbers of measurements in the range'}, #{'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/camera.py b/camera.py index fa2b9a3..e4b3e3c 100755 --- a/camera.py +++ b/camera.py @@ -197,10 +197,10 @@ class epics_cam(object): elif k=='roi': pv_rxs=self.getPv('REGIONX_START');pv_rxe=self.getPv('REGIONX_END') pv_rys=self.getPv('REGIONY_START');pv_rye=self.getPv('REGIONY_END') - pv_rxs.put(v[0], wait=False) - pv_rxe.put(v[0]+v[2], wait=False) - pv_rys.put(v[1], wait=False) - pv_rye.put(v[1]+v[3], wait=False) + #pv_rxs.put(v[0], wait=False) + #pv_rxe.put(v[0]+v[2], wait=False) + #pv_rys.put(v[1], wait=False) + #pv_rye.put(v[1]+v[3], wait=False) param.append((pv_rxs,v[0])) param.append((pv_rxe,v[0]+v[2])) param.append((pv_rys,v[1])) @@ -240,17 +240,17 @@ class epics_cam(object): def update_params(self, *args): """update parameters on camera""" pv_cam=self.getPv('CAMERA') - pv_cam.put(CameraStatus.IDLE, wait=True) + pv_cs = self.getPv('CAMERASTATUS') + pv_cs.put(CameraStatus.IDLE, wait=True) for pv, val in args: if not pv.connected: _log.info('force connect {}'.format(pv)) pv.force_connect() #force to connect pv _log.debug("updating {} = {}".format(pv.pvname, val)) pv.put(val, wait=True) - pv_cs = self.getPv('CAMERASTATUS') #pv_set_param=self.getPv("SET_PARAM") #pv_set_param.put(1, wait=True) - pv_cam.put(CameraStatus.RUNNING, wait=True) + pv_cs.put(CameraStatus.RUNNING, wait=True) self.update_size() @staticmethod diff --git a/geometry.py b/geometry.py index 317d4b0..0872f97 100755 --- a/geometry.py +++ b/geometry.py @@ -312,7 +312,7 @@ class geometry: mx=mtr.argmax() _log.debug(f'best focus at idx:{mx}= pos:{posLst[mx]} = metric:{mtr[mx]:.6g}') - if mx>0 and mx 1 and mx+2<=len(posLst): #fit parabola and interpolate: # y=ax2+bx+c, at positions x=-1, 0, 1, y'= 2a+b == 0 (top of parabola) # calc a,b,c: diff --git a/swissmx.py b/swissmx.py index 4724058..59670fc 100755 --- a/swissmx.py +++ b/swissmx.py @@ -1596,10 +1596,14 @@ Author Thierry Zamofing (thierry.zamofing@psi.ch) def cb_autofocus(self): app=QApplication.instance() + cfg=app._cfg geo=app._geometry #geo.autofocus(app._camera, self.tweakers['base_z'],rng=(-1, 1), n=30,saveImg=True) - n=10 - rng=(-1, 1) + + misc=cfg.value(AppCfg.GBL_MISC) + af_range=misc['af_range'] + n=misc['af_steps'] + rng=(-af_range/2, af_range/2) with pg.ProgressDialog('Progress', 0, n) as dlg: geo.autofocus(app._camera, self.tweakers['base_z'],rng, n,dlg) @@ -1947,6 +1951,9 @@ Author Thierry Zamofing (thierry.zamofing@psi.ch) go.setPos(geo._opt_ctr-oc_sz/2) go.blockSignals(False) # allow to call cb_marker_moved + def cb_fiducial_update_z(self,obj,*vargs): + obj._z=self.tweakers["base_z"].get_rbv() + def module_fix_target_add_obj(self,*args,**kwargs): mft=self._moduleFixTarget fx=self.tweakers["fast_x"].get_rbv() @@ -1969,6 +1976,7 @@ Author Thierry Zamofing (thierry.zamofing@psi.ch) #go=UsrGO.Fiducial(bm_pos+bm_sz/2-(20, 20), (40, 40),(fx,fy,bz)) l=.120 go=UsrGO.Fiducial((fx-l/2,fy-l/2), (l, l),bz) + go.sigRegionChangeFinished.connect(self.cb_fiducial_update_z) elif idx==1: v=geo.pos2pix((12.5, 0)) l=np.linalg.norm(v)