-
Notifications
You must be signed in to change notification settings - Fork 11
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
add i18 beamline definition - WITH device_factory #722
Closed
Changes from all commits
Commits
Show all changes
94 commits
Select commit
Hold shift + click to select a range
0baece2
add i18 beamline definition
stan-dot c902167
add metadata to dcm crystals
stan-dot 4fb6a76
adapt the tests
stan-dot 7311a8e
udpate fixtures
stan-dot 9c52087
move devices from i18-bluesky
stan-dot d902185
fix some pv values
stan-dot d774413
move away from ophyd devices
stan-dot ed4f4c8
add a kb mirror device@
stan-dot 52d6ffe
test lookup table
stan-dot 42f1618
readjust the value param in the set method
stan-dot ba01d19
trying to add the sim extra for ophyd-async
stan-dot 80ac2e8
adapt to the ophyd-async update
stan-dot 2aa1255
remove the wrong panda import
stan-dot 378b978
fix epics imports
stan-dot d2a5c14
fix motor
stan-dot a01e7f5
add a set method
stan-dot e97bbae
add set wrap asyncstatus
stan-dot 1792482
remove the Movable interface
stan-dot 1502f89
table error still
stan-dot 5b760eb
devices cleared up
stan-dot a712008
add testing to the i18 devices
stan-dot b0583a8
respond to feedback
stan-dot 52f7b71
add testing for the crystal metadata
stan-dot ccd69e5
ruff fix
stan-dot 0f53ba6
respond to feedback
stan-dot 68c0a7a
cancel the skip_device comment
stan-dot a8a020b
cancel the crystal metadata
stan-dot 314edda
fix imports again
stan-dot 9d522ca
fix dcm i18 test
stan-dot 9376dd1
fix lint
stan-dot 67b43cd
fix import
stan-dot f5f0618
add test to increase covereage
stan-dot b808dd1
update the imports
stan-dot 9f2369e
respond to feedback
stan-dot 6526c61
delete test for sim detector (old)
stan-dot 01de971
delete sim detector
stan-dot 70df1eb
add name to diode
stan-dot 78fdc27
restore the thor labs stage and cancel the xpress3 not working one
stan-dot 5224b96
make all connect
stan-dot 61007bd
fix the tests imports
stan-dot e8c8bcd
Add device_factory
DiamondJoseph e039885
remove unknown values and simulated device
DiamondJoseph d94415f
i18 slits centre spelling
DiamondJoseph 5972984
Skip devices that require device classes
DiamondJoseph ebb5175
Remove unused devices
DiamondJoseph 1068b44
Restore i18 dcm
DiamondJoseph 9201e5b
add i18 beamline definition
stan-dot b916855
add metadata to dcm crystals
stan-dot 216728c
adapt the tests
stan-dot 1ba4df5
udpate fixtures
stan-dot cdaaf25
move devices from i18-bluesky
stan-dot 7d2ddd3
fix some pv values
stan-dot c19a147
move away from ophyd devices
stan-dot 9faa28e
add a kb mirror device@
stan-dot eb13245
test lookup table
stan-dot 02a94dd
readjust the value param in the set method
stan-dot fd7adc2
adapt to the ophyd-async update
stan-dot 6616168
remove the wrong panda import
stan-dot 2dccb09
fix epics imports
stan-dot f9bf3e5
fix motor
stan-dot 3f4cbf2
add a set method
stan-dot 18515b6
add set wrap asyncstatus
stan-dot f1e03f9
remove the Movable interface
stan-dot 87c9c73
table error still
stan-dot b79b76d
devices cleared up
stan-dot 11b08e3
add testing to the i18 devices
stan-dot f743462
respond to feedback
stan-dot e753e40
add testing for the crystal metadata
stan-dot 17fa5d3
ruff fix
stan-dot 7c651cc
respond to feedback
stan-dot e3a2e0e
cancel the skip_device comment
stan-dot 3b3fc28
cancel the crystal metadata
stan-dot 5536626
fix imports again
stan-dot 568828d
fix dcm i18 test
stan-dot 8e42ad9
fix lint
stan-dot 8e17e2f
fix import
stan-dot c239359
add test to increase covereage
stan-dot 1e7f4a2
update the imports
stan-dot 5fe2ca2
respond to feedback
stan-dot fe7ff5e
delete test for sim detector (old)
stan-dot a3f8b1a
delete sim detector
stan-dot b5fef2d
add name to diode
stan-dot 05f2f50
restore the thor labs stage and cancel the xpress3 not working one
stan-dot 5b8fec4
make all connect
stan-dot 3f2a7c3
fix the tests imports
stan-dot 7d66522
respond to feedback
stan-dot cfc9f78
fix lint
stan-dot 5a87cee
merged
stan-dot f111987
apply some feedback
stan-dot 5fbf51e
Update src/dodal/beamlines/i22.py
stan-dot 10b54a7
add issue link to vfm error
stan-dot 8171e96
add the tests for i18
stan-dot de2d3c6
adjust the dcm for i18 to have no metadata
stan-dot 5f4220e
fix the tests
stan-dot 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 |
---|---|---|
@@ -0,0 +1,123 @@ | ||
from pathlib import Path | ||
|
||
from ophyd_async.fastcs.panda import HDFPanda | ||
|
||
from dodal.common.beamlines.beamline_utils import ( | ||
device_factory, | ||
get_path_provider, | ||
set_path_provider, | ||
) | ||
from dodal.common.beamlines.beamline_utils import set_beamline as set_utils_beamline | ||
from dodal.common.visit import ( | ||
LocalDirectoryServiceClient, | ||
StaticVisitPathProvider, | ||
) | ||
from dodal.devices.i18.diode import Diode | ||
from dodal.devices.i18.KBMirror import KBMirror | ||
from dodal.devices.i18.table import Table | ||
from dodal.devices.i18.thor_labs_stage import ThorLabsStage | ||
from dodal.devices.i22.dcm import DoubleCrystalMonochromator | ||
from dodal.devices.slits import Slits | ||
from dodal.devices.synchrotron import Synchrotron | ||
from dodal.devices.tetramm import TetrammDetector | ||
from dodal.devices.undulator import Undulator | ||
from dodal.log import set_beamline as set_log_beamline | ||
from dodal.utils import BeamlinePrefix, get_beamline_name | ||
|
||
BL = get_beamline_name("i18") | ||
PREFIX = BeamlinePrefix(BL) | ||
set_log_beamline(BL) | ||
set_utils_beamline(BL) | ||
|
||
|
||
# Currently we must hard-code the visit, determining the visit at runtime requires | ||
# infrastructure that is still WIP. | ||
# Communication with GDA is also WIP so for now we determine an arbitrary scan number | ||
# locally and write the commissioning directory. The scan number is not guaranteed to | ||
# be unique and the data is at risk - this configuration is for testing only. | ||
set_path_provider( | ||
StaticVisitPathProvider( | ||
BL, | ||
Path("/dls/i18/data/2024/cm37264-2/bluesky"), | ||
client=LocalDirectoryServiceClient(), | ||
) | ||
) | ||
|
||
|
||
@device_factory() | ||
def synchrotron() -> Synchrotron: | ||
return Synchrotron() | ||
|
||
|
||
@device_factory() | ||
def undulator() -> Undulator: | ||
return Undulator(f"{PREFIX.insertion_prefix}-MO-SERVC-01:") | ||
|
||
|
||
@device_factory() | ||
def dcm() -> DoubleCrystalMonochromator: | ||
return DoubleCrystalMonochromator( | ||
prefix=f"{PREFIX.beamline_prefix}-MO-DCM-01:", | ||
temperature_prefix=f"{PREFIX.beamline_prefix}-DI-DCM-01:", | ||
) | ||
|
||
|
||
@device_factory() | ||
def slits_1() -> Slits: | ||
return Slits( | ||
f"{PREFIX.beamline_prefix}-AL-SLITS-01:", | ||
x_centre="X:CENTER", | ||
y_centre="Y:CENTER", | ||
) | ||
|
||
|
||
# PandA IOC needs to be updated to support PVI | ||
@device_factory(skip=True) | ||
def panda1() -> HDFPanda: | ||
return HDFPanda( | ||
f"{PREFIX.beamline_prefix}-MO-PANDA-01:", | ||
path_provider=get_path_provider(), | ||
) | ||
|
||
|
||
@device_factory() | ||
def i0() -> TetrammDetector: | ||
return TetrammDetector( | ||
f"{PREFIX.beamline_prefix}-DI-XBPM-02:", | ||
path_provider=get_path_provider(), | ||
type="Cividec Diamond XBPM", | ||
) | ||
|
||
|
||
@device_factory() | ||
def it() -> TetrammDetector: | ||
return TetrammDetector( | ||
f"{PREFIX.beamline_prefix}-DI-XBPM-01:", | ||
path_provider=get_path_provider(), | ||
) | ||
|
||
|
||
@device_factory(skip=True) | ||
# VFM uses different IOC than HFM https://github.com/DiamondLightSource/dodal/issues/1009 | ||
def vfm() -> KBMirror: | ||
return KBMirror(f"{PREFIX.beamline_prefix}-OP-VFM-01:") | ||
|
||
|
||
@device_factory() | ||
def hfm() -> KBMirror: | ||
return KBMirror(f"{PREFIX.beamline_prefix}-OP-HFM-01:") | ||
|
||
|
||
@device_factory() | ||
def d7diode() -> Diode: | ||
return Diode(f"{PREFIX.beamline_prefix}-DI-PHDGN-07:") | ||
|
||
|
||
@device_factory() | ||
def main_table() -> Table: | ||
return Table(f"{PREFIX.beamline_prefix}-MO-TABLE-01:") | ||
|
||
|
||
@device_factory() | ||
def thor_labs_stage() -> ThorLabsStage: | ||
return ThorLabsStage(f"{PREFIX.beamline_prefix}-MO-TABLE-02:") |
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,31 @@ | ||
from bluesky.protocols import Movable | ||
from ophyd_async.core import AsyncStatus, StandardReadable | ||
from ophyd_async.epics.core import epics_signal_rw | ||
from pydantic import BaseModel | ||
|
||
|
||
class XYPosition(BaseModel): | ||
x: float | ||
y: float | ||
|
||
|
||
class KBMirror(StandardReadable, Movable): | ||
def __init__( | ||
self, | ||
prefix: str, | ||
name: str = "", | ||
): | ||
self._prefix = prefix | ||
with self.add_children_as_readables(): | ||
self.x = epics_signal_rw(float, prefix + "X") | ||
self.y = epics_signal_rw(float, prefix + "Y") | ||
self.bend1 = epics_signal_rw(float, prefix + "BEND1") | ||
self.bend2 = epics_signal_rw(float, prefix + "BEND2") | ||
self.curve = epics_signal_rw(float, prefix + "CURVE") | ||
self.ellip = epics_signal_rw(float, prefix + "ELLIP") | ||
super().__init__(name=name) | ||
|
||
@AsyncStatus.wrap | ||
async def set(self, value: XYPosition): | ||
self.x.set(value.x) | ||
self.y.set(value.y) |
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,17 @@ | ||||
from ophyd_async.core import ( | ||||
StandardReadable, | ||||
) | ||||
from ophyd_async.epics.core import epics_signal_r | ||||
|
||||
|
||||
class Diode(StandardReadable): | ||||
def __init__( | ||||
self, | ||||
prefix: str, | ||||
name: str = "", | ||||
): | ||||
self._prefix = prefix | ||||
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.
Suggested change
nit |
||||
with self.add_children_as_readables(): | ||||
self.signal = epics_signal_r(float, prefix + "B:DIODE:I") | ||||
|
||||
super().__init__(name=name) |
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,32 @@ | ||
from ophyd_async.core import ( | ||
AsyncStatus, | ||
StandardReadable, | ||
) | ||
from ophyd_async.epics.motor import Motor | ||
from pydantic import BaseModel | ||
|
||
|
||
class TablePosition(BaseModel): | ||
x: float | ||
y: float | ||
z: float | None = None | ||
theta: float | None = None | ||
stan-dot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
class Table(StandardReadable): | ||
def __init__(self, prefix: str, name: str = "") -> None: | ||
with self.add_children_as_readables(): | ||
self.x = Motor(prefix + "X") | ||
self.y = Motor(prefix + "Y") | ||
self.z = Motor(prefix + "Z") | ||
self.theta = Motor(prefix + "THETA") | ||
super().__init__(name=name) | ||
|
||
@AsyncStatus.wrap | ||
async def set(self, value: TablePosition): | ||
self.x.set(value.x) | ||
self.y.set(value.y) | ||
if value.z: | ||
self.z.set(value.z) | ||
if value.theta: | ||
self.theta.set(value.theta) |
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,24 @@ | ||
from ophyd_async.core import ( | ||
AsyncStatus, | ||
StandardReadable, | ||
) | ||
from ophyd_async.epics.motor import Motor | ||
from pydantic import BaseModel | ||
|
||
|
||
class XYPosition(BaseModel): | ||
x: float | ||
y: float | ||
|
||
|
||
class ThorLabsStage(StandardReadable): | ||
def __init__(self, prefix: str, name: str = "") -> None: | ||
with self.add_children_as_readables(): | ||
self.x = Motor(prefix + "X") | ||
self.y = Motor(prefix + "Y") | ||
super().__init__(name=name) | ||
|
||
@AsyncStatus.wrap | ||
async def set(self, value: XYPosition): | ||
self.x.set(value.x) | ||
self.y.set(value.y) |
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,66 @@ | ||
from unittest.mock import ANY | ||
|
||
import pytest | ||
from ophyd_async.core import DeviceCollector | ||
from ophyd_async.testing import set_mock_value | ||
|
||
from dodal.devices.i18.KBMirror import KBMirror, XYPosition | ||
|
||
|
||
@pytest.fixture | ||
async def kbmirror() -> KBMirror: | ||
"""Fixture to set up a mock KBMirror device using DeviceCollector.""" | ||
async with DeviceCollector(mock=True): | ||
kbmirror = KBMirror(prefix="MIRROR:") | ||
return kbmirror | ||
|
||
|
||
async def test_setting_xy_position_kbmirror(kbmirror: KBMirror): | ||
""" | ||
Test setting x and y positions on the KBMirror using the ophyd_async mock tools. | ||
""" | ||
# Mock the initial values of the x and y signals | ||
set_mock_value(kbmirror.x, 0.0) | ||
set_mock_value(kbmirror.y, 0.0) | ||
|
||
# Create a position object | ||
position = XYPosition(x=1.23, y=4.56) | ||
|
||
# Call set to update the position | ||
await kbmirror.set(position) | ||
|
||
reading = await kbmirror.read() | ||
expected_reading = { | ||
"kbmirror-y": { | ||
"value": 4.56, | ||
"timestamp": ANY, | ||
"alarm_severity": 0, | ||
}, | ||
"kbmirror-bend1": { | ||
"value": 0.0, | ||
"timestamp": ANY, | ||
"alarm_severity": 0, | ||
}, | ||
"kbmirror-ellip": { | ||
"value": 0.0, | ||
"timestamp": ANY, | ||
"alarm_severity": 0, | ||
}, | ||
"kbmirror-x": { | ||
"value": 1.23, | ||
"timestamp": ANY, | ||
"alarm_severity": 0, | ||
}, | ||
"kbmirror-bend2": { | ||
"value": 0.0, | ||
"timestamp": ANY, | ||
"alarm_severity": 0, | ||
}, | ||
"kbmirror-curve": { | ||
"value": 0.0, | ||
"timestamp": ANY, | ||
"alarm_severity": 0, | ||
}, | ||
} | ||
|
||
assert reading == expected_reading |
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.
nit: not used anywhere
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.
I'd like to have it for reference for checking the object status though