lidar_correction_ghk.py

changeset 19
40d55af749b6
parent 16
313ac320b970
child 21
857c95060313
equal deleted inserted replaced
18:b66dbbe6c4fa 19:40d55af749b6
17 17
18 Equation reference: http://www.atmos-meas-tech-discuss.net/amt-2015-338/amt-2015-338.pdf 18 Equation reference: http://www.atmos-meas-tech-discuss.net/amt-2015-338/amt-2015-338.pdf
19 With equations code from Appendix C 19 With equations code from Appendix C
20 Python 3.4.2 20 Python 3.4.2
21 """ 21 """
22 #!/usr/bin/env python3 22 # !/usr/bin/env python3
23 23
24 # Comment: The code works with Python 2.7 with the help of following line, which enables Python2 to correctly interpret the Python 3 print statements. 24 # Comment: The code works with Python 2.7 with the help of following line, which enables Python2 to correctly interpret the Python 3 print statements.
25 from __future__ import print_function 25 from __future__ import print_function
26 #import math 26
27 import os
28 import sys
29
27 import numpy as np 30 import numpy as np
28 import sys
29 import os
30 31
31 # Comment: the seaborn library makes nicer plots, but the code works also without it. 32 # Comment: the seaborn library makes nicer plots, but the code works also without it.
32 try: 33 try:
33 import seaborn as sns 34 import seaborn as sns
35
34 sns_loaded = True 36 sns_loaded = True
35 except ImportError: 37 except ImportError:
36 sns_loaded = False 38 sns_loaded = False
37 39
38 import matplotlib.pyplot as plt 40 import matplotlib.pyplot as plt
39 from time import clock 41 from time import clock
40 42
41 #from matplotlib.backends.backend_pdf import PdfPages 43 # from matplotlib.backends.backend_pdf import PdfPages
42 #pdffile = '{}.pdf'.format('path') 44 # pdffile = '{}.pdf'.format('path')
43 #pp = PdfPages(pdffile) 45 # pp = PdfPages(pdffile)
44 ## pp.savefig can be called multiple times to save to multiple pages 46 ## pp.savefig can be called multiple times to save to multiple pages
45 #pp.savefig() 47 # pp.savefig()
46 #pp.close() 48 # pp.close()
47 49
48 from contextlib import contextmanager 50 from contextlib import contextmanager
51
52
49 @contextmanager 53 @contextmanager
50 def redirect_stdout(new_target): 54 def redirect_stdout(new_target):
51 old_target, sys.stdout = sys.stdout, new_target # replace sys.stdout 55 old_target, sys.stdout = sys.stdout, new_target # replace sys.stdout
52 try: 56 try:
53 yield new_target # run some code with the replaced stdout 57 yield new_target # run some code with the replaced stdout
54 finally: 58 finally:
55 sys.stdout.flush() 59 sys.stdout.flush()
56 sys.stdout = old_target # restore to the previous value 60 sys.stdout = old_target # restore to the previous value
61
62
57 ''' 63 '''
58 real_raw_input = vars(__builtins__).get('raw_input',input) 64 real_raw_input = vars(__builtins__).get('raw_input',input)
59 ''' 65 '''
60 try: 66 try:
61 import __builtin__ 67 import __builtin__
68
62 input = getattr(__builtin__, 'raw_input') 69 input = getattr(__builtin__, 'raw_input')
63 except (ImportError, AttributeError): 70 except (ImportError, AttributeError):
64 pass 71 pass
65 72
66 from distutils.util import strtobool 73 from distutils.util import strtobool
74
75
67 def user_yes_no_query(question): 76 def user_yes_no_query(question):
68 sys.stdout.write('%s [y/n]\n' % question) 77 sys.stdout.write('%s [y/n]\n' % question)
69 while True: 78 while True:
70 try: 79 try:
71 return strtobool(input().lower()) 80 return strtobool(input().lower())
72 except ValueError: 81 except ValueError:
73 sys.stdout.write('Please respond with \'y\' or \'n\'.\n') 82 sys.stdout.write('Please respond with \'y\' or \'n\'.\n')
74 83
75 #if user_yes_no_query('want to exit?') == 1: sys.exit() 84
85 # if user_yes_no_query('want to exit?') == 1: sys.exit()
76 86
77 abspath = os.path.abspath(__file__) 87 abspath = os.path.abspath(__file__)
78 dname = os.path.dirname(abspath) 88 dname = os.path.dirname(abspath)
79 fname = os.path.basename(abspath) 89 fname = os.path.basename(abspath)
80 os.chdir(dname) 90 os.chdir(dname)
81 91
82 #PrintToOutputFile = True 92 # PrintToOutputFile = True
83 93
84 sqr05 = 0.5**0.5 94 sqr05 = 0.5 ** 0.5
85 95
86 # Do you want to calculate the errors? If not, just the GHK-parameters are determined. 96 # Do you want to calculate the errors? If not, just the GHK-parameters are determined.
87 Error_Calc = True 97 Error_Calc = True
88 # ---- Initial definition of variables; the actual values will be read in with exec(open('./optic_input.py').read()) below 98 # ---- Initial definition of variables; the actual values will be read in with exec(open('./optic_input.py').read()) below
89 LID = "internal" 99 LID = "internal"
90 EID = "internal" 100 EID = "internal"
91 # --- IL Laser IL and +-Uncertainty 101 # --- IL Laser IL and +-Uncertainty
92 bL = 1. #degree of linear polarization; default 1 102 bL = 1. # degree of linear polarization; default 1
93 RotL, dRotL, nRotL = 0.0, 0.0, 1 #alpha; rotation of laser polarization in degrees; default 0 103 RotL, dRotL, nRotL = 0.0, 0.0, 1 # alpha; rotation of laser polarization in degrees; default 0
94 # --- ME Emitter and +-Uncertainty 104 # --- ME Emitter and +-Uncertainty
95 DiE, dDiE, nDiE = 0., 0.00, 1 # Diattenuation 105 DiE, dDiE, nDiE = 0., 0.00, 1 # Diattenuation
96 TiE = 1. # Unpolarized transmittance 106 TiE = 1. # Unpolarized transmittance
97 RetE, dRetE, nRetE = 0., 180.0, 0 # Retardance in degrees 107 RetE, dRetE, nRetE = 0., 180.0, 0 # Retardance in degrees
98 RotE, dRotE, nRotE = 0., 0.0, 0 # beta: Rotation of optical element in degrees 108 RotE, dRotE, nRotE = 0., 0.0, 0 # beta: Rotation of optical element in degrees
99 # --- MO Receiver Optics including telescope 109 # --- MO Receiver Optics including telescope
100 DiO, dDiO, nDiO = -0.055, 0.003, 1 110 DiO, dDiO, nDiO = -0.055, 0.003, 1
101 TiO = 0.9 111 TiO = 0.9
102 RetO, dRetO, nRetO = 0., 180.0, 2 112 RetO, dRetO, nRetO = 0., 180.0, 2
103 RotO, dRotO, nRotO = 0., 0.1, 1 #gamma 113 RotO, dRotO, nRotO = 0., 0.1, 1 # gamma
104 # --- PBS MT transmitting path defined with (TS,TP); and +-Uncertainty 114 # --- PBS MT transmitting path defined with (TS,TP); and +-Uncertainty
105 TP, dTP, nTP = 0.98, 0.02, 1 115 TP, dTP, nTP = 0.98, 0.02, 1
106 TS, dTS, nTS = 0.001, 0.001, 1 116 TS, dTS, nTS = 0.001, 0.001, 1
107 TiT = 0.5 * (TP + TS) 117 TiT = 0.5 * (TP + TS)
108 DiT = (TP-TS)/(TP+TS) 118 DiT = (TP - TS) / (TP + TS)
109 # PolFilter 119 # PolFilter
110 RetT, dRetT, nRetT = 0., 180., 0 120 RetT, dRetT, nRetT = 0., 180., 0
111 ERaT, dERaT, nERaT = 0.001, 0.001, 1 121 ERaT, dERaT, nERaT = 0.001, 0.001, 1
112 RotaT, dRotaT, nRotaT = 0., 3., 1 122 RotaT, dRotaT, nRotaT = 0., 3., 1
113 DaT = (1-ERaT)/(1+ERaT) 123 DaT = (1 - ERaT) / (1 + ERaT)
114 TaT = 0.5*(1+ERaT) 124 TaT = 0.5 * (1 + ERaT)
115 # --- PBS MR reflecting path defined with (RS,RP); and +-Uncertainty 125 # --- PBS MR reflecting path defined with (RS,RP); and +-Uncertainty
116 RS_RP_depend_on_TS_TP = False 126 RS_RP_depend_on_TS_TP = False
117 if(RS_RP_depend_on_TS_TP): 127 if (RS_RP_depend_on_TS_TP):
118 RP, dRP, nRP = 1-TP, 0.00, 0 128 RP, dRP, nRP = 1 - TP, 0.00, 0
119 RS, dRS, nRS = 1-TS, 0.00, 0 129 RS, dRS, nRS = 1 - TS, 0.00, 0
120 else: 130 else:
121 RP, dRP, nRP = 0.05, 0.01, 1 131 RP, dRP, nRP = 0.05, 0.01, 1
122 RS, dRS, nRS = 0.98, 0.01, 1 132 RS, dRS, nRS = 0.98, 0.01, 1
123 TiR = 0.5 * (RP + RS) 133 TiR = 0.5 * (RP + RS)
124 DiR = (RP-RS)/(RP+RS) 134 DiR = (RP - RS) / (RP + RS)
125 # PolFilter 135 # PolFilter
126 RetR, dRetR, nRetR = 0., 180., 0 136 RetR, dRetR, nRetR = 0., 180., 0
127 ERaR, dERaR, nERaR = 0.001, 0.001, 1 137 ERaR, dERaR, nERaR = 0.001, 0.001, 1
128 RotaR,dRotaR,nRotaR = 90., 3., 1 138 RotaR, dRotaR, nRotaR = 90., 3., 1
129 DaR = (1-ERaR)/(1+ERaR) 139 DaR = (1 - ERaR) / (1 + ERaR)
130 TaR = 0.5*(1+ERaR) 140 TaR = 0.5 * (1 + ERaR)
131 141
132 # Parellel signal detected in the transmitted channel => Y = 1, or in the reflected channel => Y = -1 142 # Parellel signal detected in the transmitted channel => Y = 1, or in the reflected channel => Y = -1
133 Y = -1. 143 Y = -1.
134 144
135 # Calibrator = type defined by matrix values 145 # Calibrator = type defined by matrix values
136 LocC = 4 # location of calibrator: behind laser = 1; behind emitter = 2; before receiver = 3; before PBS = 4 146 LocC = 4 # location of calibrator: behind laser = 1; behind emitter = 2; before receiver = 3; before PBS = 4
137 147
138 TypeC = 3 # linear polarizer calibrator 148 TypeC = 3 # linear polarizer calibrator
139 # example with extinction ratio 0.001 149 # example with extinction ratio 0.001
140 DiC, dDiC, nDiC = 1.0, 0., 0 # ideal 1.0 150 DiC, dDiC, nDiC = 1.0, 0., 0 # ideal 1.0
141 TiC = 0.5 # ideal 0.5 151 TiC = 0.5 # ideal 0.5
142 RetC, dRetC, nRetC = 0., 0., 0 152 RetC, dRetC, nRetC = 0., 0., 0
143 RotC, dRotC, nRotC = 0.0, 0.1, 0 #constant calibrator offset epsilon 153 RotC, dRotC, nRotC = 0.0, 0.1, 0 # constant calibrator offset epsilon
144 RotationErrorEpsilonForNormalMeasurements = False # is in general False for TypeC == 3 calibrator 154 RotationErrorEpsilonForNormalMeasurements = False # is in general False for TypeC == 3 calibrator
145 155
146 # Rotation error without calibrator: if False, then epsilon = 0 for normal measurements 156 # Rotation error without calibrator: if False, then epsilon = 0 for normal measurements
147 RotationErrorEpsilonForNormalMeasurements = True 157 RotationErrorEpsilonForNormalMeasurements = True
148 158
149 # LDRCal assumed atmospheric linear depolarization ratio during the calibration measurements (first guess) 159 # LDRCal assumed atmospheric linear depolarization ratio during the calibration measurements (first guess)
150 LDRCal0,dLDRCal,nLDRCal= 0.25, 0.04, 1 160 LDRCal0, dLDRCal, nLDRCal = 0.25, 0.04, 1
151 LDRCal = LDRCal0 161 LDRCal = LDRCal0
152 # measured LDRm will be corrected with calculated parameters 162 # measured LDRm will be corrected with calculated parameters
153 LDRmeas = 0.015 163 LDRmeas = 0.015
154 # LDRtrue for simulation of measurement => LDRsim 164 # LDRtrue for simulation of measurement => LDRsim
155 LDRtrue = 0.5 165 LDRtrue = 0.5
165 Ir = 0. 175 Ir = 0.
166 It = 0. 176 It = 0.
167 h = 1. 177 h = 1.
168 178
169 Loc = ['', 'behind laser', 'behind emitter', 'before receiver', 'before PBS'] 179 Loc = ['', 'behind laser', 'behind emitter', 'before receiver', 'before PBS']
170 Type = ['', 'mechanical rotator', 'hwp rotator', 'linear polarizer', 'qwp rotator', 'circular polarizer', 'real HWP +-22.5°'] 180 Type = ['', 'mechanical rotator', 'hwp rotator', 'linear polarizer', 'qwp rotator', 'circular polarizer',
181 'real HWP +-22.5°']
171 dY = ['reflected channel', '', 'transmitted channel'] 182 dY = ['reflected channel', '', 'transmitted channel']
172 183
173 # end of initial definition of variables 184 # end of initial definition of variables
174 # ******************************************************************************************************************************* 185 # *******************************************************************************************************************************
175 186
176 # --- Read actual lidar system parameters from ./optic_input.py (must be in the same directory) 187 # --- Read actual lidar system parameters from ./optic_input.py (must be in the same directory)
177 InputFile = 'optic_input_example_lidar.py' 188 InputFile = 'optic_input_example_lidar.py'
178 #InputFile = 'optic_input_ver6e_POLIS_355.py' 189 # InputFile = 'optic_input_ver6e_POLIS_355.py'
179 #InputFile = 'optic_input_ver6e_POLIS_355_JA.py' 190 # InputFile = 'optic_input_ver6e_POLIS_355_JA.py'
180 #InputFile = 'optic_input_ver6c_POLIS_532.py' 191 # InputFile = 'optic_input_ver6c_POLIS_532.py'
181 #InputFile = 'optic_input_ver6e_POLIS_532.py' 192 # InputFile = 'optic_input_ver6e_POLIS_532.py'
182 #InputFile = 'optic_input_ver8c_POLIS_532.py' 193 # InputFile = 'optic_input_ver8c_POLIS_532.py'
183 #InputFile = 'optic_input_ver6e_MUSA.py' 194 # InputFile = 'optic_input_ver6e_MUSA.py'
184 #InputFile = 'optic_input_ver6e_MUSA_JA.py' 195 # InputFile = 'optic_input_ver6e_MUSA_JA.py'
185 #InputFile = 'optic_input_ver6e_PollyXTSea.py' 196 # InputFile = 'optic_input_ver6e_PollyXTSea.py'
186 #InputFile = 'optic_input_ver6e_PollyXTSea_JA.py' 197 # InputFile = 'optic_input_ver6e_PollyXTSea_JA.py'
187 #InputFile = 'optic_input_ver6e_PollyXT_RALPH.py' 198 # InputFile = 'optic_input_ver6e_PollyXT_RALPH.py'
188 #InputFile = 'optic_input_ver8c_PollyXT_RALPH.py' 199 # InputFile = 'optic_input_ver8c_PollyXT_RALPH.py'
189 #InputFile = 'optic_input_ver8c_PollyXT_RALPH_2.py' 200 # InputFile = 'optic_input_ver8c_PollyXT_RALPH_2.py'
190 #InputFile = 'optic_input_ver8c_PollyXT_RALPH_3.py' 201 # InputFile = 'optic_input_ver8c_PollyXT_RALPH_3.py'
191 #InputFile = 'optic_input_ver8c_PollyXT_RALPH_4.py' 202 # InputFile = 'optic_input_ver8c_PollyXT_RALPH_4.py'
192 #InputFile = 'optic_input_ver8c_PollyXT_RALPH_5.py' 203 # InputFile = 'optic_input_ver8c_PollyXT_RALPH_5.py'
193 #InputFile = 'optic_input_ver8c_PollyXT_RALPH_6.py' 204 # InputFile = 'optic_input_ver8c_PollyXT_RALPH_6.py'
194 #InputFile = 'optic_input_ver8c_PollyXT_RALPH_7.py' 205 # InputFile = 'optic_input_ver8c_PollyXT_RALPH_7.py'
195 #InputFile = 'optic_input_ver8a_MOHP_DPL_355.py' 206 # InputFile = 'optic_input_ver8a_MOHP_DPL_355.py'
196 #InputFile = 'optic_input_ver9_MOHP_DPL_355.py' 207 # InputFile = 'optic_input_ver9_MOHP_DPL_355.py'
197 #InputFile = 'optic_input_ver6e_RALI.py' 208 # InputFile = 'optic_input_ver6e_RALI.py'
198 #InputFile = 'optic_input_ver6e_RALI_JA.py' 209 # InputFile = 'optic_input_ver6e_RALI_JA.py'
199 #InputFile = 'optic_input_ver6e_RALI_new.py' 210 # InputFile = 'optic_input_ver6e_RALI_new.py'
200 #InputFile = 'optic_input_ver6e_RALI_act.py' 211 # InputFile = 'optic_input_ver6e_RALI_act.py'
201 #InputFile = 'optic_input_ver6e_MULHACEN.py' 212 # InputFile = 'optic_input_ver6e_MULHACEN.py'
202 #InputFile = 'optic_input_ver6e_MULHACEN_JA.py' 213 # InputFile = 'optic_input_ver6e_MULHACEN_JA.py'
203 #InputFile = 'optic_input_ver6e-IPRAL.py' 214 # InputFile = 'optic_input_ver6e-IPRAL.py'
204 #InputFile = 'optic_input_ver6e-IPRAL_JA.py' 215 # InputFile = 'optic_input_ver6e-IPRAL_JA.py'
205 #InputFile = 'optic_input_ver6e-LB21.py' 216 # InputFile = 'optic_input_ver6e-LB21.py'
206 #InputFile = 'optic_input_ver6e-LB21_JA.py' 217 # InputFile = 'optic_input_ver6e-LB21_JA.py'
207 #InputFile = 'optic_input_ver6e_Bertha_b_355.py' 218 # InputFile = 'optic_input_ver6e_Bertha_b_355.py'
208 #InputFile = 'optic_input_ver6e_Bertha_b_532.py' 219 # InputFile = 'optic_input_ver6e_Bertha_b_532.py'
209 #InputFile = 'optic_input_ver6e_Bertha_b_1064.py' 220 # InputFile = 'optic_input_ver6e_Bertha_b_1064.py'
210 221
211 ''' 222 '''
212 print("From ", dname) 223 print("From ", dname)
213 print("Running ", fname) 224 print("Running ", fname)
214 print("Reading input file ", InputFile, " for") 225 print("Reading input file ", InputFile, " for")
215 ''' 226 '''
216 input_path = os.path.join('.', 'system_settings', InputFile) 227 input_path = os.path.join('.', 'system_settings', InputFile)
217 # this works with Python 2 - and 3? 228 # this works with Python 2 - and 3?
218 exec(open(input_path).read(), globals()) 229 exec (open(input_path).read(), globals())
219 # end of read actual system parameters 230 # end of read actual system parameters
220 231
221 # --- Manual Parameter Change --- 232 # --- Manual Parameter Change ---
222 # (use for quick parameter changes without changing the input file ) 233 # (use for quick parameter changes without changing the input file )
223 #DiO = 0. 234 # DiO = 0.
224 #LDRtrue = 0.45 235 # LDRtrue = 0.45
225 #LDRtrue2 = 0.004 236 # LDRtrue2 = 0.004
226 #Y = -1 237 # Y = -1
227 #LocC = 4 #location of calibrator: 1 = behind laser; 2 = behind emitter; 3 = before receiver; 4 = before PBS 238 # LocC = 4 #location of calibrator: 1 = behind laser; 2 = behind emitter; 3 = before receiver; 4 = before PBS
228 ##TypeC = 6 Don't change the TypeC here 239 ##TypeC = 6 Don't change the TypeC here
229 #RotationErrorEpsilonForNormalMeasurements = True 240 # RotationErrorEpsilonForNormalMeasurements = True
230 #LDRCal = 0.25 241 # LDRCal = 0.25
231 #bL = 0.8 242 # bL = 0.8
232 ## --- Errors 243 ## --- Errors
233 RotL0, dRotL, nRotL = RotL, dRotL, nRotL 244 RotL0, dRotL, nRotL = RotL, dRotL, nRotL
234 245
235 DiE0, dDiE, nDiE = DiE, dDiE, nDiE 246 DiE0, dDiE, nDiE = DiE, dDiE, nDiE
236 RetE0, dRetE, nRetE = RetE, dRetE, nRetE 247 RetE0, dRetE, nRetE = RetE, dRetE, nRetE
237 RotE0, dRotE, nRotE = RotE, dRotE, nRotE 248 RotE0, dRotE, nRotE = RotE, dRotE, nRotE
238 249
239 DiO0, dDiO, nDiO = DiO, dDiO, nDiO 250 DiO0, dDiO, nDiO = DiO, dDiO, nDiO
240 RetO0, dRetO, nRetO = RetO, dRetO, nRetO 251 RetO0, dRetO, nRetO = RetO, dRetO, nRetO
241 RotO0, dRotO, nRotO = RotO, dRotO, nRotO 252 RotO0, dRotO, nRotO = RotO, dRotO, nRotO
242 253
243 DiC0, dDiC, nDiC = DiC, dDiC, nDiC 254 DiC0, dDiC, nDiC = DiC, dDiC, nDiC
244 RetC0, dRetC, nRetC = RetC, dRetC, nRetC 255 RetC0, dRetC, nRetC = RetC, dRetC, nRetC
245 RotC0, dRotC, nRotC = RotC, dRotC, nRotC 256 RotC0, dRotC, nRotC = RotC, dRotC, nRotC
246 257
247 TP0, dTP, nTP = TP, dTP, nTP 258 TP0, dTP, nTP = TP, dTP, nTP
248 TS0, dTS, nTS = TS, dTS, nTS 259 TS0, dTS, nTS = TS, dTS, nTS
249 RetT0, dRetT, nRetT = RetT, dRetT, nRetT 260 RetT0, dRetT, nRetT = RetT, dRetT, nRetT
250 261
251 ERaT0, dERaT, nERaT = ERaT, dERaT, nERaT 262 ERaT0, dERaT, nERaT = ERaT, dERaT, nERaT
252 RotaT0,dRotaT,nRotaT= RotaT,dRotaT,nRotaT 263 RotaT0, dRotaT, nRotaT = RotaT, dRotaT, nRotaT
253 264
254 RP0, dRP, nRP = RP, dRP, nRP 265 RP0, dRP, nRP = RP, dRP, nRP
255 RS0, dRS, nRS = RS, dRS, nRS 266 RS0, dRS, nRS = RS, dRS, nRS
256 RetR0, dRetR, nRetR = RetR, dRetR, nRetR 267 RetR0, dRetR, nRetR = RetR, dRetR, nRetR
257 268
258 ERaR0, dERaR, nERaR = ERaR, dERaR, nERaR 269 ERaR0, dERaR, nERaR = ERaR, dERaR, nERaR
259 RotaR0,dRotaR,nRotaR= RotaR,dRotaR,nRotaR 270 RotaR0, dRotaR, nRotaR = RotaR, dRotaR, nRotaR
260 271
261 LDRCal0,dLDRCal,nLDRCal=LDRCal,dLDRCal,nLDRCal 272 LDRCal0, dLDRCal, nLDRCal = LDRCal, dLDRCal, nLDRCal
262 #LDRCal0,dLDRCal,nLDRCal=LDRCal,dLDRCal,0 273 # LDRCal0,dLDRCal,nLDRCal=LDRCal,dLDRCal,0
263 # ---------- End of manual parameter change 274 # ---------- End of manual parameter change
264 275
265 RotL, RotE, RetE, DiE, RotO, RetO, DiO, RotC, RetC, DiC = RotL0, RotE0, RetE0, DiE0, RotO0, RetO0, DiO0, RotC0, RetC0, DiC0 276 RotL, RotE, RetE, DiE, RotO, RetO, DiO, RotC, RetC, DiC = RotL0, RotE0, RetE0, DiE0, RotO0, RetO0, DiO0, RotC0, RetC0, DiC0
266 TP, TS, RP, RS, ERaT, RotaT, RetT, ERaR, RotaR, RetR = TP0, TS0, RP0, RS0 , ERaT0, RotaT0, RetT0, ERaR0, RotaR0, RetR0 277 TP, TS, RP, RS, ERaT, RotaT, RetT, ERaR, RotaR, RetR = TP0, TS0, RP0, RS0, ERaT0, RotaT0, RetT0, ERaR0, RotaR0, RetR0
267 LDRCal = LDRCal0 278 LDRCal = LDRCal0
268 DTa0, TTa0, DRa0, TRa0, LDRsimx, LDRCorr = 0,0,0,0,0,0 279 DTa0, TTa0, DRa0, TRa0, LDRsimx, LDRCorr = 0, 0, 0, 0, 0, 0
269 280
270 TiT = 0.5 * (TP + TS) 281 TiT = 0.5 * (TP + TS)
271 DiT = (TP-TS)/(TP+TS) 282 DiT = (TP - TS) / (TP + TS)
272 ZiT = (1. - DiT**2)**0.5 283 ZiT = (1. - DiT ** 2) ** 0.5
273 TiR = 0.5 * (RP + RS) 284 TiR = 0.5 * (RP + RS)
274 DiR = (RP-RS)/(RP+RS) 285 DiR = (RP - RS) / (RP + RS)
275 ZiR = (1. - DiR**2)**0.5 286 ZiR = (1. - DiR ** 2) ** 0.5
287
276 288
277 # --- this subroutine is for the calculation with certain fixed parameters ----------------------------------------------------- 289 # --- this subroutine is for the calculation with certain fixed parameters -----------------------------------------------------
278 def Calc(RotL, RotE, RetE, DiE, RotO, RetO, DiO, RotC, RetC, DiC, TP, TS, RP, RS, ERaT, RotaT, RetT, ERaR, RotaR, RetR, LDRCal): 290 def Calc(RotL, RotE, RetE, DiE, RotO, RetO, DiO, RotC, RetC, DiC, TP, TS, RP, RS, ERaT, RotaT, RetT, ERaR, RotaR, RetR,
291 LDRCal):
279 # ---- Do the calculations of bra-ket vectors 292 # ---- Do the calculations of bra-ket vectors
280 h = -1. if TypeC == 2 else 1 293 h = -1. if TypeC == 2 else 1
281 # from input file: assumed LDRCal for calibration measurements 294 # from input file: assumed LDRCal for calibration measurements
282 aCal = (1.-LDRCal)/(1+LDRCal) 295 aCal = (1. - LDRCal) / (1 + LDRCal)
283 # from input file: measured LDRm and true LDRtrue, LDRtrue2 => 296 # from input file: measured LDRm and true LDRtrue, LDRtrue2 =>
284 #ameas = (1.-LDRmeas)/(1+LDRmeas) 297 # ameas = (1.-LDRmeas)/(1+LDRmeas)
285 atrue = (1.-LDRtrue)/(1+LDRtrue) 298 atrue = (1. - LDRtrue) / (1 + LDRtrue)
286 #atrue2 = (1.-LDRtrue2)/(1+LDRtrue2) 299 # atrue2 = (1.-LDRtrue2)/(1+LDRtrue2)
287 300
288 # angles of emitter and laser and calibrator and receiver optics 301 # angles of emitter and laser and calibrator and receiver optics
289 # RotL = alpha, RotE = beta, RotO = gamma, RotC = epsilon 302 # RotL = alpha, RotE = beta, RotO = gamma, RotC = epsilon
290 S2a = np.sin(2*np.deg2rad(RotL)) 303 S2a = np.sin(2 * np.deg2rad(RotL))
291 C2a = np.cos(2*np.deg2rad(RotL)) 304 C2a = np.cos(2 * np.deg2rad(RotL))
292 S2b = np.sin(2*np.deg2rad(RotE)) 305 S2b = np.sin(2 * np.deg2rad(RotE))
293 C2b = np.cos(2*np.deg2rad(RotE)) 306 C2b = np.cos(2 * np.deg2rad(RotE))
294 S2ab = np.sin(np.deg2rad(2*RotL-2*RotE)) 307 S2ab = np.sin(np.deg2rad(2 * RotL - 2 * RotE))
295 C2ab = np.cos(np.deg2rad(2*RotL-2*RotE)) 308 C2ab = np.cos(np.deg2rad(2 * RotL - 2 * RotE))
296 S2g = np.sin(np.deg2rad(2*RotO)) 309 S2g = np.sin(np.deg2rad(2 * RotO))
297 C2g = np.cos(np.deg2rad(2*RotO)) 310 C2g = np.cos(np.deg2rad(2 * RotO))
298 311
299 # Laser with Degree of linear polarization DOLP = bL 312 # Laser with Degree of linear polarization DOLP = bL
300 IinL = 1. 313 IinL = 1.
301 QinL = bL 314 QinL = bL
302 UinL = 0. 315 UinL = 0.
303 VinL = (1. - bL**2)**0.5 316 VinL = (1. - bL ** 2) ** 0.5
304 317
305 # Stokes Input Vector rotation Eq. E.4 318 # Stokes Input Vector rotation Eq. E.4
306 A = C2a*QinL - S2a*UinL 319 A = C2a * QinL - S2a * UinL
307 B = S2a*QinL + C2a*UinL 320 B = S2a * QinL + C2a * UinL
308 # Stokes Input Vector rotation Eq. E.9 321 # Stokes Input Vector rotation Eq. E.9
309 C = C2ab*QinL - S2ab*UinL 322 C = C2ab * QinL - S2ab * UinL
310 D = S2ab*QinL + C2ab*UinL 323 D = S2ab * QinL + C2ab * UinL
311 324
312 # emitter optics 325 # emitter optics
313 CosE = np.cos(np.deg2rad(RetE)) 326 CosE = np.cos(np.deg2rad(RetE))
314 SinE = np.sin(np.deg2rad(RetE)) 327 SinE = np.sin(np.deg2rad(RetE))
315 ZiE = (1. - DiE**2)**0.5 328 ZiE = (1. - DiE ** 2) ** 0.5
316 WiE = (1. - ZiE*CosE) 329 WiE = (1. - ZiE * CosE)
317 330
318 # Stokes Input Vector after emitter optics equivalent to Eq. E.9 with already rotated input vector from Eq. E.4 331 # Stokes Input Vector after emitter optics equivalent to Eq. E.9 with already rotated input vector from Eq. E.4
319 # b = beta 332 # b = beta
320 IinE = (IinL + DiE*C) 333 IinE = (IinL + DiE * C)
321 QinE = (C2b*DiE*IinL + A + S2b*(WiE*D - ZiE*SinE*VinL)) 334 QinE = (C2b * DiE * IinL + A + S2b * (WiE * D - ZiE * SinE * VinL))
322 UinE = (S2b*DiE*IinL + B - C2b*(WiE*D - ZiE*SinE*VinL)) 335 UinE = (S2b * DiE * IinL + B - C2b * (WiE * D - ZiE * SinE * VinL))
323 VinE = (-ZiE*SinE*D + ZiE*CosE*VinL) 336 VinE = (-ZiE * SinE * D + ZiE * CosE * VinL)
324 337
325 # Stokes Input Vector before receiver optics Eq. E.19 (after atmosphere F) 338 # Stokes Input Vector before receiver optics Eq. E.19 (after atmosphere F)
326 IinF = IinE 339 IinF = IinE
327 QinF = aCal*QinE 340 QinF = aCal * QinE
328 UinF = -aCal*UinE 341 UinF = -aCal * UinE
329 VinF = (1.-2.*aCal)*VinE 342 VinF = (1. - 2. * aCal) * VinE
330 343
331 # receiver optics 344 # receiver optics
332 CosO = np.cos(np.deg2rad(RetO)) 345 CosO = np.cos(np.deg2rad(RetO))
333 SinO = np.sin(np.deg2rad(RetO)) 346 SinO = np.sin(np.deg2rad(RetO))
334 ZiO = (1. - DiO**2)**0.5 347 ZiO = (1. - DiO ** 2) ** 0.5
335 WiO = (1. - ZiO*CosO) 348 WiO = (1. - ZiO * CosO)
336 349
337 # calibrator 350 # calibrator
338 CosC = np.cos(np.deg2rad(RetC)) 351 CosC = np.cos(np.deg2rad(RetC))
339 SinC = np.sin(np.deg2rad(RetC)) 352 SinC = np.sin(np.deg2rad(RetC))
340 ZiC = (1. - DiC**2)**0.5 353 ZiC = (1. - DiC ** 2) ** 0.5
341 WiC = (1. - ZiC*CosC) 354 WiC = (1. - ZiC * CosC)
342 355
343 # Stokes Input Vector before the polarising beam splitter Eq. E.31 356 # Stokes Input Vector before the polarising beam splitter Eq. E.31
344 A = C2g*QinE - S2g*UinE 357 A = C2g * QinE - S2g * UinE
345 B = S2g*QinE + C2g*UinE 358 B = S2g * QinE + C2g * UinE
346 359
347 IinP = (IinE + DiO*aCal*A) 360 IinP = (IinE + DiO * aCal * A)
348 QinP = (C2g*DiO*IinE + aCal*QinE - S2g*(WiO*aCal*B + ZiO*SinO*(1-2*aCal)*VinE)) 361 QinP = (C2g * DiO * IinE + aCal * QinE - S2g * (WiO * aCal * B + ZiO * SinO * (1 - 2 * aCal) * VinE))
349 UinP = (S2g*DiO*IinE - aCal*UinE + C2g*(WiO*aCal*B + ZiO*SinO*(1-2*aCal)*VinE)) 362 UinP = (S2g * DiO * IinE - aCal * UinE + C2g * (WiO * aCal * B + ZiO * SinO * (1 - 2 * aCal) * VinE))
350 VinP = (ZiO*SinO*aCal*B + ZiO*CosO*(1-2*aCal)*VinE) 363 VinP = (ZiO * SinO * aCal * B + ZiO * CosO * (1 - 2 * aCal) * VinE)
351 364
352 #------------------------- 365 # -------------------------
353 # F11 assuemd to be = 1 => measured: F11m = IinP / IinE with atrue 366 # F11 assuemd to be = 1 => measured: F11m = IinP / IinE with atrue
354 #F11sim = TiO*(IinE + DiO*atrue*A)/IinE 367 # F11sim = TiO*(IinE + DiO*atrue*A)/IinE
355 #------------------------- 368 # -------------------------
356 369
357 # analyser 370 # analyser
358 #For POLLY_XTs 371 # For POLLY_XTs
359 if(RS_RP_depend_on_TS_TP): 372 if (RS_RP_depend_on_TS_TP):
360 RS = 1 - TS 373 RS = 1 - TS
361 RP = 1 - TP 374 RP = 1 - TP
362 TiT = 0.5 * (TP + TS) 375 TiT = 0.5 * (TP + TS)
363 DiT = (TP-TS)/(TP+TS) 376 DiT = (TP - TS) / (TP + TS)
364 ZiT = (1. - DiT**2)**0.5 377 ZiT = (1. - DiT ** 2) ** 0.5
365 TiR = 0.5 * (RP + RS) 378 TiR = 0.5 * (RP + RS)
366 DiR = (RP-RS)/(RP+RS) 379 DiR = (RP - RS) / (RP + RS)
367 ZiR = (1. - DiR**2)**0.5 380 ZiR = (1. - DiR ** 2) ** 0.5
368 CosT = np.cos(np.deg2rad(RetT)) 381 CosT = np.cos(np.deg2rad(RetT))
369 SinT = np.sin(np.deg2rad(RetT)) 382 SinT = np.sin(np.deg2rad(RetT))
370 CosR = np.cos(np.deg2rad(RetR)) 383 CosR = np.cos(np.deg2rad(RetR))
371 SinR = np.sin(np.deg2rad(RetR)) 384 SinR = np.sin(np.deg2rad(RetR))
372 385
373 DaT = (1-ERaT)/(1+ERaT) 386 DaT = (1 - ERaT) / (1 + ERaT)
374 DaR = (1-ERaR)/(1+ERaR) 387 DaR = (1 - ERaR) / (1 + ERaR)
375 TaT = 0.5*(1+ERaT) 388 TaT = 0.5 * (1 + ERaT)
376 TaR = 0.5*(1+ERaR) 389 TaR = 0.5 * (1 + ERaR)
377 390
378 S2aT = np.sin(np.deg2rad(h*2*RotaT)) 391 S2aT = np.sin(np.deg2rad(h * 2 * RotaT))
379 C2aT = np.cos(np.deg2rad(2*RotaT)) 392 C2aT = np.cos(np.deg2rad(2 * RotaT))
380 S2aR = np.sin(np.deg2rad(h*2*RotaR)) 393 S2aR = np.sin(np.deg2rad(h * 2 * RotaR))
381 C2aR = np.cos(np.deg2rad(2*RotaR)) 394 C2aR = np.cos(np.deg2rad(2 * RotaR))
382 395
383 # Aanalyzer As before the PBS Eq. D.5 396 # Aanalyzer As before the PBS Eq. D.5
384 ATP1 = (1+C2aT*DaT*DiT) 397 ATP1 = (1 + C2aT * DaT * DiT)
385 ATP2 = Y*(DiT+C2aT*DaT) 398 ATP2 = Y * (DiT + C2aT * DaT)
386 ATP3 = Y*S2aT*DaT*ZiT*CosT 399 ATP3 = Y * S2aT * DaT * ZiT * CosT
387 ATP4 = S2aT*DaT*ZiT*SinT 400 ATP4 = S2aT * DaT * ZiT * SinT
388 ATP = np.array([ATP1,ATP2,ATP3,ATP4]) 401 ATP = np.array([ATP1, ATP2, ATP3, ATP4])
389 402
390 ARP1 = (1+C2aR*DaR*DiR) 403 ARP1 = (1 + C2aR * DaR * DiR)
391 ARP2 = Y*(DiR+C2aR*DaR) 404 ARP2 = Y * (DiR + C2aR * DaR)
392 ARP3 = Y*S2aR*DaR*ZiR*CosR 405 ARP3 = Y * S2aR * DaR * ZiR * CosR
393 ARP4 = S2aR*DaR*ZiR*SinR 406 ARP4 = S2aR * DaR * ZiR * SinR
394 ARP = np.array([ARP1,ARP2,ARP3,ARP4]) 407 ARP = np.array([ARP1, ARP2, ARP3, ARP4])
395 408
396 DTa = ATP2*Y/ATP1 409 DTa = ATP2 * Y / ATP1
397 DRa = ARP2*Y/ARP1 410 DRa = ARP2 * Y / ARP1
398 411
399 # ---- Calculate signals and correction parameters for diffeent locations and calibrators 412 # ---- Calculate signals and correction parameters for diffeent locations and calibrators
400 if LocC == 4: # Calibrator before the PBS 413 if LocC == 4: # Calibrator before the PBS
401 #print("Calibrator location not implemented yet") 414 # print("Calibrator location not implemented yet")
402 415
403 #S2ge = np.sin(np.deg2rad(2*RotO + h*2*RotC)) 416 # S2ge = np.sin(np.deg2rad(2*RotO + h*2*RotC))
404 #C2ge = np.cos(np.deg2rad(2*RotO + h*2*RotC)) 417 # C2ge = np.cos(np.deg2rad(2*RotO + h*2*RotC))
405 S2e = np.sin(np.deg2rad(h*2*RotC)) 418 S2e = np.sin(np.deg2rad(h * 2 * RotC))
406 C2e = np.cos(np.deg2rad(2*RotC)) 419 C2e = np.cos(np.deg2rad(2 * RotC))
407 # rotated AinP by epsilon Eq. C.3 420 # rotated AinP by epsilon Eq. C.3
408 ATP2e = C2e*ATP2 + S2e*ATP3 421 ATP2e = C2e * ATP2 + S2e * ATP3
409 ATP3e = C2e*ATP3 - S2e*ATP2 422 ATP3e = C2e * ATP3 - S2e * ATP2
410 ARP2e = C2e*ARP2 + S2e*ARP3 423 ARP2e = C2e * ARP2 + S2e * ARP3
411 ARP3e = C2e*ARP3 - S2e*ARP2 424 ARP3e = C2e * ARP3 - S2e * ARP2
412 ATPe = np.array([ATP1,ATP2e,ATP3e,ATP4]) 425 ATPe = np.array([ATP1, ATP2e, ATP3e, ATP4])
413 ARPe = np.array([ARP1,ARP2e,ARP3e,ARP4]) 426 ARPe = np.array([ARP1, ARP2e, ARP3e, ARP4])
414 # Stokes Input Vector before the polarising beam splitter Eq. E.31 427 # Stokes Input Vector before the polarising beam splitter Eq. E.31
415 A = C2g*QinE - S2g*UinE 428 A = C2g * QinE - S2g * UinE
416 B = S2g*QinE + C2g*UinE 429 B = S2g * QinE + C2g * UinE
417 #C = (WiO*aCal*B + ZiO*SinO*(1-2*aCal)*VinE) 430 # C = (WiO*aCal*B + ZiO*SinO*(1-2*aCal)*VinE)
418 Co = ZiO*SinO*VinE 431 Co = ZiO * SinO * VinE
419 Ca = (WiO*B - 2*ZiO*SinO*VinE) 432 Ca = (WiO * B - 2 * ZiO * SinO * VinE)
420 #C = Co + aCal*Ca 433 # C = Co + aCal*Ca
421 #IinP = (IinE + DiO*aCal*A) 434 # IinP = (IinE + DiO*aCal*A)
422 #QinP = (C2g*DiO*IinE + aCal*QinE - S2g*C) 435 # QinP = (C2g*DiO*IinE + aCal*QinE - S2g*C)
423 #UinP = (S2g*DiO*IinE - aCal*UinE + C2g*C) 436 # UinP = (S2g*DiO*IinE - aCal*UinE + C2g*C)
424 #VinP = (ZiO*SinO*aCal*B + ZiO*CosO*(1-2*aCal)*VinE) 437 # VinP = (ZiO*SinO*aCal*B + ZiO*CosO*(1-2*aCal)*VinE)
425 IinPo = IinE 438 IinPo = IinE
426 QinPo = (C2g*DiO*IinE - S2g*Co) 439 QinPo = (C2g * DiO * IinE - S2g * Co)
427 UinPo = (S2g*DiO*IinE + C2g*Co) 440 UinPo = (S2g * DiO * IinE + C2g * Co)
428 VinPo = ZiO*CosO*VinE 441 VinPo = ZiO * CosO * VinE
429 442
430 IinPa = DiO*A 443 IinPa = DiO * A
431 QinPa = QinE - S2g*Ca 444 QinPa = QinE - S2g * Ca
432 UinPa = -UinE + C2g*Ca 445 UinPa = -UinE + C2g * Ca
433 VinPa = ZiO*(SinO*B - 2*CosO*VinE) 446 VinPa = ZiO * (SinO * B - 2 * CosO * VinE)
434 447
435 IinP = IinPo + aCal*IinPa 448 IinP = IinPo + aCal * IinPa
436 QinP = QinPo + aCal*QinPa 449 QinP = QinPo + aCal * QinPa
437 UinP = UinPo + aCal*UinPa 450 UinP = UinPo + aCal * UinPa
438 VinP = VinPo + aCal*VinPa 451 VinP = VinPo + aCal * VinPa
439 # Stokes Input Vector before the polarising beam splitter rotated by epsilon Eq. C.3 452 # Stokes Input Vector before the polarising beam splitter rotated by epsilon Eq. C.3
440 #QinPe = C2e*QinP + S2e*UinP 453 # QinPe = C2e*QinP + S2e*UinP
441 #UinPe = C2e*UinP - S2e*QinP 454 # UinPe = C2e*UinP - S2e*QinP
442 QinPoe = C2e*QinPo + S2e*UinPo 455 QinPoe = C2e * QinPo + S2e * UinPo
443 UinPoe = C2e*UinPo - S2e*QinPo 456 UinPoe = C2e * UinPo - S2e * QinPo
444 QinPae = C2e*QinPa + S2e*UinPa 457 QinPae = C2e * QinPa + S2e * UinPa
445 UinPae = C2e*UinPa - S2e*QinPa 458 UinPae = C2e * UinPa - S2e * QinPa
446 QinPe = C2e*QinP + S2e*UinP 459 QinPe = C2e * QinP + S2e * UinP
447 UinPe = C2e*UinP - S2e*QinP 460 UinPe = C2e * UinP - S2e * QinP
448 461
449 # Calibration signals and Calibration correction K from measurements with LDRCal / aCal 462 # Calibration signals and Calibration correction K from measurements with LDRCal / aCal
450 if (TypeC == 2) or (TypeC == 1): # rotator calibration Eq. C.4 463 if (TypeC == 2) or (TypeC == 1): # rotator calibration Eq. C.4
451 # parameters for calibration with aCal 464 # parameters for calibration with aCal
452 AT = ATP1*IinP + h*ATP4*VinP 465 AT = ATP1 * IinP + h * ATP4 * VinP
453 BT = ATP3e*QinP - h*ATP2e*UinP 466 BT = ATP3e * QinP - h * ATP2e * UinP
454 AR = ARP1*IinP + h*ARP4*VinP 467 AR = ARP1 * IinP + h * ARP4 * VinP
455 BR = ARP3e*QinP - h*ARP2e*UinP 468 BR = ARP3e * QinP - h * ARP2e * UinP
456 # Correction paremeters for normal measurements; they are independent of LDR 469 # Correction paremeters for normal measurements; they are independent of LDR
457 if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out 470 if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out
458 IS1 = np.array([IinPo,QinPo,UinPo,VinPo]) 471 IS1 = np.array([IinPo, QinPo, UinPo, VinPo])
459 IS2 = np.array([IinPa,QinPa,UinPa,VinPa]) 472 IS2 = np.array([IinPa, QinPa, UinPa, VinPa])
460 GT = np.dot(ATP,IS1) 473 GT = np.dot(ATP, IS1)
461 GR = np.dot(ARP,IS1) 474 GR = np.dot(ARP, IS1)
462 HT = np.dot(ATP,IS2) 475 HT = np.dot(ATP, IS2)
463 HR = np.dot(ARP,IS2) 476 HR = np.dot(ARP, IS2)
464 else: 477 else:
465 IS1 = np.array([IinPo,QinPo,UinPo,VinPo]) 478 IS1 = np.array([IinPo, QinPo, UinPo, VinPo])
466 IS2 = np.array([IinPa,QinPa,UinPa,VinPa]) 479 IS2 = np.array([IinPa, QinPa, UinPa, VinPa])
467 GT = np.dot(ATPe,IS1) 480 GT = np.dot(ATPe, IS1)
468 GR = np.dot(ARPe,IS1) 481 GR = np.dot(ARPe, IS1)
469 HT = np.dot(ATPe,IS2) 482 HT = np.dot(ATPe, IS2)
470 HR = np.dot(ARPe,IS2) 483 HR = np.dot(ARPe, IS2)
471 elif (TypeC == 3) or (TypeC == 4): # linear polariser calibration Eq. C.5 484 elif (TypeC == 3) or (TypeC == 4): # linear polariser calibration Eq. C.5
472 # parameters for calibration with aCal 485 # parameters for calibration with aCal
473 AT = ATP1*IinP + ATP3e*UinPe + ZiC*CosC*(ATP2e*QinPe + ATP4*VinP) 486 AT = ATP1 * IinP + ATP3e * UinPe + ZiC * CosC * (ATP2e * QinPe + ATP4 * VinP)
474 BT = DiC*(ATP1*UinPe + ATP3e*IinP) - ZiC*SinC*(ATP2e*VinP - ATP4*QinPe) 487 BT = DiC * (ATP1 * UinPe + ATP3e * IinP) - ZiC * SinC * (ATP2e * VinP - ATP4 * QinPe)
475 AR = ARP1*IinP + ARP3e*UinPe + ZiC*CosC*(ARP2e*QinPe + ARP4*VinP) 488 AR = ARP1 * IinP + ARP3e * UinPe + ZiC * CosC * (ARP2e * QinPe + ARP4 * VinP)
476 BR = DiC*(ARP1*UinPe + ARP3e*IinP) - ZiC*SinC*(ARP2e*VinP - ARP4*QinPe) 489 BR = DiC * (ARP1 * UinPe + ARP3e * IinP) - ZiC * SinC * (ARP2e * VinP - ARP4 * QinPe)
477 # Correction paremeters for normal measurements; they are independent of LDR 490 # Correction paremeters for normal measurements; they are independent of LDR
478 if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out 491 if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out
479 IS1 = np.array([IinPo,QinPo,UinPo,VinPo]) 492 IS1 = np.array([IinPo, QinPo, UinPo, VinPo])
480 IS2 = np.array([IinPa,QinPa,UinPa,VinPa]) 493 IS2 = np.array([IinPa, QinPa, UinPa, VinPa])
481 GT = np.dot(ATP,IS1) 494 GT = np.dot(ATP, IS1)
482 GR = np.dot(ARP,IS1) 495 GR = np.dot(ARP, IS1)
483 HT = np.dot(ATP,IS2) 496 HT = np.dot(ATP, IS2)
484 HR = np.dot(ARP,IS2) 497 HR = np.dot(ARP, IS2)
485 else: 498 else:
486 IS1e = np.array([IinPo+DiC*QinPoe,DiC*IinPo+QinPoe,ZiC*(CosC*UinPoe+SinC*VinPo),-ZiC*(SinC*UinPoe-CosC*VinPo)]) 499 IS1e = np.array([IinPo + DiC * QinPoe, DiC * IinPo + QinPoe, ZiC * (CosC * UinPoe + SinC * VinPo),
487 IS2e = np.array([IinPa+DiC*QinPae,DiC*IinPa+QinPae,ZiC*(CosC*UinPae+SinC*VinPa),-ZiC*(SinC*UinPae-CosC*VinPa)]) 500 -ZiC * (SinC * UinPoe - CosC * VinPo)])
488 GT = np.dot(ATPe,IS1e) 501 IS2e = np.array([IinPa + DiC * QinPae, DiC * IinPa + QinPae, ZiC * (CosC * UinPae + SinC * VinPa),
489 GR = np.dot(ARPe,IS1e) 502 -ZiC * (SinC * UinPae - CosC * VinPa)])
490 HT = np.dot(ATPe,IS2e) 503 GT = np.dot(ATPe, IS1e)
491 HR = np.dot(ARPe,IS2e) 504 GR = np.dot(ARPe, IS1e)
505 HT = np.dot(ATPe, IS2e)
506 HR = np.dot(ARPe, IS2e)
492 elif (TypeC == 6): # diattenuator calibration +-22.5° rotated_diattenuator_X22x5deg.odt 507 elif (TypeC == 6): # diattenuator calibration +-22.5° rotated_diattenuator_X22x5deg.odt
493 # parameters for calibration with aCal 508 # parameters for calibration with aCal
494 AT = ATP1*IinP + sqr05*DiC*(ATP1*QinPe + ATP2e*IinP) + (1-0.5*WiC)*(ATP2e*QinPe + ATP3e*UinPe) + ZiC*(sqr05*SinC*(ATP3e*VinP-ATP4*UinPe) + ATP4*CosC*VinP) 509 AT = ATP1 * IinP + sqr05 * DiC * (ATP1 * QinPe + ATP2e * IinP) + (1 - 0.5 * WiC) * (
495 BT = sqr05*DiC*(ATP1*UinPe + ATP3e*IinP) + 0.5*WiC*(ATP2e*UinPe + ATP3e*QinPe) - sqr05*ZiC*SinC*(ATP2e*VinP - ATP4*QinPe) 510 ATP2e * QinPe + ATP3e * UinPe) + ZiC * (sqr05 * SinC * (ATP3e * VinP - ATP4 * UinPe) + ATP4 * CosC * VinP)
496 AR = ARP1*IinP + sqr05*DiC*(ARP1*QinPe + ARP2e*IinP) + (1-0.5*WiC)*(ARP2e*QinPe + ARP3e*UinPe) + ZiC*(sqr05*SinC*(ARP3e*VinP-ARP4*UinPe) + ARP4*CosC*VinP) 511 BT = sqr05 * DiC * (ATP1 * UinPe + ATP3e * IinP) + 0.5 * WiC * (
497 BR = sqr05*DiC*(ARP1*UinPe + ARP3e*IinP) + 0.5*WiC*(ARP2e*UinPe + ARP3e*QinPe) - sqr05*ZiC*SinC*(ARP2e*VinP - ARP4*QinPe) 512 ATP2e * UinPe + ATP3e * QinPe) - sqr05 * ZiC * SinC * (ATP2e * VinP - ATP4 * QinPe)
513 AR = ARP1 * IinP + sqr05 * DiC * (ARP1 * QinPe + ARP2e * IinP) + (1 - 0.5 * WiC) * (
514 ARP2e * QinPe + ARP3e * UinPe) + ZiC * (sqr05 * SinC * (ARP3e * VinP - ARP4 * UinPe) + ARP4 * CosC * VinP)
515 BR = sqr05 * DiC * (ARP1 * UinPe + ARP3e * IinP) + 0.5 * WiC * (
516 ARP2e * UinPe + ARP3e * QinPe) - sqr05 * ZiC * SinC * (ARP2e * VinP - ARP4 * QinPe)
498 # Correction paremeters for normal measurements; they are independent of LDR 517 # Correction paremeters for normal measurements; they are independent of LDR
499 if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out 518 if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out
500 IS1 = np.array([IinPo,QinPo,UinPo,VinPo]) 519 IS1 = np.array([IinPo, QinPo, UinPo, VinPo])
501 IS2 = np.array([IinPa,QinPa,UinPa,VinPa]) 520 IS2 = np.array([IinPa, QinPa, UinPa, VinPa])
502 GT = np.dot(ATP,IS1) 521 GT = np.dot(ATP, IS1)
503 GR = np.dot(ARP,IS1) 522 GR = np.dot(ARP, IS1)
504 HT = np.dot(ATP,IS2) 523 HT = np.dot(ATP, IS2)
505 HR = np.dot(ARP,IS2) 524 HR = np.dot(ARP, IS2)
506 else: 525 else:
507 IS1e = np.array([IinPo+DiC*QinPoe,DiC*IinPo+QinPoe,ZiC*(CosC*UinPoe+SinC*VinPo),-ZiC*(SinC*UinPoe-CosC*VinPo)]) 526 IS1e = np.array([IinPo + DiC * QinPoe, DiC * IinPo + QinPoe, ZiC * (CosC * UinPoe + SinC * VinPo),
508 IS2e = np.array([IinPa+DiC*QinPae,DiC*IinPa+QinPae,ZiC*(CosC*UinPae+SinC*VinPa),-ZiC*(SinC*UinPae-CosC*VinPa)]) 527 -ZiC * (SinC * UinPoe - CosC * VinPo)])
509 GT = np.dot(ATPe,IS1e) 528 IS2e = np.array([IinPa + DiC * QinPae, DiC * IinPa + QinPae, ZiC * (CosC * UinPae + SinC * VinPa),
510 GR = np.dot(ARPe,IS1e) 529 -ZiC * (SinC * UinPae - CosC * VinPa)])
511 HT = np.dot(ATPe,IS2e) 530 GT = np.dot(ATPe, IS1e)
512 HR = np.dot(ARPe,IS2e) 531 GR = np.dot(ARPe, IS1e)
532 HT = np.dot(ATPe, IS2e)
533 HR = np.dot(ARPe, IS2e)
513 else: 534 else:
514 print("Calibrator not implemented yet") 535 print("Calibrator not implemented yet")
515 sys.exit() 536 sys.exit()
516 537
517 elif LocC == 3: # C before receiver optics Eq.57 538 elif LocC == 3: # C before receiver optics Eq.57
518 539
519 #S2ge = np.sin(np.deg2rad(2*RotO - 2*RotC)) 540 # S2ge = np.sin(np.deg2rad(2*RotO - 2*RotC))
520 #C2ge = np.cos(np.deg2rad(2*RotO - 2*RotC)) 541 # C2ge = np.cos(np.deg2rad(2*RotO - 2*RotC))
521 S2e = np.sin(np.deg2rad(2*RotC)) 542 S2e = np.sin(np.deg2rad(2 * RotC))
522 C2e = np.cos(np.deg2rad(2*RotC)) 543 C2e = np.cos(np.deg2rad(2 * RotC))
523 544
524 # As with C before the receiver optics (rotated_diattenuator_X22x5deg.odt) 545 # As with C before the receiver optics (rotated_diattenuator_X22x5deg.odt)
525 AF1 = np.array([1,C2g*DiO,S2g*DiO,0]) 546 AF1 = np.array([1, C2g * DiO, S2g * DiO, 0])
526 AF2 = np.array([C2g*DiO,1-S2g**2*WiO,S2g*C2g*WiO,-S2g*ZiO*SinO]) 547 AF2 = np.array([C2g * DiO, 1 - S2g ** 2 * WiO, S2g * C2g * WiO, -S2g * ZiO * SinO])
527 AF3 = np.array([S2g*DiO,S2g*C2g*WiO,1-C2g**2*WiO,C2g*ZiO*SinO]) 548 AF3 = np.array([S2g * DiO, S2g * C2g * WiO, 1 - C2g ** 2 * WiO, C2g * ZiO * SinO])
528 AF4 = np.array([0,S2g*SinO,-C2g*SinO,CosO]) 549 AF4 = np.array([0, S2g * SinO, -C2g * SinO, CosO])
529 550
530 ATF = (ATP1*AF1+ATP2*AF2+ATP3*AF3+ATP4*AF4) 551 ATF = (ATP1 * AF1 + ATP2 * AF2 + ATP3 * AF3 + ATP4 * AF4)
531 ARF = (ARP1*AF1+ARP2*AF2+ARP3*AF3+ARP4*AF4) 552 ARF = (ARP1 * AF1 + ARP2 * AF2 + ARP3 * AF3 + ARP4 * AF4)
532 ATF2 = ATF[1] 553 ATF2 = ATF[1]
533 ATF3 = ATF[2] 554 ATF3 = ATF[2]
534 ARF2 = ARF[1] 555 ARF2 = ARF[1]
535 ARF3 = ARF[2] 556 ARF3 = ARF[2]
536 557
537 # rotated AinF by epsilon 558 # rotated AinF by epsilon
538 ATF1 = ATF[0] 559 ATF1 = ATF[0]
539 ATF4 = ATF[3] 560 ATF4 = ATF[3]
540 ATF2e = C2e*ATF[1] + S2e*ATF[2] 561 ATF2e = C2e * ATF[1] + S2e * ATF[2]
541 ATF3e = C2e*ATF[2] - S2e*ATF[1] 562 ATF3e = C2e * ATF[2] - S2e * ATF[1]
542 ARF1 = ARF[0] 563 ARF1 = ARF[0]
543 ARF4 = ARF[3] 564 ARF4 = ARF[3]
544 ARF2e = C2e*ARF[1] + S2e*ARF[2] 565 ARF2e = C2e * ARF[1] + S2e * ARF[2]
545 ARF3e = C2e*ARF[2] - S2e*ARF[1] 566 ARF3e = C2e * ARF[2] - S2e * ARF[1]
546 567
547 ATFe = np.array([ATF1,ATF2e,ATF3e,ATF4]) 568 ATFe = np.array([ATF1, ATF2e, ATF3e, ATF4])
548 ARFe = np.array([ARF1,ARF2e,ARF3e,ARF4]) 569 ARFe = np.array([ARF1, ARF2e, ARF3e, ARF4])
549 570
550 QinEe = C2e*QinE + S2e*UinE 571 QinEe = C2e * QinE + S2e * UinE
551 UinEe = C2e*UinE - S2e*QinE 572 UinEe = C2e * UinE - S2e * QinE
552 573
553 # Stokes Input Vector before receiver optics Eq. E.19 (after atmosphere F) 574 # Stokes Input Vector before receiver optics Eq. E.19 (after atmosphere F)
554 IinF = IinE 575 IinF = IinE
555 QinF = aCal*QinE 576 QinF = aCal * QinE
556 UinF = -aCal*UinE 577 UinF = -aCal * UinE
557 VinF = (1.-2.*aCal)*VinE 578 VinF = (1. - 2. * aCal) * VinE
558 579
559 IinFo = IinE 580 IinFo = IinE
560 QinFo = 0. 581 QinFo = 0.
561 UinFo = 0. 582 UinFo = 0.
562 VinFo = VinE 583 VinFo = VinE
563 584
564 IinFa = 0. 585 IinFa = 0.
565 QinFa = QinE 586 QinFa = QinE
566 UinFa = -UinE 587 UinFa = -UinE
567 VinFa = -2.*VinE 588 VinFa = -2. * VinE
568 589
569 # Stokes Input Vector before receiver optics rotated by epsilon Eq. C.3 590 # Stokes Input Vector before receiver optics rotated by epsilon Eq. C.3
570 QinFe = C2e*QinF + S2e*UinF 591 QinFe = C2e * QinF + S2e * UinF
571 UinFe = C2e*UinF - S2e*QinF 592 UinFe = C2e * UinF - S2e * QinF
572 QinFoe = C2e*QinFo + S2e*UinFo 593 QinFoe = C2e * QinFo + S2e * UinFo
573 UinFoe = C2e*UinFo - S2e*QinFo 594 UinFoe = C2e * UinFo - S2e * QinFo
574 QinFae = C2e*QinFa + S2e*UinFa 595 QinFae = C2e * QinFa + S2e * UinFa
575 UinFae = C2e*UinFa - S2e*QinFa 596 UinFae = C2e * UinFa - S2e * QinFa
576 597
577 # Calibration signals and Calibration correction K from measurements with LDRCal / aCal 598 # Calibration signals and Calibration correction K from measurements with LDRCal / aCal
578 if (TypeC == 2) or (TypeC == 1): # rotator calibration Eq. C.4 599 if (TypeC == 2) or (TypeC == 1): # rotator calibration Eq. C.4
579 # parameters for calibration with aCal 600 # parameters for calibration with aCal
580 AT = ATF1*IinF + ATF4*h*VinF 601 AT = ATF1 * IinF + ATF4 * h * VinF
581 BT = ATF3e*QinF - ATF2e*h*UinF 602 BT = ATF3e * QinF - ATF2e * h * UinF
582 AR = ARF1*IinF + ARF4*h*VinF 603 AR = ARF1 * IinF + ARF4 * h * VinF
583 BR = ARF3e*QinF - ARF2e*h*UinF 604 BR = ARF3e * QinF - ARF2e * h * UinF
584 # Correction paremeters for normal measurements; they are independent of LDR 605 # Correction paremeters for normal measurements; they are independent of LDR
585 if (not RotationErrorEpsilonForNormalMeasurements): 606 if (not RotationErrorEpsilonForNormalMeasurements):
586 GT = ATF1*IinE + ATF4*VinE 607 GT = ATF1 * IinE + ATF4 * VinE
587 GR = ARF1*IinE + ARF4*VinE 608 GR = ARF1 * IinE + ARF4 * VinE
588 HT = ATF2*QinE - ATF3*UinE - ATF4*2*VinE 609 HT = ATF2 * QinE - ATF3 * UinE - ATF4 * 2 * VinE
589 HR = ARF2*QinE - ARF3*UinE - ARF4*2*VinE 610 HR = ARF2 * QinE - ARF3 * UinE - ARF4 * 2 * VinE
590 else: 611 else:
591 GT = ATF1*IinE + ATF4*h*VinE 612 GT = ATF1 * IinE + ATF4 * h * VinE
592 GR = ARF1*IinE + ARF4*h*VinE 613 GR = ARF1 * IinE + ARF4 * h * VinE
593 HT = ATF2e*QinE - ATF3e*h*UinE - ATF4*h*2*VinE 614 HT = ATF2e * QinE - ATF3e * h * UinE - ATF4 * h * 2 * VinE
594 HR = ARF2e*QinE - ARF3e*h*UinE - ARF4*h*2*VinE 615 HR = ARF2e * QinE - ARF3e * h * UinE - ARF4 * h * 2 * VinE
595 elif (TypeC == 3) or (TypeC == 4): # linear polariser calibration Eq. C.5 616 elif (TypeC == 3) or (TypeC == 4): # linear polariser calibration Eq. C.5
596 # p = +45°, m = -45° 617 # p = +45°, m = -45°
597 IF1e = np.array([IinF, ZiC*CosC*QinFe, UinFe, ZiC*CosC*VinF]) 618 IF1e = np.array([IinF, ZiC * CosC * QinFe, UinFe, ZiC * CosC * VinF])
598 IF2e = np.array([DiC*UinFe, -ZiC*SinC*VinF, DiC*IinF, ZiC*SinC*QinFe]) 619 IF2e = np.array([DiC * UinFe, -ZiC * SinC * VinF, DiC * IinF, ZiC * SinC * QinFe])
599 AT = np.dot(ATFe,IF1e) 620 AT = np.dot(ATFe, IF1e)
600 AR = np.dot(ARFe,IF1e) 621 AR = np.dot(ARFe, IF1e)
601 BT = np.dot(ATFe,IF2e) 622 BT = np.dot(ATFe, IF2e)
602 BR = np.dot(ARFe,IF2e) 623 BR = np.dot(ARFe, IF2e)
603 624
604 # Correction paremeters for normal measurements; they are independent of LDR --- the same as for TypeC = 6 625 # Correction paremeters for normal measurements; they are independent of LDR --- the same as for TypeC = 6
605 if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out 626 if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out
606 IS1 = np.array([IinE,0,0,VinE]) 627 IS1 = np.array([IinE, 0, 0, VinE])
607 IS2 = np.array([0,QinE,-UinE,-2*VinE]) 628 IS2 = np.array([0, QinE, -UinE, -2 * VinE])
608 GT = np.dot(ATF,IS1) 629 GT = np.dot(ATF, IS1)
609 GR = np.dot(ARF,IS1) 630 GR = np.dot(ARF, IS1)
610 HT = np.dot(ATF,IS2) 631 HT = np.dot(ATF, IS2)
611 HR = np.dot(ARF,IS2) 632 HR = np.dot(ARF, IS2)
612 else: 633 else:
613 IS1e = np.array([IinFo+DiC*QinFoe,DiC*IinFo+QinFoe,ZiC*(CosC*UinFoe+SinC*VinFo),-ZiC*(SinC*UinFoe-CosC*VinFo)]) 634 IS1e = np.array([IinFo + DiC * QinFoe, DiC * IinFo + QinFoe, ZiC * (CosC * UinFoe + SinC * VinFo),
614 IS2e = np.array([IinFa+DiC*QinFae,DiC*IinFa+QinFae,ZiC*(CosC*UinFae+SinC*VinFa),-ZiC*(SinC*UinFae-CosC*VinFa)]) 635 -ZiC * (SinC * UinFoe - CosC * VinFo)])
615 GT = np.dot(ATFe,IS1e) 636 IS2e = np.array([IinFa + DiC * QinFae, DiC * IinFa + QinFae, ZiC * (CosC * UinFae + SinC * VinFa),
616 GR = np.dot(ARFe,IS1e) 637 -ZiC * (SinC * UinFae - CosC * VinFa)])
617 HT = np.dot(ATFe,IS2e) 638 GT = np.dot(ATFe, IS1e)
618 HR = np.dot(ARFe,IS2e) 639 GR = np.dot(ARFe, IS1e)
640 HT = np.dot(ATFe, IS2e)
641 HR = np.dot(ARFe, IS2e)
619 642
620 elif (TypeC == 6): # diattenuator calibration +-22.5° rotated_diattenuator_X22x5deg.odt 643 elif (TypeC == 6): # diattenuator calibration +-22.5° rotated_diattenuator_X22x5deg.odt
621 # parameters for calibration with aCal 644 # parameters for calibration with aCal
622 IF1e = np.array([IinF+sqr05*DiC*QinFe, sqr05*DiC*IinF+(1-0.5*WiC)*QinFe, (1-0.5*WiC)*UinFe+sqr05*ZiC*SinC*VinF, -sqr05*ZiC*SinC*UinFe+ZiC*CosC*VinF]) 645 IF1e = np.array([IinF + sqr05 * DiC * QinFe, sqr05 * DiC * IinF + (1 - 0.5 * WiC) * QinFe,
623 IF2e = np.array([sqr05*DiC*UinFe, 0.5*WiC*UinFe-sqr05*ZiC*SinC*VinF, sqr05*DiC*IinF+0.5*WiC*QinFe, sqr05*ZiC*SinC*QinFe]) 646 (1 - 0.5 * WiC) * UinFe + sqr05 * ZiC * SinC * VinF,
624 AT = np.dot(ATFe,IF1e) 647 -sqr05 * ZiC * SinC * UinFe + ZiC * CosC * VinF])
625 AR = np.dot(ARFe,IF1e) 648 IF2e = np.array([sqr05 * DiC * UinFe, 0.5 * WiC * UinFe - sqr05 * ZiC * SinC * VinF,
626 BT = np.dot(ATFe,IF2e) 649 sqr05 * DiC * IinF + 0.5 * WiC * QinFe, sqr05 * ZiC * SinC * QinFe])
627 BR = np.dot(ARFe,IF2e) 650 AT = np.dot(ATFe, IF1e)
651 AR = np.dot(ARFe, IF1e)
652 BT = np.dot(ATFe, IF2e)
653 BR = np.dot(ARFe, IF2e)
628 654
629 # Correction paremeters for normal measurements; they are independent of LDR 655 # Correction paremeters for normal measurements; they are independent of LDR
630 if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out 656 if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out
631 #IS1 = np.array([IinE,0,0,VinE]) 657 # IS1 = np.array([IinE,0,0,VinE])
632 #IS2 = np.array([0,QinE,-UinE,-2*VinE]) 658 # IS2 = np.array([0,QinE,-UinE,-2*VinE])
633 IS1 = np.array([IinFo,0,0,VinFo]) 659 IS1 = np.array([IinFo, 0, 0, VinFo])
634 IS2 = np.array([0,QinFa,UinFa,VinFa]) 660 IS2 = np.array([0, QinFa, UinFa, VinFa])
635 GT = np.dot(ATF,IS1) 661 GT = np.dot(ATF, IS1)
636 GR = np.dot(ARF,IS1) 662 GR = np.dot(ARF, IS1)
637 HT = np.dot(ATF,IS2) 663 HT = np.dot(ATF, IS2)
638 HR = np.dot(ARF,IS2) 664 HR = np.dot(ARF, IS2)
639 else: 665 else:
640 IS1e = np.array([IinFo+DiC*QinFoe,DiC*IinFo+QinFoe,ZiC*(CosC*UinFoe+SinC*VinFo),-ZiC*(SinC*UinFoe-CosC*VinFo)]) 666 IS1e = np.array([IinFo + DiC * QinFoe, DiC * IinFo + QinFoe, ZiC * (CosC * UinFoe + SinC * VinFo),
641 IS2e = np.array([IinFa+DiC*QinFae,DiC*IinFa+QinFae,ZiC*(CosC*UinFae+SinC*VinFa),-ZiC*(SinC*UinFae-CosC*VinFa)]) 667 -ZiC * (SinC * UinFoe - CosC * VinFo)])
642 #IS1e = np.array([IinFo,0,0,VinFo]) 668 IS2e = np.array([IinFa + DiC * QinFae, DiC * IinFa + QinFae, ZiC * (CosC * UinFae + SinC * VinFa),
643 #IS2e = np.array([0,QinFae,UinFae,VinFa]) 669 -ZiC * (SinC * UinFae - CosC * VinFa)])
644 GT = np.dot(ATFe,IS1e) 670 # IS1e = np.array([IinFo,0,0,VinFo])
645 GR = np.dot(ARFe,IS1e) 671 # IS2e = np.array([0,QinFae,UinFae,VinFa])
646 HT = np.dot(ATFe,IS2e) 672 GT = np.dot(ATFe, IS1e)
647 HR = np.dot(ARFe,IS2e) 673 GR = np.dot(ARFe, IS1e)
674 HT = np.dot(ATFe, IS2e)
675 HR = np.dot(ARFe, IS2e)
648 676
649 else: 677 else:
650 print('Calibrator not implemented yet') 678 print('Calibrator not implemented yet')
651 sys.exit() 679 sys.exit()
652 680
653 elif LocC == 2: # C behind emitter optics Eq.57 ------------------------------------------------------- 681 elif LocC == 2: # C behind emitter optics Eq.57 -------------------------------------------------------
654 #print("Calibrator location not implemented yet") 682 # print("Calibrator location not implemented yet")
655 S2e = np.sin(np.deg2rad(2*RotC)) 683 S2e = np.sin(np.deg2rad(2 * RotC))
656 C2e = np.cos(np.deg2rad(2*RotC)) 684 C2e = np.cos(np.deg2rad(2 * RotC))
657 685
658 # AS with C before the receiver optics (see document rotated_diattenuator_X22x5deg.odt) 686 # AS with C before the receiver optics (see document rotated_diattenuator_X22x5deg.odt)
659 AF1 = np.array([1,C2g*DiO,S2g*DiO,0]) 687 AF1 = np.array([1, C2g * DiO, S2g * DiO, 0])
660 AF2 = np.array([C2g*DiO,1-S2g**2*WiO,S2g*C2g*WiO,-S2g*ZiO*SinO]) 688 AF2 = np.array([C2g * DiO, 1 - S2g ** 2 * WiO, S2g * C2g * WiO, -S2g * ZiO * SinO])
661 AF3 = np.array([S2g*DiO, S2g*C2g*WiO, 1-C2g**2*WiO, C2g*ZiO*SinO]) 689 AF3 = np.array([S2g * DiO, S2g * C2g * WiO, 1 - C2g ** 2 * WiO, C2g * ZiO * SinO])
662 AF4 = np.array([0, S2g*SinO, -C2g*SinO, CosO]) 690 AF4 = np.array([0, S2g * SinO, -C2g * SinO, CosO])
663 691
664 ATF = (ATP1*AF1+ATP2*AF2+ATP3*AF3+ATP4*AF4) 692 ATF = (ATP1 * AF1 + ATP2 * AF2 + ATP3 * AF3 + ATP4 * AF4)
665 ARF = (ARP1*AF1+ARP2*AF2+ARP3*AF3+ARP4*AF4) 693 ARF = (ARP1 * AF1 + ARP2 * AF2 + ARP3 * AF3 + ARP4 * AF4)
666 ATF1 = ATF[0] 694 ATF1 = ATF[0]
667 ATF2 = ATF[1] 695 ATF2 = ATF[1]
668 ATF3 = ATF[2] 696 ATF3 = ATF[2]
669 ATF4 = ATF[3] 697 ATF4 = ATF[3]
670 ARF1 = ARF[0] 698 ARF1 = ARF[0]
677 ATE1o, ARE1o = ATF1, ARF1 705 ATE1o, ARE1o = ATF1, ARF1
678 ATE2o, ARE2o = 0., 0. 706 ATE2o, ARE2o = 0., 0.
679 ATE3o, ARE3o = 0., 0. 707 ATE3o, ARE3o = 0., 0.
680 ATE4o, ARE4o = ATF4, ARF4 708 ATE4o, ARE4o = ATF4, ARF4
681 # terms with aCal 709 # terms with aCal
682 ATE1a, ARE1a = 0. , 0. 710 ATE1a, ARE1a = 0., 0.
683 ATE2a, ARE2a = ATF2, ARF2 711 ATE2a, ARE2a = ATF2, ARF2
684 ATE3a, ARE3a = -ATF3, -ARF3 712 ATE3a, ARE3a = -ATF3, -ARF3
685 ATE4a, ARE4a = -2*ATF4, -2*ARF4 713 ATE4a, ARE4a = -2 * ATF4, -2 * ARF4
686 # rotated AinEa by epsilon 714 # rotated AinEa by epsilon
687 ATE2ae = C2e*ATF2 + S2e*ATF3 715 ATE2ae = C2e * ATF2 + S2e * ATF3
688 ATE3ae = -S2e*ATF2 - C2e*ATF3 716 ATE3ae = -S2e * ATF2 - C2e * ATF3
689 ARE2ae = C2e*ARF2 + S2e*ARF3 717 ARE2ae = C2e * ARF2 + S2e * ARF3
690 ARE3ae = -S2e*ARF2 - C2e*ARF3 718 ARE3ae = -S2e * ARF2 - C2e * ARF3
691 719
692 ATE1 = ATE1o 720 ATE1 = ATE1o
693 ATE2e = aCal*ATE2ae 721 ATE2e = aCal * ATE2ae
694 ATE3e = aCal*ATE3ae 722 ATE3e = aCal * ATE3ae
695 ATE4 = (1-2*aCal)*ATF4 723 ATE4 = (1 - 2 * aCal) * ATF4
696 ARE1 = ARE1o 724 ARE1 = ARE1o
697 ARE2e = aCal*ARE2ae 725 ARE2e = aCal * ARE2ae
698 ARE3e = aCal*ARE3ae 726 ARE3e = aCal * ARE3ae
699 ARE4 = (1-2*aCal)*ARF4 727 ARE4 = (1 - 2 * aCal) * ARF4
700 728
701 # rotated IinE 729 # rotated IinE
702 QinEe = C2e*QinE + S2e*UinE 730 QinEe = C2e * QinE + S2e * UinE
703 UinEe = C2e*UinE - S2e*QinE 731 UinEe = C2e * UinE - S2e * QinE
704 732
705 # Calibration signals and Calibration correction K from measurements with LDRCal / aCal 733 # Calibration signals and Calibration correction K from measurements with LDRCal / aCal
706 if (TypeC == 2) or (TypeC == 1): # +++++++++ rotator calibration Eq. C.4 734 if (TypeC == 2) or (TypeC == 1): # +++++++++ rotator calibration Eq. C.4
707 AT = ATE1o*IinE + (ATE4o+aCal*ATE4a)*h*VinE 735 AT = ATE1o * IinE + (ATE4o + aCal * ATE4a) * h * VinE
708 BT = aCal * (ATE3ae*QinEe - ATE2ae*h*UinEe) 736 BT = aCal * (ATE3ae * QinEe - ATE2ae * h * UinEe)
709 AR = ARE1o*IinE + (ARE4o+aCal*ARE4a)*h*VinE 737 AR = ARE1o * IinE + (ARE4o + aCal * ARE4a) * h * VinE
710 BR = aCal * (ARE3ae*QinEe - ARE2ae*h*UinEe) 738 BR = aCal * (ARE3ae * QinEe - ARE2ae * h * UinEe)
711 739
712 # Correction paremeters for normal measurements; they are independent of LDR 740 # Correction paremeters for normal measurements; they are independent of LDR
713 if (not RotationErrorEpsilonForNormalMeasurements): 741 if (not RotationErrorEpsilonForNormalMeasurements):
714 # Stokes Input Vector before receiver optics Eq. E.19 (after atmosphere F) 742 # Stokes Input Vector before receiver optics Eq. E.19 (after atmosphere F)
715 GT = ATE1o*IinE + ATE4o*h*VinE 743 GT = ATE1o * IinE + ATE4o * h * VinE
716 GR = ARE1o*IinE + ARE4o*h*VinE 744 GR = ARE1o * IinE + ARE4o * h * VinE
717 HT = ATE2a*QinE + ATE3a*h*UinEe + ATE4a*h*VinE 745 HT = ATE2a * QinE + ATE3a * h * UinEe + ATE4a * h * VinE
718 HR = ARE2a*QinE + ARE3a*h*UinEe + ARE4a*h*VinE 746 HR = ARE2a * QinE + ARE3a * h * UinEe + ARE4a * h * VinE
719 else: 747 else:
720 GT = ATE1o*IinE + ATE4o*h*VinE 748 GT = ATE1o * IinE + ATE4o * h * VinE
721 GR = ARE1o*IinE + ARE4o*h*VinE 749 GR = ARE1o * IinE + ARE4o * h * VinE
722 HT = ATE2ae*QinE + ATE3ae*h*UinEe + ATE4a*h*VinE 750 HT = ATE2ae * QinE + ATE3ae * h * UinEe + ATE4a * h * VinE
723 HR = ARE2ae*QinE + ARE3ae*h*UinEe + ARE4a*h*VinE 751 HR = ARE2ae * QinE + ARE3ae * h * UinEe + ARE4a * h * VinE
724 752
725 elif (TypeC == 3) or (TypeC == 4): # +++++++++ linear polariser calibration Eq. C.5 753 elif (TypeC == 3) or (TypeC == 4): # +++++++++ linear polariser calibration Eq. C.5
726 # p = +45°, m = -45° 754 # p = +45°, m = -45°
727 AT = ATE1*IinE + ZiC*CosC*(ATE2e*QinEe + ATE4*VinE) + ATE3e*UinEe 755 AT = ATE1 * IinE + ZiC * CosC * (ATE2e * QinEe + ATE4 * VinE) + ATE3e * UinEe
728 BT = DiC*(ATE1*UinEe + ATE3e*IinE) + ZiC*SinC*(ATE4*QinEe - ATE2e*VinE) 756 BT = DiC * (ATE1 * UinEe + ATE3e * IinE) + ZiC * SinC * (ATE4 * QinEe - ATE2e * VinE)
729 AR = ARE1*IinE + ZiC*CosC*(ARE2e*QinEe + ARE4*VinE) + ARE3e*UinEe 757 AR = ARE1 * IinE + ZiC * CosC * (ARE2e * QinEe + ARE4 * VinE) + ARE3e * UinEe
730 BR = DiC*(ARE1*UinEe + ARE3e*IinE) + ZiC*SinC*(ARE4*QinEe - ARE2e*VinE) 758 BR = DiC * (ARE1 * UinEe + ARE3e * IinE) + ZiC * SinC * (ARE4 * QinEe - ARE2e * VinE)
731 759
732 # Correction paremeters for normal measurements; they are independent of LDR 760 # Correction paremeters for normal measurements; they are independent of LDR
733 if (not RotationErrorEpsilonForNormalMeasurements): 761 if (not RotationErrorEpsilonForNormalMeasurements):
734 # Stokes Input Vector before receiver optics Eq. E.19 (after atmosphere F) 762 # Stokes Input Vector before receiver optics Eq. E.19 (after atmosphere F)
735 GT = ATE1o*IinE + ATE4o*VinE 763 GT = ATE1o * IinE + ATE4o * VinE
736 GR = ARE1o*IinE + ARE4o*VinE 764 GR = ARE1o * IinE + ARE4o * VinE
737 HT = ATE2a*QinE + ATE3a*UinE + ATE4a*VinE 765 HT = ATE2a * QinE + ATE3a * UinE + ATE4a * VinE
738 HR = ARE2a*QinE + ARE3a*UinE + ARE4a*VinE 766 HR = ARE2a * QinE + ARE3a * UinE + ARE4a * VinE
739 else: 767 else:
740 D = IinE + DiC*QinEe 768 D = IinE + DiC * QinEe
741 A = DiC*IinE + QinEe 769 A = DiC * IinE + QinEe
742 B = ZiC*(CosC*UinEe + SinC*VinE) 770 B = ZiC * (CosC * UinEe + SinC * VinE)
743 C = -ZiC*(SinC*UinEe - CosC*VinE) 771 C = -ZiC * (SinC * UinEe - CosC * VinE)
744 GT = ATE1o*D + ATE4o*C 772 GT = ATE1o * D + ATE4o * C
745 GR = ARE1o*D + ARE4o*C 773 GR = ARE1o * D + ARE4o * C
746 HT = ATE2a*A + ATE3a*B + ATE4a*C 774 HT = ATE2a * A + ATE3a * B + ATE4a * C
747 HR = ARE2a*A + ARE3a*B + ARE4a*C 775 HR = ARE2a * A + ARE3a * B + ARE4a * C
748 776
749 elif (TypeC == 6): # real HWP calibration +-22.5° rotated_diattenuator_X22x5deg.odt 777 elif (TypeC == 6): # real HWP calibration +-22.5° rotated_diattenuator_X22x5deg.odt
750 # p = +22.5°, m = -22.5° 778 # p = +22.5°, m = -22.5°
751 IE1e = np.array([IinE+sqr05*DiC*QinEe, sqr05*DiC*IinE+(1-0.5*WiC)*QinEe, (1-0.5*WiC)*UinEe+sqr05*ZiC*SinC*VinE, -sqr05*ZiC*SinC*UinEe+ZiC*CosC*VinE]) 779 IE1e = np.array([IinE + sqr05 * DiC * QinEe, sqr05 * DiC * IinE + (1 - 0.5 * WiC) * QinEe,
752 IE2e = np.array([sqr05*DiC*UinEe, 0.5*WiC*UinEe-sqr05*ZiC*SinC*VinE, sqr05*DiC*IinE+0.5*WiC*QinEe, sqr05*ZiC*SinC*QinEe]) 780 (1 - 0.5 * WiC) * UinEe + sqr05 * ZiC * SinC * VinE,
753 ATEe = np.array([ATE1,ATE2e,ATE3e,ATE4]) 781 -sqr05 * ZiC * SinC * UinEe + ZiC * CosC * VinE])
754 AREe = np.array([ARE1,ARE2e,ARE3e,ARE4]) 782 IE2e = np.array([sqr05 * DiC * UinEe, 0.5 * WiC * UinEe - sqr05 * ZiC * SinC * VinE,
755 AT = np.dot(ATEe,IE1e) 783 sqr05 * DiC * IinE + 0.5 * WiC * QinEe, sqr05 * ZiC * SinC * QinEe])
756 AR = np.dot(AREe,IE1e) 784 ATEe = np.array([ATE1, ATE2e, ATE3e, ATE4])
757 BT = np.dot(ATEe,IE2e) 785 AREe = np.array([ARE1, ARE2e, ARE3e, ARE4])
758 BR = np.dot(AREe,IE2e) 786 AT = np.dot(ATEe, IE1e)
787 AR = np.dot(AREe, IE1e)
788 BT = np.dot(ATEe, IE2e)
789 BR = np.dot(AREe, IE2e)
759 790
760 # Correction paremeters for normal measurements; they are independent of LDR 791 # Correction paremeters for normal measurements; they are independent of LDR
761 if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out 792 if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out
762 GT = ATE1o*IinE + ATE4o*VinE 793 GT = ATE1o * IinE + ATE4o * VinE
763 GR = ARE1o*IinE + ARE4o*VinE 794 GR = ARE1o * IinE + ARE4o * VinE
764 HT = ATE2a*QinE + ATE3a*UinE + ATE4a*VinE 795 HT = ATE2a * QinE + ATE3a * UinE + ATE4a * VinE
765 HR = ARE2a*QinE + ARE3a*UinE + ARE4a*VinE 796 HR = ARE2a * QinE + ARE3a * UinE + ARE4a * VinE
766 else: 797 else:
767 D = IinE + DiC*QinEe 798 D = IinE + DiC * QinEe
768 A = DiC*IinE + QinEe 799 A = DiC * IinE + QinEe
769 B = ZiC*(CosC*UinEe + SinC*VinE) 800 B = ZiC * (CosC * UinEe + SinC * VinE)
770 C = -ZiC*(SinC*UinEe - CosC*VinE) 801 C = -ZiC * (SinC * UinEe - CosC * VinE)
771 GT = ATE1o*D + ATE4o*C 802 GT = ATE1o * D + ATE4o * C
772 GR = ARE1o*D + ARE4o*C 803 GR = ARE1o * D + ARE4o * C
773 HT = ATE2a*A + ATE3a*B + ATE4a*C 804 HT = ATE2a * A + ATE3a * B + ATE4a * C
774 HR = ARE2a*A + ARE3a*B + ARE4a*C 805 HR = ARE2a * A + ARE3a * B + ARE4a * C
775 806
776 else: 807 else:
777 print('Calibrator not implemented yet') 808 print('Calibrator not implemented yet')
778 sys.exit() 809 sys.exit()
779 810
780 else: 811 else:
781 print("Calibrator location not implemented yet") 812 print("Calibrator location not implemented yet")
782 sys.exit() 813 sys.exit()
783 814
784 # Determination of the correction K of the calibration factor 815 # Determination of the correction K of the calibration factor
785 IoutTp = TaT*TiT*TiO*TiE*(AT + BT) 816 IoutTp = TaT * TiT * TiO * TiE * (AT + BT)
786 IoutTm = TaT*TiT*TiO*TiE*(AT - BT) 817 IoutTm = TaT * TiT * TiO * TiE * (AT - BT)
787 IoutRp = TaR*TiR*TiO*TiE*(AR + BR) 818 IoutRp = TaR * TiR * TiO * TiE * (AR + BR)
788 IoutRm = TaR*TiR*TiO*TiE*(AR - BR) 819 IoutRm = TaR * TiR * TiO * TiE * (AR - BR)
789 820
790 # --- Results and Corrections; electronic etaR and etaT are assumed to be 1 821 # --- Results and Corrections; electronic etaR and etaT are assumed to be 1
791 Etapx = IoutRp/IoutTp 822 Etapx = IoutRp / IoutTp
792 Etamx = IoutRm/IoutTm 823 Etamx = IoutRm / IoutTm
793 Etax = (Etapx*Etamx)**0.5 824 Etax = (Etapx * Etamx) ** 0.5
794 825
795 Eta = (TaR*TiR)/(TaT*TiT) # Eta = Eta*/K Eq. 84 826 Eta = (TaR * TiR) / (TaT * TiT) # Eta = Eta*/K Eq. 84
796 K = Etax / Eta 827 K = Etax / Eta
797 828
798 # For comparison with Volkers Libreoffice Müller Matrix spreadsheet 829 # For comparison with Volkers Libreoffice Müller Matrix spreadsheet
799 #Eta_test_p = (IoutRp/IoutTp) 830 # Eta_test_p = (IoutRp/IoutTp)
800 #Eta_test_m = (IoutRm/IoutTm) 831 # Eta_test_m = (IoutRm/IoutTm)
801 #Eta_test = (Eta_test_p*Eta_test_m)**0.5 832 # Eta_test = (Eta_test_p*Eta_test_m)**0.5
802 833
803 # ----- Forward simulated signals and LDRsim with atrue; from input file 834 # ----- Forward simulated signals and LDRsim with atrue; from input file
804 It = TaT*TiT*TiO*TiE*(GT+atrue*HT) 835 It = TaT * TiT * TiO * TiE * (GT + atrue * HT)
805 Ir = TaR*TiR*TiO*TiE*(GR+atrue*HR) 836 Ir = TaR * TiR * TiO * TiE * (GR + atrue * HR)
806 # LDRsim = 1/Eta*Ir/It # simulated LDR* with Y from input file 837 # LDRsim = 1/Eta*Ir/It # simulated LDR* with Y from input file
807 LDRsim = Ir/It # simulated uncorrected LDR with Y from input file 838 LDRsim = Ir / It # simulated uncorrected LDR with Y from input file
808 # Corrected LDRsimCorr from forward simulated LDRsim (atrue) 839 # Corrected LDRsimCorr from forward simulated LDRsim (atrue)
809 # LDRsimCorr = (1./Eta*LDRsim*(GT+HT)-(GR+HR))/((GR-HR)-1./Eta*LDRsim*(GT-HT)) 840 # LDRsimCorr = (1./Eta*LDRsim*(GT+HT)-(GR+HR))/((GR-HR)-1./Eta*LDRsim*(GT-HT))
810 if Y == -1.: 841 if Y == -1.:
811 LDRsimx = 1./LDRsim 842 LDRsimx = 1. / LDRsim
812 else: 843 else:
813 LDRsimx = LDRsim 844 LDRsimx = LDRsim
814 845
815 # The following is correct without doubt 846 # The following is correct without doubt
816 #LDRCorr = (LDRsim*K/Etax*(GT+HT)-(GR+HR))/((GR-HR)-LDRsim*K/Etax*(GT-HT)) 847 # LDRCorr = (LDRsim*K/Etax*(GT+HT)-(GR+HR))/((GR-HR)-LDRsim*K/Etax*(GT-HT))
817 848
818 # The following is a test whether the equations for calibration Etax and normal signal (GHK, LDRsim) are consistent 849 # The following is a test whether the equations for calibration Etax and normal signal (GHK, LDRsim) are consistent
819 LDRCorr = (LDRsim/Eta*(GT+HT)-(GR+HR))/((GR-HR)-LDRsim*K/Etax*(GT-HT)) 850 LDRCorr = (LDRsim / Eta * (GT + HT) - (GR + HR)) / ((GR - HR) - LDRsim * K / Etax * (GT - HT))
820 851
821 TTa = TiT*TaT #*ATP1 852 TTa = TiT * TaT # *ATP1
822 TRa = TiR*TaR #*ARP1 853 TRa = TiR * TaR # *ARP1
823 854
824 F11sim = 1/(TiO*TiE)*((HR*Etax/K*It/TTa-HT*Ir/TRa)/(HR*GT-HT*GR)) # IL = 1, Etat = Etar = 1 855 F11sim = 1 / (TiO * TiE) * (
856 (HR * Etax / K * It / TTa - HT * Ir / TRa) / (HR * GT - HT * GR)) # IL = 1, Etat = Etar = 1
825 857
826 return (GT, HT, GR, HR, K, Eta, LDRsimx, LDRCorr, DTa, DRa, TTa, TRa, F11sim) 858 return (GT, HT, GR, HR, K, Eta, LDRsimx, LDRCorr, DTa, DRa, TTa, TRa, F11sim)
859
860
827 # ******************************************************************************************************************************* 861 # *******************************************************************************************************************************
828 862
829 # --- CALC truth 863 # --- CALC truth
830 GT0, HT0, GR0, HR0, K0, Eta0, LDRsimx, LDRCorr, DTa0, DRa0, TTa0, TRa0, F11sim0 = Calc(RotL0, RotE0, RetE0, DiE0, RotO0, RetO0, DiO0, RotC0, RetC0, DiC0, TP0, TS0, RP0, RS0, ERaT0, RotaT0, RetT0, ERaR0, RotaR0, RetR0, LDRCal0) 864 GT0, HT0, GR0, HR0, K0, Eta0, LDRsimx, LDRCorr, DTa0, DRa0, TTa0, TRa0, F11sim0 = Calc(RotL0, RotE0, RetE0, DiE0, RotO0,
865 RetO0, DiO0, RotC0, RetC0, DiC0,
866 TP0, TS0, RP0, RS0, ERaT0,
867 RotaT0, RetT0, ERaR0, RotaR0,
868 RetR0, LDRCal0)
831 869
832 # --- Print parameters to console and output file 870 # --- Print parameters to console and output file
833 with open('output_files\output_' + LID + '.dat', 'w') as f: 871 with open('output_files\output_' + LID + '.dat', 'w') as f:
834 with redirect_stdout(f): 872 with redirect_stdout(f):
835 print("From ", dname) 873 print("From ", dname)
836 print("Running ", fname) 874 print("Running ", fname)
837 print("Reading input file ", InputFile) #, " for Lidar system :", EID, ", ", LID) 875 print("Reading input file ", InputFile) # , " for Lidar system :", EID, ", ", LID)
838 print("for Lidar system: ", EID, ", ", LID) 876 print("for Lidar system: ", EID, ", ", LID)
839 # --- Print iput information********************************* 877 # --- Print iput information*********************************
840 print(" --- Input parameters: value ±error / ±steps ----------------------") 878 print(" --- Input parameters: value ±error / ±steps ----------------------")
841 print("{0:8} {1:8} {2:8.5f}; {3:8} {4:7.4f}±{5:7.4f}/{6:2d}".format("Laser: ", "DOLP = ", bL, " rotation alpha = ", RotL0, dRotL, nRotL)) 879 print("{0:8} {1:8} {2:8.5f}; {3:8} {4:7.4f}±{5:7.4f}/{6:2d}".format("Laser: ", "DOLP = ", bL,
880 " rotation alpha = ", RotL0, dRotL,
881 nRotL))
842 print(" Diatt., Tunpol, Retard., Rotation (deg)") 882 print(" Diatt., Tunpol, Retard., Rotation (deg)")
843 print("{0:12} {1:7.4f}±{2:7.4f}/{8:2d}, {3:7.4f}, {4:3.0f}±{5:3.0f}/{9:2d}, {6:7.4f}±{7:7.4f}/{10:2d}".format("Emitter ", DiE0, dDiE, TiE, RetE0, dRetE, RotE0, dRotE, nDiE, nRetE, nRotE)) 883 print("{0:12} {1:7.4f}±{2:7.4f}/{8:2d}, {3:7.4f}, {4:3.0f}±{5:3.0f}/{9:2d}, {6:7.4f}±{7:7.4f}/{10:2d}".format(
844 print("{0:12} {1:7.4f}±{2:7.4f}/{8:2d}, {3:7.4f}, {4:3.0f}±{5:3.0f}/{9:2d}, {6:7.4f}±{7:7.4f}/{10:2d}".format("Receiver ", DiO0, dDiO, TiO, RetO0, dRetO, RotO0, dRotO, nDiO, nRetO, nRotO)) 884 "Emitter ", DiE0, dDiE, TiE, RetE0, dRetE, RotE0, dRotE, nDiE, nRetE, nRotE))
845 print("{0:12} {1:7.4f}±{2:7.4f}/{8:2d}, {3:7.4f}, {4:3.0f}±{5:3.0f}/{9:2d}, {6:7.4f}±{7:7.4f}/{10:2d}".format("Calibrator ", DiC0, dDiC, TiC, RetC0, dRetC, RotC0, dRotC, nDiC, nRetC, nRotC)) 885 print("{0:12} {1:7.4f}±{2:7.4f}/{8:2d}, {3:7.4f}, {4:3.0f}±{5:3.0f}/{9:2d}, {6:7.4f}±{7:7.4f}/{10:2d}".format(
886 "Receiver ", DiO0, dDiO, TiO, RetO0, dRetO, RotO0, dRotO, nDiO, nRetO, nRotO))
887 print("{0:12} {1:7.4f}±{2:7.4f}/{8:2d}, {3:7.4f}, {4:3.0f}±{5:3.0f}/{9:2d}, {6:7.4f}±{7:7.4f}/{10:2d}".format(
888 "Calibrator ", DiC0, dDiC, TiC, RetC0, dRetC, RotC0, dRotC, nDiC, nRetC, nRotC))
846 print("{0:12}".format(" --- Pol.-filter ---")) 889 print("{0:12}".format(" --- Pol.-filter ---"))
847 print("{0:12}{1:7.4f}±{2:7.4f}/{3:2d}, {4:7.4f}±{5:7.4f}/{6:2d}".format("ERT, RotT :", ERaT0, dERaT, nERaT, RotaT0, dRotaT, nRotaT)) 890 print(
848 print("{0:12}{1:7.4f}±{2:7.4f}/{3:2d}, {4:7.4f}±{5:7.4f}/{6:2d}".format("ERR, RotR :", ERaR0, dERaR, nERaR, RotaR0, dRotaR, nRotaR)) 891 "{0:12}{1:7.4f}±{2:7.4f}/{3:2d}, {4:7.4f}±{5:7.4f}/{6:2d}".format("ERT, RotT :", ERaT0, dERaT, nERaT,
892 RotaT0, dRotaT, nRotaT))
893 print(
894 "{0:12}{1:7.4f}±{2:7.4f}/{3:2d}, {4:7.4f}±{5:7.4f}/{6:2d}".format("ERR, RotR :", ERaR0, dERaR, nERaR,
895 RotaR0, dRotaR, nRotaR))
849 print("{0:12}".format(" --- PBS ---")) 896 print("{0:12}".format(" --- PBS ---"))
850 print("{0:12}{1:7.4f}±{2:7.4f}/{3:2d}, {4:7.4f}±{5:7.4f}/{6:2d}".format("TP,TS :", TP0, dTP, nTP, TS0, dTS, nTS)) 897 print("{0:12}{1:7.4f}±{2:7.4f}/{3:2d}, {4:7.4f}±{5:7.4f}/{6:2d}".format("TP,TS :", TP0, dTP, nTP, TS0,
851 print("{0:12}{1:7.4f}±{2:7.4f}/{3:2d}, {4:7.4f}±{5:7.4f}/{6:2d}".format("RP,RS :", RP0, dRP, nRP, RS0, dRS, nRS)) 898 dTS, nTS))
899 print("{0:12}{1:7.4f}±{2:7.4f}/{3:2d}, {4:7.4f}±{5:7.4f}/{6:2d}".format("RP,RS :", RP0, dRP, nRP, RS0,
900 dRS, nRS))
852 print("{0:12}{1:7.4f},{2:7.4f}, {3:7.4f},{4:7.4f}, {5:1.0f}".format("DT,TT,DR,TR,Y :", DiT, TiT, DiR, TiR, Y)) 901 print("{0:12}{1:7.4f},{2:7.4f}, {3:7.4f},{4:7.4f}, {5:1.0f}".format("DT,TT,DR,TR,Y :", DiT, TiT, DiR, TiR, Y))
853 print("{0:12}".format(" --- Combined PBS + Pol.-filter ---")) 902 print("{0:12}".format(" --- Combined PBS + Pol.-filter ---"))
854 print("{0:12}{1:7.4f},{2:7.4f}, {3:7.4f},{4:7.4f}".format("DT,TT,DR,TR :", DTa0, TTa0, DRa0, TRa0)) 903 print("{0:12}{1:7.4f},{2:7.4f}, {3:7.4f},{4:7.4f}".format("DT,TT,DR,TR :", DTa0, TTa0, DRa0, TRa0))
855 print() 904 print()
856 print("Rotation Error Epsilon For Normal Measurements = ", RotationErrorEpsilonForNormalMeasurements) 905 print("Rotation Error Epsilon For Normal Measurements = ", RotationErrorEpsilonForNormalMeasurements)
857 print(Type[TypeC], Loc[LocC]) 906 print(Type[TypeC], Loc[LocC])
858 print("Parallel signal detected in", dY[int(Y+1)]) 907 print("Parallel signal detected in", dY[int(Y + 1)])
859 print("RS_RP_depend_on_TS_TP = ", RS_RP_depend_on_TS_TP) 908 print("RS_RP_depend_on_TS_TP = ", RS_RP_depend_on_TS_TP)
860 # end of print actual system parameters 909 # end of print actual system parameters
861 # ****************************************************************************** 910 # ******************************************************************************
862 911
863 #print() 912 # print()
864 #print(" --- LDRCal during calibration | simulated and corrected LDRs -------------") 913 # print(" --- LDRCal during calibration | simulated and corrected LDRs -------------")
865 #print("{0:8} |{1:8}->{2:8},{3:9}->{4:9} |{5:8}->{6:8}".format(" LDRCal"," LDRtrue", " LDRsim"," LDRtrue2", " LDRsim2", " LDRmeas", " LDRcorr")) 914 # print("{0:8} |{1:8}->{2:8},{3:9}->{4:9} |{5:8}->{6:8}".format(" LDRCal"," LDRtrue", " LDRsim"," LDRtrue2", " LDRsim2", " LDRmeas", " LDRcorr"))
866 #print("{0:8.5f} |{1:8.5f}->{2:8.5f},{3:9.5f}->{4:9.5f} |{5:8.5f}->{6:8.5f}".format(LDRCal, LDRtrue, LDRsim, LDRtrue2, LDRsim2, LDRmeas, LDRCorr)) 915 # print("{0:8.5f} |{1:8.5f}->{2:8.5f},{3:9.5f}->{4:9.5f} |{5:8.5f}->{6:8.5f}".format(LDRCal, LDRtrue, LDRsim, LDRtrue2, LDRsim2, LDRmeas, LDRCorr))
867 #print("{0:8} |{1:8}->{2:8}->{3:8}".format(" LDRCal"," LDRtrue", " LDRsimx", " LDRcorr")) 916 # print("{0:8} |{1:8}->{2:8}->{3:8}".format(" LDRCal"," LDRtrue", " LDRsimx", " LDRcorr"))
868 #print("{0:6.3f}±{1:5.3f}/{2:2d}|{3:8.5f}->{4:8.5f}->{5:8.5f}".format(LDRCal0, dLDRCal, nLDRCal, LDRtrue, LDRsimx, LDRCorr)) 917 # print("{0:6.3f}±{1:5.3f}/{2:2d}|{3:8.5f}->{4:8.5f}->{5:8.5f}".format(LDRCal0, dLDRCal, nLDRCal, LDRtrue, LDRsimx, LDRCorr))
869 #print("{0:8} |{1:8}->{2:8}->{3:8}".format(" LDRCal"," LDRtrue", " LDRsimx", " LDRcorr")) 918 # print("{0:8} |{1:8}->{2:8}->{3:8}".format(" LDRCal"," LDRtrue", " LDRsimx", " LDRcorr"))
870 #print(" --- LDRCal during calibration") 919 # print(" --- LDRCal during calibration")
871 print("{0:26}: {1:6.3f}±{2:5.3f}/{3:2d}".format("LDRCal during calibration in calibration range", LDRCal0, dLDRCal, nLDRCal)) 920 print("{0:26}: {1:6.3f}±{2:5.3f}/{3:2d}".format("LDRCal during calibration in calibration range", LDRCal0,
872 921 dLDRCal, nLDRCal))
873 #print("{0:8}={1:8.5f};{2:8}={3:8.5f}".format(" IinP",IinP," F11sim",F11sim)) 922
923 # print("{0:8}={1:8.5f};{2:8}={3:8.5f}".format(" IinP",IinP," F11sim",F11sim))
874 print() 924 print()
875 925
876 K0List = np.zeros(3) 926 K0List = np.zeros(3)
877 LDRsimxList = np.zeros(3) 927 LDRsimxList = np.zeros(3)
878 LDRCalList = 0.004, 0.2, 0.45 928 LDRCalList = 0.004, 0.2, 0.45
879 for i,LDRCal in enumerate(LDRCalList): 929 for i, LDRCal in enumerate(LDRCalList):
880 GT0, HT0, GR0, HR0, K0, Eta0, LDRsimx, LDRCorr, DTa0, DRa0, TTa0, TRa0, F11sim0 = Calc(RotL0, RotE0, RetE0, DiE0, RotO0, RetO0, DiO0, RotC0, RetC0, DiC0, TP0, TS0, RP0, RS0, ERaT0, RotaT0, RetT0, ERaR0, RotaR0, RetR0, LDRCal) 930 GT0, HT0, GR0, HR0, K0, Eta0, LDRsimx, LDRCorr, DTa0, DRa0, TTa0, TRa0, F11sim0 = Calc(RotL0, RotE0, RetE0,
931 DiE0, RotO0, RetO0,
932 DiO0, RotC0, RetC0,
933 DiC0, TP0, TS0, RP0,
934 RS0, ERaT0, RotaT0,
935 RetT0, ERaR0, RotaR0,
936 RetR0, LDRCal)
881 K0List[i] = K0 937 K0List[i] = K0
882 LDRsimxList[i] = LDRsimx 938 LDRsimxList[i] = LDRsimx
883 939
884 print('========================================================================') 940 print('========================================================================')
885 print("{0:8},{1:8},{2:8},{3:8},{4:9},{5:8},{6:9}".format(" GR", " GT", " HR", " HT", " K(0.004)", " K(0.2)", " K(0.45)")) 941 print("{0:8},{1:8},{2:8},{3:8},{4:9},{5:8},{6:9}".format(" GR", " GT", " HR", " HT", " K(0.004)", " K(0.2)",
886 print("{0:8.5f},{1:8.5f},{2:8.5f},{3:8.5f},{4:9.5f},{5:9.5f},{6:9.5f}".format(GR0, GT0, HR0, HT0, K0List[0], K0List[1], K0List[2])) 942 " K(0.45)"))
943 print("{0:8.5f},{1:8.5f},{2:8.5f},{3:8.5f},{4:9.5f},{5:9.5f},{6:9.5f}".format(GR0, GT0, HR0, HT0, K0List[0],
944 K0List[1], K0List[2]))
887 print('========================================================================') 945 print('========================================================================')
888 946
889 print("{0:9},{1:9},{2:9}".format(" LDRtrue", " LDRsimx", " LDRCorr")) 947 print("{0:9},{1:9},{2:9}".format(" LDRtrue", " LDRsimx", " LDRCorr"))
890 LDRtrueList = 0.004, 0.02, 0.2, 0.45 948 LDRtrueList = 0.004, 0.02, 0.2, 0.45
891 for i,LDRtrue in enumerate(LDRtrueList): 949 for i, LDRtrue in enumerate(LDRtrueList):
892 GT0, HT0, GR0, HR0, K0, Eta0, LDRsimx, LDRCorr, DTa0, DRa0, TTa0, TRa0, F11sim0 = Calc(RotL0, RotE0, RetE0, DiE0, RotO0, RetO0, DiO0, RotC0, RetC0, DiC0, TP0, TS0, RP0, RS0, ERaT0, RotaT0, RetT0, ERaR0, RotaR0, RetR0, LDRCal0) 950 GT0, HT0, GR0, HR0, K0, Eta0, LDRsimx, LDRCorr, DTa0, DRa0, TTa0, TRa0, F11sim0 = Calc(RotL0, RotE0, RetE0,
951 DiE0, RotO0, RetO0,
952 DiO0, RotC0, RetC0,
953 DiC0, TP0, TS0, RP0,
954 RS0, ERaT0, RotaT0,
955 RetT0, ERaR0, RotaR0,
956 RetR0, LDRCal0)
893 print("{0:9.5f},{1:9.5f},{2:9.5f}".format(LDRtrue, LDRsimx, LDRCorr)) 957 print("{0:9.5f},{1:9.5f},{2:9.5f}".format(LDRtrue, LDRsimx, LDRCorr))
894 958
895
896 file = open('output_files\output_' + LID + '.dat', 'r') 959 file = open('output_files\output_' + LID + '.dat', 'r')
897 print (file.read()) 960 print(file.read())
898 file.close() 961 file.close()
899 962
900 ''' 963 '''
901 if(PrintToOutputFile): 964 if(PrintToOutputFile):
902 f = open('output_ver7.dat', 'w') 965 f = open('output_ver7.dat', 'w')
908 if(PrintToOutputFile): 971 if(PrintToOutputFile):
909 sys.stdout.flush() 972 sys.stdout.flush()
910 f.close 973 f.close
911 sys.stdout = old_target 974 sys.stdout = old_target
912 ''' 975 '''
913 if(Error_Calc): 976 if (Error_Calc):
914 # --- CALC again truth with LDRCal0 to reset all 0-values 977 # --- CALC again truth with LDRCal0 to reset all 0-values
915 GT0, HT0, GR0, HR0, K0, Eta0, LDRsimx, LDRCorr, DTa0, DRa0, TTa0, TRa0, F11sim0 = Calc(RotL0, RotE0, RetE0, DiE0, RotO0, RetO0, DiO0, RotC0, RetC0, DiC0, TP0, TS0, RP0, RS0, ERaT0, RotaT0, RetT0, ERaR0, RotaR0, RetR0, LDRCal0) 978 GT0, HT0, GR0, HR0, K0, Eta0, LDRsimx, LDRCorr, DTa0, DRa0, TTa0, TRa0, F11sim0 = Calc(RotL0, RotE0, RetE0, DiE0,
979 RotO0, RetO0, DiO0, RotC0,
980 RetC0, DiC0, TP0, TS0, RP0,
981 RS0, ERaT0, RotaT0, RetT0,
982 ERaR0, RotaR0, RetR0,
983 LDRCal0)
916 984
917 # --- Start Errors calculation with variable parameters ------------------------------------------------------------------ 985 # --- Start Errors calculation with variable parameters ------------------------------------------------------------------
918 986
919 iN = -1 987 iN = -1
920 N = ((nRotL*2+1)* 988 N = ((nRotL * 2 + 1) *
921 (nRotE*2+1)*(nRetE*2+1)*(nDiE*2+1)* 989 (nRotE * 2 + 1) * (nRetE * 2 + 1) * (nDiE * 2 + 1) *
922 (nRotO*2+1)*(nRetO*2+1)*(nDiO*2+1)* 990 (nRotO * 2 + 1) * (nRetO * 2 + 1) * (nDiO * 2 + 1) *
923 (nRotC*2+1)*(nRetC*2+1)*(nDiC*2+1)* 991 (nRotC * 2 + 1) * (nRetC * 2 + 1) * (nDiC * 2 + 1) *
924 (nTP*2+1)*(nTS*2+1)*(nRP*2+1)*(nRS*2+1)*(nERaT*2+1)*(nERaR*2+1)* 992 (nTP * 2 + 1) * (nTS * 2 + 1) * (nRP * 2 + 1) * (nRS * 2 + 1) * (nERaT * 2 + 1) * (nERaR * 2 + 1) *
925 (nRotaT*2+1)*(nRotaR*2+1)*(nRetT*2+1)*(nRetR*2+1)*(nLDRCal*2+1)) 993 (nRotaT * 2 + 1) * (nRotaR * 2 + 1) * (nRetT * 2 + 1) * (nRetR * 2 + 1) * (nLDRCal * 2 + 1))
926 print("N = ",N ," ", end="") 994 print("N = ", N, " ", end="")
927 995
928 if N > 1e6: 996 if N > 1e6:
929 if user_yes_no_query('Warning: processing ' + str(N) + ' samples will take very long. Do you want to proceed?') == 0: sys.exit() 997 if user_yes_no_query('Warning: processing ' + str(
998 N) + ' samples will take very long. Do you want to proceed?') == 0: sys.exit()
930 if N > 5e6: 999 if N > 5e6:
931 if user_yes_no_query('Warning: the memory required for ' + str(N) + ' samples might be ' + '{0:5.1f}'.format(N/4e6) + ' GB. Do you anyway want to proceed?') == 0: sys.exit() 1000 if user_yes_no_query('Warning: the memory required for ' + str(N) + ' samples might be ' + '{0:5.1f}'.format(
932 1001 N / 4e6) + ' GB. Do you anyway want to proceed?') == 0: sys.exit()
933 #if user_yes_no_query('Warning: processing' + str(N) + ' samples will take very long. Do you want to proceed?') == 0: sys.exit() 1002
1003 # if user_yes_no_query('Warning: processing' + str(N) + ' samples will take very long. Do you want to proceed?') == 0: sys.exit()
934 1004
935 # --- Arrays for plotting ------ 1005 # --- Arrays for plotting ------
936 LDRmin = np.zeros(5) 1006 LDRmin = np.zeros(5)
937 LDRmax = np.zeros(5) 1007 LDRmax = np.zeros(5)
938 F11min = np.zeros(5) 1008 F11min = np.zeros(5)
939 F11max = np.zeros(5) 1009 F11max = np.zeros(5)
940 1010
941 LDRrange = np.zeros(5) 1011 LDRrange = np.zeros(5)
942 LDRrange = 0.004, 0.02, 0.1, 0.3, 0.45 1012 LDRrange = 0.004, 0.02, 0.1, 0.3, 0.45
943 #aLDRsimx = np.zeros(N) 1013 # aLDRsimx = np.zeros(N)
944 #aLDRsimx2 = np.zeros(N) 1014 # aLDRsimx2 = np.zeros(N)
945 #aLDRcorr = np.zeros(N) 1015 # aLDRcorr = np.zeros(N)
946 #aLDRcorr2 = np.zeros(N) 1016 # aLDRcorr2 = np.zeros(N)
947 aERaT = np.zeros(N) 1017 aERaT = np.zeros(N)
948 aERaR = np.zeros(N) 1018 aERaR = np.zeros(N)
949 aRotaT = np.zeros(N) 1019 aRotaT = np.zeros(N)
950 aRotaR = np.zeros(N) 1020 aRotaR = np.zeros(N)
951 aRetT = np.zeros(N) 1021 aRetT = np.zeros(N)
963 aRetE = np.zeros(N) 1033 aRetE = np.zeros(N)
964 aRotE = np.zeros(N) 1034 aRotE = np.zeros(N)
965 aRetO = np.zeros(N) 1035 aRetO = np.zeros(N)
966 aRotO = np.zeros(N) 1036 aRotO = np.zeros(N)
967 aLDRCal = np.zeros(N) 1037 aLDRCal = np.zeros(N)
968 aA = np.zeros((5,N)) 1038 aA = np.zeros((5, N))
969 aX = np.zeros((5,N)) 1039 aX = np.zeros((5, N))
970 aF11corr = np.zeros((5,N)) 1040 aF11corr = np.zeros((5, N))
971 1041
972 atime = clock() 1042 atime = clock()
973 dtime = clock() 1043 dtime = clock()
974 1044
975 # --- Calc Error signals 1045 # --- Calc Error signals
976 #GT, HT, GR, HR, K, Eta, LDRsim = Calc(RotL, RotE, RetE, DiE, RotO, RetO, DiO, RotC, RetC, DiC, TP, TS) 1046 # GT, HT, GR, HR, K, Eta, LDRsim = Calc(RotL, RotE, RetE, DiE, RotO, RetO, DiO, RotC, RetC, DiC, TP, TS)
977 # ---- Do the calculations of bra-ket vectors 1047 # ---- Do the calculations of bra-ket vectors
978 h = -1. if TypeC == 2 else 1 1048 h = -1. if TypeC == 2 else 1
979 1049
980 # from input file: measured LDRm and true LDRtrue, LDRtrue2 => 1050 # from input file: measured LDRm and true LDRtrue, LDRtrue2 =>
981 ameas = (1.-LDRmeas)/(1+LDRmeas) 1051 ameas = (1. - LDRmeas) / (1 + LDRmeas)
982 atrue = (1.-LDRtrue)/(1+LDRtrue) 1052 atrue = (1. - LDRtrue) / (1 + LDRtrue)
983 atrue2 = (1.-LDRtrue2)/(1+LDRtrue2) 1053 atrue2 = (1. - LDRtrue2) / (1 + LDRtrue2)
984 1054
985 for iLDRCal in range(-nLDRCal,nLDRCal+1): 1055 for iLDRCal in range(-nLDRCal, nLDRCal + 1):
986 # from input file: assumed LDRCal for calibration measurements 1056 # from input file: assumed LDRCal for calibration measurements
987 LDRCal = LDRCal0 1057 LDRCal = LDRCal0
988 if nLDRCal > 0: LDRCal = LDRCal0 + iLDRCal*dLDRCal/nLDRCal 1058 if nLDRCal > 0: LDRCal = LDRCal0 + iLDRCal * dLDRCal / nLDRCal
989 1059
990 GT0, HT0, GR0, HR0, K0, Eta0, LDRsimx, LDRCorr, DTa0, DRa0, TTa0, TRa0, F11sim0 = Calc(RotL0, RotE0, RetE0, DiE0, RotO0, RetO0, DiO0, RotC0, RetC0, DiC0, TP0, TS0, RP0, RS0, ERaT0, RotaT0, RetT0, ERaR0, RotaR0, RetR0, LDRCal) 1060 GT0, HT0, GR0, HR0, K0, Eta0, LDRsimx, LDRCorr, DTa0, DRa0, TTa0, TRa0, F11sim0 = Calc(RotL0, RotE0, RetE0,
991 aCal = (1.-LDRCal)/(1+LDRCal) 1061 DiE0, RotO0, RetO0, DiO0,
1062 RotC0, RetC0, DiC0, TP0,
1063 TS0, RP0, RS0, ERaT0,
1064 RotaT0, RetT0, ERaR0,
1065 RotaR0, RetR0, LDRCal)
1066 aCal = (1. - LDRCal) / (1 + LDRCal)
992 for iRotL, iRotE, iRetE, iDiE \ 1067 for iRotL, iRotE, iRetE, iDiE \
993 in [(iRotL,iRotE,iRetE,iDiE) 1068 in [(iRotL, iRotE, iRetE, iDiE)
994 for iRotL in range(-nRotL,nRotL+1) 1069 for iRotL in range(-nRotL, nRotL + 1)
995 for iRotE in range(-nRotE,nRotE+1) 1070 for iRotE in range(-nRotE, nRotE + 1)
996 for iRetE in range(-nRetE,nRetE+1) 1071 for iRetE in range(-nRetE, nRetE + 1)
997 for iDiE in range(-nDiE,nDiE+1)]: 1072 for iDiE in range(-nDiE, nDiE + 1)]:
998 1073
999 if nRotL > 0: RotL = RotL0 + iRotL*dRotL/nRotL 1074 if nRotL > 0: RotL = RotL0 + iRotL * dRotL / nRotL
1000 if nRotE > 0: RotE = RotE0 + iRotE*dRotE/nRotE 1075 if nRotE > 0: RotE = RotE0 + iRotE * dRotE / nRotE
1001 if nRetE > 0: RetE = RetE0 + iRetE*dRetE/nRetE 1076 if nRetE > 0: RetE = RetE0 + iRetE * dRetE / nRetE
1002 if nDiE > 0: DiE = DiE0 + iDiE*dDiE/nDiE 1077 if nDiE > 0: DiE = DiE0 + iDiE * dDiE / nDiE
1003 1078
1004 # angles of emitter and laser and calibrator and receiver optics 1079 # angles of emitter and laser and calibrator and receiver optics
1005 # RotL = alpha, RotE = beta, RotO = gamma, RotC = epsilon 1080 # RotL = alpha, RotE = beta, RotO = gamma, RotC = epsilon
1006 S2a = np.sin(2*np.deg2rad(RotL)) 1081 S2a = np.sin(2 * np.deg2rad(RotL))
1007 C2a = np.cos(2*np.deg2rad(RotL)) 1082 C2a = np.cos(2 * np.deg2rad(RotL))
1008 S2b = np.sin(2*np.deg2rad(RotE)) 1083 S2b = np.sin(2 * np.deg2rad(RotE))
1009 C2b = np.cos(2*np.deg2rad(RotE)) 1084 C2b = np.cos(2 * np.deg2rad(RotE))
1010 S2ab = np.sin(np.deg2rad(2*RotL-2*RotE)) 1085 S2ab = np.sin(np.deg2rad(2 * RotL - 2 * RotE))
1011 C2ab = np.cos(np.deg2rad(2*RotL-2*RotE)) 1086 C2ab = np.cos(np.deg2rad(2 * RotL - 2 * RotE))
1012 1087
1013 # Laser with Degree of linear polarization DOLP = bL 1088 # Laser with Degree of linear polarization DOLP = bL
1014 IinL = 1. 1089 IinL = 1.
1015 QinL = bL 1090 QinL = bL
1016 UinL = 0. 1091 UinL = 0.
1017 VinL = (1. - bL**2)**0.5 1092 VinL = (1. - bL ** 2) ** 0.5
1018 1093
1019 # Stokes Input Vector rotation Eq. E.4 1094 # Stokes Input Vector rotation Eq. E.4
1020 A = C2a*QinL - S2a*UinL 1095 A = C2a * QinL - S2a * UinL
1021 B = S2a*QinL + C2a*UinL 1096 B = S2a * QinL + C2a * UinL
1022 # Stokes Input Vector rotation Eq. E.9 1097 # Stokes Input Vector rotation Eq. E.9
1023 C = C2ab*QinL - S2ab*UinL 1098 C = C2ab * QinL - S2ab * UinL
1024 D = S2ab*QinL + C2ab*UinL 1099 D = S2ab * QinL + C2ab * UinL
1025 1100
1026 # emitter optics 1101 # emitter optics
1027 CosE = np.cos(np.deg2rad(RetE)) 1102 CosE = np.cos(np.deg2rad(RetE))
1028 SinE = np.sin(np.deg2rad(RetE)) 1103 SinE = np.sin(np.deg2rad(RetE))
1029 ZiE = (1. - DiE**2)**0.5 1104 ZiE = (1. - DiE ** 2) ** 0.5
1030 WiE = (1. - ZiE*CosE) 1105 WiE = (1. - ZiE * CosE)
1031 1106
1032 # Stokes Input Vector after emitter optics equivalent to Eq. E.9 with already rotated input vector from Eq. E.4 1107 # Stokes Input Vector after emitter optics equivalent to Eq. E.9 with already rotated input vector from Eq. E.4
1033 # b = beta 1108 # b = beta
1034 IinE = (IinL + DiE*C) 1109 IinE = (IinL + DiE * C)
1035 QinE = (C2b*DiE*IinL + A + S2b*(WiE*D - ZiE*SinE*VinL)) 1110 QinE = (C2b * DiE * IinL + A + S2b * (WiE * D - ZiE * SinE * VinL))
1036 UinE = (S2b*DiE*IinL + B - C2b*(WiE*D - ZiE*SinE*VinL)) 1111 UinE = (S2b * DiE * IinL + B - C2b * (WiE * D - ZiE * SinE * VinL))
1037 VinE = (-ZiE*SinE*D + ZiE*CosE*VinL) 1112 VinE = (-ZiE * SinE * D + ZiE * CosE * VinL)
1038 1113
1039 #------------------------- 1114 # -------------------------
1040 # F11 assuemd to be = 1 => measured: F11m = IinP / IinE with atrue 1115 # F11 assuemd to be = 1 => measured: F11m = IinP / IinE with atrue
1041 #F11sim = (IinE + DiO*atrue*(C2g*QinE - S2g*UinE))/IinE 1116 # F11sim = (IinE + DiO*atrue*(C2g*QinE - S2g*UinE))/IinE
1042 #------------------------- 1117 # -------------------------
1043 1118
1044 for iRotO, iRetO, iDiO, iRotC, iRetC, iDiC, iTP, iTS, iRP, iRS, iERaT, iRotaT, iRetT, iERaR, iRotaR, iRetR \ 1119 for iRotO, iRetO, iDiO, iRotC, iRetC, iDiC, iTP, iTS, iRP, iRS, iERaT, iRotaT, iRetT, iERaR, iRotaR, iRetR \
1045 in [(iRotO,iRetO,iDiO,iRotC,iRetC,iDiC,iTP,iTS,iRP,iRS,iERaT,iRotaT,iRetT,iERaR,iRotaR,iRetR ) 1120 in [
1046 for iRotO in range(-nRotO,nRotO+1) 1121 (iRotO, iRetO, iDiO, iRotC, iRetC, iDiC, iTP, iTS, iRP, iRS, iERaT, iRotaT, iRetT, iERaR, iRotaR, iRetR)
1047 for iRetO in range(-nRetO,nRetO+1) 1122 for iRotO in range(-nRotO, nRotO + 1)
1048 for iDiO in range(-nDiO,nDiO+1) 1123 for iRetO in range(-nRetO, nRetO + 1)
1049 for iRotC in range(-nRotC,nRotC+1) 1124 for iDiO in range(-nDiO, nDiO + 1)
1050 for iRetC in range(-nRetC,nRetC+1) 1125 for iRotC in range(-nRotC, nRotC + 1)
1051 for iDiC in range(-nDiC,nDiC+1) 1126 for iRetC in range(-nRetC, nRetC + 1)
1052 for iTP in range(-nTP,nTP+1) 1127 for iDiC in range(-nDiC, nDiC + 1)
1053 for iTS in range(-nTS,nTS+1) 1128 for iTP in range(-nTP, nTP + 1)
1054 for iRP in range(-nRP,nRP+1) 1129 for iTS in range(-nTS, nTS + 1)
1055 for iRS in range(-nRS,nRS+1) 1130 for iRP in range(-nRP, nRP + 1)
1056 for iERaT in range(-nERaT,nERaT+1) 1131 for iRS in range(-nRS, nRS + 1)
1057 for iRotaT in range(-nRotaT,nRotaT+1) 1132 for iERaT in range(-nERaT, nERaT + 1)
1058 for iRetT in range(-nRetT,nRetT+1) 1133 for iRotaT in range(-nRotaT, nRotaT + 1)
1059 for iERaR in range(-nERaR,nERaR+1) 1134 for iRetT in range(-nRetT, nRetT + 1)
1060 for iRotaR in range(-nRotaR,nRotaR+1) 1135 for iERaR in range(-nERaR, nERaR + 1)
1061 for iRetR in range(-nRetR,nRetR+1)]: 1136 for iRotaR in range(-nRotaR, nRotaR + 1)
1137 for iRetR in range(-nRetR, nRetR + 1)]:
1062 1138
1063 iN = iN + 1 1139 iN = iN + 1
1064 if (iN == 10001): 1140 if (iN == 10001):
1065 ctime = clock() 1141 ctime = clock()
1066 print(" estimated time ", "{0:4.2f}".format(N/10000 * (ctime-atime)), "sec ") #, end="") 1142 print(" estimated time ", "{0:4.2f}".format(N / 10000 * (ctime - atime)), "sec ") # , end="")
1067 print("\r elapsed time ", "{0:5.0f}".format((ctime-atime)), "sec ", end="\r") 1143 print("\r elapsed time ", "{0:5.0f}".format((ctime - atime)), "sec ", end="\r")
1068 ctime = clock() 1144 ctime = clock()
1069 if ((ctime - dtime) > 10): 1145 if ((ctime - dtime) > 10):
1070 print("\r elapsed time ", "{0:5.0f}".format((ctime-atime)), "sec ", end="\r") 1146 print("\r elapsed time ", "{0:5.0f}".format((ctime - atime)), "sec ", end="\r")
1071 dtime = ctime 1147 dtime = ctime
1072 1148
1073 if nRotO > 0: RotO = RotO0 + iRotO*dRotO/nRotO 1149 if nRotO > 0: RotO = RotO0 + iRotO * dRotO / nRotO
1074 if nRetO > 0: RetO = RetO0 + iRetO*dRetO/nRetO 1150 if nRetO > 0: RetO = RetO0 + iRetO * dRetO / nRetO
1075 if nDiO > 0: DiO = DiO0 + iDiO*dDiO/nDiO 1151 if nDiO > 0: DiO = DiO0 + iDiO * dDiO / nDiO
1076 if nRotC > 0: RotC = RotC0 + iRotC*dRotC/nRotC 1152 if nRotC > 0: RotC = RotC0 + iRotC * dRotC / nRotC
1077 if nRetC > 0: RetC = RetC0 + iRetC*dRetC/nRetC 1153 if nRetC > 0: RetC = RetC0 + iRetC * dRetC / nRetC
1078 if nDiC > 0: DiC = DiC0 + iDiC*dDiC/nDiC 1154 if nDiC > 0: DiC = DiC0 + iDiC * dDiC / nDiC
1079 if nTP > 0: TP = TP0 + iTP*dTP/nTP 1155 if nTP > 0: TP = TP0 + iTP * dTP / nTP
1080 if nTS > 0: TS = TS0 + iTS*dTS/nTS 1156 if nTS > 0: TS = TS0 + iTS * dTS / nTS
1081 if nRP > 0: RP = RP0 + iRP*dRP/nRP 1157 if nRP > 0: RP = RP0 + iRP * dRP / nRP
1082 if nRS > 0: RS = RS0 + iRS*dRS/nRS 1158 if nRS > 0: RS = RS0 + iRS * dRS / nRS
1083 if nERaT > 0: ERaT = ERaT0 + iERaT*dERaT/nERaT 1159 if nERaT > 0: ERaT = ERaT0 + iERaT * dERaT / nERaT
1084 if nRotaT > 0:RotaT= RotaT0+ iRotaT*dRotaT/nRotaT 1160 if nRotaT > 0: RotaT = RotaT0 + iRotaT * dRotaT / nRotaT
1085 if nRetT > 0: RetT = RetT0 + iRetT*dRetT/nRetT 1161 if nRetT > 0: RetT = RetT0 + iRetT * dRetT / nRetT
1086 if nERaR > 0: ERaR = ERaR0 + iERaR*dERaR/nERaR 1162 if nERaR > 0: ERaR = ERaR0 + iERaR * dERaR / nERaR
1087 if nRotaR > 0:RotaR= RotaR0+ iRotaR*dRotaR/nRotaR 1163 if nRotaR > 0: RotaR = RotaR0 + iRotaR * dRotaR / nRotaR
1088 if nRetR > 0: RetR = RetR0 + iRetR*dRetR/nRetR 1164 if nRetR > 0: RetR = RetR0 + iRetR * dRetR / nRetR
1089 1165
1090 #print("{0:5.2f}, {1:5.2f}, {2:5.2f}, {3:10d}".format(RotL, RotE, RotO, iN)) 1166 # print("{0:5.2f}, {1:5.2f}, {2:5.2f}, {3:10d}".format(RotL, RotE, RotO, iN))
1091 1167
1092 # receiver optics 1168 # receiver optics
1093 CosO = np.cos(np.deg2rad(RetO)) 1169 CosO = np.cos(np.deg2rad(RetO))
1094 SinO = np.sin(np.deg2rad(RetO)) 1170 SinO = np.sin(np.deg2rad(RetO))
1095 ZiO = (1. - DiO**2)**0.5 1171 ZiO = (1. - DiO ** 2) ** 0.5
1096 WiO = (1. - ZiO*CosO) 1172 WiO = (1. - ZiO * CosO)
1097 S2g = np.sin(np.deg2rad(2*RotO)) 1173 S2g = np.sin(np.deg2rad(2 * RotO))
1098 C2g = np.cos(np.deg2rad(2*RotO)) 1174 C2g = np.cos(np.deg2rad(2 * RotO))
1099 # calibrator 1175 # calibrator
1100 CosC = np.cos(np.deg2rad(RetC)) 1176 CosC = np.cos(np.deg2rad(RetC))
1101 SinC = np.sin(np.deg2rad(RetC)) 1177 SinC = np.sin(np.deg2rad(RetC))
1102 ZiC = (1. - DiC**2)**0.5 1178 ZiC = (1. - DiC ** 2) ** 0.5
1103 WiC = (1. - ZiC*CosC) 1179 WiC = (1. - ZiC * CosC)
1104 1180
1105 # analyser 1181 # analyser
1106 #For POLLY_XTs 1182 # For POLLY_XTs
1107 if(RS_RP_depend_on_TS_TP): 1183 if (RS_RP_depend_on_TS_TP):
1108 RS = 1 - TS 1184 RS = 1 - TS
1109 RP = 1 - TP 1185 RP = 1 - TP
1110 TiT = 0.5 * (TP + TS) 1186 TiT = 0.5 * (TP + TS)
1111 DiT = (TP-TS)/(TP+TS) 1187 DiT = (TP - TS) / (TP + TS)
1112 ZiT = (1. - DiT**2)**0.5 1188 ZiT = (1. - DiT ** 2) ** 0.5
1113 TiR = 0.5 * (RP + RS) 1189 TiR = 0.5 * (RP + RS)
1114 DiR = (RP-RS)/(RP+RS) 1190 DiR = (RP - RS) / (RP + RS)
1115 ZiR = (1. - DiR**2)**0.5 1191 ZiR = (1. - DiR ** 2) ** 0.5
1116 CosT = np.cos(np.deg2rad(RetT)) 1192 CosT = np.cos(np.deg2rad(RetT))
1117 SinT = np.sin(np.deg2rad(RetT)) 1193 SinT = np.sin(np.deg2rad(RetT))
1118 CosR = np.cos(np.deg2rad(RetR)) 1194 CosR = np.cos(np.deg2rad(RetR))
1119 SinR = np.sin(np.deg2rad(RetR)) 1195 SinR = np.sin(np.deg2rad(RetR))
1120 1196
1121 DaT = (1-ERaT)/(1+ERaT) 1197 DaT = (1 - ERaT) / (1 + ERaT)
1122 DaR = (1-ERaR)/(1+ERaR) 1198 DaR = (1 - ERaR) / (1 + ERaR)
1123 TaT = 0.5*(1+ERaT) 1199 TaT = 0.5 * (1 + ERaT)
1124 TaR = 0.5*(1+ERaR) 1200 TaR = 0.5 * (1 + ERaR)
1125 1201
1126 S2aT = np.sin(np.deg2rad(h*2*RotaT)) 1202 S2aT = np.sin(np.deg2rad(h * 2 * RotaT))
1127 C2aT = np.cos(np.deg2rad(2*RotaT)) 1203 C2aT = np.cos(np.deg2rad(2 * RotaT))
1128 S2aR = np.sin(np.deg2rad(h*2*RotaR)) 1204 S2aR = np.sin(np.deg2rad(h * 2 * RotaR))
1129 C2aR = np.cos(np.deg2rad(2*RotaR)) 1205 C2aR = np.cos(np.deg2rad(2 * RotaR))
1130 1206
1131 # Aanalyzer As before the PBS Eq. D.5 1207 # Aanalyzer As before the PBS Eq. D.5
1132 ATP1 = (1+C2aT*DaT*DiT) 1208 ATP1 = (1 + C2aT * DaT * DiT)
1133 ATP2 = Y*(DiT+C2aT*DaT) 1209 ATP2 = Y * (DiT + C2aT * DaT)
1134 ATP3 = Y*S2aT*DaT*ZiT*CosT 1210 ATP3 = Y * S2aT * DaT * ZiT * CosT
1135 ATP4 = S2aT*DaT*ZiT*SinT 1211 ATP4 = S2aT * DaT * ZiT * SinT
1136 ATP = np.array([ATP1,ATP2,ATP3,ATP4]) 1212 ATP = np.array([ATP1, ATP2, ATP3, ATP4])
1137 1213
1138 ARP1 = (1+C2aR*DaR*DiR) 1214 ARP1 = (1 + C2aR * DaR * DiR)
1139 ARP2 = Y*(DiR+C2aR*DaR) 1215 ARP2 = Y * (DiR + C2aR * DaR)
1140 ARP3 = Y*S2aR*DaR*ZiR*CosR 1216 ARP3 = Y * S2aR * DaR * ZiR * CosR
1141 ARP4 = S2aR*DaR*ZiR*SinR 1217 ARP4 = S2aR * DaR * ZiR * SinR
1142 ARP = np.array([ARP1,ARP2,ARP3,ARP4]) 1218 ARP = np.array([ARP1, ARP2, ARP3, ARP4])
1143 1219
1144 TTa = TiT*TaT #*ATP1 1220 TTa = TiT * TaT # *ATP1
1145 TRa = TiR*TaR #*ARP1 1221 TRa = TiR * TaR # *ARP1
1146 1222
1147 # ---- Calculate signals and correction parameters for diffeent locations and calibrators 1223 # ---- Calculate signals and correction parameters for diffeent locations and calibrators
1148 if LocC == 4: # Calibrator before the PBS 1224 if LocC == 4: # Calibrator before the PBS
1149 #print("Calibrator location not implemented yet") 1225 # print("Calibrator location not implemented yet")
1150 1226
1151 #S2ge = np.sin(np.deg2rad(2*RotO + h*2*RotC)) 1227 # S2ge = np.sin(np.deg2rad(2*RotO + h*2*RotC))
1152 #C2ge = np.cos(np.deg2rad(2*RotO + h*2*RotC)) 1228 # C2ge = np.cos(np.deg2rad(2*RotO + h*2*RotC))
1153 S2e = np.sin(np.deg2rad(h*2*RotC)) 1229 S2e = np.sin(np.deg2rad(h * 2 * RotC))
1154 C2e = np.cos(np.deg2rad(2*RotC)) 1230 C2e = np.cos(np.deg2rad(2 * RotC))
1155 # rotated AinP by epsilon Eq. C.3 1231 # rotated AinP by epsilon Eq. C.3
1156 ATP2e = C2e*ATP2 + S2e*ATP3 1232 ATP2e = C2e * ATP2 + S2e * ATP3
1157 ATP3e = C2e*ATP3 - S2e*ATP2 1233 ATP3e = C2e * ATP3 - S2e * ATP2
1158 ARP2e = C2e*ARP2 + S2e*ARP3 1234 ARP2e = C2e * ARP2 + S2e * ARP3
1159 ARP3e = C2e*ARP3 - S2e*ARP2 1235 ARP3e = C2e * ARP3 - S2e * ARP2
1160 ATPe = np.array([ATP1,ATP2e,ATP3e,ATP4]) 1236 ATPe = np.array([ATP1, ATP2e, ATP3e, ATP4])
1161 ARPe = np.array([ARP1,ARP2e,ARP3e,ARP4]) 1237 ARPe = np.array([ARP1, ARP2e, ARP3e, ARP4])
1162 # Stokes Input Vector before the polarising beam splitter Eq. E.31 1238 # Stokes Input Vector before the polarising beam splitter Eq. E.31
1163 A = C2g*QinE - S2g*UinE 1239 A = C2g * QinE - S2g * UinE
1164 B = S2g*QinE + C2g*UinE 1240 B = S2g * QinE + C2g * UinE
1165 #C = (WiO*aCal*B + ZiO*SinO*(1-2*aCal)*VinE) 1241 # C = (WiO*aCal*B + ZiO*SinO*(1-2*aCal)*VinE)
1166 Co = ZiO*SinO*VinE 1242 Co = ZiO * SinO * VinE
1167 Ca = (WiO*B - 2*ZiO*SinO*VinE) 1243 Ca = (WiO * B - 2 * ZiO * SinO * VinE)
1168 #C = Co + aCal*Ca 1244 # C = Co + aCal*Ca
1169 #IinP = (IinE + DiO*aCal*A) 1245 # IinP = (IinE + DiO*aCal*A)
1170 #QinP = (C2g*DiO*IinE + aCal*QinE - S2g*C) 1246 # QinP = (C2g*DiO*IinE + aCal*QinE - S2g*C)
1171 #UinP = (S2g*DiO*IinE - aCal*UinE + C2g*C) 1247 # UinP = (S2g*DiO*IinE - aCal*UinE + C2g*C)
1172 #VinP = (ZiO*SinO*aCal*B + ZiO*CosO*(1-2*aCal)*VinE) 1248 # VinP = (ZiO*SinO*aCal*B + ZiO*CosO*(1-2*aCal)*VinE)
1173 IinPo = IinE 1249 IinPo = IinE
1174 QinPo = (C2g*DiO*IinE - S2g*Co) 1250 QinPo = (C2g * DiO * IinE - S2g * Co)
1175 UinPo = (S2g*DiO*IinE + C2g*Co) 1251 UinPo = (S2g * DiO * IinE + C2g * Co)
1176 VinPo = ZiO*CosO*VinE 1252 VinPo = ZiO * CosO * VinE
1177 1253
1178 IinPa = DiO*A 1254 IinPa = DiO * A
1179 QinPa = QinE - S2g*Ca 1255 QinPa = QinE - S2g * Ca
1180 UinPa = -UinE + C2g*Ca 1256 UinPa = -UinE + C2g * Ca
1181 VinPa = ZiO*(SinO*B - 2*CosO*VinE) 1257 VinPa = ZiO * (SinO * B - 2 * CosO * VinE)
1182 1258
1183 IinP = IinPo + aCal*IinPa 1259 IinP = IinPo + aCal * IinPa
1184 QinP = QinPo + aCal*QinPa 1260 QinP = QinPo + aCal * QinPa
1185 UinP = UinPo + aCal*UinPa 1261 UinP = UinPo + aCal * UinPa
1186 VinP = VinPo + aCal*VinPa 1262 VinP = VinPo + aCal * VinPa
1187 # Stokes Input Vector before the polarising beam splitter rotated by epsilon Eq. C.3 1263 # Stokes Input Vector before the polarising beam splitter rotated by epsilon Eq. C.3
1188 #QinPe = C2e*QinP + S2e*UinP 1264 # QinPe = C2e*QinP + S2e*UinP
1189 #UinPe = C2e*UinP - S2e*QinP 1265 # UinPe = C2e*UinP - S2e*QinP
1190 QinPoe = C2e*QinPo + S2e*UinPo 1266 QinPoe = C2e * QinPo + S2e * UinPo
1191 UinPoe = C2e*UinPo - S2e*QinPo 1267 UinPoe = C2e * UinPo - S2e * QinPo
1192 QinPae = C2e*QinPa + S2e*UinPa 1268 QinPae = C2e * QinPa + S2e * UinPa
1193 UinPae = C2e*UinPa - S2e*QinPa 1269 UinPae = C2e * UinPa - S2e * QinPa
1194 QinPe = C2e*QinP + S2e*UinP 1270 QinPe = C2e * QinP + S2e * UinP
1195 UinPe = C2e*UinP - S2e*QinP 1271 UinPe = C2e * UinP - S2e * QinP
1196 1272
1197 # Calibration signals and Calibration correction K from measurements with LDRCal / aCal 1273 # Calibration signals and Calibration correction K from measurements with LDRCal / aCal
1198 if (TypeC == 2) or (TypeC == 1): # rotator calibration Eq. C.4 1274 if (TypeC == 2) or (TypeC == 1): # rotator calibration Eq. C.4
1199 # parameters for calibration with aCal 1275 # parameters for calibration with aCal
1200 AT = ATP1*IinP + h*ATP4*VinP 1276 AT = ATP1 * IinP + h * ATP4 * VinP
1201 BT = ATP3e*QinP - h*ATP2e*UinP 1277 BT = ATP3e * QinP - h * ATP2e * UinP
1202 AR = ARP1*IinP + h*ARP4*VinP 1278 AR = ARP1 * IinP + h * ARP4 * VinP
1203 BR = ARP3e*QinP - h*ARP2e*UinP 1279 BR = ARP3e * QinP - h * ARP2e * UinP
1204 # Correction paremeters for normal measurements; they are independent of LDR 1280 # Correction paremeters for normal measurements; they are independent of LDR
1205 if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out 1281 if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out
1206 IS1 = np.array([IinPo,QinPo,UinPo,VinPo]) 1282 IS1 = np.array([IinPo, QinPo, UinPo, VinPo])
1207 IS2 = np.array([IinPa,QinPa,UinPa,VinPa]) 1283 IS2 = np.array([IinPa, QinPa, UinPa, VinPa])
1208 GT = np.dot(ATP,IS1) 1284 GT = np.dot(ATP, IS1)
1209 GR = np.dot(ARP,IS1) 1285 GR = np.dot(ARP, IS1)
1210 HT = np.dot(ATP,IS2) 1286 HT = np.dot(ATP, IS2)
1211 HR = np.dot(ARP,IS2) 1287 HR = np.dot(ARP, IS2)
1212 else: 1288 else:
1213 IS1 = np.array([IinPo,QinPo,UinPo,VinPo]) 1289 IS1 = np.array([IinPo, QinPo, UinPo, VinPo])
1214 IS2 = np.array([IinPa,QinPa,UinPa,VinPa]) 1290 IS2 = np.array([IinPa, QinPa, UinPa, VinPa])
1215 GT = np.dot(ATPe,IS1) 1291 GT = np.dot(ATPe, IS1)
1216 GR = np.dot(ARPe,IS1) 1292 GR = np.dot(ARPe, IS1)
1217 HT = np.dot(ATPe,IS2) 1293 HT = np.dot(ATPe, IS2)
1218 HR = np.dot(ARPe,IS2) 1294 HR = np.dot(ARPe, IS2)
1219 elif (TypeC == 3) or (TypeC == 4): # linear polariser calibration Eq. C.5 1295 elif (TypeC == 3) or (TypeC == 4): # linear polariser calibration Eq. C.5
1220 # parameters for calibration with aCal 1296 # parameters for calibration with aCal
1221 AT = ATP1*IinP + ATP3e*UinPe + ZiC*CosC*(ATP2e*QinPe + ATP4*VinP) 1297 AT = ATP1 * IinP + ATP3e * UinPe + ZiC * CosC * (ATP2e * QinPe + ATP4 * VinP)
1222 BT = DiC*(ATP1*UinPe + ATP3e*IinP) - ZiC*SinC*(ATP2e*VinP - ATP4*QinPe) 1298 BT = DiC * (ATP1 * UinPe + ATP3e * IinP) - ZiC * SinC * (ATP2e * VinP - ATP4 * QinPe)
1223 AR = ARP1*IinP + ARP3e*UinPe + ZiC*CosC*(ARP2e*QinPe + ARP4*VinP) 1299 AR = ARP1 * IinP + ARP3e * UinPe + ZiC * CosC * (ARP2e * QinPe + ARP4 * VinP)
1224 BR = DiC*(ARP1*UinPe + ARP3e*IinP) - ZiC*SinC*(ARP2e*VinP - ARP4*QinPe) 1300 BR = DiC * (ARP1 * UinPe + ARP3e * IinP) - ZiC * SinC * (ARP2e * VinP - ARP4 * QinPe)
1225 # Correction paremeters for normal measurements; they are independent of LDR 1301 # Correction paremeters for normal measurements; they are independent of LDR
1226 if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out 1302 if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out
1227 IS1 = np.array([IinPo,QinPo,UinPo,VinPo]) 1303 IS1 = np.array([IinPo, QinPo, UinPo, VinPo])
1228 IS2 = np.array([IinPa,QinPa,UinPa,VinPa]) 1304 IS2 = np.array([IinPa, QinPa, UinPa, VinPa])
1229 GT = np.dot(ATP,IS1) 1305 GT = np.dot(ATP, IS1)
1230 GR = np.dot(ARP,IS1) 1306 GR = np.dot(ARP, IS1)
1231 HT = np.dot(ATP,IS2) 1307 HT = np.dot(ATP, IS2)
1232 HR = np.dot(ARP,IS2) 1308 HR = np.dot(ARP, IS2)
1233 else: 1309 else:
1234 IS1e = np.array([IinPo+DiC*QinPoe,DiC*IinPo+QinPoe,ZiC*(CosC*UinPoe+SinC*VinPo),-ZiC*(SinC*UinPoe-CosC*VinPo)]) 1310 IS1e = np.array(
1235 IS2e = np.array([IinPa+DiC*QinPae,DiC*IinPa+QinPae,ZiC*(CosC*UinPae+SinC*VinPa),-ZiC*(SinC*UinPae-CosC*VinPa)]) 1311 [IinPo + DiC * QinPoe, DiC * IinPo + QinPoe, ZiC * (CosC * UinPoe + SinC * VinPo),
1236 GT = np.dot(ATPe,IS1e) 1312 -ZiC * (SinC * UinPoe - CosC * VinPo)])
1237 GR = np.dot(ARPe,IS1e) 1313 IS2e = np.array(
1238 HT = np.dot(ATPe,IS2e) 1314 [IinPa + DiC * QinPae, DiC * IinPa + QinPae, ZiC * (CosC * UinPae + SinC * VinPa),
1239 HR = np.dot(ARPe,IS2e) 1315 -ZiC * (SinC * UinPae - CosC * VinPa)])
1316 GT = np.dot(ATPe, IS1e)
1317 GR = np.dot(ARPe, IS1e)
1318 HT = np.dot(ATPe, IS2e)
1319 HR = np.dot(ARPe, IS2e)
1240 elif (TypeC == 6): # diattenuator calibration +-22.5° rotated_diattenuator_X22x5deg.odt 1320 elif (TypeC == 6): # diattenuator calibration +-22.5° rotated_diattenuator_X22x5deg.odt
1241 # parameters for calibration with aCal 1321 # parameters for calibration with aCal
1242 AT = ATP1*IinP + sqr05*DiC*(ATP1*QinPe + ATP2e*IinP) + (1-0.5*WiC)*(ATP2e*QinPe + ATP3e*UinPe) + ZiC*(sqr05*SinC*(ATP3e*VinP-ATP4*UinPe) + ATP4*CosC*VinP) 1322 AT = ATP1 * IinP + sqr05 * DiC * (ATP1 * QinPe + ATP2e * IinP) + (1 - 0.5 * WiC) * (
1243 BT = sqr05*DiC*(ATP1*UinPe + ATP3e*IinP) + 0.5*WiC*(ATP2e*UinPe + ATP3e*QinPe) - sqr05*ZiC*SinC*(ATP2e*VinP - ATP4*QinPe) 1323 ATP2e * QinPe + ATP3e * UinPe) + ZiC * (
1244 AR = ARP1*IinP + sqr05*DiC*(ARP1*QinPe + ARP2e*IinP) + (1-0.5*WiC)*(ARP2e*QinPe + ARP3e*UinPe) + ZiC*(sqr05*SinC*(ARP3e*VinP-ARP4*UinPe) + ARP4*CosC*VinP) 1324 sqr05 * SinC * (ATP3e * VinP - ATP4 * UinPe) + ATP4 * CosC * VinP)
1245 BR = sqr05*DiC*(ARP1*UinPe + ARP3e*IinP) + 0.5*WiC*(ARP2e*UinPe + ARP3e*QinPe) - sqr05*ZiC*SinC*(ARP2e*VinP - ARP4*QinPe) 1325 BT = sqr05 * DiC * (ATP1 * UinPe + ATP3e * IinP) + 0.5 * WiC * (
1326 ATP2e * UinPe + ATP3e * QinPe) - sqr05 * ZiC * SinC * (ATP2e * VinP - ATP4 * QinPe)
1327 AR = ARP1 * IinP + sqr05 * DiC * (ARP1 * QinPe + ARP2e * IinP) + (1 - 0.5 * WiC) * (
1328 ARP2e * QinPe + ARP3e * UinPe) + ZiC * (
1329 sqr05 * SinC * (ARP3e * VinP - ARP4 * UinPe) + ARP4 * CosC * VinP)
1330 BR = sqr05 * DiC * (ARP1 * UinPe + ARP3e * IinP) + 0.5 * WiC * (
1331 ARP2e * UinPe + ARP3e * QinPe) - sqr05 * ZiC * SinC * (ARP2e * VinP - ARP4 * QinPe)
1246 # Correction paremeters for normal measurements; they are independent of LDR 1332 # Correction paremeters for normal measurements; they are independent of LDR
1247 if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out 1333 if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out
1248 IS1 = np.array([IinPo,QinPo,UinPo,VinPo]) 1334 IS1 = np.array([IinPo, QinPo, UinPo, VinPo])
1249 IS2 = np.array([IinPa,QinPa,UinPa,VinPa]) 1335 IS2 = np.array([IinPa, QinPa, UinPa, VinPa])
1250 GT = np.dot(ATP,IS1) 1336 GT = np.dot(ATP, IS1)
1251 GR = np.dot(ARP,IS1) 1337 GR = np.dot(ARP, IS1)
1252 HT = np.dot(ATP,IS2) 1338 HT = np.dot(ATP, IS2)
1253 HR = np.dot(ARP,IS2) 1339 HR = np.dot(ARP, IS2)
1254 else: 1340 else:
1255 IS1e = np.array([IinPo+DiC*QinPoe,DiC*IinPo+QinPoe,ZiC*(CosC*UinPoe+SinC*VinPo),-ZiC*(SinC*UinPoe-CosC*VinPo)]) 1341 IS1e = np.array(
1256 IS2e = np.array([IinPa+DiC*QinPae,DiC*IinPa+QinPae,ZiC*(CosC*UinPae+SinC*VinPa),-ZiC*(SinC*UinPae-CosC*VinPa)]) 1342 [IinPo + DiC * QinPoe, DiC * IinPo + QinPoe, ZiC * (CosC * UinPoe + SinC * VinPo),
1257 GT = np.dot(ATPe,IS1e) 1343 -ZiC * (SinC * UinPoe - CosC * VinPo)])
1258 GR = np.dot(ARPe,IS1e) 1344 IS2e = np.array(
1259 HT = np.dot(ATPe,IS2e) 1345 [IinPa + DiC * QinPae, DiC * IinPa + QinPae, ZiC * (CosC * UinPae + SinC * VinPa),
1260 HR = np.dot(ARPe,IS2e) 1346 -ZiC * (SinC * UinPae - CosC * VinPa)])
1347 GT = np.dot(ATPe, IS1e)
1348 GR = np.dot(ARPe, IS1e)
1349 HT = np.dot(ATPe, IS2e)
1350 HR = np.dot(ARPe, IS2e)
1261 else: 1351 else:
1262 print("Calibrator not implemented yet") 1352 print("Calibrator not implemented yet")
1263 sys.exit() 1353 sys.exit()
1264 1354
1265 elif LocC == 3: # C before receiver optics Eq.57 1355 elif LocC == 3: # C before receiver optics Eq.57
1266 1356
1267 #S2ge = np.sin(np.deg2rad(2*RotO - 2*RotC)) 1357 # S2ge = np.sin(np.deg2rad(2*RotO - 2*RotC))
1268 #C2ge = np.cos(np.deg2rad(2*RotO - 2*RotC)) 1358 # C2ge = np.cos(np.deg2rad(2*RotO - 2*RotC))
1269 S2e = np.sin(np.deg2rad(2*RotC)) 1359 S2e = np.sin(np.deg2rad(2 * RotC))
1270 C2e = np.cos(np.deg2rad(2*RotC)) 1360 C2e = np.cos(np.deg2rad(2 * RotC))
1271 1361
1272 # AS with C before the receiver optics (see document rotated_diattenuator_X22x5deg.odt) 1362 # AS with C before the receiver optics (see document rotated_diattenuator_X22x5deg.odt)
1273 AF1 = np.array([1,C2g*DiO,S2g*DiO,0]) 1363 AF1 = np.array([1, C2g * DiO, S2g * DiO, 0])
1274 AF2 = np.array([C2g*DiO,1-S2g**2*WiO,S2g*C2g*WiO,-S2g*ZiO*SinO]) 1364 AF2 = np.array([C2g * DiO, 1 - S2g ** 2 * WiO, S2g * C2g * WiO, -S2g * ZiO * SinO])
1275 AF3 = np.array([S2g*DiO, S2g*C2g*WiO, 1-C2g**2*WiO, C2g*ZiO*SinO]) 1365 AF3 = np.array([S2g * DiO, S2g * C2g * WiO, 1 - C2g ** 2 * WiO, C2g * ZiO * SinO])
1276 AF4 = np.array([0, S2g*SinO, -C2g*SinO, CosO]) 1366 AF4 = np.array([0, S2g * SinO, -C2g * SinO, CosO])
1277 1367
1278 ATF = (ATP1*AF1+ATP2*AF2+ATP3*AF3+ATP4*AF4) 1368 ATF = (ATP1 * AF1 + ATP2 * AF2 + ATP3 * AF3 + ATP4 * AF4)
1279 ARF = (ARP1*AF1+ARP2*AF2+ARP3*AF3+ARP4*AF4) 1369 ARF = (ARP1 * AF1 + ARP2 * AF2 + ARP3 * AF3 + ARP4 * AF4)
1280 ATF1 = ATF[0] 1370 ATF1 = ATF[0]
1281 ATF2 = ATF[1] 1371 ATF2 = ATF[1]
1282 ATF3 = ATF[2] 1372 ATF3 = ATF[2]
1283 ATF4 = ATF[3] 1373 ATF4 = ATF[3]
1284 ARF1 = ARF[0] 1374 ARF1 = ARF[0]
1285 ARF2 = ARF[1] 1375 ARF2 = ARF[1]
1286 ARF3 = ARF[2] 1376 ARF3 = ARF[2]
1287 ARF4 = ARF[3] 1377 ARF4 = ARF[3]
1288 1378
1289 # rotated AinF by epsilon 1379 # rotated AinF by epsilon
1290 ATF2e = C2e*ATF[1] + S2e*ATF[2] 1380 ATF2e = C2e * ATF[1] + S2e * ATF[2]
1291 ATF3e = C2e*ATF[2] - S2e*ATF[1] 1381 ATF3e = C2e * ATF[2] - S2e * ATF[1]
1292 ARF2e = C2e*ARF[1] + S2e*ARF[2] 1382 ARF2e = C2e * ARF[1] + S2e * ARF[2]
1293 ARF3e = C2e*ARF[2] - S2e*ARF[1] 1383 ARF3e = C2e * ARF[2] - S2e * ARF[1]
1294 1384
1295 ATFe = np.array([ATF1,ATF2e,ATF3e,ATF4]) 1385 ATFe = np.array([ATF1, ATF2e, ATF3e, ATF4])
1296 ARFe = np.array([ARF1,ARF2e,ARF3e,ARF4]) 1386 ARFe = np.array([ARF1, ARF2e, ARF3e, ARF4])
1297 1387
1298 QinEe = C2e*QinE + S2e*UinE 1388 QinEe = C2e * QinE + S2e * UinE
1299 UinEe = C2e*UinE - S2e*QinE 1389 UinEe = C2e * UinE - S2e * QinE
1300 1390
1301 # Stokes Input Vector before receiver optics Eq. E.19 (after atmosphere F) 1391 # Stokes Input Vector before receiver optics Eq. E.19 (after atmosphere F)
1302 IinF = IinE 1392 IinF = IinE
1303 QinF = aCal*QinE 1393 QinF = aCal * QinE
1304 UinF = -aCal*UinE 1394 UinF = -aCal * UinE
1305 VinF = (1.-2.*aCal)*VinE 1395 VinF = (1. - 2. * aCal) * VinE
1306 1396
1307 IinFo = IinE 1397 IinFo = IinE
1308 QinFo = 0. 1398 QinFo = 0.
1309 UinFo = 0. 1399 UinFo = 0.
1310 VinFo = VinE 1400 VinFo = VinE
1311 1401
1312 IinFa = 0. 1402 IinFa = 0.
1313 QinFa = QinE 1403 QinFa = QinE
1314 UinFa = -UinE 1404 UinFa = -UinE
1315 VinFa = -2.*VinE 1405 VinFa = -2. * VinE
1316 1406
1317 # Stokes Input Vector before receiver optics rotated by epsilon Eq. C.3 1407 # Stokes Input Vector before receiver optics rotated by epsilon Eq. C.3
1318 QinFe = C2e*QinF + S2e*UinF 1408 QinFe = C2e * QinF + S2e * UinF
1319 UinFe = C2e*UinF - S2e*QinF 1409 UinFe = C2e * UinF - S2e * QinF
1320 QinFoe = C2e*QinFo + S2e*UinFo 1410 QinFoe = C2e * QinFo + S2e * UinFo
1321 UinFoe = C2e*UinFo - S2e*QinFo 1411 UinFoe = C2e * UinFo - S2e * QinFo
1322 QinFae = C2e*QinFa + S2e*UinFa 1412 QinFae = C2e * QinFa + S2e * UinFa
1323 UinFae = C2e*UinFa - S2e*QinFa 1413 UinFae = C2e * UinFa - S2e * QinFa
1324 1414
1325 # Calibration signals and Calibration correction K from measurements with LDRCal / aCal 1415 # Calibration signals and Calibration correction K from measurements with LDRCal / aCal
1326 if (TypeC == 2) or (TypeC == 1): # rotator calibration Eq. C.4 1416 if (TypeC == 2) or (TypeC == 1): # rotator calibration Eq. C.4
1327 AT = ATF1*IinF + ATF4*h*VinF 1417 AT = ATF1 * IinF + ATF4 * h * VinF
1328 BT = ATF3e*QinF - ATF2e*h*UinF 1418 BT = ATF3e * QinF - ATF2e * h * UinF
1329 AR = ARF1*IinF + ARF4*h*VinF 1419 AR = ARF1 * IinF + ARF4 * h * VinF
1330 BR = ARF3e*QinF - ARF2e*h*UinF 1420 BR = ARF3e * QinF - ARF2e * h * UinF
1331 1421
1332 # Correction paremeters for normal measurements; they are independent of LDR 1422 # Correction paremeters for normal measurements; they are independent of LDR
1333 if (not RotationErrorEpsilonForNormalMeasurements): 1423 if (not RotationErrorEpsilonForNormalMeasurements):
1334 GT = ATF1*IinE + ATF4*VinE 1424 GT = ATF1 * IinE + ATF4 * VinE
1335 GR = ARF1*IinE + ARF4*VinE 1425 GR = ARF1 * IinE + ARF4 * VinE
1336 HT = ATF2*QinE - ATF3*UinE - ATF4*2*VinE 1426 HT = ATF2 * QinE - ATF3 * UinE - ATF4 * 2 * VinE
1337 HR = ARF2*QinE - ARF3*UinE - ARF4*2*VinE 1427 HR = ARF2 * QinE - ARF3 * UinE - ARF4 * 2 * VinE
1338 else: 1428 else:
1339 GT = ATF1*IinE + ATF4*h*VinE 1429 GT = ATF1 * IinE + ATF4 * h * VinE
1340 GR = ARF1*IinE + ARF4*h*VinE 1430 GR = ARF1 * IinE + ARF4 * h * VinE
1341 HT = ATF2e*QinE - ATF3e*h*UinE - ATF4*h*2*VinE 1431 HT = ATF2e * QinE - ATF3e * h * UinE - ATF4 * h * 2 * VinE
1342 HR = ARF2e*QinE - ARF3e*h*UinE - ARF4*h*2*VinE 1432 HR = ARF2e * QinE - ARF3e * h * UinE - ARF4 * h * 2 * VinE
1343 1433
1344 elif (TypeC == 3) or (TypeC == 4): # linear polariser calibration Eq. C.5 1434 elif (TypeC == 3) or (TypeC == 4): # linear polariser calibration Eq. C.5
1345 # p = +45°, m = -45° 1435 # p = +45°, m = -45°
1346 IF1e = np.array([IinF, ZiC*CosC*QinFe, UinFe, ZiC*CosC*VinF]) 1436 IF1e = np.array([IinF, ZiC * CosC * QinFe, UinFe, ZiC * CosC * VinF])
1347 IF2e = np.array([DiC*UinFe, -ZiC*SinC*VinF, DiC*IinF, ZiC*SinC*QinFe]) 1437 IF2e = np.array([DiC * UinFe, -ZiC * SinC * VinF, DiC * IinF, ZiC * SinC * QinFe])
1348 1438
1349 AT = np.dot(ATFe,IF1e) 1439 AT = np.dot(ATFe, IF1e)
1350 AR = np.dot(ARFe,IF1e) 1440 AR = np.dot(ARFe, IF1e)
1351 BT = np.dot(ATFe,IF2e) 1441 BT = np.dot(ATFe, IF2e)
1352 BR = np.dot(ARFe,IF2e) 1442 BR = np.dot(ARFe, IF2e)
1353 1443
1354 # Correction paremeters for normal measurements; they are independent of LDR --- the same as for TypeC = 6 1444 # Correction paremeters for normal measurements; they are independent of LDR --- the same as for TypeC = 6
1355 if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out 1445 if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out
1356 IS1 = np.array([IinE,0,0,VinE]) 1446 IS1 = np.array([IinE, 0, 0, VinE])
1357 IS2 = np.array([0,QinE,-UinE,-2*VinE]) 1447 IS2 = np.array([0, QinE, -UinE, -2 * VinE])
1358 1448
1359 GT = np.dot(ATF,IS1) 1449 GT = np.dot(ATF, IS1)
1360 GR = np.dot(ARF,IS1) 1450 GR = np.dot(ARF, IS1)
1361 HT = np.dot(ATF,IS2) 1451 HT = np.dot(ATF, IS2)
1362 HR = np.dot(ARF,IS2) 1452 HR = np.dot(ARF, IS2)
1363 else: 1453 else:
1364 IS1e = np.array([IinFo+DiC*QinFoe,DiC*IinFo+QinFoe,ZiC*(CosC*UinFoe+SinC*VinFo),-ZiC*(SinC*UinFoe-CosC*VinFo)]) 1454 IS1e = np.array(
1365 IS2e = np.array([IinFa+DiC*QinFae,DiC*IinFa+QinFae,ZiC*(CosC*UinFae+SinC*VinFa),-ZiC*(SinC*UinFae-CosC*VinFa)]) 1455 [IinFo + DiC * QinFoe, DiC * IinFo + QinFoe, ZiC * (CosC * UinFoe + SinC * VinFo),
1366 GT = np.dot(ATFe,IS1e) 1456 -ZiC * (SinC * UinFoe - CosC * VinFo)])
1367 GR = np.dot(ARFe,IS1e) 1457 IS2e = np.array(
1368 HT = np.dot(ATFe,IS2e) 1458 [IinFa + DiC * QinFae, DiC * IinFa + QinFae, ZiC * (CosC * UinFae + SinC * VinFa),
1369 HR = np.dot(ARFe,IS2e) 1459 -ZiC * (SinC * UinFae - CosC * VinFa)])
1460 GT = np.dot(ATFe, IS1e)
1461 GR = np.dot(ARFe, IS1e)
1462 HT = np.dot(ATFe, IS2e)
1463 HR = np.dot(ARFe, IS2e)
1370 1464
1371 elif (TypeC == 6): # diattenuator calibration +-22.5° rotated_diattenuator_X22x5deg.odt 1465 elif (TypeC == 6): # diattenuator calibration +-22.5° rotated_diattenuator_X22x5deg.odt
1372 # p = +22.5°, m = -22.5° 1466 # p = +22.5°, m = -22.5°
1373 IF1e = np.array([IinF+sqr05*DiC*QinFe, sqr05*DiC*IinF+(1-0.5*WiC)*QinFe, (1-0.5*WiC)*UinFe+sqr05*ZiC*SinC*VinF, -sqr05*ZiC*SinC*UinFe+ZiC*CosC*VinF]) 1467 IF1e = np.array([IinF + sqr05 * DiC * QinFe, sqr05 * DiC * IinF + (1 - 0.5 * WiC) * QinFe,
1374 IF2e = np.array([sqr05*DiC*UinFe, 0.5*WiC*UinFe-sqr05*ZiC*SinC*VinF, sqr05*DiC*IinF+0.5*WiC*QinFe, sqr05*ZiC*SinC*QinFe]) 1468 (1 - 0.5 * WiC) * UinFe + sqr05 * ZiC * SinC * VinF,
1375 1469 -sqr05 * ZiC * SinC * UinFe + ZiC * CosC * VinF])
1376 AT = np.dot(ATFe,IF1e) 1470 IF2e = np.array([sqr05 * DiC * UinFe, 0.5 * WiC * UinFe - sqr05 * ZiC * SinC * VinF,
1377 AR = np.dot(ARFe,IF1e) 1471 sqr05 * DiC * IinF + 0.5 * WiC * QinFe, sqr05 * ZiC * SinC * QinFe])
1378 BT = np.dot(ATFe,IF2e) 1472
1379 BR = np.dot(ARFe,IF2e) 1473 AT = np.dot(ATFe, IF1e)
1474 AR = np.dot(ARFe, IF1e)
1475 BT = np.dot(ATFe, IF2e)
1476 BR = np.dot(ARFe, IF2e)
1380 1477
1381 # Correction paremeters for normal measurements; they are independent of LDR 1478 # Correction paremeters for normal measurements; they are independent of LDR
1382 if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out 1479 if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out
1383 #IS1 = np.array([IinE,0,0,VinE]) 1480 # IS1 = np.array([IinE,0,0,VinE])
1384 #IS2 = np.array([0,QinE,-UinE,-2*VinE]) 1481 # IS2 = np.array([0,QinE,-UinE,-2*VinE])
1385 IS1 = np.array([IinFo,0,0,VinFo]) 1482 IS1 = np.array([IinFo, 0, 0, VinFo])
1386 IS2 = np.array([0,QinFa,UinFa,VinFa]) 1483 IS2 = np.array([0, QinFa, UinFa, VinFa])
1387 GT = np.dot(ATF,IS1) 1484 GT = np.dot(ATF, IS1)
1388 GR = np.dot(ARF,IS1) 1485 GR = np.dot(ARF, IS1)
1389 HT = np.dot(ATF,IS2) 1486 HT = np.dot(ATF, IS2)
1390 HR = np.dot(ARF,IS2) 1487 HR = np.dot(ARF, IS2)
1391 else: 1488 else:
1392 #IS1e = np.array([IinE,DiC*IinE,ZiC*SinC*VinE,ZiC*CosC*VinE]) 1489 # IS1e = np.array([IinE,DiC*IinE,ZiC*SinC*VinE,ZiC*CosC*VinE])
1393 #IS2e = np.array([DiC*QinEe,QinEe,-ZiC*(CosC*UinEe+2*SinC*VinE),ZiC*(SinC*UinEe-2*CosC*VinE)]) 1490 # IS2e = np.array([DiC*QinEe,QinEe,-ZiC*(CosC*UinEe+2*SinC*VinE),ZiC*(SinC*UinEe-2*CosC*VinE)])
1394 IS1e = np.array([IinFo+DiC*QinFoe,DiC*IinFo+QinFoe,ZiC*(CosC*UinFoe+SinC*VinFo),-ZiC*(SinC*UinFoe-CosC*VinFo)]) 1491 IS1e = np.array(
1395 IS2e = np.array([IinFa+DiC*QinFae,DiC*IinFa+QinFae,ZiC*(CosC*UinFae+SinC*VinFa),-ZiC*(SinC*UinFae-CosC*VinFa)]) 1492 [IinFo + DiC * QinFoe, DiC * IinFo + QinFoe, ZiC * (CosC * UinFoe + SinC * VinFo),
1396 GT = np.dot(ATFe,IS1e) 1493 -ZiC * (SinC * UinFoe - CosC * VinFo)])
1397 GR = np.dot(ARFe,IS1e) 1494 IS2e = np.array(
1398 HT = np.dot(ATFe,IS2e) 1495 [IinFa + DiC * QinFae, DiC * IinFa + QinFae, ZiC * (CosC * UinFae + SinC * VinFa),
1399 HR = np.dot(ARFe,IS2e) 1496 -ZiC * (SinC * UinFae - CosC * VinFa)])
1497 GT = np.dot(ATFe, IS1e)
1498 GR = np.dot(ARFe, IS1e)
1499 HT = np.dot(ATFe, IS2e)
1500 HR = np.dot(ARFe, IS2e)
1400 1501
1401 1502
1402 else: 1503 else:
1403 print('Calibrator not implemented yet') 1504 print('Calibrator not implemented yet')
1404 sys.exit() 1505 sys.exit()
1405 1506
1406 elif LocC == 2: # C behind emitter optics Eq.57 1507 elif LocC == 2: # C behind emitter optics Eq.57
1407 #print("Calibrator location not implemented yet") 1508 # print("Calibrator location not implemented yet")
1408 S2e = np.sin(np.deg2rad(2*RotC)) 1509 S2e = np.sin(np.deg2rad(2 * RotC))
1409 C2e = np.cos(np.deg2rad(2*RotC)) 1510 C2e = np.cos(np.deg2rad(2 * RotC))
1410 1511
1411 # AS with C before the receiver optics (see document rotated_diattenuator_X22x5deg.odt) 1512 # AS with C before the receiver optics (see document rotated_diattenuator_X22x5deg.odt)
1412 AF1 = np.array([1,C2g*DiO,S2g*DiO,0]) 1513 AF1 = np.array([1, C2g * DiO, S2g * DiO, 0])
1413 AF2 = np.array([C2g*DiO,1-S2g**2*WiO,S2g*C2g*WiO,-S2g*ZiO*SinO]) 1514 AF2 = np.array([C2g * DiO, 1 - S2g ** 2 * WiO, S2g * C2g * WiO, -S2g * ZiO * SinO])
1414 AF3 = np.array([S2g*DiO, S2g*C2g*WiO, 1-C2g**2*WiO, C2g*ZiO*SinO]) 1515 AF3 = np.array([S2g * DiO, S2g * C2g * WiO, 1 - C2g ** 2 * WiO, C2g * ZiO * SinO])
1415 AF4 = np.array([0, S2g*SinO, -C2g*SinO, CosO]) 1516 AF4 = np.array([0, S2g * SinO, -C2g * SinO, CosO])
1416 1517
1417 ATF = (ATP1*AF1+ATP2*AF2+ATP3*AF3+ATP4*AF4) 1518 ATF = (ATP1 * AF1 + ATP2 * AF2 + ATP3 * AF3 + ATP4 * AF4)
1418 ARF = (ARP1*AF1+ARP2*AF2+ARP3*AF3+ARP4*AF4) 1519 ARF = (ARP1 * AF1 + ARP2 * AF2 + ARP3 * AF3 + ARP4 * AF4)
1419 ATF1 = ATF[0] 1520 ATF1 = ATF[0]
1420 ATF2 = ATF[1] 1521 ATF2 = ATF[1]
1421 ATF3 = ATF[2] 1522 ATF3 = ATF[2]
1422 ATF4 = ATF[3] 1523 ATF4 = ATF[3]
1423 ARF1 = ARF[0] 1524 ARF1 = ARF[0]
1430 ATE1o, ARE1o = ATF1, ARF1 1531 ATE1o, ARE1o = ATF1, ARF1
1431 ATE2o, ARE2o = 0., 0. 1532 ATE2o, ARE2o = 0., 0.
1432 ATE3o, ARE3o = 0., 0. 1533 ATE3o, ARE3o = 0., 0.
1433 ATE4o, ARE4o = ATF4, ARF4 1534 ATE4o, ARE4o = ATF4, ARF4
1434 # terms with aCal 1535 # terms with aCal
1435 ATE1a, ARE1a = 0. , 0. 1536 ATE1a, ARE1a = 0., 0.
1436 ATE2a, ARE2a = ATF2, ARF2 1537 ATE2a, ARE2a = ATF2, ARF2
1437 ATE3a, ARE3a = -ATF3, -ARF3 1538 ATE3a, ARE3a = -ATF3, -ARF3
1438 ATE4a, ARE4a = -2*ATF4, -2*ARF4 1539 ATE4a, ARE4a = -2 * ATF4, -2 * ARF4
1439 # rotated AinEa by epsilon 1540 # rotated AinEa by epsilon
1440 ATE2ae = C2e*ATF2 + S2e*ATF3 1541 ATE2ae = C2e * ATF2 + S2e * ATF3
1441 ATE3ae = -S2e*ATF2 - C2e*ATF3 1542 ATE3ae = -S2e * ATF2 - C2e * ATF3
1442 ARE2ae = C2e*ARF2 + S2e*ARF3 1543 ARE2ae = C2e * ARF2 + S2e * ARF3
1443 ARE3ae = -S2e*ARF2 - C2e*ARF3 1544 ARE3ae = -S2e * ARF2 - C2e * ARF3
1444 1545
1445 ATE1 = ATE1o 1546 ATE1 = ATE1o
1446 ATE2e = aCal*ATE2ae 1547 ATE2e = aCal * ATE2ae
1447 ATE3e = aCal*ATE3ae 1548 ATE3e = aCal * ATE3ae
1448 ATE4 = (1-2*aCal)*ATF4 1549 ATE4 = (1 - 2 * aCal) * ATF4
1449 ARE1 = ARE1o 1550 ARE1 = ARE1o
1450 ARE2e = aCal*ARE2ae 1551 ARE2e = aCal * ARE2ae
1451 ARE3e = aCal*ARE3ae 1552 ARE3e = aCal * ARE3ae
1452 ARE4 = (1-2*aCal)*ARF4 1553 ARE4 = (1 - 2 * aCal) * ARF4
1453 1554
1454 # rotated IinE 1555 # rotated IinE
1455 QinEe = C2e*QinE + S2e*UinE 1556 QinEe = C2e * QinE + S2e * UinE
1456 UinEe = C2e*UinE - S2e*QinE 1557 UinEe = C2e * UinE - S2e * QinE
1457 1558
1458 # --- Calibration signals and Calibration correction K from measurements with LDRCal / aCal 1559 # --- Calibration signals and Calibration correction K from measurements with LDRCal / aCal
1459 if (TypeC == 2) or (TypeC == 1): # +++++++++ rotator calibration Eq. C.4 1560 if (TypeC == 2) or (TypeC == 1): # +++++++++ rotator calibration Eq. C.4
1460 AT = ATE1o*IinE + (ATE4o+aCal*ATE4a)*h*VinE 1561 AT = ATE1o * IinE + (ATE4o + aCal * ATE4a) * h * VinE
1461 BT = aCal * (ATE3ae*QinEe - ATE2ae*h*UinEe) 1562 BT = aCal * (ATE3ae * QinEe - ATE2ae * h * UinEe)
1462 AR = ARE1o*IinE + (ARE4o+aCal*ARE4a)*h*VinE 1563 AR = ARE1o * IinE + (ARE4o + aCal * ARE4a) * h * VinE
1463 BR = aCal * (ARE3ae*QinEe - ARE2ae*h*UinEe) 1564 BR = aCal * (ARE3ae * QinEe - ARE2ae * h * UinEe)
1464 1565
1465 # Correction paremeters for normal measurements; they are independent of LDR 1566 # Correction paremeters for normal measurements; they are independent of LDR
1466 if (not RotationErrorEpsilonForNormalMeasurements): 1567 if (not RotationErrorEpsilonForNormalMeasurements):
1467 # Stokes Input Vector before receiver optics Eq. E.19 (after atmosphere F) 1568 # Stokes Input Vector before receiver optics Eq. E.19 (after atmosphere F)
1468 GT = ATE1o*IinE + ATE4o*h*VinE 1569 GT = ATE1o * IinE + ATE4o * h * VinE
1469 GR = ARE1o*IinE + ARE4o*h*VinE 1570 GR = ARE1o * IinE + ARE4o * h * VinE
1470 HT = ATE2a*QinE + ATE3a*h*UinEe + ATE4a*h*VinE 1571 HT = ATE2a * QinE + ATE3a * h * UinEe + ATE4a * h * VinE
1471 HR = ARE2a*QinE + ARE3a*h*UinEe + ARE4a*h*VinE 1572 HR = ARE2a * QinE + ARE3a * h * UinEe + ARE4a * h * VinE
1472 else: 1573 else:
1473 GT = ATE1o*IinE + ATE4o*h*VinE 1574 GT = ATE1o * IinE + ATE4o * h * VinE
1474 GR = ARE1o*IinE + ARE4o*h*VinE 1575 GR = ARE1o * IinE + ARE4o * h * VinE
1475 HT = ATE2ae*QinE + ATE3ae*h*UinEe + ATE4a*h*VinE 1576 HT = ATE2ae * QinE + ATE3ae * h * UinEe + ATE4a * h * VinE
1476 HR = ARE2ae*QinE + ARE3ae*h*UinEe + ARE4a*h*VinE 1577 HR = ARE2ae * QinE + ARE3ae * h * UinEe + ARE4a * h * VinE
1477 1578
1478 elif (TypeC == 3) or (TypeC == 4): # +++++++++ linear polariser calibration Eq. C.5 1579 elif (TypeC == 3) or (TypeC == 4): # +++++++++ linear polariser calibration Eq. C.5
1479 # p = +45°, m = -45° 1580 # p = +45°, m = -45°
1480 AT = ATE1*IinE + ZiC*CosC*(ATE2e*QinEe + ATE4*VinE) + ATE3e*UinEe 1581 AT = ATE1 * IinE + ZiC * CosC * (ATE2e * QinEe + ATE4 * VinE) + ATE3e * UinEe
1481 BT = DiC*(ATE1*UinEe + ATE3e*IinE) + ZiC*SinC*(ATE4*QinEe - ATE2e*VinE) 1582 BT = DiC * (ATE1 * UinEe + ATE3e * IinE) + ZiC * SinC * (ATE4 * QinEe - ATE2e * VinE)
1482 AR = ARE1*IinE + ZiC*CosC*(ARE2e*QinEe + ARE4*VinE) + ARE3e*UinEe 1583 AR = ARE1 * IinE + ZiC * CosC * (ARE2e * QinEe + ARE4 * VinE) + ARE3e * UinEe
1483 BR = DiC*(ARE1*UinEe + ARE3e*IinE) + ZiC*SinC*(ARE4*QinEe - ARE2e*VinE) 1584 BR = DiC * (ARE1 * UinEe + ARE3e * IinE) + ZiC * SinC * (ARE4 * QinEe - ARE2e * VinE)
1484 1585
1485 # Correction paremeters for normal measurements; they are independent of LDR 1586 # Correction paremeters for normal measurements; they are independent of LDR
1486 if (not RotationErrorEpsilonForNormalMeasurements): 1587 if (not RotationErrorEpsilonForNormalMeasurements):
1487 # Stokes Input Vector before receiver optics Eq. E.19 (after atmosphere F) 1588 # Stokes Input Vector before receiver optics Eq. E.19 (after atmosphere F)
1488 GT = ATE1o*IinE + ATE4o*VinE 1589 GT = ATE1o * IinE + ATE4o * VinE
1489 GR = ARE1o*IinE + ARE4o*VinE 1590 GR = ARE1o * IinE + ARE4o * VinE
1490 HT = ATE2a*QinE + ATE3a*UinE + ATE4a*VinE 1591 HT = ATE2a * QinE + ATE3a * UinE + ATE4a * VinE
1491 HR = ARE2a*QinE + ARE3a*UinE + ARE4a*VinE 1592 HR = ARE2a * QinE + ARE3a * UinE + ARE4a * VinE
1492 else: 1593 else:
1493 D = IinE + DiC*QinEe 1594 D = IinE + DiC * QinEe
1494 A = DiC*IinE + QinEe 1595 A = DiC * IinE + QinEe
1495 B = ZiC*(CosC*UinEe + SinC*VinE) 1596 B = ZiC * (CosC * UinEe + SinC * VinE)
1496 C = -ZiC*(SinC*UinEe - CosC*VinE) 1597 C = -ZiC * (SinC * UinEe - CosC * VinE)
1497 GT = ATE1o*D + ATE4o*C 1598 GT = ATE1o * D + ATE4o * C
1498 GR = ARE1o*D + ARE4o*C 1599 GR = ARE1o * D + ARE4o * C
1499 HT = ATE2a*A + ATE3a*B + ATE4a*C 1600 HT = ATE2a * A + ATE3a * B + ATE4a * C
1500 HR = ARE2a*A + ARE3a*B + ARE4a*C 1601 HR = ARE2a * A + ARE3a * B + ARE4a * C
1501 1602
1502 elif (TypeC == 6): # real HWP calibration +-22.5° rotated_diattenuator_X22x5deg.odt 1603 elif (TypeC == 6): # real HWP calibration +-22.5° rotated_diattenuator_X22x5deg.odt
1503 # p = +22.5°, m = -22.5° 1604 # p = +22.5°, m = -22.5°
1504 IE1e = np.array([IinE+sqr05*DiC*QinEe, sqr05*DiC*IinE+(1-0.5*WiC)*QinEe, (1-0.5*WiC)*UinEe+sqr05*ZiC*SinC*VinE, -sqr05*ZiC*SinC*UinEe+ZiC*CosC*VinE]) 1605 IE1e = np.array([IinE + sqr05 * DiC * QinEe, sqr05 * DiC * IinE + (1 - 0.5 * WiC) * QinEe,
1505 IE2e = np.array([sqr05*DiC*UinEe, 0.5*WiC*UinEe-sqr05*ZiC*SinC*VinE, sqr05*DiC*IinE+0.5*WiC*QinEe, sqr05*ZiC*SinC*QinEe]) 1606 (1 - 0.5 * WiC) * UinEe + sqr05 * ZiC * SinC * VinE,
1506 ATEe = np.array([ATE1,ATE2e,ATE3e,ATE4]) 1607 -sqr05 * ZiC * SinC * UinEe + ZiC * CosC * VinE])
1507 AREe = np.array([ARE1,ARE2e,ARE3e,ARE4]) 1608 IE2e = np.array([sqr05 * DiC * UinEe, 0.5 * WiC * UinEe - sqr05 * ZiC * SinC * VinE,
1508 AT = np.dot(ATEe,IE1e) 1609 sqr05 * DiC * IinE + 0.5 * WiC * QinEe, sqr05 * ZiC * SinC * QinEe])
1509 AR = np.dot(AREe,IE1e) 1610 ATEe = np.array([ATE1, ATE2e, ATE3e, ATE4])
1510 BT = np.dot(ATEe,IE2e) 1611 AREe = np.array([ARE1, ARE2e, ARE3e, ARE4])
1511 BR = np.dot(AREe,IE2e) 1612 AT = np.dot(ATEe, IE1e)
1613 AR = np.dot(AREe, IE1e)
1614 BT = np.dot(ATEe, IE2e)
1615 BR = np.dot(AREe, IE2e)
1512 1616
1513 # Correction paremeters for normal measurements; they are independent of LDR 1617 # Correction paremeters for normal measurements; they are independent of LDR
1514 if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out 1618 if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out
1515 GT = ATE1o*IinE + ATE4o*VinE 1619 GT = ATE1o * IinE + ATE4o * VinE
1516 GR = ARE1o*IinE + ARE4o*VinE 1620 GR = ARE1o * IinE + ARE4o * VinE
1517 HT = ATE2a*QinE + ATE3a*UinE + ATE4a*VinE 1621 HT = ATE2a * QinE + ATE3a * UinE + ATE4a * VinE
1518 HR = ARE2a*QinE + ARE3a*UinE + ARE4a*VinE 1622 HR = ARE2a * QinE + ARE3a * UinE + ARE4a * VinE
1519 else: 1623 else:
1520 D = IinE + DiC*QinEe 1624 D = IinE + DiC * QinEe
1521 A = DiC*IinE + QinEe 1625 A = DiC * IinE + QinEe
1522 B = ZiC*(CosC*UinEe + SinC*VinE) 1626 B = ZiC * (CosC * UinEe + SinC * VinE)
1523 C = -ZiC*(SinC*UinEe - CosC*VinE) 1627 C = -ZiC * (SinC * UinEe - CosC * VinE)
1524 GT = ATE1o*D + ATE4o*C 1628 GT = ATE1o * D + ATE4o * C
1525 GR = ARE1o*D + ARE4o*C 1629 GR = ARE1o * D + ARE4o * C
1526 HT = ATE2a*A + ATE3a*B + ATE4a*C 1630 HT = ATE2a * A + ATE3a * B + ATE4a * C
1527 HR = ARE2a*A + ARE3a*B + ARE4a*C 1631 HR = ARE2a * A + ARE3a * B + ARE4a * C
1528 1632
1529 else: 1633 else:
1530 print('Calibrator not implemented yet') 1634 print('Calibrator not implemented yet')
1531 sys.exit() 1635 sys.exit()
1532 1636
1533 # Calibration signals with aCal => Determination of the correction K of the real calibration factor 1637 # Calibration signals with aCal => Determination of the correction K of the real calibration factor
1534 IoutTp = TaT*TiT*TiO*TiE*(AT + BT) 1638 IoutTp = TaT * TiT * TiO * TiE * (AT + BT)
1535 IoutTm = TaT*TiT*TiO*TiE*(AT - BT) 1639 IoutTm = TaT * TiT * TiO * TiE * (AT - BT)
1536 IoutRp = TaR*TiR*TiO*TiE*(AR + BR) 1640 IoutRp = TaR * TiR * TiO * TiE * (AR + BR)
1537 IoutRm = TaR*TiR*TiO*TiE*(AR - BR) 1641 IoutRm = TaR * TiR * TiO * TiE * (AR - BR)
1538 # --- Results and Corrections; electronic etaR and etaT are assumed to be 1 1642 # --- Results and Corrections; electronic etaR and etaT are assumed to be 1
1539 #Eta = TiR/TiT # Eta = Eta*/K Eq. 84 1643 # Eta = TiR/TiT # Eta = Eta*/K Eq. 84
1540 Etapx = IoutRp/IoutTp 1644 Etapx = IoutRp / IoutTp
1541 Etamx = IoutRm/IoutTm 1645 Etamx = IoutRm / IoutTm
1542 Etax = (Etapx*Etamx)**0.5 1646 Etax = (Etapx * Etamx) ** 0.5
1543 K = Etax / Eta0 1647 K = Etax / Eta0
1544 #print("{0:6.3f},{1:6.3f},{2:6.3f},{3:6.3f},{4:6.3f},{5:6.3f},{6:6.3f},{7:6.3f},{8:6.3f},{9:6.3f},{10:6.3f}".format(AT, BT, AR, BR, DiC, ZiC, RetO, TP, TS, Kp, Km)) 1648 # print("{0:6.3f},{1:6.3f},{2:6.3f},{3:6.3f},{4:6.3f},{5:6.3f},{6:6.3f},{7:6.3f},{8:6.3f},{9:6.3f},{10:6.3f}".format(AT, BT, AR, BR, DiC, ZiC, RetO, TP, TS, Kp, Km))
1545 #print("{0:6.3f},{1:6.3f},{2:6.3f},{3:6.3f}".format(DiC, ZiC, Kp, Km)) 1649 # print("{0:6.3f},{1:6.3f},{2:6.3f},{3:6.3f}".format(DiC, ZiC, Kp, Km))
1546 1650
1547 # For comparison with Volkers Libreoffice Müller Matrix spreadsheet 1651 # For comparison with Volkers Libreoffice Müller Matrix spreadsheet
1548 #Eta_test_p = (IoutRp/IoutTp) 1652 # Eta_test_p = (IoutRp/IoutTp)
1549 #Eta_test_m = (IoutRm/IoutTm) 1653 # Eta_test_m = (IoutRm/IoutTm)
1550 #Eta_test = (Eta_test_p*Eta_test_m)**0.5 1654 # Eta_test = (Eta_test_p*Eta_test_m)**0.5
1551 1655
1552 # ************************************************************************* 1656 # *************************************************************************
1553 iLDR = -1 1657 iLDR = -1
1554 for LDRTrue in LDRrange: 1658 for LDRTrue in LDRrange:
1555 iLDR = iLDR + 1 1659 iLDR = iLDR + 1
1556 atrue = (1-LDRTrue)/(1+LDRTrue) 1660 atrue = (1 - LDRTrue) / (1 + LDRTrue)
1557 # ----- Forward simulated signals and LDRsim with atrue; from input file 1661 # ----- Forward simulated signals and LDRsim with atrue; from input file
1558 It = TaT*TiT*TiO*TiE*(GT+atrue*HT) # TaT*TiT*TiC*TiO*IinL*(GT+atrue*HT) 1662 It = TaT * TiT * TiO * TiE * (GT + atrue * HT) # TaT*TiT*TiC*TiO*IinL*(GT+atrue*HT)
1559 Ir = TaR*TiR*TiO*TiE*(GR+atrue*HR) # TaR*TiR*TiC*TiO*IinL*(GR+atrue*HR) 1663 Ir = TaR * TiR * TiO * TiE * (GR + atrue * HR) # TaR*TiR*TiC*TiO*IinL*(GR+atrue*HR)
1560 1664
1561 # LDRsim = 1/Eta*Ir/It # simulated LDR* with Y from input file 1665 # LDRsim = 1/Eta*Ir/It # simulated LDR* with Y from input file
1562 LDRsim = Ir/It # simulated uncorrected LDR with Y from input file 1666 LDRsim = Ir / It # simulated uncorrected LDR with Y from input file
1563 ''' 1667 '''
1564 if Y == 1.: 1668 if Y == 1.:
1565 LDRsimx = LDRsim 1669 LDRsimx = LDRsim
1566 LDRsimx2 = LDRsim2 1670 LDRsimx2 = LDRsim2
1567 else: 1671 else:
1568 LDRsimx = 1./LDRsim 1672 LDRsimx = 1./LDRsim
1569 LDRsimx2 = 1./LDRsim2 1673 LDRsimx2 = 1./LDRsim2
1570 ''' 1674 '''
1571 # ----- Backward correction 1675 # ----- Backward correction
1572 # Corrected LDRCorr from forward simulated LDRsim (atrue) with assumed true G0,H0,K0 1676 # Corrected LDRCorr from forward simulated LDRsim (atrue) with assumed true G0,H0,K0
1573 LDRCorr = (LDRsim*K0/Etax*(GT0+HT0)-(GR0+HR0))/((GR0-HR0)-LDRsim*K0/Etax*(GT0-HT0)) 1677 LDRCorr = (LDRsim * K0 / Etax * (GT0 + HT0) - (GR0 + HR0)) / (
1678 (GR0 - HR0) - LDRsim * K0 / Etax * (GT0 - HT0))
1574 1679
1575 # -- F11corr from It and Ir and calibration EtaX 1680 # -- F11corr from It and Ir and calibration EtaX
1576 Text1 = "!!! EXPERIMENTAL !!! F11corr from It and Ir with calibration EtaX: x-axis: F11corr(LDRtrue) / F11corr(LDRtrue = 0.004) - 1" 1681 Text1 = "!!! EXPERIMENTAL !!! F11corr from It and Ir with calibration EtaX: x-axis: F11corr(LDRtrue) / F11corr(LDRtrue = 0.004) - 1"
1577 F11corr = 1/(TiO*TiE)*((HR0*Etax/K0*It/TTa-HT0*Ir/TRa)/(HR0*GT0-HT0*GR0)) # IL = 1 Eq.(64) 1682 F11corr = 1 / (TiO * TiE) * (
1578 1683 (HR0 * Etax / K0 * It / TTa - HT0 * Ir / TRa) / (HR0 * GT0 - HT0 * GR0)) # IL = 1 Eq.(64)
1579 #Text1 = "F11corr from It and Ir without corrections but with calibration EtaX: x-axis: F11corr(LDRtrue) devided by F11corr(LDRtrue = 0.004)" 1684
1580 #F11corr = 0.5/(TiO*TiE)*(Etax*It/TTa+Ir/TRa) # IL = 1 Eq.(64) 1685 # Text1 = "F11corr from It and Ir without corrections but with calibration EtaX: x-axis: F11corr(LDRtrue) devided by F11corr(LDRtrue = 0.004)"
1686 # F11corr = 0.5/(TiO*TiE)*(Etax*It/TTa+Ir/TRa) # IL = 1 Eq.(64)
1581 1687
1582 # -- It from It only with atrue without corrections - for BERTHA (and PollyXTs) 1688 # -- It from It only with atrue without corrections - for BERTHA (and PollyXTs)
1583 #Text1 = " x-axis: IT(LDRtrue) / IT(LDRtrue = 0.004) - 1" 1689 # Text1 = " x-axis: IT(LDRtrue) / IT(LDRtrue = 0.004) - 1"
1584 #F11corr = It/(TaT*TiT*TiO*TiE) #/(TaT*TiT*TiO*TiE*(GT0+atrue*HT0)) 1690 # F11corr = It/(TaT*TiT*TiO*TiE) #/(TaT*TiT*TiO*TiE*(GT0+atrue*HT0))
1585 # !!! see below line 1673ff 1691 # !!! see below line 1673ff
1586 1692
1587 aF11corr[iLDR,iN] = F11corr 1693 aF11corr[iLDR, iN] = F11corr
1588 aA[iLDR,iN] = LDRCorr 1694 aA[iLDR, iN] = LDRCorr
1589 1695
1590 aX[0,iN] = GR 1696 aX[0, iN] = GR
1591 aX[1,iN] = GT 1697 aX[1, iN] = GT
1592 aX[2,iN] = HR 1698 aX[2, iN] = HR
1593 aX[3,iN] = HT 1699 aX[3, iN] = HT
1594 aX[4,iN] = K 1700 aX[4, iN] = K
1595 1701
1596 aLDRCal[iN] = iLDRCal 1702 aLDRCal[iN] = iLDRCal
1597 aERaT[iN] = iERaT 1703 aERaT[iN] = iERaT
1598 aERaR[iN] = iERaR 1704 aERaR[iN] = iERaR
1599 aRotaT[iN] = iRotaT 1705 aRotaT[iN] = iRotaT
1616 aRP[iN] = iRP 1722 aRP[iN] = iRP
1617 aRS[iN] = iRS 1723 aRS[iN] = iRS
1618 1724
1619 # --- END loop 1725 # --- END loop
1620 btime = clock() 1726 btime = clock()
1621 print("\r done in ", "{0:5.0f}".format(btime-atime), "sec") #, end="\r") 1727 print("\r done in ", "{0:5.0f}".format(btime - atime), "sec") # , end="\r")
1622 1728
1623 # --- Plot ----------------------------------------------------------------- 1729 # --- Plot -----------------------------------------------------------------
1624 if (sns_loaded): 1730 if (sns_loaded):
1625 sns.set_style("whitegrid") 1731 sns.set_style("whitegrid")
1626 sns.set_palette("bright", 6) 1732 sns.set_palette("bright", 6)
1631 plt.plot(aA[3,:],'r.') 1737 plt.plot(aA[3,:],'r.')
1632 plt.plot(aA[4,:],'g.') 1738 plt.plot(aA[4,:],'g.')
1633 #plt.plot(aA[6,:],'c.') 1739 #plt.plot(aA[6,:],'c.')
1634 plt.show 1740 plt.show
1635 ''' 1741 '''
1742
1743
1636 # Plot LDR 1744 # Plot LDR
1637 def PlotSubHist(aVar, aX, X0, daX, iaX, naX): 1745 def PlotSubHist(aVar, aX, X0, daX, iaX, naX):
1638 fig, ax = plt.subplots(nrows=1, ncols=5, sharex=True, sharey=True, figsize=(25, 2)) 1746 fig, ax = plt.subplots(nrows=1, ncols=5, sharex=True, sharey=True, figsize=(25, 2))
1639 iLDR = -1 1747 iLDR = -1
1640 for LDRTrue in LDRrange: 1748 for LDRTrue in LDRrange:
1641 iLDR = iLDR + 1 1749 iLDR = iLDR + 1
1642 1750
1643 LDRmin[iLDR] = np.min(aA[iLDR,:]) 1751 LDRmin[iLDR] = np.min(aA[iLDR, :])
1644 LDRmax[iLDR] = np.max(aA[iLDR,:]) 1752 LDRmax[iLDR] = np.max(aA[iLDR, :])
1645 Rmin = LDRmin[iLDR] * 0.995 # np.min(aA[iLDR,:]) * 0.995 1753 Rmin = LDRmin[iLDR] * 0.995 # np.min(aA[iLDR,:]) * 0.995
1646 Rmax = LDRmax[iLDR] * 1.005 # np.max(aA[iLDR,:]) * 1.005 1754 Rmax = LDRmax[iLDR] * 1.005 # np.max(aA[iLDR,:]) * 1.005
1647 1755
1648 #plt.subplot(5,2,iLDR+1) 1756 # plt.subplot(5,2,iLDR+1)
1649 plt.subplot(1,5,iLDR+1) 1757 plt.subplot(1, 5, iLDR + 1)
1650 (n, bins, patches) = plt.hist(aA[iLDR,:], 1758 (n, bins, patches) = plt.hist(aA[iLDR, :],
1651 bins=100, log=False, 1759 bins=100, log=False,
1652 range=[Rmin, Rmax], 1760 range=[Rmin, Rmax],
1653 alpha=0.5, normed=False, color = '0.5', histtype='stepfilled') 1761 alpha=0.5, normed=False, color='0.5', histtype='stepfilled')
1654 1762
1655 for iaX in range(-naX,naX+1): 1763 for iaX in range(-naX, naX + 1):
1656 plt.hist(aA[iLDR,aX == iaX], 1764 plt.hist(aA[iLDR, aX == iaX],
1657 range=[Rmin, Rmax], 1765 range=[Rmin, Rmax],
1658 bins=100, log=False, alpha=0.3, normed=False, histtype='stepfilled', label = str(round(X0 + iaX*daX/naX,5))) 1766 bins=100, log=False, alpha=0.3, normed=False, histtype='stepfilled',
1767 label=str(round(X0 + iaX * daX / naX, 5)))
1659 1768
1660 if (iLDR == 2): plt.legend() 1769 if (iLDR == 2): plt.legend()
1661 1770
1662 plt.tick_params(axis='both', labelsize=9) 1771 plt.tick_params(axis='both', labelsize=9)
1663 plt.plot([LDRTrue, LDRTrue], [0, np.max(n)], 'r-', lw=2) 1772 plt.plot([LDRTrue, LDRTrue], [0, np.max(n)], 'r-', lw=2)
1664 1773
1665 #plt.title(LID + ' ' + aVar, fontsize=18) 1774 # plt.title(LID + ' ' + aVar, fontsize=18)
1666 #plt.ylabel('frequency', fontsize=10) 1775 # plt.ylabel('frequency', fontsize=10)
1667 #plt.xlabel('LDRcorr', fontsize=10) 1776 # plt.xlabel('LDRcorr', fontsize=10)
1668 #fig.tight_layout() 1777 # fig.tight_layout()
1669 fig.suptitle(LID + ' with ' + str(Type[TypeC]) + ' ' + str(Loc[LocC]) + ' - ' + aVar, fontsize=14, y=1.05) 1778 fig.suptitle(LID + ' with ' + str(Type[TypeC]) + ' ' + str(Loc[LocC]) + ' - ' + aVar, fontsize=14, y=1.05)
1670 #plt.show() 1779 # plt.show()
1671 #fig.savefig(LID + '_' + aVar + '.png', dpi=150, bbox_inches='tight', pad_inches=0) 1780 # fig.savefig(LID + '_' + aVar + '.png', dpi=150, bbox_inches='tight', pad_inches=0)
1672 #plt.close 1781 # plt.close
1673 return 1782 return
1783
1674 1784
1675 if (nRotL > 0): PlotSubHist("RotL", aRotL, RotL0, dRotL, iRotL, nRotL) 1785 if (nRotL > 0): PlotSubHist("RotL", aRotL, RotL0, dRotL, iRotL, nRotL)
1676 if (nRetE > 0): PlotSubHist("RetE", aRetE, RetE0, dRetE, iRetE, nRetE) 1786 if (nRetE > 0): PlotSubHist("RetE", aRetE, RetE0, dRetE, iRetE, nRetE)
1677 if (nRotE > 0): PlotSubHist("RotE", aRotE, RotE0, dRotE, iRotE, nRotE) 1787 if (nRotE > 0): PlotSubHist("RotE", aRotE, RotE0, dRotE, iRotE, nRotE)
1678 if (nDiE > 0): PlotSubHist("DiE", aDiE, DiE0, dDiE, iDiE, nDiE) 1788 if (nDiE > 0): PlotSubHist("DiE", aDiE, DiE0, dDiE, iDiE, nDiE)
1795 plt.close 1905 plt.close
1796 ''' 1906 '''
1797 1907
1798 # --- Plot LDRmin, LDRmax 1908 # --- Plot LDRmin, LDRmax
1799 fig2 = plt.figure() 1909 fig2 = plt.figure()
1800 plt.plot(LDRrange,LDRmax-LDRrange, linewidth=2.0, color='b') 1910 plt.plot(LDRrange, LDRmax - LDRrange, linewidth=2.0, color='b')
1801 plt.plot(LDRrange,LDRmin-LDRrange, linewidth=2.0, color='g') 1911 plt.plot(LDRrange, LDRmin - LDRrange, linewidth=2.0, color='g')
1802 1912
1803 plt.xlabel('LDRtrue', fontsize=18) 1913 plt.xlabel('LDRtrue', fontsize=18)
1804 plt.ylabel('LDRTrue-LDRmin, LDRTrue-LDRmax', fontsize=14) 1914 plt.ylabel('LDRTrue-LDRmin, LDRTrue-LDRmax', fontsize=14)
1805 plt.title(LID + ' ' + str(Type[TypeC]) + ' ' + str(Loc[LocC]), fontsize=18) 1915 plt.title(LID + ' ' + str(Type[TypeC]) + ' ' + str(Loc[LocC]), fontsize=18)
1806 #plt.ylimit(-0.07, 0.07) 1916 # plt.ylimit(-0.07, 0.07)
1807 plt.show() 1917 plt.show()
1808 plt.close 1918 plt.close
1809 1919
1810 # --- Save LDRmin, LDRmax to file 1920 # --- Save LDRmin, LDRmax to file
1811 # http://stackoverflow.com/questions/4675728/redirect-stdout-to-a-file-in-python 1921 # http://stackoverflow.com/questions/4675728/redirect-stdout-to-a-file-in-python

mercurial