dls-dodal 1.67.0__py3-none-any.whl → 1.69.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 (86) hide show
  1. {dls_dodal-1.67.0.dist-info → dls_dodal-1.69.0.dist-info}/METADATA +2 -32
  2. {dls_dodal-1.67.0.dist-info → dls_dodal-1.69.0.dist-info}/RECORD +79 -71
  3. dodal/_version.py +2 -2
  4. dodal/beamlines/adsim.py +30 -23
  5. dodal/beamlines/b07.py +1 -1
  6. dodal/beamlines/b07_1.py +1 -1
  7. dodal/beamlines/i02_1.py +14 -42
  8. dodal/beamlines/i02_2.py +5 -11
  9. dodal/beamlines/i03.py +4 -1
  10. dodal/beamlines/i03_supervisor.py +19 -0
  11. dodal/beamlines/i04.py +74 -179
  12. dodal/beamlines/i05.py +9 -1
  13. dodal/beamlines/i06.py +1 -1
  14. dodal/beamlines/i06_1.py +24 -0
  15. dodal/beamlines/i09.py +53 -9
  16. dodal/beamlines/i09_1.py +9 -1
  17. dodal/beamlines/i09_2.py +7 -6
  18. dodal/beamlines/i10_optics.py +1 -1
  19. dodal/beamlines/i16.py +34 -0
  20. dodal/beamlines/i17.py +1 -1
  21. dodal/beamlines/i20_1.py +14 -0
  22. dodal/beamlines/i21.py +71 -4
  23. dodal/beamlines/i23.py +19 -25
  24. dodal/beamlines/i24.py +55 -105
  25. dodal/beamlines/p60.py +12 -2
  26. dodal/common/__init__.py +2 -1
  27. dodal/common/maths.py +80 -0
  28. dodal/devices/eiger.py +44 -23
  29. dodal/devices/electron_analyser/__init__.py +0 -33
  30. dodal/devices/electron_analyser/base/__init__.py +58 -0
  31. dodal/devices/electron_analyser/base/base_controller.py +84 -0
  32. dodal/devices/electron_analyser/base/base_detector.py +214 -0
  33. dodal/devices/electron_analyser/{abstract → base}/base_driver_io.py +23 -42
  34. dodal/devices/electron_analyser/{enums.py → base/base_enums.py} +0 -5
  35. dodal/devices/electron_analyser/{abstract → base}/base_region.py +48 -11
  36. dodal/devices/electron_analyser/{util.py → base/base_util.py} +1 -1
  37. dodal/devices/electron_analyser/{energy_sources.py → base/energy_sources.py} +27 -26
  38. dodal/devices/electron_analyser/specs/__init__.py +4 -4
  39. dodal/devices/electron_analyser/specs/specs_detector.py +47 -0
  40. dodal/devices/electron_analyser/specs/{driver_io.py → specs_driver_io.py} +23 -26
  41. dodal/devices/electron_analyser/specs/{region.py → specs_region.py} +4 -3
  42. dodal/devices/electron_analyser/vgscienta/__init__.py +4 -4
  43. dodal/devices/electron_analyser/vgscienta/vgscienta_detector.py +53 -0
  44. dodal/devices/electron_analyser/vgscienta/{driver_io.py → vgscienta_driver_io.py} +25 -31
  45. dodal/devices/electron_analyser/vgscienta/{region.py → vgscienta_region.py} +6 -6
  46. dodal/devices/fast_shutter.py +108 -25
  47. dodal/devices/i04/beam_centre.py +84 -0
  48. dodal/devices/i04/max_pixel.py +4 -17
  49. dodal/devices/i04/murko_results.py +18 -3
  50. dodal/devices/i09_2_shared/i09_apple2.py +0 -72
  51. dodal/devices/i10/i10_apple2.py +7 -7
  52. dodal/devices/i17/i17_apple2.py +6 -6
  53. dodal/devices/i21/__init__.py +3 -1
  54. dodal/devices/i24/commissioning_jungfrau.py +9 -10
  55. dodal/devices/insertion_device/__init__.py +62 -0
  56. dodal/devices/insertion_device/apple2_controller.py +380 -0
  57. dodal/devices/insertion_device/apple2_undulator.py +152 -481
  58. dodal/devices/insertion_device/energy.py +88 -0
  59. dodal/devices/insertion_device/energy_motor_lookup.py +1 -1
  60. dodal/devices/insertion_device/enum.py +17 -0
  61. dodal/devices/insertion_device/lookup_table_models.py +66 -36
  62. dodal/devices/insertion_device/polarisation.py +36 -0
  63. dodal/devices/oav/oav_detector.py +66 -1
  64. dodal/devices/oav/utils.py +17 -0
  65. dodal/devices/robot.py +35 -18
  66. dodal/devices/selectable_source.py +38 -0
  67. dodal/devices/zebra/zebra.py +15 -0
  68. dodal/devices/zebra/zebra_constants_mapping.py +1 -0
  69. dodal/plans/configure_arm_trigger_and_disarm_detector.py +0 -1
  70. dodal/testing/__init__.py +0 -0
  71. dodal/testing/electron_analyser/device_factory.py +4 -4
  72. dodal/testing/fixtures/devices/apple2.py +1 -1
  73. dodal/testing/fixtures/run_engine.py +4 -0
  74. dodal/devices/electron_analyser/abstract/__init__.py +0 -25
  75. dodal/devices/electron_analyser/abstract/base_detector.py +0 -63
  76. dodal/devices/electron_analyser/abstract/types.py +0 -12
  77. dodal/devices/electron_analyser/detector.py +0 -143
  78. dodal/devices/electron_analyser/specs/detector.py +0 -34
  79. dodal/devices/electron_analyser/types.py +0 -57
  80. dodal/devices/electron_analyser/vgscienta/detector.py +0 -48
  81. {dls_dodal-1.67.0.dist-info → dls_dodal-1.69.0.dist-info}/WHEEL +0 -0
  82. {dls_dodal-1.67.0.dist-info → dls_dodal-1.69.0.dist-info}/entry_points.txt +0 -0
  83. {dls_dodal-1.67.0.dist-info → dls_dodal-1.69.0.dist-info}/licenses/LICENSE +0 -0
  84. {dls_dodal-1.67.0.dist-info → dls_dodal-1.69.0.dist-info}/top_level.txt +0 -0
  85. /dodal/devices/electron_analyser/specs/{enums.py → specs_enums.py} +0 -0
  86. /dodal/devices/electron_analyser/vgscienta/{enums.py → vgscienta_enums.py} +0 -0
