From 61896774956091a7e3a03836947191c1a6443e50 Mon Sep 17 00:00:00 2001 From: Mark Wolfman Date: Mon, 23 Sep 2024 16:49:02 -0500 Subject: [PATCH] Added a prepare method to the area detector FlyerMixin() class. --- src/haven/instrument/area_detector.py | 15 +++++++++++---- src/haven/tests/test_area_detector.py | 23 ++++++++++++++++++++--- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/haven/instrument/area_detector.py b/src/haven/instrument/area_detector.py index cb5e88f6..04a339ef 100644 --- a/src/haven/instrument/area_detector.py +++ b/src/haven/instrument/area_detector.py @@ -42,6 +42,7 @@ from ophyd.areadetector.plugins import TIFFPlugin_V31, TIFFPlugin_V34 from ophyd.flyers import FlyerInterface from ophyd.status import Status, StatusBase, SubscriptionStatus +from ophyd_async.core import DetectorTrigger, TriggerInfo from .. import exceptions from .._iconfig import load_config @@ -116,13 +117,22 @@ def save_fly_datum(self, *, value, timestamp, obj, **kwargs): datum = fly_event(timestamp=timestamp, value=value) self._fly_data.setdefault(obj, []).append(datum) - def kickoff(self) -> StatusBase: + def prepare(self, value: TriggerInfo) -> StatusBase: + assert ( + value.trigger == DetectorTrigger.internal + ), f"Trigger mode {value.trigger} not supported." + status = self.cam.image_mode.set(ImageMode.CONTINUOUS) + status &= self.cam.num_images.set(value.number) + status &= self.cam.trigger_mode.set(self.flyscan_trigger_mode) # Set up subscriptions for capturing data self._fly_data = {} for walk in self.walk_fly_signals(): sig = walk.item # Run subs the first time to make sure all signals are present sig.subscribe(self.save_fly_datum, run=True) + return status + + def kickoff(self) -> StatusBase: # Set up the status for when the detector is ready to fly def check_acquiring(*, old_value, value, **kwargs): @@ -134,9 +144,6 @@ def check_acquiring(*, old_value, value, **kwargs): status = SubscriptionStatus(self.cam.detector_state, check_acquiring) # Set the right parameters self._original_vals.setdefault(self.cam.image_mode, self.cam.image_mode.get()) - status &= self.cam.image_mode.set(ImageMode.CONTINUOUS) - status &= self.cam.trigger_mode.set(self.flyscan_trigger_mode) - status &= self.cam.num_images.set(2**14) status &= self.cam.acquire.set(AcquireState.ACQUIRE) return status diff --git a/src/haven/tests/test_area_detector.py b/src/haven/tests/test_area_detector.py index a7358be0..28629a1a 100644 --- a/src/haven/tests/test_area_detector.py +++ b/src/haven/tests/test_area_detector.py @@ -5,6 +5,7 @@ from ophyd import ADComponent as ADCpt from ophyd.areadetector.cam import AreaDetectorCam from ophyd.sim import instantiate_fake_device +from ophyd_async.core import DetectorTrigger, TriggerInfo from haven.instrument.area_detector import ( DetectorBase, @@ -25,8 +26,25 @@ def detector(sim_registry): return det -def test_flyscan_kickoff(detector): - detector.flyer_num_points.set(10) +@pytest.fixture() +def trigger_info(): + return TriggerInfo( + number=5, trigger=DetectorTrigger.internal, deadtime=0.2, livetime=1.3 + ) + + +def test_flyscan_prepare(detector, trigger_info): + status = detector.prepare(trigger_info).wait(timeout=3) + # Check that the device was properly configured for fly-scanning + assert detector._fly_data == {} + # Check that signals were set up properly + assert detector.cam.image_mode.get() == 2 + assert detector.cam.num_images.get() == 5 + assert detector.cam.trigger_mode.get() == 0 + + +def test_flyscan_kickoff(detector, trigger_info): + detector.prepare(trigger_info).wait(timeout=1) status = detector.kickoff() detector.cam.detector_state.sim_put(DetectorState.ACQUIRE) status.wait(timeout=3) @@ -34,7 +52,6 @@ def test_flyscan_kickoff(detector): assert status.done # Check that the device was properly configured for fly-scanning assert detector.cam.acquire.get() == 1 - assert detector._fly_data == {} # Check that timestamps get recorded when new data are available detector.cam.array_counter.sim_put(1) event = detector._fly_data[detector.cam.array_counter]