-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into 772_beamline_specific…
…_zebra_constants
- Loading branch information
Showing
20 changed files
with
257 additions
and
56 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
from asyncio import gather | ||
from math import isclose | ||
|
||
from ophyd_async.core import StandardReadable, StrictEnum | ||
from ophyd_async.epics.motor import Motor | ||
|
||
from dodal.common.beamlines.beamline_parameters import GDABeamlineParameters | ||
from dodal.common.signal_utils import create_hardware_backed_soft_signal | ||
|
||
|
||
class BeamstopPositions(StrictEnum): | ||
""" | ||
Beamstop positions. | ||
GDA supports Standard/High/Low resolution positions, as well as parked and | ||
robot load however all 3 resolution positions are the same. We also | ||
do not use the robot load position in Hyperion. | ||
Until we support moving the beamstop it is only necessary to check whether the | ||
beamstop is in beam or not. | ||
See Also: | ||
https://github.com/DiamondLightSource/mx-bluesky/issues/484 | ||
Attributes: | ||
DATA_COLLECTION: The beamstop is in beam ready for data collection | ||
UNKNOWN: The beamstop is in some other position, check the device motor | ||
positions to determine it. | ||
""" | ||
|
||
DATA_COLLECTION = "Data Collection" | ||
UNKNOWN = "Unknown" | ||
|
||
|
||
class Beamstop(StandardReadable): | ||
""" | ||
Beamstop for I03. | ||
Attributes: | ||
x: beamstop x position in mm | ||
y: beamstop y position in mm | ||
z: beamstop z position in mm | ||
selected_pos: Get the current position of the beamstop as an enum. Currently this | ||
is read-only. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
prefix: str, | ||
beamline_parameters: GDABeamlineParameters, | ||
name: str = "", | ||
): | ||
with self.add_children_as_readables(): | ||
self.x_mm = Motor(prefix + "X") | ||
self.y_mm = Motor(prefix + "Y") | ||
self.z_mm = Motor(prefix + "Z") | ||
self.selected_pos = create_hardware_backed_soft_signal( | ||
BeamstopPositions, self._get_selected_position | ||
) | ||
|
||
self._in_beam_xyz_mm = [ | ||
float(beamline_parameters[f"in_beam_{axis}_STANDARD"]) | ||
for axis in ("x", "y", "z") | ||
] | ||
self._xyz_tolerance_mm = [ | ||
float(beamline_parameters[f"bs_{axis}_tolerance"]) | ||
for axis in ("x", "y", "z") | ||
] | ||
|
||
super().__init__(name) | ||
|
||
async def _get_selected_position(self) -> BeamstopPositions: | ||
current_pos = await gather( | ||
self.x_mm.user_readback.get_value(), | ||
self.y_mm.user_readback.get_value(), | ||
self.z_mm.user_readback.get_value(), | ||
) | ||
if all( | ||
isclose(axis_pos, axis_in_beam, abs_tol=axis_tolerance) | ||
for axis_pos, axis_in_beam, axis_tolerance in zip( | ||
current_pos, self._in_beam_xyz_mm, self._xyz_tolerance_mm, strict=False | ||
) | ||
): | ||
return BeamstopPositions.DATA_COLLECTION | ||
else: | ||
return BeamstopPositions.UNKNOWN |
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
Empty file.
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 @@ | ||
from itertools import dropwhile | ||
from unittest.mock import Mock | ||
|
||
import pytest | ||
from bluesky import plan_stubs as bps | ||
from bluesky.preprocessors import run_decorator | ||
from bluesky.run_engine import RunEngine | ||
from ophyd_async.testing import set_mock_value | ||
|
||
from dodal.common.beamlines.beamline_parameters import GDABeamlineParameters | ||
from dodal.devices.i03.beamstop import Beamstop, BeamstopPositions | ||
|
||
|
||
@pytest.fixture | ||
def beamline_parameters() -> GDABeamlineParameters: | ||
return GDABeamlineParameters.from_file( | ||
"tests/test_data/test_beamline_parameters.txt" | ||
) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"x, y, z, expected_pos", | ||
[ | ||
[0, 0, 0, BeamstopPositions.UNKNOWN], | ||
[1.52, 44.78, 30.0, BeamstopPositions.DATA_COLLECTION], | ||
[1.501, 44.776, 29.71, BeamstopPositions.DATA_COLLECTION], | ||
[1.499, 44.776, 29.71, BeamstopPositions.UNKNOWN], | ||
[1.501, 44.774, 29.71, BeamstopPositions.UNKNOWN], | ||
[1.501, 44.776, 29.69, BeamstopPositions.UNKNOWN], | ||
], | ||
) | ||
async def test_beamstop_pos_select( | ||
beamline_parameters: GDABeamlineParameters, | ||
RE: RunEngine, | ||
x: float, | ||
y: float, | ||
z: float, | ||
expected_pos: BeamstopPositions, | ||
): | ||
beamstop = Beamstop("-MO-BS-01:", beamline_parameters, name="beamstop") | ||
await beamstop.connect(mock=True) | ||
set_mock_value(beamstop.x_mm.user_readback, x) | ||
set_mock_value(beamstop.y_mm.user_readback, y) | ||
set_mock_value(beamstop.z_mm.user_readback, z) | ||
|
||
mock_callback = Mock() | ||
RE.subscribe(mock_callback, "event") | ||
|
||
@run_decorator() | ||
def check_in_beam(): | ||
current_pos = yield from bps.rd(beamstop.selected_pos) | ||
assert current_pos == expected_pos | ||
yield from bps.create() | ||
yield from bps.read(beamstop) | ||
yield from bps.save() | ||
|
||
RE(check_in_beam()) | ||
|
||
event_call = next( | ||
dropwhile(lambda c: c.args[0] != "event", mock_callback.mock_calls) | ||
) | ||
data = event_call.args[1]["data"] | ||
assert data["beamstop-x_mm"] == x | ||
assert data["beamstop-y_mm"] == y | ||
assert data["beamstop-z_mm"] == z | ||
assert data["beamstop-selected_pos"] == expected_pos |
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.