Fri, 05 Jun 2020 14:06:28 +0200
Added tag 0.9.8e5 for changeset d2c9785f0d61
Volker@43 | 1 | # -*- coding: utf-8 -*- |
Volker@43 | 2 | """ |
Volker@43 | 3 | Copyright 2016, 2019 Volker Freudenthaler |
Volker@43 | 4 | |
Volker@43 | 5 | Licensed under the EUPL, Version 1.1 only (the "Licence"). |
Volker@43 | 6 | |
Volker@43 | 7 | You may not use this work except in compliance with the Licence. |
Volker@43 | 8 | A copy of the licence is distributed with the code. Alternatively, you may obtain |
Volker@43 | 9 | a copy of the Licence at: |
Volker@43 | 10 | |
Volker@43 | 11 | https://joinup.ec.europa.eu/community/eupl/og_page/eupl |
Volker@43 | 12 | |
Volker@43 | 13 | Unless required by applicable law or agreed to in writing, software distributed |
Volker@43 | 14 | under the Licence is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS |
Volker@43 | 15 | OF ANY KIND, either express or implied. See the Licence for the specific language governing |
Volker@43 | 16 | permissions and limitations under the Licence. |
Volker@43 | 17 | |
Volker@43 | 18 | Equation reference: http://www.atmos-meas-tech-discuss.net/amt-2015-338/amt-2015-338.pdf |
Volker@43 | 19 | With equations code from Appendix C |
Volker@43 | 20 | Python 3.7, seaborn 0.9.0 |
Volker@43 | 21 | |
Volker@43 | 22 | Code description: |
Volker@43 | 23 | |
Volker@43 | 24 | From measured lidar signals we cannot directly determine the desired backscatter coefficient (F11) and the linear depolarization ratio (LDR) |
Volker@43 | 25 | because of the cross talk between the channles and systematic errors of a lidar system. |
Volker@43 | 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@43 | 27 | with which the measured signals can be corrected. |
Volker@43 | 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@43 | 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@43 | 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@43 | 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@43 | 32 | GHK parameters (GT0, GR0, HT0, HR0, and K0) to derive finally the distributions of "possibly real" linear depolarization ratios (LDRCorr), |
Volker@43 | 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@43 | 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@43 | 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@43 | 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@43 | 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@43 | 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@43 | 39 | |
Volker@43 | 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@43 | 41 | |
Volker@43 | 42 | Ver. 0.9.7: includes the random error (signal noise) of the calibration and standard measurements |
Volker@43 | 43 | Changes: |
Volker@43 | 44 | Line 1687 Eta = (TaR * TiR) / (TaT * TiT) |
Volker@43 | 45 | Line 1691 K = Etax / Eta # K of the real system; but correction in Line 1721 with K0 / Etax |
Volker@43 | 46 | should work with nTCalT = nTCalR = 0 |
Volker@43 | 47 | Ver. 0.9.7b: |
Volker@43 | 48 | ToDo: include error due to TCalT und TCalR => determination of NCalT and NCalR etc. in error calculation line 1741ff |
Volker@43 | 49 | combined error loops iNI and INCal for signals |
Volker@43 | 50 | Ver. 0.9.7c: individual error loops for each of the six signals |
Volker@43 | 51 | Ver. 0.9.7c2: different calculation of the signal noise errors |
Volker@43 | 52 | Ver. 0.9.7c3: n.a.different calculation of the signal noise errors |
Volker@43 | 53 | Ver. 0.9.7c4: test to speed up the loops for error calculation by moving them just before the actual calculation: still some code errors |
Volker@43 | 54 | Ver. 0.9.8: |
Volker@43 | 55 | - 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@43 | 56 | - calculation of the PLDR from LDR and BSR, BSR, and LDRm |
Volker@43 | 57 | - 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@43 | 58 | Ver. 0.9.8b: change from "TTa = TiT * TaT" to "TTa = TiT * TaT * ATPT" etc. (compare ver 0.9.8 with 0.9.8b) removes |
Volker@43 | 59 | - the strong Tp dependence of the errors |
Volker@43 | 60 | - the factor 2 in the GH parameters |
Volker@43 | 61 | - see c:\technik\Optik\Polarizers\DepCal\ApplOpt\GH-parameters-190114.odt |
Volker@43 | 62 | Ver. 0.9.8c: includes error of Etax |
Volker@43 | 63 | Ver. 0.9.8d: Eta0, K0 etc in error loop replaced by Eta0y, K0y etc. Changes in signal noise calculations |
Volker@43 | 64 | Ver. 0.9.8e: ambiguous laser spec. DOLP (no discrimination between left and right circular polarisation) replaced by Stokes parameters Qin, Uin |
Volker@43 | 65 | Ver. 0.9.8e2: Added plot of LDRsim, Etax, Etapx, Etamx; LDRCorr and aLDRcorr consistently named |
Volker@43 | 66 | Ver. 0.9.8e3: Change of OutputFile name; Change of Ir and It noise if (CalcFrom0deg) = False; (Different calculation of error contributions tested but not implemented) |
Volker@43 | 67 | Ver. 0.9.8e4: text changed for y=+-1 (see line 274 ff and line 1044 ff |
Volker@43 | 68 | Ver. 0.9.8e5: changed: LDRunCorr = LDRsim / Etax |
Volker@43 | 69 | |
Volker@43 | 70 | ======================================================== |
Volker@43 | 71 | simulation: LDRsim = Ir / It with variable parameters (possible truths) |
Volker@43 | 72 | G,H,Eta,Etax,K |
Volker@43 | 73 | It = TaT * TiT * ATP1 * TiO * TiE * (GT + atrue * HT) |
Volker@43 | 74 | LDRsim = Ir / It |
Volker@43 | 75 | consistency test: is forward simulation and correction consistent? |
Volker@43 | 76 | LDRCorr = (LDRsim / Eta * (GT + HT) - (GR + HR)) / ((GR - HR) - LDRsim / Eta * (GT - HT)) => atrue? |
Volker@43 | 77 | assumed true: G0,H0,Eta0,Etax0,K0 => actual retrievals of LDRCorr |
Volker@43 | 78 | => correct possible truths with assumed true G0,H0,Eta0 |
Volker@43 | 79 | measure: It, Ir, EtaX |
Volker@43 | 80 | LDRunCorr = LDRsim / Etax |
Volker@43 | 81 | correct it with G0,H0,K0: |
Volker@43 | 82 | LDRCorr = (LDRsim / (Etax / K0) * (GT0 + HT0) - (GR0 + HR0)) / ((GR0 - HR0) - LDRsim0 / (Etax / K0) * (GT0 - HT0)) |
Volker@43 | 83 | """ |
Volker@43 | 84 | # 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. |
Volker@43 | 85 | from __future__ import print_function |
Volker@43 | 86 | # !/usr/bin/env python3 |
Volker@43 | 87 | |
Volker@43 | 88 | import os |
Volker@43 | 89 | import sys |
Volker@43 | 90 | |
Volker@43 | 91 | from scipy.stats import kurtosis |
Volker@43 | 92 | from scipy.stats import skew |
Volker@43 | 93 | # use: kurtosis(data, fisher=True,bias=False) => 0; skew(data,bias=False) => 0 |
Volker@43 | 94 | # Comment: the seaborn library makes nicer plots, but the code works also without it. |
Volker@43 | 95 | import numpy as np |
Volker@43 | 96 | import matplotlib.pyplot as plt |
Volker@43 | 97 | |
Volker@43 | 98 | try: |
Volker@43 | 99 | import seaborn as sns |
Volker@43 | 100 | |
Volker@43 | 101 | sns_loaded = True |
Volker@43 | 102 | except ImportError: |
Volker@43 | 103 | sns_loaded = False |
Volker@43 | 104 | |
Volker@43 | 105 | # from time import clock # python 2 |
Volker@43 | 106 | from timeit import default_timer as clock |
Volker@43 | 107 | |
Volker@43 | 108 | # from matplotlib.backends.backend_pdf import PdfPages |
Volker@43 | 109 | # pdffile = '{}.pdf'.format('path') |
Volker@43 | 110 | # pp = PdfPages(pdffile) |
Volker@43 | 111 | ## pp.savefig can be called multiple times to save to multiple pages |
Volker@43 | 112 | # pp.savefig() |
Volker@43 | 113 | # pp.close() |
Volker@43 | 114 | |
Volker@43 | 115 | from contextlib import contextmanager |
Volker@43 | 116 | |
Volker@43 | 117 | @contextmanager |
Volker@43 | 118 | def redirect_stdout(new_target): |
Volker@43 | 119 | old_target, sys.stdout = sys.stdout, new_target # replace sys.stdout |
Volker@43 | 120 | try: |
Volker@43 | 121 | yield new_target # run some code with the replaced stdout |
Volker@43 | 122 | finally: |
Volker@43 | 123 | sys.stdout.flush() |
Volker@43 | 124 | sys.stdout = old_target # restore to the previous value |
Volker@43 | 125 | |
Volker@43 | 126 | ''' |
Volker@43 | 127 | real_raw_input = vars(__builtins__).get('raw_input',input) |
Volker@43 | 128 | ''' |
Volker@43 | 129 | try: |
Volker@43 | 130 | import __builtin__ |
Volker@43 | 131 | |
Volker@43 | 132 | input = getattr(__builtin__, 'raw_input') |
Volker@43 | 133 | except (ImportError, AttributeError): |
Volker@43 | 134 | pass |
Volker@43 | 135 | |
Volker@43 | 136 | from distutils.util import strtobool |
Volker@43 | 137 | |
Volker@43 | 138 | |
Volker@43 | 139 | def user_yes_no_query(question): |
Volker@43 | 140 | sys.stdout.write('%s [y/n]\n' % question) |
Volker@43 | 141 | while True: |
Volker@43 | 142 | try: |
Volker@43 | 143 | return strtobool(input().lower()) |
Volker@43 | 144 | except ValueError: |
Volker@43 | 145 | sys.stdout.write('Please respond with \'y\' or \'n\'.\n') |
Volker@43 | 146 | |
Volker@43 | 147 | |
Volker@43 | 148 | # if user_yes_no_query('want to exit?') == 1: sys.exit() |
Volker@43 | 149 | |
Volker@43 | 150 | abspath = os.path.abspath(__file__) |
Volker@43 | 151 | dname = os.path.dirname(abspath) |
Volker@43 | 152 | fname = os.path.basename(abspath) |
Volker@43 | 153 | os.chdir(dname) |
Volker@43 | 154 | |
Volker@43 | 155 | # PrintToOutputFile = True |
Volker@43 | 156 | |
Volker@43 | 157 | sqr05 = 0.5 ** 0.5 |
Volker@43 | 158 | |
Volker@43 | 159 | # ---- Initial definition of variables; the actual values will be read in with exec(open('./optic_input.py').read()) below |
Volker@43 | 160 | # Do you want to calculate the errors? If not, just the GHK-parameters are determined. |
Volker@43 | 161 | Error_Calc = True |
Volker@43 | 162 | LID = "internal" |
Volker@43 | 163 | EID = "internal" |
Volker@43 | 164 | # --- IL Laser IL and +-Uncertainty |
Volker@43 | 165 | Qin, dQin, nQin = 1., 0.0, 0 # second Stokes vector parameter; default 1 => linear polarization |
Volker@43 | 166 | Vin, dVin, nVin = 0., 0.0, 0 # fourth Stokes vector parameter |
Volker@43 | 167 | RotL, dRotL, nRotL = 0.0, 0.0, 1 # alpha; rotation of laser polarization in degrees; default 0 |
Volker@43 | 168 | # IL = 1e5 #photons in the laser beam, including detection efficiency of the telescope, atmodspheric and r^2 attenuation |
Volker@43 | 169 | # --- ME Emitter and +-Uncertainty |
Volker@43 | 170 | DiE, dDiE, nDiE = 0., 0.00, 1 # Diattenuation |
Volker@43 | 171 | TiE = 1. # Unpolarized transmittance |
Volker@43 | 172 | RetE, dRetE, nRetE = 0., 180.0, 0 # Retardance in degrees |
Volker@43 | 173 | RotE, dRotE, nRotE = 0., 0.0, 0 # beta: Rotation of optical element in degrees |
Volker@43 | 174 | # --- MO Receiver Optics including telescope |
Volker@43 | 175 | DiO, dDiO, nDiO = -0.055, 0.003, 1 |
Volker@43 | 176 | TiO = 0.9 |
Volker@43 | 177 | RetO, dRetO, nRetO = 0., 180.0, 2 |
Volker@43 | 178 | RotO, dRotO, nRotO = 0., 0.1, 1 # gamma |
Volker@43 | 179 | # --- PBS MT transmitting path defined with (TS,TP); and +-Uncertainty |
Volker@43 | 180 | TP, dTP, nTP = 0.98, 0.02, 1 |
Volker@43 | 181 | TS, dTS, nTS = 0.001, 0.001, 1 |
Volker@43 | 182 | TiT = 0.5 * (TP + TS) |
Volker@43 | 183 | DiT = (TP - TS) / (TP + TS) |
Volker@43 | 184 | # PolFilter |
Volker@43 | 185 | RetT, dRetT, nRetT = 0., 180., 0 |
Volker@43 | 186 | ERaT, dERaT, nERaT = 0.001, 0.001, 1 |
Volker@43 | 187 | RotaT, dRotaT, nRotaT = 0., 3., 1 |
Volker@43 | 188 | DaT = (1 - ERaT) / (1 + ERaT) |
Volker@43 | 189 | TaT = 0.5 * (1 + ERaT) |
Volker@43 | 190 | # --- PBS MR reflecting path defined with (RS,RP); and +-Uncertainty |
Volker@43 | 191 | RS_RP_depend_on_TS_TP = False |
Volker@43 | 192 | if (RS_RP_depend_on_TS_TP): |
Volker@43 | 193 | RP, dRP, nRP = 1 - TP, 0.0, 0 |
Volker@43 | 194 | RS, dRS, nRS = 1 - TS, 0.0, 0 |
Volker@43 | 195 | else: |
Volker@43 | 196 | RP, dRP, nRP = 0.05, 0.01, 1 |
Volker@43 | 197 | RS, dRS, nRS = 0.98, 0.01, 1 |
Volker@43 | 198 | TiR = 0.5 * (RP + RS) |
Volker@43 | 199 | DiR = (RP - RS) / (RP + RS) |
Volker@43 | 200 | # PolFilter |
Volker@43 | 201 | RetR, dRetR, nRetR = 0., 180., 0 |
Volker@43 | 202 | ERaR, dERaR, nERaR = 0.001, 0.001, 1 |
Volker@43 | 203 | RotaR, dRotaR, nRotaR = 90., 3., 1 |
Volker@43 | 204 | DaR = (1 - ERaR) / (1 + ERaR) |
Volker@43 | 205 | TaR = 0.5 * (1 + ERaR) |
Volker@43 | 206 | |
Volker@43 | 207 | # +++ Orientation of the PBS with respect to the reference plane (see Polarisation-orientation.png and Polarisation-orientation-2.png in /system_settings) |
Volker@43 | 208 | # Y = +1: PBS incidence plane is parallel to reference plane and polarisation in reference plane is finally transmitted. |
Volker@43 | 209 | # Y = -1: PBS incidence plane is perpendicular to reference plane and polarisation in reference plane is finally reflected. |
Volker@43 | 210 | Y = 1. |
Volker@43 | 211 | |
Volker@43 | 212 | # Calibrator = type defined by matrix values |
Volker@43 | 213 | LocC = 4 # location of calibrator: behind laser = 1; behind emitter = 2; before receiver = 3; before PBS = 4 |
Volker@43 | 214 | |
Volker@43 | 215 | # --- Additional attenuation (transmission of the ND-filter) during the calibration |
Volker@43 | 216 | TCalT, dTCalT, nTCalT = 1, 0., 0 # transmitting path; error calc not working yet |
Volker@43 | 217 | TCalR, dTCalR, nTCalR = 1, 0., 0 # reflecting path; error calc not working yet |
Volker@43 | 218 | |
Volker@43 | 219 | # *** signal noise error calculation |
Volker@43 | 220 | # --- number of photon counts in the signal summed up in the calibration range during the calibration measurements |
Volker@43 | 221 | NCalT = 1e6 # default 1e6, assumed the same in +45° and -45° signals |
Volker@43 | 222 | NCalR = 1e6 # default 1e6, assumed the same in +45° and -45° signals |
Volker@43 | 223 | NILfac = 1.0 # duration of standard (0°) measurement relative to calibration measurements |
Volker@43 | 224 | nNCal = 0 # error nNCal: one-sigma in steps to left and right for calibration signals |
Volker@43 | 225 | nNI = 0 # error nNI: one-sigma in steps to left and right for 0° signals |
Volker@43 | 226 | NI = 50000 #number of photon counts in the parallel 0°-signal |
Volker@43 | 227 | eFacT = 1.0 # rel. amplification of transmitted channel, approximate values are sufficient; def. = 1 |
Volker@43 | 228 | eFacR = 10.0 |
Volker@43 | 229 | IoutTp0, IoutTp, dIoutTp0 = 0.5, 0.5, 0.0 |
Volker@43 | 230 | IoutTm0, IoutTm, dIoutTm0 = 0.5, 0.5, 0.0 |
Volker@43 | 231 | IoutRp0, IoutRp, dIoutRp0 = 0.5, 0.5, 0.0 |
Volker@43 | 232 | IoutRm0, IoutRm, dIoutRm0 = 0.5, 0.5, 0.0 |
Volker@43 | 233 | It0, It, dIt0 = 1 , 1, 0 |
Volker@43 | 234 | Ir0, Ir, dTr0 = 1 , 1, 0 |
Volker@43 | 235 | CalcFrom0deg = True |
Volker@43 | 236 | |
Volker@43 | 237 | TypeC = 3 # linear polarizer calibrator |
Volker@43 | 238 | # example with extinction ratio 0.001 |
Volker@43 | 239 | DiC, dDiC, nDiC = 1.0, 0., 0 # ideal 1.0 |
Volker@43 | 240 | TiC = 0.5 # ideal 0.5 |
Volker@43 | 241 | RetC, dRetC, nRetC = 0.0, 0.0, 0 |
Volker@43 | 242 | RotC, dRotC, nRotC = 0.0, 0.1, 0 # constant calibrator offset epsilon |
Volker@43 | 243 | RotationErrorEpsilonForNormalMeasurements = False # is in general False for TypeC == 3 calibrator |
Volker@43 | 244 | |
Volker@43 | 245 | # Rotation error without calibrator: if False, then epsilon = 0 for normal measurements |
Volker@43 | 246 | RotationErrorEpsilonForNormalMeasurements = True |
Volker@43 | 247 | # BSR backscatter ratio |
Volker@43 | 248 | # BSR, dBSR, nBSR = 10, 0.05, 1 |
Volker@43 | 249 | BSR = np.zeros(5) |
Volker@43 | 250 | BSR = [1.1, 2, 5, 10., 50.] |
Volker@43 | 251 | # theoretical molecular LDR LDRm |
Volker@43 | 252 | LDRm, dLDRm, nLDRm = 0.004, 0.001, 1 |
Volker@43 | 253 | # LDRCal assumed atmospheric linear depolarization ratio during the calibration measurements (first guess) |
Volker@43 | 254 | LDRCal0, dLDRCal, nLDRCal = 0.25, 0.04, 1 |
Volker@43 | 255 | LDRCal = LDRCal0 |
Volker@43 | 256 | # measured LDRm will be corrected with calculated parameters |
Volker@43 | 257 | LDRmeas = 0.015 |
Volker@43 | 258 | # LDRtrue for simulation of measurement => LDRsim |
Volker@43 | 259 | LDRtrue = 0.004 |
Volker@43 | 260 | LDRtrue2 = 0.004 |
Volker@43 | 261 | LDRunCorr = 1. |
Volker@43 | 262 | # Initialize other values to 0 |
Volker@43 | 263 | ER, nER, dER = 0.001, 0, 0.001 |
Volker@43 | 264 | K = 0. |
Volker@43 | 265 | Km = 0. |
Volker@43 | 266 | Kp = 0. |
Volker@43 | 267 | LDRCorr = 0. |
Volker@43 | 268 | Eta = 0. |
Volker@43 | 269 | Ir = 0. |
Volker@43 | 270 | It = 0. |
Volker@43 | 271 | h = 1. |
Volker@43 | 272 | |
Volker@43 | 273 | Loc = ['', 'behind laser', 'behind emitter', 'before receiver', 'before PBS'] |
Volker@43 | 274 | Type = ['', 'mechanical rotator', 'hwp rotator', 'linear polarizer', 'qwp rotator', 'circular polarizer', |
Volker@43 | 275 | 'real HWP +-22.5°'] |
Volker@43 | 276 | |
Volker@43 | 277 | bPlotEtax = False |
Volker@43 | 278 | |
Volker@43 | 279 | # end of initial definition of variables |
Volker@43 | 280 | # ******************************************************************************************************************************* |
Volker@43 | 281 | # --- Read actual lidar system parameters from optic_input.py (must be in the programs sub-directory 'system_settings') |
Volker@43 | 282 | # ******************************************************************************************************************************* |
Volker@43 | 283 | |
Volker@43 | 284 | # InputFile = 'optic_input_0.9.8e4-PollyXT_Lacros.py' |
Volker@43 | 285 | InputFile = 'optic_input_example_lidar_ver0.9.8e.py' |
Volker@43 | 286 | |
Volker@43 | 287 | # ******************************************************************************************************************************* |
Volker@43 | 288 | |
Volker@43 | 289 | ''' |
Volker@43 | 290 | print("From ", dname) |
Volker@43 | 291 | print("Running ", fname) |
Volker@43 | 292 | print("Reading input file ", InputFile, " for") |
Volker@43 | 293 | ''' |
Volker@43 | 294 | input_path = os.path.join('.', 'system_settings', InputFile) |
Volker@43 | 295 | # this works with Python 2 and 3! |
Volker@43 | 296 | exec(open(input_path).read(), globals()) |
Volker@43 | 297 | # end of read actual system parameters |
Volker@43 | 298 | |
Volker@43 | 299 | |
Volker@43 | 300 | # --- Manual Parameter Change --- |
Volker@43 | 301 | # (use for quick parameter changes without changing the input file ) |
Volker@43 | 302 | # DiO = 0. |
Volker@43 | 303 | # LDRtrue = 0.45 |
Volker@43 | 304 | # LDRtrue2 = 0.004 |
Volker@43 | 305 | # Y = -1 |
Volker@43 | 306 | # LocC = 4 #location of calibrator: 1 = behind laser; 2 = behind emitter; 3 = before receiver; 4 = before PBS |
Volker@43 | 307 | # #TypeC = 6 Don't change the TypeC here |
Volker@43 | 308 | # RotationErrorEpsilonForNormalMeasurements = True |
Volker@43 | 309 | # LDRCal = 0.25 |
Volker@43 | 310 | # # --- Errors |
Volker@43 | 311 | Qin0, dQin, nQin = Qin, dQin, nQin |
Volker@43 | 312 | Vin0, dVin, nVin = Vin, dVin, nVin |
Volker@43 | 313 | RotL0, dRotL, nRotL = RotL, dRotL, nRotL |
Volker@43 | 314 | |
Volker@43 | 315 | DiE0, dDiE, nDiE = DiE, dDiE, nDiE |
Volker@43 | 316 | RetE0, dRetE, nRetE = RetE, dRetE, nRetE |
Volker@43 | 317 | RotE0, dRotE, nRotE = RotE, dRotE, nRotE |
Volker@43 | 318 | |
Volker@43 | 319 | DiO0, dDiO, nDiO = DiO, dDiO, nDiO |
Volker@43 | 320 | RetO0, dRetO, nRetO = RetO, dRetO, nRetO |
Volker@43 | 321 | RotO0, dRotO, nRotO = RotO, dRotO, nRotO |
Volker@43 | 322 | |
Volker@43 | 323 | DiC0, dDiC, nDiC = DiC, dDiC, nDiC |
Volker@43 | 324 | RetC0, dRetC, nRetC = RetC, dRetC, nRetC |
Volker@43 | 325 | RotC0, dRotC, nRotC = RotC, dRotC, nRotC |
Volker@43 | 326 | |
Volker@43 | 327 | TP0, dTP, nTP = TP, dTP, nTP |
Volker@43 | 328 | TS0, dTS, nTS = TS, dTS, nTS |
Volker@43 | 329 | RetT0, dRetT, nRetT = RetT, dRetT, nRetT |
Volker@43 | 330 | |
Volker@43 | 331 | ERaT0, dERaT, nERaT = ERaT, dERaT, nERaT |
Volker@43 | 332 | RotaT0, dRotaT, nRotaT = RotaT, dRotaT, nRotaT |
Volker@43 | 333 | |
Volker@43 | 334 | RP0, dRP, nRP = RP, dRP, nRP |
Volker@43 | 335 | RS0, dRS, nRS = RS, dRS, nRS |
Volker@43 | 336 | RetR0, dRetR, nRetR = RetR, dRetR, nRetR |
Volker@43 | 337 | |
Volker@43 | 338 | ERaR0, dERaR, nERaR = ERaR, dERaR, nERaR |
Volker@43 | 339 | RotaR0, dRotaR, nRotaR = RotaR, dRotaR, nRotaR |
Volker@43 | 340 | |
Volker@43 | 341 | LDRCal0, dLDRCal, nLDRCal = LDRCal, dLDRCal, nLDRCal |
Volker@43 | 342 | |
Volker@43 | 343 | # BSR0, dBSR, nBSR = BSR, dBSR, nBSR |
Volker@43 | 344 | LDRm0, dLDRm, nLDRm = LDRm, dLDRm, nLDRm |
Volker@43 | 345 | # ---------- End of manual parameter change |
Volker@43 | 346 | |
Volker@43 | 347 | RotL, RotE, RetE, DiE, RotO, RetO, DiO, RotC, RetC, DiC = RotL0, RotE0, RetE0, DiE0, RotO0, RetO0, DiO0, RotC0, RetC0, DiC0 |
Volker@43 | 348 | TP, TS, RP, RS, ERaT, RotaT, RetT, ERaR, RotaR, RetR = TP0, TS0, RP0, RS0, ERaT0, RotaT0, RetT0, ERaR0, RotaR0, RetR0 |
Volker@43 | 349 | LDRCal = LDRCal0 |
Volker@43 | 350 | DTa0, TTa0, DRa0, TRa0, LDRsimx, LDRCorr = 0., 0., 0., 0., 0., 0. |
Volker@43 | 351 | TCalT0, TCalR0 = TCalT, TCalR |
Volker@43 | 352 | |
Volker@43 | 353 | TiT = 0.5 * (TP + TS) |
Volker@43 | 354 | DiT = (TP - TS) / (TP + TS) |
Volker@43 | 355 | ZiT = (1. - DiT ** 2) ** 0.5 |
Volker@43 | 356 | TiR = 0.5 * (RP + RS) |
Volker@43 | 357 | DiR = (RP - RS) / (RP + RS) |
Volker@43 | 358 | ZiR = (1. - DiR ** 2) ** 0.5 |
Volker@43 | 359 | |
Volker@43 | 360 | C2aT = np.cos(np.deg2rad(2. * RotaT)) |
Volker@43 | 361 | C2aR = np.cos(np.deg2rad(2. * RotaR)) |
Volker@43 | 362 | ATPT = float(1. + C2aT * DaT * DiT) |
Volker@43 | 363 | ARPT = float(1. + C2aR * DaR * DiR) |
Volker@43 | 364 | TTa = TiT * TaT * ATPT # unpolarized transmission |
Volker@43 | 365 | TRa = TiR * TaR * ARPT # unpolarized transmission |
Volker@43 | 366 | Eta0 = TRa / TTa |
Volker@43 | 367 | |
Volker@43 | 368 | # --- alternative texts for output |
Volker@43 | 369 | dY = ['perpendicular', '', 'parallel'] |
Volker@43 | 370 | dY2 = ['reflected', '', 'transmitted'] |
Volker@43 | 371 | if ((abs(RotL) < 45 and Y == 1) or (abs(RotL) >= 45 and Y == -1)): |
Volker@44 | 372 | dY3 = "the parallel laser polarisation is detected in the transmitted channel." |
Volker@43 | 373 | else: |
Volker@44 | 374 | dY3 = "the parallel laser polarisation is detected in the reflected channel." |
Volker@43 | 375 | |
Volker@43 | 376 | # --- check input errors |
Volker@43 | 377 | if ((Qin ** 2 + Vin ** 2) ** 0.5) > 1: |
Volker@43 | 378 | print("Error: degree of polarisation of laser > 1. Check Qin and Vin! ") |
Volker@43 | 379 | sys.exit() |
Volker@43 | 380 | |
Volker@43 | 381 | # --- this subroutine is for the calculation of the PLDR from LDR, BSR, and LDRm ------------------- |
Volker@43 | 382 | def CalcPLDR(LDR, BSR, LDRm): |
Volker@43 | 383 | PLDR = (BSR * (1. + LDRm) * LDR - LDRm * (1. + LDR)) / (BSR * (1. + LDRm) - (1. + LDR)) |
Volker@43 | 384 | return (PLDR) |
Volker@43 | 385 | # --- this subroutine is for the calculation with certain fixed parameters ------------------------ |
Volker@43 | 386 | def Calc(TCalT, TCalR, NCalT, NCalR, Qin, Vin, RotL, RotE, RetE, DiE, RotO, RetO, DiO, |
Volker@43 | 387 | RotC, RetC, DiC, TP, TS, RP, RS, |
Volker@43 | 388 | ERaT, RotaT, RetT, ERaR, RotaR, RetR, LDRCal): |
Volker@43 | 389 | # ---- Do the calculations of bra-ket vectors |
Volker@43 | 390 | h = -1. if TypeC == 2 else 1 |
Volker@43 | 391 | # from input file: assumed LDRCal for calibration measurements |
Volker@43 | 392 | aCal = (1. - LDRCal) / (1. + LDRCal) |
Volker@43 | 393 | atrue = (1. - LDRtrue) / (1. + LDRtrue) |
Volker@43 | 394 | |
Volker@43 | 395 | # angles of emitter and laser and calibrator and receiver optics |
Volker@43 | 396 | # RotL = alpha, RotE = beta, RotO = gamma, RotC = epsilon |
Volker@43 | 397 | S2a = np.sin(2 * np.deg2rad(RotL)) |
Volker@43 | 398 | C2a = np.cos(2 * np.deg2rad(RotL)) |
Volker@43 | 399 | S2b = np.sin(2 * np.deg2rad(RotE)) |
Volker@43 | 400 | C2b = np.cos(2 * np.deg2rad(RotE)) |
Volker@43 | 401 | S2ab = np.sin(np.deg2rad(2 * RotL - 2 * RotE)) |
Volker@43 | 402 | C2ab = np.cos(np.deg2rad(2 * RotL - 2 * RotE)) |
Volker@43 | 403 | S2g = np.sin(np.deg2rad(2 * RotO)) |
Volker@43 | 404 | C2g = np.cos(np.deg2rad(2 * RotO)) |
Volker@43 | 405 | |
Volker@43 | 406 | # Laser with Degree of linear polarization DOLP |
Volker@43 | 407 | IinL = 1. |
Volker@43 | 408 | QinL = Qin |
Volker@43 | 409 | UinL = 0. |
Volker@43 | 410 | VinL = Vin |
Volker@43 | 411 | # VinL = (1. - DOLP ** 2) ** 0.5 |
Volker@43 | 412 | |
Volker@43 | 413 | # Stokes Input Vector rotation Eq. E.4 |
Volker@43 | 414 | A = C2a * QinL - S2a * UinL |
Volker@43 | 415 | B = S2a * QinL + C2a * UinL |
Volker@43 | 416 | # Stokes Input Vector rotation Eq. E.9 |
Volker@43 | 417 | C = C2ab * QinL - S2ab * UinL |
Volker@43 | 418 | D = S2ab * QinL + C2ab * UinL |
Volker@43 | 419 | |
Volker@43 | 420 | # emitter optics |
Volker@43 | 421 | CosE = np.cos(np.deg2rad(RetE)) |
Volker@43 | 422 | SinE = np.sin(np.deg2rad(RetE)) |
Volker@43 | 423 | ZiE = (1. - DiE ** 2) ** 0.5 |
Volker@43 | 424 | WiE = (1. - ZiE * CosE) |
Volker@43 | 425 | |
Volker@43 | 426 | # Stokes Input Vector after emitter optics equivalent to Eq. E.9 with already rotated input vector from Eq. E.4 |
Volker@43 | 427 | # b = beta |
Volker@43 | 428 | IinE = (IinL + DiE * C) |
Volker@43 | 429 | QinE = (C2b * DiE * IinL + A + S2b * (WiE * D - ZiE * SinE * VinL)) |
Volker@43 | 430 | UinE = (S2b * DiE * IinL + B - C2b * (WiE * D - ZiE * SinE * VinL)) |
Volker@43 | 431 | VinE = (-ZiE * SinE * D + ZiE * CosE * VinL) |
Volker@43 | 432 | |
Volker@43 | 433 | # Stokes Input Vector before receiver optics Eq. E.19 (after atmosphere F) |
Volker@43 | 434 | IinF = IinE |
Volker@43 | 435 | QinF = aCal * QinE |
Volker@43 | 436 | UinF = -aCal * UinE |
Volker@43 | 437 | VinF = (1. - 2. * aCal) * VinE |
Volker@43 | 438 | |
Volker@43 | 439 | # receiver optics |
Volker@43 | 440 | CosO = np.cos(np.deg2rad(RetO)) |
Volker@43 | 441 | SinO = np.sin(np.deg2rad(RetO)) |
Volker@43 | 442 | ZiO = (1. - DiO ** 2) ** 0.5 |
Volker@43 | 443 | WiO = (1. - ZiO * CosO) |
Volker@43 | 444 | |
Volker@43 | 445 | # calibrator |
Volker@43 | 446 | CosC = np.cos(np.deg2rad(RetC)) |
Volker@43 | 447 | SinC = np.sin(np.deg2rad(RetC)) |
Volker@43 | 448 | ZiC = (1. - DiC ** 2) ** 0.5 |
Volker@43 | 449 | WiC = (1. - ZiC * CosC) |
Volker@43 | 450 | |
Volker@43 | 451 | # Stokes Input Vector before the polarising beam splitter Eq. E.31 |
Volker@43 | 452 | A = C2g * QinE - S2g * UinE |
Volker@43 | 453 | B = S2g * QinE + C2g * UinE |
Volker@43 | 454 | |
Volker@43 | 455 | IinP = (IinE + DiO * aCal * A) |
Volker@43 | 456 | QinP = (C2g * DiO * IinE + aCal * QinE - S2g * (WiO * aCal * B + ZiO * SinO * (1. - 2. * aCal) * VinE)) |
Volker@43 | 457 | UinP = (S2g * DiO * IinE - aCal * UinE + C2g * (WiO * aCal * B + ZiO * SinO * (1. - 2. * aCal) * VinE)) |
Volker@43 | 458 | VinP = (ZiO * SinO * aCal * B + ZiO * CosO * (1. - 2. * aCal) * VinE) |
Volker@43 | 459 | |
Volker@43 | 460 | # ------------------------- |
Volker@43 | 461 | # F11 assuemd to be = 1 => measured: F11m = IinP / IinE with atrue |
Volker@43 | 462 | # F11sim = TiO*(IinE + DiO*atrue*A)/IinE |
Volker@43 | 463 | # ------------------------- |
Volker@43 | 464 | |
Volker@43 | 465 | # analyser |
Volker@43 | 466 | if (RS_RP_depend_on_TS_TP): |
Volker@43 | 467 | RS = 1. - TS |
Volker@43 | 468 | RP = 1. - TP |
Volker@43 | 469 | |
Volker@43 | 470 | TiT = 0.5 * (TP + TS) |
Volker@43 | 471 | DiT = (TP - TS) / (TP + TS) |
Volker@43 | 472 | ZiT = (1. - DiT ** 2) ** 0.5 |
Volker@43 | 473 | TiR = 0.5 * (RP + RS) |
Volker@43 | 474 | DiR = (RP - RS) / (RP + RS) |
Volker@43 | 475 | ZiR = (1. - DiR ** 2) ** 0.5 |
Volker@43 | 476 | CosT = np.cos(np.deg2rad(RetT)) |
Volker@43 | 477 | SinT = np.sin(np.deg2rad(RetT)) |
Volker@43 | 478 | CosR = np.cos(np.deg2rad(RetR)) |
Volker@43 | 479 | SinR = np.sin(np.deg2rad(RetR)) |
Volker@43 | 480 | |
Volker@43 | 481 | DaT = (1. - ERaT) / (1. + ERaT) |
Volker@43 | 482 | DaR = (1. - ERaR) / (1. + ERaR) |
Volker@43 | 483 | TaT = 0.5 * (1. + ERaT) |
Volker@43 | 484 | TaR = 0.5 * (1. + ERaR) |
Volker@43 | 485 | |
Volker@43 | 486 | S2aT = np.sin(np.deg2rad(h * 2 * RotaT)) |
Volker@43 | 487 | C2aT = np.cos(np.deg2rad(2 * RotaT)) |
Volker@43 | 488 | S2aR = np.sin(np.deg2rad(h * 2 * RotaR)) |
Volker@43 | 489 | C2aR = np.cos(np.deg2rad(2 * RotaR)) |
Volker@43 | 490 | |
Volker@43 | 491 | # Analyzer As before the PBS Eq. D.5; combined PBS and cleaning pol-filter |
Volker@43 | 492 | ATPT = (1. + C2aT * DaT * DiT) # unpolarized transmission correction |
Volker@43 | 493 | TTa = TiT * TaT * ATPT # unpolarized transmission |
Volker@43 | 494 | ATP1 = 1. |
Volker@43 | 495 | ATP2 = Y * (DiT + C2aT * DaT) / ATPT |
Volker@43 | 496 | ATP3 = Y * S2aT * DaT * ZiT * CosT / ATPT |
Volker@43 | 497 | ATP4 = S2aT * DaT * ZiT * SinT / ATPT |
Volker@43 | 498 | ATP = np.array([ATP1, ATP2, ATP3, ATP4]) |
Volker@43 | 499 | DTa = ATP2 * Y |
Volker@43 | 500 | |
Volker@43 | 501 | ARPT = (1 + C2aR * DaR * DiR) # unpolarized transmission correction |
Volker@43 | 502 | TRa = TiR * TaR * ARPT # unpolarized transmission |
Volker@43 | 503 | ARP1 = 1 |
Volker@43 | 504 | ARP2 = Y * (DiR + C2aR * DaR) / ARPT |
Volker@43 | 505 | ARP3 = Y * S2aR * DaR * ZiR * CosR / ARPT |
Volker@43 | 506 | ARP4 = S2aR * DaR * ZiR * SinR / ARPT |
Volker@43 | 507 | ARP = np.array([ARP1, ARP2, ARP3, ARP4]) |
Volker@43 | 508 | DRa = ARP2 * Y |
Volker@43 | 509 | |
Volker@43 | 510 | |
Volker@43 | 511 | # ---- Calculate signals and correction parameters for diffeent locations and calibrators |
Volker@43 | 512 | if LocC == 4: # Calibrator before the PBS |
Volker@43 | 513 | # print("Calibrator location not implemented yet") |
Volker@43 | 514 | |
Volker@43 | 515 | # S2ge = np.sin(np.deg2rad(2*RotO + h*2*RotC)) |
Volker@43 | 516 | # C2ge = np.cos(np.deg2rad(2*RotO + h*2*RotC)) |
Volker@43 | 517 | S2e = np.sin(np.deg2rad(h * 2 * RotC)) |
Volker@43 | 518 | C2e = np.cos(np.deg2rad(2 * RotC)) |
Volker@43 | 519 | # rotated AinP by epsilon Eq. C.3 |
Volker@43 | 520 | ATP2e = C2e * ATP2 + S2e * ATP3 |
Volker@43 | 521 | ATP3e = C2e * ATP3 - S2e * ATP2 |
Volker@43 | 522 | ARP2e = C2e * ARP2 + S2e * ARP3 |
Volker@43 | 523 | ARP3e = C2e * ARP3 - S2e * ARP2 |
Volker@43 | 524 | ATPe = np.array([ATP1, ATP2e, ATP3e, ATP4]) |
Volker@43 | 525 | ARPe = np.array([ARP1, ARP2e, ARP3e, ARP4]) |
Volker@43 | 526 | # Stokes Input Vector before the polarising beam splitter Eq. E.31 |
Volker@43 | 527 | A = C2g * QinE - S2g * UinE |
Volker@43 | 528 | B = S2g * QinE + C2g * UinE |
Volker@43 | 529 | # C = (WiO*aCal*B + ZiO*SinO*(1-2*aCal)*VinE) |
Volker@43 | 530 | Co = ZiO * SinO * VinE |
Volker@43 | 531 | Ca = (WiO * B - 2 * ZiO * SinO * VinE) |
Volker@43 | 532 | # C = Co + aCal*Ca |
Volker@43 | 533 | # IinP = (IinE + DiO*aCal*A) |
Volker@43 | 534 | # QinP = (C2g*DiO*IinE + aCal*QinE - S2g*C) |
Volker@43 | 535 | # UinP = (S2g*DiO*IinE - aCal*UinE + C2g*C) |
Volker@43 | 536 | # VinP = (ZiO*SinO*aCal*B + ZiO*CosO*(1-2*aCal)*VinE) |
Volker@43 | 537 | IinPo = IinE |
Volker@43 | 538 | QinPo = (C2g * DiO * IinE - S2g * Co) |
Volker@43 | 539 | UinPo = (S2g * DiO * IinE + C2g * Co) |
Volker@43 | 540 | VinPo = ZiO * CosO * VinE |
Volker@43 | 541 | |
Volker@43 | 542 | IinPa = DiO * A |
Volker@43 | 543 | QinPa = QinE - S2g * Ca |
Volker@43 | 544 | UinPa = -UinE + C2g * Ca |
Volker@43 | 545 | VinPa = ZiO * (SinO * B - 2 * CosO * VinE) |
Volker@43 | 546 | |
Volker@43 | 547 | IinP = IinPo + aCal * IinPa |
Volker@43 | 548 | QinP = QinPo + aCal * QinPa |
Volker@43 | 549 | UinP = UinPo + aCal * UinPa |
Volker@43 | 550 | VinP = VinPo + aCal * VinPa |
Volker@43 | 551 | # Stokes Input Vector before the polarising beam splitter rotated by epsilon Eq. C.3 |
Volker@43 | 552 | # QinPe = C2e*QinP + S2e*UinP |
Volker@43 | 553 | # UinPe = C2e*UinP - S2e*QinP |
Volker@43 | 554 | QinPoe = C2e * QinPo + S2e * UinPo |
Volker@43 | 555 | UinPoe = C2e * UinPo - S2e * QinPo |
Volker@43 | 556 | QinPae = C2e * QinPa + S2e * UinPa |
Volker@43 | 557 | UinPae = C2e * UinPa - S2e * QinPa |
Volker@43 | 558 | QinPe = C2e * QinP + S2e * UinP |
Volker@43 | 559 | UinPe = C2e * UinP - S2e * QinP |
Volker@43 | 560 | |
Volker@43 | 561 | # Calibration signals and Calibration correction K from measurements with LDRCal / aCal |
Volker@43 | 562 | if (TypeC == 2) or (TypeC == 1): # rotator calibration Eq. C.4 |
Volker@43 | 563 | # parameters for calibration with aCal |
Volker@43 | 564 | AT = ATP1 * IinP + h * ATP4 * VinP |
Volker@43 | 565 | BT = ATP3e * QinP - h * ATP2e * UinP |
Volker@43 | 566 | AR = ARP1 * IinP + h * ARP4 * VinP |
Volker@43 | 567 | BR = ARP3e * QinP - h * ARP2e * UinP |
Volker@43 | 568 | # Correction parameters for normal measurements; they are independent of LDR |
Volker@43 | 569 | if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out |
Volker@43 | 570 | IS1 = np.array([IinPo, QinPo, UinPo, VinPo]) |
Volker@43 | 571 | IS2 = np.array([IinPa, QinPa, UinPa, VinPa]) |
Volker@43 | 572 | GT = np.dot(ATP, IS1) |
Volker@43 | 573 | GR = np.dot(ARP, IS1) |
Volker@43 | 574 | HT = np.dot(ATP, IS2) |
Volker@43 | 575 | HR = np.dot(ARP, IS2) |
Volker@43 | 576 | else: |
Volker@43 | 577 | IS1 = np.array([IinPo, QinPo, UinPo, VinPo]) |
Volker@43 | 578 | IS2 = np.array([IinPa, QinPa, UinPa, VinPa]) |
Volker@43 | 579 | GT = np.dot(ATPe, IS1) |
Volker@43 | 580 | GR = np.dot(ARPe, IS1) |
Volker@43 | 581 | HT = np.dot(ATPe, IS2) |
Volker@43 | 582 | HR = np.dot(ARPe, IS2) |
Volker@43 | 583 | elif (TypeC == 3) or (TypeC == 4): # linear polariser calibration Eq. C.5 |
Volker@43 | 584 | # parameters for calibration with aCal |
Volker@43 | 585 | AT = ATP1 * IinP + ATP3e * UinPe + ZiC * CosC * (ATP2e * QinPe + ATP4 * VinP) |
Volker@43 | 586 | BT = DiC * (ATP1 * UinPe + ATP3e * IinP) - ZiC * SinC * (ATP2e * VinP - ATP4 * QinPe) |
Volker@43 | 587 | AR = ARP1 * IinP + ARP3e * UinPe + ZiC * CosC * (ARP2e * QinPe + ARP4 * VinP) |
Volker@43 | 588 | BR = DiC * (ARP1 * UinPe + ARP3e * IinP) - ZiC * SinC * (ARP2e * VinP - ARP4 * QinPe) |
Volker@43 | 589 | # Correction parameters for normal measurements; they are independent of LDR |
Volker@43 | 590 | if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out |
Volker@43 | 591 | IS1 = np.array([IinPo, QinPo, UinPo, VinPo]) |
Volker@43 | 592 | IS2 = np.array([IinPa, QinPa, UinPa, VinPa]) |
Volker@43 | 593 | GT = np.dot(ATP, IS1) |
Volker@43 | 594 | GR = np.dot(ARP, IS1) |
Volker@43 | 595 | HT = np.dot(ATP, IS2) |
Volker@43 | 596 | HR = np.dot(ARP, IS2) |
Volker@43 | 597 | else: |
Volker@43 | 598 | IS1e = np.array([IinPo + DiC * QinPoe, DiC * IinPo + QinPoe, ZiC * (CosC * UinPoe + SinC * VinPo), |
Volker@43 | 599 | -ZiC * (SinC * UinPoe - CosC * VinPo)]) |
Volker@43 | 600 | IS2e = np.array([IinPa + DiC * QinPae, DiC * IinPa + QinPae, ZiC * (CosC * UinPae + SinC * VinPa), |
Volker@43 | 601 | -ZiC * (SinC * UinPae - CosC * VinPa)]) |
Volker@43 | 602 | GT = np.dot(ATPe, IS1e) |
Volker@43 | 603 | GR = np.dot(ARPe, IS1e) |
Volker@43 | 604 | HT = np.dot(ATPe, IS2e) |
Volker@43 | 605 | HR = np.dot(ARPe, IS2e) |
Volker@43 | 606 | elif (TypeC == 6): # diattenuator calibration +-22.5° rotated_diattenuator_X22x5deg.odt |
Volker@43 | 607 | # parameters for calibration with aCal |
Volker@43 | 608 | AT = ATP1 * IinP + sqr05 * DiC * (ATP1 * QinPe + ATP2e * IinP) + (1. - 0.5 * WiC) * ( |
Volker@43 | 609 | ATP2e * QinPe + ATP3e * UinPe) + ZiC * (sqr05 * SinC * (ATP3e * VinP - ATP4 * UinPe) + ATP4 * CosC * VinP) |
Volker@43 | 610 | BT = sqr05 * DiC * (ATP1 * UinPe + ATP3e * IinP) + 0.5 * WiC * ( |
Volker@43 | 611 | ATP2e * UinPe + ATP3e * QinPe) - sqr05 * ZiC * SinC * (ATP2e * VinP - ATP4 * QinPe) |
Volker@43 | 612 | AR = ARP1 * IinP + sqr05 * DiC * (ARP1 * QinPe + ARP2e * IinP) + (1. - 0.5 * WiC) * ( |
Volker@43 | 613 | ARP2e * QinPe + ARP3e * UinPe) + ZiC * (sqr05 * SinC * (ARP3e * VinP - ARP4 * UinPe) + ARP4 * CosC * VinP) |
Volker@43 | 614 | BR = sqr05 * DiC * (ARP1 * UinPe + ARP3e * IinP) + 0.5 * WiC * ( |
Volker@43 | 615 | ARP2e * UinPe + ARP3e * QinPe) - sqr05 * ZiC * SinC * (ARP2e * VinP - ARP4 * QinPe) |
Volker@43 | 616 | # Correction parameters for normal measurements; they are independent of LDR |
Volker@43 | 617 | if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out |
Volker@43 | 618 | IS1 = np.array([IinPo, QinPo, UinPo, VinPo]) |
Volker@43 | 619 | IS2 = np.array([IinPa, QinPa, UinPa, VinPa]) |
Volker@43 | 620 | GT = np.dot(ATP, IS1) |
Volker@43 | 621 | GR = np.dot(ARP, IS1) |
Volker@43 | 622 | HT = np.dot(ATP, IS2) |
Volker@43 | 623 | HR = np.dot(ARP, IS2) |
Volker@43 | 624 | else: |
Volker@43 | 625 | IS1e = np.array([IinPo + DiC * QinPoe, DiC * IinPo + QinPoe, ZiC * (CosC * UinPoe + SinC * VinPo), |
Volker@43 | 626 | -ZiC * (SinC * UinPoe - CosC * VinPo)]) |
Volker@43 | 627 | IS2e = np.array([IinPa + DiC * QinPae, DiC * IinPa + QinPae, ZiC * (CosC * UinPae + SinC * VinPa), |
Volker@43 | 628 | -ZiC * (SinC * UinPae - CosC * VinPa)]) |
Volker@43 | 629 | GT = np.dot(ATPe, IS1e) |
Volker@43 | 630 | GR = np.dot(ARPe, IS1e) |
Volker@43 | 631 | HT = np.dot(ATPe, IS2e) |
Volker@43 | 632 | HR = np.dot(ARPe, IS2e) |
Volker@43 | 633 | else: |
Volker@43 | 634 | print("Calibrator not implemented yet") |
Volker@43 | 635 | sys.exit() |
Volker@43 | 636 | |
Volker@43 | 637 | elif LocC == 3: # C before receiver optics Eq.57 |
Volker@43 | 638 | |
Volker@43 | 639 | # S2ge = np.sin(np.deg2rad(2*RotO - 2*RotC)) |
Volker@43 | 640 | # C2ge = np.cos(np.deg2rad(2*RotO - 2*RotC)) |
Volker@43 | 641 | S2e = np.sin(np.deg2rad(2. * RotC)) |
Volker@43 | 642 | C2e = np.cos(np.deg2rad(2. * RotC)) |
Volker@43 | 643 | |
Volker@43 | 644 | # As with C before the receiver optics (rotated_diattenuator_X22x5deg.odt) |
Volker@43 | 645 | AF1 = np.array([1., C2g * DiO, S2g * DiO, 0.]) |
Volker@43 | 646 | AF2 = np.array([C2g * DiO, 1. - S2g ** 2 * WiO, S2g * C2g * WiO, -S2g * ZiO * SinO]) |
Volker@43 | 647 | AF3 = np.array([S2g * DiO, S2g * C2g * WiO, 1. - C2g ** 2 * WiO, C2g * ZiO * SinO]) |
Volker@43 | 648 | AF4 = np.array([0., S2g * SinO, -C2g * SinO, CosO]) |
Volker@43 | 649 | |
Volker@43 | 650 | ATF = (ATP1 * AF1 + ATP2 * AF2 + ATP3 * AF3 + ATP4 * AF4) |
Volker@43 | 651 | ARF = (ARP1 * AF1 + ARP2 * AF2 + ARP3 * AF3 + ARP4 * AF4) |
Volker@43 | 652 | ATF2 = ATF[1] |
Volker@43 | 653 | ATF3 = ATF[2] |
Volker@43 | 654 | ARF2 = ARF[1] |
Volker@43 | 655 | ARF3 = ARF[2] |
Volker@43 | 656 | |
Volker@43 | 657 | # rotated AinF by epsilon |
Volker@43 | 658 | ATF1 = ATF[0] |
Volker@43 | 659 | ATF4 = ATF[3] |
Volker@43 | 660 | ATF2e = C2e * ATF[1] + S2e * ATF[2] |
Volker@43 | 661 | ATF3e = C2e * ATF[2] - S2e * ATF[1] |
Volker@43 | 662 | ARF1 = ARF[0] |
Volker@43 | 663 | ARF4 = ARF[3] |
Volker@43 | 664 | ARF2e = C2e * ARF[1] + S2e * ARF[2] |
Volker@43 | 665 | ARF3e = C2e * ARF[2] - S2e * ARF[1] |
Volker@43 | 666 | |
Volker@43 | 667 | ATFe = np.array([ATF1, ATF2e, ATF3e, ATF4]) |
Volker@43 | 668 | ARFe = np.array([ARF1, ARF2e, ARF3e, ARF4]) |
Volker@43 | 669 | |
Volker@43 | 670 | QinEe = C2e * QinE + S2e * UinE |
Volker@43 | 671 | UinEe = C2e * UinE - S2e * QinE |
Volker@43 | 672 | |
Volker@43 | 673 | # Stokes Input Vector before receiver optics Eq. E.19 (after atmosphere F) |
Volker@43 | 674 | IinF = IinE |
Volker@43 | 675 | QinF = aCal * QinE |
Volker@43 | 676 | UinF = -aCal * UinE |
Volker@43 | 677 | VinF = (1. - 2. * aCal) * VinE |
Volker@43 | 678 | |
Volker@43 | 679 | IinFo = IinE |
Volker@43 | 680 | QinFo = 0. |
Volker@43 | 681 | UinFo = 0. |
Volker@43 | 682 | VinFo = VinE |
Volker@43 | 683 | |
Volker@43 | 684 | IinFa = 0. |
Volker@43 | 685 | QinFa = QinE |
Volker@43 | 686 | UinFa = -UinE |
Volker@43 | 687 | VinFa = -2. * VinE |
Volker@43 | 688 | |
Volker@43 | 689 | # Stokes Input Vector before receiver optics rotated by epsilon Eq. C.3 |
Volker@43 | 690 | QinFe = C2e * QinF + S2e * UinF |
Volker@43 | 691 | UinFe = C2e * UinF - S2e * QinF |
Volker@43 | 692 | QinFoe = C2e * QinFo + S2e * UinFo |
Volker@43 | 693 | UinFoe = C2e * UinFo - S2e * QinFo |
Volker@43 | 694 | QinFae = C2e * QinFa + S2e * UinFa |
Volker@43 | 695 | UinFae = C2e * UinFa - S2e * QinFa |
Volker@43 | 696 | |
Volker@43 | 697 | # Calibration signals and Calibration correction K from measurements with LDRCal / aCal |
Volker@43 | 698 | if (TypeC == 2) or (TypeC == 1): # rotator calibration Eq. C.4 |
Volker@43 | 699 | # parameters for calibration with aCal |
Volker@43 | 700 | AT = ATF1 * IinF + ATF4 * h * VinF |
Volker@43 | 701 | BT = ATF3e * QinF - ATF2e * h * UinF |
Volker@43 | 702 | AR = ARF1 * IinF + ARF4 * h * VinF |
Volker@43 | 703 | BR = ARF3e * QinF - ARF2e * h * UinF |
Volker@43 | 704 | # Correction parameters for normal measurements; they are independent of LDR |
Volker@43 | 705 | if (not RotationErrorEpsilonForNormalMeasurements): |
Volker@43 | 706 | GT = ATF1 * IinE + ATF4 * VinE |
Volker@43 | 707 | GR = ARF1 * IinE + ARF4 * VinE |
Volker@43 | 708 | HT = ATF2 * QinE - ATF3 * UinE - ATF4 * 2 * VinE |
Volker@43 | 709 | HR = ARF2 * QinE - ARF3 * UinE - ARF4 * 2 * VinE |
Volker@43 | 710 | else: |
Volker@43 | 711 | GT = ATF1 * IinE + ATF4 * h * VinE |
Volker@43 | 712 | GR = ARF1 * IinE + ARF4 * h * VinE |
Volker@43 | 713 | HT = ATF2e * QinE - ATF3e * h * UinE - ATF4 * h * 2 * VinE |
Volker@43 | 714 | HR = ARF2e * QinE - ARF3e * h * UinE - ARF4 * h * 2 * VinE |
Volker@43 | 715 | elif (TypeC == 3) or (TypeC == 4): # linear polariser calibration Eq. C.5 |
Volker@43 | 716 | # p = +45°, m = -45° |
Volker@43 | 717 | IF1e = np.array([IinF, ZiC * CosC * QinFe, UinFe, ZiC * CosC * VinF]) |
Volker@43 | 718 | IF2e = np.array([DiC * UinFe, -ZiC * SinC * VinF, DiC * IinF, ZiC * SinC * QinFe]) |
Volker@43 | 719 | AT = np.dot(ATFe, IF1e) |
Volker@43 | 720 | AR = np.dot(ARFe, IF1e) |
Volker@43 | 721 | BT = np.dot(ATFe, IF2e) |
Volker@43 | 722 | BR = np.dot(ARFe, IF2e) |
Volker@43 | 723 | |
Volker@43 | 724 | # Correction parameters for normal measurements; they are independent of LDR --- the same as for TypeC = 6 |
Volker@43 | 725 | if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out |
Volker@43 | 726 | IS1 = np.array([IinE, 0., 0., VinE]) |
Volker@43 | 727 | IS2 = np.array([0., QinE, -UinE, -2. * VinE]) |
Volker@43 | 728 | GT = np.dot(ATF, IS1) |
Volker@43 | 729 | GR = np.dot(ARF, IS1) |
Volker@43 | 730 | HT = np.dot(ATF, IS2) |
Volker@43 | 731 | HR = np.dot(ARF, IS2) |
Volker@43 | 732 | else: |
Volker@43 | 733 | IS1e = np.array([IinFo + DiC * QinFoe, DiC * IinFo + QinFoe, ZiC * (CosC * UinFoe + SinC * VinFo), |
Volker@43 | 734 | -ZiC * (SinC * UinFoe - CosC * VinFo)]) |
Volker@43 | 735 | IS2e = np.array([IinFa + DiC * QinFae, DiC * IinFa + QinFae, ZiC * (CosC * UinFae + SinC * VinFa), |
Volker@43 | 736 | -ZiC * (SinC * UinFae - CosC * VinFa)]) |
Volker@43 | 737 | GT = np.dot(ATFe, IS1e) |
Volker@43 | 738 | GR = np.dot(ARFe, IS1e) |
Volker@43 | 739 | HT = np.dot(ATFe, IS2e) |
Volker@43 | 740 | HR = np.dot(ARFe, IS2e) |
Volker@43 | 741 | |
Volker@43 | 742 | elif (TypeC == 6): # diattenuator calibration +-22.5° rotated_diattenuator_X22x5deg.odt |
Volker@43 | 743 | # parameters for calibration with aCal |
Volker@43 | 744 | IF1e = np.array([IinF + sqr05 * DiC * QinFe, sqr05 * DiC * IinF + (1. - 0.5 * WiC) * QinFe, |
Volker@43 | 745 | (1. - 0.5 * WiC) * UinFe + sqr05 * ZiC * SinC * VinF, |
Volker@43 | 746 | -sqr05 * ZiC * SinC * UinFe + ZiC * CosC * VinF]) |
Volker@43 | 747 | IF2e = np.array([sqr05 * DiC * UinFe, 0.5 * WiC * UinFe - sqr05 * ZiC * SinC * VinF, |
Volker@43 | 748 | sqr05 * DiC * IinF + 0.5 * WiC * QinFe, sqr05 * ZiC * SinC * QinFe]) |
Volker@43 | 749 | AT = np.dot(ATFe, IF1e) |
Volker@43 | 750 | AR = np.dot(ARFe, IF1e) |
Volker@43 | 751 | BT = np.dot(ATFe, IF2e) |
Volker@43 | 752 | BR = np.dot(ARFe, IF2e) |
Volker@43 | 753 | |
Volker@43 | 754 | # Correction parameters for normal measurements; they are independent of LDR |
Volker@43 | 755 | if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out |
Volker@43 | 756 | # IS1 = np.array([IinE,0,0,VinE]) |
Volker@43 | 757 | # IS2 = np.array([0,QinE,-UinE,-2*VinE]) |
Volker@43 | 758 | IS1 = np.array([IinFo, 0., 0., VinFo]) |
Volker@43 | 759 | IS2 = np.array([0., QinFa, UinFa, VinFa]) |
Volker@43 | 760 | GT = np.dot(ATF, IS1) |
Volker@43 | 761 | GR = np.dot(ARF, IS1) |
Volker@43 | 762 | HT = np.dot(ATF, IS2) |
Volker@43 | 763 | HR = np.dot(ARF, IS2) |
Volker@43 | 764 | else: |
Volker@43 | 765 | IS1e = np.array([IinFo + DiC * QinFoe, DiC * IinFo + QinFoe, ZiC * (CosC * UinFoe + SinC * VinFo), |
Volker@43 | 766 | -ZiC * (SinC * UinFoe - CosC * VinFo)]) |
Volker@43 | 767 | IS2e = np.array([IinFa + DiC * QinFae, DiC * IinFa + QinFae, ZiC * (CosC * UinFae + SinC * VinFa), |
Volker@43 | 768 | -ZiC * (SinC * UinFae - CosC * VinFa)]) |
Volker@43 | 769 | # IS1e = np.array([IinFo,0,0,VinFo]) |
Volker@43 | 770 | # IS2e = np.array([0,QinFae,UinFae,VinFa]) |
Volker@43 | 771 | GT = np.dot(ATFe, IS1e) |
Volker@43 | 772 | GR = np.dot(ARFe, IS1e) |
Volker@43 | 773 | HT = np.dot(ATFe, IS2e) |
Volker@43 | 774 | HR = np.dot(ARFe, IS2e) |
Volker@43 | 775 | |
Volker@43 | 776 | else: |
Volker@43 | 777 | print('Calibrator not implemented yet') |
Volker@43 | 778 | sys.exit() |
Volker@43 | 779 | |
Volker@43 | 780 | elif LocC == 2: # C behind emitter optics Eq.57 ------------------------------------------------------- |
Volker@43 | 781 | # print("Calibrator location not implemented yet") |
Volker@43 | 782 | S2e = np.sin(np.deg2rad(2. * RotC)) |
Volker@43 | 783 | C2e = np.cos(np.deg2rad(2. * RotC)) |
Volker@43 | 784 | |
Volker@43 | 785 | # AS with C before the receiver optics (see document rotated_diattenuator_X22x5deg.odt) |
Volker@43 | 786 | AF1 = np.array([1, C2g * DiO, S2g * DiO, 0.]) |
Volker@43 | 787 | AF2 = np.array([C2g * DiO, 1. - S2g ** 2 * WiO, S2g * C2g * WiO, -S2g * ZiO * SinO]) |
Volker@43 | 788 | AF3 = np.array([S2g * DiO, S2g * C2g * WiO, 1. - C2g ** 2 * WiO, C2g * ZiO * SinO]) |
Volker@43 | 789 | AF4 = np.array([0., S2g * SinO, -C2g * SinO, CosO]) |
Volker@43 | 790 | |
Volker@43 | 791 | ATF = (ATP1 * AF1 + ATP2 * AF2 + ATP3 * AF3 + ATP4 * AF4) |
Volker@43 | 792 | ARF = (ARP1 * AF1 + ARP2 * AF2 + ARP3 * AF3 + ARP4 * AF4) |
Volker@43 | 793 | ATF1 = ATF[0] |
Volker@43 | 794 | ATF2 = ATF[1] |
Volker@43 | 795 | ATF3 = ATF[2] |
Volker@43 | 796 | ATF4 = ATF[3] |
Volker@43 | 797 | ARF1 = ARF[0] |
Volker@43 | 798 | ARF2 = ARF[1] |
Volker@43 | 799 | ARF3 = ARF[2] |
Volker@43 | 800 | ARF4 = ARF[3] |
Volker@43 | 801 | |
Volker@43 | 802 | # AS with C behind the emitter |
Volker@43 | 803 | # terms without aCal |
Volker@43 | 804 | ATE1o, ARE1o = ATF1, ARF1 |
Volker@43 | 805 | ATE2o, ARE2o = 0., 0. |
Volker@43 | 806 | ATE3o, ARE3o = 0., 0. |
Volker@43 | 807 | ATE4o, ARE4o = ATF4, ARF4 |
Volker@43 | 808 | # terms with aCal |
Volker@43 | 809 | ATE1a, ARE1a = 0., 0. |
Volker@43 | 810 | ATE2a, ARE2a = ATF2, ARF2 |
Volker@43 | 811 | ATE3a, ARE3a = -ATF3, -ARF3 |
Volker@43 | 812 | ATE4a, ARE4a = -2. * ATF4, -2. * ARF4 |
Volker@43 | 813 | # rotated AinEa by epsilon |
Volker@43 | 814 | ATE2ae = C2e * ATF2 + S2e * ATF3 |
Volker@43 | 815 | ATE3ae = -S2e * ATF2 - C2e * ATF3 |
Volker@43 | 816 | ARE2ae = C2e * ARF2 + S2e * ARF3 |
Volker@43 | 817 | ARE3ae = -S2e * ARF2 - C2e * ARF3 |
Volker@43 | 818 | |
Volker@43 | 819 | ATE1 = ATE1o |
Volker@43 | 820 | ATE2e = aCal * ATE2ae |
Volker@43 | 821 | ATE3e = aCal * ATE3ae |
Volker@43 | 822 | ATE4 = (1 - 2 * aCal) * ATF4 |
Volker@43 | 823 | ARE1 = ARE1o |
Volker@43 | 824 | ARE2e = aCal * ARE2ae |
Volker@43 | 825 | ARE3e = aCal * ARE3ae |
Volker@43 | 826 | ARE4 = (1 - 2 * aCal) * ARF4 |
Volker@43 | 827 | |
Volker@43 | 828 | # rotated IinE |
Volker@43 | 829 | QinEe = C2e * QinE + S2e * UinE |
Volker@43 | 830 | UinEe = C2e * UinE - S2e * QinE |
Volker@43 | 831 | |
Volker@43 | 832 | # Calibration signals and Calibration correction K from measurements with LDRCal / aCal |
Volker@43 | 833 | if (TypeC == 2) or (TypeC == 1): # +++++++++ rotator calibration Eq. C.4 |
Volker@43 | 834 | AT = ATE1o * IinE + (ATE4o + aCal * ATE4a) * h * VinE |
Volker@43 | 835 | BT = aCal * (ATE3ae * QinEe - ATE2ae * h * UinEe) |
Volker@43 | 836 | AR = ARE1o * IinE + (ARE4o + aCal * ARE4a) * h * VinE |
Volker@43 | 837 | BR = aCal * (ARE3ae * QinEe - ARE2ae * h * UinEe) |
Volker@43 | 838 | |
Volker@43 | 839 | # Correction parameters for normal measurements; they are independent of LDR |
Volker@43 | 840 | if (not RotationErrorEpsilonForNormalMeasurements): |
Volker@43 | 841 | # Stokes Input Vector before receiver optics Eq. E.19 (after atmosphere F) |
Volker@43 | 842 | GT = ATE1o * IinE + ATE4o * h * VinE |
Volker@43 | 843 | GR = ARE1o * IinE + ARE4o * h * VinE |
Volker@43 | 844 | HT = ATE2a * QinE + ATE3a * h * UinEe + ATE4a * h * VinE |
Volker@43 | 845 | HR = ARE2a * QinE + ARE3a * h * UinEe + ARE4a * h * VinE |
Volker@43 | 846 | else: |
Volker@43 | 847 | GT = ATE1o * IinE + ATE4o * h * VinE |
Volker@43 | 848 | GR = ARE1o * IinE + ARE4o * h * VinE |
Volker@43 | 849 | HT = ATE2ae * QinE + ATE3ae * h * UinEe + ATE4a * h * VinE |
Volker@43 | 850 | HR = ARE2ae * QinE + ARE3ae * h * UinEe + ARE4a * h * VinE |
Volker@43 | 851 | |
Volker@43 | 852 | elif (TypeC == 3) or (TypeC == 4): # +++++++++ linear polariser calibration Eq. C.5 |
Volker@43 | 853 | # p = +45°, m = -45° |
Volker@43 | 854 | AT = ATE1 * IinE + ZiC * CosC * (ATE2e * QinEe + ATE4 * VinE) + ATE3e * UinEe |
Volker@43 | 855 | BT = DiC * (ATE1 * UinEe + ATE3e * IinE) + ZiC * SinC * (ATE4 * QinEe - ATE2e * VinE) |
Volker@43 | 856 | AR = ARE1 * IinE + ZiC * CosC * (ARE2e * QinEe + ARE4 * VinE) + ARE3e * UinEe |
Volker@43 | 857 | BR = DiC * (ARE1 * UinEe + ARE3e * IinE) + ZiC * SinC * (ARE4 * QinEe - ARE2e * VinE) |
Volker@43 | 858 | |
Volker@43 | 859 | # Correction parameters for normal measurements; they are independent of LDR |
Volker@43 | 860 | if (not RotationErrorEpsilonForNormalMeasurements): |
Volker@43 | 861 | # Stokes Input Vector before receiver optics Eq. E.19 (after atmosphere F) |
Volker@43 | 862 | GT = ATE1o * IinE + ATE4o * VinE |
Volker@43 | 863 | GR = ARE1o * IinE + ARE4o * VinE |
Volker@43 | 864 | HT = ATE2a * QinE + ATE3a * UinE + ATE4a * VinE |
Volker@43 | 865 | HR = ARE2a * QinE + ARE3a * UinE + ARE4a * VinE |
Volker@43 | 866 | else: |
Volker@43 | 867 | D = IinE + DiC * QinEe |
Volker@43 | 868 | A = DiC * IinE + QinEe |
Volker@43 | 869 | B = ZiC * (CosC * UinEe + SinC * VinE) |
Volker@43 | 870 | C = -ZiC * (SinC * UinEe - CosC * VinE) |
Volker@43 | 871 | GT = ATE1o * D + ATE4o * C |
Volker@43 | 872 | GR = ARE1o * D + ARE4o * C |
Volker@43 | 873 | HT = ATE2a * A + ATE3a * B + ATE4a * C |
Volker@43 | 874 | HR = ARE2a * A + ARE3a * B + ARE4a * C |
Volker@43 | 875 | |
Volker@43 | 876 | elif (TypeC == 6): # real HWP calibration +-22.5° rotated_diattenuator_X22x5deg.odt |
Volker@43 | 877 | # p = +22.5°, m = -22.5° |
Volker@43 | 878 | IE1e = np.array([IinE + sqr05 * DiC * QinEe, sqr05 * DiC * IinE + (1 - 0.5 * WiC) * QinEe, |
Volker@43 | 879 | (1 - 0.5 * WiC) * UinEe + sqr05 * ZiC * SinC * VinE, |
Volker@43 | 880 | -sqr05 * ZiC * SinC * UinEe + ZiC * CosC * VinE]) |
Volker@43 | 881 | IE2e = np.array([sqr05 * DiC * UinEe, 0.5 * WiC * UinEe - sqr05 * ZiC * SinC * VinE, |
Volker@43 | 882 | sqr05 * DiC * IinE + 0.5 * WiC * QinEe, sqr05 * ZiC * SinC * QinEe]) |
Volker@43 | 883 | ATEe = np.array([ATE1, ATE2e, ATE3e, ATE4]) |
Volker@43 | 884 | AREe = np.array([ARE1, ARE2e, ARE3e, ARE4]) |
Volker@43 | 885 | AT = np.dot(ATEe, IE1e) |
Volker@43 | 886 | AR = np.dot(AREe, IE1e) |
Volker@43 | 887 | BT = np.dot(ATEe, IE2e) |
Volker@43 | 888 | BR = np.dot(AREe, IE2e) |
Volker@43 | 889 | |
Volker@43 | 890 | # Correction parameters for normal measurements; they are independent of LDR |
Volker@43 | 891 | if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out |
Volker@43 | 892 | GT = ATE1o * IinE + ATE4o * VinE |
Volker@43 | 893 | GR = ARE1o * IinE + ARE4o * VinE |
Volker@43 | 894 | HT = ATE2a * QinE + ATE3a * UinE + ATE4a * VinE |
Volker@43 | 895 | HR = ARE2a * QinE + ARE3a * UinE + ARE4a * VinE |
Volker@43 | 896 | else: |
Volker@43 | 897 | D = IinE + DiC * QinEe |
Volker@43 | 898 | A = DiC * IinE + QinEe |
Volker@43 | 899 | B = ZiC * (CosC * UinEe + SinC * VinE) |
Volker@43 | 900 | C = -ZiC * (SinC * UinEe - CosC * VinE) |
Volker@43 | 901 | GT = ATE1o * D + ATE4o * C |
Volker@43 | 902 | GR = ARE1o * D + ARE4o * C |
Volker@43 | 903 | HT = ATE2a * A + ATE3a * B + ATE4a * C |
Volker@43 | 904 | HR = ARE2a * A + ARE3a * B + ARE4a * C |
Volker@43 | 905 | |
Volker@43 | 906 | else: |
Volker@43 | 907 | print('Calibrator not implemented yet') |
Volker@43 | 908 | sys.exit() |
Volker@43 | 909 | |
Volker@43 | 910 | else: |
Volker@43 | 911 | print("Calibrator location not implemented yet") |
Volker@43 | 912 | sys.exit() |
Volker@43 | 913 | |
Volker@43 | 914 | # Determination of the correction K of the calibration factor. |
Volker@43 | 915 | IoutTp = TTa * TiC * TiO * TiE * (AT + BT) |
Volker@43 | 916 | IoutTm = TTa * TiC * TiO * TiE * (AT - BT) |
Volker@43 | 917 | IoutRp = TRa * TiC * TiO * TiE * (AR + BR) |
Volker@43 | 918 | IoutRm = TRa * TiC * TiO * TiE * (AR - BR) |
Volker@43 | 919 | # --- Results and Corrections; electronic etaR and etaT are assumed to be 1 |
Volker@43 | 920 | Etapx = IoutRp / IoutTp |
Volker@43 | 921 | Etamx = IoutRm / IoutTm |
Volker@43 | 922 | Etax = (Etapx * Etamx) ** 0.5 |
Volker@43 | 923 | |
Volker@43 | 924 | 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 |
Volker@43 | 925 | K = Etax / Eta |
Volker@43 | 926 | |
Volker@43 | 927 | # For comparison with Volkers Libreoffice Müller Matrix spreadsheet |
Volker@43 | 928 | # Eta_test_p = (IoutRp/IoutTp) |
Volker@43 | 929 | # Eta_test_m = (IoutRm/IoutTm) |
Volker@43 | 930 | # Eta_test = (Eta_test_p*Eta_test_m)**0.5 |
Volker@43 | 931 | |
Volker@43 | 932 | # ----- random error calculation ---------- |
Volker@43 | 933 | # noise must be calculated with the photon counts of measured signals; |
Volker@43 | 934 | # relative standard deviation of calibration signals with LDRcal; assumed to be statisitcally independent |
Volker@43 | 935 | # normalised noise errors |
Volker@43 | 936 | if (CalcFrom0deg): |
Volker@43 | 937 | dIoutTp = (NCalT * IoutTp) ** -0.5 |
Volker@43 | 938 | dIoutTm = (NCalT * IoutTm) ** -0.5 |
Volker@43 | 939 | dIoutRp = (NCalR * IoutRp) ** -0.5 |
Volker@43 | 940 | dIoutRm = (NCalR * IoutRm) ** -0.5 |
Volker@43 | 941 | else: |
Volker@43 | 942 | dIoutTp = (NCalT ** -0.5) |
Volker@43 | 943 | dIoutTm = (NCalT ** -0.5) |
Volker@43 | 944 | dIoutRp = (NCalR ** -0.5) |
Volker@43 | 945 | dIoutRm = (NCalR ** -0.5) |
Volker@43 | 946 | # Forward simulated 0°-signals with LDRCal with atrue; from input file |
Volker@43 | 947 | |
Volker@43 | 948 | It = TTa * TiO * TiE * (GT + atrue * HT) |
Volker@43 | 949 | Ir = TRa * TiO * TiE * (GR + atrue * HR) |
Volker@43 | 950 | # relative standard deviation of standard signals with LDRmeas; assumed to be statisitcally independent |
Volker@43 | 951 | if (CalcFrom0deg): # this works! |
Volker@43 | 952 | dIt = ((It * NI * eFacT) ** -0.5) |
Volker@43 | 953 | dIr = ((Ir * NI * eFacR) ** -0.5) |
Volker@43 | 954 | ''' |
Volker@43 | 955 | dIt = ((NCalT * It / IoutTp * NILfac / TCalT) ** -0.5) |
Volker@43 | 956 | dIr = ((NCalR * Ir / IoutRp * NILfac / TCalR) ** -0.5) |
Volker@43 | 957 | ''' |
Volker@43 | 958 | else: # does this work? Why not as above? |
Volker@43 | 959 | dIt = ((NCalT * 2 * NILfac / TCalT ) ** -0.5) |
Volker@43 | 960 | dIr = ((NCalR * 2 * NILfac / TCalR) ** -0.5) |
Volker@43 | 961 | |
Volker@43 | 962 | # ----- Forward simulated LDRsim = 1/Eta*Ir/It # simulated LDR* with Y from input file |
Volker@43 | 963 | LDRsim = Ir / It # simulated uncorrected LDR with Y from input file |
Volker@43 | 964 | # Corrected LDRsimCorr from forward simulated LDRsim (atrue) |
Volker@43 | 965 | # LDRsimCorr = (1./Eta*LDRsim*(GT+HT)-(GR+HR))/((GR-HR)-1./Eta*LDRsim*(GT-HT)) |
Volker@43 | 966 | ''' |
Volker@43 | 967 | if ((Y == -1.) and (abs(RotL0) < 45)) or ((Y == +1.) and (abs(RotL0) > 45)): |
Volker@43 | 968 | LDRsimx = 1. / LDRsim / Etax |
Volker@43 | 969 | else: |
Volker@43 | 970 | LDRsimx = LDRsim / Etax |
Volker@43 | 971 | ''' |
Volker@43 | 972 | LDRsimx = LDRsim |
Volker@43 | 973 | |
Volker@43 | 974 | # The following is correct without doubt |
Volker@43 | 975 | # LDRCorr = (LDRsim/(Etax/K)*(GT+HT)-(GR+HR))/((GR-HR)-LDRsim/(Etax/K)*(GT-HT)) |
Volker@43 | 976 | |
Volker@43 | 977 | # The following is a test whether the equations for calibration Etax and normal signal (GHK, LDRsim) are consistent |
Volker@43 | 978 | LDRCorr = (LDRsim / (Etax / K) * (GT + HT) - (GR + HR)) / ((GR - HR) - LDRsim / (Etax / K) * (GT - HT)) |
Volker@43 | 979 | # here we could also use Eta instead of Etax / K => how to test whether Etax is correct? => comparison with MüllerMatrix simulation! |
Volker@43 | 980 | # Without any correction: only measured It, Ir, EtaX are used |
Volker@43 | 981 | LDRunCorr = LDRsim / Etax |
Volker@43 | 982 | # 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@43 | 983 | |
Volker@43 | 984 | #LDRCorr = LDRsimx # for test only |
Volker@43 | 985 | |
Volker@43 | 986 | 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 |
Volker@43 | 987 | |
Volker@43 | 988 | return (IoutTp, IoutTm, IoutRp, IoutRm, It, Ir, dIoutTp, dIoutTm, dIoutRp, dIoutRm, dIt, dIr, |
Volker@43 | 989 | GT, HT, GR, HR, K, Eta, LDRsimx, LDRCorr, DTa, DRa, TTa, TRa, F11sim, LDRunCorr) |
Volker@43 | 990 | |
Volker@43 | 991 | |
Volker@43 | 992 | |
Volker@43 | 993 | # ******************************************************************************************************************************* |
Volker@43 | 994 | |
Volker@43 | 995 | # --- CALC with assumed true parameters from the input file |
Volker@43 | 996 | LDRtrue = LDRtrue2 |
Volker@43 | 997 | IoutTp0, IoutTm0, IoutRp0, IoutRm0, It0, Ir0, dIoutTp0, dIoutTm0, dIoutRp0, dIoutRm0, dIt0, dIr0, \ |
Volker@43 | 998 | GT0, HT0, GR0, HR0, K0, Eta0, LDRsimx, LDRCorr, DTa0, DRa0, TTa0, TRa0, F11sim0, LDRunCorr = \ |
Volker@43 | 999 | Calc(TCalT, TCalR, NCalT, NCalR, Qin0, Vin0, RotL0, RotE0, RetE0, DiE0, |
Volker@43 | 1000 | RotO0, RetO0, DiO0, RotC0, RetC0, DiC0, TP0, TS0, RP0, RS0, |
Volker@43 | 1001 | ERaT0, RotaT0, RetT0, ERaR0, RotaR0, RetR0, LDRCal0) |
Volker@43 | 1002 | Etax0 = K0 * Eta0 |
Volker@43 | 1003 | Etapx0 = IoutRp0 / IoutTp0 |
Volker@43 | 1004 | Etamx0 = IoutRm0 / IoutTm0 |
Volker@43 | 1005 | # --- Print parameters to console and output file |
Volker@43 | 1006 | OutputFile = 'output_' + InputFile[0:-3] + '_' + fname[0:-3] +'.dat' |
Volker@43 | 1007 | with open('output_files\\' + OutputFile, 'w') as f: |
Volker@43 | 1008 | with redirect_stdout(f): |
Volker@43 | 1009 | print("From ", dname) |
Volker@43 | 1010 | print("Running ", fname) |
Volker@43 | 1011 | print("Reading input file ", InputFile) # , " for Lidar system :", EID, ", ", LID) |
Volker@43 | 1012 | print("for Lidar system: ", EID, ", ", LID) |
Volker@43 | 1013 | # --- Print iput information********************************* |
Volker@43 | 1014 | print(" --- Input parameters: value ±error / ±steps ----------------------") |
Volker@43 | 1015 | print("{0:7}{1:17} {2:6.4f}±{3:7.4f}/{4:2d}".format("Laser: ", "Qin =", Qin0, dQin, nQin)) |
Volker@43 | 1016 | print("{0:7}{1:17} {2:6.4f}±{3:7.4f}/{4:2d}".format("", "Vin =", Vin0, dVin, nVin)) |
Volker@43 | 1017 | print("{0:7}{1:17} {2:6.4f}±{3:7.4f}/{4:2d}".format("", "Rotation alpha = ", RotL0, dRotL, nRotL)) |
Volker@43 | 1018 | print("{0:7}{1:15} {2:8.4f} {3:17}".format("", "=> DOP", ((Qin ** 2 + Vin ** 2) ** 0.5), " (degree of polarisation)")) |
Volker@43 | 1019 | |
Volker@43 | 1020 | print("Optic: Diatt., Tunpol, Retard., Rotation (deg)") |
Volker@43 | 1021 | 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( |
Volker@43 | 1022 | "Emitter ", DiE0, dDiE, TiE, RetE0, dRetE, RotE0, dRotE, nDiE, nRetE, nRotE)) |
Volker@43 | 1023 | 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( |
Volker@43 | 1024 | "Receiver ", DiO0, dDiO, TiO, RetO0, dRetO, RotO0, dRotO, nDiO, nRetO, nRotO)) |
Volker@43 | 1025 | print("{0:12} {1:9.6f}±{2:9.6f}/{8:2d}, {3:7.4f}, {4:3.0f}±{5:3.0f}/{9:2d}, {6:7.4f}±{7:7.4f}/{10:2d}".format( |
Volker@43 | 1026 | "Calibrator ", DiC0, dDiC, TiC, RetC0, dRetC, RotC0, dRotC, nDiC, nRetC, nRotC)) |
Volker@43 | 1027 | print("{0:12}".format(" Pol.-filter ------ ")) |
Volker@43 | 1028 | print("{0:12}{1:7.4f}±{2:7.4f}/{3:2d}, {4:7.4f}±{5:7.4f}/{6:2d}".format( |
Volker@43 | 1029 | "ERT, RotT :", ERaT0, dERaT, nERaT, RotaT0, dRotaT, nRotaT)) |
Volker@43 | 1030 | print("{0:12}{1:7.4f}±{2:7.4f}/{3:2d}, {4:7.4f}±{5:7.4f}/{6:2d}".format( |
Volker@43 | 1031 | "ERR, RotR :", ERaR0, dERaR, nERaR, RotaR0, dRotaR, nRotaR)) |
Volker@43 | 1032 | print("{0:12}".format(" PBS ------ ")) |
Volker@43 | 1033 | print("{0:12}{1:7.4f}±{2:7.4f}/{3:2d}, {4:7.4f}±{5:7.4f}/{6:2d}".format( |
Volker@43 | 1034 | "TP,TS :", TP0, dTP, nTP, TS0, dTS, nTS)) |
Volker@43 | 1035 | print("{0:12}{1:7.4f}±{2:7.4f}/{3:2d}, {4:7.4f}±{5:7.4f}/{6:2d}".format( |
Volker@43 | 1036 | "RP,RS :", RP0, dRP, nRP, RS0, dRS, nRS)) |
Volker@43 | 1037 | print("{0:12}{1:7.4f},{2:7.4f}, {3:7.4f},{4:7.4f}, {5:1.0f}".format( |
Volker@43 | 1038 | "DT,TT,DR,TR,Y :", DiT, TiT, DiR, TiR, Y)) |
Volker@43 | 1039 | print("{0:12}".format(" Combined PBS + Pol.-filter ------ ")) |
Volker@43 | 1040 | print("{0:12}{1:7.4f},{2:7.4f}, {3:7.4f},{4:7.4f}".format( |
Volker@43 | 1041 | "DT,TT,DR,TR :", DTa0, TTa0, DRa0, TRa0)) |
Volker@43 | 1042 | print("{0:26}: {1:6.3f}± {2:5.3f}/{3:2d}".format( |
Volker@43 | 1043 | "LDRCal during calibration in calibration range", LDRCal0, dLDRCal, nLDRCal)) |
Volker@43 | 1044 | print("{0:12}".format(" --- Additional ND filter attenuation (transmission) during the calibration ---")) |
Volker@43 | 1045 | print("{0:12}{1:7.4f}±{2:7.4f}/{3:2d}, {4:7.4f}±{5:7.4f}/{6:2d}".format( |
Volker@43 | 1046 | "TCalT,TCalR :", TCalT0, dTCalT, nTCalT, TCalR0, dTCalR, nTCalR)) |
Volker@43 | 1047 | print() |
Volker@44 | 1048 | print(Type[TypeC],"calibrator is located", Loc[LocC]) |
Volker@44 | 1049 | print("Rotation error epsilon is considered also for normal measurements = ", RotationErrorEpsilonForNormalMeasurements) |
Volker@44 | 1050 | print("The PBS incidence plane is ", dY[int(Y + 1)], "to the reference plane" ) |
Volker@44 | 1051 | print("The laser polarisation in the reference plane is finally", dY2[int(Y + 1)], "=>", dY3) |
Volker@43 | 1052 | print("RS_RP_depend_on_TS_TP = ", RS_RP_depend_on_TS_TP) |
Volker@43 | 1053 | # end of print actual system parameters |
Volker@43 | 1054 | # ****************************************************************************** |
Volker@43 | 1055 | |
Volker@43 | 1056 | |
Volker@43 | 1057 | print() |
Volker@43 | 1058 | |
Volker@43 | 1059 | K0List = np.zeros(7) |
Volker@43 | 1060 | LDRsimxList = np.zeros(7) |
Volker@43 | 1061 | LDRCalList = 0.0, 0.004, 0.02, 0.1, 0.2, 0.3, 0.45 |
Volker@43 | 1062 | # 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@43 | 1063 | # Still with assumed true parameters in input file |
Volker@43 | 1064 | |
Volker@43 | 1065 | ''' |
Volker@43 | 1066 | facIt = NCalT / TCalT0 * NILfac |
Volker@43 | 1067 | facIr = NCalR / TCalR0 * NILfac |
Volker@43 | 1068 | ''' |
Volker@43 | 1069 | facIt = NI * eFacT |
Volker@43 | 1070 | facIr = NI * eFacR |
Volker@43 | 1071 | if (bPlotEtax): |
Volker@43 | 1072 | # check error signals |
Volker@43 | 1073 | # dIs are relative stdevs |
Volker@43 | 1074 | print("LDRCal, IoutTp, IoutTm, IoutRp, IoutRm, It, Ir, dIoutTp,dIoutTm,dIoutRp,dIoutRm,dIt, dIr") |
Volker@43 | 1075 | |
Volker@43 | 1076 | for i, LDRCal in enumerate(LDRCalList): |
Volker@43 | 1077 | IoutTp, IoutTm, IoutRp, IoutRm, It, Ir, dIoutTp, dIoutTm, dIoutRp, dIoutRm, dIt, dIr, \ |
Volker@43 | 1078 | GT0, HT0, GR0, HR0, K0, Eta0, LDRsimx, LDRCorr, DTa0, DRa0, TTa0, TRa0, F11sim0, LDRunCorr = \ |
Volker@43 | 1079 | Calc(TCalT0, TCalR0, NCalT, NCalR, Qin0, Vin0, RotL0, RotE0, RetE0, DiE0, |
Volker@43 | 1080 | RotO0, RetO0, DiO0, RotC0, RetC0, DiC0, TP0, TS0, RP0, RS0, |
Volker@43 | 1081 | ERaT0, RotaT0, RetT0, ERaR0, RotaR0, RetR0, LDRCal) |
Volker@43 | 1082 | K0List[i] = K0 |
Volker@43 | 1083 | LDRsimxList[i] = LDRsimx |
Volker@43 | 1084 | |
Volker@43 | 1085 | if (bPlotEtax): |
Volker@43 | 1086 | # check error signals |
Volker@43 | 1087 | print( "{:0.2f}, {: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(LDRCal, IoutTp * NCalT, IoutTm * NCalT, IoutRp * NCalR, IoutRm * NCalR, It * facIt, Ir * facIr, dIoutTp, dIoutTm, dIoutRp, dIoutRm, dIt, dIr)) |
Volker@43 | 1088 | #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@43 | 1089 | # end check error signals |
Volker@43 | 1090 | print('===========================================================================================================') |
Volker@43 | 1091 | print("{0:8},{1:8},{2:8},{3:8},{4:9},{5:8},{6:9},{7:9},{8:9},{9:9},{10:9}".format( |
Volker@43 | 1092 | " GR", " GT", " HR", " HT", " K(0.000)", " K(0.004)", " K(0.02)", " K(0.1)", " K(0.2)", " K(0.3)", " K(0.45)")) |
Volker@43 | 1093 | 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},{10:9.5f}".format( |
Volker@43 | 1094 | GR0, GT0, HR0, HT0, K0List[0], K0List[1], K0List[2], K0List[3], K0List[4], K0List[5], K0List[6])) |
Volker@43 | 1095 | print('===========================================================================================================') |
Volker@43 | 1096 | print() |
Volker@43 | 1097 | print("Errors from neglecting GHK corrections and/or calibration:") |
Volker@43 | 1098 | print("{0:>10},{1:>10},{2:>10},{3:>10},{4:>10},{5:>10}".format( |
Volker@43 | 1099 | "LDRtrue", "LDRunCorr", "1/LDRunCorr", "LDRsimx", "1/LDRsimx", "LDRCorr")) |
Volker@43 | 1100 | |
Volker@43 | 1101 | aF11sim0 = np.zeros(5) |
Volker@43 | 1102 | LDRrange = np.zeros(5) |
Volker@43 | 1103 | LDRsim0 = np.zeros(5) |
Volker@43 | 1104 | LDRrange = [0.004, 0.02, 0.1, 0.3, 0.45] # list |
Volker@43 | 1105 | LDRrange[0] = LDRtrue2 # value in the input file; default 0.004 |
Volker@43 | 1106 | |
Volker@43 | 1107 | # The loop over LDRtrueList is only for checking how much the uncorrected LDRsimx deviates from LDRtrue ... and whether the corrections work. |
Volker@43 | 1108 | # LDRsimx = LDRsim = Ir / It or 1/LDRsim |
Volker@43 | 1109 | # Still with assumed true parameters in input file |
Volker@43 | 1110 | for i, LDRtrue in enumerate(LDRrange): |
Volker@43 | 1111 | #for LDRtrue in LDRrange: |
Volker@43 | 1112 | IoutTp, IoutTm, IoutRp, IoutRm, It, Ir, dIoutTp, dIoutTm, dIoutRp, dIoutRm, dIt, dIr, \ |
Volker@43 | 1113 | GT0, HT0, GR0, HR0, K0, Eta0, LDRsimx, LDRCorr, DTa0, DRa0, TTa0, TRa0, F11sim0, LDRunCorr = \ |
Volker@43 | 1114 | Calc(TCalT0, TCalR0, NCalT, NCalR, Qin0, Vin0, RotL0, RotE0, RetE0, DiE0, |
Volker@43 | 1115 | RotO0, RetO0, DiO0, RotC0, RetC0, DiC0, TP0, TS0, RP0, RS0, |
Volker@43 | 1116 | ERaT0, RotaT0, RetT0, ERaR0, RotaR0, RetR0, LDRCal0) |
Volker@43 | 1117 | 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@43 | 1118 | aF11sim0[i] = F11sim0 |
Volker@43 | 1119 | LDRsim0[i] = Ir / It |
Volker@43 | 1120 | # the assumed true aF11sim0 results will be used below to calc the deviation from the real signals |
Volker@43 | 1121 | print("LDRsimx = LDR of the nominal system directly from measured signals without calibration and GHK-corrections") |
Volker@43 | 1122 | print("LDRunCorr = LDR of the nominal system directly from measured signals with calibration but without GHK-corrections; electronic amplifications = 1 assumed") |
Volker@43 | 1123 | print("LDRCorr = LDR calibrated and GHK-corrected") |
Volker@43 | 1124 | print() |
Volker@43 | 1125 | print("Errors from signal noise:") |
Volker@43 | 1126 | print("Signal counts: NI, NCalT, NCalR, NILfac, nNCal, nNI, stdev(NI)/NI = {0:10.0f},{1:10.0f},{2:10.0f},{3:3.0f},{4:2.0f},{5:2.0f},{6:8.5f}".format( |
Volker@43 | 1127 | NI, NCalT, NCalR, NILfac, nNCal, nNI, 1.0 / NI ** 0.5)) |
Volker@43 | 1128 | print() |
Volker@43 | 1129 | print() |
Volker@43 | 1130 | '''# das muß wieder weg |
Volker@43 | 1131 | print("IoutTp, IoutTm, IoutRp, IoutRm, It , Ir , dIoutTp, dIoutTm, dIoutRp, dIoutRm, dIt, dIr") |
Volker@43 | 1132 | LDRCal = 0.01 |
Volker@43 | 1133 | for i, LDRtrue in enumerate(LDRrange): |
Volker@43 | 1134 | IoutTp, IoutTm, IoutRp, IoutRm, It, Ir, dIoutTp, dIoutTm, dIoutRp, dIoutRm, dIt, dIr, \ |
Volker@43 | 1135 | GT0, HT0, GR0, HR0, K0, Eta0, LDRsimx, LDRCorr, DTa0, DRa0, TTa0, TRa0, F11sim0, LDRunCorr = \ |
Volker@43 | 1136 | Calc(TCalT0, TCalR0, NCalT, NCalR, DOLP0, RotL0, RotE0, RetE0, DiE0, |
Volker@43 | 1137 | RotO0, RetO0, DiO0, RotC0, RetC0, DiC0, TP0, TS0, RP0, RS0, |
Volker@43 | 1138 | ERaT0, RotaT0, RetT0, ERaR0, RotaR0, RetR0, LDRCal0) |
Volker@43 | 1139 | 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@43 | 1140 | IoutTp * NCalT, IoutTm * NCalT, IoutRp * NCalR, IoutRm * NCalR, It * facIt, Ir * facIr, |
Volker@43 | 1141 | dIoutTp, dIoutTm, dIoutRp, dIoutRm, dIt, dIr)) |
Volker@43 | 1142 | aF11sim0[i] = F11sim0 |
Volker@43 | 1143 | # the assumed true aF11sim0 results will be used below to calc the deviation from the real signals |
Volker@43 | 1144 | # bis hierher weg |
Volker@43 | 1145 | ''' |
Volker@43 | 1146 | |
Volker@43 | 1147 | file = open('output_files\\' + OutputFile, 'r') |
Volker@43 | 1148 | print(file.read()) |
Volker@43 | 1149 | file.close() |
Volker@43 | 1150 | |
Volker@43 | 1151 | # --- CALC again assumed truth with LDRCal0 and with assumed true parameters in input file to reset all 0-values |
Volker@43 | 1152 | LDRtrue = LDRtrue2 |
Volker@43 | 1153 | IoutTp0, IoutTm0, IoutRp0, IoutRm0, It0, Ir0, dIoutTp0, dIoutTm0, dIoutRp0, dIoutRm0, dIt0, dIr0, \ |
Volker@43 | 1154 | GT0, HT0, GR0, HR0, K0, Eta0, LDRsimx, LDRCorr, DTa0, DRa0, TTa0, TRa0, F11sim0, LDRunCorr = \ |
Volker@43 | 1155 | Calc(TCalT0, TCalR0, NCalT, NCalR, Qin0, Vin0, RotL0, RotE0, RetE0, DiE0, |
Volker@43 | 1156 | RotO0, RetO0, DiO0, RotC0, RetC0, DiC0, TP0, TS0, RP0, RS0, |
Volker@43 | 1157 | ERaT0, RotaT0, RetT0, ERaR0, RotaR0, RetR0, LDRCal0) |
Volker@43 | 1158 | Etax0 = K0 * Eta0 |
Volker@43 | 1159 | Etapx0 = IoutRp0 / IoutTp0 |
Volker@43 | 1160 | Etamx0 = IoutRm0 / IoutTm0 |
Volker@43 | 1161 | ''' |
Volker@43 | 1162 | if(PrintToOutputFile): |
Volker@43 | 1163 | f = open('output_ver7.dat', 'w') |
Volker@43 | 1164 | old_target = sys.stdout |
Volker@43 | 1165 | sys.stdout = f |
Volker@43 | 1166 | |
Volker@43 | 1167 | print("something") |
Volker@43 | 1168 | |
Volker@43 | 1169 | if(PrintToOutputFile): |
Volker@43 | 1170 | sys.stdout.flush() |
Volker@43 | 1171 | f.close |
Volker@43 | 1172 | sys.stdout = old_target |
Volker@43 | 1173 | ''' |
Volker@43 | 1174 | if (Error_Calc): |
Volker@43 | 1175 | # --- CALC again assumed truth with LDRCal0 and with assumed true parameters in input file to reset all 0-values |
Volker@43 | 1176 | LDRtrue = LDRtrue2 |
Volker@43 | 1177 | IoutTp0, IoutTm0, IoutRp0, IoutRm0, It0, Ir0, dIoutTp0, dIoutTm0, dIoutRp0, dIoutRm0, dIt0, dIr0, \ |
Volker@43 | 1178 | GT0, HT0, GR0, HR0, K0, Eta0, LDRsimx, LDRCorr, DTa0, DRa0, TTa0, TRa0, F11sim0, LDRunCorr = \ |
Volker@43 | 1179 | Calc(TCalT0, TCalR0, NCalT, NCalR, Qin0, Vin0, RotL0, RotE0, RetE0, DiE0, |
Volker@43 | 1180 | RotO0, RetO0, DiO0, RotC0, RetC0, DiC0, TP0, TS0, RP0, RS0, |
Volker@43 | 1181 | ERaT0, RotaT0, RetT0, ERaR0, RotaR0, RetR0, LDRCal0) |
Volker@43 | 1182 | Etax0 = K0 * Eta0 |
Volker@43 | 1183 | Etapx0 = IoutRp0 / IoutTp0 |
Volker@43 | 1184 | Etamx0 = IoutRm0 / IoutTm0 |
Volker@43 | 1185 | |
Volker@43 | 1186 | # --- Start Error calculation with variable parameters ------------------------------------------------------------------ |
Volker@43 | 1187 | # error nNCal: one-sigma in steps to left and right for calibration signals |
Volker@43 | 1188 | # error nNI: one-sigma in steps to left and right for 0° signals |
Volker@43 | 1189 | |
Volker@43 | 1190 | iN = -1 |
Volker@43 | 1191 | N = ((nTCalT * 2 + 1) * (nTCalR * 2 + 1) * |
Volker@43 | 1192 | (nNCal * 2 + 1) ** 4 * (nNI * 2 + 1) ** 2 * |
Volker@43 | 1193 | (nQin * 2 + 1) * (nVin * 2 + 1) * (nRotL * 2 + 1) * |
Volker@43 | 1194 | (nRotE * 2 + 1) * (nRetE * 2 + 1) * (nDiE * 2 + 1) * |
Volker@43 | 1195 | (nRotO * 2 + 1) * (nRetO * 2 + 1) * (nDiO * 2 + 1) * |
Volker@43 | 1196 | (nRotC * 2 + 1) * (nRetC * 2 + 1) * (nDiC * 2 + 1) * |
Volker@43 | 1197 | (nTP * 2 + 1) * (nTS * 2 + 1) * (nRP * 2 + 1) * (nRS * 2 + 1) * (nERaT * 2 + 1) * (nERaR * 2 + 1) * |
Volker@43 | 1198 | (nRotaT * 2 + 1) * (nRotaR * 2 + 1) * (nRetT * 2 + 1) * (nRetR * 2 + 1) * (nLDRCal * 2 + 1)) |
Volker@43 | 1199 | print("number of system variations N = ", N, " ", end="") |
Volker@43 | 1200 | |
Volker@43 | 1201 | if N > 1e6: |
Volker@43 | 1202 | if user_yes_no_query('Warning: processing ' + str( |
Volker@43 | 1203 | N) + ' samples will take very long. Do you want to proceed?') == 0: sys.exit() |
Volker@43 | 1204 | if N > 5e6: |
Volker@43 | 1205 | if user_yes_no_query('Warning: the memory required for ' + str(N) + ' samples might be ' + '{0:5.1f}'.format( |
Volker@43 | 1206 | N / 4e6) + ' GB. Do you anyway want to proceed?') == 0: sys.exit() |
Volker@43 | 1207 | |
Volker@43 | 1208 | # if user_yes_no_query('Warning: processing' + str(N) + ' samples will take very long. Do you want to proceed?') == 0: sys.exit() |
Volker@43 | 1209 | |
Volker@43 | 1210 | # --- Arrays for plotting ------ |
Volker@43 | 1211 | LDRmin = np.zeros(5) |
Volker@43 | 1212 | LDRmax = np.zeros(5) |
Volker@43 | 1213 | LDRstd = np.zeros(5) |
Volker@43 | 1214 | LDRmean = np.zeros(5) |
Volker@43 | 1215 | LDRmedian = np.zeros(5) |
Volker@43 | 1216 | LDRskew = np.zeros(5) |
Volker@43 | 1217 | LDRkurt = np.zeros(5) |
Volker@43 | 1218 | LDRsimmin = np.zeros(5) |
Volker@43 | 1219 | LDRsimmax = np.zeros(5) |
Volker@43 | 1220 | LDRsimmean = np.zeros(5) |
Volker@43 | 1221 | |
Volker@43 | 1222 | F11min = np.zeros(5) |
Volker@43 | 1223 | F11max = np.zeros(5) |
Volker@43 | 1224 | Etaxmin = np.zeros(5) |
Volker@43 | 1225 | Etaxmax = np.zeros(5) |
Volker@43 | 1226 | |
Volker@43 | 1227 | aQin = np.zeros(N) |
Volker@43 | 1228 | aVin = np.zeros(N) |
Volker@43 | 1229 | aERaT = np.zeros(N) |
Volker@43 | 1230 | aERaR = np.zeros(N) |
Volker@43 | 1231 | aRotaT = np.zeros(N) |
Volker@43 | 1232 | aRotaR = np.zeros(N) |
Volker@43 | 1233 | aRetT = np.zeros(N) |
Volker@43 | 1234 | aRetR = np.zeros(N) |
Volker@43 | 1235 | aTP = np.zeros(N) |
Volker@43 | 1236 | aTS = np.zeros(N) |
Volker@43 | 1237 | aRP = np.zeros(N) |
Volker@43 | 1238 | aRS = np.zeros(N) |
Volker@43 | 1239 | aDiE = np.zeros(N) |
Volker@43 | 1240 | aDiO = np.zeros(N) |
Volker@43 | 1241 | aDiC = np.zeros(N) |
Volker@43 | 1242 | aRotC = np.zeros(N) |
Volker@43 | 1243 | aRetC = np.zeros(N) |
Volker@43 | 1244 | aRotL = np.zeros(N) |
Volker@43 | 1245 | aRetE = np.zeros(N) |
Volker@43 | 1246 | aRotE = np.zeros(N) |
Volker@43 | 1247 | aRetO = np.zeros(N) |
Volker@43 | 1248 | aRotO = np.zeros(N) |
Volker@43 | 1249 | aLDRCal = np.zeros(N) |
Volker@43 | 1250 | aNCalTp = np.zeros(N) |
Volker@43 | 1251 | aNCalTm = np.zeros(N) |
Volker@43 | 1252 | aNCalRp = np.zeros(N) |
Volker@43 | 1253 | aNCalRm = np.zeros(N) |
Volker@43 | 1254 | aNIt = np.zeros(N) |
Volker@43 | 1255 | aNIr = np.zeros(N) |
Volker@43 | 1256 | aTCalT = np.zeros(N) |
Volker@43 | 1257 | aTCalR = np.zeros(N) |
Volker@43 | 1258 | |
Volker@43 | 1259 | # each np.zeros((LDRrange, N)) array has the same N-dependency |
Volker@43 | 1260 | aLDRcorr = np.zeros((5, N)) |
Volker@43 | 1261 | aLDRsim = np.zeros((5, N)) |
Volker@43 | 1262 | aF11corr = np.zeros((5, N)) |
Volker@43 | 1263 | aPLDR = np.zeros((5, N)) |
Volker@43 | 1264 | aEtax = np.zeros((5, N)) |
Volker@43 | 1265 | aEtapx = np.zeros((5, N)) |
Volker@43 | 1266 | aEtamx = np.zeros((5, N)) |
Volker@43 | 1267 | |
Volker@43 | 1268 | # np.zeros((GHKs, N)) |
Volker@43 | 1269 | aGHK = np.zeros((5, N)) |
Volker@43 | 1270 | |
Volker@43 | 1271 | atime = clock() |
Volker@43 | 1272 | dtime = clock() |
Volker@43 | 1273 | |
Volker@43 | 1274 | # --- Calc Error signals |
Volker@43 | 1275 | # ---- Do the calculations of bra-ket vectors |
Volker@43 | 1276 | h = -1. if TypeC == 2 else 1 |
Volker@43 | 1277 | |
Volker@43 | 1278 | for iLDRCal in range(-nLDRCal, nLDRCal + 1): |
Volker@43 | 1279 | # from input file: LDRCal for calibration measurements |
Volker@43 | 1280 | LDRCal = LDRCal0 |
Volker@43 | 1281 | if nLDRCal > 0: |
Volker@43 | 1282 | LDRCal = LDRCal0 + iLDRCal * dLDRCal / nLDRCal |
Volker@43 | 1283 | # provides the intensities of the calibration measurements at various LDRCal for signal noise errors |
Volker@43 | 1284 | # IoutTp, IoutTm, IoutRp, IoutRm, dIoutTp, dIoutTm, dIoutRp, dIoutRm |
Volker@43 | 1285 | |
Volker@43 | 1286 | aCal = (1. - LDRCal) / (1. + LDRCal) |
Volker@43 | 1287 | for iQin, iVin, iRotL, iRotE, iRetE, iDiE \ |
Volker@43 | 1288 | in [(iQin, iVin, iRotL, iRotE, iRetE, iDiE) |
Volker@43 | 1289 | for iQin in range(-nQin, nQin + 1) |
Volker@43 | 1290 | for iVin in range(-nVin, nVin + 1) |
Volker@43 | 1291 | for iRotL in range(-nRotL, nRotL + 1) |
Volker@43 | 1292 | for iRotE in range(-nRotE, nRotE + 1) |
Volker@43 | 1293 | for iRetE in range(-nRetE, nRetE + 1) |
Volker@43 | 1294 | for iDiE in range(-nDiE, nDiE + 1)]: |
Volker@43 | 1295 | |
Volker@43 | 1296 | if nQin > 0: Qin = Qin0 + iQin * dQin / nQin |
Volker@43 | 1297 | if nVin > 0: Vin = Vin0 + iVin * dVin / nVin |
Volker@43 | 1298 | if nRotL > 0: RotL = RotL0 + iRotL * dRotL / nRotL |
Volker@43 | 1299 | if nRotE > 0: RotE = RotE0 + iRotE * dRotE / nRotE |
Volker@43 | 1300 | if nRetE > 0: RetE = RetE0 + iRetE * dRetE / nRetE |
Volker@43 | 1301 | if nDiE > 0: DiE = DiE0 + iDiE * dDiE / nDiE |
Volker@43 | 1302 | |
Volker@43 | 1303 | if ((Qin ** 2 + Vin ** 2) ** 0.5) > 1.0: |
Volker@43 | 1304 | print("Error: degree of polarisation of laser > 1. Check Qin and Vin! ") |
Volker@43 | 1305 | sys.exit() |
Volker@43 | 1306 | # angles of emitter and laser and calibrator and receiver optics |
Volker@43 | 1307 | # RotL = alpha, RotE = beta, RotO = gamma, RotC = epsilon |
Volker@43 | 1308 | S2a = np.sin(2 * np.deg2rad(RotL)) |
Volker@43 | 1309 | C2a = np.cos(2 * np.deg2rad(RotL)) |
Volker@43 | 1310 | S2b = np.sin(2 * np.deg2rad(RotE)) |
Volker@43 | 1311 | C2b = np.cos(2 * np.deg2rad(RotE)) |
Volker@43 | 1312 | S2ab = np.sin(np.deg2rad(2 * RotL - 2 * RotE)) |
Volker@43 | 1313 | C2ab = np.cos(np.deg2rad(2 * RotL - 2 * RotE)) |
Volker@43 | 1314 | |
Volker@43 | 1315 | # Laser with Degree of linear polarization DOLP |
Volker@43 | 1316 | IinL = 1. |
Volker@43 | 1317 | QinL = Qin |
Volker@43 | 1318 | UinL = 0. |
Volker@43 | 1319 | VinL = Vin |
Volker@43 | 1320 | # VinL = (1. - DOLP ** 2) ** 0.5 |
Volker@43 | 1321 | |
Volker@43 | 1322 | # Stokes Input Vector rotation Eq. E.4 |
Volker@43 | 1323 | A = C2a * QinL - S2a * UinL |
Volker@43 | 1324 | B = S2a * QinL + C2a * UinL |
Volker@43 | 1325 | # Stokes Input Vector rotation Eq. E.9 |
Volker@43 | 1326 | C = C2ab * QinL - S2ab * UinL |
Volker@43 | 1327 | D = S2ab * QinL + C2ab * UinL |
Volker@43 | 1328 | |
Volker@43 | 1329 | # emitter optics |
Volker@43 | 1330 | CosE = np.cos(np.deg2rad(RetE)) |
Volker@43 | 1331 | SinE = np.sin(np.deg2rad(RetE)) |
Volker@43 | 1332 | ZiE = (1. - DiE ** 2) ** 0.5 |
Volker@43 | 1333 | WiE = (1. - ZiE * CosE) |
Volker@43 | 1334 | |
Volker@43 | 1335 | # Stokes Input Vector after emitter optics equivalent to Eq. E.9 with already rotated input vector from Eq. E.4 |
Volker@43 | 1336 | # b = beta |
Volker@43 | 1337 | IinE = (IinL + DiE * C) |
Volker@43 | 1338 | QinE = (C2b * DiE * IinL + A + S2b * (WiE * D - ZiE * SinE * VinL)) |
Volker@43 | 1339 | UinE = (S2b * DiE * IinL + B - C2b * (WiE * D - ZiE * SinE * VinL)) |
Volker@43 | 1340 | VinE = (-ZiE * SinE * D + ZiE * CosE * VinL) |
Volker@43 | 1341 | |
Volker@43 | 1342 | # ------------------------- |
Volker@43 | 1343 | # F11 assuemd to be = 1 => measured: F11m = IinP / IinE with atrue |
Volker@43 | 1344 | # F11sim = (IinE + DiO*atrue*(C2g*QinE - S2g*UinE))/IinE |
Volker@43 | 1345 | # ------------------------- |
Volker@43 | 1346 | |
Volker@43 | 1347 | for iRotO, iRetO, iDiO, iRotC, iRetC, iDiC, iTP, iTS, iRP, iRS, iERaT, iRotaT, iRetT, iERaR, iRotaR, iRetR \ |
Volker@43 | 1348 | in [ |
Volker@43 | 1349 | (iRotO, iRetO, iDiO, iRotC, iRetC, iDiC, iTP, iTS, iRP, iRS, iERaT, iRotaT, iRetT, iERaR, iRotaR, iRetR) |
Volker@43 | 1350 | for iRotO in range(-nRotO, nRotO + 1) |
Volker@43 | 1351 | for iRetO in range(-nRetO, nRetO + 1) |
Volker@43 | 1352 | for iDiO in range(-nDiO, nDiO + 1) |
Volker@43 | 1353 | for iRotC in range(-nRotC, nRotC + 1) |
Volker@43 | 1354 | for iRetC in range(-nRetC, nRetC + 1) |
Volker@43 | 1355 | for iDiC in range(-nDiC, nDiC + 1) |
Volker@43 | 1356 | for iTP in range(-nTP, nTP + 1) |
Volker@43 | 1357 | for iTS in range(-nTS, nTS + 1) |
Volker@43 | 1358 | for iRP in range(-nRP, nRP + 1) |
Volker@43 | 1359 | for iRS in range(-nRS, nRS + 1) |
Volker@43 | 1360 | for iERaT in range(-nERaT, nERaT + 1) |
Volker@43 | 1361 | for iRotaT in range(-nRotaT, nRotaT + 1) |
Volker@43 | 1362 | for iRetT in range(-nRetT, nRetT + 1) |
Volker@43 | 1363 | for iERaR in range(-nERaR, nERaR + 1) |
Volker@43 | 1364 | for iRotaR in range(-nRotaR, nRotaR + 1) |
Volker@43 | 1365 | for iRetR in range(-nRetR, nRetR + 1)]: |
Volker@43 | 1366 | |
Volker@43 | 1367 | if nRotO > 0: RotO = RotO0 + iRotO * dRotO / nRotO |
Volker@43 | 1368 | if nRetO > 0: RetO = RetO0 + iRetO * dRetO / nRetO |
Volker@43 | 1369 | if nDiO > 0: DiO = DiO0 + iDiO * dDiO / nDiO |
Volker@43 | 1370 | if nRotC > 0: RotC = RotC0 + iRotC * dRotC / nRotC |
Volker@43 | 1371 | if nRetC > 0: RetC = RetC0 + iRetC * dRetC / nRetC |
Volker@43 | 1372 | if nDiC > 0: DiC = DiC0 + iDiC * dDiC / nDiC |
Volker@43 | 1373 | if nTP > 0: TP = TP0 + iTP * dTP / nTP |
Volker@43 | 1374 | if nTS > 0: TS = TS0 + iTS * dTS / nTS |
Volker@43 | 1375 | if nRP > 0: RP = RP0 + iRP * dRP / nRP |
Volker@43 | 1376 | if nRS > 0: RS = RS0 + iRS * dRS / nRS |
Volker@43 | 1377 | if nERaT > 0: ERaT = ERaT0 + iERaT * dERaT / nERaT |
Volker@43 | 1378 | if nRotaT > 0: RotaT = RotaT0 + iRotaT * dRotaT / nRotaT |
Volker@43 | 1379 | if nRetT > 0: RetT = RetT0 + iRetT * dRetT / nRetT |
Volker@43 | 1380 | if nERaR > 0: ERaR = ERaR0 + iERaR * dERaR / nERaR |
Volker@43 | 1381 | if nRotaR > 0: RotaR = RotaR0 + iRotaR * dRotaR / nRotaR |
Volker@43 | 1382 | if nRetR > 0: RetR = RetR0 + iRetR * dRetR / nRetR |
Volker@43 | 1383 | |
Volker@43 | 1384 | # print("{0:5.2f}, {1:5.2f}, {2:5.2f}, {3:10d}".format(RotL, RotE, RotO, iN)) |
Volker@43 | 1385 | |
Volker@43 | 1386 | # receiver optics |
Volker@43 | 1387 | CosO = np.cos(np.deg2rad(RetO)) |
Volker@43 | 1388 | SinO = np.sin(np.deg2rad(RetO)) |
Volker@43 | 1389 | ZiO = (1. - DiO ** 2) ** 0.5 |
Volker@43 | 1390 | WiO = (1. - ZiO * CosO) |
Volker@43 | 1391 | S2g = np.sin(np.deg2rad(2 * RotO)) |
Volker@43 | 1392 | C2g = np.cos(np.deg2rad(2 * RotO)) |
Volker@43 | 1393 | # calibrator |
Volker@43 | 1394 | CosC = np.cos(np.deg2rad(RetC)) |
Volker@43 | 1395 | SinC = np.sin(np.deg2rad(RetC)) |
Volker@43 | 1396 | ZiC = (1. - DiC ** 2) ** 0.5 |
Volker@43 | 1397 | WiC = (1. - ZiC * CosC) |
Volker@43 | 1398 | |
Volker@43 | 1399 | # analyser |
Volker@43 | 1400 | # For POLLY_XTs |
Volker@43 | 1401 | if (RS_RP_depend_on_TS_TP): |
Volker@43 | 1402 | RS = 1.0 - TS |
Volker@43 | 1403 | RP = 1.0 - TP |
Volker@43 | 1404 | TiT = 0.5 * (TP + TS) |
Volker@43 | 1405 | DiT = (TP - TS) / (TP + TS) |
Volker@43 | 1406 | ZiT = (1. - DiT ** 2.) ** 0.5 |
Volker@43 | 1407 | TiR = 0.5 * (RP + RS) |
Volker@43 | 1408 | DiR = (RP - RS) / (RP + RS) |
Volker@43 | 1409 | ZiR = (1. - DiR ** 2.) ** 0.5 |
Volker@43 | 1410 | CosT = np.cos(np.deg2rad(RetT)) |
Volker@43 | 1411 | SinT = np.sin(np.deg2rad(RetT)) |
Volker@43 | 1412 | CosR = np.cos(np.deg2rad(RetR)) |
Volker@43 | 1413 | SinR = np.sin(np.deg2rad(RetR)) |
Volker@43 | 1414 | |
Volker@43 | 1415 | # cleaning pol-filter |
Volker@43 | 1416 | DaT = (1.0 - ERaT) / (1.0 + ERaT) |
Volker@43 | 1417 | DaR = (1.0 - ERaR) / (1.0 + ERaR) |
Volker@43 | 1418 | TaT = 0.5 * (1.0 + ERaT) |
Volker@43 | 1419 | TaR = 0.5 * (1.0 + ERaR) |
Volker@43 | 1420 | |
Volker@43 | 1421 | S2aT = np.sin(np.deg2rad(h * 2.0 * RotaT)) |
Volker@43 | 1422 | C2aT = np.cos(np.deg2rad(2.0 * RotaT)) |
Volker@43 | 1423 | S2aR = np.sin(np.deg2rad(h * 2.0 * RotaR)) |
Volker@43 | 1424 | C2aR = np.cos(np.deg2rad(2.0 * RotaR)) |
Volker@43 | 1425 | |
Volker@43 | 1426 | # Analyzer As before the PBS Eq. D.5; combined PBS and cleaning pol-filter |
Volker@43 | 1427 | ATPT = (1 + C2aT * DaT * DiT) # unpolarized transmission correction |
Volker@43 | 1428 | TTa = TiT * TaT * ATPT # unpolarized transmission |
Volker@43 | 1429 | ATP1 = 1.0 |
Volker@43 | 1430 | ATP2 = Y * (DiT + C2aT * DaT) / ATPT |
Volker@43 | 1431 | ATP3 = Y * S2aT * DaT * ZiT * CosT / ATPT |
Volker@43 | 1432 | ATP4 = S2aT * DaT * ZiT * SinT / ATPT |
Volker@43 | 1433 | ATP = np.array([ATP1, ATP2, ATP3, ATP4]) |
Volker@43 | 1434 | DTa = ATP2 * Y |
Volker@43 | 1435 | |
Volker@43 | 1436 | ARPT = (1 + C2aR * DaR * DiR) # unpolarized transmission correction |
Volker@43 | 1437 | TRa = TiR * TaR * ARPT # unpolarized transmission |
Volker@43 | 1438 | ARP1 = 1 |
Volker@43 | 1439 | ARP2 = Y * (DiR + C2aR * DaR) / ARPT |
Volker@43 | 1440 | ARP3 = Y * S2aR * DaR * ZiR * CosR / ARPT |
Volker@43 | 1441 | ARP4 = S2aR * DaR * ZiR * SinR / ARPT |
Volker@43 | 1442 | ARP = np.array([ARP1, ARP2, ARP3, ARP4]) |
Volker@43 | 1443 | DRa = ARP2 * Y |
Volker@43 | 1444 | |
Volker@43 | 1445 | # ---- Calculate signals and correction parameters for diffeent locations and calibrators |
Volker@43 | 1446 | if LocC == 4: # Calibrator before the PBS |
Volker@43 | 1447 | # print("Calibrator location not implemented yet") |
Volker@43 | 1448 | |
Volker@43 | 1449 | # S2ge = np.sin(np.deg2rad(2*RotO + h*2*RotC)) |
Volker@43 | 1450 | # C2ge = np.cos(np.deg2rad(2*RotO + h*2*RotC)) |
Volker@43 | 1451 | S2e = np.sin(np.deg2rad(h * 2 * RotC)) |
Volker@43 | 1452 | C2e = np.cos(np.deg2rad(2 * RotC)) |
Volker@43 | 1453 | # rotated AinP by epsilon Eq. C.3 |
Volker@43 | 1454 | ATP2e = C2e * ATP2 + S2e * ATP3 |
Volker@43 | 1455 | ATP3e = C2e * ATP3 - S2e * ATP2 |
Volker@43 | 1456 | ARP2e = C2e * ARP2 + S2e * ARP3 |
Volker@43 | 1457 | ARP3e = C2e * ARP3 - S2e * ARP2 |
Volker@43 | 1458 | ATPe = np.array([ATP1, ATP2e, ATP3e, ATP4]) |
Volker@43 | 1459 | ARPe = np.array([ARP1, ARP2e, ARP3e, ARP4]) |
Volker@43 | 1460 | # Stokes Input Vector before the polarising beam splitter Eq. E.31 |
Volker@43 | 1461 | A = C2g * QinE - S2g * UinE |
Volker@43 | 1462 | B = S2g * QinE + C2g * UinE |
Volker@43 | 1463 | # C = (WiO*aCal*B + ZiO*SinO*(1-2*aCal)*VinE) |
Volker@43 | 1464 | Co = ZiO * SinO * VinE |
Volker@43 | 1465 | Ca = (WiO * B - 2 * ZiO * SinO * VinE) |
Volker@43 | 1466 | # C = Co + aCal*Ca |
Volker@43 | 1467 | # IinP = (IinE + DiO*aCal*A) |
Volker@43 | 1468 | # QinP = (C2g*DiO*IinE + aCal*QinE - S2g*C) |
Volker@43 | 1469 | # UinP = (S2g*DiO*IinE - aCal*UinE + C2g*C) |
Volker@43 | 1470 | # VinP = (ZiO*SinO*aCal*B + ZiO*CosO*(1-2*aCal)*VinE) |
Volker@43 | 1471 | IinPo = IinE |
Volker@43 | 1472 | QinPo = (C2g * DiO * IinE - S2g * Co) |
Volker@43 | 1473 | UinPo = (S2g * DiO * IinE + C2g * Co) |
Volker@43 | 1474 | VinPo = ZiO * CosO * VinE |
Volker@43 | 1475 | |
Volker@43 | 1476 | IinPa = DiO * A |
Volker@43 | 1477 | QinPa = QinE - S2g * Ca |
Volker@43 | 1478 | UinPa = -UinE + C2g * Ca |
Volker@43 | 1479 | VinPa = ZiO * (SinO * B - 2 * CosO * VinE) |
Volker@43 | 1480 | |
Volker@43 | 1481 | IinP = IinPo + aCal * IinPa |
Volker@43 | 1482 | QinP = QinPo + aCal * QinPa |
Volker@43 | 1483 | UinP = UinPo + aCal * UinPa |
Volker@43 | 1484 | VinP = VinPo + aCal * VinPa |
Volker@43 | 1485 | # Stokes Input Vector before the polarising beam splitter rotated by epsilon Eq. C.3 |
Volker@43 | 1486 | # QinPe = C2e*QinP + S2e*UinP |
Volker@43 | 1487 | # UinPe = C2e*UinP - S2e*QinP |
Volker@43 | 1488 | QinPoe = C2e * QinPo + S2e * UinPo |
Volker@43 | 1489 | UinPoe = C2e * UinPo - S2e * QinPo |
Volker@43 | 1490 | QinPae = C2e * QinPa + S2e * UinPa |
Volker@43 | 1491 | UinPae = C2e * UinPa - S2e * QinPa |
Volker@43 | 1492 | QinPe = C2e * QinP + S2e * UinP |
Volker@43 | 1493 | UinPe = C2e * UinP - S2e * QinP |
Volker@43 | 1494 | |
Volker@43 | 1495 | # Calibration signals and Calibration correction K from measurements with LDRCal / aCal |
Volker@43 | 1496 | if (TypeC == 2) or (TypeC == 1): # rotator calibration Eq. C.4 |
Volker@43 | 1497 | # parameters for calibration with aCal |
Volker@43 | 1498 | AT = ATP1 * IinP + h * ATP4 * VinP |
Volker@43 | 1499 | BT = ATP3e * QinP - h * ATP2e * UinP |
Volker@43 | 1500 | AR = ARP1 * IinP + h * ARP4 * VinP |
Volker@43 | 1501 | BR = ARP3e * QinP - h * ARP2e * UinP |
Volker@43 | 1502 | # Correction parameters for normal measurements; they are independent of LDR |
Volker@43 | 1503 | if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out |
Volker@43 | 1504 | IS1 = np.array([IinPo, QinPo, UinPo, VinPo]) |
Volker@43 | 1505 | IS2 = np.array([IinPa, QinPa, UinPa, VinPa]) |
Volker@43 | 1506 | GT = np.dot(ATP, IS1) |
Volker@43 | 1507 | GR = np.dot(ARP, IS1) |
Volker@43 | 1508 | HT = np.dot(ATP, IS2) |
Volker@43 | 1509 | HR = np.dot(ARP, IS2) |
Volker@43 | 1510 | else: |
Volker@43 | 1511 | IS1 = np.array([IinPo, QinPo, UinPo, VinPo]) |
Volker@43 | 1512 | IS2 = np.array([IinPa, QinPa, UinPa, VinPa]) |
Volker@43 | 1513 | GT = np.dot(ATPe, IS1) |
Volker@43 | 1514 | GR = np.dot(ARPe, IS1) |
Volker@43 | 1515 | HT = np.dot(ATPe, IS2) |
Volker@43 | 1516 | HR = np.dot(ARPe, IS2) |
Volker@43 | 1517 | elif (TypeC == 3) or (TypeC == 4): # linear polariser calibration Eq. C.5 |
Volker@43 | 1518 | # parameters for calibration with aCal |
Volker@43 | 1519 | AT = ATP1 * IinP + ATP3e * UinPe + ZiC * CosC * (ATP2e * QinPe + ATP4 * VinP) |
Volker@43 | 1520 | BT = DiC * (ATP1 * UinPe + ATP3e * IinP) - ZiC * SinC * (ATP2e * VinP - ATP4 * QinPe) |
Volker@43 | 1521 | AR = ARP1 * IinP + ARP3e * UinPe + ZiC * CosC * (ARP2e * QinPe + ARP4 * VinP) |
Volker@43 | 1522 | BR = DiC * (ARP1 * UinPe + ARP3e * IinP) - ZiC * SinC * (ARP2e * VinP - ARP4 * QinPe) |
Volker@43 | 1523 | # Correction parameters for normal measurements; they are independent of LDR |
Volker@43 | 1524 | if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out |
Volker@43 | 1525 | IS1 = np.array([IinPo, QinPo, UinPo, VinPo]) |
Volker@43 | 1526 | IS2 = np.array([IinPa, QinPa, UinPa, VinPa]) |
Volker@43 | 1527 | GT = np.dot(ATP, IS1) |
Volker@43 | 1528 | GR = np.dot(ARP, IS1) |
Volker@43 | 1529 | HT = np.dot(ATP, IS2) |
Volker@43 | 1530 | HR = np.dot(ARP, IS2) |
Volker@43 | 1531 | else: |
Volker@43 | 1532 | IS1e = np.array( |
Volker@43 | 1533 | [IinPo + DiC * QinPoe, DiC * IinPo + QinPoe, ZiC * (CosC * UinPoe + SinC * VinPo), |
Volker@43 | 1534 | -ZiC * (SinC * UinPoe - CosC * VinPo)]) |
Volker@43 | 1535 | IS2e = np.array( |
Volker@43 | 1536 | [IinPa + DiC * QinPae, DiC * IinPa + QinPae, ZiC * (CosC * UinPae + SinC * VinPa), |
Volker@43 | 1537 | -ZiC * (SinC * UinPae - CosC * VinPa)]) |
Volker@43 | 1538 | GT = np.dot(ATPe, IS1e) |
Volker@43 | 1539 | GR = np.dot(ARPe, IS1e) |
Volker@43 | 1540 | HT = np.dot(ATPe, IS2e) |
Volker@43 | 1541 | HR = np.dot(ARPe, IS2e) |
Volker@43 | 1542 | elif (TypeC == 6): # diattenuator calibration +-22.5° rotated_diattenuator_X22x5deg.odt |
Volker@43 | 1543 | # parameters for calibration with aCal |
Volker@43 | 1544 | AT = ATP1 * IinP + sqr05 * DiC * (ATP1 * QinPe + ATP2e * IinP) + (1 - 0.5 * WiC) * ( |
Volker@43 | 1545 | ATP2e * QinPe + ATP3e * UinPe) + ZiC * ( |
Volker@43 | 1546 | sqr05 * SinC * (ATP3e * VinP - ATP4 * UinPe) + ATP4 * CosC * VinP) |
Volker@43 | 1547 | BT = sqr05 * DiC * (ATP1 * UinPe + ATP3e * IinP) + 0.5 * WiC * ( |
Volker@43 | 1548 | ATP2e * UinPe + ATP3e * QinPe) - sqr05 * ZiC * SinC * (ATP2e * VinP - ATP4 * QinPe) |
Volker@43 | 1549 | AR = ARP1 * IinP + sqr05 * DiC * (ARP1 * QinPe + ARP2e * IinP) + (1 - 0.5 * WiC) * ( |
Volker@43 | 1550 | ARP2e * QinPe + ARP3e * UinPe) + ZiC * ( |
Volker@43 | 1551 | sqr05 * SinC * (ARP3e * VinP - ARP4 * UinPe) + ARP4 * CosC * VinP) |
Volker@43 | 1552 | BR = sqr05 * DiC * (ARP1 * UinPe + ARP3e * IinP) + 0.5 * WiC * ( |
Volker@43 | 1553 | ARP2e * UinPe + ARP3e * QinPe) - sqr05 * ZiC * SinC * (ARP2e * VinP - ARP4 * QinPe) |
Volker@43 | 1554 | # Correction parameters for normal measurements; they are independent of LDR |
Volker@43 | 1555 | if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out |
Volker@43 | 1556 | IS1 = np.array([IinPo, QinPo, UinPo, VinPo]) |
Volker@43 | 1557 | IS2 = np.array([IinPa, QinPa, UinPa, VinPa]) |
Volker@43 | 1558 | GT = np.dot(ATP, IS1) |
Volker@43 | 1559 | GR = np.dot(ARP, IS1) |
Volker@43 | 1560 | HT = np.dot(ATP, IS2) |
Volker@43 | 1561 | HR = np.dot(ARP, IS2) |
Volker@43 | 1562 | else: |
Volker@43 | 1563 | IS1e = np.array( |
Volker@43 | 1564 | [IinPo + DiC * QinPoe, DiC * IinPo + QinPoe, ZiC * (CosC * UinPoe + SinC * VinPo), |
Volker@43 | 1565 | -ZiC * (SinC * UinPoe - CosC * VinPo)]) |
Volker@43 | 1566 | IS2e = np.array( |
Volker@43 | 1567 | [IinPa + DiC * QinPae, DiC * IinPa + QinPae, ZiC * (CosC * UinPae + SinC * VinPa), |
Volker@43 | 1568 | -ZiC * (SinC * UinPae - CosC * VinPa)]) |
Volker@43 | 1569 | GT = np.dot(ATPe, IS1e) |
Volker@43 | 1570 | GR = np.dot(ARPe, IS1e) |
Volker@43 | 1571 | HT = np.dot(ATPe, IS2e) |
Volker@43 | 1572 | HR = np.dot(ARPe, IS2e) |
Volker@43 | 1573 | else: |
Volker@43 | 1574 | print("Calibrator not implemented yet") |
Volker@43 | 1575 | sys.exit() |
Volker@43 | 1576 | |
Volker@43 | 1577 | elif LocC == 3: # C before receiver optics Eq.57 |
Volker@43 | 1578 | |
Volker@43 | 1579 | # S2ge = np.sin(np.deg2rad(2*RotO - 2*RotC)) |
Volker@43 | 1580 | # C2ge = np.cos(np.deg2rad(2*RotO - 2*RotC)) |
Volker@43 | 1581 | S2e = np.sin(np.deg2rad(2 * RotC)) |
Volker@43 | 1582 | C2e = np.cos(np.deg2rad(2 * RotC)) |
Volker@43 | 1583 | |
Volker@43 | 1584 | # AS with C before the receiver optics (see document rotated_diattenuator_X22x5deg.odt) |
Volker@43 | 1585 | AF1 = np.array([1, C2g * DiO, S2g * DiO, 0]) |
Volker@43 | 1586 | AF2 = np.array([C2g * DiO, 1 - S2g ** 2 * WiO, S2g * C2g * WiO, -S2g * ZiO * SinO]) |
Volker@43 | 1587 | AF3 = np.array([S2g * DiO, S2g * C2g * WiO, 1 - C2g ** 2 * WiO, C2g * ZiO * SinO]) |
Volker@43 | 1588 | AF4 = np.array([0, S2g * SinO, -C2g * SinO, CosO]) |
Volker@43 | 1589 | |
Volker@43 | 1590 | ATF = (ATP1 * AF1 + ATP2 * AF2 + ATP3 * AF3 + ATP4 * AF4) |
Volker@43 | 1591 | ARF = (ARP1 * AF1 + ARP2 * AF2 + ARP3 * AF3 + ARP4 * AF4) |
Volker@43 | 1592 | ATF1 = ATF[0] |
Volker@43 | 1593 | ATF2 = ATF[1] |
Volker@43 | 1594 | ATF3 = ATF[2] |
Volker@43 | 1595 | ATF4 = ATF[3] |
Volker@43 | 1596 | ARF1 = ARF[0] |
Volker@43 | 1597 | ARF2 = ARF[1] |
Volker@43 | 1598 | ARF3 = ARF[2] |
Volker@43 | 1599 | ARF4 = ARF[3] |
Volker@43 | 1600 | |
Volker@43 | 1601 | # rotated AinF by epsilon |
Volker@43 | 1602 | ATF2e = C2e * ATF[1] + S2e * ATF[2] |
Volker@43 | 1603 | ATF3e = C2e * ATF[2] - S2e * ATF[1] |
Volker@43 | 1604 | ARF2e = C2e * ARF[1] + S2e * ARF[2] |
Volker@43 | 1605 | ARF3e = C2e * ARF[2] - S2e * ARF[1] |
Volker@43 | 1606 | |
Volker@43 | 1607 | ATFe = np.array([ATF1, ATF2e, ATF3e, ATF4]) |
Volker@43 | 1608 | ARFe = np.array([ARF1, ARF2e, ARF3e, ARF4]) |
Volker@43 | 1609 | |
Volker@43 | 1610 | QinEe = C2e * QinE + S2e * UinE |
Volker@43 | 1611 | UinEe = C2e * UinE - S2e * QinE |
Volker@43 | 1612 | |
Volker@43 | 1613 | # Stokes Input Vector before receiver optics Eq. E.19 (after atmosphere F) |
Volker@43 | 1614 | IinF = IinE |
Volker@43 | 1615 | QinF = aCal * QinE |
Volker@43 | 1616 | UinF = -aCal * UinE |
Volker@43 | 1617 | VinF = (1. - 2. * aCal) * VinE |
Volker@43 | 1618 | |
Volker@43 | 1619 | IinFo = IinE |
Volker@43 | 1620 | QinFo = 0. |
Volker@43 | 1621 | UinFo = 0. |
Volker@43 | 1622 | VinFo = VinE |
Volker@43 | 1623 | |
Volker@43 | 1624 | IinFa = 0. |
Volker@43 | 1625 | QinFa = QinE |
Volker@43 | 1626 | UinFa = -UinE |
Volker@43 | 1627 | VinFa = -2. * VinE |
Volker@43 | 1628 | |
Volker@43 | 1629 | # Stokes Input Vector before receiver optics rotated by epsilon Eq. C.3 |
Volker@43 | 1630 | QinFe = C2e * QinF + S2e * UinF |
Volker@43 | 1631 | UinFe = C2e * UinF - S2e * QinF |
Volker@43 | 1632 | QinFoe = C2e * QinFo + S2e * UinFo |
Volker@43 | 1633 | UinFoe = C2e * UinFo - S2e * QinFo |
Volker@43 | 1634 | QinFae = C2e * QinFa + S2e * UinFa |
Volker@43 | 1635 | UinFae = C2e * UinFa - S2e * QinFa |
Volker@43 | 1636 | |
Volker@43 | 1637 | # Calibration signals and Calibration correction K from measurements with LDRCal / aCal |
Volker@43 | 1638 | if (TypeC == 2) or (TypeC == 1): # rotator calibration Eq. C.4 |
Volker@43 | 1639 | AT = ATF1 * IinF + ATF4 * h * VinF |
Volker@43 | 1640 | BT = ATF3e * QinF - ATF2e * h * UinF |
Volker@43 | 1641 | AR = ARF1 * IinF + ARF4 * h * VinF |
Volker@43 | 1642 | BR = ARF3e * QinF - ARF2e * h * UinF |
Volker@43 | 1643 | |
Volker@43 | 1644 | # Correction parameters for normal measurements; they are independent of LDR |
Volker@43 | 1645 | if (not RotationErrorEpsilonForNormalMeasurements): |
Volker@43 | 1646 | GT = ATF1 * IinE + ATF4 * VinE |
Volker@43 | 1647 | GR = ARF1 * IinE + ARF4 * VinE |
Volker@43 | 1648 | HT = ATF2 * QinE - ATF3 * UinE - ATF4 * 2 * VinE |
Volker@43 | 1649 | HR = ARF2 * QinE - ARF3 * UinE - ARF4 * 2 * VinE |
Volker@43 | 1650 | else: |
Volker@43 | 1651 | GT = ATF1 * IinE + ATF4 * h * VinE |
Volker@43 | 1652 | GR = ARF1 * IinE + ARF4 * h * VinE |
Volker@43 | 1653 | HT = ATF2e * QinE - ATF3e * h * UinE - ATF4 * h * 2 * VinE |
Volker@43 | 1654 | HR = ARF2e * QinE - ARF3e * h * UinE - ARF4 * h * 2 * VinE |
Volker@43 | 1655 | |
Volker@43 | 1656 | elif (TypeC == 3) or (TypeC == 4): # linear polariser calibration Eq. C.5 |
Volker@43 | 1657 | # p = +45°, m = -45° |
Volker@43 | 1658 | IF1e = np.array([IinF, ZiC * CosC * QinFe, UinFe, ZiC * CosC * VinF]) |
Volker@43 | 1659 | IF2e = np.array([DiC * UinFe, -ZiC * SinC * VinF, DiC * IinF, ZiC * SinC * QinFe]) |
Volker@43 | 1660 | |
Volker@43 | 1661 | AT = np.dot(ATFe, IF1e) |
Volker@43 | 1662 | AR = np.dot(ARFe, IF1e) |
Volker@43 | 1663 | BT = np.dot(ATFe, IF2e) |
Volker@43 | 1664 | BR = np.dot(ARFe, IF2e) |
Volker@43 | 1665 | |
Volker@43 | 1666 | # Correction parameters for normal measurements; they are independent of LDR --- the same as for TypeC = 6 |
Volker@43 | 1667 | if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out |
Volker@43 | 1668 | IS1 = np.array([IinE, 0, 0, VinE]) |
Volker@43 | 1669 | IS2 = np.array([0, QinE, -UinE, -2 * VinE]) |
Volker@43 | 1670 | |
Volker@43 | 1671 | GT = np.dot(ATF, IS1) |
Volker@43 | 1672 | GR = np.dot(ARF, IS1) |
Volker@43 | 1673 | HT = np.dot(ATF, IS2) |
Volker@43 | 1674 | HR = np.dot(ARF, IS2) |
Volker@43 | 1675 | else: |
Volker@43 | 1676 | IS1e = np.array( |
Volker@43 | 1677 | [IinFo + DiC * QinFoe, DiC * IinFo + QinFoe, ZiC * (CosC * UinFoe + SinC * VinFo), |
Volker@43 | 1678 | -ZiC * (SinC * UinFoe - CosC * VinFo)]) |
Volker@43 | 1679 | IS2e = np.array( |
Volker@43 | 1680 | [IinFa + DiC * QinFae, DiC * IinFa + QinFae, ZiC * (CosC * UinFae + SinC * VinFa), |
Volker@43 | 1681 | -ZiC * (SinC * UinFae - CosC * VinFa)]) |
Volker@43 | 1682 | GT = np.dot(ATFe, IS1e) |
Volker@43 | 1683 | GR = np.dot(ARFe, IS1e) |
Volker@43 | 1684 | HT = np.dot(ATFe, IS2e) |
Volker@43 | 1685 | HR = np.dot(ARFe, IS2e) |
Volker@43 | 1686 | |
Volker@43 | 1687 | elif (TypeC == 6): # diattenuator calibration +-22.5° rotated_diattenuator_X22x5deg.odt |
Volker@43 | 1688 | # p = +22.5°, m = -22.5° |
Volker@43 | 1689 | IF1e = np.array([IinF + sqr05 * DiC * QinFe, sqr05 * DiC * IinF + (1 - 0.5 * WiC) * QinFe, |
Volker@43 | 1690 | (1 - 0.5 * WiC) * UinFe + sqr05 * ZiC * SinC * VinF, |
Volker@43 | 1691 | -sqr05 * ZiC * SinC * UinFe + ZiC * CosC * VinF]) |
Volker@43 | 1692 | IF2e = np.array([sqr05 * DiC * UinFe, 0.5 * WiC * UinFe - sqr05 * ZiC * SinC * VinF, |
Volker@43 | 1693 | sqr05 * DiC * IinF + 0.5 * WiC * QinFe, sqr05 * ZiC * SinC * QinFe]) |
Volker@43 | 1694 | |
Volker@43 | 1695 | AT = np.dot(ATFe, IF1e) |
Volker@43 | 1696 | AR = np.dot(ARFe, IF1e) |
Volker@43 | 1697 | BT = np.dot(ATFe, IF2e) |
Volker@43 | 1698 | BR = np.dot(ARFe, IF2e) |
Volker@43 | 1699 | |
Volker@43 | 1700 | # Correction parameters for normal measurements; they are independent of LDR |
Volker@43 | 1701 | if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out |
Volker@43 | 1702 | # IS1 = np.array([IinE,0,0,VinE]) |
Volker@43 | 1703 | # IS2 = np.array([0,QinE,-UinE,-2*VinE]) |
Volker@43 | 1704 | IS1 = np.array([IinFo, 0, 0, VinFo]) |
Volker@43 | 1705 | IS2 = np.array([0, QinFa, UinFa, VinFa]) |
Volker@43 | 1706 | GT = np.dot(ATF, IS1) |
Volker@43 | 1707 | GR = np.dot(ARF, IS1) |
Volker@43 | 1708 | HT = np.dot(ATF, IS2) |
Volker@43 | 1709 | HR = np.dot(ARF, IS2) |
Volker@43 | 1710 | else: |
Volker@43 | 1711 | # IS1e = np.array([IinE,DiC*IinE,ZiC*SinC*VinE,ZiC*CosC*VinE]) |
Volker@43 | 1712 | # IS2e = np.array([DiC*QinEe,QinEe,-ZiC*(CosC*UinEe+2*SinC*VinE),ZiC*(SinC*UinEe-2*CosC*VinE)]) |
Volker@43 | 1713 | IS1e = np.array( |
Volker@43 | 1714 | [IinFo + DiC * QinFoe, DiC * IinFo + QinFoe, ZiC * (CosC * UinFoe + SinC * VinFo), |
Volker@43 | 1715 | -ZiC * (SinC * UinFoe - CosC * VinFo)]) |
Volker@43 | 1716 | IS2e = np.array( |
Volker@43 | 1717 | [IinFa + DiC * QinFae, DiC * IinFa + QinFae, ZiC * (CosC * UinFae + SinC * VinFa), |
Volker@43 | 1718 | -ZiC * (SinC * UinFae - CosC * VinFa)]) |
Volker@43 | 1719 | GT = np.dot(ATFe, IS1e) |
Volker@43 | 1720 | GR = np.dot(ARFe, IS1e) |
Volker@43 | 1721 | HT = np.dot(ATFe, IS2e) |
Volker@43 | 1722 | HR = np.dot(ARFe, IS2e) |
Volker@43 | 1723 | |
Volker@43 | 1724 | |
Volker@43 | 1725 | else: |
Volker@43 | 1726 | print('Calibrator not implemented yet') |
Volker@43 | 1727 | sys.exit() |
Volker@43 | 1728 | |
Volker@43 | 1729 | elif LocC == 2: # C behind emitter optics Eq.57 |
Volker@43 | 1730 | # print("Calibrator location not implemented yet") |
Volker@43 | 1731 | S2e = np.sin(np.deg2rad(2 * RotC)) |
Volker@43 | 1732 | C2e = np.cos(np.deg2rad(2 * RotC)) |
Volker@43 | 1733 | |
Volker@43 | 1734 | # AS with C before the receiver optics (see document rotated_diattenuator_X22x5deg.odt) |
Volker@43 | 1735 | AF1 = np.array([1, C2g * DiO, S2g * DiO, 0]) |
Volker@43 | 1736 | AF2 = np.array([C2g * DiO, 1 - S2g ** 2 * WiO, S2g * C2g * WiO, -S2g * ZiO * SinO]) |
Volker@43 | 1737 | AF3 = np.array([S2g * DiO, S2g * C2g * WiO, 1 - C2g ** 2 * WiO, C2g * ZiO * SinO]) |
Volker@43 | 1738 | AF4 = np.array([0, S2g * SinO, -C2g * SinO, CosO]) |
Volker@43 | 1739 | |
Volker@43 | 1740 | ATF = (ATP1 * AF1 + ATP2 * AF2 + ATP3 * AF3 + ATP4 * AF4) |
Volker@43 | 1741 | ARF = (ARP1 * AF1 + ARP2 * AF2 + ARP3 * AF3 + ARP4 * AF4) |
Volker@43 | 1742 | ATF1 = ATF[0] |
Volker@43 | 1743 | ATF2 = ATF[1] |
Volker@43 | 1744 | ATF3 = ATF[2] |
Volker@43 | 1745 | ATF4 = ATF[3] |
Volker@43 | 1746 | ARF1 = ARF[0] |
Volker@43 | 1747 | ARF2 = ARF[1] |
Volker@43 | 1748 | ARF3 = ARF[2] |
Volker@43 | 1749 | ARF4 = ARF[3] |
Volker@43 | 1750 | |
Volker@43 | 1751 | # AS with C behind the emitter -------------------------------------------- |
Volker@43 | 1752 | # terms without aCal |
Volker@43 | 1753 | ATE1o, ARE1o = ATF1, ARF1 |
Volker@43 | 1754 | ATE2o, ARE2o = 0., 0. |
Volker@43 | 1755 | ATE3o, ARE3o = 0., 0. |
Volker@43 | 1756 | ATE4o, ARE4o = ATF4, ARF4 |
Volker@43 | 1757 | # terms with aCal |
Volker@43 | 1758 | ATE1a, ARE1a = 0., 0. |
Volker@43 | 1759 | ATE2a, ARE2a = ATF2, ARF2 |
Volker@43 | 1760 | ATE3a, ARE3a = -ATF3, -ARF3 |
Volker@43 | 1761 | ATE4a, ARE4a = -2 * ATF4, -2 * ARF4 |
Volker@43 | 1762 | # rotated AinEa by epsilon |
Volker@43 | 1763 | ATE2ae = C2e * ATF2 + S2e * ATF3 |
Volker@43 | 1764 | ATE3ae = -S2e * ATF2 - C2e * ATF3 |
Volker@43 | 1765 | ARE2ae = C2e * ARF2 + S2e * ARF3 |
Volker@43 | 1766 | ARE3ae = -S2e * ARF2 - C2e * ARF3 |
Volker@43 | 1767 | |
Volker@43 | 1768 | ATE1 = ATE1o |
Volker@43 | 1769 | ATE2e = aCal * ATE2ae |
Volker@43 | 1770 | ATE3e = aCal * ATE3ae |
Volker@43 | 1771 | ATE4 = (1 - 2 * aCal) * ATF4 |
Volker@43 | 1772 | ARE1 = ARE1o |
Volker@43 | 1773 | ARE2e = aCal * ARE2ae |
Volker@43 | 1774 | ARE3e = aCal * ARE3ae |
Volker@43 | 1775 | ARE4 = (1. - 2. * aCal) * ARF4 |
Volker@43 | 1776 | |
Volker@43 | 1777 | # rotated IinE |
Volker@43 | 1778 | QinEe = C2e * QinE + S2e * UinE |
Volker@43 | 1779 | UinEe = C2e * UinE - S2e * QinE |
Volker@43 | 1780 | |
Volker@43 | 1781 | # --- Calibration signals and Calibration correction K from measurements with LDRCal / aCal |
Volker@43 | 1782 | if (TypeC == 2) or (TypeC == 1): # +++++++++ rotator calibration Eq. C.4 |
Volker@43 | 1783 | AT = ATE1o * IinE + (ATE4o + aCal * ATE4a) * h * VinE |
Volker@43 | 1784 | BT = aCal * (ATE3ae * QinEe - ATE2ae * h * UinEe) |
Volker@43 | 1785 | AR = ARE1o * IinE + (ARE4o + aCal * ARE4a) * h * VinE |
Volker@43 | 1786 | BR = aCal * (ARE3ae * QinEe - ARE2ae * h * UinEe) |
Volker@43 | 1787 | |
Volker@43 | 1788 | # Correction parameters for normal measurements; they are independent of LDR |
Volker@43 | 1789 | if (not RotationErrorEpsilonForNormalMeasurements): |
Volker@43 | 1790 | # Stokes Input Vector before receiver optics Eq. E.19 (after atmosphere F) |
Volker@43 | 1791 | GT = ATE1o * IinE + ATE4o * h * VinE |
Volker@43 | 1792 | GR = ARE1o * IinE + ARE4o * h * VinE |
Volker@43 | 1793 | HT = ATE2a * QinE + ATE3a * h * UinEe + ATE4a * h * VinE |
Volker@43 | 1794 | HR = ARE2a * QinE + ARE3a * h * UinEe + ARE4a * h * VinE |
Volker@43 | 1795 | else: |
Volker@43 | 1796 | GT = ATE1o * IinE + ATE4o * h * VinE |
Volker@43 | 1797 | GR = ARE1o * IinE + ARE4o * h * VinE |
Volker@43 | 1798 | HT = ATE2ae * QinE + ATE3ae * h * UinEe + ATE4a * h * VinE |
Volker@43 | 1799 | HR = ARE2ae * QinE + ARE3ae * h * UinEe + ARE4a * h * VinE |
Volker@43 | 1800 | |
Volker@43 | 1801 | elif (TypeC == 3) or (TypeC == 4): # +++++++++ linear polariser calibration Eq. C.5 |
Volker@43 | 1802 | # p = +45°, m = -45° |
Volker@43 | 1803 | AT = ATE1 * IinE + ZiC * CosC * (ATE2e * QinEe + ATE4 * VinE) + ATE3e * UinEe |
Volker@43 | 1804 | BT = DiC * (ATE1 * UinEe + ATE3e * IinE) + ZiC * SinC * (ATE4 * QinEe - ATE2e * VinE) |
Volker@43 | 1805 | AR = ARE1 * IinE + ZiC * CosC * (ARE2e * QinEe + ARE4 * VinE) + ARE3e * UinEe |
Volker@43 | 1806 | BR = DiC * (ARE1 * UinEe + ARE3e * IinE) + ZiC * SinC * (ARE4 * QinEe - ARE2e * VinE) |
Volker@43 | 1807 | |
Volker@43 | 1808 | # Correction parameters for normal measurements; they are independent of LDR |
Volker@43 | 1809 | if (not RotationErrorEpsilonForNormalMeasurements): |
Volker@43 | 1810 | # Stokes Input Vector before receiver optics Eq. E.19 (after atmosphere F) |
Volker@43 | 1811 | GT = ATE1o * IinE + ATE4o * VinE |
Volker@43 | 1812 | GR = ARE1o * IinE + ARE4o * VinE |
Volker@43 | 1813 | HT = ATE2a * QinE + ATE3a * UinE + ATE4a * VinE |
Volker@43 | 1814 | HR = ARE2a * QinE + ARE3a * UinE + ARE4a * VinE |
Volker@43 | 1815 | else: |
Volker@43 | 1816 | D = IinE + DiC * QinEe |
Volker@43 | 1817 | A = DiC * IinE + QinEe |
Volker@43 | 1818 | B = ZiC * (CosC * UinEe + SinC * VinE) |
Volker@43 | 1819 | C = -ZiC * (SinC * UinEe - CosC * VinE) |
Volker@43 | 1820 | GT = ATE1o * D + ATE4o * C |
Volker@43 | 1821 | GR = ARE1o * D + ARE4o * C |
Volker@43 | 1822 | HT = ATE2a * A + ATE3a * B + ATE4a * C |
Volker@43 | 1823 | HR = ARE2a * A + ARE3a * B + ARE4a * C |
Volker@43 | 1824 | |
Volker@43 | 1825 | elif (TypeC == 6): # real HWP calibration +-22.5° rotated_diattenuator_X22x5deg.odt |
Volker@43 | 1826 | # p = +22.5°, m = -22.5° |
Volker@43 | 1827 | IE1e = np.array([IinE + sqr05 * DiC * QinEe, sqr05 * DiC * IinE + (1 - 0.5 * WiC) * QinEe, |
Volker@43 | 1828 | (1. - 0.5 * WiC) * UinEe + sqr05 * ZiC * SinC * VinE, |
Volker@43 | 1829 | -sqr05 * ZiC * SinC * UinEe + ZiC * CosC * VinE]) |
Volker@43 | 1830 | IE2e = np.array([sqr05 * DiC * UinEe, 0.5 * WiC * UinEe - sqr05 * ZiC * SinC * VinE, |
Volker@43 | 1831 | sqr05 * DiC * IinE + 0.5 * WiC * QinEe, sqr05 * ZiC * SinC * QinEe]) |
Volker@43 | 1832 | ATEe = np.array([ATE1, ATE2e, ATE3e, ATE4]) |
Volker@43 | 1833 | AREe = np.array([ARE1, ARE2e, ARE3e, ARE4]) |
Volker@43 | 1834 | AT = np.dot(ATEe, IE1e) |
Volker@43 | 1835 | AR = np.dot(AREe, IE1e) |
Volker@43 | 1836 | BT = np.dot(ATEe, IE2e) |
Volker@43 | 1837 | BR = np.dot(AREe, IE2e) |
Volker@43 | 1838 | |
Volker@43 | 1839 | # Correction parameters for normal measurements; they are independent of LDR |
Volker@43 | 1840 | if (not RotationErrorEpsilonForNormalMeasurements): # calibrator taken out |
Volker@43 | 1841 | GT = ATE1o * IinE + ATE4o * VinE |
Volker@43 | 1842 | GR = ARE1o * IinE + ARE4o * VinE |
Volker@43 | 1843 | HT = ATE2a * QinE + ATE3a * UinE + ATE4a * VinE |
Volker@43 | 1844 | HR = ARE2a * QinE + ARE3a * UinE + ARE4a * VinE |
Volker@43 | 1845 | else: |
Volker@43 | 1846 | D = IinE + DiC * QinEe |
Volker@43 | 1847 | A = DiC * IinE + QinEe |
Volker@43 | 1848 | B = ZiC * (CosC * UinEe + SinC * VinE) |
Volker@43 | 1849 | C = -ZiC * (SinC * UinEe - CosC * VinE) |
Volker@43 | 1850 | GT = ATE1o * D + ATE4o * C |
Volker@43 | 1851 | GR = ARE1o * D + ARE4o * C |
Volker@43 | 1852 | HT = ATE2a * A + ATE3a * B + ATE4a * C |
Volker@43 | 1853 | HR = ARE2a * A + ARE3a * B + ARE4a * C |
Volker@43 | 1854 | else: |
Volker@43 | 1855 | print('Calibrator not implemented yet') |
Volker@43 | 1856 | sys.exit() |
Volker@43 | 1857 | |
Volker@43 | 1858 | for iTCalT, iTCalR, iNCalTp, iNCalTm, iNCalRp, iNCalRm, iNIt, iNIr \ |
Volker@43 | 1859 | in [ |
Volker@43 | 1860 | (iTCalT, iTCalR, iNCalTp, iNCalTm, iNCalRp, iNCalRm, iNIt, iNIr) |
Volker@43 | 1861 | for iTCalT in range(-nTCalT, nTCalT + 1) # Etax |
Volker@43 | 1862 | for iTCalR in range(-nTCalR, nTCalR + 1) # Etax |
Volker@43 | 1863 | for iNCalTp in range(-nNCal, nNCal + 1) # noise error of calibration signals => Etax |
Volker@43 | 1864 | for iNCalTm in range(-nNCal, nNCal + 1) # noise error of calibration signals => Etax |
Volker@43 | 1865 | for iNCalRp in range(-nNCal, nNCal + 1) # noise error of calibration signals => Etax |
Volker@43 | 1866 | for iNCalRm in range(-nNCal, nNCal + 1) # noise error of calibration signals => Etax |
Volker@43 | 1867 | for iNIt in range(-nNI, nNI + 1) |
Volker@43 | 1868 | for iNIr in range(-nNI, nNI + 1)]: |
Volker@43 | 1869 | |
Volker@43 | 1870 | # Calibration signals with aCal => Determination of the correction K of the real calibration factor |
Volker@43 | 1871 | IoutTp = TTa * TiC * TiO * TiE * (AT + BT) |
Volker@43 | 1872 | IoutTm = TTa * TiC * TiO * TiE * (AT - BT) |
Volker@43 | 1873 | IoutRp = TRa * TiC * TiO * TiE * (AR + BR) |
Volker@43 | 1874 | IoutRm = TRa * TiC * TiO * TiE * (AR - BR) |
Volker@43 | 1875 | |
Volker@43 | 1876 | if nTCalT > 0: TCalT = TCalT0 + iTCalT * dTCalT / nTCalT |
Volker@43 | 1877 | if nTCalR > 0: TCalR = TCalR0 + iTCalR * dTCalR / nTCalR |
Volker@43 | 1878 | # signal noise errors |
Volker@43 | 1879 | # ----- random error calculation ---------- |
Volker@43 | 1880 | # noise must be calculated from/with the actually measured signals; influence of TCalT, TCalR errors on noise are not considered ? |
Volker@43 | 1881 | # actually measured signal counts are in input file and don't change |
Volker@43 | 1882 | # relative standard deviation of calibration signals with LDRcal; assumed to be statisitcally independent |
Volker@43 | 1883 | # error nNCal: one-sigma in steps to left and right for calibration signals |
Volker@43 | 1884 | if nNCal > 0: |
Volker@43 | 1885 | if (CalcFrom0deg): |
Volker@43 | 1886 | dIoutTp = (NCalT * IoutTp) ** -0.5 |
Volker@43 | 1887 | dIoutTm = (NCalT * IoutTm) ** -0.5 |
Volker@43 | 1888 | dIoutRp = (NCalR * IoutRp) ** -0.5 |
Volker@43 | 1889 | dIoutRm = (NCalR * IoutRm) ** -0.5 |
Volker@43 | 1890 | else: |
Volker@43 | 1891 | dIoutTp = dIoutTp0 * (IoutTp / IoutTp0) |
Volker@43 | 1892 | dIoutTm = dIoutTm0 * (IoutTm / IoutTm0) |
Volker@43 | 1893 | dIoutRp = dIoutRp0 * (IoutRp / IoutRp0) |
Volker@43 | 1894 | dIoutRm = dIoutRm0 * (IoutRm / IoutRm0) |
Volker@43 | 1895 | # print(iTCalT, iTCalR, iNCalTp, iNCalTm, iNCalRp, iNCalRm, iNIt, iNIr, IoutTp, dIoutTp) |
Volker@43 | 1896 | IoutTp = IoutTp * (1. + iNCalTp * dIoutTp / nNCal) |
Volker@43 | 1897 | IoutTm = IoutTm * (1. + iNCalTm * dIoutTm / nNCal) |
Volker@43 | 1898 | IoutRp = IoutRp * (1. + iNCalRp * dIoutRp / nNCal) |
Volker@43 | 1899 | IoutRm = IoutRm * (1. + iNCalRm * dIoutRm / nNCal) |
Volker@43 | 1900 | |
Volker@43 | 1901 | IoutTp = IoutTp * TCalT / TCalT0 |
Volker@43 | 1902 | IoutTm = IoutTm * TCalT / TCalT0 |
Volker@43 | 1903 | IoutRp = IoutRp * TCalR / TCalR0 |
Volker@43 | 1904 | IoutRm = IoutRm * TCalR / TCalR0 |
Volker@43 | 1905 | # --- Results and Corrections; electronic etaR and etaT are assumed to be 1 for true and assumed true systems |
Volker@43 | 1906 | # calibration factor |
Volker@43 | 1907 | Eta = (TRa / TTa) # = TRa / TTa; Eta = Eta*/K Eq. 84; corrected according to the papers supplement Eqs. (S.10.10.1) ff |
Volker@43 | 1908 | # possibly real calibration factor |
Volker@43 | 1909 | Etapx = IoutRp / IoutTp |
Volker@43 | 1910 | Etamx = IoutRm / IoutTm |
Volker@43 | 1911 | Etax = (Etapx * Etamx) ** 0.5 |
Volker@43 | 1912 | K = Etax / Eta |
Volker@43 | 1913 | # 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@43 | 1914 | # print("{0:6.3f},{1:6.3f},{2:6.3f},{3:6.3f}".format(DiC, ZiC, Kp, Km)) |
Volker@43 | 1915 | |
Volker@43 | 1916 | # For comparison with Volkers Libreoffice Müller Matrix spreadsheet |
Volker@43 | 1917 | # Eta_test_p = (IoutRp/IoutTp) |
Volker@43 | 1918 | # Eta_test_m = (IoutRm/IoutTm) |
Volker@43 | 1919 | # Eta_test = (Eta_test_p*Eta_test_m)**0.5 |
Volker@43 | 1920 | ''' |
Volker@43 | 1921 | for iIt, iIr \ |
Volker@43 | 1922 | in [(iIt, iIr) |
Volker@43 | 1923 | for iIt in range(-nNI, nNI + 1) |
Volker@43 | 1924 | for iIr in range(-nNI, nNI + 1)]: |
Volker@43 | 1925 | ''' |
Volker@43 | 1926 | |
Volker@43 | 1927 | iN = iN + 1 |
Volker@43 | 1928 | if (iN == 10001): |
Volker@43 | 1929 | ctime = clock() |
Volker@43 | 1930 | print(" estimated time ", "{0:4.2f}".format(N / 10000 * (ctime - atime)), "sec ") # , end="") |
Volker@43 | 1931 | print("\r elapsed time ", "{0:5.0f}".format((ctime - atime)), "sec ", end="\r") |
Volker@43 | 1932 | ctime = clock() |
Volker@43 | 1933 | if ((ctime - dtime) > 10): |
Volker@43 | 1934 | print("\r elapsed time ", "{0:5.0f}".format((ctime - atime)), "sec ", end="\r") |
Volker@43 | 1935 | dtime = ctime |
Volker@43 | 1936 | |
Volker@43 | 1937 | # *** loop for different real LDRs ********************************************************************** |
Volker@43 | 1938 | iLDR = -1 |
Volker@43 | 1939 | for LDRTrue in LDRrange: |
Volker@43 | 1940 | iLDR = iLDR + 1 |
Volker@43 | 1941 | atrue = (1. - LDRTrue) / (1. + LDRTrue) |
Volker@43 | 1942 | # ----- Forward simulated signals and LDRsim with atrue; from input file; not considering TiC. |
Volker@43 | 1943 | It = TTa * TiO * TiE * (GT + atrue * HT) # TaT*TiT*TiC*TiO*IinL*(GT+atrue*HT) |
Volker@43 | 1944 | Ir = TRa * TiO * TiE * (GR + atrue * HR) # TaR*TiR*TiC*TiO*IinL*(GR+atrue*HR) |
Volker@43 | 1945 | # # signal noise errors; standard deviation of signals; assumed to be statisitcally independent |
Volker@43 | 1946 | # because the signals depend on LDRtrue, the errors dIt and dIr must be calculated for each LDRtrue |
Volker@43 | 1947 | if (CalcFrom0deg): |
Volker@43 | 1948 | ''' |
Volker@43 | 1949 | dIt = ((NCalT * It / IoutTp * NILfac / TCalT) ** -0.5) |
Volker@43 | 1950 | dIr = ((NCalR * Ir / IoutRp * NILfac / TCalR) ** -0.5) |
Volker@43 | 1951 | ''' |
Volker@43 | 1952 | dIt = ((It * NI * eFacT) ** -0.5) |
Volker@43 | 1953 | dIr = ((Ir * NI * eFacR) ** -0.5) |
Volker@43 | 1954 | else: |
Volker@43 | 1955 | dIt = ((It * NI * eFacT) ** -0.5) |
Volker@43 | 1956 | dIr = ((Ir * NI * eFacR) ** -0.5) |
Volker@43 | 1957 | ''' |
Volker@43 | 1958 | # does this work? Why not as above? |
Volker@43 | 1959 | dIt = ((NCalT * 2. * NILfac / TCalT ) ** -0.5) |
Volker@43 | 1960 | dIr = ((NCalR * 2. * NILfac / TCalR) ** -0.5) |
Volker@43 | 1961 | ''' |
Volker@43 | 1962 | # error nNI: one-sigma in steps to left and right for 0° signals |
Volker@43 | 1963 | if nNI > 0: |
Volker@43 | 1964 | It = It * (1. + iNIt * dIt / nNI) |
Volker@43 | 1965 | Ir = Ir * (1. + iNIr * dIr / nNI) |
Volker@43 | 1966 | |
Volker@43 | 1967 | # LDRsim = 1/Eta*Ir/It # simulated LDR* with Y from input file |
Volker@43 | 1968 | LDRsim = Ir / It # simulated uncorrected LDR with Y from input file |
Volker@43 | 1969 | |
Volker@43 | 1970 | # ----- Backward correction |
Volker@43 | 1971 | # Corrected LDRCorr with assumed true G0,H0,K0,Eta0 from forward simulated (real) LDRsim(atrue) |
Volker@43 | 1972 | LDRCorr = (LDRsim / (Etax / K0) * (GT0 + HT0) - (GR0 + HR0)) / ((GR0 - HR0) - LDRsim / (Etax / K0) * (GT0 - HT0)) |
Volker@43 | 1973 | |
Volker@43 | 1974 | # The following is a test whether the equations for calibration Etax and normal signal (GHK, LDRsim) are consistent |
Volker@43 | 1975 | # LDRCorr = (LDRsim / Eta * (GT + HT) - (GR + HR)) / ((GR - HR) - LDRsim / Eta * (GT - HT)) |
Volker@43 | 1976 | # Without any correction |
Volker@43 | 1977 | LDRunCorr = LDRsim / Etax |
Volker@43 | 1978 | # 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@43 | 1979 | |
Volker@43 | 1980 | |
Volker@43 | 1981 | ''' |
Volker@43 | 1982 | # -- F11corr from It and Ir and calibration EtaX |
Volker@43 | 1983 | Text1 = "!!! EXPERIMENTAL !!! F11corr from It and Ir with calibration EtaX: x-axis: F11corr(LDRtrue) / F11corr(LDRtrue = 0.004) - 1" |
Volker@43 | 1984 | F11corr = 1 / (TiO * TiE) * ( |
Volker@43 | 1985 | (HR0 * Etax / K0 * It / TTa - HT0 * Ir / TRa) / (HR0 * GT0 - HT0 * GR0)) # IL = 1 Eq.(64); Etax/K0 = Eta0. |
Volker@43 | 1986 | ''' |
Volker@43 | 1987 | # Corrected F11corr with assumed true G0,H0,K0 from forward simulated (real) It and Ir (atrue) |
Volker@43 | 1988 | Text1 = "!!! EXPERIMENTAL !!! F11corr from real It and Ir with real calibration EtaX: x-axis: F11corr(LDRtrue) / aF11sim0(LDRtrue) - 1" |
Volker@43 | 1989 | F11corr = 1 / (TiO * TiE) * ( |
Volker@43 | 1990 | (HR0 * Etax / K0 * It / TTa - HT0 * Ir / TRa) / (HR0 * GT0 - HT0 * GR0)) # IL = 1 Eq.(64); Etax/K0 = Eta0. |
Volker@43 | 1991 | |
Volker@43 | 1992 | # Text1 = "F11corr from It and Ir without corrections but with calibration EtaX: x-axis: F11corr(LDRtrue) devided by F11corr(LDRtrue = 0.004)" |
Volker@43 | 1993 | # F11corr = 0.5/(TiO*TiE)*(Etax*It/TTa+Ir/TRa) # IL = 1 Eq.(64) |
Volker@43 | 1994 | |
Volker@43 | 1995 | # -- It from It only with atrue without corrections - for BERTHA (and PollyXTs) |
Volker@43 | 1996 | # Text1 = " x-axis: IT(LDRtrue) / IT(LDRtrue = 0.004) - 1" |
Volker@43 | 1997 | # F11corr = It/(TaT*TiT*TiO*TiE) #/(TaT*TiT*TiO*TiE*(GT0+atrue*HT0)) |
Volker@43 | 1998 | # ! see below line 1673ff |
Volker@43 | 1999 | |
Volker@43 | 2000 | aF11corr[iLDR, iN] = F11corr |
Volker@43 | 2001 | aLDRcorr[iLDR, iN] = LDRCorr # LDRCorr # LDRsim # for test only |
Volker@43 | 2002 | aLDRsim[iLDR, iN] = LDRsim # LDRCorr # LDRsim # for test only |
Volker@43 | 2003 | # aPLDR[iLDR, iN] = CalcPLDR(LDRCorr, BSR[iLDR], LDRm0) |
Volker@43 | 2004 | aEtax[iLDR, iN] = Etax |
Volker@43 | 2005 | aEtapx[iLDR, iN] = Etapx |
Volker@43 | 2006 | aEtamx[iLDR, iN] = Etamx |
Volker@43 | 2007 | |
Volker@43 | 2008 | aGHK[0, iN] = GR |
Volker@43 | 2009 | aGHK[1, iN] = GT |
Volker@43 | 2010 | aGHK[2, iN] = HR |
Volker@43 | 2011 | aGHK[3, iN] = HT |
Volker@43 | 2012 | aGHK[4, iN] = K |
Volker@43 | 2013 | |
Volker@43 | 2014 | aLDRCal[iN] = iLDRCal |
Volker@43 | 2015 | aQin[iN] = iQin |
Volker@43 | 2016 | aVin[iN] = iVin |
Volker@43 | 2017 | aERaT[iN] = iERaT |
Volker@43 | 2018 | aERaR[iN] = iERaR |
Volker@43 | 2019 | aRotaT[iN] = iRotaT |
Volker@43 | 2020 | aRotaR[iN] = iRotaR |
Volker@43 | 2021 | aRetT[iN] = iRetT |
Volker@43 | 2022 | aRetR[iN] = iRetR |
Volker@43 | 2023 | |
Volker@43 | 2024 | aRotL[iN] = iRotL |
Volker@43 | 2025 | aRotE[iN] = iRotE |
Volker@43 | 2026 | aRetE[iN] = iRetE |
Volker@43 | 2027 | aRotO[iN] = iRotO |
Volker@43 | 2028 | aRetO[iN] = iRetO |
Volker@43 | 2029 | aRotC[iN] = iRotC |
Volker@43 | 2030 | aRetC[iN] = iRetC |
Volker@43 | 2031 | aDiO[iN] = iDiO |
Volker@43 | 2032 | aDiE[iN] = iDiE |
Volker@43 | 2033 | aDiC[iN] = iDiC |
Volker@43 | 2034 | aTP[iN] = iTP |
Volker@43 | 2035 | aTS[iN] = iTS |
Volker@43 | 2036 | aRP[iN] = iRP |
Volker@43 | 2037 | aRS[iN] = iRS |
Volker@43 | 2038 | aTCalT[iN] = iTCalT |
Volker@43 | 2039 | aTCalR[iN] = iTCalR |
Volker@43 | 2040 | |
Volker@43 | 2041 | aNCalTp[iN] = iNCalTp # IoutTp, IoutTm, IoutRp, IoutRm => Etax |
Volker@43 | 2042 | aNCalTm[iN] = iNCalTm # IoutTp, IoutTm, IoutRp, IoutRm => Etax |
Volker@43 | 2043 | aNCalRp[iN] = iNCalRp # IoutTp, IoutTm, IoutRp, IoutRm => Etax |
Volker@43 | 2044 | aNCalRm[iN] = iNCalRm # IoutTp, IoutTm, IoutRp, IoutRm => Etax |
Volker@43 | 2045 | aNIt[iN] = iNIt # It, Tr |
Volker@43 | 2046 | aNIr[iN] = iNIr # It, Tr |
Volker@43 | 2047 | |
Volker@43 | 2048 | # --- END loop |
Volker@43 | 2049 | btime = clock() |
Volker@43 | 2050 | # print("\r done in ", "{0:5.0f}".format(btime - atime), "sec. => producing plots now .... some more seconds ..."), # , end="\r"); |
Volker@43 | 2051 | print(" done in ", "{0:5.0f}".format(btime - atime), "sec. => producing plots now .... some more seconds ...") |
Volker@43 | 2052 | # --- Plot ----------------------------------------------------------------- |
Volker@43 | 2053 | print("Errors from GHK correction uncertainties:") |
Volker@43 | 2054 | if (sns_loaded): |
Volker@43 | 2055 | sns.set_style("whitegrid") |
Volker@43 | 2056 | sns.set_palette("bright6", 6) |
Volker@43 | 2057 | # for older seaborn versions use: |
Volker@43 | 2058 | # sns.set_palette("bright", 6) |
Volker@43 | 2059 | |
Volker@43 | 2060 | ''' |
Volker@43 | 2061 | fig2 = plt.figure() |
Volker@43 | 2062 | plt.plot(aLDRcorr[2,:],'b.') |
Volker@43 | 2063 | plt.plot(aLDRcorr[3,:],'r.') |
Volker@43 | 2064 | plt.plot(aLDRcorr[4,:],'g.') |
Volker@43 | 2065 | #plt.plot(aLDRcorr[6,:],'c.') |
Volker@43 | 2066 | plt.show |
Volker@43 | 2067 | ''' |
Volker@43 | 2068 | |
Volker@43 | 2069 | # Plot LDR |
Volker@43 | 2070 | def PlotSubHist(aVar, aX, X0, daX, iaX, naX): |
Volker@43 | 2071 | # aVar is the name of the parameter and aX is the subset of aLDRcorr which is coloured in the plot |
Volker@43 | 2072 | # example: PlotSubHist("DOLP", aDOLP, DOLP0, dDOLP, iDOLP, nDOLP) |
Volker@43 | 2073 | fig, ax = plt.subplots(nrows=1, ncols=5, sharex=True, sharey=True, figsize=(25, 2)) |
Volker@43 | 2074 | iLDR = -1 |
Volker@43 | 2075 | for LDRTrue in LDRrange: |
Volker@43 | 2076 | aXmean = np.zeros(2 * naX + 1) |
Volker@43 | 2077 | iLDR = iLDR + 1 |
Volker@43 | 2078 | LDRmin[iLDR] = np.amin(aLDRcorr[iLDR, :]) |
Volker@43 | 2079 | LDRmax[iLDR] = np.amax(aLDRcorr[iLDR, :]) |
Volker@43 | 2080 | if (LDRmax[iLDR] > 10): LDRmax[iLDR] = 10 |
Volker@43 | 2081 | if (LDRmin[iLDR] < -10): LDRmin[iLDR] = -10 |
Volker@43 | 2082 | Rmin = LDRmin[iLDR] * 0.995 # np.min(aLDRcorr[iLDR,:]) * 0.995 |
Volker@43 | 2083 | Rmax = LDRmax[iLDR] * 1.005 # np.max(aLDRcorr[iLDR,:]) * 1.005 |
Volker@43 | 2084 | |
Volker@43 | 2085 | # Determine mean distance of all aXmean from each other for each iLDR |
Volker@43 | 2086 | meanDist = 0.0 |
Volker@43 | 2087 | for iaX in range(-naX, naX + 1): |
Volker@43 | 2088 | # mean LDRCorr value for certain error (iaX) of parameter aVar |
Volker@43 | 2089 | aXmean[iaX + naX] = np.mean(aLDRcorr[iLDR, aX == iaX]) |
Volker@43 | 2090 | # relative to absolute spread of LDRCorrs |
Volker@43 | 2091 | meanDist = (np.max(aXmean) - np.min(aXmean)) / (LDRmax[iLDR] - LDRmin[iLDR]) * 100 |
Volker@43 | 2092 | |
Volker@43 | 2093 | plt.subplot(1, 5, iLDR + 1) |
Volker@43 | 2094 | (n, bins, patches) = plt.hist(aLDRcorr[iLDR, :], |
Volker@43 | 2095 | bins=100, log=False, |
Volker@43 | 2096 | range=[Rmin, Rmax], |
Volker@43 | 2097 | alpha=0.5, density=False, color='0.5', histtype='stepfilled') |
Volker@43 | 2098 | |
Volker@43 | 2099 | for iaX in range(-naX, naX + 1): |
Volker@43 | 2100 | # mean LDRCorr value for certain error (iaX) of parameter aVar |
Volker@43 | 2101 | plt.hist(aLDRcorr[iLDR, aX == iaX], |
Volker@43 | 2102 | range=[Rmin, Rmax], |
Volker@43 | 2103 | bins=100, log=False, alpha=0.3, density=False, histtype='stepfilled', |
Volker@43 | 2104 | label=str(round(X0 + iaX * daX / naX, 5))) |
Volker@43 | 2105 | |
Volker@43 | 2106 | if (iLDR == 2): |
Volker@43 | 2107 | leg = plt.legend() |
Volker@43 | 2108 | leg.get_frame().set_alpha(0.1) |
Volker@43 | 2109 | |
Volker@43 | 2110 | plt.tick_params(axis='both', labelsize=10) |
Volker@43 | 2111 | plt.plot([LDRTrue, LDRTrue], [0, np.max(n)], 'r-', lw=2) |
Volker@43 | 2112 | plt.gca().set_title("{0:3.0f}%".format(meanDist)) |
Volker@43 | 2113 | plt.gca().set_xlabel('LDRtrue', color="red") |
Volker@43 | 2114 | |
Volker@43 | 2115 | # plt.ylabel('frequency', fontsize=10) |
Volker@43 | 2116 | # plt.xlabel('LDRCorr', fontsize=10) |
Volker@43 | 2117 | # fig.tight_layout() |
Volker@43 | 2118 | fig.suptitle(LID + ' with ' + str(Type[TypeC]) + ' ' + str(Loc[LocC]) + ' - ' + aVar + ' error contribution', fontsize=14, y=1.10) |
Volker@43 | 2119 | # plt.show() |
Volker@43 | 2120 | # fig.savefig(LID + '_' + aVar + '.png', dpi=150, bbox_inches='tight', pad_inches=0) |
Volker@43 | 2121 | # plt.close |
Volker@43 | 2122 | return |
Volker@43 | 2123 | |
Volker@43 | 2124 | def PlotLDRsim(aVar, aX, X0, daX, iaX, naX): |
Volker@43 | 2125 | # aVar is the name of the parameter and aX is the subset of aLDRsim which is coloured in the plot |
Volker@43 | 2126 | # example: PlotSubHist("DOLP", aDOLP, DOLP0, dDOLP, iDOLP, nDOLP) |
Volker@43 | 2127 | fig, ax = plt.subplots(nrows=1, ncols=5, sharex=True, sharey=True, figsize=(25, 2)) |
Volker@43 | 2128 | iLDR = -1 |
Volker@43 | 2129 | for LDRTrue in LDRrange: |
Volker@43 | 2130 | aXmean = np.zeros(2 * naX + 1) |
Volker@43 | 2131 | iLDR = iLDR + 1 |
Volker@43 | 2132 | LDRsimmin[iLDR] = np.amin(aLDRsim[iLDR, :]) |
Volker@43 | 2133 | LDRsimmax[iLDR] = np.amax(aLDRsim[iLDR, :]) |
Volker@43 | 2134 | # print("LDRsimmin[iLDR], LDRsimmax[iLDR] = ", LDRsimmin[iLDR], LDRsimmax[iLDR]) |
Volker@43 | 2135 | # if (LDRsimmax[iLDR] > 10): LDRsimmax[iLDR] = 10 |
Volker@43 | 2136 | # if (LDRsimmin[iLDR] < -10): LDRsimmin[iLDR] = -10 |
Volker@43 | 2137 | Rmin = LDRsimmin[iLDR] * 0.995 # np.min(aLDRsim[iLDR,:]) * 0.995 |
Volker@43 | 2138 | Rmax = LDRsimmax[iLDR] * 1.005 # np.max(aLDRsim[iLDR,:]) * 1.005 |
Volker@43 | 2139 | # print("Rmin, Rmax = ", Rmin, Rmax) |
Volker@43 | 2140 | |
Volker@43 | 2141 | # Determine mean distance of all aXmean from each other for each iLDR |
Volker@43 | 2142 | meanDist = 0.0 |
Volker@43 | 2143 | for iaX in range(-naX, naX + 1): |
Volker@43 | 2144 | # mean LDRCorr value for certain error (iaX) of parameter aVar |
Volker@43 | 2145 | aXmean[iaX + naX] = np.mean(aLDRsim[iLDR, aX == iaX]) |
Volker@43 | 2146 | # relative to absolute spread of LDRCorrs |
Volker@43 | 2147 | meanDist = (np.max(aXmean) - np.min(aXmean)) / (LDRsimmax[iLDR] - LDRsimmin[iLDR]) * 100 |
Volker@43 | 2148 | |
Volker@43 | 2149 | plt.subplot(1, 5, iLDR + 1) |
Volker@43 | 2150 | (n, bins, patches) = plt.hist(aLDRsim[iLDR, :], |
Volker@43 | 2151 | bins=100, log=False, |
Volker@43 | 2152 | range=[Rmin, Rmax], |
Volker@43 | 2153 | alpha=0.5, density=False, color='0.5', histtype='stepfilled') |
Volker@43 | 2154 | |
Volker@43 | 2155 | for iaX in range(-naX, naX + 1): |
Volker@43 | 2156 | # mean LDRCorr value for certain error (iaX) of parameter aVar |
Volker@43 | 2157 | plt.hist(aLDRsim[iLDR, aX == iaX], |
Volker@43 | 2158 | range=[Rmin, Rmax], |
Volker@43 | 2159 | bins=100, log=False, alpha=0.3, density=False, histtype='stepfilled', |
Volker@43 | 2160 | label=str(round(X0 + iaX * daX / naX, 5))) |
Volker@43 | 2161 | |
Volker@43 | 2162 | if (iLDR == 2): |
Volker@43 | 2163 | leg = plt.legend() |
Volker@43 | 2164 | leg.get_frame().set_alpha(0.1) |
Volker@43 | 2165 | |
Volker@43 | 2166 | plt.tick_params(axis='both', labelsize=10) |
Volker@43 | 2167 | plt.plot([LDRsim0[iLDR], LDRsim0[iLDR]], [0, np.max(n)], 'r-', lw=2) |
Volker@43 | 2168 | plt.gca().set_title("{0:3.0f}%".format(meanDist)) |
Volker@43 | 2169 | plt.gca().set_xlabel('LDRsim0', color="red") |
Volker@43 | 2170 | |
Volker@43 | 2171 | fig.suptitle('LDRsim - ' +LID + ' with ' + str(Type[TypeC]) + ' ' + str(Loc[LocC]) + ' - ' + aVar + ' error contribution', fontsize=14, y=1.10) |
Volker@43 | 2172 | return |
Volker@43 | 2173 | |
Volker@43 | 2174 | |
Volker@43 | 2175 | # Plot Etax |
Volker@43 | 2176 | def PlotEtax(aVar, aX, X0, daX, iaX, naX): |
Volker@43 | 2177 | # aVar is the name of the parameter and aX is the subset of aLDRcorr which is coloured in the plot |
Volker@43 | 2178 | # example: PlotSubHist("DOLP", aDOLP, DOLP0, dDOLP, iDOLP, nDOLP) |
Volker@43 | 2179 | fig, ax = plt.subplots(nrows=1, ncols=5, sharex=True, sharey=True, figsize=(25, 2)) |
Volker@43 | 2180 | iLDR = -1 |
Volker@43 | 2181 | for LDRTrue in LDRrange: |
Volker@43 | 2182 | aXmean = np.zeros(2 * naX + 1) |
Volker@43 | 2183 | iLDR = iLDR + 1 |
Volker@43 | 2184 | Etaxmin = np.amin(aEtax[iLDR, :]) |
Volker@43 | 2185 | Etaxmax = np.amax(aEtax[iLDR, :]) |
Volker@43 | 2186 | Rmin = Etaxmin * 0.995 # np.min(aLDRcorr[iLDR,:]) * 0.995 |
Volker@43 | 2187 | Rmax = Etaxmax * 1.005 # np.max(aLDRcorr[iLDR,:]) * 1.005 |
Volker@43 | 2188 | |
Volker@43 | 2189 | # Determine mean distance of all aXmean from each other for each iLDR |
Volker@43 | 2190 | meanDist = 0.0 |
Volker@43 | 2191 | for iaX in range(-naX, naX + 1): |
Volker@43 | 2192 | # mean Etax value for certain error (iaX) of parameter aVar |
Volker@43 | 2193 | aXmean[iaX + naX] = np.mean(aEtax[iLDR, aX == iaX]) |
Volker@43 | 2194 | # relative to absolute spread of Etax |
Volker@43 | 2195 | meanDist = (np.max(aXmean) - np.min(aXmean)) / (Etaxmax - Etaxmin) * 100 |
Volker@43 | 2196 | |
Volker@43 | 2197 | plt.subplot(1, 5, iLDR + 1) |
Volker@43 | 2198 | (n, bins, patches) = plt.hist(aEtax[iLDR, :], |
Volker@43 | 2199 | bins=50, log=False, |
Volker@43 | 2200 | range=[Rmin, Rmax], |
Volker@43 | 2201 | alpha=0.5, density=False, color='0.5', histtype='stepfilled') |
Volker@43 | 2202 | for iaX in range(-naX, naX + 1): |
Volker@43 | 2203 | plt.hist(aEtax[iLDR, aX == iaX], |
Volker@43 | 2204 | range=[Rmin, Rmax], |
Volker@43 | 2205 | bins=50, log=False, alpha=0.3, density=False, histtype='stepfilled', |
Volker@43 | 2206 | label=str(round(X0 + iaX * daX / naX, 5))) |
Volker@43 | 2207 | if (iLDR == 2): |
Volker@43 | 2208 | leg = plt.legend() |
Volker@43 | 2209 | leg.get_frame().set_alpha(0.1) |
Volker@43 | 2210 | plt.tick_params(axis='both', labelsize=10) |
Volker@43 | 2211 | plt.plot([Etax0, Etax0], [0, np.max(n)], 'r-', lw=2) |
Volker@43 | 2212 | plt.gca().set_title("{0:3.0f}%".format(meanDist)) |
Volker@43 | 2213 | plt.gca().set_xlabel('Etax0', color="red") |
Volker@43 | 2214 | fig.suptitle('Etax - ' + LID + ' with ' + str(Type[TypeC]) + ' ' + str(Loc[LocC]) + ' - ' + aVar + ' error contribution', fontsize=14, y=1.10) |
Volker@43 | 2215 | return |
Volker@43 | 2216 | |
Volker@43 | 2217 | def PlotEtapx(aVar, aX, X0, daX, iaX, naX): |
Volker@43 | 2218 | # aVar is the name of the parameter and aX is the subset of aLDRcorr which is coloured in the plot |
Volker@43 | 2219 | # example: PlotSubHist("DOLP", aDOLP, DOLP0, dDOLP, iDOLP, nDOLP) |
Volker@43 | 2220 | fig, ax = plt.subplots(nrows=1, ncols=5, sharex=True, sharey=True, figsize=(25, 2)) |
Volker@43 | 2221 | iLDR = -1 |
Volker@43 | 2222 | for LDRTrue in LDRrange: |
Volker@43 | 2223 | aXmean = np.zeros(2 * naX + 1) |
Volker@43 | 2224 | iLDR = iLDR + 1 |
Volker@43 | 2225 | Etapxmin = np.amin(aEtapx[iLDR, :]) |
Volker@43 | 2226 | Etapxmax = np.amax(aEtapx[iLDR, :]) |
Volker@43 | 2227 | Rmin = Etapxmin * 0.995 # np.min(aLDRcorr[iLDR,:]) * 0.995 |
Volker@43 | 2228 | Rmax = Etapxmax * 1.005 # np.max(aLDRcorr[iLDR,:]) * 1.005 |
Volker@43 | 2229 | |
Volker@43 | 2230 | # Determine mean distance of all aXmean from each other for each iLDR |
Volker@43 | 2231 | meanDist = 0.0 |
Volker@43 | 2232 | for iaX in range(-naX, naX + 1): |
Volker@43 | 2233 | # mean Etapx value for certain error (iaX) of parameter aVar |
Volker@43 | 2234 | aXmean[iaX + naX] = np.mean(aEtapx[iLDR, aX == iaX]) |
Volker@43 | 2235 | # relative to absolute spread of Etapx |
Volker@43 | 2236 | meanDist = (np.max(aXmean) - np.min(aXmean)) / (Etapxmax - Etapxmin) * 100 |
Volker@43 | 2237 | |
Volker@43 | 2238 | plt.subplot(1, 5, iLDR + 1) |
Volker@43 | 2239 | (n, bins, patches) = plt.hist(aEtapx[iLDR, :], |
Volker@43 | 2240 | bins=50, log=False, |
Volker@43 | 2241 | range=[Rmin, Rmax], |
Volker@43 | 2242 | alpha=0.5, density=False, color='0.5', histtype='stepfilled') |
Volker@43 | 2243 | for iaX in range(-naX, naX + 1): |
Volker@43 | 2244 | plt.hist(aEtapx[iLDR, aX == iaX], |
Volker@43 | 2245 | range=[Rmin, Rmax], |
Volker@43 | 2246 | bins=50, log=False, alpha=0.3, density=False, histtype='stepfilled', |
Volker@43 | 2247 | label=str(round(X0 + iaX * daX / naX, 5))) |
Volker@43 | 2248 | if (iLDR == 2): |
Volker@43 | 2249 | leg = plt.legend() |
Volker@43 | 2250 | leg.get_frame().set_alpha(0.1) |
Volker@43 | 2251 | plt.tick_params(axis='both', labelsize=10) |
Volker@43 | 2252 | plt.plot([Etapx0, Etapx0], [0, np.max(n)], 'r-', lw=2) |
Volker@43 | 2253 | plt.gca().set_title("{0:3.0f}%".format(meanDist)) |
Volker@43 | 2254 | plt.gca().set_xlabel('Etapx0', color="red") |
Volker@43 | 2255 | fig.suptitle('Etapx - ' + LID + ' with ' + str(Type[TypeC]) + ' ' + str(Loc[LocC]) + ' - ' + aVar + ' error contribution', fontsize=14, y=1.10) |
Volker@43 | 2256 | return |
Volker@43 | 2257 | |
Volker@43 | 2258 | def PlotEtamx(aVar, aX, X0, daX, iaX, naX): |
Volker@43 | 2259 | # aVar is the name of the parameter and aX is the subset of aLDRcorr which is coloured in the plot |
Volker@43 | 2260 | # example: PlotSubHist("DOLP", aDOLP, DOLP0, dDOLP, iDOLP, nDOLP) |
Volker@43 | 2261 | fig, ax = plt.subplots(nrows=1, ncols=5, sharex=True, sharey=True, figsize=(25, 2)) |
Volker@43 | 2262 | iLDR = -1 |
Volker@43 | 2263 | for LDRTrue in LDRrange: |
Volker@43 | 2264 | aXmean = np.zeros(2 * naX + 1) |
Volker@43 | 2265 | iLDR = iLDR + 1 |
Volker@43 | 2266 | Etamxmin = np.amin(aEtamx[iLDR, :]) |
Volker@43 | 2267 | Etamxmax = np.amax(aEtamx[iLDR, :]) |
Volker@43 | 2268 | Rmin = Etamxmin * 0.995 # np.min(aLDRcorr[iLDR,:]) * 0.995 |
Volker@43 | 2269 | Rmax = Etamxmax * 1.005 # np.max(aLDRcorr[iLDR,:]) * 1.005 |
Volker@43 | 2270 | |
Volker@43 | 2271 | # Determine mean distance of all aXmean from each other for each iLDR |
Volker@43 | 2272 | meanDist = 0.0 |
Volker@43 | 2273 | for iaX in range(-naX, naX + 1): |
Volker@43 | 2274 | # mean Etamx value for certain error (iaX) of parameter aVar |
Volker@43 | 2275 | aXmean[iaX + naX] = np.mean(aEtamx[iLDR, aX == iaX]) |
Volker@43 | 2276 | # relative to absolute spread of Etamx |
Volker@43 | 2277 | meanDist = (np.max(aXmean) - np.min(aXmean)) / (Etamxmax - Etamxmin) * 100 |
Volker@43 | 2278 | |
Volker@43 | 2279 | plt.subplot(1, 5, iLDR + 1) |
Volker@43 | 2280 | (n, bins, patches) = plt.hist(aEtamx[iLDR, :], |
Volker@43 | 2281 | bins=50, log=False, |
Volker@43 | 2282 | range=[Rmin, Rmax], |
Volker@43 | 2283 | alpha=0.5, density=False, color='0.5', histtype='stepfilled') |
Volker@43 | 2284 | for iaX in range(-naX, naX + 1): |
Volker@43 | 2285 | plt.hist(aEtamx[iLDR, aX == iaX], |
Volker@43 | 2286 | range=[Rmin, Rmax], |
Volker@43 | 2287 | bins=50, log=False, alpha=0.3, density=False, histtype='stepfilled', |
Volker@43 | 2288 | label=str(round(X0 + iaX * daX / naX, 5))) |
Volker@43 | 2289 | if (iLDR == 2): |
Volker@43 | 2290 | leg = plt.legend() |
Volker@43 | 2291 | leg.get_frame().set_alpha(0.1) |
Volker@43 | 2292 | plt.tick_params(axis='both', labelsize=10) |
Volker@43 | 2293 | plt.plot([Etamx0, Etamx0], [0, np.max(n)], 'r-', lw=2) |
Volker@43 | 2294 | plt.gca().set_title("{0:3.0f}%".format(meanDist)) |
Volker@43 | 2295 | plt.gca().set_xlabel('Etamx0', color="red") |
Volker@43 | 2296 | fig.suptitle('Etamx - ' + LID + ' with ' + str(Type[TypeC]) + ' ' + str(Loc[LocC]) + ' - ' + aVar + ' error contribution', fontsize=14, y=1.10) |
Volker@43 | 2297 | return |
Volker@43 | 2298 | |
Volker@43 | 2299 | # calc contribution of the error of aVar = aX to aY for each LDRtrue |
Volker@43 | 2300 | def Contribution(aVar, aX, X0, daX, iaX, naX, aY, Ysum, widthSum): |
Volker@43 | 2301 | # aVar is the name of the parameter and aX is the subset of aY which is coloured in the plot |
Volker@43 | 2302 | # example: Contribution("DOLP", aDOLP, DOLP0, dDOLP, iDOLP, nDOLP, aLDRcorr, DOLPcontr) |
Volker@43 | 2303 | iLDR = -1 |
Volker@43 | 2304 | # Ysum, widthSum = np.zeros(5) |
Volker@43 | 2305 | meanDist = np.zeros(5) # iLDR |
Volker@43 | 2306 | widthDist = np.zeros(5) # iLDR |
Volker@43 | 2307 | for LDRTrue in LDRrange: |
Volker@43 | 2308 | aXmean = np.zeros(2 * naX + 1) |
Volker@43 | 2309 | aXwidth = np.zeros(2 * naX + 1) |
Volker@43 | 2310 | iLDR = iLDR + 1 |
Volker@43 | 2311 | # total width of distribution |
Volker@43 | 2312 | aYmin = np.amin(aY[iLDR, :]) |
Volker@43 | 2313 | aYmax = np.amax(aY[iLDR, :]) |
Volker@43 | 2314 | aYwidth = aYmax - aYmin |
Volker@43 | 2315 | # Determine mean distance of all aXmean from each other for each iLDR |
Volker@43 | 2316 | for iaX in range(-naX, naX + 1): |
Volker@43 | 2317 | # mean LDRCorr value for all errors iaX of parameter aVar |
Volker@43 | 2318 | aXmean[iaX + naX] = np.mean(aY[iLDR, aX == iaX]) |
Volker@43 | 2319 | aXwidth[iaX + naX] = np.max(aY[iLDR, aX == iaX]) - np.min(aY[iLDR, aX == iaX]) |
Volker@43 | 2320 | # relative to absolute spread of LDRCorrs |
Volker@43 | 2321 | meanDist[iLDR] = (np.max(aXmean) - np.min(aXmean)) / aYwidth * 1000 |
Volker@43 | 2322 | # meanDist[iLDR] = (aYwidth - aXwidth[naX]) / aYwidth * 1000 |
Volker@43 | 2323 | widthDist[iLDR] = (np.max(aXwidth) - aXwidth[naX]) / aYwidth * 1000 |
Volker@43 | 2324 | |
Volker@43 | 2325 | print("{:12}{:5.0f} {:5.0f} {:5.0f} {:5.0f} {:5.0f} {:5.0f} {:5.0f} {:5.0f} {:5.0f} {:5.0f}"\ |
Volker@43 | 2326 | .format(aVar,meanDist[0],meanDist[1],meanDist[2],meanDist[3],meanDist[4],widthDist[0],widthDist[1],widthDist[2],widthDist[3],widthDist[4])) |
Volker@43 | 2327 | Ysum = Ysum + meanDist |
Volker@43 | 2328 | widthSum = widthSum + widthDist |
Volker@43 | 2329 | return(Ysum, widthSum) |
Volker@43 | 2330 | |
Volker@43 | 2331 | # print(.format(LDRrangeA[iLDR],)) |
Volker@43 | 2332 | |
Volker@43 | 2333 | # error contributions to a certain output aY; loop over all variables |
Volker@43 | 2334 | def Contribution_aY(aYvar, aY): |
Volker@43 | 2335 | Ysum = np.zeros(5) |
Volker@43 | 2336 | widthSum = np.zeros(5) |
Volker@43 | 2337 | # meanDist = np.zeros(5) # iLDR |
Volker@43 | 2338 | LDRrangeA = np.array(LDRrange) |
Volker@43 | 2339 | print() |
Volker@43 | 2340 | print(aYvar + ": contribution to the total error (per mill)") |
Volker@43 | 2341 | print(" of individual parameter errors of combined parameter errors") |
Volker@43 | 2342 | print(" at LDRtrue {:5.3f} {:5.3f} {:5.3f} {:5.3f} {:5.3f} {:5.3f} {:5.3f} {:5.3f} {:5.3f} {:5.3f}"\ |
Volker@43 | 2343 | .format(LDRrangeA[0],LDRrangeA[1],LDRrangeA[2],LDRrangeA[3],LDRrangeA[4],LDRrangeA[0],LDRrangeA[1],LDRrangeA[2],LDRrangeA[3],LDRrangeA[4])) |
Volker@43 | 2344 | print() |
Volker@43 | 2345 | if (nQin > 0): Ysum, widthSum = Contribution("Qin", aQin, Qin0, dQin, iQin, nQin, aY, Ysum, widthSum) |
Volker@43 | 2346 | if (nVin > 0): Ysum, widthSum = Contribution("Vin", aVin, Vin0, dVin, iVin, nVin, aY, Ysum, widthSum) |
Volker@43 | 2347 | if (nRotL > 0): Ysum, widthSum = Contribution("RotL", aRotL, RotL0, dRotL, iRotL, nRotL, aY, Ysum, widthSum) |
Volker@43 | 2348 | if (nRetE > 0): Ysum, widthSum = Contribution("RetE", aRetE, RetE0, dRetE, iRetE, nRetE, aY, Ysum, widthSum) |
Volker@43 | 2349 | if (nRotE > 0): Ysum, widthSum = Contribution("RotE", aRotE, RotE0, dRotE, iRotE, nRotE, aY, Ysum, widthSum) |
Volker@43 | 2350 | if (nDiE > 0): Ysum, widthSum = Contribution("DiE", aDiE, DiE0, dDiE, iDiE, nDiE, aY, Ysum, widthSum) |
Volker@43 | 2351 | if (nRetO > 0): Ysum, widthSum = Contribution("RetO", aRetO, RetO0, dRetO, iRetO, nRetO, aY, Ysum, widthSum) |
Volker@43 | 2352 | if (nRotO > 0): Ysum, widthSum = Contribution("RotO", aRotO, RotO0, dRotO, iRotO, nRotO, aY, Ysum, widthSum) |
Volker@43 | 2353 | if (nDiO > 0): Ysum, widthSum = Contribution("DiO", aDiO, DiO0, dDiO, iDiO, nDiO, aY, Ysum, widthSum) |
Volker@43 | 2354 | if (nDiC > 0): Ysum, widthSum = Contribution("DiC", aDiC, DiC0, dDiC, iDiC, nDiC, aY, Ysum, widthSum) |
Volker@43 | 2355 | if (nRotC > 0): Ysum, widthSum = Contribution("RotC", aRotC, RotC0, dRotC, iRotC, nRotC, aY, Ysum, widthSum) |
Volker@43 | 2356 | if (nRetC > 0): Ysum, widthSum = Contribution("RetC", aRetC, RetC0, dRetC, iRetC, nRetC, aY, Ysum, widthSum) |
Volker@43 | 2357 | if (nTP > 0): Ysum, widthSum = Contribution("TP", aTP, TP0, dTP, iTP, nTP, aY, Ysum, widthSum) |
Volker@43 | 2358 | if (nTS > 0): Ysum, widthSum = Contribution("TS", aTS, TS0, dTS, iTS, nTS, aY, Ysum, widthSum) |
Volker@43 | 2359 | if (nRP > 0): Ysum, widthSum = Contribution("RP", aRP, RP0, dRP, iRP, nRP, aY, Ysum, widthSum) |
Volker@43 | 2360 | if (nRS > 0): Ysum, widthSum = Contribution("RS", aRS, RS0, dRS, iRS, nRS, aY, Ysum, widthSum) |
Volker@43 | 2361 | if (nRetT > 0): Ysum, widthSum = Contribution("RetT", aRetT, RetT0, dRetT, iRetT, nRetT, aY, Ysum, widthSum) |
Volker@43 | 2362 | if (nRetR > 0): Ysum, widthSum = Contribution("RetR", aRetR, RetR0, dRetR, iRetR, nRetR, aY, Ysum, widthSum) |
Volker@43 | 2363 | if (nERaT > 0): Ysum, widthSum = Contribution("ERaT", aERaT, ERaT0, dERaT, iERaT, nERaT, aY, Ysum, widthSum) |
Volker@43 | 2364 | if (nERaR > 0): Ysum, widthSum = Contribution("ERaR", aERaR, ERaR0, dERaR, iERaR, nERaR, aY, Ysum, widthSum) |
Volker@43 | 2365 | if (nRotaT > 0): Ysum, widthSum = Contribution("RotaT", aRotaT, RotaT0, dRotaT, iRotaT, nRotaT, aY, Ysum, widthSum) |
Volker@43 | 2366 | if (nRotaR > 0): Ysum, widthSum = Contribution("RotaR", aRotaR, RotaR0, dRotaR, iRotaR, nRotaR, aY, Ysum, widthSum) |
Volker@43 | 2367 | if (nLDRCal > 0): Ysum, widthSum = Contribution("LDRCal", aLDRCal, LDRCal0, dLDRCal, iLDRCal, nLDRCal, aY, Ysum, widthSum) |
Volker@43 | 2368 | if (nTCalT > 0): Ysum, widthSum = Contribution("TCalT", aTCalT, TCalT0, dTCalT, iTCalT, nTCalT, aY, Ysum, widthSum) |
Volker@43 | 2369 | if (nTCalR > 0): Ysum, widthSum = Contribution("TCalR", aTCalR, TCalR0, dTCalR, iTCalR, nTCalR, aY, Ysum, widthSum) |
Volker@43 | 2370 | if (nNCal > 0): Ysum, widthSum = Contribution("CalNoiseTp", aNCalTp, 0, 1, iNCalTp, nNCal, aY, Ysum, widthSum) |
Volker@43 | 2371 | if (nNCal > 0): Ysum, widthSum = Contribution("CalNoiseTm", aNCalTm, 0, 1, iNCalTm, nNCal, aY, Ysum, widthSum) |
Volker@43 | 2372 | if (nNCal > 0): Ysum, widthSum = Contribution("CalNoiseRp", aNCalRp, 0, 1, iNCalRp, nNCal, aY, Ysum, widthSum) |
Volker@43 | 2373 | if (nNCal > 0): Ysum, widthSum = Contribution("CalNoiseRm", aNCalRm, 0, 1, iNCalRm, nNCal, aY, Ysum, widthSum) |
Volker@43 | 2374 | if (nNI > 0): Ysum, widthSum = Contribution("SigNoiseIt", aNIt, 0, 1, iNIt, nNI, aY, Ysum, widthSum) |
Volker@43 | 2375 | if (nNI > 0): Ysum, widthSum = Contribution("SigNoiseIr", aNIr, 0, 1, iNIr, nNI, aY, Ysum, widthSum) |
Volker@43 | 2376 | print("{:12}{:5.0f} {:5.0f} {:5.0f} {:5.0f} {:5.0f} {:5.0f} {:5.0f} {:5.0f} {:5.0f} {:5.0f}"\ |
Volker@43 | 2377 | .format("Sum ",Ysum[0],Ysum[1],Ysum[2],Ysum[3],Ysum[4],widthSum[0],widthSum[1],widthSum[2],widthSum[3],widthSum[4])) |
Volker@43 | 2378 | |
Volker@43 | 2379 | |
Volker@43 | 2380 | # Plot LDR histograms |
Volker@43 | 2381 | if (nQin > 0): PlotSubHist("Qin", aQin, Qin0, dQin, iQin, nQin) |
Volker@43 | 2382 | if (nVin > 0): PlotSubHist("Vin", aVin, Vin0, dVin, iVin, nVin) |
Volker@43 | 2383 | if (nRotL > 0): PlotSubHist("RotL", aRotL, RotL0, dRotL, iRotL, nRotL) |
Volker@43 | 2384 | if (nRetE > 0): PlotSubHist("RetE", aRetE, RetE0, dRetE, iRetE, nRetE) |
Volker@43 | 2385 | if (nRotE > 0): PlotSubHist("RotE", aRotE, RotE0, dRotE, iRotE, nRotE) |
Volker@43 | 2386 | if (nDiE > 0): PlotSubHist("DiE", aDiE, DiE0, dDiE, iDiE, nDiE) |
Volker@43 | 2387 | if (nRetO > 0): PlotSubHist("RetO", aRetO, RetO0, dRetO, iRetO, nRetO) |
Volker@43 | 2388 | if (nRotO > 0): PlotSubHist("RotO", aRotO, RotO0, dRotO, iRotO, nRotO) |
Volker@43 | 2389 | if (nDiO > 0): PlotSubHist("DiO", aDiO, DiO0, dDiO, iDiO, nDiO) |
Volker@43 | 2390 | if (nDiC > 0): PlotSubHist("DiC", aDiC, DiC0, dDiC, iDiC, nDiC) |
Volker@43 | 2391 | if (nRotC > 0): PlotSubHist("RotC", aRotC, RotC0, dRotC, iRotC, nRotC) |
Volker@43 | 2392 | if (nRetC > 0): PlotSubHist("RetC", aRetC, RetC0, dRetC, iRetC, nRetC) |
Volker@43 | 2393 | if (nTP > 0): PlotSubHist("TP", aTP, TP0, dTP, iTP, nTP) |
Volker@43 | 2394 | if (nTS > 0): PlotSubHist("TS", aTS, TS0, dTS, iTS, nTS) |
Volker@43 | 2395 | if (nRP > 0): PlotSubHist("RP", aRP, RP0, dRP, iRP, nRP) |
Volker@43 | 2396 | if (nRS > 0): PlotSubHist("RS", aRS, RS0, dRS, iRS, nRS) |
Volker@43 | 2397 | if (nRetT > 0): PlotSubHist("RetT", aRetT, RetT0, dRetT, iRetT, nRetT) |
Volker@43 | 2398 | if (nRetR > 0): PlotSubHist("RetR", aRetR, RetR0, dRetR, iRetR, nRetR) |
Volker@43 | 2399 | if (nERaT > 0): PlotSubHist("ERaT", aERaT, ERaT0, dERaT, iERaT, nERaT) |
Volker@43 | 2400 | if (nERaR > 0): PlotSubHist("ERaR", aERaR, ERaR0, dERaR, iERaR, nERaR) |
Volker@43 | 2401 | if (nRotaT > 0): PlotSubHist("RotaT", aRotaT, RotaT0, dRotaT, iRotaT, nRotaT) |
Volker@43 | 2402 | if (nRotaR > 0): PlotSubHist("RotaR", aRotaR, RotaR0, dRotaR, iRotaR, nRotaR) |
Volker@43 | 2403 | if (nLDRCal > 0): PlotSubHist("LDRCal", aLDRCal, LDRCal0, dLDRCal, iLDRCal, nLDRCal) |
Volker@43 | 2404 | if (nTCalT > 0): PlotSubHist("TCalT", aTCalT, TCalT0, dTCalT, iTCalT, nTCalT) |
Volker@43 | 2405 | if (nTCalR > 0): PlotSubHist("TCalR", aTCalR, TCalR0, dTCalR, iTCalR, nTCalR) |
Volker@43 | 2406 | if (nNCal > 0): PlotSubHist("CalNoiseTp", aNCalTp, 0, 1, iNCalTp, nNCal) |
Volker@43 | 2407 | if (nNCal > 0): PlotSubHist("CalNoiseTm", aNCalTm, 0, 1, iNCalTm, nNCal) |
Volker@43 | 2408 | if (nNCal > 0): PlotSubHist("CalNoiseRp", aNCalRp, 0, 1, iNCalRp, nNCal) |
Volker@43 | 2409 | if (nNCal > 0): PlotSubHist("CalNoiseRm", aNCalRm, 0, 1, iNCalRm, nNCal) |
Volker@43 | 2410 | if (nNI > 0): PlotSubHist("SigNoiseIt", aNIt, 0, 1, iNIt, nNI) |
Volker@43 | 2411 | if (nNI > 0): PlotSubHist("SigNoiseIr", aNIr, 0, 1, iNIr, nNI) |
Volker@43 | 2412 | plt.show() |
Volker@43 | 2413 | plt.close |
Volker@43 | 2414 | |
Volker@43 | 2415 | |
Volker@43 | 2416 | |
Volker@43 | 2417 | # --- Plot LDRmin, LDRmax |
Volker@43 | 2418 | iLDR = -1 |
Volker@43 | 2419 | for LDRTrue in LDRrange: |
Volker@43 | 2420 | iLDR = iLDR + 1 |
Volker@43 | 2421 | LDRmin[iLDR] = np.amin(aLDRcorr[iLDR, :]) |
Volker@43 | 2422 | LDRmax[iLDR] = np.amax(aLDRcorr[iLDR, :]) |
Volker@43 | 2423 | LDRstd[iLDR] = np.std(aLDRcorr[iLDR, :]) |
Volker@43 | 2424 | LDRmean[iLDR] = np.mean(aLDRcorr[iLDR, :]) |
Volker@43 | 2425 | LDRmedian[iLDR] = np.median(aLDRcorr[iLDR, :]) |
Volker@43 | 2426 | LDRskew[iLDR] = skew(aLDRcorr[iLDR, :],bias=False) |
Volker@43 | 2427 | LDRkurt[iLDR] = kurtosis(aLDRcorr[iLDR, :],fisher=True,bias=False) |
Volker@43 | 2428 | |
Volker@43 | 2429 | fig2 = plt.figure() |
Volker@43 | 2430 | LDRrangeA = np.array(LDRrange) |
Volker@43 | 2431 | if((np.amax(LDRmax - LDRrangeA)-np.amin(LDRmin - LDRrangeA)) < 0.001): |
Volker@43 | 2432 | plt.ylim(-0.001,0.001) |
Volker@43 | 2433 | plt.plot(LDRrangeA, LDRmax - LDRrangeA, linewidth=2.0, color='b') |
Volker@43 | 2434 | plt.plot(LDRrangeA, LDRmin - LDRrangeA, linewidth=2.0, color='g') |
Volker@43 | 2435 | |
Volker@43 | 2436 | plt.xlabel('LDRtrue', fontsize=18) |
Volker@43 | 2437 | plt.ylabel('LDRTrue-LDRmin, LDRTrue-LDRmax', fontsize=14) |
Volker@43 | 2438 | plt.title(LID + ' ' + str(Type[TypeC]) + ' ' + str(Loc[LocC]), fontsize=18) |
Volker@43 | 2439 | # plt.ylimit(-0.07, 0.07) |
Volker@43 | 2440 | plt.show() |
Volker@43 | 2441 | plt.close |
Volker@43 | 2442 | |
Volker@43 | 2443 | # --- Save LDRmin, LDRmax to file |
Volker@43 | 2444 | # http://stackoverflow.com/questions/4675728/redirect-stdout-to-a-file-in-python |
Volker@43 | 2445 | with open('output_files\\' + OutputFile, 'a') as f: |
Volker@43 | 2446 | # with open('output_files\\' + LID + '-' + InputFile[0:-3] + '-LDR_min_max.dat', 'w') as f: |
Volker@43 | 2447 | with redirect_stdout(f): |
Volker@43 | 2448 | print("Lidar ID: " + LID) |
Volker@43 | 2449 | print() |
Volker@43 | 2450 | print("minimum and maximum values of the distributions of possibly measured LDR for different LDRtrue") |
Volker@43 | 2451 | print("LDRtrue , LDRmin, LDRmax") |
Volker@43 | 2452 | for i in range(len(LDRrangeA)): |
Volker@43 | 2453 | print("{0:7.4f},{1:7.4f},{2:7.4f}".format(LDRrangeA[i], LDRmin[i], LDRmax[i])) |
Volker@43 | 2454 | print() |
Volker@43 | 2455 | # Print LDR statistics |
Volker@43 | 2456 | print("LDRtrue , mean , median, max-mean, min-mean, std, excess_kurtosis, skewness") |
Volker@43 | 2457 | iLDR = -1 |
Volker@43 | 2458 | LDRrangeA = np.array(LDRrange) |
Volker@43 | 2459 | for LDRTrue in LDRrange: |
Volker@43 | 2460 | iLDR = iLDR + 1 |
Volker@43 | 2461 | print("{0:8.5f},{1:8.5f},{2:8.5f}, {3:8.5f},{4:8.5f},{5:8.5f}, {6:8.5f},{7:8.5f}"\ |
Volker@43 | 2462 | .format(LDRrangeA[iLDR], LDRmean[iLDR], LDRmedian[iLDR], LDRmax[iLDR]-LDRrangeA[iLDR], \ |
Volker@43 | 2463 | LDRmin[iLDR]-LDRrangeA[iLDR], LDRstd[iLDR], LDRkurt[iLDR], LDRskew[iLDR])) |
Volker@43 | 2464 | print() |
Volker@43 | 2465 | # Calculate and print statistics for calibration factors |
Volker@43 | 2466 | print("minimum and maximum values of the distributions of signal ratios and calibration factors for different LDRtrue") |
Volker@43 | 2467 | iLDR = -1 |
Volker@43 | 2468 | LDRrangeA = np.array(LDRrange) |
Volker@43 | 2469 | print("LDRtrue , LDRsim, (max-min)/2, relerr") |
Volker@43 | 2470 | for LDRTrue in LDRrange: |
Volker@43 | 2471 | iLDR = iLDR + 1 |
Volker@43 | 2472 | LDRsimmin[iLDR] = np.amin(aLDRsim[iLDR, :]) |
Volker@43 | 2473 | LDRsimmax[iLDR] = np.amax(aLDRsim[iLDR, :]) |
Volker@43 | 2474 | # LDRsimstd = np.std(aLDRsim[iLDR, :]) |
Volker@43 | 2475 | LDRsimmean[iLDR] = np.mean(aLDRsim[iLDR, :]) |
Volker@43 | 2476 | # LDRsimmedian = np.median(aLDRsim[iLDR, :]) |
Volker@43 | 2477 | print("{0:8.5f}, {1:8.5f}, {2:8.5f}, {3:8.5f}".format(LDRrangeA[iLDR],LDRsimmean[iLDR],(LDRsimmax[iLDR]-LDRsimmin[iLDR])/2,(LDRsimmax[iLDR]-LDRsimmin[iLDR])/2/LDRsimmean[iLDR])) |
Volker@43 | 2478 | iLDR = -1 |
Volker@43 | 2479 | print("LDRtrue , Etax , (max-min)/2, relerr") |
Volker@43 | 2480 | for LDRTrue in LDRrange: |
Volker@43 | 2481 | iLDR = iLDR + 1 |
Volker@43 | 2482 | Etaxmin = np.amin(aEtax[iLDR, :]) |
Volker@43 | 2483 | Etaxmax = np.amax(aEtax[iLDR, :]) |
Volker@43 | 2484 | # Etaxstd = np.std(aEtax[iLDR, :]) |
Volker@43 | 2485 | Etaxmean = np.mean(aEtax[iLDR, :]) |
Volker@43 | 2486 | # Etaxmedian = np.median(aEtax[iLDR, :]) |
Volker@43 | 2487 | print("{0:8.5f}, {1:8.5f}, {2:8.5f}, {3:8.5f}".format(LDRrangeA[iLDR], Etaxmean, (Etaxmax-Etaxmin)/2, (Etaxmax-Etaxmin)/2/Etaxmean)) |
Volker@43 | 2488 | iLDR = -1 |
Volker@43 | 2489 | print("LDRtrue , Etapx , (max-min)/2, relerr") |
Volker@43 | 2490 | for LDRTrue in LDRrange: |
Volker@43 | 2491 | iLDR = iLDR + 1 |
Volker@43 | 2492 | Etapxmin = np.amin(aEtapx[iLDR, :]) |
Volker@43 | 2493 | Etapxmax = np.amax(aEtapx[iLDR, :]) |
Volker@43 | 2494 | # Etapxstd = np.std(aEtapx[iLDR, :]) |
Volker@43 | 2495 | Etapxmean = np.mean(aEtapx[iLDR, :]) |
Volker@43 | 2496 | # Etapxmedian = np.median(aEtapx[iLDR, :]) |
Volker@43 | 2497 | print("{0:8.5f}, {1:8.5f}, {2:8.5f}, {3:8.5f}".format(LDRrangeA[iLDR], Etapxmean, (Etapxmax-Etapxmin)/2, (Etapxmax-Etapxmin)/2/Etapxmean)) |
Volker@43 | 2498 | iLDR = -1 |
Volker@43 | 2499 | print("LDRtrue , Etamx , (max-min)/2, relerr") |
Volker@43 | 2500 | for LDRTrue in LDRrange: |
Volker@43 | 2501 | iLDR = iLDR + 1 |
Volker@43 | 2502 | Etamxmin = np.amin(aEtamx[iLDR, :]) |
Volker@43 | 2503 | Etamxmax = np.amax(aEtamx[iLDR, :]) |
Volker@43 | 2504 | # Etamxstd = np.std(aEtamx[iLDR, :]) |
Volker@43 | 2505 | Etamxmean = np.mean(aEtamx[iLDR, :]) |
Volker@43 | 2506 | # Etamxmedian = np.median(aEtamx[iLDR, :]) |
Volker@43 | 2507 | print("{0:8.5f}, {1:8.5f}, {2:8.5f}, {3:8.5f}".format(LDRrangeA[iLDR], Etamxmean, (Etamxmax-Etamxmin)/2, (Etamxmax-Etamxmin)/2/Etamxmean)) |
Volker@43 | 2508 | |
Volker@43 | 2509 | # Print LDR statistics |
Volker@43 | 2510 | print("LDRtrue , mean , median, max-mean, min-mean, std, excess_kurtosis, skewness") |
Volker@43 | 2511 | iLDR = -1 |
Volker@43 | 2512 | LDRrangeA = np.array(LDRrange) |
Volker@43 | 2513 | for LDRTrue in LDRrange: |
Volker@43 | 2514 | iLDR = iLDR + 1 |
Volker@43 | 2515 | print("{0:8.5f},{1:8.5f},{2:8.5f}, {3:8.5f},{4:8.5f},{5:8.5f}, {6:8.5f},{7:8.5f}".format(LDRrangeA[iLDR], LDRmean[iLDR], LDRmedian[iLDR], LDRmax[iLDR]-LDRrangeA[iLDR], LDRmin[iLDR]-LDRrangeA[iLDR], LDRstd[iLDR],LDRkurt[iLDR],LDRskew[iLDR])) |
Volker@43 | 2516 | |
Volker@43 | 2517 | |
Volker@43 | 2518 | with open('output_files\\' + OutputFile, 'a') as f: |
Volker@43 | 2519 | # with open('output_files\\' + LID + '-' + InputFile[0:-3] + '-LDR_min_max.dat', 'a') as f: |
Volker@43 | 2520 | with redirect_stdout(f): |
Volker@43 | 2521 | Contribution_aY("LDRCorr", aLDRcorr) |
Volker@43 | 2522 | Contribution_aY("LDRsim", aLDRsim) |
Volker@43 | 2523 | Contribution_aY("EtaX, D90", aEtax) |
Volker@43 | 2524 | Contribution_aY("Etapx, +45°", aEtapx) |
Volker@43 | 2525 | Contribution_aY("Etamx -45°", aEtamx) |
Volker@43 | 2526 | |
Volker@43 | 2527 | |
Volker@43 | 2528 | # Plot other histograms |
Volker@43 | 2529 | if (bPlotEtax): |
Volker@43 | 2530 | |
Volker@43 | 2531 | if (nQin > 0): PlotLDRsim("Qin", aQin, Qin0, dQin, iQin, nQin) |
Volker@43 | 2532 | if (nVin > 0): PlotLDRsim("Vin", aVin, Vin0, dVin, iVin, nVin) |
Volker@43 | 2533 | if (nRotL > 0): PlotLDRsim("RotL", aRotL, RotL0, dRotL, iRotL, nRotL) |
Volker@43 | 2534 | if (nRetE > 0): PlotLDRsim("RetE", aRetE, RetE0, dRetE, iRetE, nRetE) |
Volker@43 | 2535 | if (nRotE > 0): PlotLDRsim("RotE", aRotE, RotE0, dRotE, iRotE, nRotE) |
Volker@43 | 2536 | if (nDiE > 0): PlotLDRsim("DiE", aDiE, DiE0, dDiE, iDiE, nDiE) |
Volker@43 | 2537 | if (nRetO > 0): PlotLDRsim("RetO", aRetO, RetO0, dRetO, iRetO, nRetO) |
Volker@43 | 2538 | if (nRotO > 0): PlotLDRsim("RotO", aRotO, RotO0, dRotO, iRotO, nRotO) |
Volker@43 | 2539 | if (nDiO > 0): PlotLDRsim("DiO", aDiO, DiO0, dDiO, iDiO, nDiO) |
Volker@43 | 2540 | if (nDiC > 0): PlotLDRsim("DiC", aDiC, DiC0, dDiC, iDiC, nDiC) |
Volker@43 | 2541 | if (nRotC > 0): PlotLDRsim("RotC", aRotC, RotC0, dRotC, iRotC, nRotC) |
Volker@43 | 2542 | if (nRetC > 0): PlotLDRsim("RetC", aRetC, RetC0, dRetC, iRetC, nRetC) |
Volker@43 | 2543 | if (nTP > 0): PlotLDRsim("TP", aTP, TP0, dTP, iTP, nTP) |
Volker@43 | 2544 | if (nTS > 0): PlotLDRsim("TS", aTS, TS0, dTS, iTS, nTS) |
Volker@43 | 2545 | if (nRP > 0): PlotLDRsim("RP", aRP, RP0, dRP, iRP, nRP) |
Volker@43 | 2546 | if (nRS > 0): PlotLDRsim("RS", aRS, RS0, dRS, iRS, nRS) |
Volker@43 | 2547 | if (nRetT > 0): PlotLDRsim("RetT", aRetT, RetT0, dRetT, iRetT, nRetT) |
Volker@43 | 2548 | if (nRetR > 0): PlotLDRsim("RetR", aRetR, RetR0, dRetR, iRetR, nRetR) |
Volker@43 | 2549 | if (nERaT > 0): PlotLDRsim("ERaT", aERaT, ERaT0, dERaT, iERaT, nERaT) |
Volker@43 | 2550 | if (nERaR > 0): PlotLDRsim("ERaR", aERaR, ERaR0, dERaR, iERaR, nERaR) |
Volker@43 | 2551 | if (nRotaT > 0): PlotLDRsim("RotaT", aRotaT, RotaT0, dRotaT, iRotaT, nRotaT) |
Volker@43 | 2552 | if (nRotaR > 0): PlotLDRsim("RotaR", aRotaR, RotaR0, dRotaR, iRotaR, nRotaR) |
Volker@43 | 2553 | if (nLDRCal > 0): PlotLDRsim("LDRCal", aLDRCal, LDRCal0, dLDRCal, iLDRCal, nLDRCal) |
Volker@43 | 2554 | if (nTCalT > 0): PlotLDRsim("TCalT", aTCalT, TCalT0, dTCalT, iTCalT, nTCalT) |
Volker@43 | 2555 | if (nTCalR > 0): PlotLDRsim("TCalR", aTCalR, TCalR0, dTCalR, iTCalR, nTCalR) |
Volker@43 | 2556 | if (nNCal > 0): PlotLDRsim("CalNoiseTp", aNCalTp, 0, 1, iNCalTp, nNCal) |
Volker@43 | 2557 | if (nNCal > 0): PlotLDRsim("CalNoiseTm", aNCalTm, 0, 1, iNCalTm, nNCal) |
Volker@43 | 2558 | if (nNCal > 0): PlotLDRsim("CalNoiseRp", aNCalRp, 0, 1, iNCalRp, nNCal) |
Volker@43 | 2559 | if (nNCal > 0): PlotLDRsim("CalNoiseRm", aNCalRm, 0, 1, iNCalRm, nNCal) |
Volker@43 | 2560 | if (nNI > 0): PlotLDRsim("SigNoiseIt", aNIt, 0, 1, iNIt, nNI) |
Volker@43 | 2561 | if (nNI > 0): PlotLDRsim("SigNoiseIr", aNIr, 0, 1, iNIr, nNI) |
Volker@43 | 2562 | plt.show() |
Volker@43 | 2563 | plt.close |
Volker@43 | 2564 | print("---------------------------------------...producing more plots...------------------------------------------------------------------") |
Volker@43 | 2565 | |
Volker@43 | 2566 | if (nQin > 0): PlotEtax("Qin", aQin, Qin0, dQin, iQin, nQin) |
Volker@43 | 2567 | if (nVin > 0): PlotEtax("Vin", aVin, Vin0, dVin, iVin, nVin) |
Volker@43 | 2568 | if (nRotL > 0): PlotEtax("RotL", aRotL, RotL0, dRotL, iRotL, nRotL) |
Volker@43 | 2569 | if (nRetE > 0): PlotEtax("RetE", aRetE, RetE0, dRetE, iRetE, nRetE) |
Volker@43 | 2570 | if (nRotE > 0): PlotEtax("RotE", aRotE, RotE0, dRotE, iRotE, nRotE) |
Volker@43 | 2571 | if (nDiE > 0): PlotEtax("DiE", aDiE, DiE0, dDiE, iDiE, nDiE) |
Volker@43 | 2572 | if (nRetO > 0): PlotEtax("RetO", aRetO, RetO0, dRetO, iRetO, nRetO) |
Volker@43 | 2573 | if (nRotO > 0): PlotEtax("RotO", aRotO, RotO0, dRotO, iRotO, nRotO) |
Volker@43 | 2574 | if (nDiO > 0): PlotEtax("DiO", aDiO, DiO0, dDiO, iDiO, nDiO) |
Volker@43 | 2575 | if (nDiC > 0): PlotEtax("DiC", aDiC, DiC0, dDiC, iDiC, nDiC) |
Volker@43 | 2576 | if (nRotC > 0): PlotEtax("RotC", aRotC, RotC0, dRotC, iRotC, nRotC) |
Volker@43 | 2577 | if (nRetC > 0): PlotEtax("RetC", aRetC, RetC0, dRetC, iRetC, nRetC) |
Volker@43 | 2578 | if (nTP > 0): PlotEtax("TP", aTP, TP0, dTP, iTP, nTP) |
Volker@43 | 2579 | if (nTS > 0): PlotEtax("TS", aTS, TS0, dTS, iTS, nTS) |
Volker@43 | 2580 | if (nRP > 0): PlotEtax("RP", aRP, RP0, dRP, iRP, nRP) |
Volker@43 | 2581 | if (nRS > 0): PlotEtax("RS", aRS, RS0, dRS, iRS, nRS) |
Volker@43 | 2582 | if (nRetT > 0): PlotEtax("RetT", aRetT, RetT0, dRetT, iRetT, nRetT) |
Volker@43 | 2583 | if (nRetR > 0): PlotEtax("RetR", aRetR, RetR0, dRetR, iRetR, nRetR) |
Volker@43 | 2584 | if (nERaT > 0): PlotEtax("ERaT", aERaT, ERaT0, dERaT, iERaT, nERaT) |
Volker@43 | 2585 | if (nERaR > 0): PlotEtax("ERaR", aERaR, ERaR0, dERaR, iERaR, nERaR) |
Volker@43 | 2586 | if (nRotaT > 0): PlotEtax("RotaT", aRotaT, RotaT0, dRotaT, iRotaT, nRotaT) |
Volker@43 | 2587 | if (nRotaR > 0): PlotEtax("RotaR", aRotaR, RotaR0, dRotaR, iRotaR, nRotaR) |
Volker@43 | 2588 | if (nLDRCal > 0): PlotEtax("LDRCal", aLDRCal, LDRCal0, dLDRCal, iLDRCal, nLDRCal) |
Volker@43 | 2589 | if (nTCalT > 0): PlotEtax("TCalT", aTCalT, TCalT0, dTCalT, iTCalT, nTCalT) |
Volker@43 | 2590 | if (nTCalR > 0): PlotEtax("TCalR", aTCalR, TCalR0, dTCalR, iTCalR, nTCalR) |
Volker@43 | 2591 | if (nNCal > 0): PlotEtax("CalNoiseTp", aNCalTp, 0, 1, iNCalTp, nNCal) |
Volker@43 | 2592 | if (nNCal > 0): PlotEtax("CalNoiseTm", aNCalTm, 0, 1, iNCalTm, nNCal) |
Volker@43 | 2593 | if (nNCal > 0): PlotEtax("CalNoiseRp", aNCalRp, 0, 1, iNCalRp, nNCal) |
Volker@43 | 2594 | if (nNCal > 0): PlotEtax("CalNoiseRm", aNCalRm, 0, 1, iNCalRm, nNCal) |
Volker@43 | 2595 | if (nNI > 0): PlotEtax("SigNoiseIt", aNIt, 0, 1, iNIt, nNI) |
Volker@43 | 2596 | if (nNI > 0): PlotEtax("SigNoiseIr", aNIr, 0, 1, iNIr, nNI) |
Volker@43 | 2597 | plt.show() |
Volker@43 | 2598 | plt.close |
Volker@43 | 2599 | print("---------------------------------------...producing more plots...------------------------------------------------------------------") |
Volker@43 | 2600 | |
Volker@43 | 2601 | if (nQin > 0): PlotEtapx("Qin", aQin, Qin0, dQin, iQin, nQin) |
Volker@43 | 2602 | if (nVin > 0): PlotEtapx("Vin", aVin, Vin0, dVin, iVin, nVin) |
Volker@43 | 2603 | if (nRotL > 0): PlotEtapx("RotL", aRotL, RotL0, dRotL, iRotL, nRotL) |
Volker@43 | 2604 | if (nRetE > 0): PlotEtapx("RetE", aRetE, RetE0, dRetE, iRetE, nRetE) |
Volker@43 | 2605 | if (nRotE > 0): PlotEtapx("RotE", aRotE, RotE0, dRotE, iRotE, nRotE) |
Volker@43 | 2606 | if (nDiE > 0): PlotEtapx("DiE", aDiE, DiE0, dDiE, iDiE, nDiE) |
Volker@43 | 2607 | if (nRetO > 0): PlotEtapx("RetO", aRetO, RetO0, dRetO, iRetO, nRetO) |
Volker@43 | 2608 | if (nRotO > 0): PlotEtapx("RotO", aRotO, RotO0, dRotO, iRotO, nRotO) |
Volker@43 | 2609 | if (nDiO > 0): PlotEtapx("DiO", aDiO, DiO0, dDiO, iDiO, nDiO) |
Volker@43 | 2610 | if (nDiC > 0): PlotEtapx("DiC", aDiC, DiC0, dDiC, iDiC, nDiC) |
Volker@43 | 2611 | if (nRotC > 0): PlotEtapx("RotC", aRotC, RotC0, dRotC, iRotC, nRotC) |
Volker@43 | 2612 | if (nRetC > 0): PlotEtapx("RetC", aRetC, RetC0, dRetC, iRetC, nRetC) |
Volker@43 | 2613 | if (nTP > 0): PlotEtapx("TP", aTP, TP0, dTP, iTP, nTP) |
Volker@43 | 2614 | if (nTS > 0): PlotEtapx("TS", aTS, TS0, dTS, iTS, nTS) |
Volker@43 | 2615 | if (nRP > 0): PlotEtapx("RP", aRP, RP0, dRP, iRP, nRP) |
Volker@43 | 2616 | if (nRS > 0): PlotEtapx("RS", aRS, RS0, dRS, iRS, nRS) |
Volker@43 | 2617 | if (nRetT > 0): PlotEtapx("RetT", aRetT, RetT0, dRetT, iRetT, nRetT) |
Volker@43 | 2618 | if (nRetR > 0): PlotEtapx("RetR", aRetR, RetR0, dRetR, iRetR, nRetR) |
Volker@43 | 2619 | if (nERaT > 0): PlotEtapx("ERaT", aERaT, ERaT0, dERaT, iERaT, nERaT) |
Volker@43 | 2620 | if (nERaR > 0): PlotEtapx("ERaR", aERaR, ERaR0, dERaR, iERaR, nERaR) |
Volker@43 | 2621 | if (nRotaT > 0): PlotEtapx("RotaT", aRotaT, RotaT0, dRotaT, iRotaT, nRotaT) |
Volker@43 | 2622 | if (nRotaR > 0): PlotEtapx("RotaR", aRotaR, RotaR0, dRotaR, iRotaR, nRotaR) |
Volker@43 | 2623 | if (nLDRCal > 0): PlotEtapx("LDRCal", aLDRCal, LDRCal0, dLDRCal, iLDRCal, nLDRCal) |
Volker@43 | 2624 | if (nTCalT > 0): PlotEtapx("TCalT", aTCalT, TCalT0, dTCalT, iTCalT, nTCalT) |
Volker@43 | 2625 | if (nTCalR > 0): PlotEtapx("TCalR", aTCalR, TCalR0, dTCalR, iTCalR, nTCalR) |
Volker@43 | 2626 | if (nNCal > 0): PlotEtapx("CalNoiseTp", aNCalTp, 0, 1, iNCalTp, nNCal) |
Volker@43 | 2627 | if (nNCal > 0): PlotEtapx("CalNoiseTm", aNCalTm, 0, 1, iNCalTm, nNCal) |
Volker@43 | 2628 | if (nNCal > 0): PlotEtapx("CalNoiseRp", aNCalRp, 0, 1, iNCalRp, nNCal) |
Volker@43 | 2629 | if (nNCal > 0): PlotEtapx("CalNoiseRm", aNCalRm, 0, 1, iNCalRm, nNCal) |
Volker@43 | 2630 | if (nNI > 0): PlotEtapx("SigNoiseIt", aNIt, 0, 1, iNIt, nNI) |
Volker@43 | 2631 | if (nNI > 0): PlotEtapx("SigNoiseIr", aNIr, 0, 1, iNIr, nNI) |
Volker@43 | 2632 | plt.show() |
Volker@43 | 2633 | plt.close |
Volker@43 | 2634 | print("---------------------------------------...producing more plots...------------------------------------------------------------------") |
Volker@43 | 2635 | |
Volker@43 | 2636 | if (nQin > 0): PlotEtamx("Qin", aQin, Qin0, dQin, iQin, nQin) |
Volker@43 | 2637 | if (nVin > 0): PlotEtamx("Vin", aVin, Vin0, dVin, iVin, nVin) |
Volker@43 | 2638 | if (nRotL > 0): PlotEtamx("RotL", aRotL, RotL0, dRotL, iRotL, nRotL) |
Volker@43 | 2639 | if (nRetE > 0): PlotEtamx("RetE", aRetE, RetE0, dRetE, iRetE, nRetE) |
Volker@43 | 2640 | if (nRotE > 0): PlotEtamx("RotE", aRotE, RotE0, dRotE, iRotE, nRotE) |
Volker@43 | 2641 | if (nDiE > 0): PlotEtamx("DiE", aDiE, DiE0, dDiE, iDiE, nDiE) |
Volker@43 | 2642 | if (nRetO > 0): PlotEtamx("RetO", aRetO, RetO0, dRetO, iRetO, nRetO) |
Volker@43 | 2643 | if (nRotO > 0): PlotEtamx("RotO", aRotO, RotO0, dRotO, iRotO, nRotO) |
Volker@43 | 2644 | if (nDiO > 0): PlotEtamx("DiO", aDiO, DiO0, dDiO, iDiO, nDiO) |
Volker@43 | 2645 | if (nDiC > 0): PlotEtamx("DiC", aDiC, DiC0, dDiC, iDiC, nDiC) |
Volker@43 | 2646 | if (nRotC > 0): PlotEtamx("RotC", aRotC, RotC0, dRotC, iRotC, nRotC) |
Volker@43 | 2647 | if (nRetC > 0): PlotEtamx("RetC", aRetC, RetC0, dRetC, iRetC, nRetC) |
Volker@43 | 2648 | if (nTP > 0): PlotEtamx("TP", aTP, TP0, dTP, iTP, nTP) |
Volker@43 | 2649 | if (nTS > 0): PlotEtamx("TS", aTS, TS0, dTS, iTS, nTS) |
Volker@43 | 2650 | if (nRP > 0): PlotEtamx("RP", aRP, RP0, dRP, iRP, nRP) |
Volker@43 | 2651 | if (nRS > 0): PlotEtamx("RS", aRS, RS0, dRS, iRS, nRS) |
Volker@43 | 2652 | if (nRetT > 0): PlotEtamx("RetT", aRetT, RetT0, dRetT, iRetT, nRetT) |
Volker@43 | 2653 | if (nRetR > 0): PlotEtamx("RetR", aRetR, RetR0, dRetR, iRetR, nRetR) |
Volker@43 | 2654 | if (nERaT > 0): PlotEtamx("ERaT", aERaT, ERaT0, dERaT, iERaT, nERaT) |
Volker@43 | 2655 | if (nERaR > 0): PlotEtamx("ERaR", aERaR, ERaR0, dERaR, iERaR, nERaR) |
Volker@43 | 2656 | if (nRotaT > 0): PlotEtamx("RotaT", aRotaT, RotaT0, dRotaT, iRotaT, nRotaT) |
Volker@43 | 2657 | if (nRotaR > 0): PlotEtamx("RotaR", aRotaR, RotaR0, dRotaR, iRotaR, nRotaR) |
Volker@43 | 2658 | if (nLDRCal > 0): PlotEtamx("LDRCal", aLDRCal, LDRCal0, dLDRCal, iLDRCal, nLDRCal) |
Volker@43 | 2659 | if (nTCalT > 0): PlotEtamx("TCalT", aTCalT, TCalT0, dTCalT, iTCalT, nTCalT) |
Volker@43 | 2660 | if (nTCalR > 0): PlotEtamx("TCalR", aTCalR, TCalR0, dTCalR, iTCalR, nTCalR) |
Volker@43 | 2661 | if (nNCal > 0): PlotEtamx("CalNoiseTp", aNCalTp, 0, 1, iNCalTp, nNCal) |
Volker@43 | 2662 | if (nNCal > 0): PlotEtamx("CalNoiseTm", aNCalTm, 0, 1, iNCalTm, nNCal) |
Volker@43 | 2663 | if (nNCal > 0): PlotEtamx("CalNoiseRp", aNCalRp, 0, 1, iNCalRp, nNCal) |
Volker@43 | 2664 | if (nNCal > 0): PlotEtamx("CalNoiseRm", aNCalRm, 0, 1, iNCalRm, nNCal) |
Volker@43 | 2665 | if (nNI > 0): PlotEtamx("SigNoiseIt", aNIt, 0, 1, iNIt, nNI) |
Volker@43 | 2666 | if (nNI > 0): PlotEtamx("SigNoiseIr", aNIr, 0, 1, iNIr, nNI) |
Volker@43 | 2667 | plt.show() |
Volker@43 | 2668 | plt.close |
Volker@43 | 2669 | |
Volker@43 | 2670 | # Print Etax statistics |
Volker@43 | 2671 | Etaxmin = np.amin(aEtax[1, :]) |
Volker@43 | 2672 | Etaxmax = np.amax(aEtax[1, :]) |
Volker@43 | 2673 | Etaxstd = np.std(aEtax[1, :]) |
Volker@43 | 2674 | Etaxmean = np.mean(aEtax[1, :]) |
Volker@43 | 2675 | Etaxmedian = np.median(aEtax[1, :]) |
Volker@43 | 2676 | print("Etax , max-mean, min-mean, median, mean ± std, eta") |
Volker@43 | 2677 | print("{0:8.5f} ±({1:8.5f},{2:8.5f}),{3:8.5f},{4:8.5f}±{5:8.5f},{6:8.5f}".format(Etax0, Etaxmax-Etax0, Etaxmin-Etax0, Etaxmedian, Etaxmean, Etaxstd, Etax0 / K0)) |
Volker@43 | 2678 | print() |
Volker@43 | 2679 | |
Volker@43 | 2680 | # Calculate and print statistics for calibration factors |
Volker@43 | 2681 | iLDR = -1 |
Volker@43 | 2682 | LDRrangeA = np.array(LDRrange) |
Volker@43 | 2683 | print("LDR...., LDRsim, (max-min)/2, relerr") |
Volker@43 | 2684 | for LDRTrue in LDRrange: |
Volker@43 | 2685 | iLDR = iLDR + 1 |
Volker@43 | 2686 | LDRsimmin[iLDR] = np.amin(aLDRsim[iLDR, :]) |
Volker@43 | 2687 | LDRsimmax[iLDR] = np.amax(aLDRsim[iLDR, :]) |
Volker@43 | 2688 | # LDRsimstd = np.std(aLDRsim[iLDR, :]) |
Volker@43 | 2689 | LDRsimmean[iLDR] = np.mean(aLDRsim[iLDR, :]) |
Volker@43 | 2690 | # LDRsimmedian = np.median(aLDRsim[iLDR, :]) |
Volker@43 | 2691 | print("{0:8.5f}, {1:8.5f}, {2:8.5f}, {3:8.5f}".format(LDRrangeA[iLDR], LDRsimmean[iLDR], (LDRsimmax[iLDR]-LDRsimmin[iLDR])/2, (LDRsimmax[iLDR]-LDRsimmin[iLDR])/2/LDRsimmean[iLDR])) |
Volker@43 | 2692 | iLDR = -1 |
Volker@43 | 2693 | print("LDR...., Etax , (max-min)/2, relerr") |
Volker@43 | 2694 | for LDRTrue in LDRrange: |
Volker@43 | 2695 | iLDR = iLDR + 1 |
Volker@43 | 2696 | Etaxmin = np.amin(aEtax[iLDR, :]) |
Volker@43 | 2697 | Etaxmax = np.amax(aEtax[iLDR, :]) |
Volker@43 | 2698 | # Etaxstd = np.std(aEtax[iLDR, :]) |
Volker@43 | 2699 | Etaxmean = np.mean(aEtax[iLDR, :]) |
Volker@43 | 2700 | # Etaxmedian = np.median(aEtax[iLDR, :]) |
Volker@43 | 2701 | print("{0:8.5f}, {1:8.5f}, {2:8.5f}, {3:8.5f}".format(LDRrangeA[iLDR], Etaxmean, (Etaxmax-Etaxmin)/2, (Etaxmax-Etaxmin)/2/Etaxmean)) |
Volker@43 | 2702 | iLDR = -1 |
Volker@43 | 2703 | print("LDR...., Etapx , (max-min)/2, relerr") |
Volker@43 | 2704 | for LDRTrue in LDRrange: |
Volker@43 | 2705 | iLDR = iLDR + 1 |
Volker@43 | 2706 | Etapxmin = np.amin(aEtapx[iLDR, :]) |
Volker@43 | 2707 | Etapxmax = np.amax(aEtapx[iLDR, :]) |
Volker@43 | 2708 | # Etapxstd = np.std(aEtapx[iLDR, :]) |
Volker@43 | 2709 | Etapxmean = np.mean(aEtapx[iLDR, :]) |
Volker@43 | 2710 | # Etapxmedian = np.median(aEtapx[iLDR, :]) |
Volker@43 | 2711 | print("{0:8.5f}, {1:8.5f}, {2:8.5f}, {3:8.5f}".format(LDRrangeA[iLDR], Etapxmean, (Etapxmax-Etapxmin)/2, (Etapxmax-Etapxmin)/2/Etapxmean)) |
Volker@43 | 2712 | iLDR = -1 |
Volker@43 | 2713 | print("LDR...., Etamx , (max-min)/2, relerr") |
Volker@43 | 2714 | for LDRTrue in LDRrange: |
Volker@43 | 2715 | iLDR = iLDR + 1 |
Volker@43 | 2716 | Etamxmin = np.amin(aEtamx[iLDR, :]) |
Volker@43 | 2717 | Etamxmax = np.amax(aEtamx[iLDR, :]) |
Volker@43 | 2718 | # Etamxstd = np.std(aEtamx[iLDR, :]) |
Volker@43 | 2719 | Etamxmean = np.mean(aEtamx[iLDR, :]) |
Volker@43 | 2720 | # Etamxmedian = np.median(aEtamx[iLDR, :]) |
Volker@43 | 2721 | print("{0:8.5f}, {1:8.5f}, {2:8.5f}, {3:8.5f}".format(LDRrangeA[iLDR], Etamxmean, (Etamxmax-Etamxmin)/2, (Etamxmax-Etamxmin)/2/Etamxmean)) |
Volker@43 | 2722 | |
Volker@43 | 2723 | f.close() |
Volker@43 | 2724 | |
Volker@43 | 2725 | |
Volker@43 | 2726 | ''' |
Volker@43 | 2727 | # --- Plot F11 histograms |
Volker@43 | 2728 | print() |
Volker@43 | 2729 | print(" ############################################################################## ") |
Volker@43 | 2730 | print(Text1) |
Volker@43 | 2731 | print() |
Volker@43 | 2732 | |
Volker@43 | 2733 | iLDR = 5 |
Volker@43 | 2734 | for LDRTrue in LDRrange: |
Volker@43 | 2735 | iLDR = iLDR - 1 |
Volker@43 | 2736 | #aF11corr[iLDR,:] = aF11corr[iLDR,:] / aF11corr[0,:] - 1.0 |
Volker@43 | 2737 | aF11corr[iLDR,:] = aF11corr[iLDR,:] / aF11sim0[iLDR] - 1.0 |
Volker@43 | 2738 | # Plot F11 |
Volker@43 | 2739 | def PlotSubHistF11(aVar, aX, X0, daX, iaX, naX): |
Volker@43 | 2740 | fig, ax = plt.subplots(nrows=1, ncols=5, sharex=True, sharey=True, figsize=(25, 2)) |
Volker@43 | 2741 | iLDR = -1 |
Volker@43 | 2742 | for LDRTrue in LDRrange: |
Volker@43 | 2743 | iLDR = iLDR + 1 |
Volker@43 | 2744 | |
Volker@43 | 2745 | #F11min[iLDR] = np.min(aF11corr[iLDR,:]) |
Volker@43 | 2746 | #F11max[iLDR] = np.max(aF11corr[iLDR,:]) |
Volker@43 | 2747 | #Rmin = F11min[iLDR] * 0.995 # np.min(aLDRcorr[iLDR,:]) * 0.995 |
Volker@43 | 2748 | #Rmax = F11max[iLDR] * 1.005 # np.max(aLDRcorr[iLDR,:]) * 1.005 |
Volker@43 | 2749 | |
Volker@43 | 2750 | #Rmin = 0.8 |
Volker@43 | 2751 | #Rmax = 1.2 |
Volker@43 | 2752 | |
Volker@43 | 2753 | #plt.subplot(5,2,iLDR+1) |
Volker@43 | 2754 | plt.subplot(1,5,iLDR+1) |
Volker@43 | 2755 | (n, bins, patches) = plt.hist(aF11corr[iLDR,:], |
Volker@43 | 2756 | bins=100, log=False, |
Volker@43 | 2757 | alpha=0.5, density=False, color = '0.5', histtype='stepfilled') |
Volker@43 | 2758 | |
Volker@43 | 2759 | for iaX in range(-naX,naX+1): |
Volker@43 | 2760 | plt.hist(aF11corr[iLDR,aX == iaX], |
Volker@43 | 2761 | bins=100, log=False, alpha=0.3, density=False, histtype='stepfilled', label = str(round(X0 + iaX*daX/naX,5))) |
Volker@43 | 2762 | |
Volker@43 | 2763 | if (iLDR == 2): plt.legend() |
Volker@43 | 2764 | |
Volker@43 | 2765 | plt.tick_params(axis='both', labelsize=9) |
Volker@43 | 2766 | #plt.plot([LDRTrue, LDRTrue], [0, np.max(n)], 'r-', lw=2) |
Volker@43 | 2767 | |
Volker@43 | 2768 | #plt.title(LID + ' ' + aVar, fontsize=18) |
Volker@43 | 2769 | #plt.ylabel('frequency', fontsize=10) |
Volker@43 | 2770 | #plt.xlabel('LDRCorr', fontsize=10) |
Volker@43 | 2771 | #fig.tight_layout() |
Volker@43 | 2772 | fig.suptitle(LID + ' ' + str(Type[TypeC]) + ' ' + str(Loc[LocC]) + ' - ' + aVar, fontsize=14, y=1.05) |
Volker@43 | 2773 | #plt.show() |
Volker@43 | 2774 | #fig.savefig(LID + '_' + aVar + '.png', dpi=150, bbox_inches='tight', pad_inches=0) |
Volker@43 | 2775 | #plt.close |
Volker@43 | 2776 | return |
Volker@43 | 2777 | |
Volker@43 | 2778 | if (nQin > 0): PlotSubHistF11("Qin", aQin, Qin0, dQin, iQin, nQin) |
Volker@43 | 2779 | if (nVin > 0): PlotSubHistF11("Vin", aVin, Vin0, dVin, iVin, nVin) |
Volker@43 | 2780 | if (nRotL > 0): PlotSubHistF11("RotL", aRotL, RotL0, dRotL, iRotL, nRotL) |
Volker@43 | 2781 | if (nRetE > 0): PlotSubHistF11("RetE", aRetE, RetE0, dRetE, iRetE, nRetE) |
Volker@43 | 2782 | if (nRotE > 0): PlotSubHistF11("RotE", aRotE, RotE0, dRotE, iRotE, nRotE) |
Volker@43 | 2783 | if (nDiE > 0): PlotSubHistF11("DiE", aDiE, DiE0, dDiE, iDiE, nDiE) |
Volker@43 | 2784 | if (nRetO > 0): PlotSubHistF11("RetO", aRetO, RetO0, dRetO, iRetO, nRetO) |
Volker@43 | 2785 | if (nRotO > 0): PlotSubHistF11("RotO", aRotO, RotO0, dRotO, iRotO, nRotO) |
Volker@43 | 2786 | if (nDiO > 0): PlotSubHistF11("DiO", aDiO, DiO0, dDiO, iDiO, nDiO) |
Volker@43 | 2787 | if (nDiC > 0): PlotSubHistF11("DiC", aDiC, DiC0, dDiC, iDiC, nDiC) |
Volker@43 | 2788 | if (nRotC > 0): PlotSubHistF11("RotC", aRotC, RotC0, dRotC, iRotC, nRotC) |
Volker@43 | 2789 | if (nRetC > 0): PlotSubHistF11("RetC", aRetC, RetC0, dRetC, iRetC, nRetC) |
Volker@43 | 2790 | if (nTP > 0): PlotSubHistF11("TP", aTP, TP0, dTP, iTP, nTP) |
Volker@43 | 2791 | if (nTS > 0): PlotSubHistF11("TS", aTS, TS0, dTS, iTS, nTS) |
Volker@43 | 2792 | if (nRP > 0): PlotSubHistF11("RP", aRP, RP0, dRP, iRP, nRP) |
Volker@43 | 2793 | if (nRS > 0): PlotSubHistF11("RS", aRS, RS0, dRS, iRS, nRS) |
Volker@43 | 2794 | if (nRetT > 0): PlotSubHistF11("RetT", aRetT, RetT0, dRetT, iRetT, nRetT) |
Volker@43 | 2795 | if (nRetR > 0): PlotSubHistF11("RetR", aRetR, RetR0, dRetR, iRetR, nRetR) |
Volker@43 | 2796 | if (nERaT > 0): PlotSubHistF11("ERaT", aERaT, ERaT0, dERaT, iERaT, nERaT) |
Volker@43 | 2797 | if (nERaR > 0): PlotSubHistF11("ERaR", aERaR, ERaR0, dERaR, iERaR, nERaR) |
Volker@43 | 2798 | if (nRotaT > 0): PlotSubHistF11("RotaT", aRotaT, RotaT0, dRotaT, iRotaT, nRotaT) |
Volker@43 | 2799 | if (nRotaR > 0): PlotSubHistF11("RotaR", aRotaR, RotaR0, dRotaR, iRotaR, nRotaR) |
Volker@43 | 2800 | if (nLDRCal > 0): PlotSubHistF11("LDRCal", aLDRCal, LDRCal0, dLDRCal, iLDRCal, nLDRCal) |
Volker@43 | 2801 | if (nTCalT > 0): PlotSubHistF11("TCalT", aTCalT, TCalT0, dTCalT, iTCalT, nTCalT) |
Volker@43 | 2802 | if (nTCalR > 0): PlotSubHistF11("TCalR", aTCalR, TCalR0, dTCalR, iTCalR, nTCalR) |
Volker@43 | 2803 | if (nNCal > 0): PlotSubHistF11("CalNoise", aNCal, 0, 1/nNCal, iNCal, nNCal) |
Volker@43 | 2804 | if (nNI > 0): PlotSubHistF11("SigNoise", aNI, 0, 1/nNI, iNI, nNI) |
Volker@43 | 2805 | |
Volker@43 | 2806 | |
Volker@43 | 2807 | plt.show() |
Volker@43 | 2808 | plt.close |
Volker@43 | 2809 | |
Volker@43 | 2810 | ''' |
Volker@43 | 2811 | ''' |
Volker@43 | 2812 | # only histogram |
Volker@43 | 2813 | #print("******************* " + aVar + " *******************") |
Volker@43 | 2814 | fig, ax = plt.subplots(nrows=5, ncols=2, sharex=True, sharey=True, figsize=(10, 10)) |
Volker@43 | 2815 | iLDR = -1 |
Volker@43 | 2816 | for LDRTrue in LDRrange: |
Volker@43 | 2817 | iLDR = iLDR + 1 |
Volker@43 | 2818 | LDRmin[iLDR] = np.min(aLDRcorr[iLDR,:]) |
Volker@43 | 2819 | LDRmax[iLDR] = np.max(aLDRcorr[iLDR,:]) |
Volker@43 | 2820 | Rmin = np.min(aLDRcorr[iLDR,:]) * 0.999 |
Volker@43 | 2821 | Rmax = np.max(aLDRcorr[iLDR,:]) * 1.001 |
Volker@43 | 2822 | plt.subplot(5,2,iLDR+1) |
Volker@43 | 2823 | (n, bins, patches) = plt.hist(aLDRcorr[iLDR,:], |
Volker@43 | 2824 | range=[Rmin, Rmax], |
Volker@43 | 2825 | bins=200, log=False, alpha=0.2, density=False, color = '0.5', histtype='stepfilled') |
Volker@43 | 2826 | plt.tick_params(axis='both', labelsize=9) |
Volker@43 | 2827 | plt.plot([LDRTrue, LDRTrue], [0, np.max(n)], 'r-', lw=2) |
Volker@43 | 2828 | plt.show() |
Volker@43 | 2829 | plt.close |
Volker@43 | 2830 | # --- End of Plot F11 histograms |
Volker@43 | 2831 | ''' |
Volker@43 | 2832 | |
Volker@43 | 2833 | |
Volker@43 | 2834 | ''' |
Volker@43 | 2835 | # --- Plot K over LDRCal |
Volker@43 | 2836 | fig3 = plt.figure() |
Volker@43 | 2837 | plt.plot(LDRCal0+aLDRCal*dLDRCal/nLDRCal,aGHK[4,:], linewidth=2.0, color='b') |
Volker@43 | 2838 | |
Volker@43 | 2839 | plt.xlabel('LDRCal', fontsize=18) |
Volker@43 | 2840 | plt.ylabel('K', fontsize=14) |
Volker@43 | 2841 | plt.title(LID, fontsize=18) |
Volker@43 | 2842 | plt.show() |
Volker@43 | 2843 | plt.close |
Volker@43 | 2844 | ''' |
Volker@43 | 2845 | |
Volker@43 | 2846 | # Additional plot routines ======> |
Volker@43 | 2847 | ''' |
Volker@43 | 2848 | #****************************************************************************** |
Volker@43 | 2849 | # 1. Plot LDRCorrected - LDR(measured Icross/Iparallel) |
Volker@43 | 2850 | LDRa = np.arange(1.,100.)*0.005 |
Volker@43 | 2851 | LDRCorra = np.arange(1.,100.) |
Volker@43 | 2852 | if Y == - 1.: LDRa = 1./LDRa |
Volker@43 | 2853 | LDRCorra = (1./Eta*LDRa*(GT+HT)-(GR+HR))/((GR-HR)-1./Eta*LDRa*(GT-HT)) |
Volker@43 | 2854 | if Y == - 1.: LDRa = 1./LDRa |
Volker@43 | 2855 | # |
Volker@43 | 2856 | #fig = plt.figure() |
Volker@43 | 2857 | plt.plot(LDRa,LDRCorra-LDRa) |
Volker@43 | 2858 | plt.plot([0.,0.5],[0.,0.5]) |
Volker@43 | 2859 | plt.suptitle('LDRCorrected - LDR(measured Icross/Iparallel)', fontsize=16) |
Volker@43 | 2860 | plt.xlabel('LDR', fontsize=18) |
Volker@43 | 2861 | plt.ylabel('LDRCorr - LDR', fontsize=16) |
Volker@43 | 2862 | #plt.savefig('test.png') |
Volker@43 | 2863 | # |
Volker@43 | 2864 | ''' |
Volker@43 | 2865 | ''' |
Volker@43 | 2866 | #****************************************************************************** |
Volker@43 | 2867 | # 2. Plot LDRsim (simulated measurements without corrections = Icross/Iparallel) over LDRtrue |
Volker@43 | 2868 | LDRa = np.arange(1.,100.)*0.005 |
Volker@43 | 2869 | LDRsima = np.arange(1.,100.) |
Volker@43 | 2870 | |
Volker@43 | 2871 | atruea = (1.-LDRa)/(1+LDRa) |
Volker@43 | 2872 | Ita = TiT*TiO*IinL*(GT+atruea*HT) |
Volker@43 | 2873 | Ira = TiR*TiO*IinL*(GR+atruea*HR) |
Volker@43 | 2874 | LDRsima = Ira/Ita # simulated uncorrected LDR with Y from input file |
Volker@43 | 2875 | if Y == -1.: LDRsima = 1./LDRsima |
Volker@43 | 2876 | # |
Volker@43 | 2877 | #fig = plt.figure() |
Volker@43 | 2878 | plt.plot(LDRa,LDRsima) |
Volker@43 | 2879 | plt.plot([0.,0.5],[0.,0.5]) |
Volker@43 | 2880 | plt.suptitle('LDRsim (simulated measurements without corrections = Icross/Iparallel) over LDRtrue', fontsize=10) |
Volker@43 | 2881 | plt.xlabel('LDRtrue', fontsize=18) |
Volker@43 | 2882 | plt.ylabel('LDRsim', fontsize=16) |
Volker@43 | 2883 | #plt.savefig('test.png') |
Volker@43 | 2884 | # |
Volker@43 | 2885 | ''' |