Coverage for src/susi/base/config/spectropol.py: 96%

27 statements  

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

1# -*- coding: utf-8 -*- 

2""" 

3Module to specify configuration for spectropolarimetry 

4 

5@author: hoelken 

6""" 

7from dataclasses import dataclass 

8 

9from ..globals import Globals 

10from ..exceptions import MissConfigurationException 

11from ..header_keys import * 

12 

13 

14@dataclass 

15class SpectroPol: 

16 # === (De)modulator === 

17 #: Number of modulation states per modulation cycle 

18 mod_cycle_frames: int = Globals.MOD_CYCLE_FRAMES 

19 

20 #: Minimum number of modulation cycles required to reliably identify the modulation states 

21 min_mod_cycles: int = 20 

22 

23 #: If modulation cycle states shall be ignored the PMU_ANGLE flag is not checked and all operations (i.e. averaging) 

24 #: will assume that all frames are equal wrt mod state. Set this to `True` when processing darks 

25 #: or framesets where the PMU was Off. 

26 ignore_mod_states: bool = False 

27 

28 #: Fail if a mod cycle has too many frames lost. If set to `False` the cycle will be ignored. 

29 fail_on_lost_frames: bool = True 

30 

31 #: Mode for demodulation. Default is 'ROW_WISE'. 

32 #: Supported: 

33 #: - 'ROW_WISE': Take the average value per row. 

34 #: - 'FULL_FRAME' Pixel by pixel 2D demodulation. 

35 demod_mode: str = 'ROW_WISE' 

36 

37 # === PMU Config === 

38 #: Indicates if PMU was active (True, default) or not (False) 

39 #: Use it e.g., to demodulate data acquired with PMU off 

40 pmu_status: bool = True 

41 

42 #: Header field that provides the angle of the Polarization Modulator wave plate (PMU) in deg (0..360) 

43 pmu_ang_field: str = HK_PMU_ANG 

44 

45 #: Header field that provides pointing errors for the angle of the Polarization Modulator 

46 #: wave plate in deg (0..360). 

47 pmu_ang_error_field: str = HK_PMU_ANG_ERR 

48 

49 #: threshold for pointing errors of the angle of the Polarization Modulator. Default=1.5 

50 pmu_ang_threshold: float = 1.5 

51 

52 #: Header field that provides the current of the Polarization Modulator wave plate (PMU) in Amps 

53 pmu_cur_field: str = HK_PMU_CUR 

54 

55 #: threshold for pointing errors of the angle of the Polarization Modulator (Default=0.1) 

56 pmu_cur_threshold: float = 0.1 

57 

58 def __repr__(self) -> str: 

59 txt = f'== {self.__class__.__name__} ==\n' 

60 txt += '\n'.join(['{:<21} = {}'.format(k, v) for k, v in self.__dict__.items()]) 

61 return txt 

62 

63 def amend_from_dict(self, data: dict): 

64 """ 

65 Overwrites the parameters with the values from the given dictionary. 

66 All instance variable names are supported as keywords. 

67 All keywords are optional, if the keyword is not present the previous value will be kept. 

68 

69 ### Params 

70 - data: The dictionary to parse. 

71 - c_name: The name of the camera to set defaults for. 

72 

73 ### Returns 

74 the created Config 

75 """ 

76 for k, v in data.items(): 

77 if not hasattr(self, k): 

78 raise MissConfigurationException(f'{self.__class__.__name__} config has no attribute {k}') 

79 setattr(self, k, v)