From 010fefd11d89f1d35886ca43658ebb182b94948d Mon Sep 17 00:00:00 2001 From: gac-x07mb Date: Fri, 20 Dec 2024 11:40:26 +0100 Subject: [PATCH] add check for xmap to trigger --- phoenix_bec/devices/phoenix_trigger.py | 39 ++++++++++++++++++- phoenix_bec/devices/phoenix_xmap.py | 39 +++++++++++++------ .../test_phoenix_trigger.py | 7 ++++ .../Code_to_test_devices/test_xmap.py | 4 +- .../local_scripts/TEST_scanning/Linescan_1.py | 2 + 5 files changed, 76 insertions(+), 15 deletions(-) create mode 100644 phoenix_bec/local_scripts/Code_to_test_devices/test_phoenix_trigger.py diff --git a/phoenix_bec/devices/phoenix_trigger.py b/phoenix_bec/devices/phoenix_trigger.py index d0a6c39..8344f4c 100644 --- a/phoenix_bec/devices/phoenix_trigger.py +++ b/phoenix_bec/devices/phoenix_trigger.py @@ -89,7 +89,10 @@ class PhoenixTriggerSetup(CustomDetectorMixin): # TODO Test the proper check for the falcon state # Check first that falcon is set to acquiring - falcon = self.parent.device_manager.devices.get("falcon_nohdf5", None) # get device + + # check for falcon + + falcon = self.parent.device_manager.devices.get("falcon", None) # get device timeout = 1 if falcon is not None: # TODO Check that falcon.state.get() == 1 is the correct check. @@ -102,6 +105,20 @@ class PhoenixTriggerSetup(CustomDetectorMixin): f"Device {self.parent.name} is not ready to take trigger, timeout due to waiting for Falcon to get ready. Timeout after {timeout}s" ) + + xmap = self.parent.device_manager.devices.get("xmap", None) # get device + timeout = 1 + if xmap is not None: + # TODO Check that falcon.state.get() == 1 is the correct check. + # --> When is the falcon acquiring, this assumes 1? + # self.wait_for_signals is defined in PSI_detector_base.CustomDetectorMixin + # + + if not self.wait_for_signals([(xmap.state.get, 1)], timeout=timeout): + raise PhoenixTriggerError( + f"Device {self.parent.name} is not ready to take trigger, timeout due to waiting for xmap to get ready. Timeout after {timeout}s" + ) + if self.parent.scaninfo.scan_type == "step": time.sleep(0.2) self.parent.smpl.put(1) @@ -232,6 +249,15 @@ class PhoenixTrigger(PSIDetectorBase): EpicsSignalRO, "SMPL-DONE", kind=Kind.config ) # show trigger is done, consider using string=True + + ph_start_csmpl = start_csmpl + ph_intr_count = intr_count + ph_total_cycles = total_cycles + ph_smpl = smpl + ph_smpl_done = smpl_done + + # create subset in name spacs + def help(self): """ Help function for phoenix_trigger @@ -268,9 +294,18 @@ class PhoenixTrigger(PSIDetectorBase): dev.PH_TTL.total_cycles.set(1) For further general help try the attributes - .describe() .describe_confguration() .summary() + .describe() considered as stable dict + .describe_confguration() + .summary() ._config ._info + Important channel are collected with prefix ph, to ease finding of the channels + + for example + + dev.PH_TTl.ph_total_cycles = dev.PH_TTl.total_cycles + + .. etc """ print("Name of device is", self.name) diff --git a/phoenix_bec/devices/phoenix_xmap.py b/phoenix_bec/devices/phoenix_xmap.py index dfd3dd6..32de042 100644 --- a/phoenix_bec/devices/phoenix_xmap.py +++ b/phoenix_bec/devices/phoenix_xmap.py @@ -94,12 +94,14 @@ class XMAPSetup(CustomDetectorMixin): def update_readout_time(self) -> None: """Set readout time for Eiger9M detector""" + """ readout_time = ( self.parent.scaninfo.readout_time if hasattr(self.parent.scaninfo, "readout_time") else self.parent.MIN_READOUT ) self.parent.readout_time = max(readout_time, self.parent.MIN_READOUT) + """ def initialize_detector(self) -> None: """Initialize XMAP detector""" @@ -141,9 +143,12 @@ class XMAPSetup(CustomDetectorMixin): # self.parent.nd_array_mode.put(1) def on_stage(self) -> None: - """Prepare detector and backend for acquisition""" + """ + Prepare detector and backend for acquisition + """ # staging for XMAP as used in FDA + self.parent.stop_all.set(1) time.sleep(0.05) self.parent.collect_mode.set(0) @@ -159,7 +164,9 @@ class XMAPSetup(CustomDetectorMixin): # self.arm_acquisition() time.sleep(0.05) def prepare_detector(self) -> None: - """Prepare detector for acquisition""" + """Prepare detector for acquisition.. originally called from on stage """ + pass + """ self.set_trigger( mapping_mode=MappingSource.MAPPING, trigger_source=TriggerSource.GATE, ignore_gate=0 ) @@ -167,9 +174,10 @@ class XMAPSetup(CustomDetectorMixin): self.parent.pixels_per_run.put( int(self.parent.scaninfo.num_points * self.parent.scaninfo.frames_per_trigger) ) + """ def prepare_data_backend(self) -> None: - """Prepare data backend for acquisition""" + """Prepare data backend for acquisition.. originally called from on_stage """ pass """ -------------------------------------------------------------- self.parent.filepath.set( @@ -190,7 +198,9 @@ class XMAPSetup(CustomDetectorMixin): """ def arm_acquisition(self) -> None: - """Arm detector for acquisition""" + """Arm detector for acquisition called fron on stage """ + pass + """ self.parent.start_all.put(1) signal_conditions = [ ( @@ -207,6 +217,7 @@ class XMAPSetup(CustomDetectorMixin): raise XMAPTimeoutError( f"Failed to arm the acquisition. Detector state {signal_conditions[0][0]}" ) + """ def on_unstage(self) -> None: """Unstage detector and backend""" @@ -222,11 +233,11 @@ class XMAPSetup(CustomDetectorMixin): def on_stop(self) -> None: """Stop detector and backend""" self.stop_detector() + # self.stop_detector_backend() def stop_detector(self) -> None: - """Stops detector""" - + """Stops detector called from on _sttop""" self.parent.stop_all.put(1) self.parent.erase_all.put(1) @@ -244,11 +255,11 @@ class XMAPSetup(CustomDetectorMixin): def stop_detector_backend(self) -> None: """Stop the detector backend""" - # self.parent.hdf5.capture.put(0) - w = 0 + self.parent.hdf5.capture.put(0) + def finished(self, timeout: int = 5) -> None: - """Check if scan finished succesfully""" + """Check if scan finished succesfully called fon on _complete """ with self._lock: total_frames = int( self.parent.scaninfo.num_points * self.parent.scaninfo.frames_per_trigger @@ -269,26 +280,30 @@ class XMAPSetup(CustomDetectorMixin): f" {total_frames}" ) self.stop_detector() + self.stop_detector_backend() def set_trigger( self, mapping_mode: MappingSource, trigger_source: TriggerSource, ignore_gate: int = 0 ) -> None: """ - Set triggering mode for detector + Set triggering mode for finisheddetector Args: mapping_mode (MappingSource): Mapping mode for the detector trigger_source (TriggerSource): Trigger source for the detector, pixel_advance_signal ignore_gate (int): Ignore gate from TTL signal; defaults to 0 + """ + pass + """ mapping = int(mapping_mode) trigger = trigger_source self.parent.collect_mode.put(mapping) self.parent.pixel_advance_mode.put(trigger) self.parent.ignore_gate.put(ignore_gate) - + """ class XMAPPhoenix(PSIDetectorBase, xMAP): """ @@ -336,3 +351,5 @@ class XMAPPhoenix(PSIDetectorBase, xMAP): ph_preset_live = xMAP.preset_live_time ph_elapsed_real = xMAP.elapsed_real ph_elapsed_live = xMAP.elapsed_live + + diff --git a/phoenix_bec/local_scripts/Code_to_test_devices/test_phoenix_trigger.py b/phoenix_bec/local_scripts/Code_to_test_devices/test_phoenix_trigger.py new file mode 100644 index 0000000..7a96243 --- /dev/null +++ b/phoenix_bec/local_scripts/Code_to_test_devices/test_phoenix_trigger.py @@ -0,0 +1,7 @@ +import time +from phoenix_bec.scripts.phoenix import PhoenixBL + +from ophyd import Component as Cpt +import phoenix_bec.devices.phoenix_trigger as pt + +trig = pt.PhoenixTrigger(name="phoenixTrigger", prefix="X07MB-OP2:") diff --git a/phoenix_bec/local_scripts/Code_to_test_devices/test_xmap.py b/phoenix_bec/local_scripts/Code_to_test_devices/test_xmap.py index a566dca..dcce1b8 100644 --- a/phoenix_bec/local_scripts/Code_to_test_devices/test_xmap.py +++ b/phoenix_bec/local_scripts/Code_to_test_devices/test_xmap.py @@ -2,7 +2,7 @@ # creates newly -ff = 0 +ff = 0W falcon = 0 from ophyd import Component as Cpt @@ -12,7 +12,7 @@ xmap = ff.XMAPPhoenix(name="xmap", prefix="X07MB-XMAP:") # xmap = ff.FalconPhoenix(name="falcon_hdf5", prefix="X07MB-XMAP:") # make a 'get to read all epics channels # there will be an error message, if device contains a channel whcih does not exist -w = xmap.read() +#w = xmap.read() # phoenix_bec / local_scripts / Code_to_test_devices / test_falcon.py diff --git a/phoenix_bec/local_scripts/TEST_scanning/Linescan_1.py b/phoenix_bec/local_scripts/TEST_scanning/Linescan_1.py index 043b8bc..a2659ab 100644 --- a/phoenix_bec/local_scripts/TEST_scanning/Linescan_1.py +++ b/phoenix_bec/local_scripts/TEST_scanning/Linescan_1.py @@ -34,6 +34,7 @@ import sys # create PHOENIX base configuration phoenix.create_base_config() +phoenix.add_xmap() dev.MA1_ScanX.enabled = True print("---------------------------------") @@ -47,6 +48,7 @@ ti = tt.time_ns() phoenix.run_shell("sh monitor.sh > monitor.out & ") dev.PP2_VO5.enabled = True dev.MA1_ScanX.enabled = True +#dev.xmap.enabled = True """ s1 = scans.line_scan(