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