Skip to content

Commit

Permalink
Added a prepare method to the area detector FlyerMixin() class.
Browse files Browse the repository at this point in the history
  • Loading branch information
canismarko committed Sep 23, 2024
1 parent a1e3aa1 commit 6189677
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
15 changes: 11 additions & 4 deletions src/haven/instrument/area_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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

Expand Down
23 changes: 20 additions & 3 deletions src/haven/tests/test_area_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -25,16 +26,32 @@ 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)
assert status.success
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]
Expand Down

0 comments on commit 6189677

Please sign in to comment.