Coverage for src/susi/reduc/validation/shape_check.py: 100%

30 statements  

« prev     ^ index     » next       coverage.py v7.5.0, created at 2025-06-13 14:15 +0000

1#!/usr/bin/env python3 

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

3""" 

4module provides ShapeCheck 

5 

6@author: hoelken 

7""" 

8from ...base import Logging 

9 

10logger = Logging.get_logger() 

11 

12 

13class ShapeCheck: 

14 """ 

15 ## ShapeCheck 

16 Validation for the data shape (ROI) to load. 

17 """ 

18 

19 def __init__(self, config, reference): 

20 #: The Config 

21 self.config = config 

22 #: The reference object providing the ROI metadata 

23 self.reference = reference 

24 #: shape from the reference object 

25 self.reference_shape = [] 

26 #: Validation result 

27 self.valid = False 

28 

29 def validate(self, autocorrect=False) -> bool: 

30 """ 

31 :param autocorrect: Flag to determine if autocorrection shall be applied 

32 

33 :return: True, if the shape is valid 

34 """ 

35 if not self.reference_shape: 

36 self.__build_reference() 

37 self.__check_shape() 

38 autocorrect and self.__correct() 

39 return self.valid 

40 

41 def __build_reference(self): 

42 for pair in self.config.base.roi_keys: 

43 start = self.reference.value_of(pair[0]) 

44 stop = self.reference.value_of(pair[1]) 

45 self.reference_shape.append(slice(start, stop)) 

46 

47 def __check_shape(self): 

48 self.valid = self.config.cam.data_shape == self.reference_shape 

49 if not self.valid: 

50 logger.debug("Configured shape '%s' doesn't match ROI '%s'", 

51 self.config.cam.data_shape, self.reference_shape) 

52 

53 def __correct(self): 

54 if self.valid: 

55 return 

56 

57 logger.warning('Adjusting img shape to match modulation matrix') 

58 self.config.cam.data_shape = self.reference_shape 

59 self.valid = True