dls-dodal 1.34.1__py3-none-any.whl → 1.35.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.
Files changed (71) hide show
  1. {dls_dodal-1.34.1.dist-info → dls_dodal-1.35.0.dist-info}/METADATA +2 -2
  2. {dls_dodal-1.34.1.dist-info → dls_dodal-1.35.0.dist-info}/RECORD +70 -67
  3. {dls_dodal-1.34.1.dist-info → dls_dodal-1.35.0.dist-info}/WHEEL +1 -1
  4. dodal/_version.py +2 -2
  5. dodal/beamlines/i22.py +24 -11
  6. dodal/beamlines/i24.py +4 -4
  7. dodal/beamlines/p38.py +23 -11
  8. dodal/common/beamlines/beamline_utils.py +1 -2
  9. dodal/common/crystal_metadata.py +61 -0
  10. dodal/common/signal_utils.py +10 -14
  11. dodal/devices/CTAB.py +1 -1
  12. dodal/devices/aperture.py +1 -1
  13. dodal/devices/aperturescatterguard.py +20 -8
  14. dodal/devices/apple2_undulator.py +30 -29
  15. dodal/devices/areadetector/plugins/CAM.py +3 -5
  16. dodal/devices/areadetector/plugins/MJPG.py +1 -1
  17. dodal/devices/attenuator.py +1 -1
  18. dodal/devices/backlight.py +4 -5
  19. dodal/devices/cryostream.py +3 -5
  20. dodal/devices/dcm.py +26 -2
  21. dodal/devices/detector/detector_motion.py +3 -5
  22. dodal/devices/diamond_filter.py +3 -4
  23. dodal/devices/fast_grid_scan.py +1 -1
  24. dodal/devices/fluorescence_detector_motion.py +5 -7
  25. dodal/devices/focusing_mirror.py +12 -11
  26. dodal/devices/hutch_shutter.py +4 -5
  27. dodal/devices/i10/i10_apple2.py +20 -19
  28. dodal/devices/i10/i10_setting_data.py +2 -2
  29. dodal/devices/i22/dcm.py +43 -75
  30. dodal/devices/i22/fswitch.py +5 -5
  31. dodal/devices/i24/aperture.py +3 -5
  32. dodal/devices/i24/beamstop.py +3 -5
  33. dodal/devices/i24/dcm.py +1 -1
  34. dodal/devices/i24/dual_backlight.py +4 -6
  35. dodal/devices/i24/pmac.py +35 -46
  36. dodal/devices/i24/vgonio.py +16 -0
  37. dodal/devices/ipin.py +5 -3
  38. dodal/devices/linkam3.py +7 -7
  39. dodal/devices/oav/oav_detector.py +3 -3
  40. dodal/devices/oav/oav_to_redis_forwarder.py +8 -7
  41. dodal/devices/oav/pin_image_recognition/__init__.py +9 -7
  42. dodal/devices/oav/snapshots/grid_overlay.py +16 -16
  43. dodal/devices/oav/snapshots/snapshot_with_beam_centre.py +5 -5
  44. dodal/devices/oav/snapshots/snapshot_with_grid.py +6 -6
  45. dodal/devices/oav/utils.py +2 -2
  46. dodal/devices/p99/sample_stage.py +3 -5
  47. dodal/devices/pgm.py +5 -6
  48. dodal/devices/qbpm.py +1 -1
  49. dodal/devices/robot.py +3 -3
  50. dodal/devices/smargon.py +1 -1
  51. dodal/devices/synchrotron.py +9 -4
  52. dodal/devices/tetramm.py +7 -7
  53. dodal/devices/thawer.py +13 -7
  54. dodal/devices/undulator.py +5 -5
  55. dodal/devices/util/epics_util.py +1 -1
  56. dodal/devices/watsonmarlow323_pump.py +45 -0
  57. dodal/devices/webcam.py +9 -2
  58. dodal/devices/xbpm_feedback.py +3 -5
  59. dodal/devices/xspress3/xspress3.py +8 -9
  60. dodal/devices/xspress3/xspress3_channel.py +3 -5
  61. dodal/devices/zebra.py +7 -6
  62. dodal/devices/zebra_controlled_shutter.py +5 -6
  63. dodal/devices/zocalo/__init__.py +2 -2
  64. dodal/devices/zocalo/zocalo_constants.py +3 -0
  65. dodal/devices/zocalo/zocalo_interaction.py +2 -1
  66. dodal/devices/zocalo/zocalo_results.py +92 -79
  67. dodal/utils.py +4 -0
  68. dodal/devices/i24/i24_vgonio.py +0 -17
  69. {dls_dodal-1.34.1.dist-info → dls_dodal-1.35.0.dist-info}/LICENSE +0 -0
  70. {dls_dodal-1.34.1.dist-info → dls_dodal-1.35.0.dist-info}/entry_points.txt +0 -0
  71. {dls_dodal-1.34.1.dist-info → dls_dodal-1.35.0.dist-info}/top_level.txt +0 -0
