lidar_correction_ghk.py

Thu, 24 Jan 2019 21:24:25 +0100

author
Volker Freudenthaler <volker.freudenthaler@lmu.de>
date
Thu, 24 Jan 2019 21:24:25 +0100
changeset 28
79fa4a41420f
parent 26
28b5510492ba
permissions
-rw-r--r--

Bug fixes and further options. Read Improvements_of_lidar_correction_ghk_ver.0.9.8_190124.pdf

ulalume3@0 1 # -*- coding: utf-8 -*-
ulalume3@0 2 """
volker@28 3 Copyright 2016, 2019 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@28 20 Python 3.7, seaborn 0.9.0
volker@21 21
volker@21 22 Code description:
volker@21 23
volker@21 24 From measured lidar signals we cannot directly determine the desired backscatter coefficient (F11) and the linear depolarization ratio (LDR)
volker@21 25 because of the cross talk between the channles and systematic errors of a lidar system.
volker@21 26 http://www.atmos-meas-tech-discuss.net/amt-2015-338/amt-2015-338.pdf provides an analytical model for the description of these errors,
volker@21 27 with which the measured signals can be corrected.
volker@21 28 This code simulates the lidar measurements with "assumed true" model parameters from an input file, and calculates the correction parameters (G,H, and K).
volker@21 29 The "assumed true" system parameters are the ones we think are the right ones, but in reality these parameters probably deviate from the assumed truth due to
volker@21 30 uncertainties. The uncertainties of the "assumed true" parameters can be described in the input file. Then this code calculates the lidar signals and the
volker@21 31 gain ratio eta* with all possible combinations of "errors", which represents the distribution of "possibly real" signals, and "corrects" them with the "assumed true"
volker@21 32 GHK parameters (GT0, GR0, HT0, HR0, and K0) to derive finally the distributions of "possibly real" linear depolarization ratios (LDRcorr),
volker@21 33 which are plotted for five different input linear depolarization ratios (LDRtrue). The red bars in the plots represent the input values of LDRtrue.
volker@21 34 A complication arises from the fact that the correction parameter K = eta*/eta (Eq. 83) can depend on the LDR during the calibration measurement, i.e. LDRcal or aCal
volker@21 35 in the code (see e.g. Eqs. (103), (115), and (141); mind the mistake in Eq. (116)). Therefor values of K for LDRcal = 0.004, 0.2, and 0.45 are calculated for
volker@21 36 "assumed true" system parameters and printed in the output file behind the GH parameters. The full impact of the LDRcal dependent K can be considered in the error
volker@21 37 calculation by specifying a range of possible LDRcal values in the input file. For the real calibration measurements a calibration range with low or no aerosol
volker@21 38 content should be chosen, and the default in the input file is a range of LDRcal between 0.004 and 0.014 (i.e. 0.009 +-0.005).
volker@21 39
volker@21 40 Tip: In case you run the code with Spyder, all output text and plots can be displayed together in an IPython console, which can be saved as an html file.
volker@28 41
volker@28 42 Ver. 0.9.8: - for details, see "Improvements_of_lidar_correction_ghk_ver.0.9.8_190124.pdf"
volker@28 43 - correct calculation of Eta for cleaned anaylsers considering the combined transmission Eta = (TaT* TiT)(1 + cos2RotaT * DaT * DiT) and (TaR * TiR)(1 + cos2RotaR * DaR * DiR) according to the papers supplement Eqs. (S.10.10.1) ff
volker@28 44 - ND-filters can be added for the calibration measurements in the transmitted (TCalT) and the reflected path (TCalR) in order to include their uncertainties in the error calculation.
volker@28 45 - includes the simulation of signal noise
ulalume3@0 46 """
volker@28 47 # Comment: The code might works with Python 2.7 with the help of following line, which enables Python2 to correctly interpret the Python 3 print statements.
ulalume3@0 48 from __future__ import print_function
volker@21 49 # !/usr/bin/env python3
binietoglou@19 50
binietoglou@19 51 import os
binietoglou@19 52 import sys
binietoglou@19 53
ulalume3@0 54 import numpy as np
ulalume3@0 55
volker@11 56 # Comment: the seaborn library makes nicer plots, but the code works also without it.
volker@11 57 try:
volker@11 58 import seaborn as sns
binietoglou@19 59
volker@11 60 sns_loaded = True
volker@11 61 except ImportError:
volker@11 62 sns_loaded = False
volker@11 63
ulalume3@0 64 import matplotlib.pyplot as plt
volker@28 65 # from time import clock # python 2
volker@28 66 from timeit import default_timer as clock
ulalume3@0 67
binietoglou@19 68 # from matplotlib.backends.backend_pdf import PdfPages
binietoglou@19 69 # pdffile = '{}.pdf'.format('path')
binietoglou@19 70 # pp = PdfPages(pdffile)
ulalume3@0 71 ## pp.savefig can be called multiple times to save to multiple pages
binietoglou@19 72 # pp.savefig()
binietoglou@19 73 # pp.close()
ulalume3@0 74
ulalume3@0 75 from contextlib import contextmanager
binietoglou@19 76
ulalume3@0 77 @contextmanager
ulalume3@0 78 def redirect_stdout(new_target):
binietoglou@19 79 old_target, sys.stdout = sys.stdout, new_target # replace sys.stdout
ulalume3@0 80 try:
binietoglou@19 81 yield new_target # run some code with the replaced stdout
ulalume3@0 82 finally:
ulalume3@0 83 sys.stdout.flush()
binietoglou@19 84 sys.stdout = old_target # restore to the previous value
binietoglou@19 85
ulalume3@0 86 '''
ulalume3@0 87 real_raw_input = vars(__builtins__).get('raw_input',input)
ulalume3@0 88 '''
ulalume3@0 89 try:
ulalume3@0 90 import __builtin__
binietoglou@19 91
ulalume3@0 92 input = getattr(__builtin__, 'raw_input')
ulalume3@0 93 except (ImportError, AttributeError):
ulalume3@0 94 pass
ulalume3@0 95
ulalume3@0 96 from distutils.util import strtobool
binietoglou@19 97
binietoglou@19 98
ulalume3@0 99 def user_yes_no_query(question):
ulalume3@0 100 sys.stdout.write('%s [y/n]\n' % question)
ulalume3@0 101 while True:
ulalume3@0 102 try:
ulalume3@0 103 return strtobool(input().lower())
ulalume3@0 104 except ValueError:
ulalume3@0 105 sys.stdout.write('Please respond with \'y\' or \'n\'.\n')
ulalume3@0 106
binietoglou@19 107
binietoglou@19 108 # if user_yes_no_query('want to exit?') == 1: sys.exit()
ulalume3@0 109
ulalume3@0 110 abspath = os.path.abspath(__file__)
ulalume3@0 111 dname = os.path.dirname(abspath)
ulalume3@0 112 fname = os.path.basename(abspath)
ulalume3@0 113 os.chdir(dname)
ulalume3@0 114
binietoglou@19 115 # PrintToOutputFile = True
ulalume3@0 116
binietoglou@19 117 sqr05 = 0.5 ** 0.5
ulalume3@0 118
volker@21 119 # ---- Initial definition of variables; the actual values will be read in with exec(open('./optic_input.py').read()) below
volker@16 120 # Do you want to calculate the errors? If not, just the GHK-parameters are determined.
volker@28 121 ScriptVersion = "0.9.8d"
volker@16 122 Error_Calc = True
ulalume3@0 123 LID = "internal"
ulalume3@0 124 EID = "internal"
ulalume3@0 125 # --- IL Laser IL and +-Uncertainty
volker@23 126 DOLP, dDOLP, nDOLP = 0.995, 0.005, 1 # degree of linear polarization; default 1
binietoglou@19 127 RotL, dRotL, nRotL = 0.0, 0.0, 1 # alpha; rotation of laser polarization in degrees; default 0
volker@28 128 # IL = 1e5 #photons in the laser beam, including detection efficiency of the telescope, atmodspheric and r^2 attenuation
ulalume3@0 129 # --- ME Emitter and +-Uncertainty
binietoglou@19 130 DiE, dDiE, nDiE = 0., 0.00, 1 # Diattenuation
binietoglou@19 131 TiE = 1. # Unpolarized transmittance
binietoglou@19 132 RetE, dRetE, nRetE = 0., 180.0, 0 # Retardance in degrees
binietoglou@19 133 RotE, dRotE, nRotE = 0., 0.0, 0 # beta: Rotation of optical element in degrees
ulalume3@0 134 # --- MO Receiver Optics including telescope
binietoglou@19 135 DiO, dDiO, nDiO = -0.055, 0.003, 1
binietoglou@19 136 TiO = 0.9
binietoglou@19 137 RetO, dRetO, nRetO = 0., 180.0, 2
binietoglou@19 138 RotO, dRotO, nRotO = 0., 0.1, 1 # gamma
ulalume3@0 139 # --- PBS MT transmitting path defined with (TS,TP); and +-Uncertainty
binietoglou@19 140 TP, dTP, nTP = 0.98, 0.02, 1
binietoglou@19 141 TS, dTS, nTS = 0.001, 0.001, 1
ulalume3@0 142 TiT = 0.5 * (TP + TS)
binietoglou@19 143 DiT = (TP - TS) / (TP + TS)
ulalume3@0 144 # PolFilter
binietoglou@19 145 RetT, dRetT, nRetT = 0., 180., 0
binietoglou@19 146 ERaT, dERaT, nERaT = 0.001, 0.001, 1
binietoglou@19 147 RotaT, dRotaT, nRotaT = 0., 3., 1
binietoglou@19 148 DaT = (1 - ERaT) / (1 + ERaT)
binietoglou@19 149 TaT = 0.5 * (1 + ERaT)
ulalume3@0 150 # --- PBS MR reflecting path defined with (RS,RP); and +-Uncertainty
volker@13 151 RS_RP_depend_on_TS_TP = False
binietoglou@19 152 if (RS_RP_depend_on_TS_TP):
binietoglou@19 153 RP, dRP, nRP = 1 - TP, 0.00, 0
binietoglou@19 154 RS, dRS, nRS = 1 - TS, 0.00, 0
volker@13 155 else:
binietoglou@19 156 RP, dRP, nRP = 0.05, 0.01, 1
binietoglou@19 157 RS, dRS, nRS = 0.98, 0.01, 1
ulalume3@0 158 TiR = 0.5 * (RP + RS)
binietoglou@19 159 DiR = (RP - RS) / (RP + RS)
ulalume3@0 160 # PolFilter
binietoglou@19 161 RetR, dRetR, nRetR = 0., 180., 0
binietoglou@19 162 ERaR, dERaR, nERaR = 0.001, 0.001, 1
binietoglou@19 163 RotaR, dRotaR, nRotaR = 90., 3., 1
binietoglou@19 164 DaR = (1 - ERaR) / (1 + ERaR)
binietoglou@19 165 TaR = 0.5 * (1 + ERaR)
ulalume3@0 166
volker@28 167 # +++ Orientation of the PBS with respect to the reference plane (see Polarisation-orientation.png and Polarisation-orientation-2.png in /system_settings)
volker@28 168 # Y = +1: polarisation in reference plane is finally transmitted,
volker@28 169 # Y = -1: polarisation in reference plane is finally reflected.
volker@28 170 Y = 1.
ulalume3@0 171
ulalume3@0 172 # Calibrator = type defined by matrix values
binietoglou@19 173 LocC = 4 # location of calibrator: behind laser = 1; behind emitter = 2; before receiver = 3; before PBS = 4
ulalume3@0 174
volker@28 175 # --- Additional attenuation (transmission of the ND-filter) during the calibration
volker@28 176 TCalT, dTCalT, nTCalT = 1, 0, 0 # transmitting path; error calc not working yet
volker@28 177 TCalR, dTCalR, nTCalR = 1, 0, 0 # reflecting path; error calc not working yet
volker@28 178
volker@28 179 # *** signal noise error calculation
volker@28 180 # --- number of photon counts in the signal summed up in the calibration range during the calibration measurements
volker@28 181 NCalT = 1e6 # default 1e6, assumed the same in +45° and -45° signals
volker@28 182 NCalR = 1e6 # default 1e6, assumed the same in +45° and -45° signals
volker@28 183 NILfac = 200 # duration of standard (0°) measurement relative to calibration measurements
volker@28 184 nNCal = 0 # error nNCal: one-sigma in steps to left and right for calibration signals
volker@28 185 nNI = 0 # error nNI: one-sigma in steps to left and right for 0° signals
volker@28 186 IoutTp0, IoutTp, dIoutTp0 = 0.5, 0.5, 0
volker@28 187 IoutTm0, IoutTm, dIoutTm0 = 0.5, 0.5, 0
volker@28 188 IoutRp0, IoutRp, dIoutRp0 = 0.5, 0.5, 0
volker@28 189 IoutRm0, IoutRm, dIoutRm0 = 0.5, 0.5, 0
volker@28 190 It0, It, dIt0 = 1 , 1, 0
volker@28 191 Ir0, Ir, dTr0 = 1 , 1, 0
volker@28 192 CalcFrom0deg = True
volker@28 193
binietoglou@19 194 TypeC = 3 # linear polarizer calibrator
ulalume3@0 195 # example with extinction ratio 0.001
binietoglou@19 196 DiC, dDiC, nDiC = 1.0, 0., 0 # ideal 1.0
binietoglou@19 197 TiC = 0.5 # ideal 0.5
binietoglou@19 198 RetC, dRetC, nRetC = 0., 0., 0
binietoglou@19 199 RotC, dRotC, nRotC = 0.0, 0.1, 0 # constant calibrator offset epsilon
binietoglou@19 200 RotationErrorEpsilonForNormalMeasurements = False # is in general False for TypeC == 3 calibrator
ulalume3@0 201
ulalume3@0 202 # Rotation error without calibrator: if False, then epsilon = 0 for normal measurements
ulalume3@0 203 RotationErrorEpsilonForNormalMeasurements = True
volker@28 204 # BSR backscatter ratio
volker@28 205 # BSR, dBSR, nBSR = 10, 0.05, 1
volker@28 206 BSR = np.zeros(5)
volker@28 207 BSR = [1.1, 2, 5, 10, 50]
volker@28 208 # theoretical molecular LDR LDRm
volker@28 209 LDRm, dLDRm, nLDRm = 0.004, 0.001, 1
ulalume3@0 210 # LDRCal assumed atmospheric linear depolarization ratio during the calibration measurements (first guess)
binietoglou@19 211 LDRCal0, dLDRCal, nLDRCal = 0.25, 0.04, 1
ulalume3@0 212 LDRCal = LDRCal0
ulalume3@0 213 # measured LDRm will be corrected with calculated parameters
ulalume3@0 214 LDRmeas = 0.015
ulalume3@0 215 # LDRtrue for simulation of measurement => LDRsim
ulalume3@0 216 LDRtrue = 0.5
ulalume3@0 217 LDRtrue2 = 0.004
volker@28 218 LDRunCorr = 1
ulalume3@0 219 # Initialize other values to 0
ulalume3@0 220 ER, nER, dER = 0.001, 0, 0.001
ulalume3@0 221 K = 0.
ulalume3@0 222 Km = 0.
ulalume3@0 223 Kp = 0.
ulalume3@0 224 LDRcorr = 0.
ulalume3@0 225 Eta = 0.
ulalume3@0 226 Ir = 0.
ulalume3@0 227 It = 0.
ulalume3@0 228 h = 1.
ulalume3@0 229
ulalume3@0 230 Loc = ['', 'behind laser', 'behind emitter', 'before receiver', 'before PBS']
binietoglou@19 231 Type = ['', 'mechanical rotator', 'hwp rotator', 'linear polarizer', 'qwp rotator', 'circular polarizer',
binietoglou@19 232 'real HWP +-22.5°']
ulalume3@0 233 dY = ['reflected channel', '', 'transmitted channel']
volker@28 234 bPlotEtax = False
ulalume3@0 235
ulalume3@0 236 # end of initial definition of variables
ulalume3@0 237 # *******************************************************************************************************************************
ulalume3@0 238
volker@28 239 # --- Read actual lidar system parameters from optic_input.py (must be in the programs sub-directory 'system_settings')
volker@28 240 #InputFile = 'optic_input_example_lidar_2.py'
volker@28 241 #InputFile = 'optic_input_example_lidar_3.py'
volker@28 242 #InputFile = 'optic_input_example_lidar_4.py'
volker@28 243 #InputFile = 'optic_input_example_lidar_5.py'
volker@28 244 InputFile = 'optic_input_example_lidar.py'
volker@28 245
ulalume3@0 246 '''
ulalume3@0 247 print("From ", dname)
ulalume3@0 248 print("Running ", fname)
ulalume3@0 249 print("Reading input file ", InputFile, " for")
ulalume3@0 250 '''
ulalume3@0 251 input_path = os.path.join('.', 'system_settings', InputFile)
volker@21 252 # this works with Python 2 and 3!
binietoglou@19 253 exec (open(input_path).read(), globals())
ulalume3@0 254 # end of read actual system parameters
ulalume3@0 255
volker@21 256
ulalume3@0 257 # --- Manual Parameter Change ---
ulalume3@0 258 # (use for quick parameter changes without changing the input file )
binietoglou@19 259 # DiO = 0.
binietoglou@19 260 # LDRtrue = 0.45
binietoglou@19 261 # LDRtrue2 = 0.004
binietoglou@19 262 # Y = -1
binietoglou@19 263 # LocC = 4 #location of calibrator: 1 = behind laser; 2 = behind emitter; 3 = before receiver; 4 = before PBS
ulalume3@0 264 ##TypeC = 6 Don't change the TypeC here
binietoglou@19 265 # RotationErrorEpsilonForNormalMeasurements = True
binietoglou@19 266 # LDRCal = 0.25
ulalume3@0 267 ## --- Errors
volker@23 268 DOLP0, dDOLP, nDOLP = DOLP, dDOLP, nDOLP
ulalume3@0 269 RotL0, dRotL, nRotL = RotL, dRotL, nRotL
ulalume3@0 270
binietoglou@19 271 DiE0, dDiE, nDiE = DiE, dDiE, nDiE
ulalume3@0 272 RetE0, dRetE, nRetE = RetE, dRetE, nRetE
ulalume3@0 273 RotE0, dRotE, nRotE = RotE, dRotE, nRotE
ulalume3@0 274
binietoglou@19 275 DiO0, dDiO, nDiO = DiO, dDiO, nDiO
ulalume3@0 276 RetO0, dRetO, nRetO = RetO, dRetO, nRetO
ulalume3@0 277 RotO0, dRotO, nRotO = RotO, dRotO, nRotO
ulalume3@0 278
binietoglou@19 279 DiC0, dDiC, nDiC = DiC, dDiC, nDiC
ulalume3@0 280 RetC0, dRetC, nRetC = RetC, dRetC, nRetC
ulalume3@0 281 RotC0, dRotC, nRotC = RotC, dRotC, nRotC
ulalume3@0 282
binietoglou@19 283 TP0, dTP, nTP = TP, dTP, nTP
binietoglou@19 284 TS0, dTS, nTS = TS, dTS, nTS
ulalume3@0 285 RetT0, dRetT, nRetT = RetT, dRetT, nRetT
ulalume3@0 286
ulalume3@0 287 ERaT0, dERaT, nERaT = ERaT, dERaT, nERaT
binietoglou@19 288 RotaT0, dRotaT, nRotaT = RotaT, dRotaT, nRotaT
ulalume3@0 289
binietoglou@19 290 RP0, dRP, nRP = RP, dRP, nRP
binietoglou@19 291 RS0, dRS, nRS = RS, dRS, nRS
ulalume3@0 292 RetR0, dRetR, nRetR = RetR, dRetR, nRetR
ulalume3@0 293
ulalume3@0 294 ERaR0, dERaR, nERaR = ERaR, dERaR, nERaR
binietoglou@19 295 RotaR0, dRotaR, nRotaR = RotaR, dRotaR, nRotaR
ulalume3@0 296
binietoglou@19 297 LDRCal0, dLDRCal, nLDRCal = LDRCal, dLDRCal, nLDRCal
volker@28 298
volker@28 299 # BSR0, dBSR, nBSR = BSR, dBSR, nBSR
volker@28 300 LDRm0, dLDRm, nLDRm = LDRm, dLDRm, nLDRm
ulalume3@0 301 # ---------- End of manual parameter change
ulalume3@0 302
ulalume3@0 303 RotL, RotE, RetE, DiE, RotO, RetO, DiO, RotC, RetC, DiC = RotL0, RotE0, RetE0, DiE0, RotO0, RetO0, DiO0, RotC0, RetC0, DiC0
binietoglou@19 304 TP, TS, RP, RS, ERaT, RotaT, RetT, ERaR, RotaR, RetR = TP0, TS0, RP0, RS0, ERaT0, RotaT0, RetT0, ERaR0, RotaR0, RetR0
ulalume3@0 305 LDRCal = LDRCal0
binietoglou@19 306 DTa0, TTa0, DRa0, TRa0, LDRsimx, LDRCorr = 0, 0, 0, 0, 0, 0
volker@28 307 TCalT0, TCalR0 = TCalT, TCalR
ulalume3@0 308
ulalume3@0 309 TiT = 0.5 * (TP + TS)
binietoglou@19 310 DiT = (TP - TS) / (TP + TS)
binietoglou@19 311 ZiT = (1. - DiT ** 2) ** 0.5
ulalume3@0 312 TiR = 0.5 * (RP + RS)
binietoglou@19 313 DiR = (RP - RS) / (RP + RS)
binietoglou@19 314 ZiR = (1. - DiR ** 2) ** 0.5
binietoglou@19 315
volker@28 316 C2aT = np.cos(np.deg2rad(2 * RotaT))
volker@28 317 C2aR = np.cos(np.deg2rad(2 * RotaR))
volker@28 318 ATPT = (1 + C2aT * DaT * DiT)
volker@28 319 ARPT = (1 + C2aR * DaR * DiR)
volker@28 320 TTa = TiT * TaT * ATPT # unpolarized transmission
volker@28 321 TRa = TiR * TaR * ARPT # unpolarized transmission
volker@28 322 Eta0 = TRa / TTa
volker@28 323 # --- this subroutine is for the calculation of the PLDR from LDR, BSR, and LDRm -----------------------------------------------------
volker@28 324 def CalcPLDR(LDR, BSR, LDRm):
volker@28 325 PLDR = (BSR * (1. + LDRm) * LDR - LDRm * (1. + LDR)) / (BSR * (1. + LDRm) - (1. + LDR))
volker@28 326 return (PLDR)
volker@13 327 # --- this subroutine is for the calculation with certain fixed parameters -----------------------------------------------------
volker@28 328 def Calc(TCalT, TCalR, NCalT, NCalR, DOLP, RotL, RotE, RetE, DiE, RotO, RetO, DiO,
volker@28 329 RotC, RetC, DiC, TP, TS, RP, RS,
volker@28 330 ERaT, RotaT, RetT, ERaR, RotaR, RetR, LDRCal):
ulalume3@0 331 # ---- Do the calculations of bra-ket vectors
ulalume3@0 332 h = -1. if TypeC == 2 else 1
ulalume3@0 333 # from input file: assumed LDRCal for calibration measurements
binietoglou@19 334 aCal = (1. - LDRCal) / (1 + LDRCal)
ulalume3@0 335 # from input file: measured LDRm and true LDRtrue, LDRtrue2 =>
binietoglou@19 336 # ameas = (1.-LDRmeas)/(1+LDRmeas)
binietoglou@19 337 atrue = (1. - LDRtrue) / (1 + LDRtrue)
binietoglou@19 338 # atrue2 = (1.-LDRtrue2)/(1+LDRtrue2)
ulalume3@0 339
ulalume3@0 340 # angles of emitter and laser and calibrator and receiver optics
ulalume3@0 341 # RotL = alpha, RotE = beta, RotO = gamma, RotC = epsilon
binietoglou@19 342 S2a = np.sin(2 * np.deg2rad(RotL))
binietoglou@19 343 C2a = np.cos(2 * np.deg2rad(RotL))
binietoglou@19 344 S2b = np.sin(2 * np.deg2rad(RotE))
binietoglou@19 345 C2b = np.cos(2 * np.deg2rad(RotE))
binietoglou@19 346 S2ab = np.sin(np.deg2rad(2 * RotL - 2 * RotE))
binietoglou@19 347 C2ab = np.cos(np.deg2rad(2 * RotL - 2 * RotE))
binietoglou@19 348 S2g = np.sin(np.deg2rad(2 * RotO))
binietoglou@19 349 C2g = np.cos(np.deg2rad(2 * RotO))
ulalume3@0 350
volker@23 351 # Laser with Degree of linear polarization DOLP
ulalume3@0 352 IinL = 1.
volker@23 353 QinL = DOLP
ulalume3@0 354 UinL = 0.
volker@23 355 VinL = (1. - DOLP ** 2) ** 0.5
ulalume3@0 356
ulalume3@0 357 # Stokes Input Vector rotation Eq. E.4
binietoglou@19 358 A = C2a * QinL - S2a * UinL
binietoglou@19 359 B = S2a * QinL + C2a * UinL
ulalume3@0 360 # Stokes Input Vector rotation Eq. E.9
binietoglou@19 361 C = C2ab * QinL - S2ab * UinL
binietoglou@19 362 D = S2ab * QinL + C2ab * UinL
ulalume3@0 363
ulalume3@0 364 # emitter optics
ulalume3@0 365 CosE = np.cos(np.deg2rad(RetE))
ulalume3@0 366 SinE = np.sin(np.deg2rad(RetE))
binietoglou@19 367 ZiE = (1. - DiE ** 2) ** 0.5
binietoglou@19 368 WiE = (1. - ZiE * CosE)
ulalume3@0 369
ulalume3@0 370 # Stokes Input Vector after emitter optics equivalent to Eq. E.9 with already rotated input vector from Eq. E.4
ulalume3@0 371 # b = beta
binietoglou@19 372 IinE = (IinL + DiE * C)
binietoglou@19 373 QinE = (C2b * DiE * IinL + A + S2b * (WiE * D - ZiE * SinE * VinL))
binietoglou@19 374 UinE = (S2b * DiE * IinL + B - C2b * (WiE * D - ZiE * SinE * VinL))
binietoglou@19 375 VinE = (-ZiE * SinE * D + ZiE * CosE * VinL)
ulalume3@0 376
ulalume3@0 377 # Stokes Input Vector before receiver optics Eq. E.19 (after atmosphere F)
ulalume3@0 378 IinF = IinE
binietoglou@19 379 QinF = aCal * QinE
binietoglou@19 380 UinF = -aCal * UinE
binietoglou@19 381 VinF = (1. - 2. * aCal) * VinE
ulalume3@0 382
ulalume3@0 383 # receiver optics
ulalume3@0 384 CosO = np.cos(np.deg2rad(RetO))
ulalume3@0 385 SinO = np.sin(np.deg2rad(RetO))
binietoglou@19 386 ZiO = (1. - DiO ** 2) ** 0.5
binietoglou@19 387 WiO = (1. - ZiO * CosO)
ulalume3@0 388
ulalume3@0 389 # calibrator
ulalume3@0 390 CosC = np.cos(np.deg2rad(RetC))
ulalume3@0 391 SinC = np.sin(np.deg2rad(RetC))
binietoglou@19 392 ZiC = (1. - DiC ** 2) ** 0.5
binietoglou@19 393 WiC = (1. - ZiC * CosC)
ulalume3@0 394
ulalume3@0 395 # Stokes Input Vector before the polarising beam splitter Eq. E.31
binietoglou@19 396 A = C2g * QinE - S2g * UinE
binietoglou@19 397 B = S2g * QinE + C2g * UinE
ulalume3@0 398
binietoglou@19 399 IinP = (IinE + DiO * aCal * A)
binietoglou@19 400 QinP = (C2g * DiO * IinE + aCal * QinE - S2g * (WiO * aCal * B + ZiO * SinO * (1 - 2 * aCal) * VinE))
binietoglou@19 401 UinP = (S2g * DiO * IinE - aCal * UinE + C2g * (WiO * aCal * B + ZiO * SinO * (1 - 2 * aCal) * VinE))
binietoglou@19 402 VinP = (ZiO * SinO * aCal * B + ZiO * CosO * (1 - 2 * aCal) * VinE)
ulalume3@0 403
binietoglou@19 404 # -------------------------
ulalume3@0 405 # F11 assuemd to be = 1 => measured: F11m = IinP / IinE with atrue
binietoglou@19 406 # F11sim = TiO*(IinE + DiO*atrue*A)/IinE
binietoglou@19 407 # -------------------------
ulalume3@0 408
ulalume3@0 409 # analyser
binietoglou@19 410 if (RS_RP_depend_on_TS_TP):
volker@13 411 RS = 1 - TS
volker@13 412 RP = 1 - TP
volker@21 413
ulalume3@0 414 TiT = 0.5 * (TP + TS)
binietoglou@19 415 DiT = (TP - TS) / (TP + TS)
binietoglou@19 416 ZiT = (1. - DiT ** 2) ** 0.5
ulalume3@0 417 TiR = 0.5 * (RP + RS)
binietoglou@19 418 DiR = (RP - RS) / (RP + RS)
binietoglou@19 419 ZiR = (1. - DiR ** 2) ** 0.5
ulalume3@0 420 CosT = np.cos(np.deg2rad(RetT))
ulalume3@0 421 SinT = np.sin(np.deg2rad(RetT))
ulalume3@0 422 CosR = np.cos(np.deg2rad(RetR))
ulalume3@0 423 SinR = np.sin(np.deg2rad(RetR))
ulalume3@0 424
binietoglou@19 425 DaT = (1 - ERaT) / (1 + ERaT)
binietoglou@19 426 DaR = (1 - ERaR) / (1 + ERaR)
binietoglou@19 427 TaT = 0.5 * (1 + ERaT)
binietoglou@19 428 TaR = 0.5 * (1 + ERaR)
ulalume3@0 429
binietoglou@19 430 S2aT = np.sin(np.deg2rad(h * 2 * RotaT))
binietoglou@19 431 C2aT = np.cos(np.deg2rad(2 * RotaT))
binietoglou@19 432 S2aR = np.sin(np.deg2rad(h * 2 * RotaR))
binietoglou@19 433 C2aR = np.cos(np.deg2rad(2 * RotaR))
ulalume3@0 434
volker@28 435 # Analyzer As before the PBS Eq. D.5; combined PBS and cleaning pol-filter
volker@28 436 ATPT = (1 + C2aT * DaT * DiT) # unpolarized transmission correction
volker@28 437 TTa = TiT * TaT * ATPT # unpolarized transmission
volker@28 438 ATP1 = 1
volker@28 439 ATP2 = Y * (DiT + C2aT * DaT) / ATPT
volker@28 440 ATP3 = Y * S2aT * DaT * ZiT * CosT / ATPT
volker@28 441 ATP4 = S2aT * DaT * ZiT * SinT / ATPT
binietoglou@19 442 ATP = np.array([ATP1, ATP2, ATP3, ATP4])
volker@28 443 DTa = ATP2 * Y
ulalume3@0 444
volker@28 445 ARPT = (1 + C2aR * DaR * DiR) # unpolarized transmission correction
volker@28 446 TRa = TiR * TaR * ARPT # unpolarized transmission
volker@28 447 ARP1 = 1
volker@28 448 ARP2 = Y * (DiR + C2aR * DaR) / ARPT
volker@28 449 ARP3 = Y * S2aR * DaR * ZiR * CosR / ARPT
volker@28 450 ARP4 = S2aR * DaR * ZiR * SinR / ARPT
binietoglou@19 451 ARP = np.array([ARP1, ARP2, ARP3, ARP4])
volker@28 452 DRa = ARP2 * Y
ulalume3@0 453
ulalume3@0 454
ulalume3@0 455 # ---- Calculate signals and correction parameters for diffeent locations and calibrators
ulalume3@0 456 if LocC == 4: # Calibrator before the PBS
binietoglou@19 457 # print("Calibrator location not implemented yet")
ulalume3@0 458
binietoglou@19 459 # S2ge = np.sin(np.deg2rad(2*RotO + h*2*RotC))
binietoglou@19 460 # C2ge = np.cos(np.deg2rad(2*RotO + h*2*RotC))
binietoglou@19 461 S2e = np.sin(np.deg2rad(h * 2 * RotC))
binietoglou@19 462 C2e = np.cos(np.deg2rad(2 * RotC))
ulalume3@0 463 # rotated AinP by epsilon Eq. C.3
binietoglou@19 464 ATP2e = C2e * ATP2 + S2e * ATP3
binietoglou@19 465 ATP3e = C2e * ATP3 - S2e * ATP2
binietoglou@19 466 ARP2e = C2e * ARP2 + S2e * ARP3
binietoglou@19 467 ARP3e = C2e * ARP3 - S2e * ARP2
binietoglou@19 468 ATPe = np.array([ATP1, ATP2e, ATP3e, ATP4])
binietoglou@19 469 ARPe = np.array([ARP1, ARP2e, ARP3e, ARP4])
ulalume3@0 470 # Stokes Input Vector before the polarising beam splitter Eq. E.31
binietoglou@19 471 A = C2g * QinE - S2g * UinE
binietoglou@19 472 B = S2g * QinE + C2g * UinE
binietoglou@19 473 # C = (WiO*aCal*B + ZiO*SinO*(1-2*aCal)*VinE)
binietoglou@19 474 Co = ZiO * SinO * VinE
binietoglou@19 475 Ca = (WiO * B - 2 * ZiO * SinO * VinE)
binietoglou@19 476 # C = Co + aCal*Ca
binietoglou@19 477 # IinP = (IinE + DiO*aCal*A)
binietoglou@19 478 # QinP = (C2g*DiO*IinE + aCal*QinE - S2g*C)
binietoglou@19 479 # UinP = (S2g*DiO*IinE - aCal*UinE + C2g*C)
binietoglou@19 480 # VinP = (ZiO*SinO*aCal*B + ZiO*CosO*(1-2*aCal)*VinE)
ulalume3@0 481 IinPo = IinE
binietoglou@19 482 QinPo = (C2g * DiO * IinE - S2g * Co)
binietoglou@19 483 UinPo = (S2g * DiO * IinE + C2g * Co)
binietoglou@19 484 VinPo = ZiO * CosO * VinE
ulalume3@0 485
binietoglou@19 486 IinPa = DiO * A
binietoglou@19 487 QinPa = QinE - S2g * Ca
binietoglou@19 488 UinPa = -UinE + C2g * Ca
binietoglou@19 489 VinPa = ZiO * (SinO * B - 2 * CosO * VinE)
ulalume3@0 490
binietoglou@19 491 IinP = IinPo + aCal * IinPa
binietoglou@19 492 QinP = QinPo + aCal * QinPa
binietoglou@19 493 UinP = UinPo + aCal * UinPa
binietoglou@19 494 VinP = VinPo + aCal * VinPa
ulalume3@0 495 # Stokes Input Vector before the polarising beam splitter rotated by epsilon Eq. C.3
binietoglou@19 496 # QinPe = C2e*QinP + S2e*UinP
binietoglou@19 497 # UinPe = C2e*UinP - S2e*QinP
binietoglou@19 498 QinPoe = C2e * QinPo + S2e * UinPo
binietoglou@19 499 UinPoe = C2e * UinPo - S2e * QinPo
binietoglou@19 500 QinPae = C2e * QinPa + S2e * UinPa
binietoglou@19 501 UinPae = C2e * UinPa - S2e * QinPa
binietoglou@19 502 QinPe = C2e * QinP + S2e * UinP
binietoglou@19 503 UinPe = C2e * UinP - S2e * QinP
ulalume3@0 504
ulalume3@0 505 # Calibration signals and Calibration correction K from measurements with LDRCal / aCal
ulalume3@0 506 if (TypeC == 2) or (TypeC == 1): # rotator calibration Eq. C.4
ulalume3@0 507 # parameters for calibration with aCal
binietoglou@19 508 AT = ATP1 * IinP + h * ATP4 * VinP
binietoglou@19 509 BT = ATP3e * QinP - h * ATP2e * UinP
binietoglou@19 510 AR = ARP1 * IinP + h * ARP4 * VinP
binietoglou@19 511 BR = ARP3e * QinP - h * ARP2e * UinP
volker@23 512 # Correction parameters for normal measurements; they are independent of LDR
binietoglou@19 513 if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out
binietoglou@19 514 IS1 = np.array([IinPo, QinPo, UinPo, VinPo])
binietoglou@19 515 IS2 = np.array([IinPa, QinPa, UinPa, VinPa])
binietoglou@19 516 GT = np.dot(ATP, IS1)
binietoglou@19 517 GR = np.dot(ARP, IS1)
binietoglou@19 518 HT = np.dot(ATP, IS2)
binietoglou@19 519 HR = np.dot(ARP, IS2)
ulalume3@0 520 else:
binietoglou@19 521 IS1 = np.array([IinPo, QinPo, UinPo, VinPo])
binietoglou@19 522 IS2 = np.array([IinPa, QinPa, UinPa, VinPa])
binietoglou@19 523 GT = np.dot(ATPe, IS1)
binietoglou@19 524 GR = np.dot(ARPe, IS1)
binietoglou@19 525 HT = np.dot(ATPe, IS2)
binietoglou@19 526 HR = np.dot(ARPe, IS2)
ulalume3@0 527 elif (TypeC == 3) or (TypeC == 4): # linear polariser calibration Eq. C.5
ulalume3@0 528 # parameters for calibration with aCal
binietoglou@19 529 AT = ATP1 * IinP + ATP3e * UinPe + ZiC * CosC * (ATP2e * QinPe + ATP4 * VinP)
binietoglou@19 530 BT = DiC * (ATP1 * UinPe + ATP3e * IinP) - ZiC * SinC * (ATP2e * VinP - ATP4 * QinPe)
binietoglou@19 531 AR = ARP1 * IinP + ARP3e * UinPe + ZiC * CosC * (ARP2e * QinPe + ARP4 * VinP)
binietoglou@19 532 BR = DiC * (ARP1 * UinPe + ARP3e * IinP) - ZiC * SinC * (ARP2e * VinP - ARP4 * QinPe)
volker@23 533 # Correction parameters for normal measurements; they are independent of LDR
binietoglou@19 534 if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out
binietoglou@19 535 IS1 = np.array([IinPo, QinPo, UinPo, VinPo])
binietoglou@19 536 IS2 = np.array([IinPa, QinPa, UinPa, VinPa])
binietoglou@19 537 GT = np.dot(ATP, IS1)
binietoglou@19 538 GR = np.dot(ARP, IS1)
binietoglou@19 539 HT = np.dot(ATP, IS2)
binietoglou@19 540 HR = np.dot(ARP, IS2)
ulalume3@0 541 else:
binietoglou@19 542 IS1e = np.array([IinPo + DiC * QinPoe, DiC * IinPo + QinPoe, ZiC * (CosC * UinPoe + SinC * VinPo),
binietoglou@19 543 -ZiC * (SinC * UinPoe - CosC * VinPo)])
binietoglou@19 544 IS2e = np.array([IinPa + DiC * QinPae, DiC * IinPa + QinPae, ZiC * (CosC * UinPae + SinC * VinPa),
binietoglou@19 545 -ZiC * (SinC * UinPae - CosC * VinPa)])
binietoglou@19 546 GT = np.dot(ATPe, IS1e)
binietoglou@19 547 GR = np.dot(ARPe, IS1e)
binietoglou@19 548 HT = np.dot(ATPe, IS2e)
binietoglou@19 549 HR = np.dot(ARPe, IS2e)
ulalume3@0 550 elif (TypeC == 6): # diattenuator calibration +-22.5° rotated_diattenuator_X22x5deg.odt
ulalume3@0 551 # parameters for calibration with aCal
binietoglou@19 552 AT = ATP1 * IinP + sqr05 * DiC * (ATP1 * QinPe + ATP2e * IinP) + (1 - 0.5 * WiC) * (
binietoglou@19 553 ATP2e * QinPe + ATP3e * UinPe) + ZiC * (sqr05 * SinC * (ATP3e * VinP - ATP4 * UinPe) + ATP4 * CosC * VinP)
binietoglou@19 554 BT = sqr05 * DiC * (ATP1 * UinPe + ATP3e * IinP) + 0.5 * WiC * (
binietoglou@19 555 ATP2e * UinPe + ATP3e * QinPe) - sqr05 * ZiC * SinC * (ATP2e * VinP - ATP4 * QinPe)
binietoglou@19 556 AR = ARP1 * IinP + sqr05 * DiC * (ARP1 * QinPe + ARP2e * IinP) + (1 - 0.5 * WiC) * (
binietoglou@19 557 ARP2e * QinPe + ARP3e * UinPe) + ZiC * (sqr05 * SinC * (ARP3e * VinP - ARP4 * UinPe) + ARP4 * CosC * VinP)
binietoglou@19 558 BR = sqr05 * DiC * (ARP1 * UinPe + ARP3e * IinP) + 0.5 * WiC * (
binietoglou@19 559 ARP2e * UinPe + ARP3e * QinPe) - sqr05 * ZiC * SinC * (ARP2e * VinP - ARP4 * QinPe)
volker@23 560 # Correction parameters for normal measurements; they are independent of LDR
binietoglou@19 561 if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out
binietoglou@19 562 IS1 = np.array([IinPo, QinPo, UinPo, VinPo])
binietoglou@19 563 IS2 = np.array([IinPa, QinPa, UinPa, VinPa])
binietoglou@19 564 GT = np.dot(ATP, IS1)
binietoglou@19 565 GR = np.dot(ARP, IS1)
binietoglou@19 566 HT = np.dot(ATP, IS2)
binietoglou@19 567 HR = np.dot(ARP, IS2)
ulalume3@0 568 else:
binietoglou@19 569 IS1e = np.array([IinPo + DiC * QinPoe, DiC * IinPo + QinPoe, ZiC * (CosC * UinPoe + SinC * VinPo),
binietoglou@19 570 -ZiC * (SinC * UinPoe - CosC * VinPo)])
binietoglou@19 571 IS2e = np.array([IinPa + DiC * QinPae, DiC * IinPa + QinPae, ZiC * (CosC * UinPae + SinC * VinPa),
binietoglou@19 572 -ZiC * (SinC * UinPae - CosC * VinPa)])
binietoglou@19 573 GT = np.dot(ATPe, IS1e)
binietoglou@19 574 GR = np.dot(ARPe, IS1e)
binietoglou@19 575 HT = np.dot(ATPe, IS2e)
binietoglou@19 576 HR = np.dot(ARPe, IS2e)
ulalume3@0 577 else:
ulalume3@0 578 print("Calibrator not implemented yet")
ulalume3@0 579 sys.exit()
ulalume3@0 580
ulalume3@0 581 elif LocC == 3: # C before receiver optics Eq.57
ulalume3@0 582
binietoglou@19 583 # S2ge = np.sin(np.deg2rad(2*RotO - 2*RotC))
binietoglou@19 584 # C2ge = np.cos(np.deg2rad(2*RotO - 2*RotC))
binietoglou@19 585 S2e = np.sin(np.deg2rad(2 * RotC))
binietoglou@19 586 C2e = np.cos(np.deg2rad(2 * RotC))
ulalume3@0 587
ulalume3@0 588 # As with C before the receiver optics (rotated_diattenuator_X22x5deg.odt)
binietoglou@19 589 AF1 = np.array([1, C2g * DiO, S2g * DiO, 0])
binietoglou@19 590 AF2 = np.array([C2g * DiO, 1 - S2g ** 2 * WiO, S2g * C2g * WiO, -S2g * ZiO * SinO])
binietoglou@19 591 AF3 = np.array([S2g * DiO, S2g * C2g * WiO, 1 - C2g ** 2 * WiO, C2g * ZiO * SinO])
binietoglou@19 592 AF4 = np.array([0, S2g * SinO, -C2g * SinO, CosO])
ulalume3@0 593
binietoglou@19 594 ATF = (ATP1 * AF1 + ATP2 * AF2 + ATP3 * AF3 + ATP4 * AF4)
binietoglou@19 595 ARF = (ARP1 * AF1 + ARP2 * AF2 + ARP3 * AF3 + ARP4 * AF4)
ulalume3@0 596 ATF2 = ATF[1]
ulalume3@0 597 ATF3 = ATF[2]
ulalume3@0 598 ARF2 = ARF[1]
ulalume3@0 599 ARF3 = ARF[2]
ulalume3@0 600
ulalume3@0 601 # rotated AinF by epsilon
ulalume3@0 602 ATF1 = ATF[0]
ulalume3@0 603 ATF4 = ATF[3]
binietoglou@19 604 ATF2e = C2e * ATF[1] + S2e * ATF[2]
binietoglou@19 605 ATF3e = C2e * ATF[2] - S2e * ATF[1]
ulalume3@0 606 ARF1 = ARF[0]
ulalume3@0 607 ARF4 = ARF[3]
binietoglou@19 608 ARF2e = C2e * ARF[1] + S2e * ARF[2]
binietoglou@19 609 ARF3e = C2e * ARF[2] - S2e * ARF[1]
ulalume3@0 610
binietoglou@19 611 ATFe = np.array([ATF1, ATF2e, ATF3e, ATF4])
binietoglou@19 612 ARFe = np.array([ARF1, ARF2e, ARF3e, ARF4])
ulalume3@0 613
binietoglou@19 614 QinEe = C2e * QinE + S2e * UinE
binietoglou@19 615 UinEe = C2e * UinE - S2e * QinE
ulalume3@0 616
ulalume3@0 617 # Stokes Input Vector before receiver optics Eq. E.19 (after atmosphere F)
ulalume3@0 618 IinF = IinE
binietoglou@19 619 QinF = aCal * QinE
binietoglou@19 620 UinF = -aCal * UinE
binietoglou@19 621 VinF = (1. - 2. * aCal) * VinE
ulalume3@0 622
ulalume3@0 623 IinFo = IinE
ulalume3@0 624 QinFo = 0.
ulalume3@0 625 UinFo = 0.
ulalume3@0 626 VinFo = VinE
ulalume3@0 627
ulalume3@0 628 IinFa = 0.
ulalume3@0 629 QinFa = QinE
ulalume3@0 630 UinFa = -UinE
binietoglou@19 631 VinFa = -2. * VinE
ulalume3@0 632
ulalume3@0 633 # Stokes Input Vector before receiver optics rotated by epsilon Eq. C.3
binietoglou@19 634 QinFe = C2e * QinF + S2e * UinF
binietoglou@19 635 UinFe = C2e * UinF - S2e * QinF
binietoglou@19 636 QinFoe = C2e * QinFo + S2e * UinFo
binietoglou@19 637 UinFoe = C2e * UinFo - S2e * QinFo
binietoglou@19 638 QinFae = C2e * QinFa + S2e * UinFa
binietoglou@19 639 UinFae = C2e * UinFa - S2e * QinFa
ulalume3@0 640
ulalume3@0 641 # Calibration signals and Calibration correction K from measurements with LDRCal / aCal
binietoglou@19 642 if (TypeC == 2) or (TypeC == 1): # rotator calibration Eq. C.4
ulalume3@0 643 # parameters for calibration with aCal
binietoglou@19 644 AT = ATF1 * IinF + ATF4 * h * VinF
binietoglou@19 645 BT = ATF3e * QinF - ATF2e * h * UinF
binietoglou@19 646 AR = ARF1 * IinF + ARF4 * h * VinF
binietoglou@19 647 BR = ARF3e * QinF - ARF2e * h * UinF
volker@23 648 # Correction parameters for normal measurements; they are independent of LDR
ulalume3@0 649 if (not RotationErrorEpsilonForNormalMeasurements):
binietoglou@19 650 GT = ATF1 * IinE + ATF4 * VinE
binietoglou@19 651 GR = ARF1 * IinE + ARF4 * VinE
binietoglou@19 652 HT = ATF2 * QinE - ATF3 * UinE - ATF4 * 2 * VinE
binietoglou@19 653 HR = ARF2 * QinE - ARF3 * UinE - ARF4 * 2 * VinE
ulalume3@0 654 else:
binietoglou@19 655 GT = ATF1 * IinE + ATF4 * h * VinE
binietoglou@19 656 GR = ARF1 * IinE + ARF4 * h * VinE
binietoglou@19 657 HT = ATF2e * QinE - ATF3e * h * UinE - ATF4 * h * 2 * VinE
binietoglou@19 658 HR = ARF2e * QinE - ARF3e * h * UinE - ARF4 * h * 2 * VinE
ulalume3@0 659 elif (TypeC == 3) or (TypeC == 4): # linear polariser calibration Eq. C.5
ulalume3@0 660 # p = +45°, m = -45°
binietoglou@19 661 IF1e = np.array([IinF, ZiC * CosC * QinFe, UinFe, ZiC * CosC * VinF])
binietoglou@19 662 IF2e = np.array([DiC * UinFe, -ZiC * SinC * VinF, DiC * IinF, ZiC * SinC * QinFe])
binietoglou@19 663 AT = np.dot(ATFe, IF1e)
binietoglou@19 664 AR = np.dot(ARFe, IF1e)
binietoglou@19 665 BT = np.dot(ATFe, IF2e)
binietoglou@19 666 BR = np.dot(ARFe, IF2e)
ulalume3@0 667
volker@23 668 # Correction parameters for normal measurements; they are independent of LDR --- the same as for TypeC = 6
binietoglou@19 669 if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out
binietoglou@19 670 IS1 = np.array([IinE, 0, 0, VinE])
binietoglou@19 671 IS2 = np.array([0, QinE, -UinE, -2 * VinE])
binietoglou@19 672 GT = np.dot(ATF, IS1)
binietoglou@19 673 GR = np.dot(ARF, IS1)
binietoglou@19 674 HT = np.dot(ATF, IS2)
binietoglou@19 675 HR = np.dot(ARF, IS2)
ulalume3@0 676 else:
binietoglou@19 677 IS1e = np.array([IinFo + DiC * QinFoe, DiC * IinFo + QinFoe, ZiC * (CosC * UinFoe + SinC * VinFo),
binietoglou@19 678 -ZiC * (SinC * UinFoe - CosC * VinFo)])
binietoglou@19 679 IS2e = np.array([IinFa + DiC * QinFae, DiC * IinFa + QinFae, ZiC * (CosC * UinFae + SinC * VinFa),
binietoglou@19 680 -ZiC * (SinC * UinFae - CosC * VinFa)])
binietoglou@19 681 GT = np.dot(ATFe, IS1e)
binietoglou@19 682 GR = np.dot(ARFe, IS1e)
binietoglou@19 683 HT = np.dot(ATFe, IS2e)
binietoglou@19 684 HR = np.dot(ARFe, IS2e)
ulalume3@0 685
ulalume3@0 686 elif (TypeC == 6): # diattenuator calibration +-22.5° rotated_diattenuator_X22x5deg.odt
ulalume3@0 687 # parameters for calibration with aCal
binietoglou@19 688 IF1e = np.array([IinF + sqr05 * DiC * QinFe, sqr05 * DiC * IinF + (1 - 0.5 * WiC) * QinFe,
binietoglou@19 689 (1 - 0.5 * WiC) * UinFe + sqr05 * ZiC * SinC * VinF,
binietoglou@19 690 -sqr05 * ZiC * SinC * UinFe + ZiC * CosC * VinF])
binietoglou@19 691 IF2e = np.array([sqr05 * DiC * UinFe, 0.5 * WiC * UinFe - sqr05 * ZiC * SinC * VinF,
binietoglou@19 692 sqr05 * DiC * IinF + 0.5 * WiC * QinFe, sqr05 * ZiC * SinC * QinFe])
binietoglou@19 693 AT = np.dot(ATFe, IF1e)
binietoglou@19 694 AR = np.dot(ARFe, IF1e)
binietoglou@19 695 BT = np.dot(ATFe, IF2e)
binietoglou@19 696 BR = np.dot(ARFe, IF2e)
ulalume3@0 697
volker@23 698 # Correction parameters for normal measurements; they are independent of LDR
binietoglou@19 699 if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out
binietoglou@19 700 # IS1 = np.array([IinE,0,0,VinE])
binietoglou@19 701 # IS2 = np.array([0,QinE,-UinE,-2*VinE])
binietoglou@19 702 IS1 = np.array([IinFo, 0, 0, VinFo])
binietoglou@19 703 IS2 = np.array([0, QinFa, UinFa, VinFa])
binietoglou@19 704 GT = np.dot(ATF, IS1)
binietoglou@19 705 GR = np.dot(ARF, IS1)
binietoglou@19 706 HT = np.dot(ATF, IS2)
binietoglou@19 707 HR = np.dot(ARF, IS2)
ulalume3@0 708 else:
binietoglou@19 709 IS1e = np.array([IinFo + DiC * QinFoe, DiC * IinFo + QinFoe, ZiC * (CosC * UinFoe + SinC * VinFo),
binietoglou@19 710 -ZiC * (SinC * UinFoe - CosC * VinFo)])
binietoglou@19 711 IS2e = np.array([IinFa + DiC * QinFae, DiC * IinFa + QinFae, ZiC * (CosC * UinFae + SinC * VinFa),
binietoglou@19 712 -ZiC * (SinC * UinFae - CosC * VinFa)])
binietoglou@19 713 # IS1e = np.array([IinFo,0,0,VinFo])
binietoglou@19 714 # IS2e = np.array([0,QinFae,UinFae,VinFa])
binietoglou@19 715 GT = np.dot(ATFe, IS1e)
binietoglou@19 716 GR = np.dot(ARFe, IS1e)
binietoglou@19 717 HT = np.dot(ATFe, IS2e)
binietoglou@19 718 HR = np.dot(ARFe, IS2e)
ulalume3@0 719
ulalume3@0 720 else:
ulalume3@0 721 print('Calibrator not implemented yet')
ulalume3@0 722 sys.exit()
ulalume3@0 723
ulalume3@0 724 elif LocC == 2: # C behind emitter optics Eq.57 -------------------------------------------------------
binietoglou@19 725 # print("Calibrator location not implemented yet")
binietoglou@19 726 S2e = np.sin(np.deg2rad(2 * RotC))
binietoglou@19 727 C2e = np.cos(np.deg2rad(2 * RotC))
ulalume3@0 728
ulalume3@0 729 # AS with C before the receiver optics (see document rotated_diattenuator_X22x5deg.odt)
binietoglou@19 730 AF1 = np.array([1, C2g * DiO, S2g * DiO, 0])
binietoglou@19 731 AF2 = np.array([C2g * DiO, 1 - S2g ** 2 * WiO, S2g * C2g * WiO, -S2g * ZiO * SinO])
binietoglou@19 732 AF3 = np.array([S2g * DiO, S2g * C2g * WiO, 1 - C2g ** 2 * WiO, C2g * ZiO * SinO])
binietoglou@19 733 AF4 = np.array([0, S2g * SinO, -C2g * SinO, CosO])
ulalume3@0 734
binietoglou@19 735 ATF = (ATP1 * AF1 + ATP2 * AF2 + ATP3 * AF3 + ATP4 * AF4)
binietoglou@19 736 ARF = (ARP1 * AF1 + ARP2 * AF2 + ARP3 * AF3 + ARP4 * AF4)
ulalume3@0 737 ATF1 = ATF[0]
ulalume3@0 738 ATF2 = ATF[1]
ulalume3@0 739 ATF3 = ATF[2]
ulalume3@0 740 ATF4 = ATF[3]
ulalume3@0 741 ARF1 = ARF[0]
ulalume3@0 742 ARF2 = ARF[1]
ulalume3@0 743 ARF3 = ARF[2]
ulalume3@0 744 ARF4 = ARF[3]
ulalume3@0 745
ulalume3@0 746 # AS with C behind the emitter
ulalume3@0 747 # terms without aCal
ulalume3@0 748 ATE1o, ARE1o = ATF1, ARF1
ulalume3@0 749 ATE2o, ARE2o = 0., 0.
ulalume3@0 750 ATE3o, ARE3o = 0., 0.
ulalume3@0 751 ATE4o, ARE4o = ATF4, ARF4
ulalume3@0 752 # terms with aCal
binietoglou@19 753 ATE1a, ARE1a = 0., 0.
ulalume3@0 754 ATE2a, ARE2a = ATF2, ARF2
ulalume3@0 755 ATE3a, ARE3a = -ATF3, -ARF3
binietoglou@19 756 ATE4a, ARE4a = -2 * ATF4, -2 * ARF4
ulalume3@0 757 # rotated AinEa by epsilon
binietoglou@19 758 ATE2ae = C2e * ATF2 + S2e * ATF3
binietoglou@19 759 ATE3ae = -S2e * ATF2 - C2e * ATF3
binietoglou@19 760 ARE2ae = C2e * ARF2 + S2e * ARF3
binietoglou@19 761 ARE3ae = -S2e * ARF2 - C2e * ARF3
ulalume3@0 762
ulalume3@0 763 ATE1 = ATE1o
binietoglou@19 764 ATE2e = aCal * ATE2ae
binietoglou@19 765 ATE3e = aCal * ATE3ae
binietoglou@19 766 ATE4 = (1 - 2 * aCal) * ATF4
ulalume3@0 767 ARE1 = ARE1o
binietoglou@19 768 ARE2e = aCal * ARE2ae
binietoglou@19 769 ARE3e = aCal * ARE3ae
binietoglou@19 770 ARE4 = (1 - 2 * aCal) * ARF4
ulalume3@0 771
ulalume3@0 772 # rotated IinE
binietoglou@19 773 QinEe = C2e * QinE + S2e * UinE
binietoglou@19 774 UinEe = C2e * UinE - S2e * QinE
ulalume3@0 775
ulalume3@0 776 # Calibration signals and Calibration correction K from measurements with LDRCal / aCal
binietoglou@19 777 if (TypeC == 2) or (TypeC == 1): # +++++++++ rotator calibration Eq. C.4
binietoglou@19 778 AT = ATE1o * IinE + (ATE4o + aCal * ATE4a) * h * VinE
binietoglou@19 779 BT = aCal * (ATE3ae * QinEe - ATE2ae * h * UinEe)
binietoglou@19 780 AR = ARE1o * IinE + (ARE4o + aCal * ARE4a) * h * VinE
binietoglou@19 781 BR = aCal * (ARE3ae * QinEe - ARE2ae * h * UinEe)
ulalume3@0 782
volker@23 783 # Correction parameters for normal measurements; they are independent of LDR
ulalume3@0 784 if (not RotationErrorEpsilonForNormalMeasurements):
ulalume3@0 785 # Stokes Input Vector before receiver optics Eq. E.19 (after atmosphere F)
binietoglou@19 786 GT = ATE1o * IinE + ATE4o * h * VinE
binietoglou@19 787 GR = ARE1o * IinE + ARE4o * h * VinE
binietoglou@19 788 HT = ATE2a * QinE + ATE3a * h * UinEe + ATE4a * h * VinE
binietoglou@19 789 HR = ARE2a * QinE + ARE3a * h * UinEe + ARE4a * h * VinE
ulalume3@0 790 else:
binietoglou@19 791 GT = ATE1o * IinE + ATE4o * h * VinE
binietoglou@19 792 GR = ARE1o * IinE + ARE4o * h * VinE
binietoglou@19 793 HT = ATE2ae * QinE + ATE3ae * h * UinEe + ATE4a * h * VinE
binietoglou@19 794 HR = ARE2ae * QinE + ARE3ae * h * UinEe + ARE4a * h * VinE
ulalume3@0 795
ulalume3@0 796 elif (TypeC == 3) or (TypeC == 4): # +++++++++ linear polariser calibration Eq. C.5
ulalume3@0 797 # p = +45°, m = -45°
binietoglou@19 798 AT = ATE1 * IinE + ZiC * CosC * (ATE2e * QinEe + ATE4 * VinE) + ATE3e * UinEe
binietoglou@19 799 BT = DiC * (ATE1 * UinEe + ATE3e * IinE) + ZiC * SinC * (ATE4 * QinEe - ATE2e * VinE)
binietoglou@19 800 AR = ARE1 * IinE + ZiC * CosC * (ARE2e * QinEe + ARE4 * VinE) + ARE3e * UinEe
binietoglou@19 801 BR = DiC * (ARE1 * UinEe + ARE3e * IinE) + ZiC * SinC * (ARE4 * QinEe - ARE2e * VinE)
ulalume3@0 802
volker@23 803 # Correction parameters for normal measurements; they are independent of LDR
ulalume3@0 804 if (not RotationErrorEpsilonForNormalMeasurements):
ulalume3@0 805 # Stokes Input Vector before receiver optics Eq. E.19 (after atmosphere F)
binietoglou@19 806 GT = ATE1o * IinE + ATE4o * VinE
binietoglou@19 807 GR = ARE1o * IinE + ARE4o * VinE
binietoglou@19 808 HT = ATE2a * QinE + ATE3a * UinE + ATE4a * VinE
binietoglou@19 809 HR = ARE2a * QinE + ARE3a * UinE + ARE4a * VinE
ulalume3@0 810 else:
binietoglou@19 811 D = IinE + DiC * QinEe
binietoglou@19 812 A = DiC * IinE + QinEe
binietoglou@19 813 B = ZiC * (CosC * UinEe + SinC * VinE)
binietoglou@19 814 C = -ZiC * (SinC * UinEe - CosC * VinE)
binietoglou@19 815 GT = ATE1o * D + ATE4o * C
binietoglou@19 816 GR = ARE1o * D + ARE4o * C
binietoglou@19 817 HT = ATE2a * A + ATE3a * B + ATE4a * C
binietoglou@19 818 HR = ARE2a * A + ARE3a * B + ARE4a * C
ulalume3@0 819
ulalume3@0 820 elif (TypeC == 6): # real HWP calibration +-22.5° rotated_diattenuator_X22x5deg.odt
ulalume3@0 821 # p = +22.5°, m = -22.5°
binietoglou@19 822 IE1e = np.array([IinE + sqr05 * DiC * QinEe, sqr05 * DiC * IinE + (1 - 0.5 * WiC) * QinEe,
binietoglou@19 823 (1 - 0.5 * WiC) * UinEe + sqr05 * ZiC * SinC * VinE,
binietoglou@19 824 -sqr05 * ZiC * SinC * UinEe + ZiC * CosC * VinE])
binietoglou@19 825 IE2e = np.array([sqr05 * DiC * UinEe, 0.5 * WiC * UinEe - sqr05 * ZiC * SinC * VinE,
binietoglou@19 826 sqr05 * DiC * IinE + 0.5 * WiC * QinEe, sqr05 * ZiC * SinC * QinEe])
binietoglou@19 827 ATEe = np.array([ATE1, ATE2e, ATE3e, ATE4])
binietoglou@19 828 AREe = np.array([ARE1, ARE2e, ARE3e, ARE4])
binietoglou@19 829 AT = np.dot(ATEe, IE1e)
binietoglou@19 830 AR = np.dot(AREe, IE1e)
binietoglou@19 831 BT = np.dot(ATEe, IE2e)
binietoglou@19 832 BR = np.dot(AREe, IE2e)
ulalume3@0 833
volker@23 834 # Correction parameters for normal measurements; they are independent of LDR
binietoglou@19 835 if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out
binietoglou@19 836 GT = ATE1o * IinE + ATE4o * VinE
binietoglou@19 837 GR = ARE1o * IinE + ARE4o * VinE
binietoglou@19 838 HT = ATE2a * QinE + ATE3a * UinE + ATE4a * VinE
binietoglou@19 839 HR = ARE2a * QinE + ARE3a * UinE + ARE4a * VinE
ulalume3@0 840 else:
binietoglou@19 841 D = IinE + DiC * QinEe
binietoglou@19 842 A = DiC * IinE + QinEe
binietoglou@19 843 B = ZiC * (CosC * UinEe + SinC * VinE)
binietoglou@19 844 C = -ZiC * (SinC * UinEe - CosC * VinE)
binietoglou@19 845 GT = ATE1o * D + ATE4o * C
binietoglou@19 846 GR = ARE1o * D + ARE4o * C
binietoglou@19 847 HT = ATE2a * A + ATE3a * B + ATE4a * C
binietoglou@19 848 HR = ARE2a * A + ARE3a * B + ARE4a * C
ulalume3@0 849
ulalume3@0 850 else:
ulalume3@0 851 print('Calibrator not implemented yet')
ulalume3@0 852 sys.exit()
ulalume3@0 853
ulalume3@0 854 else:
ulalume3@0 855 print("Calibrator location not implemented yet")
ulalume3@0 856 sys.exit()
ulalume3@0 857
volker@28 858 # Determination of the correction K of the calibration factor.
volker@28 859 IoutTp = TTa * TiC * TiO * TiE * (AT + BT)
volker@28 860 IoutTm = TTa * TiC * TiO * TiE * (AT - BT)
volker@28 861 IoutRp = TRa * TiC * TiO * TiE * (AR + BR)
volker@28 862 IoutRm = TRa * TiC * TiO * TiE * (AR - BR)
ulalume3@0 863 # --- Results and Corrections; electronic etaR and etaT are assumed to be 1
binietoglou@19 864 Etapx = IoutRp / IoutTp
binietoglou@19 865 Etamx = IoutRm / IoutTm
binietoglou@19 866 Etax = (Etapx * Etamx) ** 0.5
ulalume3@0 867
volker@28 868 Eta = (TRa / TTa) # = TRa / TTa; Eta = Eta*/K Eq. 84 => K = Eta* / Eta; equation corrected according to the papers supplement Eqs. (S.10.10.1) ff
ulalume3@0 869 K = Etax / Eta
ulalume3@0 870
ulalume3@0 871 # For comparison with Volkers Libreoffice Müller Matrix spreadsheet
binietoglou@19 872 # Eta_test_p = (IoutRp/IoutTp)
binietoglou@19 873 # Eta_test_m = (IoutRm/IoutTm)
binietoglou@19 874 # Eta_test = (Eta_test_p*Eta_test_m)**0.5
ulalume3@0 875
volker@28 876 # ----- random error calculation ----------
volker@28 877 # noise must be calculated with the photon counts of measured signals;
volker@28 878 # relative standard deviation of calibration signals with LDRcal; assumed to be statisitcally independent
volker@28 879 # normalised noise errors
volker@28 880 if (CalcFrom0deg):
volker@28 881 dIoutTp = (NCalT * IoutTp) ** -0.5
volker@28 882 dIoutTm = (NCalT * IoutTm) ** -0.5
volker@28 883 dIoutRp = (NCalR * IoutRp) ** -0.5
volker@28 884 dIoutRm = (NCalR * IoutRm) ** -0.5
volker@28 885 else:
volker@28 886 dIoutTp = (NCalT ** -0.5)
volker@28 887 dIoutTm = (NCalT ** -0.5)
volker@28 888 dIoutRp = (NCalR ** -0.5)
volker@28 889 dIoutRm = (NCalR ** -0.5)
volker@28 890 # Forward simulated 0°-signals with LDRCal with atrue; from input file
volker@28 891
volker@28 892 It = TTa * TiO * TiE * (GT + atrue * HT)
volker@28 893 Ir = TRa * TiO * TiE * (GR + atrue * HR)
volker@28 894 # relative standard deviation of standard signals with LDRmeas; assumed to be statisitcally independent
volker@28 895 if (CalcFrom0deg):
volker@28 896 dIt = ((NCalT * It / IoutTp * NILfac / TCalT) ** -0.5)
volker@28 897 dIr = ((NCalR * Ir / IoutRp * NILfac / TCalR) ** -0.5)
volker@28 898 else:
volker@28 899 dIt = ((NCalT * 2 * NILfac / TCalT ) ** -0.5) * It
volker@28 900 dIr = ((NCalR * 2 * NILfac / TCalR) ** -0.5) * Ir
volker@28 901
volker@28 902 # ----- Forward simulated LDRsim = 1/Eta*Ir/It # simulated LDR* with Y from input file
binietoglou@19 903 LDRsim = Ir / It # simulated uncorrected LDR with Y from input file
ulalume3@0 904 # Corrected LDRsimCorr from forward simulated LDRsim (atrue)
ulalume3@0 905 # LDRsimCorr = (1./Eta*LDRsim*(GT+HT)-(GR+HR))/((GR-HR)-1./Eta*LDRsim*(GT-HT))
volker@26 906 '''
volker@26 907 if ((Y == -1.) and (abs(RotL0) < 45)) or ((Y == +1.) and (abs(RotL0) > 45)):
volker@26 908 LDRsimx = 1. / LDRsim / Etax
ulalume3@0 909 else:
volker@26 910 LDRsimx = LDRsim / Etax
volker@28 911 '''
volker@26 912 LDRsimx = LDRsim
ulalume3@0 913
ulalume3@0 914 # The following is correct without doubt
volker@28 915 # LDRCorr = (LDRsim/(Etax/K)*(GT+HT)-(GR+HR))/((GR-HR)-LDRsim/(Etax/K)*(GT-HT))
ulalume3@0 916
ulalume3@0 917 # The following is a test whether the equations for calibration Etax and normal signal (GHK, LDRsim) are consistent
volker@28 918 LDRCorr = (LDRsim / (Etax / K) * (GT + HT) - (GR + HR)) / ((GR - HR) - LDRsim / (Etax / K) * (GT - HT))
volker@28 919 # here we could also use Eta instead of Etax / K => how to test whether Etax is correct? => comparison with MüllerMatrix simulation!
volker@28 920 # Without any correction: only measured It, Ir, EtaX are used
volker@28 921 LDRunCorr = (LDRsim / Etax * (GT / abs(GT) + HT / abs(HT)) - (GR / abs(GR) + HR / abs(HR))) / ((GR / abs(GR) - HR / abs(HR)) - LDRsim / Etax * (GT / abs(GT) - HT / abs(HT)))
ulalume3@0 922
volker@28 923 #LDRCorr = LDRsimx # for test only
volker@28 924
volker@28 925 F11sim = 1 / (TiO * TiE) * ((HR * Eta * It - HT * Ir) / (HR * GT - HT * GR)) # IL = 1, Etat = Etar = 1 ; AMT Eq.64; what is Etax/K? => see about 20 lines above: = Eta
ulalume3@0 926
volker@28 927 return (IoutTp, IoutTm, IoutRp, IoutRm, It, Ir, dIoutTp, dIoutTm, dIoutRp, dIoutRm, dIt, dIr,
volker@28 928 GT, HT, GR, HR, K, Eta, LDRsimx, LDRCorr, DTa, DRa, TTa, TRa, F11sim, LDRunCorr)
volker@28 929
binietoglou@19 930
binietoglou@19 931
ulalume3@0 932 # *******************************************************************************************************************************
ulalume3@0 933
volker@28 934 # --- CALC with assumed true parameters from the input file
volker@28 935 IoutTp0, IoutTm0, IoutRp0, IoutRm0, It0, Ir0, dIoutTp0, dIoutTm0, dIoutRp0, dIoutRm0, dIt0, dIr0, \
volker@28 936 GT0, HT0, GR0, HR0, K0, Eta0, LDRsimx, LDRCorr, DTa0, DRa0, TTa0, TRa0, F11sim0, LDRunCorr = \
volker@28 937 Calc(TCalT, TCalR, NCalT, NCalR, DOLP0, RotL0, RotE0, RetE0, DiE0,
volker@28 938 RotO0, RetO0, DiO0, RotC0, RetC0, DiC0, TP0, TS0, RP0, RS0,
volker@28 939 ERaT0, RotaT0, RetT0, ERaR0, RotaR0, RetR0, LDRCal0)
volker@28 940 Etax0 = K0 * Eta0
volker@13 941 # --- Print parameters to console and output file
volker@28 942 with open('output_files\\' + LID + '-' + InputFile[0:-3] + '-GHK.dat', 'w') as f:
ulalume3@0 943 with redirect_stdout(f):
volker@28 944 print("From folder", dname)
volker@28 945 print("Running prog", fname)
volker@28 946 print("Version", ScriptVersion)
binietoglou@19 947 print("Reading input file ", InputFile) # , " for Lidar system :", EID, ", ", LID)
ulalume3@0 948 print("for Lidar system: ", EID, ", ", LID)
ulalume3@0 949 # --- Print iput information*********************************
ulalume3@0 950 print(" --- Input parameters: value ±error / ±steps ----------------------")
volker@28 951 print("{0:5}{1:5} {2:6.4f}±{3:7.4f}/{4:2d}; {5:8} {6:8.4f}±{7:7.4f}/{8:2d}".format(
volker@28 952 "Laser: ", "DOLP =", DOLP0, dDOLP, nDOLP," Rotation alpha = ", RotL0, dRotL, nRotL))
ulalume3@0 953 print(" Diatt., Tunpol, Retard., Rotation (deg)")
binietoglou@19 954 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(
binietoglou@19 955 "Emitter ", DiE0, dDiE, TiE, RetE0, dRetE, RotE0, dRotE, nDiE, nRetE, nRotE))
binietoglou@19 956 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(
binietoglou@19 957 "Receiver ", DiO0, dDiO, TiO, RetO0, dRetO, RotO0, dRotO, nDiO, nRetO, nRotO))
binietoglou@19 958 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(
binietoglou@19 959 "Calibrator ", DiC0, dDiC, TiC, RetC0, dRetC, RotC0, dRotC, nDiC, nRetC, nRotC))
ulalume3@0 960 print("{0:12}".format(" --- Pol.-filter ---"))
volker@28 961 print("{0:12}{1:7.4f}±{2:7.4f}/{3:2d}, {4:7.4f}±{5:7.4f}/{6:2d}".format(
volker@28 962 "ERT, RotT :", ERaT0, dERaT, nERaT, RotaT0, dRotaT, nRotaT))
volker@28 963 print("{0:12}{1:7.4f}±{2:7.4f}/{3:2d}, {4:7.4f}±{5:7.4f}/{6:2d}".format(
volker@28 964 "ERR, RotR :", ERaR0, dERaR, nERaR, RotaR0, dRotaR, nRotaR))
ulalume3@0 965 print("{0:12}".format(" --- PBS ---"))
volker@28 966 print("{0:12}{1:7.4f}±{2:7.4f}/{3:2d}, {4:7.4f}±{5:7.4f}/{6:2d}".format(
volker@28 967 "TP,TS :", TP0, dTP, nTP, TS0, dTS, nTS))
volker@28 968 print("{0:12}{1:7.4f}±{2:7.4f}/{3:2d}, {4:7.4f}±{5:7.4f}/{6:2d}".format(
volker@28 969 "RP,RS :", RP0, dRP, nRP, RS0, dRS, nRS))
volker@28 970 print("{0:12}{1:7.4f},{2:7.4f}, {3:7.4f},{4:7.4f}, {5:1.0f}".format(
volker@28 971 "DT,TT,DR,TR,Y :", DiT, TiT, DiR, TiR, Y))
ulalume3@0 972 print("{0:12}".format(" --- Combined PBS + Pol.-filter ---"))
volker@28 973 print("{0:12}{1:7.4f},{2:7.4f}, {3:7.4f},{4:7.4f}".format(
volker@28 974 "DT,TT,DR,TR :", DTa0, TTa0, DRa0, TRa0))
volker@28 975 print("{0:26}: {1:6.3f}± {2:5.3f}/{3:2d}".format(
volker@28 976 "LDRCal during calibration in calibration range", LDRCal0, dLDRCal, nLDRCal))
volker@28 977 print("{0:12}".format(" --- Additional ND filter attenuation (transmission) during the calibration ---"))
volker@28 978 print("{0:12}{1:7.4f}±{2:7.4f}/{3:2d}, {4:7.4f}±{5:7.4f}/{6:2d}".format(
volker@28 979 "TCalT,TCalR :", TCalT0, dTCalT, nTCalT, TCalR0, dTCalR, nTCalR))
ulalume3@0 980 print()
ulalume3@0 981 print("Rotation Error Epsilon For Normal Measurements = ", RotationErrorEpsilonForNormalMeasurements)
volker@13 982 print(Type[TypeC], Loc[LocC])
binietoglou@19 983 print("Parallel signal detected in", dY[int(Y + 1)])
volker@13 984 print("RS_RP_depend_on_TS_TP = ", RS_RP_depend_on_TS_TP)
ulalume3@0 985 # end of print actual system parameters
ulalume3@0 986 # ******************************************************************************
ulalume3@0 987
binietoglou@19 988 # print()
binietoglou@19 989 # print(" --- LDRCal during calibration | simulated and corrected LDRs -------------")
binietoglou@19 990 # print("{0:8} |{1:8}->{2:8},{3:9}->{4:9} |{5:8}->{6:8}".format(" LDRCal"," LDRtrue", " LDRsim"," LDRtrue2", " LDRsim2", " LDRmeas", " LDRcorr"))
binietoglou@19 991 # 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))
binietoglou@19 992 # print("{0:8} |{1:8}->{2:8}->{3:8}".format(" LDRCal"," LDRtrue", " LDRsimx", " LDRcorr"))
binietoglou@19 993 # 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))
binietoglou@19 994 # print("{0:8} |{1:8}->{2:8}->{3:8}".format(" LDRCal"," LDRtrue", " LDRsimx", " LDRcorr"))
binietoglou@19 995 # print(" --- LDRCal during calibration")
ulalume3@0 996
binietoglou@19 997 # print("{0:8}={1:8.5f};{2:8}={3:8.5f}".format(" IinP",IinP," F11sim",F11sim))
ulalume3@0 998 print()
ulalume3@0 999
volker@28 1000 K0List = np.zeros(6)
volker@28 1001 LDRsimxList = np.zeros(6)
volker@28 1002 LDRCalList = 0.004, 0.02, 0.1, 0.2, 0.3, 0.45
volker@21 1003 # The loop over LDRCalList is ony for checking whether and how much the LDR depends on the LDRCal during calibration and whether the corrections work.
volker@21 1004 # Still with assumed true parameters in input file
volker@28 1005
volker@28 1006 facIt = NCalT / TCalT0 * NILfac
volker@28 1007 facIr = NCalR / TCalR0 * NILfac
volker@28 1008 print("IoutTp, IoutTm, IoutRp, IoutRm, It , Ir , dIoutTp, dIoutTm, dIoutRp, dIoutRm, dIt, dIr")
volker@28 1009
binietoglou@19 1010 for i, LDRCal in enumerate(LDRCalList):
volker@28 1011 IoutTp, IoutTm, IoutRp, IoutRm, It, Ir, dIoutTp, dIoutTm, dIoutRp, dIoutRm, dIt, dIr, \
volker@28 1012 GT0, HT0, GR0, HR0, K0, Eta0, LDRsimx, LDRCorr, DTa0, DRa0, TTa0, TRa0, F11sim0, LDRunCorr = \
volker@28 1013 Calc(TCalT0, TCalR0, NCalT, NCalR, DOLP0, RotL0, RotE0, RetE0, DiE0,
volker@28 1014 RotO0, RetO0, DiO0, RotC0, RetC0, DiC0, TP0, TS0, RP0, RS0,
volker@28 1015 ERaT0, RotaT0, RetT0, ERaR0, RotaR0, RetR0, LDRCal)
ulalume3@0 1016 K0List[i] = K0
ulalume3@0 1017 LDRsimxList[i] = LDRsimx
ulalume3@0 1018
volker@28 1019 # check error signals
volker@28 1020 # print( "{:0.4f}, {:0.4f}, {:0.4f}, {:0.4f}, {:0.4f}, {:0.4f}, {:0.4f}, {:0.4f}, {:0.4f}, {:0.4f}, {:0.4f}, {:0.4f}"
volker@28 1021 # .format(IoutTp * NCalT, IoutTm * NCalT, IoutRp * NCalR, IoutRm * NCalR, It * facIt, Ir * facIr, dIoutTp, dIoutTm, dIoutRp, dIoutRm, dIt, dIr))
volker@28 1022 #print( "{:0.4f}, {:0.4f}, {:0.4f}, {:0.4f}, {:0.4f}, {:0.4f}, {:0.4f}, {:0.4f}, {:0.4f}, {:0.4f}, {:0.4f}, {:0.4f}".format(IoutTp, IoutTm, IoutRp, IoutRm, It, Ir, dIoutTp, dIoutTm, dIoutRp, dIoutRm, dIt, dIr))
volker@28 1023 # end check error signals
volker@28 1024 print('===========================================================================================================')
volker@28 1025 print("{0:8},{1:8},{2:8},{3:8},{4:9},{5:8},{6:9},{7:9},{8:9},{9:9}".format(
volker@28 1026 " GR", " GT", " HR", " HT", " K(0.004)", " K(0.02)", " K(0.1)", " K(0.2)", " K(0.3)", " K(0.45)"))
volker@28 1027 print("{0:8.5f},{1:8.5f},{2:8.5f},{3:8.5f},{4:9.5f},{5:9.5f},{6:9.5f},{7:9.5f},{8:9.5f},{9:9.5f}".format(
volker@28 1028 GR0, GT0, HR0, HT0, K0List[0], K0List[1], K0List[2], K0List[3], K0List[4], K0List[5]))
volker@28 1029 print('===========================================================================================================')
volker@28 1030 print()
volker@28 1031 print("Errors from neglecting GHK corrections and/or calibration:")
volker@28 1032 print("{0:>10},{1:>10},{2:>10},{3:>10},{4:>10},{5:>10}".format(
volker@28 1033 "LDRtrue", "LDRunCorr", "1/LDRunCorr", "LDRsimx", "1/LDRsimx", "LDRCorr"))
ulalume3@0 1034
volker@21 1035 #LDRtrueList = 0.004, 0.02, 0.2, 0.45
volker@21 1036 aF11sim0 = np.zeros(5)
volker@21 1037 LDRrange = np.zeros(5)
volker@28 1038 LDRrange = [0.004, 0.02, 0.1, 0.3, 0.45] # list
volker@21 1039
volker@28 1040 # The loop over LDRtrueList is only for checking how much the uncorrected LDRsimx deviates from LDRtrue ... and whether the corrections work.
volker@21 1041 # LDRsimx = LDRsim = Ir / It or 1/LDRsim
volker@21 1042 # Still with assumed true parameters in input file
volker@21 1043 for i, LDRtrue in enumerate(LDRrange):
volker@21 1044 #for LDRtrue in LDRrange:
volker@28 1045 IoutTp, IoutTm, IoutRp, IoutRm, It, Ir, dIoutTp, dIoutTm, dIoutRp, dIoutRm, dIt, dIr, \
volker@28 1046 GT0, HT0, GR0, HR0, K0, Eta0, LDRsimx, LDRCorr, DTa0, DRa0, TTa0, TRa0, F11sim0, LDRunCorr = \
volker@28 1047 Calc(TCalT0, TCalR0, NCalT, NCalR, DOLP0, RotL0, RotE0, RetE0, DiE0,
volker@28 1048 RotO0, RetO0, DiO0, RotC0, RetC0, DiC0, TP0, TS0, RP0, RS0,
volker@28 1049 ERaT0, RotaT0, RetT0, ERaR0, RotaR0, RetR0, LDRCal0)
volker@28 1050 print("{0:10.5f},{1:10.5f},{2:10.5f},{3:10.5f},{4:10.5f},{5:10.5f}".format(LDRtrue, LDRunCorr, 1/LDRunCorr, LDRsimx, 1/LDRsimx, LDRCorr))
volker@21 1051 aF11sim0[i] = F11sim0
volker@21 1052 # the assumed true aF11sim0 results will be used below to calc the deviation from the real signals
volker@28 1053 print("LDRsimx = LDR of the nominal system directly from measured signals without calibration and GHK-corrections")
volker@28 1054 print("LDRunCorr = LDR of the nominal system directly from measured signals with calibration but without GHK-corrections; electronic amplifications = 1 assumed")
volker@28 1055 print("LDRCorr = LDR calibrated and GHK-corrected")
volker@28 1056 print()
volker@28 1057 print("Errors from signal noise:")
volker@28 1058 print("Signal counts: NCalT, NCalR, NILfac, nNCal, nNI = {0:10.0f},{1:10.0f},{2:3.0f},{3:2.0f},{4:2.0f}".format(
volker@28 1059 NCalT, NCalR, NILfac, nNCal, nNI))
ulalume3@0 1060
volker@28 1061 '''# das muß wieder weg
volker@28 1062 print("IoutTp, IoutTm, IoutRp, IoutRm, It , Ir , dIoutTp, dIoutTm, dIoutRp, dIoutRm, dIt, dIr")
volker@28 1063 LDRCal = 0.01
volker@28 1064 for i, LDRtrue in enumerate(LDRrange):
volker@28 1065 IoutTp, IoutTm, IoutRp, IoutRm, It, Ir, dIoutTp, dIoutTm, dIoutRp, dIoutRm, dIt, dIr, \
volker@28 1066 GT0, HT0, GR0, HR0, K0, Eta0, LDRsimx, LDRCorr, DTa0, DRa0, TTa0, TRa0, F11sim0, LDRunCorr = \
volker@28 1067 Calc(TCalT0, TCalR0, NCalT, NCalR, DOLP0, RotL0, RotE0, RetE0, DiE0,
volker@28 1068 RotO0, RetO0, DiO0, RotC0, RetC0, DiC0, TP0, TS0, RP0, RS0,
volker@28 1069 ERaT0, RotaT0, RetT0, ERaR0, RotaR0, RetR0, LDRCal0)
volker@28 1070 print( "{:0.4f}, {:0.4f}, {:0.4f}, {:0.4f}, {:0.4f}, {:0.4f}, {:0.4f}, {:0.4f}, {:0.4f}, {:0.4f}, {:0.4f}, {:0.4f}".format(
volker@28 1071 IoutTp * NCalT, IoutTm * NCalT, IoutRp * NCalR, IoutRm * NCalR, It * facIt, Ir * facIr,
volker@28 1072 dIoutTp, dIoutTm, dIoutRp, dIoutRm, dIt, dIr))
volker@28 1073 aF11sim0[i] = F11sim0
volker@28 1074 # the assumed true aF11sim0 results will be used below to calc the deviation from the real signals
volker@28 1075 # bis hierher weg
volker@28 1076 '''
volker@28 1077
volker@28 1078 file = open('output_files\\' + LID + '-' + InputFile[0:-3] + '-GHK.dat', 'r')
binietoglou@19 1079 print(file.read())
ulalume3@0 1080 file.close()
ulalume3@0 1081
ulalume3@0 1082 '''
ulalume3@0 1083 if(PrintToOutputFile):
ulalume3@0 1084 f = open('output_ver7.dat', 'w')
ulalume3@0 1085 old_target = sys.stdout
ulalume3@0 1086 sys.stdout = f
ulalume3@0 1087
ulalume3@0 1088 print("something")
ulalume3@0 1089
ulalume3@0 1090 if(PrintToOutputFile):
ulalume3@0 1091 sys.stdout.flush()
ulalume3@0 1092 f.close
ulalume3@0 1093 sys.stdout = old_target
ulalume3@0 1094 '''
binietoglou@19 1095 if (Error_Calc):
volker@21 1096 # --- CALC again assumed truth with LDRCal0 and with assumed true parameters in input file to reset all 0-values
volker@28 1097 IoutTp0, IoutTm0, IoutRp0, IoutRm0, It0, Ir0, dIoutTp0, dIoutTm0, dIoutRp0, dIoutRm0, dIt0, dIr0, \
volker@28 1098 GT0, HT0, GR0, HR0, K0, Eta0, LDRsimx, LDRCorr, DTa0, DRa0, TTa0, TRa0, F11sim0, LDRunCorr = \
volker@28 1099 Calc(TCalT0, TCalR0, NCalT, NCalR, DOLP0, RotL0, RotE0, RetE0, DiE0,
volker@28 1100 RotO0, RetO0, DiO0, RotC0, RetC0, DiC0, TP0, TS0, RP0, RS0,
volker@28 1101 ERaT0, RotaT0, RetT0, ERaR0, RotaR0, RetR0, LDRCal0)
volker@28 1102 Etax0 = K0 * Eta0
volker@28 1103 # --- Start Error calculation with variable parameters ------------------------------------------------------------------
volker@28 1104 # error nNCal: one-sigma in steps to left and right for calibration signals
volker@28 1105 # error nNI: one-sigma in steps to left and right for 0° signals
ulalume3@0 1106
volker@16 1107 iN = -1
volker@28 1108 N = ((nTCalT * 2 + 1) * (nTCalR * 2 + 1) *
volker@28 1109 (nNCal * 2 + 1) ** 4 * (nNI * 2 + 1) ** 2 *
volker@28 1110 (nDOLP * 2 + 1) * (nRotL * 2 + 1) *
binietoglou@19 1111 (nRotE * 2 + 1) * (nRetE * 2 + 1) * (nDiE * 2 + 1) *
binietoglou@19 1112 (nRotO * 2 + 1) * (nRetO * 2 + 1) * (nDiO * 2 + 1) *
binietoglou@19 1113 (nRotC * 2 + 1) * (nRetC * 2 + 1) * (nDiC * 2 + 1) *
binietoglou@19 1114 (nTP * 2 + 1) * (nTS * 2 + 1) * (nRP * 2 + 1) * (nRS * 2 + 1) * (nERaT * 2 + 1) * (nERaR * 2 + 1) *
binietoglou@19 1115 (nRotaT * 2 + 1) * (nRotaR * 2 + 1) * (nRetT * 2 + 1) * (nRetR * 2 + 1) * (nLDRCal * 2 + 1))
volker@28 1116 print("number of system variations N = ", N, " ", end="")
ulalume3@0 1117
volker@16 1118 if N > 1e6:
binietoglou@19 1119 if user_yes_no_query('Warning: processing ' + str(
binietoglou@19 1120 N) + ' samples will take very long. Do you want to proceed?') == 0: sys.exit()
volker@16 1121 if N > 5e6:
binietoglou@19 1122 if user_yes_no_query('Warning: the memory required for ' + str(N) + ' samples might be ' + '{0:5.1f}'.format(
binietoglou@19 1123 N / 4e6) + ' GB. Do you anyway want to proceed?') == 0: sys.exit()
ulalume3@0 1124
binietoglou@19 1125 # if user_yes_no_query('Warning: processing' + str(N) + ' samples will take very long. Do you want to proceed?') == 0: sys.exit()
ulalume3@0 1126
volker@16 1127 # --- Arrays for plotting ------
volker@16 1128 LDRmin = np.zeros(5)
volker@16 1129 LDRmax = np.zeros(5)
volker@16 1130 F11min = np.zeros(5)
volker@16 1131 F11max = np.zeros(5)
volker@28 1132 Etaxmin = np.zeros(5)
volker@28 1133 Etaxmax = np.zeros(5)
ulalume3@0 1134
volker@28 1135 # LDRrange = np.zeros(5)
volker@28 1136 # LDRrange = 0.004, 0.02, 0.1, 0.3, 0.45
binietoglou@19 1137 # aLDRsimx = np.zeros(N)
binietoglou@19 1138 # aLDRsimx2 = np.zeros(N)
binietoglou@19 1139 # aLDRcorr = np.zeros(N)
binietoglou@19 1140 # aLDRcorr2 = np.zeros(N)
volker@23 1141 aDOLP = np.zeros(N)
volker@16 1142 aERaT = np.zeros(N)
volker@16 1143 aERaR = np.zeros(N)
volker@16 1144 aRotaT = np.zeros(N)
volker@16 1145 aRotaR = np.zeros(N)
volker@16 1146 aRetT = np.zeros(N)
volker@16 1147 aRetR = np.zeros(N)
volker@16 1148 aTP = np.zeros(N)
volker@16 1149 aTS = np.zeros(N)
volker@16 1150 aRP = np.zeros(N)
volker@16 1151 aRS = np.zeros(N)
volker@16 1152 aDiE = np.zeros(N)
volker@16 1153 aDiO = np.zeros(N)
volker@16 1154 aDiC = np.zeros(N)
volker@16 1155 aRotC = np.zeros(N)
volker@16 1156 aRetC = np.zeros(N)
volker@16 1157 aRotL = np.zeros(N)
volker@16 1158 aRetE = np.zeros(N)
volker@16 1159 aRotE = np.zeros(N)
volker@16 1160 aRetO = np.zeros(N)
volker@16 1161 aRotO = np.zeros(N)
volker@16 1162 aLDRCal = np.zeros(N)
volker@28 1163 aNCalTp = np.zeros(N)
volker@28 1164 aNCalTm = np.zeros(N)
volker@28 1165 aNCalRp = np.zeros(N)
volker@28 1166 aNCalRm = np.zeros(N)
volker@28 1167 aNIt = np.zeros(N)
volker@28 1168 aNIr = np.zeros(N)
volker@28 1169 aTCalT = np.zeros(N)
volker@28 1170 aTCalR = np.zeros(N)
volker@28 1171
volker@28 1172 # each np.zeros((LDRrange, N)) array has the same N-dependency
volker@28 1173 aLDRcorr = np.zeros((5, N))
binietoglou@19 1174 aF11corr = np.zeros((5, N))
volker@28 1175 aPLDR = np.zeros((5, N))
volker@28 1176 aEtax = np.zeros((5, N))
volker@28 1177
volker@28 1178 # np.zeros((GHKs, N))
volker@28 1179 aGHK = np.zeros((5, N))
ulalume3@0 1180
volker@16 1181 atime = clock()
volker@16 1182 dtime = clock()
ulalume3@0 1183
volker@16 1184 # --- Calc Error signals
volker@16 1185 # ---- Do the calculations of bra-ket vectors
volker@16 1186 h = -1. if TypeC == 2 else 1
ulalume3@0 1187
volker@21 1188 '''
volker@16 1189 # from input file: measured LDRm and true LDRtrue, LDRtrue2 =>
binietoglou@19 1190 ameas = (1. - LDRmeas) / (1 + LDRmeas)
binietoglou@19 1191 atrue = (1. - LDRtrue) / (1 + LDRtrue)
binietoglou@19 1192 atrue2 = (1. - LDRtrue2) / (1 + LDRtrue2)
volker@21 1193 '''
ulalume3@0 1194
binietoglou@19 1195 for iLDRCal in range(-nLDRCal, nLDRCal + 1):
volker@28 1196 # from input file: LDRCal for calibration measurements
volker@16 1197 LDRCal = LDRCal0
volker@28 1198 if nLDRCal > 0:
volker@28 1199 LDRCal = LDRCal0 + iLDRCal * dLDRCal / nLDRCal
volker@28 1200 # provides the intensities of the calibration measurements at various LDRCal for signal noise errors
volker@28 1201 # IoutTp, IoutTm, IoutRp, IoutRm, dIoutTp, dIoutTm, dIoutRp, dIoutRm
volker@28 1202 '''
volker@28 1203 IoutTp, IoutTm, IoutRp, IoutRm, It, Ir, dIoutTp, dIoutTm, dIoutRp, dIoutRm, dIt, dIr, \
volker@28 1204 GT, HT, GR, HR, K, Eta, LDRsimx, LDRCorr, DTa, DRa, TTa, TRa, F11sim, LDRunCorr = \
volker@28 1205 Calc(TCalT, TCalR, NCalT, NCalR, DOLP0, RotL0, RotE0, RetE0, DiE0,
volker@28 1206 RotO0, RetO0, DiO0, RotC0, RetC0, DiC0, TP0, TS0, RP0, RS0,
volker@28 1207 ERaT0, RotaT0, RetT0, ERaR0, RotaR0, RetR0, LDRCal)
volker@28 1208 '''
binietoglou@19 1209 aCal = (1. - LDRCal) / (1 + LDRCal)
volker@23 1210 for iDOLP, iRotL, iRotE, iRetE, iDiE \
volker@23 1211 in [(iDOLP, iRotL, iRotE, iRetE, iDiE)
volker@23 1212 for iDOLP in range(-nDOLP, nDOLP + 1)
binietoglou@19 1213 for iRotL in range(-nRotL, nRotL + 1)
binietoglou@19 1214 for iRotE in range(-nRotE, nRotE + 1)
binietoglou@19 1215 for iRetE in range(-nRetE, nRetE + 1)
binietoglou@19 1216 for iDiE in range(-nDiE, nDiE + 1)]:
ulalume3@0 1217
volker@23 1218 if nDOLP > 0: DOLP = DOLP0 + iDOLP * dDOLP / nDOLP
binietoglou@19 1219 if nRotL > 0: RotL = RotL0 + iRotL * dRotL / nRotL
binietoglou@19 1220 if nRotE > 0: RotE = RotE0 + iRotE * dRotE / nRotE
binietoglou@19 1221 if nRetE > 0: RetE = RetE0 + iRetE * dRetE / nRetE
binietoglou@19 1222 if nDiE > 0: DiE = DiE0 + iDiE * dDiE / nDiE
ulalume3@0 1223
volker@16 1224 # angles of emitter and laser and calibrator and receiver optics
volker@16 1225 # RotL = alpha, RotE = beta, RotO = gamma, RotC = epsilon
binietoglou@19 1226 S2a = np.sin(2 * np.deg2rad(RotL))
binietoglou@19 1227 C2a = np.cos(2 * np.deg2rad(RotL))
binietoglou@19 1228 S2b = np.sin(2 * np.deg2rad(RotE))
binietoglou@19 1229 C2b = np.cos(2 * np.deg2rad(RotE))
binietoglou@19 1230 S2ab = np.sin(np.deg2rad(2 * RotL - 2 * RotE))
binietoglou@19 1231 C2ab = np.cos(np.deg2rad(2 * RotL - 2 * RotE))
ulalume3@0 1232
volker@23 1233 # Laser with Degree of linear polarization DOLP
volker@16 1234 IinL = 1.
volker@23 1235 QinL = DOLP
volker@16 1236 UinL = 0.
volker@23 1237 VinL = (1. - DOLP ** 2) ** 0.5
ulalume3@0 1238
volker@16 1239 # Stokes Input Vector rotation Eq. E.4
binietoglou@19 1240 A = C2a * QinL - S2a * UinL
binietoglou@19 1241 B = S2a * QinL + C2a * UinL
volker@16 1242 # Stokes Input Vector rotation Eq. E.9
binietoglou@19 1243 C = C2ab * QinL - S2ab * UinL
binietoglou@19 1244 D = S2ab * QinL + C2ab * UinL
ulalume3@0 1245
volker@16 1246 # emitter optics
volker@16 1247 CosE = np.cos(np.deg2rad(RetE))
volker@16 1248 SinE = np.sin(np.deg2rad(RetE))
binietoglou@19 1249 ZiE = (1. - DiE ** 2) ** 0.5
binietoglou@19 1250 WiE = (1. - ZiE * CosE)
ulalume3@0 1251
volker@16 1252 # Stokes Input Vector after emitter optics equivalent to Eq. E.9 with already rotated input vector from Eq. E.4
volker@16 1253 # b = beta
binietoglou@19 1254 IinE = (IinL + DiE * C)
binietoglou@19 1255 QinE = (C2b * DiE * IinL + A + S2b * (WiE * D - ZiE * SinE * VinL))
binietoglou@19 1256 UinE = (S2b * DiE * IinL + B - C2b * (WiE * D - ZiE * SinE * VinL))
binietoglou@19 1257 VinE = (-ZiE * SinE * D + ZiE * CosE * VinL)
ulalume3@0 1258
binietoglou@19 1259 # -------------------------
volker@16 1260 # F11 assuemd to be = 1 => measured: F11m = IinP / IinE with atrue
binietoglou@19 1261 # F11sim = (IinE + DiO*atrue*(C2g*QinE - S2g*UinE))/IinE
binietoglou@19 1262 # -------------------------
ulalume3@0 1263
volker@16 1264 for iRotO, iRetO, iDiO, iRotC, iRetC, iDiC, iTP, iTS, iRP, iRS, iERaT, iRotaT, iRetT, iERaR, iRotaR, iRetR \
binietoglou@19 1265 in [
binietoglou@19 1266 (iRotO, iRetO, iDiO, iRotC, iRetC, iDiC, iTP, iTS, iRP, iRS, iERaT, iRotaT, iRetT, iERaR, iRotaR, iRetR)
binietoglou@19 1267 for iRotO in range(-nRotO, nRotO + 1)
binietoglou@19 1268 for iRetO in range(-nRetO, nRetO + 1)
binietoglou@19 1269 for iDiO in range(-nDiO, nDiO + 1)
binietoglou@19 1270 for iRotC in range(-nRotC, nRotC + 1)
binietoglou@19 1271 for iRetC in range(-nRetC, nRetC + 1)
binietoglou@19 1272 for iDiC in range(-nDiC, nDiC + 1)
binietoglou@19 1273 for iTP in range(-nTP, nTP + 1)
binietoglou@19 1274 for iTS in range(-nTS, nTS + 1)
binietoglou@19 1275 for iRP in range(-nRP, nRP + 1)
binietoglou@19 1276 for iRS in range(-nRS, nRS + 1)
binietoglou@19 1277 for iERaT in range(-nERaT, nERaT + 1)
binietoglou@19 1278 for iRotaT in range(-nRotaT, nRotaT + 1)
binietoglou@19 1279 for iRetT in range(-nRetT, nRetT + 1)
binietoglou@19 1280 for iERaR in range(-nERaR, nERaR + 1)
binietoglou@19 1281 for iRotaR in range(-nRotaR, nRotaR + 1)
binietoglou@19 1282 for iRetR in range(-nRetR, nRetR + 1)]:
ulalume3@0 1283
binietoglou@19 1284 if nRotO > 0: RotO = RotO0 + iRotO * dRotO / nRotO
binietoglou@19 1285 if nRetO > 0: RetO = RetO0 + iRetO * dRetO / nRetO
binietoglou@19 1286 if nDiO > 0: DiO = DiO0 + iDiO * dDiO / nDiO
binietoglou@19 1287 if nRotC > 0: RotC = RotC0 + iRotC * dRotC / nRotC
binietoglou@19 1288 if nRetC > 0: RetC = RetC0 + iRetC * dRetC / nRetC
binietoglou@19 1289 if nDiC > 0: DiC = DiC0 + iDiC * dDiC / nDiC
binietoglou@19 1290 if nTP > 0: TP = TP0 + iTP * dTP / nTP
binietoglou@19 1291 if nTS > 0: TS = TS0 + iTS * dTS / nTS
binietoglou@19 1292 if nRP > 0: RP = RP0 + iRP * dRP / nRP
binietoglou@19 1293 if nRS > 0: RS = RS0 + iRS * dRS / nRS
binietoglou@19 1294 if nERaT > 0: ERaT = ERaT0 + iERaT * dERaT / nERaT
binietoglou@19 1295 if nRotaT > 0: RotaT = RotaT0 + iRotaT * dRotaT / nRotaT
binietoglou@19 1296 if nRetT > 0: RetT = RetT0 + iRetT * dRetT / nRetT
binietoglou@19 1297 if nERaR > 0: ERaR = ERaR0 + iERaR * dERaR / nERaR
binietoglou@19 1298 if nRotaR > 0: RotaR = RotaR0 + iRotaR * dRotaR / nRotaR
binietoglou@19 1299 if nRetR > 0: RetR = RetR0 + iRetR * dRetR / nRetR
ulalume3@0 1300
binietoglou@19 1301 # print("{0:5.2f}, {1:5.2f}, {2:5.2f}, {3:10d}".format(RotL, RotE, RotO, iN))
ulalume3@0 1302
volker@16 1303 # receiver optics
volker@16 1304 CosO = np.cos(np.deg2rad(RetO))
volker@16 1305 SinO = np.sin(np.deg2rad(RetO))
binietoglou@19 1306 ZiO = (1. - DiO ** 2) ** 0.5
binietoglou@19 1307 WiO = (1. - ZiO * CosO)
binietoglou@19 1308 S2g = np.sin(np.deg2rad(2 * RotO))
binietoglou@19 1309 C2g = np.cos(np.deg2rad(2 * RotO))
volker@16 1310 # calibrator
volker@16 1311 CosC = np.cos(np.deg2rad(RetC))
volker@16 1312 SinC = np.sin(np.deg2rad(RetC))
binietoglou@19 1313 ZiC = (1. - DiC ** 2) ** 0.5
binietoglou@19 1314 WiC = (1. - ZiC * CosC)
ulalume3@0 1315
volker@16 1316 # analyser
binietoglou@19 1317 # For POLLY_XTs
binietoglou@19 1318 if (RS_RP_depend_on_TS_TP):
volker@16 1319 RS = 1 - TS
volker@16 1320 RP = 1 - TP
volker@16 1321 TiT = 0.5 * (TP + TS)
binietoglou@19 1322 DiT = (TP - TS) / (TP + TS)
binietoglou@19 1323 ZiT = (1. - DiT ** 2) ** 0.5
volker@16 1324 TiR = 0.5 * (RP + RS)
binietoglou@19 1325 DiR = (RP - RS) / (RP + RS)
binietoglou@19 1326 ZiR = (1. - DiR ** 2) ** 0.5
volker@16 1327 CosT = np.cos(np.deg2rad(RetT))
volker@16 1328 SinT = np.sin(np.deg2rad(RetT))
volker@16 1329 CosR = np.cos(np.deg2rad(RetR))
volker@16 1330 SinR = np.sin(np.deg2rad(RetR))
ulalume3@0 1331
volker@28 1332 # cleaning pol-filter
binietoglou@19 1333 DaT = (1 - ERaT) / (1 + ERaT)
binietoglou@19 1334 DaR = (1 - ERaR) / (1 + ERaR)
binietoglou@19 1335 TaT = 0.5 * (1 + ERaT)
binietoglou@19 1336 TaR = 0.5 * (1 + ERaR)
ulalume3@0 1337
binietoglou@19 1338 S2aT = np.sin(np.deg2rad(h * 2 * RotaT))
binietoglou@19 1339 C2aT = np.cos(np.deg2rad(2 * RotaT))
binietoglou@19 1340 S2aR = np.sin(np.deg2rad(h * 2 * RotaR))
binietoglou@19 1341 C2aR = np.cos(np.deg2rad(2 * RotaR))
ulalume3@0 1342
volker@28 1343 # Analyzer As before the PBS Eq. D.5; combined PBS and cleaning pol-filter
volker@28 1344 ATPT = (1 + C2aT * DaT * DiT) # unpolarized transmission correction
volker@28 1345 TTa = TiT * TaT * ATPT # unpolarized transmission
volker@28 1346 ATP1 = 1
volker@28 1347 ATP2 = Y * (DiT + C2aT * DaT) / ATPT
volker@28 1348 ATP3 = Y * S2aT * DaT * ZiT * CosT / ATPT
volker@28 1349 ATP4 = S2aT * DaT * ZiT * SinT / ATPT
binietoglou@19 1350 ATP = np.array([ATP1, ATP2, ATP3, ATP4])
volker@28 1351 DTa = ATP2 * Y
ulalume3@0 1352
volker@28 1353 ARPT = (1 + C2aR * DaR * DiR) # unpolarized transmission correction
volker@28 1354 TRa = TiR * TaR * ARPT # unpolarized transmission
volker@28 1355 ARP1 = 1
volker@28 1356 ARP2 = Y * (DiR + C2aR * DaR) / ARPT
volker@28 1357 ARP3 = Y * S2aR * DaR * ZiR * CosR / ARPT
volker@28 1358 ARP4 = S2aR * DaR * ZiR * SinR / ARPT
binietoglou@19 1359 ARP = np.array([ARP1, ARP2, ARP3, ARP4])
volker@28 1360 DRa = ARP2 * Y
ulalume3@0 1361
volker@16 1362 # ---- Calculate signals and correction parameters for diffeent locations and calibrators
volker@16 1363 if LocC == 4: # Calibrator before the PBS
binietoglou@19 1364 # print("Calibrator location not implemented yet")
ulalume3@0 1365
binietoglou@19 1366 # S2ge = np.sin(np.deg2rad(2*RotO + h*2*RotC))
binietoglou@19 1367 # C2ge = np.cos(np.deg2rad(2*RotO + h*2*RotC))
binietoglou@19 1368 S2e = np.sin(np.deg2rad(h * 2 * RotC))
binietoglou@19 1369 C2e = np.cos(np.deg2rad(2 * RotC))
volker@16 1370 # rotated AinP by epsilon Eq. C.3
binietoglou@19 1371 ATP2e = C2e * ATP2 + S2e * ATP3
binietoglou@19 1372 ATP3e = C2e * ATP3 - S2e * ATP2
binietoglou@19 1373 ARP2e = C2e * ARP2 + S2e * ARP3
binietoglou@19 1374 ARP3e = C2e * ARP3 - S2e * ARP2
binietoglou@19 1375 ATPe = np.array([ATP1, ATP2e, ATP3e, ATP4])
binietoglou@19 1376 ARPe = np.array([ARP1, ARP2e, ARP3e, ARP4])
volker@16 1377 # Stokes Input Vector before the polarising beam splitter Eq. E.31
binietoglou@19 1378 A = C2g * QinE - S2g * UinE
binietoglou@19 1379 B = S2g * QinE + C2g * UinE
binietoglou@19 1380 # C = (WiO*aCal*B + ZiO*SinO*(1-2*aCal)*VinE)
binietoglou@19 1381 Co = ZiO * SinO * VinE
binietoglou@19 1382 Ca = (WiO * B - 2 * ZiO * SinO * VinE)
binietoglou@19 1383 # C = Co + aCal*Ca
binietoglou@19 1384 # IinP = (IinE + DiO*aCal*A)
binietoglou@19 1385 # QinP = (C2g*DiO*IinE + aCal*QinE - S2g*C)
binietoglou@19 1386 # UinP = (S2g*DiO*IinE - aCal*UinE + C2g*C)
binietoglou@19 1387 # VinP = (ZiO*SinO*aCal*B + ZiO*CosO*(1-2*aCal)*VinE)
volker@16 1388 IinPo = IinE
binietoglou@19 1389 QinPo = (C2g * DiO * IinE - S2g * Co)
binietoglou@19 1390 UinPo = (S2g * DiO * IinE + C2g * Co)
binietoglou@19 1391 VinPo = ZiO * CosO * VinE
ulalume3@0 1392
binietoglou@19 1393 IinPa = DiO * A
binietoglou@19 1394 QinPa = QinE - S2g * Ca
binietoglou@19 1395 UinPa = -UinE + C2g * Ca
binietoglou@19 1396 VinPa = ZiO * (SinO * B - 2 * CosO * VinE)
ulalume3@0 1397
binietoglou@19 1398 IinP = IinPo + aCal * IinPa
binietoglou@19 1399 QinP = QinPo + aCal * QinPa
binietoglou@19 1400 UinP = UinPo + aCal * UinPa
binietoglou@19 1401 VinP = VinPo + aCal * VinPa
volker@16 1402 # Stokes Input Vector before the polarising beam splitter rotated by epsilon Eq. C.3
binietoglou@19 1403 # QinPe = C2e*QinP + S2e*UinP
binietoglou@19 1404 # UinPe = C2e*UinP - S2e*QinP
binietoglou@19 1405 QinPoe = C2e * QinPo + S2e * UinPo
binietoglou@19 1406 UinPoe = C2e * UinPo - S2e * QinPo
binietoglou@19 1407 QinPae = C2e * QinPa + S2e * UinPa
binietoglou@19 1408 UinPae = C2e * UinPa - S2e * QinPa
binietoglou@19 1409 QinPe = C2e * QinP + S2e * UinP
binietoglou@19 1410 UinPe = C2e * UinP - S2e * QinP
ulalume3@0 1411
volker@16 1412 # Calibration signals and Calibration correction K from measurements with LDRCal / aCal
volker@16 1413 if (TypeC == 2) or (TypeC == 1): # rotator calibration Eq. C.4
volker@16 1414 # parameters for calibration with aCal
binietoglou@19 1415 AT = ATP1 * IinP + h * ATP4 * VinP
binietoglou@19 1416 BT = ATP3e * QinP - h * ATP2e * UinP
binietoglou@19 1417 AR = ARP1 * IinP + h * ARP4 * VinP
binietoglou@19 1418 BR = ARP3e * QinP - h * ARP2e * UinP
volker@23 1419 # Correction parameters for normal measurements; they are independent of LDR
binietoglou@19 1420 if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out
binietoglou@19 1421 IS1 = np.array([IinPo, QinPo, UinPo, VinPo])
binietoglou@19 1422 IS2 = np.array([IinPa, QinPa, UinPa, VinPa])
binietoglou@19 1423 GT = np.dot(ATP, IS1)
binietoglou@19 1424 GR = np.dot(ARP, IS1)
binietoglou@19 1425 HT = np.dot(ATP, IS2)
binietoglou@19 1426 HR = np.dot(ARP, IS2)
volker@16 1427 else:
binietoglou@19 1428 IS1 = np.array([IinPo, QinPo, UinPo, VinPo])
binietoglou@19 1429 IS2 = np.array([IinPa, QinPa, UinPa, VinPa])
binietoglou@19 1430 GT = np.dot(ATPe, IS1)
binietoglou@19 1431 GR = np.dot(ARPe, IS1)
binietoglou@19 1432 HT = np.dot(ATPe, IS2)
binietoglou@19 1433 HR = np.dot(ARPe, IS2)
volker@16 1434 elif (TypeC == 3) or (TypeC == 4): # linear polariser calibration Eq. C.5
volker@16 1435 # parameters for calibration with aCal
binietoglou@19 1436 AT = ATP1 * IinP + ATP3e * UinPe + ZiC * CosC * (ATP2e * QinPe + ATP4 * VinP)
binietoglou@19 1437 BT = DiC * (ATP1 * UinPe + ATP3e * IinP) - ZiC * SinC * (ATP2e * VinP - ATP4 * QinPe)
binietoglou@19 1438 AR = ARP1 * IinP + ARP3e * UinPe + ZiC * CosC * (ARP2e * QinPe + ARP4 * VinP)
binietoglou@19 1439 BR = DiC * (ARP1 * UinPe + ARP3e * IinP) - ZiC * SinC * (ARP2e * VinP - ARP4 * QinPe)
volker@23 1440 # Correction parameters for normal measurements; they are independent of LDR
binietoglou@19 1441 if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out
binietoglou@19 1442 IS1 = np.array([IinPo, QinPo, UinPo, VinPo])
binietoglou@19 1443 IS2 = np.array([IinPa, QinPa, UinPa, VinPa])
binietoglou@19 1444 GT = np.dot(ATP, IS1)
binietoglou@19 1445 GR = np.dot(ARP, IS1)
binietoglou@19 1446 HT = np.dot(ATP, IS2)
binietoglou@19 1447 HR = np.dot(ARP, IS2)
volker@16 1448 else:
binietoglou@19 1449 IS1e = np.array(
binietoglou@19 1450 [IinPo + DiC * QinPoe, DiC * IinPo + QinPoe, ZiC * (CosC * UinPoe + SinC * VinPo),
binietoglou@19 1451 -ZiC * (SinC * UinPoe - CosC * VinPo)])
binietoglou@19 1452 IS2e = np.array(
binietoglou@19 1453 [IinPa + DiC * QinPae, DiC * IinPa + QinPae, ZiC * (CosC * UinPae + SinC * VinPa),
binietoglou@19 1454 -ZiC * (SinC * UinPae - CosC * VinPa)])
binietoglou@19 1455 GT = np.dot(ATPe, IS1e)
binietoglou@19 1456 GR = np.dot(ARPe, IS1e)
binietoglou@19 1457 HT = np.dot(ATPe, IS2e)
binietoglou@19 1458 HR = np.dot(ARPe, IS2e)
volker@16 1459 elif (TypeC == 6): # diattenuator calibration +-22.5° rotated_diattenuator_X22x5deg.odt
volker@16 1460 # parameters for calibration with aCal
binietoglou@19 1461 AT = ATP1 * IinP + sqr05 * DiC * (ATP1 * QinPe + ATP2e * IinP) + (1 - 0.5 * WiC) * (
binietoglou@19 1462 ATP2e * QinPe + ATP3e * UinPe) + ZiC * (
binietoglou@19 1463 sqr05 * SinC * (ATP3e * VinP - ATP4 * UinPe) + ATP4 * CosC * VinP)
binietoglou@19 1464 BT = sqr05 * DiC * (ATP1 * UinPe + ATP3e * IinP) + 0.5 * WiC * (
binietoglou@19 1465 ATP2e * UinPe + ATP3e * QinPe) - sqr05 * ZiC * SinC * (ATP2e * VinP - ATP4 * QinPe)
binietoglou@19 1466 AR = ARP1 * IinP + sqr05 * DiC * (ARP1 * QinPe + ARP2e * IinP) + (1 - 0.5 * WiC) * (
binietoglou@19 1467 ARP2e * QinPe + ARP3e * UinPe) + ZiC * (
binietoglou@19 1468 sqr05 * SinC * (ARP3e * VinP - ARP4 * UinPe) + ARP4 * CosC * VinP)
binietoglou@19 1469 BR = sqr05 * DiC * (ARP1 * UinPe + ARP3e * IinP) + 0.5 * WiC * (
binietoglou@19 1470 ARP2e * UinPe + ARP3e * QinPe) - sqr05 * ZiC * SinC * (ARP2e * VinP - ARP4 * QinPe)
volker@23 1471 # Correction parameters for normal measurements; they are independent of LDR
binietoglou@19 1472 if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out
binietoglou@19 1473 IS1 = np.array([IinPo, QinPo, UinPo, VinPo])
binietoglou@19 1474 IS2 = np.array([IinPa, QinPa, UinPa, VinPa])
binietoglou@19 1475 GT = np.dot(ATP, IS1)
binietoglou@19 1476 GR = np.dot(ARP, IS1)
binietoglou@19 1477 HT = np.dot(ATP, IS2)
binietoglou@19 1478 HR = np.dot(ARP, IS2)
volker@16 1479 else:
binietoglou@19 1480 IS1e = np.array(
binietoglou@19 1481 [IinPo + DiC * QinPoe, DiC * IinPo + QinPoe, ZiC * (CosC * UinPoe + SinC * VinPo),
binietoglou@19 1482 -ZiC * (SinC * UinPoe - CosC * VinPo)])
binietoglou@19 1483 IS2e = np.array(
binietoglou@19 1484 [IinPa + DiC * QinPae, DiC * IinPa + QinPae, ZiC * (CosC * UinPae + SinC * VinPa),
binietoglou@19 1485 -ZiC * (SinC * UinPae - CosC * VinPa)])
binietoglou@19 1486 GT = np.dot(ATPe, IS1e)
binietoglou@19 1487 GR = np.dot(ARPe, IS1e)
binietoglou@19 1488 HT = np.dot(ATPe, IS2e)
binietoglou@19 1489 HR = np.dot(ARPe, IS2e)
ulalume3@0 1490 else:
volker@16 1491 print("Calibrator not implemented yet")
volker@16 1492 sys.exit()
volker@16 1493
volker@16 1494 elif LocC == 3: # C before receiver optics Eq.57
ulalume3@0 1495
binietoglou@19 1496 # S2ge = np.sin(np.deg2rad(2*RotO - 2*RotC))
binietoglou@19 1497 # C2ge = np.cos(np.deg2rad(2*RotO - 2*RotC))
binietoglou@19 1498 S2e = np.sin(np.deg2rad(2 * RotC))
binietoglou@19 1499 C2e = np.cos(np.deg2rad(2 * RotC))
ulalume3@0 1500
volker@16 1501 # AS with C before the receiver optics (see document rotated_diattenuator_X22x5deg.odt)
binietoglou@19 1502 AF1 = np.array([1, C2g * DiO, S2g * DiO, 0])
binietoglou@19 1503 AF2 = np.array([C2g * DiO, 1 - S2g ** 2 * WiO, S2g * C2g * WiO, -S2g * ZiO * SinO])
binietoglou@19 1504 AF3 = np.array([S2g * DiO, S2g * C2g * WiO, 1 - C2g ** 2 * WiO, C2g * ZiO * SinO])
binietoglou@19 1505 AF4 = np.array([0, S2g * SinO, -C2g * SinO, CosO])
ulalume3@0 1506
binietoglou@19 1507 ATF = (ATP1 * AF1 + ATP2 * AF2 + ATP3 * AF3 + ATP4 * AF4)
binietoglou@19 1508 ARF = (ARP1 * AF1 + ARP2 * AF2 + ARP3 * AF3 + ARP4 * AF4)
volker@16 1509 ATF1 = ATF[0]
volker@16 1510 ATF2 = ATF[1]
volker@16 1511 ATF3 = ATF[2]
volker@16 1512 ATF4 = ATF[3]
volker@16 1513 ARF1 = ARF[0]
volker@16 1514 ARF2 = ARF[1]
volker@16 1515 ARF3 = ARF[2]
volker@16 1516 ARF4 = ARF[3]
ulalume3@0 1517
volker@16 1518 # rotated AinF by epsilon
binietoglou@19 1519 ATF2e = C2e * ATF[1] + S2e * ATF[2]
binietoglou@19 1520 ATF3e = C2e * ATF[2] - S2e * ATF[1]
binietoglou@19 1521 ARF2e = C2e * ARF[1] + S2e * ARF[2]
binietoglou@19 1522 ARF3e = C2e * ARF[2] - S2e * ARF[1]
ulalume3@0 1523
binietoglou@19 1524 ATFe = np.array([ATF1, ATF2e, ATF3e, ATF4])
binietoglou@19 1525 ARFe = np.array([ARF1, ARF2e, ARF3e, ARF4])
ulalume3@0 1526
binietoglou@19 1527 QinEe = C2e * QinE + S2e * UinE
binietoglou@19 1528 UinEe = C2e * UinE - S2e * QinE
ulalume3@0 1529
volker@16 1530 # Stokes Input Vector before receiver optics Eq. E.19 (after atmosphere F)
volker@16 1531 IinF = IinE
binietoglou@19 1532 QinF = aCal * QinE
binietoglou@19 1533 UinF = -aCal * UinE
binietoglou@19 1534 VinF = (1. - 2. * aCal) * VinE
ulalume3@0 1535
volker@16 1536 IinFo = IinE
volker@16 1537 QinFo = 0.
volker@16 1538 UinFo = 0.
volker@16 1539 VinFo = VinE
ulalume3@0 1540
volker@16 1541 IinFa = 0.
volker@16 1542 QinFa = QinE
volker@16 1543 UinFa = -UinE
binietoglou@19 1544 VinFa = -2. * VinE
ulalume3@0 1545
volker@16 1546 # Stokes Input Vector before receiver optics rotated by epsilon Eq. C.3
binietoglou@19 1547 QinFe = C2e * QinF + S2e * UinF
binietoglou@19 1548 UinFe = C2e * UinF - S2e * QinF
binietoglou@19 1549 QinFoe = C2e * QinFo + S2e * UinFo
binietoglou@19 1550 UinFoe = C2e * UinFo - S2e * QinFo
binietoglou@19 1551 QinFae = C2e * QinFa + S2e * UinFa
binietoglou@19 1552 UinFae = C2e * UinFa - S2e * QinFa
ulalume3@0 1553
volker@16 1554 # Calibration signals and Calibration correction K from measurements with LDRCal / aCal
binietoglou@19 1555 if (TypeC == 2) or (TypeC == 1): # rotator calibration Eq. C.4
binietoglou@19 1556 AT = ATF1 * IinF + ATF4 * h * VinF
binietoglou@19 1557 BT = ATF3e * QinF - ATF2e * h * UinF
binietoglou@19 1558 AR = ARF1 * IinF + ARF4 * h * VinF
binietoglou@19 1559 BR = ARF3e * QinF - ARF2e * h * UinF
ulalume3@0 1560
volker@23 1561 # Correction parameters for normal measurements; they are independent of LDR
volker@16 1562 if (not RotationErrorEpsilonForNormalMeasurements):
binietoglou@19 1563 GT = ATF1 * IinE + ATF4 * VinE
binietoglou@19 1564 GR = ARF1 * IinE + ARF4 * VinE
binietoglou@19 1565 HT = ATF2 * QinE - ATF3 * UinE - ATF4 * 2 * VinE
binietoglou@19 1566 HR = ARF2 * QinE - ARF3 * UinE - ARF4 * 2 * VinE
volker@16 1567 else:
binietoglou@19 1568 GT = ATF1 * IinE + ATF4 * h * VinE
binietoglou@19 1569 GR = ARF1 * IinE + ARF4 * h * VinE
binietoglou@19 1570 HT = ATF2e * QinE - ATF3e * h * UinE - ATF4 * h * 2 * VinE
binietoglou@19 1571 HR = ARF2e * QinE - ARF3e * h * UinE - ARF4 * h * 2 * VinE
ulalume3@0 1572
volker@16 1573 elif (TypeC == 3) or (TypeC == 4): # linear polariser calibration Eq. C.5
volker@16 1574 # p = +45°, m = -45°
binietoglou@19 1575 IF1e = np.array([IinF, ZiC * CosC * QinFe, UinFe, ZiC * CosC * VinF])
binietoglou@19 1576 IF2e = np.array([DiC * UinFe, -ZiC * SinC * VinF, DiC * IinF, ZiC * SinC * QinFe])
ulalume3@0 1577
binietoglou@19 1578 AT = np.dot(ATFe, IF1e)
binietoglou@19 1579 AR = np.dot(ARFe, IF1e)
binietoglou@19 1580 BT = np.dot(ATFe, IF2e)
binietoglou@19 1581 BR = np.dot(ARFe, IF2e)
ulalume3@0 1582
volker@23 1583 # Correction parameters for normal measurements; they are independent of LDR --- the same as for TypeC = 6
binietoglou@19 1584 if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out
binietoglou@19 1585 IS1 = np.array([IinE, 0, 0, VinE])
binietoglou@19 1586 IS2 = np.array([0, QinE, -UinE, -2 * VinE])
ulalume3@0 1587
binietoglou@19 1588 GT = np.dot(ATF, IS1)
binietoglou@19 1589 GR = np.dot(ARF, IS1)
binietoglou@19 1590 HT = np.dot(ATF, IS2)
binietoglou@19 1591 HR = np.dot(ARF, IS2)
volker@16 1592 else:
binietoglou@19 1593 IS1e = np.array(
binietoglou@19 1594 [IinFo + DiC * QinFoe, DiC * IinFo + QinFoe, ZiC * (CosC * UinFoe + SinC * VinFo),
binietoglou@19 1595 -ZiC * (SinC * UinFoe - CosC * VinFo)])
binietoglou@19 1596 IS2e = np.array(
binietoglou@19 1597 [IinFa + DiC * QinFae, DiC * IinFa + QinFae, ZiC * (CosC * UinFae + SinC * VinFa),
binietoglou@19 1598 -ZiC * (SinC * UinFae - CosC * VinFa)])
binietoglou@19 1599 GT = np.dot(ATFe, IS1e)
binietoglou@19 1600 GR = np.dot(ARFe, IS1e)
binietoglou@19 1601 HT = np.dot(ATFe, IS2e)
binietoglou@19 1602 HR = np.dot(ARFe, IS2e)
ulalume3@0 1603
volker@16 1604 elif (TypeC == 6): # diattenuator calibration +-22.5° rotated_diattenuator_X22x5deg.odt
volker@16 1605 # p = +22.5°, m = -22.5°
binietoglou@19 1606 IF1e = np.array([IinF + sqr05 * DiC * QinFe, sqr05 * DiC * IinF + (1 - 0.5 * WiC) * QinFe,
binietoglou@19 1607 (1 - 0.5 * WiC) * UinFe + sqr05 * ZiC * SinC * VinF,
binietoglou@19 1608 -sqr05 * ZiC * SinC * UinFe + ZiC * CosC * VinF])
binietoglou@19 1609 IF2e = np.array([sqr05 * DiC * UinFe, 0.5 * WiC * UinFe - sqr05 * ZiC * SinC * VinF,
binietoglou@19 1610 sqr05 * DiC * IinF + 0.5 * WiC * QinFe, sqr05 * ZiC * SinC * QinFe])
ulalume3@0 1611
binietoglou@19 1612 AT = np.dot(ATFe, IF1e)
binietoglou@19 1613 AR = np.dot(ARFe, IF1e)
binietoglou@19 1614 BT = np.dot(ATFe, IF2e)
binietoglou@19 1615 BR = np.dot(ARFe, IF2e)
ulalume3@0 1616
volker@23 1617 # Correction parameters for normal measurements; they are independent of LDR
binietoglou@19 1618 if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out
binietoglou@19 1619 # IS1 = np.array([IinE,0,0,VinE])
binietoglou@19 1620 # IS2 = np.array([0,QinE,-UinE,-2*VinE])
binietoglou@19 1621 IS1 = np.array([IinFo, 0, 0, VinFo])
binietoglou@19 1622 IS2 = np.array([0, QinFa, UinFa, VinFa])
binietoglou@19 1623 GT = np.dot(ATF, IS1)
binietoglou@19 1624 GR = np.dot(ARF, IS1)
binietoglou@19 1625 HT = np.dot(ATF, IS2)
binietoglou@19 1626 HR = np.dot(ARF, IS2)
volker@16 1627 else:
binietoglou@19 1628 # IS1e = np.array([IinE,DiC*IinE,ZiC*SinC*VinE,ZiC*CosC*VinE])
binietoglou@19 1629 # IS2e = np.array([DiC*QinEe,QinEe,-ZiC*(CosC*UinEe+2*SinC*VinE),ZiC*(SinC*UinEe-2*CosC*VinE)])
binietoglou@19 1630 IS1e = np.array(
binietoglou@19 1631 [IinFo + DiC * QinFoe, DiC * IinFo + QinFoe, ZiC * (CosC * UinFoe + SinC * VinFo),
binietoglou@19 1632 -ZiC * (SinC * UinFoe - CosC * VinFo)])
binietoglou@19 1633 IS2e = np.array(
binietoglou@19 1634 [IinFa + DiC * QinFae, DiC * IinFa + QinFae, ZiC * (CosC * UinFae + SinC * VinFa),
binietoglou@19 1635 -ZiC * (SinC * UinFae - CosC * VinFa)])
binietoglou@19 1636 GT = np.dot(ATFe, IS1e)
binietoglou@19 1637 GR = np.dot(ARFe, IS1e)
binietoglou@19 1638 HT = np.dot(ATFe, IS2e)
binietoglou@19 1639 HR = np.dot(ARFe, IS2e)
ulalume3@0 1640
ulalume3@0 1641
volker@16 1642 else:
volker@16 1643 print('Calibrator not implemented yet')
volker@16 1644 sys.exit()
ulalume3@0 1645
volker@16 1646 elif LocC == 2: # C behind emitter optics Eq.57
binietoglou@19 1647 # print("Calibrator location not implemented yet")
binietoglou@19 1648 S2e = np.sin(np.deg2rad(2 * RotC))
binietoglou@19 1649 C2e = np.cos(np.deg2rad(2 * RotC))
ulalume3@0 1650
volker@16 1651 # AS with C before the receiver optics (see document rotated_diattenuator_X22x5deg.odt)
binietoglou@19 1652 AF1 = np.array([1, C2g * DiO, S2g * DiO, 0])
binietoglou@19 1653 AF2 = np.array([C2g * DiO, 1 - S2g ** 2 * WiO, S2g * C2g * WiO, -S2g * ZiO * SinO])
binietoglou@19 1654 AF3 = np.array([S2g * DiO, S2g * C2g * WiO, 1 - C2g ** 2 * WiO, C2g * ZiO * SinO])
binietoglou@19 1655 AF4 = np.array([0, S2g * SinO, -C2g * SinO, CosO])
ulalume3@0 1656
binietoglou@19 1657 ATF = (ATP1 * AF1 + ATP2 * AF2 + ATP3 * AF3 + ATP4 * AF4)
binietoglou@19 1658 ARF = (ARP1 * AF1 + ARP2 * AF2 + ARP3 * AF3 + ARP4 * AF4)
volker@16 1659 ATF1 = ATF[0]
volker@16 1660 ATF2 = ATF[1]
volker@16 1661 ATF3 = ATF[2]
volker@16 1662 ATF4 = ATF[3]
volker@16 1663 ARF1 = ARF[0]
volker@16 1664 ARF2 = ARF[1]
volker@16 1665 ARF3 = ARF[2]
volker@16 1666 ARF4 = ARF[3]
ulalume3@0 1667
volker@16 1668 # AS with C behind the emitter --------------------------------------------
volker@16 1669 # terms without aCal
volker@16 1670 ATE1o, ARE1o = ATF1, ARF1
volker@16 1671 ATE2o, ARE2o = 0., 0.
volker@16 1672 ATE3o, ARE3o = 0., 0.
volker@16 1673 ATE4o, ARE4o = ATF4, ARF4
volker@16 1674 # terms with aCal
binietoglou@19 1675 ATE1a, ARE1a = 0., 0.
volker@16 1676 ATE2a, ARE2a = ATF2, ARF2
volker@16 1677 ATE3a, ARE3a = -ATF3, -ARF3
binietoglou@19 1678 ATE4a, ARE4a = -2 * ATF4, -2 * ARF4
volker@16 1679 # rotated AinEa by epsilon
binietoglou@19 1680 ATE2ae = C2e * ATF2 + S2e * ATF3
binietoglou@19 1681 ATE3ae = -S2e * ATF2 - C2e * ATF3
binietoglou@19 1682 ARE2ae = C2e * ARF2 + S2e * ARF3
binietoglou@19 1683 ARE3ae = -S2e * ARF2 - C2e * ARF3
volker@16 1684
volker@16 1685 ATE1 = ATE1o
binietoglou@19 1686 ATE2e = aCal * ATE2ae
binietoglou@19 1687 ATE3e = aCal * ATE3ae
binietoglou@19 1688 ATE4 = (1 - 2 * aCal) * ATF4
volker@16 1689 ARE1 = ARE1o
binietoglou@19 1690 ARE2e = aCal * ARE2ae
binietoglou@19 1691 ARE3e = aCal * ARE3ae
binietoglou@19 1692 ARE4 = (1 - 2 * aCal) * ARF4
ulalume3@0 1693
volker@16 1694 # rotated IinE
binietoglou@19 1695 QinEe = C2e * QinE + S2e * UinE
binietoglou@19 1696 UinEe = C2e * UinE - S2e * QinE
volker@16 1697
volker@16 1698 # --- Calibration signals and Calibration correction K from measurements with LDRCal / aCal
binietoglou@19 1699 if (TypeC == 2) or (TypeC == 1): # +++++++++ rotator calibration Eq. C.4
binietoglou@19 1700 AT = ATE1o * IinE + (ATE4o + aCal * ATE4a) * h * VinE
binietoglou@19 1701 BT = aCal * (ATE3ae * QinEe - ATE2ae * h * UinEe)
binietoglou@19 1702 AR = ARE1o * IinE + (ARE4o + aCal * ARE4a) * h * VinE
binietoglou@19 1703 BR = aCal * (ARE3ae * QinEe - ARE2ae * h * UinEe)
ulalume3@0 1704
volker@23 1705 # Correction parameters for normal measurements; they are independent of LDR
volker@16 1706 if (not RotationErrorEpsilonForNormalMeasurements):
volker@16 1707 # Stokes Input Vector before receiver optics Eq. E.19 (after atmosphere F)
binietoglou@19 1708 GT = ATE1o * IinE + ATE4o * h * VinE
binietoglou@19 1709 GR = ARE1o * IinE + ARE4o * h * VinE
binietoglou@19 1710 HT = ATE2a * QinE + ATE3a * h * UinEe + ATE4a * h * VinE
binietoglou@19 1711 HR = ARE2a * QinE + ARE3a * h * UinEe + ARE4a * h * VinE
volker@16 1712 else:
binietoglou@19 1713 GT = ATE1o * IinE + ATE4o * h * VinE
binietoglou@19 1714 GR = ARE1o * IinE + ARE4o * h * VinE
binietoglou@19 1715 HT = ATE2ae * QinE + ATE3ae * h * UinEe + ATE4a * h * VinE
binietoglou@19 1716 HR = ARE2ae * QinE + ARE3ae * h * UinEe + ARE4a * h * VinE
volker@16 1717
volker@16 1718 elif (TypeC == 3) or (TypeC == 4): # +++++++++ linear polariser calibration Eq. C.5
volker@16 1719 # p = +45°, m = -45°
binietoglou@19 1720 AT = ATE1 * IinE + ZiC * CosC * (ATE2e * QinEe + ATE4 * VinE) + ATE3e * UinEe
binietoglou@19 1721 BT = DiC * (ATE1 * UinEe + ATE3e * IinE) + ZiC * SinC * (ATE4 * QinEe - ATE2e * VinE)
binietoglou@19 1722 AR = ARE1 * IinE + ZiC * CosC * (ARE2e * QinEe + ARE4 * VinE) + ARE3e * UinEe
binietoglou@19 1723 BR = DiC * (ARE1 * UinEe + ARE3e * IinE) + ZiC * SinC * (ARE4 * QinEe - ARE2e * VinE)
ulalume3@0 1724
volker@23 1725 # Correction parameters for normal measurements; they are independent of LDR
volker@16 1726 if (not RotationErrorEpsilonForNormalMeasurements):
volker@16 1727 # Stokes Input Vector before receiver optics Eq. E.19 (after atmosphere F)
binietoglou@19 1728 GT = ATE1o * IinE + ATE4o * VinE
binietoglou@19 1729 GR = ARE1o * IinE + ARE4o * VinE
binietoglou@19 1730 HT = ATE2a * QinE + ATE3a * UinE + ATE4a * VinE
binietoglou@19 1731 HR = ARE2a * QinE + ARE3a * UinE + ARE4a * VinE
volker@16 1732 else:
binietoglou@19 1733 D = IinE + DiC * QinEe
binietoglou@19 1734 A = DiC * IinE + QinEe
binietoglou@19 1735 B = ZiC * (CosC * UinEe + SinC * VinE)
binietoglou@19 1736 C = -ZiC * (SinC * UinEe - CosC * VinE)
binietoglou@19 1737 GT = ATE1o * D + ATE4o * C
binietoglou@19 1738 GR = ARE1o * D + ARE4o * C
binietoglou@19 1739 HT = ATE2a * A + ATE3a * B + ATE4a * C
binietoglou@19 1740 HR = ARE2a * A + ARE3a * B + ARE4a * C
ulalume3@0 1741
volker@16 1742 elif (TypeC == 6): # real HWP calibration +-22.5° rotated_diattenuator_X22x5deg.odt
volker@16 1743 # p = +22.5°, m = -22.5°
binietoglou@19 1744 IE1e = np.array([IinE + sqr05 * DiC * QinEe, sqr05 * DiC * IinE + (1 - 0.5 * WiC) * QinEe,
binietoglou@19 1745 (1 - 0.5 * WiC) * UinEe + sqr05 * ZiC * SinC * VinE,
binietoglou@19 1746 -sqr05 * ZiC * SinC * UinEe + ZiC * CosC * VinE])
binietoglou@19 1747 IE2e = np.array([sqr05 * DiC * UinEe, 0.5 * WiC * UinEe - sqr05 * ZiC * SinC * VinE,
binietoglou@19 1748 sqr05 * DiC * IinE + 0.5 * WiC * QinEe, sqr05 * ZiC * SinC * QinEe])
binietoglou@19 1749 ATEe = np.array([ATE1, ATE2e, ATE3e, ATE4])
binietoglou@19 1750 AREe = np.array([ARE1, ARE2e, ARE3e, ARE4])
binietoglou@19 1751 AT = np.dot(ATEe, IE1e)
binietoglou@19 1752 AR = np.dot(AREe, IE1e)
binietoglou@19 1753 BT = np.dot(ATEe, IE2e)
binietoglou@19 1754 BR = np.dot(AREe, IE2e)
ulalume3@0 1755
volker@23 1756 # Correction parameters for normal measurements; they are independent of LDR
binietoglou@19 1757 if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out
binietoglou@19 1758 GT = ATE1o * IinE + ATE4o * VinE
binietoglou@19 1759 GR = ARE1o * IinE + ARE4o * VinE
binietoglou@19 1760 HT = ATE2a * QinE + ATE3a * UinE + ATE4a * VinE
binietoglou@19 1761 HR = ARE2a * QinE + ARE3a * UinE + ARE4a * VinE
volker@16 1762 else:
binietoglou@19 1763 D = IinE + DiC * QinEe
binietoglou@19 1764 A = DiC * IinE + QinEe
binietoglou@19 1765 B = ZiC * (CosC * UinEe + SinC * VinE)
binietoglou@19 1766 C = -ZiC * (SinC * UinEe - CosC * VinE)
binietoglou@19 1767 GT = ATE1o * D + ATE4o * C
binietoglou@19 1768 GR = ARE1o * D + ARE4o * C
binietoglou@19 1769 HT = ATE2a * A + ATE3a * B + ATE4a * C
binietoglou@19 1770 HR = ARE2a * A + ARE3a * B + ARE4a * C
ulalume3@0 1771 else:
volker@16 1772 print('Calibrator not implemented yet')
volker@16 1773 sys.exit()
ulalume3@0 1774
volker@28 1775 for iTCalT, iTCalR, iNCalTp, iNCalTm, iNCalRp, iNCalRm, iNIt, iNIr \
volker@28 1776 in [
volker@28 1777 (iTCalT, iTCalR, iNCalTp, iNCalTm, iNCalRp, iNCalRm, iNIt, iNIr)
volker@28 1778 for iTCalT in range(-nTCalT, nTCalT + 1) # Etax
volker@28 1779 for iTCalR in range(-nTCalR, nTCalR + 1) # Etax
volker@28 1780 for iNCalTp in range(-nNCal, nNCal + 1) # noise error of calibration signals => Etax
volker@28 1781 for iNCalTm in range(-nNCal, nNCal + 1) # noise error of calibration signals => Etax
volker@28 1782 for iNCalRp in range(-nNCal, nNCal + 1) # noise error of calibration signals => Etax
volker@28 1783 for iNCalRm in range(-nNCal, nNCal + 1) # noise error of calibration signals => Etax
volker@28 1784 for iNIt in range(-nNI, nNI + 1)
volker@28 1785 for iNIr in range(-nNI, nNI + 1)]:
ulalume3@0 1786
volker@28 1787 # Calibration signals with aCal => Determination of the correction K of the real calibration factor
volker@28 1788 IoutTp = TTa * TiC * TiO * TiE * (AT + BT)
volker@28 1789 IoutTm = TTa * TiC * TiO * TiE * (AT - BT)
volker@28 1790 IoutRp = TRa * TiC * TiO * TiE * (AR + BR)
volker@28 1791 IoutRm = TRa * TiC * TiO * TiE * (AR - BR)
volker@16 1792
volker@28 1793 if nTCalT > 0: TCalT = TCalT0 + iTCalT * dTCalT / nTCalT
volker@28 1794 if nTCalR > 0: TCalR = TCalR0 + iTCalR * dTCalR / nTCalR
volker@28 1795 # signal noise errors
volker@28 1796 # ----- random error calculation ----------
volker@28 1797 # noise must be calculated from/with the actually measured signals; influence of TCalT, TCalR errors on nouse are not considered ?
volker@28 1798 # actually measured signals are in input file and don't change
volker@28 1799 # relative standard deviation of calibration signals with LDRcal; assumed to be statisitcally independent
volker@28 1800 # error nNCal: one-sigma in steps to left and right for calibration signals
volker@28 1801 if nNCal > 0:
volker@28 1802 if (CalcFrom0deg):
volker@28 1803 dIoutTp = (NCalT * IoutTp) ** -0.5
volker@28 1804 dIoutTm = (NCalT * IoutTm) ** -0.5
volker@28 1805 dIoutRp = (NCalR * IoutRp) ** -0.5
volker@28 1806 dIoutRm = (NCalR * IoutRm) ** -0.5
volker@28 1807 else:
volker@28 1808 dIoutTp = dIoutTp0 * (IoutTp / IoutTp0)
volker@28 1809 dIoutTm = dIoutTm0 * (IoutTm / IoutTm0)
volker@28 1810 dIoutRp = dIoutRp0 * (IoutRp / IoutRp0)
volker@28 1811 dIoutRm = dIoutRm0 * (IoutRm / IoutRm0)
volker@28 1812 # print(iTCalT, iTCalR, iNCalTp, iNCalTm, iNCalRp, iNCalRm, iNIt, iNIr, IoutTp, dIoutTp)
volker@28 1813 IoutTp = IoutTp * (1 + iNCalTp * dIoutTp / nNCal)
volker@28 1814 IoutTm = IoutTm * (1 + iNCalTm * dIoutTm / nNCal)
volker@28 1815 IoutRp = IoutRp * (1 + iNCalRp * dIoutRp / nNCal)
volker@28 1816 IoutRm = IoutRm * (1 + iNCalRm * dIoutRm / nNCal)
volker@16 1817
volker@28 1818 IoutTp = IoutTp * TCalT / TCalT0
volker@28 1819 IoutTm = IoutTm * TCalT / TCalT0
volker@28 1820 IoutRp = IoutRp * TCalR / TCalR0
volker@28 1821 IoutRm = IoutRm * TCalR / TCalR0
volker@28 1822 # --- Results and Corrections; electronic etaR and etaT are assumed to be 1 for true and assumed true systems
volker@28 1823 # calibration factor
volker@28 1824 Eta = (TRa / TTa) # = TRa / TTa; Eta = Eta*/K Eq. 84; corrected according to the papers supplement Eqs. (S.10.10.1) ff
volker@28 1825 # possibly real calibration factor
volker@28 1826 Etapx = IoutRp / IoutTp
volker@28 1827 Etamx = IoutRm / IoutTm
volker@28 1828 Etax = (Etapx * Etamx) ** 0.5
volker@28 1829 K = Etax / Eta
volker@28 1830 # 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@28 1831 # print("{0:6.3f},{1:6.3f},{2:6.3f},{3:6.3f}".format(DiC, ZiC, Kp, Km))
volker@28 1832
volker@28 1833 # For comparison with Volkers Libreoffice Müller Matrix spreadsheet
volker@28 1834 # Eta_test_p = (IoutRp/IoutTp)
volker@28 1835 # Eta_test_m = (IoutRm/IoutTm)
volker@28 1836 # Eta_test = (Eta_test_p*Eta_test_m)**0.5
volker@16 1837 '''
volker@28 1838 for iIt, iIr \
volker@28 1839 in [(iIt, iIr)
volker@28 1840 for iIt in range(-nNI, nNI + 1)
volker@28 1841 for iIr in range(-nNI, nNI + 1)]:
volker@21 1842 '''
volker@28 1843
volker@28 1844 iN = iN + 1
volker@28 1845 if (iN == 10001):
volker@28 1846 ctime = clock()
volker@28 1847 print(" estimated time ", "{0:4.2f}".format(N / 10000 * (ctime - atime)), "sec ") # , end="")
volker@28 1848 print("\r elapsed time ", "{0:5.0f}".format((ctime - atime)), "sec ", end="\r")
volker@28 1849 ctime = clock()
volker@28 1850 if ((ctime - dtime) > 10):
volker@28 1851 print("\r elapsed time ", "{0:5.0f}".format((ctime - atime)), "sec ", end="\r")
volker@28 1852 dtime = ctime
ulalume3@0 1853
volker@28 1854 # *** loop for different real LDRs **********************************************************************
volker@28 1855 iLDR = -1
volker@28 1856 for LDRTrue in LDRrange:
volker@28 1857 iLDR = iLDR + 1
volker@28 1858 atrue = (1 - LDRTrue) / (1 + LDRTrue)
volker@28 1859 # ----- Forward simulated signals and LDRsim with atrue; from input file; not considering TiC.
volker@28 1860 It = TTa * TiO * TiE * (GT + atrue * HT) # TaT*TiT*TiC*TiO*IinL*(GT+atrue*HT)
volker@28 1861 Ir = TRa * TiO * TiE * (GR + atrue * HR) # TaR*TiR*TiC*TiO*IinL*(GR+atrue*HR)
volker@28 1862 # # signal noise errors; standard deviation of signals; assumed to be statisitcally independent
volker@28 1863 # because the signals depend on LDRtrue, the errors dIt and dIr must be calculated for each LDRtrue
volker@28 1864 if (CalcFrom0deg):
volker@28 1865 dIt = ((NCalT * It / IoutTp * NILfac / TCalT) ** -0.5)
volker@28 1866 dIr = ((NCalR * Ir / IoutRp * NILfac / TCalR) ** -0.5)
volker@28 1867 else:
volker@28 1868 dIt = ((NCalT * 2 * NILfac / TCalT ) ** -0.5) * It
volker@28 1869 dIr = ((NCalR * 2 * NILfac / TCalR) ** -0.5) * Ir
volker@28 1870 # error nNI: one-sigma in steps to left and right for 0° signals
volker@28 1871 if nNI > 0:
volker@28 1872 It = It * (1 + iNIt * dIt / nNI)
volker@28 1873 Ir = Ir * (1 + iNIr * dIr / nNI)
volker@16 1874
volker@28 1875 # LDRsim = 1/Eta*Ir/It # simulated LDR* with Y from input file
volker@28 1876 LDRsim = Ir / It # simulated uncorrected LDR with Y from input file
volker@16 1877
volker@28 1878 # ----- Backward correction
volker@28 1879 # Corrected LDRCorr with assumed true G0,H0,K0,Eta0 from forward simulated (real) LDRsim(atrue)
volker@28 1880 LDRCorr = (LDRsim / (Etax / K0) * (GT0 + HT0) - (GR0 + HR0)) / ((GR0 - HR0) - LDRsim / (Etax / K0) * (GT0 - HT0))
volker@28 1881
volker@28 1882 # The following is a test whether the equations for calibration Etax and normal signal (GHK, LDRsim) are consistent
volker@28 1883 # LDRCorr = (LDRsim / Eta * (GT + HT) - (GR + HR)) / ((GR - HR) - LDRsim / Eta * (GT - HT))
volker@28 1884 # Without any correction
volker@28 1885 LDRunCorr = (LDRsim / Etax * (GT / abs(GT) + HT / abs(HT)) - (GR / abs(GR) + HR / abs(HR))) / ((GR / abs(GR) - HR / abs(HR)) - LDRsim / Etax * (GT / abs(GT) - HT / abs(HT)))
volker@28 1886
ulalume3@0 1887
volker@28 1888 '''
volker@28 1889 # -- F11corr from It and Ir and calibration EtaX
volker@28 1890 Text1 = "!!! EXPERIMENTAL !!! F11corr from It and Ir with calibration EtaX: x-axis: F11corr(LDRtrue) / F11corr(LDRtrue = 0.004) - 1"
volker@28 1891 F11corr = 1 / (TiO * TiE) * (
volker@28 1892 (HR0 * Etax / K0 * It / TTa - HT0 * Ir / TRa) / (HR0 * GT0 - HT0 * GR0)) # IL = 1 Eq.(64); Etax/K0 = Eta0.
volker@28 1893 '''
volker@28 1894 # Corrected F11corr with assumed true G0,H0,K0 from forward simulated (real) It and Ir (atrue)
volker@28 1895 Text1 = "!!! EXPERIMENTAL !!! F11corr from real It and Ir with real calibration EtaX: x-axis: F11corr(LDRtrue) / aF11sim0(LDRtrue) - 1"
volker@28 1896 F11corr = 1 / (TiO * TiE) * (
volker@28 1897 (HR0 * Etax / K0 * It / TTa - HT0 * Ir / TRa) / (HR0 * GT0 - HT0 * GR0)) # IL = 1 Eq.(64); Etax/K0 = Eta0.
volker@28 1898
volker@28 1899 # Text1 = "F11corr from It and Ir without corrections but with calibration EtaX: x-axis: F11corr(LDRtrue) devided by F11corr(LDRtrue = 0.004)"
volker@28 1900 # F11corr = 0.5/(TiO*TiE)*(Etax*It/TTa+Ir/TRa) # IL = 1 Eq.(64)
volker@16 1901
volker@28 1902 # -- It from It only with atrue without corrections - for BERTHA (and PollyXTs)
volker@28 1903 # Text1 = " x-axis: IT(LDRtrue) / IT(LDRtrue = 0.004) - 1"
volker@28 1904 # F11corr = It/(TaT*TiT*TiO*TiE) #/(TaT*TiT*TiO*TiE*(GT0+atrue*HT0))
volker@28 1905 # ! see below line 1673ff
volker@28 1906
volker@28 1907 aF11corr[iLDR, iN] = F11corr
volker@28 1908 aLDRcorr[iLDR, iN] = LDRCorr # LDRCorr # LDRsim # for test only
volker@28 1909 # aPLDR[iLDR, iN] = CalcPLDR(LDRCorr, BSR[iLDR], LDRm0)
volker@28 1910 aEtax[iLDR, iN] = Etax
volker@28 1911
volker@28 1912 aGHK[0, iN] = GR
volker@28 1913 aGHK[1, iN] = GT
volker@28 1914 aGHK[2, iN] = HR
volker@28 1915 aGHK[3, iN] = HT
volker@28 1916 aGHK[4, iN] = K
volker@16 1917
volker@28 1918 aLDRCal[iN] = iLDRCal
volker@28 1919 aDOLP[iN] = iDOLP
volker@28 1920 aERaT[iN] = iERaT
volker@28 1921 aERaR[iN] = iERaR
volker@28 1922 aRotaT[iN] = iRotaT
volker@28 1923 aRotaR[iN] = iRotaR
volker@28 1924 aRetT[iN] = iRetT
volker@28 1925 aRetR[iN] = iRetR
volker@28 1926
volker@28 1927 aRotL[iN] = iRotL
volker@28 1928 aRotE[iN] = iRotE
volker@28 1929 aRetE[iN] = iRetE
volker@28 1930 aRotO[iN] = iRotO
volker@28 1931 aRetO[iN] = iRetO
volker@28 1932 aRotC[iN] = iRotC
volker@28 1933 aRetC[iN] = iRetC
volker@28 1934 aDiO[iN] = iDiO
volker@28 1935 aDiE[iN] = iDiE
volker@28 1936 aDiC[iN] = iDiC
volker@28 1937 aTP[iN] = iTP
volker@28 1938 aTS[iN] = iTS
volker@28 1939 aRP[iN] = iRP
volker@28 1940 aRS[iN] = iRS
volker@28 1941 aTCalT[iN] = iTCalT
volker@28 1942 aTCalR[iN] = iTCalR
volker@28 1943
volker@28 1944 aNCalTp[iN] = iNCalTp # IoutTp, IoutTm, IoutRp, IoutRm => Etax
volker@28 1945 aNCalTm[iN] = iNCalTm # IoutTp, IoutTm, IoutRp, IoutRm => Etax
volker@28 1946 aNCalRp[iN] = iNCalRp # IoutTp, IoutTm, IoutRp, IoutRm => Etax
volker@28 1947 aNCalRm[iN] = iNCalRm # IoutTp, IoutTm, IoutRp, IoutRm => Etax
volker@28 1948 aNIt[iN] = iNIt # It, Tr
volker@28 1949 aNIr[iN] = iNIr # It, Tr
ulalume3@0 1950
volker@16 1951 # --- END loop
volker@16 1952 btime = clock()
volker@28 1953 # print("\r done in ", "{0:5.0f}".format(btime - atime), "sec. => producing plots now .... some more seconds ..."), # , end="\r");
volker@28 1954 print(" done in ", "{0:5.0f}".format(btime - atime), "sec. => producing plots now .... some more seconds ...")
volker@16 1955 # --- Plot -----------------------------------------------------------------
volker@28 1956 print("Errors from GHK correction uncertainties:")
volker@16 1957 if (sns_loaded):
volker@16 1958 sns.set_style("whitegrid")
volker@28 1959 sns.set_palette("bright6", 6)
volker@28 1960 # for older seaborn versions:
volker@28 1961 # sns.set_palette("bright", 6)
ulalume3@0 1962
volker@16 1963 '''
volker@16 1964 fig2 = plt.figure()
volker@28 1965 plt.plot(aLDRcorr[2,:],'b.')
volker@28 1966 plt.plot(aLDRcorr[3,:],'r.')
volker@28 1967 plt.plot(aLDRcorr[4,:],'g.')
volker@28 1968 #plt.plot(aLDRcorr[6,:],'c.')
volker@16 1969 plt.show
volker@16 1970 '''
binietoglou@19 1971
volker@16 1972 # Plot LDR
volker@16 1973 def PlotSubHist(aVar, aX, X0, daX, iaX, naX):
volker@28 1974 # aVar is the name of the parameter and aX is the subset of aLDRcorr which is coloured in the plot
volker@28 1975 # example: PlotSubHist("DOLP", aDOLP, DOLP0, dDOLP, iDOLP, nDOLP)
volker@16 1976 fig, ax = plt.subplots(nrows=1, ncols=5, sharex=True, sharey=True, figsize=(25, 2))
volker@16 1977 iLDR = -1
volker@16 1978 for LDRTrue in LDRrange:
volker@16 1979 iLDR = iLDR + 1
volker@28 1980 LDRmin[iLDR] = np.amin(aLDRcorr[iLDR, :])
volker@28 1981 LDRmax[iLDR] = np.amax(aLDRcorr[iLDR, :])
volker@28 1982 Rmin = LDRmin[iLDR] * 0.995 # np.min(aLDRcorr[iLDR,:]) * 0.995
volker@28 1983 Rmax = LDRmax[iLDR] * 1.005 # np.max(aLDRcorr[iLDR,:]) * 1.005
volker@16 1984
binietoglou@19 1985 # plt.subplot(5,2,iLDR+1)
binietoglou@19 1986 plt.subplot(1, 5, iLDR + 1)
volker@28 1987 (n, bins, patches) = plt.hist(aLDRcorr[iLDR, :],
binietoglou@19 1988 bins=100, log=False,
binietoglou@19 1989 range=[Rmin, Rmax],
volker@28 1990 alpha=0.5, density=False, color='0.5', histtype='stepfilled')
ulalume3@0 1991
binietoglou@19 1992 for iaX in range(-naX, naX + 1):
volker@28 1993 plt.hist(aLDRcorr[iLDR, aX == iaX],
volker@16 1994 range=[Rmin, Rmax],
volker@28 1995 bins=100, log=False, alpha=0.3, density=False, histtype='stepfilled',
binietoglou@19 1996 label=str(round(X0 + iaX * daX / naX, 5)))
volker@16 1997
volker@28 1998 if (iLDR == 2):
volker@28 1999 leg = plt.legend()
volker@28 2000 leg.get_frame().set_alpha(0.1)
volker@28 2001
volker@16 2002
volker@16 2003 plt.tick_params(axis='both', labelsize=9)
volker@16 2004 plt.plot([LDRTrue, LDRTrue], [0, np.max(n)], 'r-', lw=2)
volker@16 2005
binietoglou@19 2006 # plt.title(LID + ' ' + aVar, fontsize=18)
binietoglou@19 2007 # plt.ylabel('frequency', fontsize=10)
binietoglou@19 2008 # plt.xlabel('LDRcorr', fontsize=10)
binietoglou@19 2009 # fig.tight_layout()
binietoglou@19 2010 fig.suptitle(LID + ' with ' + str(Type[TypeC]) + ' ' + str(Loc[LocC]) + ' - ' + aVar, fontsize=14, y=1.05)
binietoglou@19 2011 # plt.show()
binietoglou@19 2012 # fig.savefig(LID + '_' + aVar + '.png', dpi=150, bbox_inches='tight', pad_inches=0)
binietoglou@19 2013 # plt.close
volker@16 2014 return
ulalume3@0 2015
volker@28 2016 # Plot Etax
volker@28 2017 def PlotEtax(aVar, aX, X0, daX, iaX, naX):
volker@28 2018 # aVar is the name of the parameter and aX is the subset of aLDRcorr which is coloured in the plot
volker@28 2019 # example: PlotSubHist("DOLP", aDOLP, DOLP0, dDOLP, iDOLP, nDOLP)
volker@28 2020 fig, ax = plt.subplots(nrows=1, ncols=5, sharex=True, sharey=True, figsize=(25, 2))
volker@28 2021 iLDR = -1
volker@28 2022 for LDRTrue in LDRrange:
volker@28 2023 iLDR = iLDR + 1
volker@28 2024 Etaxmin[iLDR] = np.amin(aEtax[iLDR, :])
volker@28 2025 Etaxmax[iLDR] = np.amax(aEtax[iLDR, :])
volker@28 2026 Rmin = Etaxmin[iLDR] * 0.995 # np.min(aLDRcorr[iLDR,:]) * 0.995
volker@28 2027 Rmax = Etaxmax[iLDR] * 1.005 # np.max(aLDRcorr[iLDR,:]) * 1.005
volker@28 2028
volker@28 2029 # plt.subplot(5,2,iLDR+1)
volker@28 2030 plt.subplot(1, 5, iLDR + 1)
volker@28 2031 (n, bins, patches) = plt.hist(aEtax[iLDR, :],
volker@28 2032 bins=100, log=False,
volker@28 2033 range=[Rmin, Rmax],
volker@28 2034 alpha=0.5, density=False, color='0.5', histtype='stepfilled')
volker@28 2035 for iaX in range(-naX, naX + 1):
volker@28 2036 plt.hist(aEtax[iLDR, aX == iaX],
volker@28 2037 range=[Rmin, Rmax],
volker@28 2038 bins=100, log=False, alpha=0.3, density=False, histtype='stepfilled',
volker@28 2039 label=str(round(X0 + iaX * daX / naX, 5)))
volker@28 2040 if (iLDR == 2):
volker@28 2041 leg = plt.legend()
volker@28 2042 leg.get_frame().set_alpha(0.1)
volker@28 2043 plt.tick_params(axis='both', labelsize=9)
volker@28 2044 plt.plot([Etax0, Etax0], [0, np.max(n)], 'r-', lw=2)
volker@28 2045 fig.suptitle('Etax - ' + LID + ' with ' + str(Type[TypeC]) + ' ' + str(Loc[LocC]) + ' - ' + aVar, fontsize=14, y=1.05)
volker@28 2046 return
binietoglou@19 2047
volker@23 2048 if (nDOLP > 0): PlotSubHist("DOLP", aDOLP, DOLP0, dDOLP, iDOLP, nDOLP)
volker@16 2049 if (nRotL > 0): PlotSubHist("RotL", aRotL, RotL0, dRotL, iRotL, nRotL)
volker@16 2050 if (nRetE > 0): PlotSubHist("RetE", aRetE, RetE0, dRetE, iRetE, nRetE)
volker@16 2051 if (nRotE > 0): PlotSubHist("RotE", aRotE, RotE0, dRotE, iRotE, nRotE)
volker@16 2052 if (nDiE > 0): PlotSubHist("DiE", aDiE, DiE0, dDiE, iDiE, nDiE)
volker@16 2053 if (nRetO > 0): PlotSubHist("RetO", aRetO, RetO0, dRetO, iRetO, nRetO)
volker@16 2054 if (nRotO > 0): PlotSubHist("RotO", aRotO, RotO0, dRotO, iRotO, nRotO)
volker@16 2055 if (nDiO > 0): PlotSubHist("DiO", aDiO, DiO0, dDiO, iDiO, nDiO)
volker@16 2056 if (nDiC > 0): PlotSubHist("DiC", aDiC, DiC0, dDiC, iDiC, nDiC)
volker@16 2057 if (nRotC > 0): PlotSubHist("RotC", aRotC, RotC0, dRotC, iRotC, nRotC)
volker@16 2058 if (nRetC > 0): PlotSubHist("RetC", aRetC, RetC0, dRetC, iRetC, nRetC)
volker@16 2059 if (nTP > 0): PlotSubHist("TP", aTP, TP0, dTP, iTP, nTP)
volker@16 2060 if (nTS > 0): PlotSubHist("TS", aTS, TS0, dTS, iTS, nTS)
volker@16 2061 if (nRP > 0): PlotSubHist("RP", aRP, RP0, dRP, iRP, nRP)
volker@16 2062 if (nRS > 0): PlotSubHist("RS", aRS, RS0, dRS, iRS, nRS)
volker@16 2063 if (nRetT > 0): PlotSubHist("RetT", aRetT, RetT0, dRetT, iRetT, nRetT)
volker@16 2064 if (nRetR > 0): PlotSubHist("RetR", aRetR, RetR0, dRetR, iRetR, nRetR)
volker@16 2065 if (nERaT > 0): PlotSubHist("ERaT", aERaT, ERaT0, dERaT, iERaT, nERaT)
volker@16 2066 if (nERaR > 0): PlotSubHist("ERaR", aERaR, ERaR0, dERaR, iERaR, nERaR)
volker@16 2067 if (nRotaT > 0): PlotSubHist("RotaT", aRotaT, RotaT0, dRotaT, iRotaT, nRotaT)
volker@16 2068 if (nRotaR > 0): PlotSubHist("RotaR", aRotaR, RotaR0, dRotaR, iRotaR, nRotaR)
volker@16 2069 if (nLDRCal > 0): PlotSubHist("LDRCal", aLDRCal, LDRCal0, dLDRCal, iLDRCal, nLDRCal)
volker@28 2070 if (nTCalT > 0): PlotSubHist("TCalT", aTCalT, TCalT0, dTCalT, iTCalT, nTCalT)
volker@28 2071 if (nTCalR > 0): PlotSubHist("TCalR", aTCalR, TCalR0, dTCalR, iTCalR, nTCalR)
volker@28 2072 if (nNCal > 0): PlotSubHist("CalNoiseTp", aNCalTp, 0, 1, iNCalTp, nNCal)
volker@28 2073 if (nNCal > 0): PlotSubHist("CalNoiseTm", aNCalTm, 0, 1, iNCalTm, nNCal)
volker@28 2074 if (nNCal > 0): PlotSubHist("CalNoiseRp", aNCalRp, 0, 1, iNCalRp, nNCal)
volker@28 2075 if (nNCal > 0): PlotSubHist("CalNoiseRm", aNCalRm, 0, 1, iNCalRm, nNCal)
volker@28 2076 if (nNI > 0): PlotSubHist("SigNoiseIt", aNIt, 0, 1, iNIt, nNI)
volker@28 2077 if (nNI > 0): PlotSubHist("SigNoiseIr", aNIr, 0, 1, iNIr, nNI)
volker@16 2078 plt.show()
volker@16 2079 plt.close
volker@21 2080
volker@16 2081 '''
volker@21 2082 # --- Plot F11 histograms
volker@16 2083 print()
volker@16 2084 print(" ############################################################################## ")
volker@16 2085 print(Text1)
volker@16 2086 print()
volker@16 2087
volker@16 2088 iLDR = 5
volker@16 2089 for LDRTrue in LDRrange:
volker@16 2090 iLDR = iLDR - 1
volker@21 2091 #aF11corr[iLDR,:] = aF11corr[iLDR,:] / aF11corr[0,:] - 1.0
volker@21 2092 aF11corr[iLDR,:] = aF11corr[iLDR,:] / aF11sim0[iLDR] - 1.0
volker@16 2093 # Plot F11
volker@16 2094 def PlotSubHistF11(aVar, aX, X0, daX, iaX, naX):
volker@16 2095 fig, ax = plt.subplots(nrows=1, ncols=5, sharex=True, sharey=True, figsize=(25, 2))
volker@16 2096 iLDR = -1
volker@16 2097 for LDRTrue in LDRrange:
volker@16 2098 iLDR = iLDR + 1
volker@16 2099
volker@16 2100 #F11min[iLDR] = np.min(aF11corr[iLDR,:])
volker@16 2101 #F11max[iLDR] = np.max(aF11corr[iLDR,:])
volker@28 2102 #Rmin = F11min[iLDR] * 0.995 # np.min(aLDRcorr[iLDR,:]) * 0.995
volker@28 2103 #Rmax = F11max[iLDR] * 1.005 # np.max(aLDRcorr[iLDR,:]) * 1.005
volker@16 2104
volker@16 2105 #Rmin = 0.8
volker@16 2106 #Rmax = 1.2
ulalume3@0 2107
volker@16 2108 #plt.subplot(5,2,iLDR+1)
volker@16 2109 plt.subplot(1,5,iLDR+1)
volker@16 2110 (n, bins, patches) = plt.hist(aF11corr[iLDR,:],
volker@16 2111 bins=100, log=False,
volker@28 2112 alpha=0.5, density=False, color = '0.5', histtype='stepfilled')
volker@16 2113
volker@16 2114 for iaX in range(-naX,naX+1):
volker@16 2115 plt.hist(aF11corr[iLDR,aX == iaX],
volker@28 2116 bins=100, log=False, alpha=0.3, density=False, histtype='stepfilled', label = str(round(X0 + iaX*daX/naX,5)))
volker@16 2117
volker@16 2118 if (iLDR == 2): plt.legend()
volker@16 2119
volker@16 2120 plt.tick_params(axis='both', labelsize=9)
volker@16 2121 #plt.plot([LDRTrue, LDRTrue], [0, np.max(n)], 'r-', lw=2)
volker@16 2122
volker@16 2123 #plt.title(LID + ' ' + aVar, fontsize=18)
volker@16 2124 #plt.ylabel('frequency', fontsize=10)
volker@16 2125 #plt.xlabel('LDRcorr', fontsize=10)
volker@16 2126 #fig.tight_layout()
volker@16 2127 fig.suptitle(LID + ' ' + str(Type[TypeC]) + ' ' + str(Loc[LocC]) + ' - ' + aVar, fontsize=14, y=1.05)
volker@16 2128 #plt.show()
volker@16 2129 #fig.savefig(LID + '_' + aVar + '.png', dpi=150, bbox_inches='tight', pad_inches=0)
volker@16 2130 #plt.close
volker@16 2131 return
ulalume3@0 2132
volker@23 2133 if (nDOLP > 0): PlotSubHistF11("DOLP", aDOLP, DOLP0, dDOLP, iDOLP, nDOLP)
volker@16 2134 if (nRotL > 0): PlotSubHistF11("RotL", aRotL, RotL0, dRotL, iRotL, nRotL)
volker@16 2135 if (nRetE > 0): PlotSubHistF11("RetE", aRetE, RetE0, dRetE, iRetE, nRetE)
volker@16 2136 if (nRotE > 0): PlotSubHistF11("RotE", aRotE, RotE0, dRotE, iRotE, nRotE)
volker@16 2137 if (nDiE > 0): PlotSubHistF11("DiE", aDiE, DiE0, dDiE, iDiE, nDiE)
volker@16 2138 if (nRetO > 0): PlotSubHistF11("RetO", aRetO, RetO0, dRetO, iRetO, nRetO)
volker@16 2139 if (nRotO > 0): PlotSubHistF11("RotO", aRotO, RotO0, dRotO, iRotO, nRotO)
volker@16 2140 if (nDiO > 0): PlotSubHistF11("DiO", aDiO, DiO0, dDiO, iDiO, nDiO)
volker@16 2141 if (nDiC > 0): PlotSubHistF11("DiC", aDiC, DiC0, dDiC, iDiC, nDiC)
volker@16 2142 if (nRotC > 0): PlotSubHistF11("RotC", aRotC, RotC0, dRotC, iRotC, nRotC)
volker@16 2143 if (nRetC > 0): PlotSubHistF11("RetC", aRetC, RetC0, dRetC, iRetC, nRetC)
volker@16 2144 if (nTP > 0): PlotSubHistF11("TP", aTP, TP0, dTP, iTP, nTP)
volker@16 2145 if (nTS > 0): PlotSubHistF11("TS", aTS, TS0, dTS, iTS, nTS)
volker@16 2146 if (nRP > 0): PlotSubHistF11("RP", aRP, RP0, dRP, iRP, nRP)
volker@16 2147 if (nRS > 0): PlotSubHistF11("RS", aRS, RS0, dRS, iRS, nRS)
volker@16 2148 if (nRetT > 0): PlotSubHistF11("RetT", aRetT, RetT0, dRetT, iRetT, nRetT)
volker@16 2149 if (nRetR > 0): PlotSubHistF11("RetR", aRetR, RetR0, dRetR, iRetR, nRetR)
volker@16 2150 if (nERaT > 0): PlotSubHistF11("ERaT", aERaT, ERaT0, dERaT, iERaT, nERaT)
volker@16 2151 if (nERaR > 0): PlotSubHistF11("ERaR", aERaR, ERaR0, dERaR, iERaR, nERaR)
volker@16 2152 if (nRotaT > 0): PlotSubHistF11("RotaT", aRotaT, RotaT0, dRotaT, iRotaT, nRotaT)
volker@16 2153 if (nRotaR > 0): PlotSubHistF11("RotaR", aRotaR, RotaR0, dRotaR, iRotaR, nRotaR)
volker@16 2154 if (nLDRCal > 0): PlotSubHistF11("LDRCal", aLDRCal, LDRCal0, dLDRCal, iLDRCal, nLDRCal)
volker@28 2155 if (nTCalT > 0): PlotSubHistF11("TCalT", aTCalT, TCalT0, dTCalT, iTCalT, nTCalT)
volker@28 2156 if (nTCalR > 0): PlotSubHistF11("TCalR", aTCalR, TCalR0, dTCalR, iTCalR, nTCalR)
volker@28 2157 if (nNCal > 0): PlotSubHistF11("CalNoise", aNCal, 0, 1/nNCal, iNCal, nNCal)
volker@28 2158 if (nNI > 0): PlotSubHistF11("SigNoise", aNI, 0, 1/nNI, iNI, nNI)
volker@28 2159
ulalume3@0 2160
volker@16 2161 plt.show()
volker@16 2162 plt.close
volker@21 2163
volker@16 2164 '''
volker@16 2165 '''
volker@16 2166 # only histogram
volker@16 2167 #print("******************* " + aVar + " *******************")
volker@16 2168 fig, ax = plt.subplots(nrows=5, ncols=2, sharex=True, sharey=True, figsize=(10, 10))
ulalume3@0 2169 iLDR = -1
ulalume3@0 2170 for LDRTrue in LDRrange:
ulalume3@0 2171 iLDR = iLDR + 1
volker@28 2172 LDRmin[iLDR] = np.min(aLDRcorr[iLDR,:])
volker@28 2173 LDRmax[iLDR] = np.max(aLDRcorr[iLDR,:])
volker@28 2174 Rmin = np.min(aLDRcorr[iLDR,:]) * 0.999
volker@28 2175 Rmax = np.max(aLDRcorr[iLDR,:]) * 1.001
volker@16 2176 plt.subplot(5,2,iLDR+1)
volker@28 2177 (n, bins, patches) = plt.hist(aLDRcorr[iLDR,:],
ulalume3@0 2178 range=[Rmin, Rmax],
volker@28 2179 bins=200, log=False, alpha=0.2, density=False, color = '0.5', histtype='stepfilled')
ulalume3@0 2180 plt.tick_params(axis='both', labelsize=9)
ulalume3@0 2181 plt.plot([LDRTrue, LDRTrue], [0, np.max(n)], 'r-', lw=2)
volker@16 2182 plt.show()
volker@16 2183 plt.close
volker@21 2184 # --- End of Plot F11 histograms
volker@16 2185 '''
ulalume3@0 2186
volker@16 2187 # --- Plot LDRmin, LDRmax
volker@28 2188 iLDR = -1
volker@28 2189 for LDRTrue in LDRrange:
volker@28 2190 iLDR = iLDR + 1
volker@28 2191 LDRmin[iLDR] = np.amin(aLDRcorr[iLDR, :])
volker@28 2192 LDRmax[iLDR] = np.amax(aLDRcorr[iLDR, :])
volker@28 2193
volker@16 2194 fig2 = plt.figure()
volker@28 2195 LDRrangeA = np.array(LDRrange)
volker@28 2196 if((np.amax(LDRmax - LDRrangeA)-np.amin(LDRmin - LDRrangeA)) < 0.001):
volker@28 2197 plt.ylim(-0.001,0.001)
volker@28 2198 plt.plot(LDRrangeA, LDRmax - LDRrangeA, linewidth=2.0, color='b')
volker@28 2199 plt.plot(LDRrangeA, LDRmin - LDRrangeA, linewidth=2.0, color='g')
ulalume3@0 2200
volker@16 2201 plt.xlabel('LDRtrue', fontsize=18)
volker@16 2202 plt.ylabel('LDRTrue-LDRmin, LDRTrue-LDRmax', fontsize=14)
volker@16 2203 plt.title(LID + ' ' + str(Type[TypeC]) + ' ' + str(Loc[LocC]), fontsize=18)
binietoglou@19 2204 # plt.ylimit(-0.07, 0.07)
volker@16 2205 plt.show()
volker@16 2206 plt.close
ulalume3@0 2207
volker@16 2208 # --- Save LDRmin, LDRmax to file
volker@16 2209 # http://stackoverflow.com/questions/4675728/redirect-stdout-to-a-file-in-python
volker@28 2210 with open('output_files\\' + LID + '-' + InputFile[0:-3] + '-LDR_min_max.dat', 'w') as f:
volker@16 2211 with redirect_stdout(f):
volker@16 2212 print(LID)
volker@16 2213 print("LDRtrue, LDRmin, LDRmax")
volker@28 2214 for i in range(len(LDRrangeA)):
volker@28 2215 print("{0:7.4f},{1:7.4f},{2:7.4f}".format(LDRrangeA[i], LDRmin[i], LDRmax[i]))
volker@28 2216
ulalume3@0 2217
volker@28 2218 if (bPlotEtax):
volker@28 2219 if (nDOLP > 0): PlotEtax("DOLP", aDOLP, DOLP0, dDOLP, iDOLP, nDOLP)
volker@28 2220 if (nRotL > 0): PlotEtax("RotL", aRotL, RotL0, dRotL, iRotL, nRotL)
volker@28 2221 if (nRetE > 0): PlotEtax("RetE", aRetE, RetE0, dRetE, iRetE, nRetE)
volker@28 2222 if (nRotE > 0): PlotEtax("RotE", aRotE, RotE0, dRotE, iRotE, nRotE)
volker@28 2223 if (nDiE > 0): PlotEtax("DiE", aDiE, DiE0, dDiE, iDiE, nDiE)
volker@28 2224 if (nRetO > 0): PlotEtax("RetO", aRetO, RetO0, dRetO, iRetO, nRetO)
volker@28 2225 if (nRotO > 0): PlotEtax("RotO", aRotO, RotO0, dRotO, iRotO, nRotO)
volker@28 2226 if (nDiO > 0): PlotEtax("DiO", aDiO, DiO0, dDiO, iDiO, nDiO)
volker@28 2227 if (nDiC > 0): PlotEtax("DiC", aDiC, DiC0, dDiC, iDiC, nDiC)
volker@28 2228 if (nRotC > 0): PlotEtax("RotC", aRotC, RotC0, dRotC, iRotC, nRotC)
volker@28 2229 if (nRetC > 0): PlotEtax("RetC", aRetC, RetC0, dRetC, iRetC, nRetC)
volker@28 2230 if (nTP > 0): PlotEtax("TP", aTP, TP0, dTP, iTP, nTP)
volker@28 2231 if (nTS > 0): PlotEtax("TS", aTS, TS0, dTS, iTS, nTS)
volker@28 2232 if (nRP > 0): PlotEtax("RP", aRP, RP0, dRP, iRP, nRP)
volker@28 2233 if (nRS > 0): PlotEtax("RS", aRS, RS0, dRS, iRS, nRS)
volker@28 2234 if (nRetT > 0): PlotEtax("RetT", aRetT, RetT0, dRetT, iRetT, nRetT)
volker@28 2235 if (nRetR > 0): PlotEtax("RetR", aRetR, RetR0, dRetR, iRetR, nRetR)
volker@28 2236 if (nERaT > 0): PlotEtax("ERaT", aERaT, ERaT0, dERaT, iERaT, nERaT)
volker@28 2237 if (nERaR > 0): PlotEtax("ERaR", aERaR, ERaR0, dERaR, iERaR, nERaR)
volker@28 2238 if (nRotaT > 0): PlotEtax("RotaT", aRotaT, RotaT0, dRotaT, iRotaT, nRotaT)
volker@28 2239 if (nRotaR > 0): PlotEtax("RotaR", aRotaR, RotaR0, dRotaR, iRotaR, nRotaR)
volker@28 2240 if (nLDRCal > 0): PlotEtax("LDRCal", aLDRCal, LDRCal0, dLDRCal, iLDRCal, nLDRCal)
volker@28 2241 if (nTCalT > 0): PlotEtax("TCalT", aTCalT, TCalT0, dTCalT, iTCalT, nTCalT)
volker@28 2242 if (nTCalR > 0): PlotEtax("TCalR", aTCalR, TCalR0, dTCalR, iTCalR, nTCalR)
volker@28 2243 if (nNCal > 0): PlotEtax("CalNoiseTp", aNCalTp, 0, 1, iNCalTp, nNCal)
volker@28 2244 if (nNCal > 0): PlotEtax("CalNoiseTm", aNCalTm, 0, 1, iNCalTm, nNCal)
volker@28 2245 if (nNCal > 0): PlotEtax("CalNoiseRp", aNCalRp, 0, 1, iNCalRp, nNCal)
volker@28 2246 if (nNCal > 0): PlotEtax("CalNoiseRm", aNCalRm, 0, 1, iNCalRm, nNCal)
volker@28 2247 if (nNI > 0): PlotEtax("SigNoiseIt", aNIt, 0, 1, iNIt, nNI)
volker@28 2248 if (nNI > 0): PlotEtax("SigNoiseIr", aNIr, 0, 1, iNIr, nNI)
volker@28 2249 plt.show()
volker@28 2250 plt.close
volker@28 2251
volker@28 2252 #Etaxmin = np.amin(aEtax[1, :])
volker@28 2253 Etaxmin = np.amin(aEtax[1, :])
volker@28 2254 Etaxmax = np.amax(aEtax[1, :])
volker@28 2255 Etaxstd = np.std(aEtax[1, :])
volker@28 2256 Etaxmean = np.mean(aEtax[1, :])
volker@28 2257 Etaxmedian = np.mean(aEtax[1, :])
volker@28 2258
volker@28 2259 print("Etax: mean±std, median, max-mean, mean-min")
volker@28 2260 print("{0:7.4f}±{1:7.4f},{2:7.4f},+{3:7.4f},-{4:7.4f}".format(Etaxmean, Etaxstd, Etaxmedian, Etaxmax-Etaxmean, Etaxmean-Etaxmin, ))
volker@28 2261
volker@16 2262 '''
volker@16 2263 # --- Plot K over LDRCal
volker@16 2264 fig3 = plt.figure()
volker@28 2265 plt.plot(LDRCal0+aLDRCal*dLDRCal/nLDRCal,aGHK[4,:], linewidth=2.0, color='b')
ulalume3@0 2266
volker@16 2267 plt.xlabel('LDRCal', fontsize=18)
volker@16 2268 plt.ylabel('K', fontsize=14)
volker@16 2269 plt.title(LID, fontsize=18)
volker@16 2270 plt.show()
volker@16 2271 plt.close
volker@16 2272 '''
ulalume3@0 2273
ulalume3@0 2274 # Additional plot routines ======>
ulalume3@0 2275 '''
ulalume3@0 2276 #******************************************************************************
ulalume3@0 2277 # 1. Plot LDRcorrected - LDR(measured Icross/Iparallel)
ulalume3@0 2278 LDRa = np.arange(1.,100.)*0.005
ulalume3@0 2279 LDRCorra = np.arange(1.,100.)
ulalume3@0 2280 if Y == - 1.: LDRa = 1./LDRa
ulalume3@0 2281 LDRCorra = (1./Eta*LDRa*(GT+HT)-(GR+HR))/((GR-HR)-1./Eta*LDRa*(GT-HT))
ulalume3@0 2282 if Y == - 1.: LDRa = 1./LDRa
ulalume3@0 2283 #
ulalume3@0 2284 #fig = plt.figure()
ulalume3@0 2285 plt.plot(LDRa,LDRCorra-LDRa)
ulalume3@0 2286 plt.plot([0.,0.5],[0.,0.5])
ulalume3@0 2287 plt.suptitle('LDRcorrected - LDR(measured Icross/Iparallel)', fontsize=16)
ulalume3@0 2288 plt.xlabel('LDR', fontsize=18)
ulalume3@0 2289 plt.ylabel('LDRCorr - LDR', fontsize=16)
ulalume3@0 2290 #plt.savefig('test.png')
ulalume3@0 2291 #
ulalume3@0 2292 '''
ulalume3@0 2293 '''
ulalume3@0 2294 #******************************************************************************
ulalume3@0 2295 # 2. Plot LDRsim (simulated measurements without corrections = Icross/Iparallel) over LDRtrue
ulalume3@0 2296 LDRa = np.arange(1.,100.)*0.005
ulalume3@0 2297 LDRsima = np.arange(1.,100.)
ulalume3@0 2298
ulalume3@0 2299 atruea = (1.-LDRa)/(1+LDRa)
ulalume3@0 2300 Ita = TiT*TiO*IinL*(GT+atruea*HT)
ulalume3@0 2301 Ira = TiR*TiO*IinL*(GR+atruea*HR)
ulalume3@0 2302 LDRsima = Ira/Ita # simulated uncorrected LDR with Y from input file
ulalume3@0 2303 if Y == -1.: LDRsima = 1./LDRsima
ulalume3@0 2304 #
ulalume3@0 2305 #fig = plt.figure()
ulalume3@0 2306 plt.plot(LDRa,LDRsima)
ulalume3@0 2307 plt.plot([0.,0.5],[0.,0.5])
ulalume3@0 2308 plt.suptitle('LDRsim (simulated measurements without corrections = Icross/Iparallel) over LDRtrue', fontsize=10)
ulalume3@0 2309 plt.xlabel('LDRtrue', fontsize=18)
ulalume3@0 2310 plt.ylabel('LDRsim', fontsize=16)
ulalume3@0 2311 #plt.savefig('test.png')
ulalume3@0 2312 #
ulalume3@0 2313 '''

mercurial