-
Notifications
You must be signed in to change notification settings - Fork 4
Merlin ophyd-async integration #33
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
Open
Jennefer Maldonado (jennmald)
wants to merge
11
commits into
main
Choose a base branch
from
merlin-opyhd
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
35a82c2
merline ophyd class
jennmald 11a6559
write_path_template
jennmald af2c26f
fix root path
jennmald fe6878b
fix root path str
jennmald 7ebb8bd
merlin async
jennmald e3586f6
merlin trigger modes
jennmald 5ed2750
modified ophyd async class for merlin
jennmald 0796add
changes from Dan's review
jennmald fcabdce
pre commit
jennmald 1bada2b
fix trigger modes
jennmald 6be7beb
fix ADArmLogic
jennmald File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| """ | ||
| Ophyd Async implementation for the Merlin Detector | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from collections.abc import Sequence | ||
| from dataclasses import dataclass | ||
| from typing import Annotated as A | ||
|
|
||
| from ophyd_async.core import ( | ||
| DetectorTriggerLogic, | ||
| DetectorArmLogic, | ||
| PathProvider, | ||
| SignalDict, | ||
| SignalR, | ||
| SignalRW, | ||
| SubsetEnum, | ||
| soft_signal_rw, | ||
| ) | ||
| from ophyd_async.epics.adcore import ( | ||
| ADBaseDataType, | ||
| ADBaseIO, | ||
| ADWriterType, | ||
| AreaDetector, | ||
| NDPluginBaseIO, | ||
| prepare_exposures, | ||
| trigger_info_from_num_images, | ||
| ) | ||
| from ophyd_async.epics.core import PvSuffix | ||
|
|
||
| __all__ = [ | ||
| "MerlinDetector", | ||
| "MerlinDriverIO", | ||
| "MerlinTriggerLogic", | ||
| ] | ||
|
|
||
| _MIN_DEAD_TIME = 0.002 | ||
|
|
||
|
|
||
| class MerlinTriggerMode(SubsetEnum): | ||
| """Trigger modes for the Merlin detector""" | ||
|
|
||
| INTERNAL = "Internal" | ||
| TRIGGER_ENABLE = "Trigger Enable" | ||
| TRIGGER_START_RISING = "Trigger start rising" | ||
| TRIGGER_START_FALLING = "Trigger start falling" | ||
| TRIGGER_BOTH_RISING = "Trigger both rising " | ||
| SOFTWARE = "Software" | ||
|
|
||
|
|
||
| class MerlinDriverIO(ADBaseIO): | ||
| """Driver for merlin model:DU897_BV as deployed on p99. | ||
|
|
||
| This mirrors the interface provided by ADMerlin/db/merlin.template. | ||
| https://github.com/areaDetector/ADMerlin/blob/master/merlinApp/Db/merlin.template | ||
| """ | ||
|
|
||
| trigger_mode: A[SignalRW[MerlinTriggerMode], PvSuffix.rbv("TriggerMode")] | ||
|
|
||
| # Since ADMerlin doesn't set the data type readback correctly, but is always uint16, | ||
| # just turn it into a static soft signal | ||
| def __init__(self, prefix: str, name: str = ""): | ||
| super().__init__(prefix, name=name) | ||
| self.data_type = soft_signal_rw( | ||
| ADBaseDataType, ADBaseDataType.UINT16, name="data_type" | ||
| ) | ||
|
|
||
|
|
||
| # The deadtime of an Merlin controller varies depending on the exact model of camera. | ||
| # Ideally we would maximize performance by dynamically retrieving the deadtime at | ||
| # runtime. See https://github.com/bluesky/ophyd-async/issues/308 | ||
| @dataclass | ||
| class MerlinTriggerLogic(DetectorTriggerLogic): | ||
| """Trigger logic for MerlinDriverIO.""" | ||
|
|
||
| driver: MerlinDriverIO | ||
|
|
||
| def get_deadtime(self, config_values: SignalDict) -> float: # noqa: ARG002 | ||
| return _MIN_DEAD_TIME | ||
|
|
||
| async def prepare_internal(self, num: int, livetime: float, deadtime: float): | ||
| await self.driver.trigger_mode.set(MerlinTriggerMode.INTERNAL) | ||
| await prepare_exposures(self.driver, num, livetime, deadtime) | ||
|
|
||
| async def prepare_edge(self, num: int, livetime: float): | ||
| await self.driver.trigger_mode.set(MerlinTriggerMode.TRIGGER_START_RISING) | ||
| await prepare_exposures(self.driver, num, livetime) | ||
|
|
||
| async def default_trigger_info(self): | ||
| return await trigger_info_from_num_images(self.driver) | ||
|
|
||
|
|
||
| class MerlinDetector(AreaDetector[MerlinDriverIO]): | ||
| """Create an ADMerlin AreaDetector instance. | ||
|
|
||
| :param prefix: EPICS PV prefix for the detector | ||
| :param path_provider: Provider for file paths during acquisition | ||
| :param driver_suffix: Suffix for the driver PV, defaults to "cam1:" | ||
| :param writer_type: Type of file writer (HDF or TIFF) | ||
| :param writer_suffix: Suffix for the writer PV | ||
| :param plugins: Additional areaDetector plugins to include | ||
| :param config_sigs: Additional signals to include in configuration | ||
| :param name: Name for the detector device | ||
| """ | ||
|
|
||
| def __init__( | ||
| self, | ||
| prefix: str, | ||
| path_provider: PathProvider | None = None, | ||
| driver_suffix="cam1:", | ||
| writer_type: ADWriterType | None = ADWriterType.HDF, | ||
| writer_suffix: str | None = None, | ||
| plugins: dict[str, NDPluginBaseIO] | None = None, | ||
| config_sigs: Sequence[SignalR] = (), | ||
| name: str = "", | ||
| ) -> None: | ||
| driver = MerlinDriverIO(prefix + driver_suffix) | ||
| super().__init__( | ||
| prefix=prefix, | ||
| driver=driver, | ||
| arm_logic=DetectorArmLogic(driver), | ||
| trigger_logic=MerlinTriggerLogic(driver), | ||
| path_provider=path_provider, | ||
| writer_type=writer_type, | ||
| writer_suffix=writer_suffix, | ||
| plugins=plugins, | ||
| config_sigs=config_sigs, | ||
| name=name, | ||
| ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.