@@ -1,21 +1,20 @@
1
- from enum import Enum
2
-
3
1
  from bluesky.protocols import Movable
4
2
  from ophyd_async.core import (
5
3
  DEFAULT_TIMEOUT,
6
4
  AsyncStatus,
7
5
  StandardReadable,
6
+ StrictEnum,
8
7
  wait_for_value,
9
8
  )
10
- from ophyd_async.epics.signal import epics_signal_r, epics_signal_rw, epics_signal_w
9
+ from ophyd_async.epics.core import epics_signal_r, epics_signal_rw, epics_signal_w
11
10
 
12
11
 
13
- class ZebraShutterState(str, Enum):
12
+ class ZebraShutterState(StrictEnum):
14
13
  CLOSE = "Close"
15
14
  OPEN = "Open"
16
15
 
17
16
 
18
- class ZebraShutterControl(str, Enum):
17
+ class ZebraShutterControl(StrictEnum):
19
18
  MANUAL = "Manual"
20
19
  AUTO = "Auto"
21
20
 
@@ -26,7 +25,7 @@ class ZebraShutter(StandardReadable, Movable):
26
25
  Internally in the zebra there are two AND gates, one for manual control and one for
27
26
  automatic control. A soft input (aliased to control_mode) will switch between
28
27
  which of these AND gates to use. For the manual gate the shutter is then controlled
29
- by a different soft input (aliased to _manual_position_setpoint). Both these AND
28
+ by a different soft input (aliased to manual_position_setpoint). Both these AND
30
29
  gates then feed into an OR gate, which then feeds to the shutter."""
31
30
 
32
31
  def __init__(self, prefix: str, name: str):
@@ -4,14 +4,14 @@ from dodal.devices.zocalo.zocalo_results import (
4
4
  NoZocaloSubscription,
5
5
  XrcResult,
6
6
  ZocaloResults,
7
- get_processing_result,
7
+ get_full_processing_results,
8
8
  )
9
9
 
10
10
  __all__ = [
11
11
  "ZocaloResults",
12
12
  "XrcResult",
13
13
  "ZocaloTrigger",
14
- "get_processing_result",
14
+ "get_full_processing_results",
15
15
  "ZOCALO_READING_PLAN_NAME",
16
16
  "NoResultsFromZocalo",
17
17
  "NoZocaloSubscription",
@@ -0,0 +1,3 @@
1
+ from dodal.utils import is_test_mode
2
+
3
+ ZOCALO_ENV = "dev_bluesky" if is_test_mode() else "bluesky"
@@ -7,6 +7,7 @@ from dataclasses import dataclass
7
7
  import zocalo.configuration
8
8
  from workflows.transport import lookup
9
9
 
10
+ from dodal.devices.zocalo.zocalo_constants import ZOCALO_ENV
10
11
  from dodal.log import LOGGER
11
12
 
12
13
 
@@ -56,7 +57,7 @@ class ZocaloTrigger:
56
57
 
57
58
  see https://github.com/DiamondLightSource/dodal/wiki/How-to-Interact-with-Zocalo"""
58
59
 
59
- def __init__(self, environment: str = "artemis"):
60
+ def __init__(self, environment: str = ZOCALO_ENV):
60
61
  self.zocalo_environment: str = environment
61
62
 
62
63
  def _send_to_zocalo(self, parameters: dict):
@@ -1,7 +1,7 @@
1
1
  import asyncio
2
- from collections import OrderedDict
3
2
  from collections.abc import Generator, Sequence
4
3
  from enum import Enum
