Skip to content

Commit 0f6ea7a

Browse files
Use protocols instead of smargon type for FGS composite (#1619)
* Use protocols instead of smargon type for FGS composite * Rename devices to gonio in all plans * Include generic type everywhere in plan
1 parent 3286d6c commit 0f6ea7a

File tree

44 files changed

+199
-209
lines changed

Some content is hidden

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

44 files changed

+199
-209
lines changed

pyproject.toml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[tool.uv]
66
# Restrict lockfile to a sane subset of platforms
7-
environments = [
8-
"sys_platform == 'linux' and platform_machine == 'x86_64'"
9-
]
7+
environments = ["sys_platform == 'linux' and platform_machine == 'x86_64'"]
108

119
[project]
1210
name = "mx-bluesky"
@@ -31,7 +29,7 @@ dependencies = [
3129
"matplotlib",
3230
"nexgen >= 0.11.0",
3331
"numpy >= 2.3.5",
34-
"opencv-python", # Needed for I24 ssx moveonclick. To be changed to headless once this is moved to separate ui.
32+
"opencv-python", # Needed for I24 ssx moveonclick. To be changed to headless once this is moved to separate ui.
3533
"opentelemetry-distro",
3634
"opentelemetry-exporter-otlp",
3735
"pydantic",
@@ -46,7 +44,7 @@ dependencies = [
4644
"matplotlib",
4745
"cachetools",
4846
"bluesky-stomp >= 0.2.0",
49-
"mysql-connector-python == 9.5.0", # Can unpin once https://github.com/DiamondLightSource/ispyb-api/pull/244 is merged and released
47+
"mysql-connector-python == 9.5.0", # Can unpin once https://github.com/DiamondLightSource/ispyb-api/pull/244 is merged and released
5048

5149
#
5250
# These dependencies may be issued as pre-release versions and should have a pin constraint
@@ -57,7 +55,7 @@ dependencies = [
5755
"ophyd >= 1.10.5",
5856
"ophyd-async >= 0.14.0",
5957
"bluesky >= 1.14.6",
60-
"dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@main",
58+
"dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@28c3f20f6108d2769e7995f1008e7d76446fb38b",
6159
]
6260

6361

@@ -269,10 +267,10 @@ env_dir = ".venv"
269267
skip_install = true
270268
commands_pre = [
271269
[
272-
"python",
273-
"{toxinidir}/utility_scripts/generate_plantuml.py",
274-
"docs/developer/hyperion/reference/param_hierarchy.puml"
275-
]
270+
"python",
271+
"{toxinidir}/utility_scripts/generate_plantuml.py",
272+
"docs/developer/hyperion/reference/param_hierarchy.puml",
273+
],
276274
]
277275
commands = [
278276
[

src/mx_bluesky/beamlines/i04/callbacks/murko_callback.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,15 @@ def event(self, doc: Event) -> Event:
9595
}
9696
)
9797

98-
if (latest_omega := data.get("smargon-omega")) is not None:
98+
if (latest_omega := data.get("gonio-omega")) is not None:
9999
if len(self.previous_omegas) <= 2 and self.last_uuid:
100100
# For the first few images there's not enough data to extrapolate so we
101101
# match them one to one
102102
self.call_murko(self.last_uuid, latest_omega)
103103
self.previous_omegas.append(
104104
OmegaReading(
105105
value=latest_omega,
106-
timestamp=doc["timestamps"]["smargon-omega"],
106+
timestamp=doc["timestamps"]["gonio-omega"],
107107
)
108108
)
109109
elif (uuid := doc["data"].get("oav_to_redis_forwarder-uuid")) is not None:

src/mx_bluesky/beamlines/i04/experiment_plans/i04_grid_detect_then_xray_centre_plan.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def i04_default_grid_detect_and_xray_centre(
140140
eiger: EigerDetector = inject("eiger"),
141141
synchrotron: Synchrotron = inject("synchrotron"),
142142
zocalo: ZocaloResults = inject("zocalo"),
143-
smargon: Smargon = inject("smargon"),
143+
smargon: Smargon = inject("gonio"),
144144
detector_motion: DetectorMotion = inject("detector_motion"),
145145
transfocator: Transfocator = inject("transfocator"),
146146
oav_config: str = OavConstants.OAV_CONFIG_JSON,
@@ -195,7 +195,7 @@ def tidy_beamline():
195195

196196
if not udc:
197197
yield from get_ready_for_oav_and_close_shutter(
198-
composite.smargon,
198+
composite.gonio,
199199
composite.backlight,
200200
composite.aperture_scatterguard,
201201
composite.detector_motion,
@@ -296,7 +296,7 @@ def construct_i04_specific_features(
296296
xrc_composite.undulator.current_gap,
297297
xrc_composite.synchrotron.synchrotron_mode,
298298
xrc_composite.s4_slit_gaps,
299-
xrc_composite.smargon,
299+
xrc_composite.gonio,
300300
xrc_composite.dcm.energy_in_keV,
301301
]
302302

src/mx_bluesky/beamlines/i04/thawing_plan.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def thaw(
1818
time_to_thaw: float,
1919
rotation: float = 360,
2020
thawer: Thawer = inject("thawer"),
21-
smargon: Smargon = inject("smargon"),
21+
smargon: Smargon = inject("gonio"),
2222
) -> MsgGenerator:
2323
"""Turns on the thawer and rotates the sample by {rotation} degrees to thaw it, then
2424
rotates {rotation} degrees back and turns the thawer off. The speed of the goniometer
@@ -54,7 +54,7 @@ def thaw_and_murko_centre(
5454
rotation: float = 360,
5555
robot: BartRobot = inject("robot"),
5656
thawer: Thawer = inject("thawer"),
57-
smargon: Smargon = inject("smargon"),
57+
smargon: Smargon = inject("gonio"),
5858
murko_results: MurkoResultsDevice = inject("murko_results"),
5959
oav_to_redis_forwarder: OAVToRedisForwarder = inject("oav_to_redis_forwarder"),
6060
) -> MsgGenerator:
@@ -157,7 +157,7 @@ def thaw_and_stream_to_redis(
157157
rotation: float = 360,
158158
robot: BartRobot = inject("robot"),
159159
thawer: Thawer = inject("thawer"),
160-
smargon: Smargon = inject("smargon"),
160+
smargon: Smargon = inject("gonio"),
161161
oav_to_redis_forwarder: OAVToRedisForwarder = inject("oav_to_redis_forwarder"),
162162
) -> MsgGenerator:
163163
"""Turns on the thawer and rotates the sample by {rotation} degrees to thaw it, then
@@ -243,7 +243,7 @@ def get_metadata_from_current_oav():
243243
)
244244

245245
yield from get_metadata_from_current_oav()
246-
yield from bps.monitor(smargon.omega.user_readback, name="smargon")
246+
yield from bps.monitor(smargon.omega.user_readback, name="gonio")
247247
yield from bps.monitor(oav_to_redis_forwarder.uuid, name="oav")
248248

249249
yield from bps.kickoff(oav_to_redis_forwarder, wait=True)

src/mx_bluesky/common/experiment_plans/change_aperture_then_move_plan.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ def get_results_then_change_aperture_and_move_to_xtal(
2828
"Flyscan result event not received or no crystal found and exception not raised"
2929
)
3030
yield from change_aperture_then_move_to_xtal(
31-
flyscan_results[0], composite.smargon, composite.aperture_scatterguard
31+
flyscan_results[0],
32+
composite.gonio,
33+
composite.aperture_scatterguard,
3234
)
3335

3436

src/mx_bluesky/common/experiment_plans/common_flyscan_xray_centre_plan.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@
2626
PlanGroupCheckpointConstants,
2727
PlanNameConstants,
2828
)
29-
from mx_bluesky.common.parameters.device_composites import FlyScanEssentialDevices
29+
from mx_bluesky.common.parameters.device_composites import (
30+
FlyScanEssentialDevices,
31+
GonioWithOmegaType,
32+
)
3033
from mx_bluesky.common.parameters.gridscan import SpecifiedThreeDGridScan
3134
from mx_bluesky.common.utils.exceptions import (
3235
SampleError,
@@ -110,7 +113,7 @@ def construct_beamline_specific_fast_gridscan_features(
110113

111114

112115
def common_flyscan_xray_centre(
113-
composite: FlyScanEssentialDevices,
116+
composite: FlyScanEssentialDevices[GonioWithOmegaType],
114117
parameters: SpecifiedThreeDGridScan,
115118
beamline_specific: BeamlineSpecificFGSFeatures,
116119
) -> MsgGenerator:
@@ -152,7 +155,7 @@ def _decorated_flyscan():
152155
)
153156
@bpp.finalize_decorator(lambda: _overall_tidy())
154157
def run_gridscan_and_tidy(
155-
fgs_composite: FlyScanEssentialDevices,
158+
fgs_composite: FlyScanEssentialDevices[GonioWithOmegaType],
156159
params: SpecifiedThreeDGridScan,
157160
beamline_specific: BeamlineSpecificFGSFeatures,
158161
) -> MsgGenerator:
@@ -170,13 +173,13 @@ def run_gridscan_and_tidy(
170173

171174

172175
def run_gridscan(
173-
fgs_composite: FlyScanEssentialDevices,
176+
fgs_composite: FlyScanEssentialDevices[GonioWithOmegaType],
174177
parameters: SpecifiedThreeDGridScan,
175178
beamline_specific: BeamlineSpecificFGSFeatures,
176179
):
177180
# Currently gridscan only works for omega 0, see https://github.com/DiamondLightSource/mx-bluesky/issues/410
178181
with TRACER.start_span("moving_omega_to_0"):
179-
yield from bps.abs_set(fgs_composite.smargon.omega, 0)
182+
yield from bps.abs_set(fgs_composite.gonio.omega, 0)
180183

181184
with TRACER.start_span("ispyb_hardware_readings"):
182185
yield from beamline_specific.read_pre_flyscan_plan()

src/mx_bluesky/common/experiment_plans/common_grid_detect_then_xray_centre_plan.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def detect_grid_and_do_gridscan(
106106
grid_params_callback = GridDetectionCallback()
107107

108108
yield from setup_beamline_for_oav(
109-
composite.smargon,
109+
composite.gonio,
110110
composite.backlight,
111111
composite.aperture_scatterguard,
112112
wait=True,
@@ -121,7 +121,7 @@ def run_grid_detection_plan(
121121
grid_detect_composite = OavGridDetectionComposite(
122122
backlight=composite.backlight,
123123
oav=composite.oav,
124-
smargon=composite.smargon,
124+
gonio=composite.gonio,
125125
pin_tip_detection=composite.pin_tip_detection,
126126
)
127127

src/mx_bluesky/common/experiment_plans/oav_grid_detection_plan.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def grid_detection_plan(
8181
box_size_um (float): The size of each box of the grid in microns
8282
"""
8383
oav: OAV = composite.oav
84-
smargon: Smargon = composite.smargon
84+
smargon: Smargon = composite.gonio
8585
pin_tip_detection: PinTipDetection = composite.pin_tip_detection
8686

8787
LOGGER.info("OAV Centring: Starting grid detection centring")

src/mx_bluesky/common/experiment_plans/oav_snapshot_plan.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222

2323
class OavSnapshotComposite(Protocol):
24-
smargon: Smargon
24+
gonio: Smargon
2525
oav: OAV
2626
aperture_scatterguard: ApertureScatterguard
2727

@@ -78,15 +78,13 @@ def _generate_oav_snapshots(composite: OavSnapshotComposite, params: WithSnapsho
7878
for _ in 0, 270:
7979
yield from bps.create(DocDescriptorNames.OAV_ROTATION_SNAPSHOT_TRIGGERED)
8080
yield from bps.read(composite.oav)
81-
yield from bps.read(composite.smargon)
81+
yield from bps.read(composite.gonio)
8282
yield from bps.save()
8383

8484

8585
def _take_oav_snapshot(composite: OavSnapshotComposite, omega: float):
8686
"""Create new snapshots by triggering the OAV"""
87-
yield from bps.abs_set(
88-
composite.smargon.omega, omega, group=OAV_SNAPSHOT_SETUP_SHOT
89-
)
87+
yield from bps.abs_set(composite.gonio.omega, omega, group=OAV_SNAPSHOT_SETUP_SHOT)
9088
filename = _snapshot_filename(omega)
9189
yield from bps.abs_set(
9290
composite.oav.snapshot.filename,

src/mx_bluesky/common/external_interaction/callbacks/common/grid_detection_callback.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,8 @@ def event(self, doc: Event):
6868
top_left_y_px = data["oav-grid_snapshot-top_left_y"]
6969
y_of_centre_of_first_box_px = top_left_y_px + box_width_px / 2
7070

71-
smargon_omega = data["smargon-omega"]
72-
current_xyz = np.array(
73-
[data["smargon-x"], data["smargon-y"], data["smargon-z"]]
74-
)
71+
gonio_omega = data["gonio-omega"]
72+
current_xyz = np.array([data["gonio-x"], data["gonio-y"], data["gonio-z"]])
7573

7674
centre_of_first_box = (
7775
x_of_centre_of_first_box_px,
@@ -89,7 +87,7 @@ def event(self, doc: Event):
8987

9088
position_grid_start_mm = calculate_x_y_z_of_pixel(
9189
current_xyz,
92-
smargon_omega,
90+
gonio_omega,
9391
centre_of_first_box,
9492
(beam_x, beam_y),
9593
(microns_per_pixel_x, microns_per_pixel_y),
@@ -98,19 +96,19 @@ def event(self, doc: Event):
9896
LOGGER.info(f"Calculated start position {position_grid_start_mm}")
9997

10098
# If data is taken at omega=~0 then it gives us x-y info, at omega=~-90 it is x-z
101-
if abs(smargon_omega) < self.OMEGA_TOLERANCE:
99+
if abs(gonio_omega) < self.OMEGA_TOLERANCE:
102100
self.start_positions_um["x"] = position_grid_start_mm[0] * 1000
103101
self.start_positions_um["y"] = position_grid_start_mm[1] * 1000
104102
self.box_numbers["x"] = data["oav-grid_snapshot-num_boxes_x"]
105103
self.box_numbers["y"] = data["oav-grid_snapshot-num_boxes_y"]
106-
elif abs(smargon_omega + 90) < self.OMEGA_TOLERANCE:
104+
elif abs(gonio_omega + 90) < self.OMEGA_TOLERANCE:
107105
self.start_positions_um["x"] = position_grid_start_mm[0] * 1000
108106
self.start_positions_um["z"] = position_grid_start_mm[2] * 1000
109107
self.box_numbers["x"] = data["oav-grid_snapshot-num_boxes_x"]
110108
self.box_numbers["z"] = data["oav-grid_snapshot-num_boxes_y"]
111109
else:
112110
raise ValueError(
113-
f"Grid detection only works at omegas of 0 or -90, omega of {smargon_omega} given."
111+
f"Grid detection only works at omegas of 0 or -90, omega of {gonio_omega} given."
114112
)
115113

116114
self.x_step_size_um = box_width_px * microns_per_pixel_x

0 commit comments

Comments
 (0)