Coverage for /opt/conda/envs/apienv/lib/python3.10/site-packages/daiquiri/implementors/samplescan/scan2.py: 58%

36 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 -*- 

3import gevent 

4from marshmallow import fields 

5import mmh3 

6 

7from bliss.config.static import get_config 

8from bliss.scanning.scan import ScanState 

9 

10from daiquiri.core.schema.validators import OneOf 

11from daiquiri.core.components import ( 

12 ComponentActor, 

13 ComponentActorSchema, 

14 ComponentActorKilled, 

15) 

16from daiquiri.core.hardware.bliss.session import * 

17from daiquiri.core.hardware.blissdata.helpers import get_scan_key 

18 

19 

20class Scan2Schema(ComponentActorSchema): 

21 sampleid = fields.Int(required=True) 

22 motor_start = fields.Float(required=True, metadata={"title": "Start Position"}) 

23 motor_end = fields.Float(required=True, metadata={"title": "End Position"}) 

24 detectors = fields.List( 

25 OneOf(["diode", "simu1", "lima_simulator"]), 

26 required=True, 

27 metadata={"title": "Detectors", "uniqueItems": True, "minItems": 1}, 

28 ) 

29 

30 class Meta: 

31 uischema = {"sampleid": {"classNames": "hidden-row", "ui:widget": "hidden"}} 

32 

33 

34class Scan2Actor(ComponentActor): 

35 schema = Scan2Schema 

36 name = "scan2" 

37 saving_args = {"data_filename": "{sampleid.name}_scan{datacollectionid}"} 

38 

39 def method(self, **kwargs): 

40 cfg = get_config() 

41 

42 kwargs["motor"] = cfg.get("omega") 

43 kwargs["npoints"] = 5 

44 kwargs["time"] = 1 

45 kwargs["detectors"] = [cfg.get(d) for d in kwargs["detectors"]] 

46 

47 scan = simple_scan(run=False, **kwargs) 

48 

49 greenlet = gevent.spawn(scan.run) 

50 

51 scan.wait_state(ScanState.STARTING) 

52 kwargs["update_datacollection"]( 

53 self, 

54 datacollectionnumber=mmh3.hash(get_scan_key(scan)) & 0xFFFFFFFF, 

55 imagecontainersubpath="1.1/measurement", 

56 numberofimages=kwargs["npoints"], 

57 exposuretime=kwargs["time"], 

58 ) 

59 

60 try: 

61 greenlet.join() 

62 except ComponentActorKilled as e: 

63 greenlet.kill() 

64 raise e 

65 

66 greenlet.get()