4
+ from inspect import get_annotations
5
5
  from queue import Empty, Queue
6
6
  from typing import Any, TypedDict
7
7
 
@@ -9,17 +9,19 @@ import bluesky.plan_stubs as bps
9
9
  import numpy as np
10
10
  import workflows.recipe
11
11
  import workflows.transport
12
- from bluesky.protocols import Descriptor, Triggerable
12
+ from bluesky.protocols import Triggerable
13
+ from bluesky.utils import Msg
13
14
  from deepdiff import DeepDiff
14
15
  from numpy.typing import NDArray
15
16
  from ophyd_async.core import (
16
17
  AsyncStatus,
17
- HintedSignal,
18
18
  StandardReadable,
19
+ StandardReadableFormat,
19
20
  soft_signal_r_and_setter,
20
21
  )
21
22
  from workflows.transport.common_transport import CommonTransport
22
23
 
24
+ from dodal.devices.zocalo.zocalo_constants import ZOCALO_ENV
23
25
  from dodal.devices.zocalo.zocalo_interaction import _get_zocalo_connection
24
26
  from dodal.log import LOGGER
25
27
 
@@ -51,7 +53,7 @@ ZOCALO_STAGE_GROUP = "clear zocalo queue"
51
53
 
52
54
 
53
55
  class XrcResult(TypedDict):
54
- centre_of_mass: list[int]
56
+ centre_of_mass: list[float]
55
57
  max_voxel: list[int]
56
58
  max_count: int
57
59
  n_voxels: int
