Coverage for src/spectroflat/smile/smile_correction.py: 84%

31 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2024-03-28 07:59 +0000

1#!/usr/bin/env python3 

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

3""" 

4provides SmileCorrector, RowCorrector 

5 

6@author: hoelken 

7""" 

8import numpy as np 

9 

10from .offset_map import OffsetMap 

11from ..base import Logging 

12from ..shift.img_rotation import RotationCorrection 

13 

14logger = Logging.get_logger() 

15 

16 

17class SmileCorrector: 

18 """ 

19 ## SmileCorrector 

20 

21 Smile correction super class 

22 """ 

23 

24 def __init__(self, smap: OffsetMap, img: np.array, mod_state: int = None): 

25 #: The `SmileMap` to apply 

26 self._smap = smap 

27 #: The `Fits` object of the image to correct 

28 self._img = img 

29 #: The modulation state to apply. Set to None to apply squashed map 

30 self._mod_state = mod_state 

31 #: The smile corrected image data 

32 self.result = None 

33 

34 def run(self): 

35 self._derotate() 

36 self._squash_smap() 

37 self._correct_smile() 

38 return self 

39 

40 def _derotate(self): 

41 if 'Rotation' not in self._smap.header: 

42 return 

43 

44 angle = float(self._smap.header['Rotation']) 

45 if angle == 0: 

46 return 

47 

48 logger.debug('De-rotating by %0.5f [deg]', angle) 

49 self._img = RotationCorrection(self._img, angle).bicubic() 

50 

51 def _squash_smap(self): 

52 if self._mod_state is not None: 

53 return 

54 self._smap.squash() 

55 

56 def _correct_smile(self): 

57 raise NotImplemented('Please use derived class!')