@@ -0,0 +1,380 @@
1
+ import abc
2
+ from math import isclose
3
+ from typing import Generic, Protocol, TypeVar
4
+
5
+ from ophyd_async.core import (
6
+ Reference,
7
+ StandardReadable,
8
+ StandardReadableFormat,
9
+ derived_signal_rw,
10
+ soft_signal_r_and_setter,
11
+ soft_signal_rw,
12
+ )
13
+
14
+ from dodal.devices.insertion_device.apple2_undulator import (
15
+ Apple2,
16
+ Apple2PhasesVal,
17
+ Apple2Val,
18
+ PhaseAxesType,
19
+ UndulatorPhaseAxes,
20
+ )
21
+ from dodal.devices.insertion_device.energy_motor_lookup import (
22
+ EnergyMotorLookup,
23
+ )
24
+ from dodal.devices.insertion_device.enum import Pol
25
+ from dodal.log import LOGGER
26
+
27
+ T = TypeVar("T")
28
+ MAXIMUM_MOVE_TIME = 550 # There is no useful movements take longer than this.
29
+ ROW_PHASE_MOTOR_TOLERANCE = 0.004
30
+ MAXIMUM_ROW_PHASE_MOTOR_POSITION = 24.0
31
+ MAXIMUM_GAP_MOTOR_POSITION = 100
32
+
33
+
34
+ class EnergyMotorConvertor(Protocol):
35
+ def __call__(self, energy: float, pol: Pol) -> float:
36
+ """Protocol to provide energy to motor position conversion"""
37
+ ...
38
+
39
+
40
+ Apple2Type = TypeVar("Apple2Type", bound=Apple2)
41
+
42
+
43
+ class Apple2Controller(abc.ABC, StandardReadable, Generic[Apple2Type]):
44
+ """
45
+
46
+ Abstract base class for controlling an Apple2 undulator device.
47
+
48
+ This class manages the undulator's gap and phase motors, and provides an interface
49
+ for controlling polarisation and energy settings. It exposes derived signals for
50
+ energy and polarisation, and handles conversion between energy/polarisation and
51
+ motor positions via a user-supplied conversion callable.
52
+
53
+ Attributes
54
+ ----------
55
+ apple2 : Reference[Apple2Type]
56
+ Reference to the Apple2 device containing gap and phase motors.
57
+ energy : derived_signal_rw
58
+ Derived signal for moving and reading back energy.
59
+ polarisation_setpoint : SignalR
60
+ Soft signal for the polarisation setpoint.
61
+ polarisation : derived_signal_rw
62
+ Hardware-backed signal for polarisation readback and control.
63
+ gap_energy_to_motor_converter : EnergyMotorConvertor
64
+ Callable that converts energy and polarisation to gap motor positions.
65
+ phase_energy_to_motor_converter : EnergyMotorConvertor
66
+ Callable that converts energy and polarisation to phase motor positions.
67
+ maximum_gap_motor_position : float
68
+ Maximum allowed position for the gap motor.
69
+ maximum_phase_motor_position : float
70
+ Maximum allowed position for the raw phase motors.
71
+
72
+ Abstract Methods
73
+ ----------------
74
+ _get_apple2_value(gap: float, phase: float) -> Apple2Val
75
+ Abstract method to return the Apple2Val used to set the apple2 with.
76
+ Notes
77
+ -----
78
+ - Subclasses must implement `_get_apple2_value` for beamline-specific logic.
79
+ - LH3 polarisation is indistinguishable from LH in hardware; special handling is provided.
80
+ - Supports multiple polarisation modes, including linear horizontal (LH), linear vertical (LV),
81
+ positive circular (PC), negative circular (NC), and linear arbitrary (LA).
82
+
83
+ """
84
+
85
+ def __init__(
86
+ self,
87
+ apple2: Apple2Type,
88
+ gap_energy_motor_converter: EnergyMotorConvertor,
89
+ phase_energy_motor_converter: EnergyMotorConvertor,
90
+ maximum_gap_motor_position: float = MAXIMUM_GAP_MOTOR_POSITION,
91
+ maximum_phase_motor_position: float = MAXIMUM_ROW_PHASE_MOTOR_POSITION,
92
+ units: str = "eV",
93
+ name: str = "",
94
+ ) -> None:
95
+ """
96
+
97
+ Parameters
98
+ ----------
99
+ apple2: Apple2
100
+ An Apple2 device.
101
+ gap_energy_motor_converter: EnergyMotorConvertor
102
+ The callable that handles the gap look up table logic for the insertion device.
103
+ phase_energy_motor_converter: EnergyMotorConvertor
104
+ The callable that handles the phase look up table logic for the insertion device.
105
+ units: str
106
+ the units of this device. Defaults to eV.
107
+ name: str
108
+ Name of the device.
109
+ """
110
+ self.apple2 = Reference(apple2)
111
+ self.gap_energy_motor_converter = gap_energy_motor_converter
112
+ self.phase_energy_motor_converter = phase_energy_motor_converter
113
+
114
+ self.maximum_gap_motor_position = maximum_gap_motor_position
115
+ self.maximum_phase_motor_position = maximum_phase_motor_position
116
+ # Store the set energy for readback.
117
+ self._energy, self._energy_set = soft_signal_r_and_setter(
118
+ float, initial_value=None, units=units
119
+ )
120
+ with self.add_children_as_readables(StandardReadableFormat.HINTED_SIGNAL):
121
+ self.energy = derived_signal_rw(
122
+ raw_to_derived=self._read_energy,
123
+ set_derived=self._set_energy,
124
+ energy=self._energy,
125
+ derived_units=units,
126
+ )
127
+
128
+ # Store the polarisation for setpoint. And provide readback for LH3.
129
+ # LH3 is a special case as it is indistinguishable from LH in the hardware.
130
+ self.polarisation_setpoint, self._polarisation_setpoint_set = (
131
+ soft_signal_r_and_setter(Pol)
132
+ )
133
+ phase = self.apple2().phase()
134
+ # check if undulator phase is unlocked.
135
+ if isinstance(phase, UndulatorPhaseAxes):
136
+ top_inner = phase.top_inner.user_readback
137
+ btm_outer = phase.btm_outer.user_readback
138
+ else:
139
+ # If locked phase axes make the locked phase 0.
140
+ top_inner = btm_outer = soft_signal_rw(float, initial_value=0.0)
141
+
142
+ with self.add_children_as_readables(StandardReadableFormat.HINTED_SIGNAL):
143
+ # Hardware backed read/write for polarisation.
144
+
145
+ self.polarisation = derived_signal_rw(
146
+ raw_to_derived=self._read_pol,
147
+ set_derived=self._set_pol,
148
+ pol=self.polarisation_setpoint,
149
+ top_outer=phase.top_outer.user_readback,
150
+ top_inner=top_inner,
151
+ btm_inner=phase.btm_inner.user_readback,
152
+ btm_outer=btm_outer,
153
+ gap=self.apple2().gap().user_readback,
154
+ )
155
+ super().__init__(name)
156
+
157
+ @abc.abstractmethod
158
+ def _get_apple2_value(self, gap: float, phase: float, pol: Pol) -> Apple2Val:
159
+ """
160
+ This method should be implemented by the beamline specific ID class as the
161
+ motor positions will be different for each beamline depending on the
162
+ undulator design.
163
+ """
164
+
165
+ async def _set_motors_from_energy_and_polarisation(
166
+ self, energy: float, pol: Pol
167
+ ) -> None:
168
+ """Set the undulator motors for a given energy and polarisation."""
169
+ gap = self.gap_energy_motor_converter(energy=energy, pol=pol)
170
+ phase = self.phase_energy_motor_converter(energy=energy, pol=pol)
171
+ apple2_val = self._get_apple2_value(gap, phase, pol)
172
+ LOGGER.info(f"Setting polarisation to {pol}, with values: {apple2_val}")
173
+ await self.apple2().set(id_motor_values=apple2_val)
174
+
175
+ async def _set_energy(self, energy: float) -> None:
176
+ pol = await self._check_and_get_pol_setpoint()
177
+ await self._set_motors_from_energy_and_polarisation(energy, pol)
178
+ self._energy_set(energy)
179
+
180
+ def _read_energy(self, energy: float) -> float:
181
+ """Readback for energy is just the set value."""
182
+ return energy
183
+
184
+ async def _check_and_get_pol_setpoint(self) -> Pol:
185
+ """
186
+ Check the polarisation setpoint and if it is NONE try to read it from
187
+ hardware.
188
+ """
189
+ pol = await self.polarisation_setpoint.get_value()
190
+
191
+ if pol == Pol.NONE:
192
+ LOGGER.warning(
193
+ "Found no setpoint for polarisation. Attempting to"
194
+ " determine polarisation from hardware..."
195
+ )
196
+ pol = await self.polarisation.get_value()
197
+ if pol == Pol.NONE:
198
+ raise ValueError(
199
+ f"Polarisation cannot be determined from hardware for {self.name}"
200
+ )
201
+ self._polarisation_setpoint_set(pol)
202
+ return pol
203
+
204
+ async def _set_pol(
205
+ self,
206
+ value: Pol,
207
+ ) -> None:
208
+ # This changes the pol setpoint and then changes polarisation via set energy.
209
+ self._polarisation_setpoint_set(value)
210
+ await self.energy.set(await self.energy.get_value(), timeout=MAXIMUM_MOVE_TIME)
211
+
212
+ def _read_pol(
213
+ self,
214
+ pol: Pol,
215
+ top_outer: float,
216
+ top_inner: float,
217
+ btm_inner: float,
218
+ btm_outer: float,
219
+ gap: float,
220
+ ) -> Pol:
221
+ LOGGER.info(
222
+ f"Reading polarisation setpoint from hardware: "
223
+ f"top_outer={top_outer}, top_inner={top_inner}, "
224
+ f"btm_inner={btm_inner}, btm_outer={btm_outer}, gap={gap}."
225
+ )
226
+
227
+ read_pol, _ = self.determine_phase_from_hardware(
228
+ top_outer, top_inner, btm_inner, btm_outer, gap
229
+ )
230
+ # LH3 is indistinguishable from LH see determine_phase_from_hardware's docString
231
+ # so we return LH3 if the setpoint is LH3 and the readback is LH.
232
+ if pol == Pol.LH3 and read_pol == Pol.LH:
233
+ LOGGER.info(
234
+ "The hardware cannot distinguish between LH and LH3."
235
+ " Returning the last commanded polarisation value"
236
+ )
237
+ return Pol.LH3
238
+
239
+ return read_pol
240
+
241
+ def determine_phase_from_hardware(
242
+ self,
243
+ top_outer: float,
244
+ top_inner: float,
245
+ btm_inner: float,
246
+ btm_outer: float,
247
+ gap: float,
248
+ ) -> tuple[Pol, float]:
249
+ """
250
+ Determine polarisation and phase value using motor position patterns.
251
+ However there is no way to return lh3 polarisation or higher harmonic setting.
252
+ (May be for future one can use the inverse poly to work out the energy and try to match it with the current energy
253
+ to workout the polarisation but during my test the inverse poly is too unstable for general use.)
254
+ """
255
+ if gap > self.maximum_gap_motor_position:
256
+ raise RuntimeError(
257
+ f"{self.name} is not in use, close gap or set polarisation to use this ID"
258
+ )
259
+
260
+ if all(
261
+ isclose(x, 0.0, abs_tol=ROW_PHASE_MOTOR_TOLERANCE)
262
+ for x in [top_outer, top_inner, btm_inner, btm_outer]
263
+ ):
264
+ LOGGER.info("Determined polarisation: LH (Linear Horizontal).")
265
+ return Pol.LH, 0.0
266
+ if (
267
+ isclose(
268
+ top_outer,
269
+ self.maximum_phase_motor_position,
270
+ abs_tol=ROW_PHASE_MOTOR_TOLERANCE,
271
+ )
272
+ and isclose(top_inner, 0.0, abs_tol=ROW_PHASE_MOTOR_TOLERANCE)
273
+ and isclose(
274
+ btm_inner,
275
+ self.maximum_phase_motor_position,
276
+ abs_tol=ROW_PHASE_MOTOR_TOLERANCE,
277
+ )
278
+ and isclose(btm_outer, 0.0, abs_tol=ROW_PHASE_MOTOR_TOLERANCE)
279
+ ):
280
+ LOGGER.info("Determined polarisation: LV (Linear Vertical).")
281
+ return Pol.LV, self.maximum_phase_motor_position
282
+ if (
283
+ isclose(top_outer, btm_inner, abs_tol=ROW_PHASE_MOTOR_TOLERANCE)
284
+ and top_outer > 0.0
285
+ and isclose(top_inner, 0.0, abs_tol=ROW_PHASE_MOTOR_TOLERANCE)
286
+ and isclose(btm_outer, 0.0, abs_tol=ROW_PHASE_MOTOR_TOLERANCE)
287
+ ):
288
+ LOGGER.info("Determined polarisation: PC (Positive Circular).")
289
+ return Pol.PC, top_outer
290
+ if (
291
+ isclose(top_outer, btm_inner, abs_tol=ROW_PHASE_MOTOR_TOLERANCE)
292
+ and top_outer < 0.0
293
+ and isclose(top_inner, 0.0, abs_tol=ROW_PHASE_MOTOR_TOLERANCE)
294
+ and isclose(btm_outer, 0.0, abs_tol=ROW_PHASE_MOTOR_TOLERANCE)
295
+ ):
296
+ LOGGER.info("Determined polarisation: NC (Negative Circular).")
297
+ return Pol.NC, top_outer
298
+ if (
299
+ isclose(top_outer, -btm_inner, abs_tol=ROW_PHASE_MOTOR_TOLERANCE)
300
+ and isclose(top_inner, 0.0, abs_tol=ROW_PHASE_MOTOR_TOLERANCE)
301
+ and isclose(btm_outer, 0.0, abs_tol=ROW_PHASE_MOTOR_TOLERANCE)
302
+ ):
303
+ LOGGER.info("Determined polarisation: LA (Positive Linear Arbitrary).")
304
+ return Pol.LA, top_outer
305
+ if (
306
+ isclose(top_inner, -btm_outer, abs_tol=ROW_PHASE_MOTOR_TOLERANCE)
307
+ and isclose(top_outer, 0.0, abs_tol=ROW_PHASE_MOTOR_TOLERANCE)
308
+ and isclose(btm_inner, 0.0, abs_tol=ROW_PHASE_MOTOR_TOLERANCE)
309
+ ):
310
+ LOGGER.info("Determined polarisation: LA (Negative Linear Arbitrary).")
311
+ return Pol.LA, top_inner
312
+
313
+ LOGGER.warning("Unable to determine polarisation. Defaulting to NONE.")
314
+ return Pol.NONE, 0.0
315
+
316
+
317
+ class Apple2EnforceLHMoveController(
318
+ Apple2Controller[Apple2[PhaseAxesType]], Generic[PhaseAxesType]
319
+ ):
320
+ """The latest Apple2 version allows unrestricted motor movement.
321
+ However, because of the high forces involved in polarization changes,
322
+ all movements must be performed using the Linear Horizontal (LH) mode.
323
+ A look-up table must also be used to determine the highest energy that can
324
+ be reached in LH mode."""
325
+
326
+ def __init__(
327
+ self,
328
+ apple2: Apple2[PhaseAxesType],
329
+ gap_energy_motor_lut: EnergyMotorLookup,
330
+ phase_energy_motor_lut: EnergyMotorLookup,
331
+ units: str = "eV",
332
+ name: str = "",
333
+ ) -> None:
334
+ self.gap_energy_motor_lu = gap_energy_motor_lut
335
+ self.phase_energy_motor_lu = phase_energy_motor_lut
336
+ super().__init__(
337
+ apple2=apple2,
338
+ gap_energy_motor_converter=gap_energy_motor_lut.find_value_in_lookup_table,
339
+ phase_energy_motor_converter=phase_energy_motor_lut.find_value_in_lookup_table,
340
+ units=units,
341
+ name=name,
342
+ )
343
+
344
+ def _get_apple2_value(self, gap: float, phase: float, pol: Pol) -> Apple2Val:
345
+ apple2_val = Apple2Val(
346
+ gap=gap,
347
+ phase=Apple2PhasesVal(
348
+ top_outer=phase,
349
+ top_inner=0.0,
350
+ btm_inner=phase,
351
+ btm_outer=0.0,
352
+ ),
353
+ )
354
+ LOGGER.info(f"Getting apple2 value for pol={pol}, gap={gap}, phase={phase}.")
355
+ LOGGER.info(f"Apple2 motor values: {apple2_val}.")
356
+
357
+ return apple2_val
358
+
359
+ async def _set_pol(
360
+ self,
361
+ value: Pol,
362
+ ) -> None:
363
+ # I09/I21 require all polarisation change to go via LH.
364
+ current_pol = await self.polarisation.get_value()
365
+ if current_pol == value:
366
+ LOGGER.info(f"Polarisation already at {value}")
367
+ else:
368
+ target_energy = await self.energy.get_value()
369
+ if (value is not Pol.LH) and (current_pol is not Pol.LH):
370
+ self._polarisation_setpoint_set(Pol.LH)
371
+ max_lh_energy = float(
372
+ self.gap_energy_motor_lu.lut.root[Pol("lh")].max_energy
373
+ )
374
+ lh_setpoint = (
375
+ max_lh_energy if target_energy > max_lh_energy else target_energy
376
+ )
377
+ LOGGER.info(f"Changing polarisation to {value} via {Pol.LH}")
378
+ await self.energy.set(lh_setpoint, timeout=MAXIMUM_MOVE_TIME)
379
+ self._polarisation_setpoint_set(value)
380
+ await self.energy.set(target_energy, timeout=MAXIMUM_MOVE_TIME)