Coverage for src/susi/base/globals.py: 93%

54 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 for sunrise-3 specific global values 

5 

6@author: hoelken, iglesias 

7""" 

8from enum import Enum 

9 

10SEC2US = 1e6 

11SEC2MS = 1e3 

12 

13 

14class Cam(Enum): 

15 """Enum to translate human-readable camera names to internal identifiers""" 

16 

17 def __init__(self, internal_name, internal_id, description): 

18 self.internal_name = internal_name 

19 self.internal_id = internal_id 

20 self.description = description 

21 

22 SP1 = 'cam1', 'US550', 'SP1: Polarimetric Channel 1' 

23 SP2 = 'cam2', 'US560', 'SP2: Polarimetric Channel 2' 

24 SJ = 'cam3', 'US540', 'SJ: Slit Jaw Camera' 

25 

26 @staticmethod 

27 def all(attr: str = 'internal_name'): 

28 return [getattr(cam, attr) for cam in [Cam.SP1, Cam.SP2, Cam.SJ]] 

29 

30 @staticmethod 

31 def by_name(name: str): 

32 return next(c for c in [Cam.SP1, Cam.SP2, Cam.SJ] if c.internal_name == name) 

33 

34 @staticmethod 

35 def sp_to_cam_name(human_readable_name: str): 

36 cam_map = {'SP1': Cam.SP1, 'SP2': Cam.SP2, 'SJ': Cam.SJ} 

37 return cam_map[human_readable_name].internal_name 

38 

39 

40class Jobs(Enum): 

41 """Enum to define pipeline job identifiers""" 

42 

43 #: Average -> bin frames 

44 AVRG = 10 

45 #: Dark Field Correction 

46 DARK = 20 

47 #: Demodulation -> Retrieve STOKES parameters 

48 DEMOD = 30 

49 #: Flat Field Correction 

50 FLAT = 40 

51 #: Shielded PX Correction 

52 SHIPX = 50 

53 #: Hot PX Correction 

54 HOTPX = 60 

55 

56 

57class IOSpeed(Enum): 

58 """Enum to define the number of workers to use when reading files""" 

59 

60 SSD = 5 

61 FAST = 15 

62 MEDIUM = 20 

63 SLOW = 32 

64 TORTOISE = 64 

65 

66 

67class Globals: 

68 """ 

69 Class to access static Sunrise-3 specific global values 

