Coverage for /opt/conda/envs/apienv/lib/python3.10/site-packages/daiquiri/core/hardware/bliss/tomoflatmotion.py: 0%

41 statements  

« prev     ^ index     » next       coverage.py v7.6.4, created at 2024-11-14 02:13 +0000

1#!/usr/bin/env python 

2# -*- coding: utf-8 -*- 

3from daiquiri.core.hardware.abstract.tomoflatmotion import ( 

4 TomoFlatMotion as AbstractTomoFlatMotion, 

5) 

6from daiquiri.core.hardware.abstract import HardwareProperty 

7from daiquiri.core.hardware.bliss.object import BlissObject, ObjectRefListProperty 

8from tomo.controllers.flat_motion import FlatMotion 

9from bliss.common.axis import Axis 

10 

11import logging 

12 

13logger = logging.getLogger(__name__) 

14 

15 

16class _MotionProperty(HardwareProperty): 

17 def translate_from(self, values: list[FlatMotion]): 

18 if values is None: 

19 return None 

20 result = [] 

21 for v in values: 

22 meta = v._asdict() 

23 name = meta.pop("axis_name") 

24 meta["axisRef"] = f"hardware:{name}" 

25 result.append(meta) 

26 return result 

27 

28 

29class _AvailableAxesProperty(ObjectRefListProperty): 

30 def translate_from(self, values: list[Axis]): 

31 if values is None: 

32 return None 

33 result = [] 

34 for v in values: 

35 result.append(f"hardware:{v.name}") 

36 return result 

37 

38 

39class TomoFlatMotion(BlissObject, AbstractTomoFlatMotion): 

40 def _get_state(self): 

41 return "READY" 

42 

43 def _get_motion(self): 

44 return self._object._out_beam_motion 

45 

46 PROPERTY_MAP = { 

47 "state": HardwareProperty("state", getter=_get_state), 

48 "settle_time": HardwareProperty("settle_time"), 

49 "power_onoff": HardwareProperty("power_onoff"), 

50 "move_in_parallel": HardwareProperty("move_in_parallel"), 

51 "available_axes": _AvailableAxesProperty("_available_motors", compose=True), 

52 "motion": _MotionProperty("out_beam_motion", getter=_get_motion), 

53 } 

54 

55 # Call moves with wait=False 

56 def _call_update_axis(self, value: dict, **kwargs): 

57 logger.debug(f"_call_update_axis {self.name()} {value} {kwargs}") 

58 axis_name = value.pop("axis_ref")[9:] 

59 absolute_position = value.pop("absolute_position", None) 

60 relative_position = value.pop("relative_position", None) 

61 if value != {}: 

62 raise ValueError(f"Unused keys: {value}") 

63 self._object.update_axis( 

64 axis_name=axis_name, 

65 absolute_position=absolute_position, 

66 relative_position=relative_position, 

67 ) 

68 

69 

70Default = TomoFlatMotion