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

29 statements  

« prev     ^ index     » next       coverage.py v7.6.5, created at 2024-11-15 02:12 +0000

1import math 

2 

3import numpy as np 

4 

5from daiquiri.core.components import ComponentActor 

6from daiquiri.core.utils import worker 

7 

8 

9class CreatemapActor(ComponentActor): 

10 name = "createmap" 

11 

12 def method(self, **kwargs): 

13 evperbin = kwargs["spectra"]["conversion"]["scale"] 

14 offset = kwargs["spectra"]["conversion"]["zero"] 

15 

16 pts = kwargs["spectra"]["npoints"] 

17 avail = kwargs["spectra"]["npoints_avail"] 

18 

19 spectra = kwargs["spectra"]["data"] 

20 

21 def generate(): 

22 maps = [] 

23 for s in spectra: 

24 spec = [] 

25 mca = kwargs["spectra"]["data"][s]["data"] 

26 

27 for r in kwargs["rois"]: 

28 roi = [] 

29 for p in range(pts): 

30 if p < avail: 

31 start = max(0, math.floor((r["start"] - offset) / evperbin)) 

32 end = min( 

33 math.ceil((r["end"] - offset) / evperbin), len(mca[p]) 

34 ) 

35 roi.append(int(np.sum(mca[p][start:end]))) 

36 

37 else: 

38 roi.append(-1) 

39 

40 spec.append({"maproiid": r["maproiid"], "data": roi}) 

41 

42 maps.append({"det": s, "maps": spec}) 

43 

44 return maps 

45 

46 return worker(generate)