-
Notifications
You must be signed in to change notification settings - Fork 4
Merlin Integration #6
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
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
9f2e67e
WIP Merlin integration
jennmald 57a4ae9
trigger mixins
jennmald 7e97dae
fix modalbase
jennmald 9757246
change name
jennmald c09d4a2
CDIModalSettings
jennmald 2ee5e77
fix file writing templates
jennmald fd4940c
fix dtype
jennmald d5859fe
fix hdf5 warning
jennmald 8f5f964
hdf5 with file store
jennmald 3332a9a
debugging
jennmald b1ba21a
fix data type
jennmald 3cc2f5c
clean up data types
jennmald 0180fef
fix precommit
jennmald 1b99844
Check for mutliple master files for each datum
thopkins32 e9bd7f4
pre-commit
thopkins32 916a1df
fix ruff
jennmald 9d762ec
more fixes for mypy
jennmald f978692
ignore ophyd errors
jennmald 887a4a1
add new line:
jennmald df2a8c1
finished trigger mixins
jennmald bca24de
passing mypy:
jennmald 6c78c41
satisfy ruff
jennmald 2a5eaf6
blank space
jennmald ffefd6f
fix eiger merge conflicts
jennmald 7d57e6b
fix utils
jennmald c40433e
fix pyright
jennmald b4f097f
eof
jennmald 9b0f72d
remove env
jennmald a6299a3
add suggestions for makedirs and fix a merge conflict error
jennmald 24323a1
fix pre-commit
jennmald 714f535
Update README.md
jennmald 7c25a27
fix prettier
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,5 @@ | ||
| { | ||
| "typeCheckingMode": "basic", | ||
| "reportMissingTypeStubs": false, | ||
| "reportUntypedBaseClass": false | ||
| } | ||
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,191 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
| from collections import OrderedDict | ||
|
|
||
| from ophyd import ( | ||
| AreaDetector, | ||
| CamBase, | ||
| Device, | ||
| EpicsSignal, | ||
| HDF5Plugin, | ||
| ProcessPlugin, | ||
| ROIPlugin, | ||
| StatsPlugin, | ||
| TIFFPlugin, | ||
| TransformPlugin, | ||
| ) | ||
| from ophyd import Component as Cpt | ||
| from ophyd.areadetector import EpicsSignalWithRBV | ||
| from ophyd.areadetector.base import ADComponent | ||
| from ophyd.areadetector.filestore_mixins import FileStorePluginBase, FileStoreTIFF | ||
| from ophyd.utils.paths import makedirs | ||
|
|
||
| from .trigger_mixins import CDIModalTrigger, FileStoreBulkReadable | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class MerlinTiffPlugin(TIFFPlugin, FileStoreBulkReadable, FileStoreTIFF, Device): | ||
| def mode_external(self) -> None: | ||
| total_points = self.parent.mode_settings.total_points.get() # type: ignore[union-attr] | ||
| self.stage_sigs[self.num_capture] = total_points | ||
|
|
||
| def get_frames_per_point(self) -> object: | ||
| mode = self.parent.mode_settings.mode.get() # type: ignore[union-attr] | ||
| if mode == "external": | ||
| return 1 | ||
| return self.parent.cam.num_images.get() # type: ignore[union-attr] | ||
|
|
||
| def describe(self) -> object: | ||
| ret = super().describe() | ||
| key = self.parent._image_name # type: ignore[union-attr] | ||
| ret[key].setdefault("dtype_str", "<u2") # type: ignore[attr-defined] | ||
| return ret | ||
|
|
||
|
|
||
| class MerlinDetectorCam(CamBase): | ||
| acquire = ADComponent(EpicsSignal, "Acquire") | ||
| quad_merlin_mode = ADComponent(EpicsSignalWithRBV, "QuadMerlinMode") | ||
|
|
||
|
|
||
| class MerlinDetector(AreaDetector): | ||
| cam = Cpt( | ||
| MerlinDetectorCam, | ||
| "cam1:", | ||
| read_attrs=[], | ||
| configuration_attrs=[ | ||
| "image_mode", | ||
| "trigger_mode", | ||
| "acquire_time", | ||
| "acquire_period", | ||
| ], | ||
| ) | ||
|
|
||
|
|
||
| class MerlinFileStoreHDF5(FileStorePluginBase, FileStoreBulkReadable): | ||
| _spec = "TPX_HDF5" | ||
| filestore_spec = _spec | ||
|
|
||
| def __init__(self, *args, **kwargs) -> None: | ||
| super().__init__(*args, **kwargs) | ||
| self.stage_sigs.update( | ||
| [ | ||
| (self.file_template, "%s%s_%6.6d.h5"), # type: ignore[attr-defined] | ||
| (self.file_write_mode, "Stream"), # type: ignore[attr-defined] | ||
| (self.compression, "zlib"), # type: ignore[attr-defined] | ||
| (self.capture, 1), # type: ignore[attr-defined] | ||
| ] | ||
| ) | ||
|
|
||
| def stage(self) -> object: | ||
| logger.info("Staging") | ||
| staged = super().stage() | ||
| logger.info("Staging step 2") | ||
| res_kwargs = {"frame_per_point": 1} | ||
| logger.info("res_kwargs = {frame_per_point: %s}", res_kwargs["frame_per_point"]) | ||
|
|
||
| logger.debug("Inserting resource with filename %s", self._fn) | ||
| logger.info("Inserting resource with filename %s", self._fn) | ||
| self._generate_resource(res_kwargs) | ||
| logger.info("generating resources") | ||
| logger.info("Staged") | ||
| return staged | ||
|
|
||
| def describe(self) -> OrderedDict[str, dict]: | ||
| ret = super().describe() | ||
| key = self.parent._image_name # type: ignore[union-attr] | ||
| ret[key].setdefault("dtype_str", "<u2") # type: ignore[attr-defined] | ||
| return ret # type: ignore[return-value] | ||
|
|
||
| def make_filename(self) -> tuple[str, str, str]: | ||
| fn, read_path, write_path = super().make_filename() | ||
| mode_settings = self.parent.mode_settings # type: ignore[union-attr] | ||
| if mode_settings.make_directories.get(): | ||
| makedirs(read_path) | ||
| return fn, read_path, write_path | ||
|
|
||
|
|
||
| class HDF5PluginWithFileStore(HDF5Plugin, MerlinFileStoreHDF5): | ||
| def stage(self) -> object: | ||
| mode_settings = self.parent.mode_settings # type: ignore[union-attr] | ||
| total_points = mode_settings.total_points.get() | ||
| self.stage_sigs[self.num_capture] = total_points | ||
|
|
||
| # ensure that setting capture is the last thing that's done | ||
| self.stage_sigs.move_to_end(self.capture) | ||
| return super().stage() | ||
|
|
||
| def describe(self): | ||
| ret = super().describe() | ||
| key = self.parent._image_name # type: ignore[union-attr] | ||
| ret[key].setdefault("dtype_str", "<u2") # type: ignore[attr-defined] | ||
| return ret | ||
|
|
||
|
|
||
| class CDIMerlinDetector(CDIModalTrigger, MerlinDetector): | ||
| hdf5 = Cpt( | ||
| HDF5PluginWithFileStore, | ||
| "HDF1:", | ||
| read_attrs=[], | ||
| configuration_attrs=[], | ||
| write_path_template="/nsls2/data/tst/legacy/mock-proposals/2025-2/pass-56789/assets/merlin/%Y/%m/%d", | ||
| root="/nsls2/data/tst/legacy/mock-proposals/2025-2/pass-56789/assets/merlin", | ||
|
mrakitin marked this conversation as resolved.
|
||
| ) | ||
|
|
||
| proc1 = Cpt(ProcessPlugin, "Proc1:") | ||
| stats1 = Cpt(StatsPlugin, "Stats1:") | ||
| stats2 = Cpt(StatsPlugin, "Stats2:") | ||
| stats3 = Cpt(StatsPlugin, "Stats3:") | ||
| stats4 = Cpt(StatsPlugin, "Stats4:") | ||
| stats5 = Cpt(StatsPlugin, "Stats5:") | ||
| transform1 = Cpt(TransformPlugin, "Trans1:") | ||
| roi1 = Cpt(ROIPlugin, "ROI1:") | ||
| roi2 = Cpt(ROIPlugin, "ROI2:") | ||
| roi3 = Cpt(ROIPlugin, "ROI3:") | ||
| roi4 = Cpt(ROIPlugin, "ROI4:") | ||
|
|
||
| def __init__( | ||
| self, | ||
| prefix, | ||
| *, | ||
| read_attrs: list[str] | None = None, | ||
| configuration_attrs: list[str] | None = None, | ||
| **kwargs, | ||
| ): | ||
| if read_attrs is None: | ||
| read_attrs = ["hdf5", "cam"] | ||
| if configuration_attrs is None: | ||
| configuration_attrs = ["hdf5", "cam"] | ||
|
|
||
| if "hdf5" not in read_attrs: | ||
| # ensure that hdf5 is still added, or data acquisition will fail | ||
| read_attrs = [*list(read_attrs), "hdf5"] | ||
|
|
||
| super().__init__( | ||
| prefix, | ||
| configuration_attrs=configuration_attrs, | ||
| read_attrs=read_attrs, | ||
| **kwargs, | ||
| ) | ||
|
|
||
| def mode_internal(self) -> None: | ||
| super().mode_internal() | ||
|
|
||
| count_time = self.count_time.get() | ||
| if isinstance(count_time, float): | ||
| self.stage_sigs[self.cam.acquire_time] = count_time | ||
| self.stage_sigs[self.cam.acquire_period] = count_time + 0.005 | ||
|
|
||
| def mode_external(self) -> None: | ||
| super().mode_external() | ||
|
|
||
| # NOTE: these values specify a debounce time for external triggering so | ||
| # they should be set to < 0.5 the expected exposure time, or at | ||
| # minimum the lowest possible dead time = 1.64ms | ||
| expected_exposure = 0.001 | ||
| min_dead_time = 0.00164 | ||
| self.stage_sigs[self.cam.acquire_time] = expected_exposure | ||
| self.stage_sigs[self.cam.acquire_period] = expected_exposure + min_dead_time | ||
|
|
||
| self.cam.stage_sigs[self.cam.trigger_mode] = "Trigger Enable" | ||
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.