dls-dodal 1.47.0__py3-none-any.whl → 1.49.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {dls_dodal-1.47.0.dist-info → dls_dodal-1.49.0.dist-info}/METADATA +3 -2
- {dls_dodal-1.47.0.dist-info → dls_dodal-1.49.0.dist-info}/RECORD +59 -49
- {dls_dodal-1.47.0.dist-info → dls_dodal-1.49.0.dist-info}/WHEEL +1 -1
- dodal/_version.py +2 -2
- dodal/beamlines/aithre.py +21 -0
- dodal/beamlines/b01_1.py +1 -1
- dodal/beamlines/b16.py +65 -0
- dodal/beamlines/b18.py +38 -0
- dodal/beamlines/i03.py +21 -6
- dodal/beamlines/i04.py +17 -10
- dodal/beamlines/i10.py +41 -233
- dodal/beamlines/i18.py +1 -1
- dodal/beamlines/i19_1.py +9 -6
- dodal/beamlines/i24.py +5 -5
- dodal/beamlines/k11.py +35 -0
- dodal/common/beamlines/beamline_parameters.py +2 -28
- dodal/common/beamlines/device_helpers.py +1 -0
- dodal/devices/aithre_lasershaping/goniometer.py +36 -2
- dodal/devices/aithre_lasershaping/laser_robot.py +27 -0
- dodal/devices/apple2_undulator.py +257 -136
- dodal/devices/b16/__init__.py +0 -0
- dodal/devices/b16/detector.py +34 -0
- dodal/devices/bimorph_mirror.py +29 -36
- dodal/devices/electron_analyser/__init__.py +21 -1
- dodal/devices/electron_analyser/abstract/__init__.py +0 -6
- dodal/devices/electron_analyser/abstract/base_detector.py +16 -128
- dodal/devices/electron_analyser/abstract/base_driver_io.py +122 -8
- dodal/devices/electron_analyser/abstract/base_region.py +7 -3
- dodal/devices/electron_analyser/detector.py +141 -0
- dodal/devices/electron_analyser/enums.py +6 -0
- dodal/devices/electron_analyser/specs/__init__.py +3 -2
- dodal/devices/electron_analyser/specs/detector.py +6 -22
- dodal/devices/electron_analyser/specs/driver_io.py +27 -3
- dodal/devices/electron_analyser/specs/enums.py +8 -0
- dodal/devices/electron_analyser/specs/region.py +3 -2
- dodal/devices/electron_analyser/types.py +30 -4
- dodal/devices/electron_analyser/util.py +1 -1
- dodal/devices/electron_analyser/vgscienta/__init__.py +3 -2
- dodal/devices/electron_analyser/vgscienta/detector.py +9 -23
- dodal/devices/electron_analyser/vgscienta/driver_io.py +33 -4
- dodal/devices/electron_analyser/vgscienta/enums.py +19 -0
- dodal/devices/electron_analyser/vgscienta/region.py +7 -23
- dodal/devices/fast_grid_scan.py +1 -1
- dodal/devices/i04/murko_results.py +93 -96
- dodal/devices/i10/__init__.py +0 -0
- dodal/devices/i10/i10_apple2.py +181 -126
- dodal/devices/i18/diode.py +37 -4
- dodal/devices/i22/nxsas.py +1 -1
- dodal/devices/mx_phase1/beamstop.py +23 -6
- dodal/devices/oav/oav_detector.py +101 -25
- dodal/devices/oav/oav_parameters.py +46 -16
- dodal/devices/oav/oav_to_redis_forwarder.py +2 -2
- dodal/devices/robot.py +20 -1
- dodal/devices/smargon.py +43 -4
- dodal/devices/zebra/zebra.py +8 -0
- dodal/plans/configure_arm_trigger_and_disarm_detector.py +167 -0
- dodal/plan_stubs/electron_analyser/__init__.py +0 -3
- dodal/plan_stubs/electron_analyser/configure_driver.py +0 -92
- {dls_dodal-1.47.0.dist-info → dls_dodal-1.49.0.dist-info}/entry_points.txt +0 -0
- {dls_dodal-1.47.0.dist-info → dls_dodal-1.49.0.dist-info}/licenses/LICENSE +0 -0
- {dls_dodal-1.47.0.dist-info → dls_dodal-1.49.0.dist-info}/top_level.txt +0 -0
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import json
|
|
2
2
|
import pickle
|
|
3
|
-
from collections import OrderedDict
|
|
4
3
|
from enum import Enum
|
|
5
4
|
from typing import TypedDict
|
|
6
5
|
|
|
@@ -17,10 +16,11 @@ from redis.asyncio import StrictRedis
|
|
|
17
16
|
from dodal.devices.i04.constants import RedisConstants
|
|
18
17
|
from dodal.devices.oav.oav_calculations import (
|
|
19
18
|
calculate_beam_distance,
|
|
20
|
-
camera_coordinates_to_xyz_mm,
|
|
21
19
|
)
|
|
22
20
|
from dodal.log import LOGGER
|
|
23
21
|
|
|
22
|
+
NO_MURKO_RESULT = (-1, -1)
|
|
23
|
+
|
|
24
24
|
MurkoResult = dict
|
|
25
25
|
FullMurkoResults = dict[str, list[MurkoResult]]
|
|
26
26
|
|
|
@@ -43,12 +43,19 @@ class Coord(Enum):
|
|
|
43
43
|
|
|
44
44
|
|
|
45
45
|
class MurkoResultsDevice(StandardReadable, Triggerable, Stageable):
|
|
46
|
-
"""Device that takes crystal centre
|
|
46
|
+
"""Device that takes crystal centre values from Murko and uses them to set the
|
|
47
47
|
x, y, z coordinate of the sample to be in line with the beam centre.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
The most_likely_click[1] value from Murko corresponds with the x coordinate of the
|
|
49
|
+
sample. The most_likely_click[0] value from Murko corresponds with a component of
|
|
50
|
+
the y and z coordinates of the sample, depending on the omega angle, as the sample
|
|
51
|
+
is rotated around the x axis.
|
|
52
|
+
|
|
53
|
+
Given a most_likely_click value at a certain omega angle θ:
|
|
54
|
+
most_likely_click[1] = x
|
|
55
|
+
most_likely_click[0] = cos(θ)y - sin(θ)z
|
|
56
|
+
|
|
57
|
+
A value for x can be found by averaging all most_likely_click[1] values, and
|
|
58
|
+
solutions for y and z can be calculated using numpy's linear algebra library.
|
|
52
59
|
"""
|
|
53
60
|
|
|
54
61
|
TIMEOUT_S = 2
|
|
@@ -59,6 +66,7 @@ class MurkoResultsDevice(StandardReadable, Triggerable, Stageable):
|
|
|
59
66
|
redis_password=RedisConstants.REDIS_PASSWORD,
|
|
60
67
|
redis_db=RedisConstants.MURKO_REDIS_DB,
|
|
61
68
|
name="",
|
|
69
|
+
stop_angle=350,
|
|
62
70
|
):
|
|
63
71
|
self.redis_client = StrictRedis(
|
|
64
72
|
host=redis_host,
|
|
@@ -67,17 +75,11 @@ class MurkoResultsDevice(StandardReadable, Triggerable, Stageable):
|
|
|
67
75
|
)
|
|
68
76
|
self.pubsub = self.redis_client.pubsub()
|
|
69
77
|
self._last_omega = 0
|
|
70
|
-
self._last_result = None
|
|
71
78
|
self.sample_id = soft_signal_rw(str) # Should get from redis
|
|
72
|
-
self.
|
|
73
|
-
self.
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
(180, ("x", "y")),
|
|
77
|
-
(270, ()), # Stop searching here
|
|
78
|
-
]
|
|
79
|
-
)
|
|
80
|
-
self.angles_to_search = list(self.search_angles.keys())
|
|
79
|
+
self.stop_angle = stop_angle
|
|
80
|
+
self.x_dists_mm = []
|
|
81
|
+
self.y_dists_mm = []
|
|
82
|
+
self.omegas = []
|
|
81
83
|
|
|
82
84
|
with self.add_children_as_readables():
|
|
83
85
|
# Diffs from current x/y/z
|
|
@@ -101,95 +103,90 @@ class MurkoResultsDevice(StandardReadable, Triggerable, Stageable):
|
|
|
101
103
|
async def trigger(self):
|
|
102
104
|
# Wait for results
|
|
103
105
|
sample_id = await self.sample_id.get_value()
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
# waits here for next batch to be recieved
|
|
106
|
+
while self._last_omega < self.stop_angle:
|
|
107
|
+
# waits here for next batch to be received
|
|
107
108
|
message = await self.pubsub.get_message(timeout=self.TIMEOUT_S)
|
|
108
109
|
if message is None: # No more messages to process
|
|
109
|
-
await self.process_batch(
|
|
110
|
-
final_message, sample_id
|
|
111
|
-
) # Process final message again
|
|
112
110
|
break
|
|
113
111
|
await self.process_batch(message, sample_id)
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
self.
|
|
112
|
+
|
|
113
|
+
for i in range(len(self.omegas)):
|
|
114
|
+
LOGGER.debug(
|
|
115
|
+
f"omega: {round(self.omegas[i], 2)}, x: {round(self.x_dists_mm[i], 2)}, y: {round(self.y_dists_mm[i], 2)}"
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
LOGGER.info(f"Using average of x beam distances: {self.x_dists_mm}")
|
|
119
|
+
avg_x = float(np.mean(self.x_dists_mm))
|
|
120
|
+
LOGGER.info(f"Finding least square y and z from y distances: {self.y_dists_mm}")
|
|
121
|
+
best_y, best_z = get_yz_least_squares(self.y_dists_mm, self.omegas)
|
|
122
|
+
# x, y, z are relative to beam centre. Need to move negative these values to get centred.
|
|
123
|
+
self._x_mm_setter(-avg_x)
|
|
124
|
+
self._y_mm_setter(-best_y)
|
|
125
|
+
self._z_mm_setter(-best_z)
|
|
124
126
|
|
|
125
127
|
async def process_batch(self, message: dict | None, sample_id: str):
|
|
126
128
|
if message and message["type"] == "message":
|
|
127
|
-
batch_results = pickle.loads(message["data"])
|
|
129
|
+
batch_results: list[dict] = pickle.loads(message["data"])
|
|
128
130
|
for results in batch_results:
|
|
129
|
-
LOGGER.info(f"Got {results} from redis")
|
|
130
131
|
for uuid, result in results.items():
|
|
131
|
-
metadata_str
|
|
132
|
+
if metadata_str := await self.redis_client.hget( # type: ignore
|
|
132
133
|
f"murko:{sample_id}:metadata", uuid
|
|
133
|
-
)
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
search_angle = self.angles_to_search.pop(0)
|
|
148
|
-
for coord in self.search_angles[search_angle]:
|
|
149
|
-
self.coords[coord][omega_angle] = movement[Coord[coord].value]
|
|
150
|
-
LOGGER.info(f"Found {coord} at {movement}, angle = {omega_angle}")
|
|
151
|
-
self._last_omega = omega_angle
|
|
152
|
-
self._last_result = result
|
|
153
|
-
|
|
154
|
-
def get_coords_if_at_angle(
|
|
155
|
-
self, metadata: MurkoMetadata, result: MurkoResult, omega: float
|
|
156
|
-
) -> np.ndarray | None:
|
|
157
|
-
"""Gets the 'most_likely_click' coordinates from Murko if omega or the last
|
|
158
|
-
omega are the closest angle to the search angle. Otherwise returns None.
|
|
134
|
+
):
|
|
135
|
+
LOGGER.info(
|
|
136
|
+
f"Found metadata for uuid {uuid}, processing result"
|
|
137
|
+
)
|
|
138
|
+
self.process_result(
|
|
139
|
+
result, MurkoMetadata(json.loads(metadata_str))
|
|
140
|
+
)
|
|
141
|
+
else:
|
|
142
|
+
LOGGER.info(f"Found no metadata for uuid {uuid}")
|
|
143
|
+
|
|
144
|
+
def process_result(self, result: dict, metadata: MurkoMetadata):
|
|
145
|
+
"""Uses the 'most_likely_click' coordinates from Murko to calculate the
|
|
146
|
+
horizontal and vertical distances from the beam centre, and store these values
|
|
147
|
+
as well as the omega angle the image was taken at.
|
|
159
148
|
"""
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
):
|
|
166
|
-
|
|
167
|
-
closest_omega = self._last_omega
|
|
168
|
-
elif omega - search_angle >= 0: # if this omega is closest
|
|
169
|
-
closest_result = result
|
|
170
|
-
closest_omega = omega
|
|
149
|
+
omega = metadata["omega_angle"]
|
|
150
|
+
coords = result["most_likely_click"] # As proportion from top, left of image
|
|
151
|
+
LOGGER.info(f"Got most_likely_click: {coords} at angle {omega}")
|
|
152
|
+
if (
|
|
153
|
+
tuple(coords) == NO_MURKO_RESULT
|
|
154
|
+
): # See https://github.com/MartinSavko/murko/issues/9
|
|
155
|
+
LOGGER.info("Murko didn't produce a result, moving on")
|
|
171
156
|
else:
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
(
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
157
|
+
shape = result["original_shape"] # Dimensions of image in pixels
|
|
158
|
+
# Murko returns coords as y, x
|
|
159
|
+
centre_px = (coords[1] * shape[1], coords[0] * shape[0])
|
|
160
|
+
|
|
161
|
+
beam_dist_px = calculate_beam_distance(
|
|
162
|
+
(metadata["beam_centre_i"], metadata["beam_centre_j"]),
|
|
163
|
+
centre_px[0],
|
|
164
|
+
centre_px[1],
|
|
165
|
+
)
|
|
166
|
+
self.x_dists_mm.append(
|
|
167
|
+
beam_dist_px[0] * metadata["microns_per_x_pixel"] / 1000
|
|
168
|
+
)
|
|
169
|
+
self.y_dists_mm.append(
|
|
170
|
+
beam_dist_px[1] * metadata["microns_per_y_pixel"] / 1000
|
|
171
|
+
)
|
|
172
|
+
self.omegas.append(omega)
|
|
173
|
+
self._last_omega = omega
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def get_yz_least_squares(vertical_dists: list, omegas: list) -> tuple[float, float]:
|
|
177
|
+
"""Get the least squares solution for y and z from the vertical distances and omega angles.
|
|
178
|
+
|
|
179
|
+
Args:
|
|
180
|
+
v_dists (list): List of vertical distances from beam centre. Any units
|
|
181
|
+
omegas (list): List of omega angles in degrees.
|
|
182
|
+
|
|
183
|
+
Returns:
|
|
184
|
+
tuple[float, float]: y, z distances from centre, in whichever units
|
|
185
|
+
v_dists came as.
|
|
186
|
+
"""
|
|
187
|
+
thetas = np.radians(omegas)
|
|
188
|
+
matrix = np.column_stack([np.cos(thetas), -np.sin(thetas)])
|
|
188
189
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
closest_omega,
|
|
193
|
-
metadata["microns_per_x_pixel"],
|
|
194
|
-
metadata["microns_per_y_pixel"],
|
|
195
|
-
)
|
|
190
|
+
yz, residuals, rank, s = np.linalg.lstsq(matrix, vertical_dists, rcond=None)
|
|
191
|
+
y, z = yz
|
|
192
|
+
return y, z
|
|
File without changes
|