Skip to content

Commit 8adcc77

Browse files
authored
Merge branch 'main' into device_context
2 parents 0487c9b + 400fe84 commit 8adcc77

File tree

94 files changed

+580
-663
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+580
-663
lines changed

docs/how-to/write-tests.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Testing is essential to maintain the integrity and reliability of the codebase.
77
- **Unit Tests**: Place unit tests for individual components in the `tests` directory, but take care to mirror the file structure of the `src` folder with the corresponding code files. Use the `test_*.py` naming convention for test files.
88
- **System Tests**: Tests that interact with DLS infrastructure, network, and filesystem should be placed in the top-level `systems_test` folder. This separation ensures that these tests are easily identifiable and can be run independently from unit tests.
99

10-
Useful functions for testing that can be reused across multiple tests for common devices and for external plan repositories belong in the `dodal/testing` directory. For example, when mocking a `Motor` device, all of the signals will default to zero, which will cause errors when trying to move. The `patch_motor` and `patch_all_motors` functions, found in `dodal.testing`, will populate the mocked motor with useful default values for the signals so that it can still be used in tests.
10+
Useful functions for testing that can be reused across multiple tests for common devices and for external plan repositories belong in the `dodal/testing` directory.
1111

1212

1313
## Writing a test for a device

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ description = "Ophyd devices and other utils that could be used across DLS beaml
1414
dependencies = [
1515
"click",
1616
"ophyd",
17-
"ophyd-async[ca,pva]>=0.13.7",
17+
"ophyd-async[ca,pva]>=v0.14.0",
1818
"bluesky>=1.14.5",
1919
"pyepics",
2020
"pillow",
@@ -48,7 +48,7 @@ dev = [
4848
# Commented out due to dependency version conflict with pydantic 1.x
4949
# "copier",
5050
"myst-parser",
51-
"ophyd_async[sim]",
51+
"ophyd_async[sim]>=v0.14.0",
5252
"pipdeptree",
5353
"pre-commit",
5454
"psutil",

src/dodal/beamline_specific_utils/i03.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/dodal/beamlines/i03.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from dodal.devices.focusing_mirror import FocusingMirrorWithStripes, MirrorVoltages
3232
from dodal.devices.hutch_shutter import HutchShutter
3333
from dodal.devices.i03 import Beamstop
34+
from dodal.devices.i03.beamsize import Beamsize
3435
from dodal.devices.i03.dcm import DCM
3536
from dodal.devices.i03.undulator_dcm import UndulatorDCM
3637
from dodal.devices.ipin import IPin
@@ -459,6 +460,16 @@ def collimation_table() -> CollimationTable:
459460
return CollimationTable(prefix=f"{PREFIX.beamline_prefix}-MO-TABLE-01")
460461

461462

463+
@device_factory()
464+
def beamsize() -> Beamsize:
465+
"""Get the i03 beamsize device, instantiate it if it hasn't already been.
466+
If this is called when already instantiated in i03, it will return the existing object.
467+
"""
468+
return Beamsize(
469+
aperture_scatterguard=aperture_scatterguard(),
470+
)
471+
472+
462473
@device_factory()
463474
def ipin() -> IPin:
464475
"""Get the i03 ipin device, instantiate it if it hasn't already been.

src/dodal/beamlines/i04.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from dodal.devices.fast_grid_scan import ZebraFastGridScanThreeD
2121
from dodal.devices.flux import Flux
2222
from dodal.devices.i03.dcm import DCM
23+
from dodal.devices.i04.beamsize import Beamsize
2324
from dodal.devices.i04.constants import RedisConstants
2425
from dodal.devices.i04.murko_results import MurkoResultsDevice
2526
from dodal.devices.i04.transfocator import Transfocator
@@ -377,3 +378,14 @@ def scintillator() -> Scintillator:
377378
Reference(aperture_scatterguard()),
378379
get_beamline_parameters(),
379380
)
381+
382+
383+
@device_factory()
384+
def beamsize() -> Beamsize:
385+
"""Get the i04 beamsize device, instantiate it if it hasn't already been.
386+
If this is called when already instantiated in i04, it will return the existing object.
387+
"""
388+
return Beamsize(
389+
transfocator=transfocator(),
390+
aperture_scatterguard=aperture_scatterguard(),
391+
)

src/dodal/devices/aperturescatterguard.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import asyncio
4+
from math import inf
45

56
from bluesky.protocols import Preparable
67
from ophyd_async.core import (
@@ -112,7 +113,7 @@ def load_positions_from_beamline_parameters(
112113
) -> dict[ApertureValue, AperturePosition]:
113114
return {
114115
ApertureValue.OUT_OF_BEAM: AperturePosition.from_gda_params(
115-
_GDAParamApertureValue.ROBOT_LOAD, 0, params
116+
_GDAParamApertureValue.ROBOT_LOAD, inf, params
116117
),
117118
ApertureValue.SMALL: AperturePosition.from_gda_params(
118119
_GDAParamApertureValue.SMALL, 20, params
@@ -124,7 +125,7 @@ def load_positions_from_beamline_parameters(
124125
_GDAParamApertureValue.LARGE, 100, params
125126
),
126127
ApertureValue.PARKED: AperturePosition.from_gda_params(
127-
_GDAParamApertureValue.MANUAL_LOAD, 0, params
128+
_GDAParamApertureValue.MANUAL_LOAD, inf, params
128129
),
129130
}
130131

src/dodal/devices/beamsize/__init__.py

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from ophyd_async.core import SignalR, StandardReadable
2+
3+
4+
class BeamsizeBase(StandardReadable):
5+
x_um: SignalR[float]
6+
y_um: SignalR[float]

src/dodal/devices/detector/det_resolution.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ def _get_detector_radius_mm(detector_params: DetectorParams):
1010
return 0.5 * _get_detector_max_size_mm(detector_params)
1111

1212

13-
def _get_detector_max_size_mm(detector_params):
13+
def _get_detector_max_size_mm(detector_params: DetectorParams):
1414
return max(
1515
detector_params.detector_size_constants.det_dimension.width,
1616
detector_params.detector_size_constants.det_dimension.height,
1717
)
1818

1919

20-
def _get_beam_xy_accounting_for_roi(detector_params, det_distance_mm):
20+
def _get_beam_xy_accounting_for_roi(
21+
detector_params: DetectorParams, det_distance_mm: float
22+
):
2123
beam_x = detector_params.beam_xy_converter.get_beam_xy_from_det_dist(
2224
det_distance_mm, Axis.X_AXIS
2325
)

src/dodal/devices/fast_grid_scan.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import asyncio
22
from abc import ABC, abstractmethod
3+
from functools import partial
4+
from math import isclose
35
from typing import Generic, TypeVar
46

57
import numpy as np
@@ -307,13 +309,23 @@ async def prepare(self, value: ParamType):
307309
set_statuses = []
308310

309311
LOGGER.info("Applying gridscan parameters...")
312+
310313
# Create arguments for bps.mv
311314
for key, signal in self._movable_params.items():
312315
param_value = value.__dict__[key]
313-
set_statuses.append(await set_and_wait_for_value(signal, param_value)) # type: ignore
316+
317+
matcher = partial(isclose, param_value, abs_tol=0.001)
318+
319+
set_statuses.append(
320+
set_and_wait_for_value(
321+
signal, # type: ignore
322+
param_value,
323+
match_value=matcher,
324+
)
325+
)
314326

315327
# Counter should always start at 0
316-
set_statuses.append(await set_and_wait_for_value(self.position_counter, 0))
328+
set_statuses.append(set_and_wait_for_value(self.position_counter, 0))
317329

318330
LOGGER.info("Gridscan parameters applied, waiting for sets to complete...")
319331

0 commit comments

Comments
 (0)