Coverage for /opt/conda/envs/apienv/lib/python3.10/site-packages/daiquiri/implementors/imageviewer/beamlineparams.py: 79%

38 statements  

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

1from marshmallow import Schema, fields, validate 

2 

3from daiquiri.core.components.params import ParamHandler, ParamsHandler, ParamSchema 

4 

5from bliss.config.static import get_config 

6 

7cfg = get_config() 

8 

9 

10class FastShutterParam(ParamHandler): 

11 def before(self, value): 

12 if value: 

13 shut = cfg.get("safshut") 

14 shut.open() 

15 

16 def after(self, value): 

17 if value: 

18 shut = cfg.get("safshut") 

19 shut.close() 

20 

21 

22class DetectorDistanceParam(ParamHandler): 

23 def before(self, value): 

24 det = cfg.get("omega") 

25 det.move(value) 

26 

27 

28class BeamlineParamsHandler(ParamsHandler): 

29 fast_shutter = FastShutterParam() 

30 detector_distance = DetectorDistanceParam() 

31 

32 

33class DiodeSchema(Schema): 

34 name = fields.Str(metadata={"enum": ["d1", "d2", "d3"]}) 

35 value = fields.Int() 

36 

37 

38class ArbMotorSchema(Schema): 

39 name = fields.Str(metadata={"enum": ["x", "y", "z"]}) 

40 value = fields.Int() 

41 

42 

43# parallelise these moves 

44class BeamlineParamsSchema(ParamSchema): 

45 handler = BeamlineParamsHandler() 

46 

47 detector_distance = fields.Float( 

48 validate=validate.Range(min=20, max=400), 

49 metadata={ 

50 "title": "Detector Distance", 

51 "unit": "mm", 

52 "description": "Move the detector to specified distance", 

53 }, 

54 ) 

55 

56 fast_shutter = fields.Bool( 

57 metadata={ 

58 "title": "Fast Shutter", 

59 "description": "Open fast shutter before and close after", 

60 } 

61 ) 

62 

63 attenuators = fields.Str( 

64 metadata={"title": "Attenuators", "enum": ["0.1mm_al", "0.5mm_al", "0.7mm_al"]} 

65 ) 

66 

67 pinhole = fields.Str(metadata={"title": "Pin Hole", "enum": ["10um", "5um", "1um"]}) 

68 

69 light = fields.Bool(metadata={"title": "Turn off Light"}) 

70 

71 diode_gain = fields.List( 

72 fields.Nested(DiodeSchema), metadata={"title": "Diode Gains"} 

73 ) 

74 

75 arb_motor = fields.List(fields.Nested(ArbMotorSchema), metadata={"title": "Motors"}) 

76 

77 energy = fields.Float(metadata={"title": "Energy", "unit": "keV"}) 

78 

79 class Meta: 

80 uischema = { 

81 "arb_motor": {"ui:field": "arrayTable"}, 

82 "diode_gain": {"ui:field": "arrayTable"}, 

83 }