@@ -114,7 +116,7 @@ class ZocaloResults(StandardReadable, Triggerable):
114
116
  def __init__(
115
117
  self,
116
118
  name: str = "zocalo",
117
- zocalo_environment: str = "dev_artemis",
119
+ zocalo_environment: str = ZOCALO_ENV,
118
120
  channel: str = "xrc.i03",
119
121
  sort_key: str = DEFAULT_SORT_KEY.value,
120
122
  timeout_s: float = DEFAULT_TIMEOUT,
@@ -130,14 +132,23 @@ class ZocaloResults(StandardReadable, Triggerable):
130
132
  self.transport: CommonTransport | None = None
131
133
  self.use_cpu_and_gpu = use_cpu_and_gpu
132
134
 
133
- self.results, self._results_setter = soft_signal_r_and_setter(
134
- list[XrcResult], name="results"
135
+ self.centre_of_mass, self._com_setter = soft_signal_r_and_setter(
136
+ NDArray[np.uint64], name="centre_of_mass"
135
137
  )
136
- self.centres_of_mass, self._com_setter = soft_signal_r_and_setter(
137
- NDArray[np.uint64], name="centres_of_mass"
138
+ self.bounding_box, self._bounding_box_setter = soft_signal_r_and_setter(
139
+ NDArray[np.uint64], name="bounding_box"
138
140
  )
139
- self.bbox_sizes, self._bbox_setter = soft_signal_r_and_setter(
140
- NDArray[np.uint64], "bbox_sizes", self.name
141
+ self.max_voxel, self._max_voxel_setter = soft_signal_r_and_setter(
142
+ NDArray[np.uint64], name="max_voxel"
143
+ )
144
+ self.max_count, self._max_count_setter = soft_signal_r_and_setter(
145
+ NDArray[np.uint64], name="max_count"
146
+ )
147
+ self.n_voxels, self._n_voxels_setter = soft_signal_r_and_setter(
148
+ NDArray[np.uint64], name="n_voxels"
149
+ )
150
+ self.total_count, self._total_count_setter = soft_signal_r_and_setter(
151
+ NDArray[np.uint64], name="total_count"
141
152
  )
142
153
  self.ispyb_dcid, self._ispyb_dcid_setter = soft_signal_r_and_setter(
143
154
  int, name="ispyb_dcid"
@@ -147,22 +158,27 @@ class ZocaloResults(StandardReadable, Triggerable):
147
158
  )
148
159
  self.add_readables(
149
160
  [
150
- self.results,
151
- self.centres_of_mass,
152
- self.bbox_sizes,
161
+ self.max_voxel,
162
+ self.max_count,
163
+ self.n_voxels,
164
+ self.total_count,
165
+ self.centre_of_mass,
166
+ self.bounding_box,
153
167
  self.ispyb_dcid,
154
168
  self.ispyb_dcgid,
155
169
  ],
156
- wrapper=HintedSignal,
170
+ format=StandardReadableFormat.HINTED_SIGNAL,
157
171
  )
158
172
  super().__init__(name)
159
173
 
160
174
  async def _put_results(self, results: Sequence[XrcResult], recipe_parameters):
161
- self._results_setter(list(results))
162
175
  centres_of_mass = np.array([r["centre_of_mass"] for r in results])
163
- bbox_sizes = np.array([bbox_size(r) for r in results])
164
176
  self._com_setter(centres_of_mass)
165
- self._bbox_setter(bbox_sizes)
177
+ self._bounding_box_setter(np.array([r["bounding_box"] for r in results]))
178
+ self._max_voxel_setter(np.array([r["max_voxel"] for r in results]))
179
+ self._max_count_setter(np.array([r["max_count"] for r in results]))
180
+ self._n_voxels_setter(np.array([r["n_voxels"] for r in results]))
181
+ self._total_count_setter(np.array([r["total_count"] for r in results]))
166
182
  self._ispyb_dcid_setter(recipe_parameters["dcid"])
167
183
  self._ispyb_dcgid_setter(recipe_parameters["dcgid"])
168
184
 
@@ -286,48 +302,6 @@ class ZocaloResults(StandardReadable, Triggerable):
286
302
  finally:
287
303
  self._kickoff_run = False
288
304
 
289
- async def describe(self) -> dict[str, Descriptor]:
290
- zocalo_array_type: Descriptor = {
291
- "source": f"zocalo_service:{self.zocalo_environment}",
292
- "dtype": "array",
293
- "shape": [-1, 3],
294
- }
295
- zocalo_int_type: Descriptor = {
296
- "source": f"zocalo_service:{self.zocalo_environment}",
297
- "dtype": "integer",
298
- "shape": [0],
299
- }
300
- return OrderedDict(
301
- [
302
- (
303
- self._name + "-results",
304
- {
305
- "source": f"zocalo_service:{self.zocalo_environment}",
306
- "dtype": "array",
307
- "shape": [
308
- -1,
309
- ], # TODO describe properly - see https://github.com/DiamondLightSource/dodal/issues/253
310
- },
311
- ),
312
- (
313
- self._name + "-centres_of_mass",
314
- zocalo_array_type,
315
- ),
316
- (
317
- self._name + "-bbox_sizes",
318
- zocalo_array_type,
319
- ),
320
- (
321
- self._name + "-ispyb_dcid",
322
- zocalo_int_type,
323
- ),
324
- (
325
- self._name + "-ispyb_dcgid",
326
- zocalo_int_type,
327
- ),
328
- ],
329
- )
330
-
331
305
  def _subscribe_to_results(self):
332
306
  self.transport = _get_zocalo_connection(self.zocalo_environment)
333
307
 
@@ -364,23 +338,62 @@ class ZocaloResults(StandardReadable, Triggerable):
364
338
  )
365
339
 
366
340
 
367
- def get_processing_result(
341
+ def _corrected_xrc_result(uncorrected: XrcResult) -> XrcResult:
342
+ corrected = XrcResult(**uncorrected)
343
+ corrected["centre_of_mass"] = [
344
+ coord - 0.5 for coord in uncorrected["centre_of_mass"]
345
+ ]
346
+ return corrected
347
+
348
+
349
+ def get_full_processing_results(
368
350
  zocalo: ZocaloResults,
369
- ) -> Generator[Any, Any, tuple[np.ndarray, np.ndarray] | tuple[None, None]]:
370
- """A minimal plan which will extract the top ranked xray centre and crystal bounding
371
- box size from the zocalo results. Returns (None, None) if no crystals were found."""
372
-
373
- LOGGER.info("Getting zocalo processing results.")
374
- centres_of_mass = yield from bps.rd(zocalo.centres_of_mass, default_value=[]) # type: ignore
375
- LOGGER.debug(f"Centres of mass: {centres_of_mass}")
376
- centre_of_mass = (
377
- None
378
- if len(centres_of_mass) == 0 # type: ignore
379
- else centres_of_mass[0] - np.array([0.5, 0.5, 0.5]) # type: ignore
380
- )
381
- LOGGER.debug(f"Adjusted top centring result: {centre_of_mass}")
382
- bbox_sizes = yield from bps.rd(zocalo.bbox_sizes, default_value=[]) # type: ignore
383
- LOGGER.debug(f"Bounding box sizes: {centres_of_mass}")
384
- bbox_size = None if len(bbox_sizes) == 0 else bbox_sizes[0] # type: ignore
385
- LOGGER.debug(f"Top bbox size: {bbox_size}")
386
- return centre_of_mass, bbox_size
351
+ ) -> Generator[Msg, Any, Sequence[XrcResult]]:
352
+ """A plan that will return the raw zocalo results, ranked in descending order according to the sort key.
353
+ Returns empty list in the event no results found."""
354
+ LOGGER.info("Retrieving raw zocalo processing results")
355
+ com = yield from bps.rd(zocalo.centre_of_mass, default_value=[]) # type: ignore
356
+ max_voxel = yield from bps.rd(zocalo.max_voxel, default_value=[]) # type: ignore
357
+ max_count = yield from bps.rd(zocalo.max_count, default_value=[]) # type: ignore
358
+ n_voxels = yield from bps.rd(zocalo.n_voxels, default_value=[]) # type: ignore
359
+ total_count = yield from bps.rd(zocalo.total_count, default_value=[]) # type: ignore
360
+ bounding_box = yield from bps.rd(zocalo.bounding_box, default_value=[]) # type: ignore
361
+ return [
362
+ _corrected_xrc_result(
363
+ XrcResult(
364
+ centre_of_mass=com.tolist(),
365
+ max_voxel=mv.tolist(),
366
+ max_count=int(mc),
367
+ n_voxels=int(n),
368
+ total_count=int(tc),
369
+ bounding_box=bb.tolist(),
370
+ )
371
+ )
372
+ for com, mv, mc, n, tc, bb in zip(
373
+ com, max_voxel, max_count, n_voxels, total_count, bounding_box, strict=True
374
+ )
375
+ ]
376
+
377
+
378
+ def get_processing_results_from_event(
379
+ device_name: str, doc: dict
380
+ ) -> Sequence[XrcResult]:
381
+ """
382
+ Decode an event document into the corresponding x-ray centring results
383
+
384
+ Args:
385
+ doc A bluesky event document containing the signals read from the ZocaloResults
386
+ device_name The device name prefix to prepend to the document keys
387
+
388
+ Returns:
389
+ The list of XrcResults decoded from the event document
390
+ """
391
+ results_keys = get_annotations(XrcResult).keys()
392
+ results_dict = {k: doc["data"][f"{device_name}-{k}"] for k in results_keys}
393
+ results_values = [results_dict[k].tolist() for k in results_keys]
394
+
395
+ def create_result(*argv):
396
+ kwargs = dict(zip(results_keys, argv, strict=False))
397
+ return XrcResult(**kwargs)
398
+
399
+ return list(map(create_result, *results_values))
dodal/utils.py CHANGED
@@ -79,6 +79,10 @@ def get_beamline_name(default: str) -> str:
79
79
  return environ.get("BEAMLINE") or default
80
80
 
81
81
 
82
+ def is_test_mode() -> bool:
83
+ return environ.get("DODAL_TEST_MODE") == "true"
84
+
85
+
82
86
  def get_hostname() -> str:
83
87
  return socket.gethostname().split(".")[0]
84
88
 
@@ -1,17 +0,0 @@
1
- from ophyd import Component as Cpt
2
- from ophyd import EpicsMotor
3
- from ophyd.epics_motor import MotorBundle
4
-
5
-
6
- class VGonio(MotorBundle):
7
- x = Cpt(EpicsMotor, "PINX")
8
- z = Cpt(EpicsMotor, "PINZ")
9
- yh = Cpt(EpicsMotor, "PINYH")
10
- omega = Cpt(EpicsMotor, "OMEGA")
11
- kappa = Cpt(EpicsMotor, "KAPPA")
12
- phi = Cpt(EpicsMotor, "PHI")
13
-
14
- # Real motors
15
- xs = Cpt(EpicsMotor, "PINXS")
16
- ys = Cpt(EpicsMotor, "PINXS")
17
- zs = Cpt(EpicsMotor, "PINZS")