Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Eiger API #111

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
3 changes: 3 additions & 0 deletions src/tickit_devices/eiger/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging

import pydantic.v1.dataclasses
from tickit.adapters.io import HttpIo, ZeroMqPushIo
from tickit.core.adapter import AdapterContainer
Expand All @@ -18,6 +20,7 @@ class Eiger(ComponentConfig):
zmq_port: int = 9999

def __call__(self) -> Component: # noqa: D102
logging.getLogger("aiohttp.access").setLevel(logging.WARNING)
device = EigerDevice()
adapters = [
AdapterContainer(
Expand Down
2 changes: 1 addition & 1 deletion src/tickit_devices/eiger/data/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class ImageCharacteristicsHeader(BaseModel):
class ImageConfigHeader(BaseModel):
"""Sent before a detector image blob.

Describes the metrics on the image acquisition.
Describes the metrics on the image acquisition. Time values are ints given in ns.
"""

real_time: int
Expand Down
33 changes: 22 additions & 11 deletions src/tickit_devices/eiger/eiger.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,23 @@ def __init__(
self.monitor_callback_period = SimTime(int(1e9))

self._num_frames_left: int = 0
self._num_triggers_left: int = 0
self._total_frames: int = 0
self._data_queue: Queue = Queue()
self._series_id: int = 0

self._finished_aquisition: asyncio.Event | None = None
self._finished_trigger: asyncio.Event | None = None

@property
def finished_aquisition(self) -> asyncio.Event:
def finished_trigger(self) -> asyncio.Event:
"""Event that is set when an acqusition series is complete.

Property ensures the event is created.
"""
if self._finished_aquisition is None:
self._finished_aquisition = asyncio.Event()
if self._finished_trigger is None:
self._finished_trigger = asyncio.Event()

return self._finished_aquisition
return self._finished_trigger

async def initialize(self) -> None:
"""Initialize the detector.
Expand All @@ -104,6 +105,7 @@ async def arm(self) -> None:
self._series_id += 1
self.stream.begin_series(self.settings, self._series_id)
self._num_frames_left = self.settings.nimages
self._num_triggers_left = self.settings.ntrigger
self._set_state(State.READY)

async def disarm(self) -> None:
Expand Down Expand Up @@ -169,11 +171,16 @@ def update(self, time: SimTime, inputs: Inputs) -> DeviceUpdate[Outputs]:
self.Outputs(), SimTime(time + int(self.settings.frame_time * 1e9))
)
else:
self.finished_aquisition.set()
self.finished_trigger.set()

if self._num_triggers_left > 0:
self._set_state(State.READY)
self._num_frames_left = self.settings.nimages
else:
LOGGER.debug("Ending Series...")
self._set_state(State.IDLE)
self.stream.end_series(self._series_id)

LOGGER.debug("Ending Series...")
self._set_state(State.IDLE)
self.stream.end_series(self._series_id)
if inputs.get("trigger", False):
self._begin_acqusition_mode()
# Should have another update immediately to begin acquisition
Expand All @@ -182,12 +189,15 @@ def update(self, time: SimTime, inputs: Inputs) -> DeviceUpdate[Outputs]:
return DeviceUpdate(self.Outputs(), None)

def _begin_acqusition_mode(self) -> None:
self._num_triggers_left -= 1
self._set_state(State.ACQUIRE)
LOGGER.info("Now in acquiring mode")
self.finished_aquisition.clear()
self.finished_trigger.clear()

def _acquire_frame(self) -> None:
frame_id = self.settings.nimages - self._num_frames_left
frame_id = (
(self.settings.ntrigger - self._num_triggers_left) * self.settings.nimages
) - self._num_frames_left
LOGGER.debug(f"Frame id {frame_id}")

shape = (
Expand All @@ -198,6 +208,7 @@ def _acquire_frame(self) -> None:
self.stream.insert_image(image, self._series_id)
self._num_frames_left -= 1
LOGGER.debug(f"Frames left: {self._num_frames_left}")
LOGGER.debug(f"Triggers left: {self._num_triggers_left}")

def get_state(self) -> State:
"""Get the eiger's current state
Expand Down
Loading
Loading