70 """ 

71 

72 #: Number of frames that belong to a complete polarimetric modulation cycle. 

73 MOD_CYCLE_FRAMES = 12 

74 

75 #: dictionary of lid areas per camera 

76 ROIS = {Cam.SP1: [slice(50, 1970), slice(70, 1840)], Cam.SP2: [slice(50, 1970), slice(100, 1840)]} 

77 

78 #: PMU Rotation period in seconds 

79 PMU_ROT_PERIOD = 0.512 

80 #: default SUSI frame time [sec] 

81 SAMP_S = PMU_ROT_PERIOD / (2 * MOD_CYCLE_FRAMES) 

82 # default SUSI frame time [ms] 

83 SAMP = SAMP_S * SEC2MS 

84 

85 # Number of max px per dimension 

86 MAX_PX = 2048 

87 

88 # Hot pixel correction modes 

89 # dark: Dark frames 

90 # modm: modulation matrix 

91 # flat: Flat field frames TODO, test 

92 # slitjaw: Slitjaw frames TODO, test 

93 # sci: Solar data TODO, test 

94 # The parameters are: 

95 # std: Criterion to identified statistical outliers 

96 # win: size of the median filter window [x,y] 

97 # use_edges: Set to also filter the edges (border row and col). It is slower 

98 CAM_HOT_PX_MODES = { 

99 'dark': {'std': 5, 'win': [3, 3], 'use_edges': True}, 

100 'modm': {'std': 5, 'win': [3, 3], 'use_edges': True}, 

101 'flat': {'std': 5, 'win': [3, 3], 'use_edges': True}, 

102 'slitjaw': {'std': 5, 'win': [3, 3], 'use_edges': True}, 

103 'sci': {'std': 5, 'win': [3, 3], 'use_edges': True}, 

104 } 

105 

106 PIPELINE = { 

107 # NOTE The default output directory and level definition can be modified by 

108 # Config.data.custom_out_level and Config.data.custom_pipeline_dir 

109 # 

110 # Internal pipeline for calibration scripts (e.g., dark, flat) that provides basic camera calibration 

111 'calib': [['C', 'X']], 

112 # Internal pipeline for flat reduction to level 3 

113 'calib_flat_lvl3': [['F', 'M'], ['S']], 

114 # Internal pipeline for basic reduction, provides camera and binning only 

115 'pipeline_quick_look': [['C', 'X', 'B']], 

116 # Low Res Spectrograph pipeline (official). 

117 # V00.01: Initial version with basic flatfielding, desmiling and demodulation 

118 'pipeline_LP_V00-01': [['C'], ['X', 'F', 'B', 'M', 'D']], 

119 # V00.02: Improved version with basic dual beam demodulation 

120 'pipeline_LP_V00-02': [['C'], ['X', 'F', 'M', 'B', 'D']], 

121 # V01.01: Improved version with moving flat field correction 

122 'pipeline_LP_V01-01': [['C'], ['X', 'F', 'M'], ['S'], ['B', 'D']], 

123 # Developer polarimeter (single beam). 

124 # V00.01: Initial version with basic single beam demodulation 

125 'pipeline_DP_V00-01': [['C'], ['X', 'D', 'B']], 

126 # Generic and variable developer pipeline: Adjust to your needs (do not change name). 

127 'pipeline_dev': [['C'], ['X', 'F', 'M', 'B'], ['D']], 

128 } 

129 

130 # TODO move all HK related stuff to a separate file 

131 UNITMAP = { 

132 "F2_Mech_Position": "", # After translation 

133 # Add more mappings as needed 

134 } 

135 

136 F2_MECH_POSITION_MAP = { 

137 35: "USAF", 

138 80: "Polka-Dot", 

139 125: "Random-Dot", 

140 170: "Random-Dot-Mosaic", 

141 215: "Open", 

142 260: "Dark", 

143 305: "Straylight", 

144 350: "Grid", 

145 0: "Init", 

146 360: "Init", 

147 } 

148 

149 POINTING_STATE_MAPPING = { 

150 0: 'Pointing Stable', 

151 1: 'Curtain open safe', 

152 2: 'Tracking', 

153 3: 'Commanding okay', 

154 4: 'Sun XCEN/YCEN valid', 

155 5: 'CWS unlock', 

156 6: 'Elevation Brake locked', 

157 7: 'Flatfield Mode', 

158 } 

159 

160 A0_RUNMODENR_MAPPING = {0: 'Open', 1: 'Tip_Tilt', 2: 'Focus', 3: 'Tip_Tilt_and_Focus', 111: '111', -1: '-1'} 

161 

162 Data_Type_Map = {"F2_Mech_Position": "str", "FwPos": "str"} # After translation, it will be a string 

163 CUSTOM_DEFAULT_MODES = { 

164 'linear': ['ScuCpuUsageCore3', 'f'], 

165 'nn': ['CamCurrentP5V'], 

166 'last': ['FwPos', 'F2_Mech_Position', 'PointingState', 'AO_runmodenr'], 

167 } 

168 TRUSTED_FILE_DUPLI_KEYS = { 

169 'icu_f2cu_reduced.csv': ['FwPos'], 

170 'susi_scu_reduced.csv': ['FwPosExp', 'SmPos', 'SmStatus', 'GmTemp', 'GmAngU', 'GmStatusExt'], 

171 'icu_sst_reduced.csv': ['AO_runmodenr'], 

172 'sunrise3_pointing_data.csv': ['PointingState', 'XCEN', 'YCEN'], 

173 } 

174 

175 @staticmethod 

176 def pipeline(key: str) -> list: 

177 """Get the list of modules (list of blocks) that compose the pipeline""" 

178 return Globals.PIPELINE[key]