This repository has been archived by the owner on Sep 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
349 Create OAV snapshot plan #1437
Merged
Merged
Changes from all commits
Commits
Show all changes
4 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 contains 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 |
---|---|---|
|
@@ -8,6 +8,7 @@ __pycache__/ | |
|
||
# Output | ||
*.png | ||
!docs/*.png | ||
|
||
# Distribution / packaging | ||
.Python | ||
|
This file contains 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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,66 @@ | ||
@startuml | ||
'https://plantuml.com/class-diagram | ||
title Hyperion Parameter Model | ||
|
||
abstract class BaseModel | ||
|
||
package Mixins { | ||
class WithSample | ||
class WithScan | ||
class WithOavCentring | ||
class WithSnapshot | ||
class OptionalXyzStarts | ||
class XyzStarts | ||
class OptionalGonioAngleStarts | ||
class SplitScan | ||
} | ||
|
||
class HyperionParameters | ||
note bottom: Base class for all experiment parameter models | ||
|
||
package Experiments { | ||
class DiffractionExperiment | ||
class DiffractionExperimentWithSample | ||
class GridCommon | ||
class GridScanWithEdgeDetect | ||
class PinTipCentreThenXrayCentre | ||
class RotationScan | ||
class RobotLoadThenCentre | ||
class SpecifiedGridScan | ||
class ThreeDGridScan | ||
} | ||
class TemporaryIspybExtras | ||
note bottom: To be removed | ||
|
||
|
||
BaseModel <|-- HyperionParameters | ||
BaseModel <|-- SplitScan | ||
BaseModel <|-- OptionalGonioAngleStarts | ||
BaseModel <|-- OptionalXyzStarts | ||
BaseModel <|-- TemporaryIspybExtras | ||
BaseModel <|-- WithOavCentring | ||
BaseModel <|-- WithSnapshot | ||
BaseModel <|-- WithSample | ||
BaseModel <|-- WithScan | ||
BaseModel <|-- XyzStarts | ||
|
||
RotationScan *-- TemporaryIspybExtras | ||
HyperionParameters <|-- DiffractionExperiment | ||
WithSnapshot <|-- DiffractionExperiment | ||
DiffractionExperiment <|-- DiffractionExperimentWithSample | ||
WithSample <|-- DiffractionExperimentWithSample | ||
DiffractionExperimentWithSample <|-- GridCommon | ||
GridCommon <|-- GridScanWithEdgeDetect | ||
GridCommon <|-- PinTipCentreThenXrayCentre | ||
GridCommon <|-- RobotLoadThenCentre | ||
GridCommon <|-- SpecifiedGridScan | ||
WithScan <|-- SpecifiedGridScan | ||
SpecifiedGridScan <|-- ThreeDGridScan | ||
SplitScan <|-- ThreeDGridScan | ||
WithOavCentring <|-- GridCommon | ||
DiffractionExperimentWithSample <|-- RotationScan | ||
OptionalXyzStarts <|-- RotationScan | ||
XyzStarts <|-- SpecifiedGridScan | ||
OptionalGonioAngleStarts <|-- GridCommon | ||
OptionalGonioAngleStarts <|-- RotationScan | ||
@enduml |
This file contains 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 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 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,64 @@ | ||
import dataclasses | ||
from datetime import datetime | ||
|
||
from blueapi.core import BlueskyContext, MsgGenerator | ||
from bluesky import plan_stubs as bps | ||
from dodal.devices.oav.oav_detector import OAV | ||
from dodal.devices.oav.oav_parameters import OAVParameters | ||
from dodal.devices.smargon import Smargon | ||
|
||
from hyperion.device_setup_plans.setup_oav import setup_general_oav_params | ||
from hyperion.parameters.components import WithSnapshot | ||
from hyperion.parameters.constants import DocDescriptorNames | ||
from hyperion.utils.context import device_composite_from_context | ||
|
||
OAV_SNAPSHOT_GROUP = "oav_snapshot_group" | ||
|
||
|
||
@dataclasses.dataclass | ||
class OavSnapshotComposite: | ||
smargon: Smargon | ||
oav: OAV | ||
|
||
|
||
def create_devices(context: BlueskyContext) -> OavSnapshotComposite: | ||
return device_composite_from_context(context, OavSnapshotComposite) # type: ignore | ||
|
||
|
||
def _setup_oav( | ||
composite: OavSnapshotComposite, | ||
parameters: WithSnapshot, | ||
oav_parameters: OAVParameters, | ||
): | ||
yield from setup_general_oav_params(composite.oav, oav_parameters) | ||
yield from bps.abs_set( | ||
composite.oav.snapshot.directory, str(parameters.snapshot_directory) | ||
) | ||
|
||
|
||
def _take_oav_snapshot( | ||
composite: OavSnapshotComposite, parameters: WithSnapshot, omega: float | ||
): | ||
yield from bps.abs_set(composite.smargon.omega, omega, group=OAV_SNAPSHOT_GROUP) | ||
time_now = datetime.now() | ||
filename = f"{time_now.strftime('%H%M%S')}_oav_snapshot_{omega:.0f}" | ||
yield from bps.abs_set(composite.oav.snapshot.filename, filename) | ||
yield from bps.trigger(composite.oav.snapshot, group=OAV_SNAPSHOT_GROUP) | ||
yield from bps.wait(group=OAV_SNAPSHOT_GROUP) | ||
yield from bps.create(DocDescriptorNames.OAV_ROTATION_SNAPSHOT_TRIGGERED) | ||
yield from bps.read(composite.oav.snapshot) | ||
yield from bps.save() | ||
|
||
|
||
def oav_snapshot_plan( | ||
composite: OavSnapshotComposite, | ||
parameters: WithSnapshot, | ||
oav_parameters: OAVParameters, | ||
wait: bool = True, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This wait parameter is here as requested in original issue, but currently unused since we have to wait for the snapshot trigger completion before firing the event. Am open to suggestions to remove it / alternate structuring to make it useful. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As it is we can remove this, I agree. If we need to do something more complex async we'll need to do it at device level anyway. |
||
) -> MsgGenerator: | ||
omegas = parameters.snapshot_omegas_deg | ||
if not omegas: | ||
return | ||
yield from _setup_oav(composite, parameters, oav_parameters) | ||
for omega in omegas: | ||
yield from _take_oav_snapshot(composite, parameters, omega) |
This file contains 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 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 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 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 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 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 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 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!