From 681b8f2953aedffe2ae26c0e9c893ea98e4a74e9 Mon Sep 17 00:00:00 2001 From: Thierry Zamofing Date: Thu, 29 Jun 2023 10:02:42 +0200 Subject: [PATCH] enhance simulation --- psi_device.py | 54 +++++++++++++++++++++++++++++---------------------- swissmx.py | 22 +++++++++++---------- 2 files changed, 43 insertions(+), 33 deletions(-) diff --git a/psi_device.py b/psi_device.py index f2c6f87..8b9f899 100644 --- a/psi_device.py +++ b/psi_device.py @@ -60,30 +60,30 @@ class Shutter: _log.info('shutter closed') class Deltatau: - def __init__(self): + def __init__(self,sim=False): app=QApplication.instance() cfg=app._cfg host=cfg.value(AppCfg.DT_HOST) - - hpp=host.split(':') - param={'host':hpp[0]} - if len(hpp)>1: - param['port']=int(hpp[1]) - if len(hpp)>2: - param['fast_gather_port']=int(hpp[2]) - _log.info(' -> ssh-tunneling PPComm({host}:{port} {host}:{fast_gather_port})'.format(**param)) - try: - self._comm=comm=PPComm(**param,timeout=2.0) - self._gather=gather=Gather(comm) - except (socket.timeout,socket.gaierror) as e: - _log.critical(f'can not connect to deltatau:"{host}" -> {e}') + if sim: self._comm=comm=None self._gather=gather=None - #return + else: + hpp=host.split(':') + param={'host':hpp[0]} + if len(hpp)>1: + param['port']=int(hpp[1]) + if len(hpp)>2: + param['fast_gather_port']=int(hpp[2]) + _log.info(' -> ssh-tunneling PPComm({host}:{port} {host}:{fast_gather_port})'.format(**param)) + try: + self._comm=comm=PPComm(**param,timeout=2.0) + self._gather=gather=Gather(comm) + except (socket.timeout,socket.gaierror) as e: + _log.critical(f'can not connect to deltatau:"{host}" -> {e}') self._shapepath=sp=shapepath.ShapePath(comm, gather, verbose=0xff, sync_mode=1, sync_flag=3) class Jungfrau: - def __init__(self): + def __init__(self,sim=False): #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 @@ -91,6 +91,9 @@ class Jungfrau: # --start_pulseid 15382163895 --stop_pulseid 15382163905 #rsync -vai gac-cristall@saresc-cons-03:/sf/jungfrau/applications/daq_client/daq_client.py . # setup slic parameters + if sim: + self._daq=None + return app=QApplication.instance() cfg=app._cfg detectors = [ cfg.value(AppCfg.DAQ_DET) ] @@ -103,13 +106,15 @@ class Jungfrau: default_detectors=detectors, default_channels=bs_channels, default_pvs=pv_channels, rate_multiplicator=1, append_user_tag_to_data_dir=True ) + self._pv_pulse_id=epics.PV('SAR-EXPMX-EVR0:RX-PULSEID') + self._pv_pulse_id.connect() except NameError as e: - _log.warning(f'Jungfrau not connected: {e}') - self._daq=None - self._pv_pulse_id=epics.PV('SAR-EXPMX-EVR0:RX-PULSEID') - self._pv_pulse_id.connect() + _log.critical(f'Jungfrau not connected: {e}') def acquire(self, n_pulses, wait=False): + if self._daq is None: + _log.info(f'simulated') + return app=QApplication.instance() cfg=app._cfg run=cfg.value(AppCfg.DAQ_RUN) @@ -118,14 +123,17 @@ class Jungfrau: except TypeError as e: _log.warning(f'failed to get _pulse_id_start: {e}') if self._daq is not None: - #n_pulses_run = n_pulses + run['padding'] - #self._daq.acquire(run['prefix'], n_pulses=min(n_pulses_run, 5000), n_repeat=ceil(n_pulses_run/5000), wait=False, cell_name=run['cell_name']) - self._daq.acquire(run['prefix'], n_pulses=n_pulses, wait=False) + n_pulses_run = n_pulses + run['padding'] + self._daq.acquire(run['prefix'], n_pulses=min(n_pulses_run, 5000), n_repeat=ceil(n_pulses_run/5000), wait=False, cell_name=run['cell_name']) + #self._daq.acquire(run['prefix'], n_pulses=n_pulses, wait=False) pass #run['id']+=1 cfg.setValue(AppCfg.DAQ_RUN,run) def gather_upload(self): + if self._daq is None: + _log.info(f'simulated') + return try: self._pulse_id_end=int(self._pv_pulse_id.value) except TypeError as e: diff --git a/swissmx.py b/swissmx.py index 551ba97..4f6a244 100755 --- a/swissmx.py +++ b/swissmx.py @@ -15,9 +15,10 @@ bitmask for simulation: 0x02: illumination 0x04: zoom 0x08: camera - 0x10: Deltatau motors + 0x10: Deltatau motors and motion code 0x20: SmarAct motors 0x40: shutter + 0x80: Jungfrau """ import logging @@ -1979,7 +1980,7 @@ Author Thierry Zamofing (thierry.zamofing@psi.ch) app=QApplication.instance() if calib: _log.info("received new pix2pos calibration") - QMessageBox.information(self,'Pixel to position calibration','''\ + QMessageBox.information(self,'Pixel to position calibration','''\ - for each zoom level: - choose a good fiducial mark - move the stage x/y at min. 3 different locations @@ -2217,11 +2218,11 @@ Author Thierry Zamofing (thierry.zamofing@psi.ch) try: dt=app._deltatau except AttributeError: - app._deltatau=dt=psi_device.Deltatau() + app._deltatau=dt=psi_device.Deltatau(app._args.sim&0x10!=0) try: jf=app._jungfrau except AttributeError: - app._jungfrau=jf=psi_device.Jungfrau() + app._jungfrau=jf=psi_device.Jungfrau(app._args.sim&0x80!=0) sp=dt._shapepath sp.verbose=dt_misc['verbose'] @@ -2285,10 +2286,11 @@ Author Thierry Zamofing (thierry.zamofing@psi.ch) sp.setup_coord_trf(fx, fy, cz) # reset to shape path system - try: - sp.comm.gpascii._cb_func=lambda i, sz:self.cb_progress(i, sz, dlg) - except AttributeError: - pass + comm=sp.comm + if comm is None: + _log.info('simulated') + else: + comm.gpascii._cb_func=lambda i, sz:self.cb_progress(i, sz, dlg) if dlg.wasCanceled(): return @@ -2300,9 +2302,9 @@ Author Thierry Zamofing (thierry.zamofing@psi.ch) jf.acquire(num_pts) sp.trigger(0.5) # send a start trigger (if needed) after given time if dt._comm is None: - dlg.setLabelText("run motion/acquisition") + dlg.setLabelText("run motion/acquisition (simulated)") dlg.setMaximum(num_pts) - for p in range(0,num_pts,int(num_pts/1000)): + for p in range(0,num_pts,int(num_pts/100)): #_log.info(f'progress {p}/{num_pts}') dlg.setValue(p) time.sleep(.1)