-
Notifications
You must be signed in to change notification settings - Fork 40
Move from ADOdin to FastCS-Odin #868
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
Draft
shihab-dls
wants to merge
2
commits into
main
Choose a base branch
from
add_fastcs_odin
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.
Draft
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -1 +1,3 @@ | ||
| __all__ = [] | ||
| from ._odin_io import OdinHdfIO, OdinWriter, OdinWriting | ||
|
|
||
| __all__ = ["OdinHdfIO", "OdinWriter", "OdinWriting"] |
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,103 @@ | ||
| import asyncio | ||
| from collections.abc import AsyncGenerator, AsyncIterator | ||
|
|
||
| from bluesky.protocols import StreamAsset | ||
| from event_model import DataKey | ||
|
|
||
| from ophyd_async.core import ( | ||
| DetectorWriter, | ||
| Device, | ||
| FilenameProvider, | ||
| PathProvider, | ||
| SignalR, | ||
| SignalRW, | ||
| StrictEnum, | ||
| observe_value, | ||
| set_and_wait_for_value, | ||
| ) | ||
| from ophyd_async.fastcs.core import fastcs_connector | ||
|
|
||
|
|
||
| class OdinWriting(StrictEnum): | ||
| ON = "ON" | ||
| OFF = "OFF" | ||
|
|
||
|
|
||
| class OdinHdfIO(Device): | ||
| config_hdf_write: SignalRW[OdinWriting] | ||
| frames_written: SignalR[int] | ||
| frames: SignalRW[int] | ||
| data_dims_0: SignalRW[int] | ||
| data_dims_1: SignalRW[int] | ||
| data_chunks_0: SignalRW[int] | ||
| data_chunks_1: SignalRW[int] | ||
| data_chunks_2: SignalRW[int] | ||
| file_path: SignalRW[str] | ||
| file_prefix: SignalRW[str] | ||
| data_datatype: SignalRW[str] | ||
|
|
||
| def __init__(self, uri: str, name: str = ""): | ||
| super().__init__(name=name, connector=fastcs_connector(self, uri)) | ||
|
|
||
|
|
||
| class OdinWriter(DetectorWriter): | ||
| def __init__( | ||
| self, | ||
| path_provider: PathProvider, | ||
| odin_driver: OdinHdfIO, | ||
| ) -> None: | ||
| self._drv = odin_driver | ||
| self._path_provider = path_provider | ||
| super().__init__() | ||
|
|
||
| async def open(self, name: str, exposures_per_event: int = 1) -> dict[str, DataKey]: | ||
| info = self._path_provider(device_name=name) | ||
| self._exposures_per_event = exposures_per_event | ||
|
|
||
| await asyncio.gather( | ||
| self._drv.file_path.set(str(info.directory_path)), | ||
| self._drv.file_prefix.set(info.filename), | ||
| self._drv.data_datatype.set( | ||
| "UInt16" | ||
| ), # TODO: Get from eiger https://github.com/bluesky/ophyd-async/issues/529 | ||
| self._drv.frames.set(0), | ||
| ) | ||
|
|
||
| await self._drv.config_hdf_write.set(OdinWriting.ON) | ||
|
|
||
| return await self._describe() | ||
|
|
||
| async def _describe(self) -> dict[str, DataKey]: | ||
| data_shape = await asyncio.gather( | ||
| self._drv.data_dims_0.get_value(), | ||
| self._drv.data_dims_1.get_value(), | ||
| ) | ||
|
|
||
| return { | ||
| "data": DataKey( | ||
| source=self._drv.file_prefix.source, | ||
| shape=list(data_shape), | ||
| dtype="array", | ||
| # TODO: Use correct type based on eiger https://github.com/bluesky/ophyd-async/issues/529 | ||
| dtype_numpy="<u2", | ||
| external="STREAM:", | ||
| ) | ||
| } | ||
|
|
||
| async def observe_indices_written( | ||
| self, timeout: float | ||
| ) -> AsyncGenerator[int, None]: | ||
| async for num_captured in observe_value(self._drv.frames_written, timeout): | ||
| yield num_captured | ||
|
|
||
| async def get_indices_written(self) -> int: | ||
| return await self._drv.frames_written.get_value() | ||
|
|
||
| def collect_stream_docs( | ||
| self, name: str, indices_written: int | ||
| ) -> AsyncIterator[StreamAsset]: | ||
| # TODO: Correctly return stream https://github.com/bluesky/ophyd-async/issues/530 | ||
| raise NotImplementedError() | ||
|
|
||
| async def close(self) -> None: | ||
| await set_and_wait_for_value(self._drv.config_hdf_write, OdinWriting.OFF) | ||
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
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.