lidar_correction_ghk.py

Tue, 15 Nov 2016 16:21:06 +0100

author
Volker Freudenthaler <volker.freudenthaler@lmu.de>
date
Tue, 15 Nov 2016 16:21:06 +0100
changeset 17
43fe065e63b6
parent 16
313ac320b970
child 19
40d55af749b6
permissions
-rw-r--r--

update

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

mercurial