AN_RQ_PLI2.f1.ipynb 47.3 KB
Newer Older
1 2 3 4
{
 "cells": [
  {
   "cell_type": "markdown",
5 6 7
   "metadata": {
    "deletable": false
   },
8 9 10 11
   "source": [
    "<h1><center>Analysis of PLI2.f1 HWC Test in an RQ Circuit</center></h1>\n",
    "\n",
    "<img src=\"https://gitlab.cern.ch/LHCData/lhc-sm-hwc/raw/master/figures/rq/RQ.png\" width=75%>\n",
12
    "source: Test Procedure and Acceptance Criteria for the 13 kA Quadrupole (RQD-RQF) Circuits, MP3 Procedure, <a href=\"https://edms.cern.ch/document/874714\">https://edms.cern.ch/document/874714</a> (Please follow this link for the latest version)"
13 14 15 16
   ]
  },
  {
   "cell_type": "markdown",
17 18 19
   "metadata": {
    "deletable": false
   },
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
   "source": [
    "# Analysis Assumptions\n",
    "- We consider standard analysis scenarios, i.e., all signals can be queried. If a signal is missing, an analysis can raise a warning and continue or an error and abort the analysis.\n",
    "- It is recommended to execute each cell one after another. However, since the signals are queried prior to analysis, any order of execution is allowed. In case an analysis cell is aborted, the following ones may not be executed (e.g. I\\_MEAS not present). \n",
    "\n",
    "# Plot Convention\n",
    "- Scales are labeled with signal name followed by a comma and a unit in square brackets, e.g., I_MEAS, [A].\n",
    "- If a reference signal is present, it is represented with a dashed line.\n",
    "- If the main current is present, its axis is on the left. Remaining signals are attached to the axis on the right. The legend of these signals is located on the lower left and upper right, respectively.\n",
    "- The grid comes from the left axis.\n",
    "- The title contains timestamp, circuit name, and signal name allowing to re-access the signal.\n",
    "- The plots assigned to the left scale have colors: blue (C0) and orange (C1). Plots presented on the right have colors red (C2) and green (C3).\n",
    "- Each plot has an individual time-synchronization mentioned explicitly in the description.\n",
    "- If an axis has a single signal, then the color of the label matches the signal's color. Otherwise, the label color is black.\n"
   ]
  },
  {
   "cell_type": "markdown",
38 39 40
   "metadata": {
    "deletable": false
   },
41 42 43 44 45 46
   "source": [
    "# 0. Initialise Working Environment"
   ]
  },
  {
   "cell_type": "code",
47
   "execution_count": null,
48 49 50
   "metadata": {
    "deletable": false
   },
51
   "outputs": [],
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
   "source": [
    "# External libraries\n",
    "print('Loading (1/11)'); import pandas as pd\n",
    "print('Loading (2/11)'); import sys\n",
    "print('Loading (3/11)'); from IPython.display import display, Javascript, clear_output, HTML\n",
    "\n",
    "# Internal libraries\n",
    "print('Loading (4/11)'); import lhcsmapi\n",
    "print('Loading (5/11)'); from lhcsmapi.Time import Time\n",
    "print('Loading (6/11)'); from lhcsmapi.Timer import Timer\n",
    "print('Loading (7/11)'); from lhcsmapi.analysis.RqCircuitQuery import RqCircuitQuery\n",
    "print('Loading (8/11)'); from lhcsmapi.analysis.RqCircuitAnalysis import RqCircuitAnalysis\n",
    "print('Loading (9/11)'); from lhcsmapi.analysis.report_template import apply_report_template\n",
    "print('Loading (10/11)'); from lhcsmapi.gui.hwc.HwcSearchModuleMediator import HwcSearchModuleMediator\n",
    "print('Loading (11/11)'); from lhcsmapi.analysis.expert_input import get_expert_decision\n",
    "\n",
    "clear_output()\n",
    "lhcsmapi.get_lhcsmapi_version()\n",
70 71
    "lhcsmapi.get_lhcsmhwc_version('../__init__.py')\n",
    "print('Analysis performed by %s' % HwcSearchModuleMediator.get_user())"
72 73 74 75
   ]
  },
  {
   "cell_type": "markdown",
76 77 78
   "metadata": {
    "deletable": false
   },
79
   "source": [
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
    "# 1. User Input\n",
    "1. Copy code from AccTesting and paste into an empty cell below\n",
    "<img src=\"https://gitlab.cern.ch/LHCData/lhc-sm-hwc/-/raw/master/figures/swan-manual-acctesting-integration.png\">\n",
    "\n",
    "    - If you only want to test the notebook only for the copy&paste feature (without opening the AccTesting), please copy and execute the code below\n",
    "    ```\n",
    "    hwc_test = 'PLI2.f1'\n",
    "    circuit_name = 'RQD.A12'\n",
    "    campaign = 'HWC_2014'\n",
    "    t_start = '2015-01-17 21:52:03.746'\n",
    "    t_end = '2015-01-17 22:04:52.451'\n",
    "    ```\n",
    "\n",
    "2. To analyze a historical test with a browser GUI, copy and execute the following code in the cell below\n",
    "```\n",
    "circuit_type = 'RQ'\n",
    "hwc_test = 'PLI2.f1'\n",
    "hwcb = HwcSearchModuleMediator(circuit_type=circuit_type, hwc_test=hwc_test, hwc_summary_path='/eos/project/l/lhcsm/hwc/HWC_Summary.csv')\n",
    "```\n",
    "\n",
    "    - After opening the browser GUI, choose a circuit name in order to display HWC test with, campaign name as well as start and end time"
101 102 103 104
   ]
  },
  {
   "cell_type": "code",
105
   "execution_count": null,
106
   "metadata": {
107
    "deletable": false,
108 109
    "scrolled": false
   },
110
   "outputs": [],
Zinur Charifoulline's avatar
Zinur Charifoulline committed
111 112 113 114 115 116 117
   "source": [
    "hwc_test = 'PLI2.f1' \n",
    "circuit_name = 'RQD.A45' \n",
    "campaign= 'Recommissioning post LS2' \n",
    "t_start = '2021-04-07 20:44:14.437000000'\n",
    "t_end = '2021-04-07 20:55:41.364000000'"
   ]
118 119 120 121 122 123
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
124
   "source": [
125
    "print('hwc_test = \\'%s\\'\\ncircuit_name = \\'%s\\'\\ncampaign = \\'%s\\'\\nt_start = \\'%s\\'\\nt_end = \\'%s\\'' % (hwc_test, circuit_name, campaign, t_start, t_end))"
126
   ]
127 128 129
  },
  {
   "cell_type": "markdown",
130 131 132
   "metadata": {
    "deletable": false
   },
133 134 135 136 137 138
   "source": [
    "# 2. Query All Signals Prior to Analysis"
   ]
  },
  {
   "cell_type": "code",
139
   "execution_count": null,
140
   "metadata": {
141
    "deleteable": false,
142 143 144 145
    "scrolled": false,
    "tags": [
     "skip_output"
    ]
146
   },
147
   "outputs": [],
148
   "source": [
149 150 151 152 153
    "circuit_type = 'RQ'\n",
    "if 'hwcb' in locals():\n",
    "    circuit_name = hwcb.get_circuit_name()\n",
    "    t_start = Time.to_unix_timestamp(hwcb.get_start_time())\n",
    "    t_end = Time.to_unix_timestamp(hwcb.get_end_time())\n",
154 155
    "    t_start_ref = Time.to_unix_timestamp(hwcb.get_ref_start_time())\n",
    "    t_end_ref = Time.to_unix_timestamp(hwcb.get_ref_end_time())\n",
156 157 158 159
    "    is_automatic = hwcb.is_automatic_mode()\n",
    "else:\n",
    "    t_start = Time.to_unix_timestamp(t_start)\n",
    "    t_end = Time.to_unix_timestamp(t_end)\n",
160 161 162
    "    t_start_ref, t_end_ref = HwcSearchModuleMediator.get_last_ref_start_end_time('/eos/project/l/lhcsm/hwc/HWC_Summary.csv', circuit_name, hwc_test, Time.to_string_short(t_start))\n",
    "    t_start_ref, t_end_ref = Time.to_unix_timestamp(t_start_ref), Time.to_unix_timestamp(t_end_ref)\n",
    "    is_automatic = False\n",
163
    "\n",
164 165
    "circuit_names = [circuit_name if 'RQD' in circuit_name else circuit_name.replace('F', 'D'), \n",
    "                 circuit_name if 'RQF' in circuit_name else circuit_name.replace('D', 'F')]\n",
166
    "\n",
Michal Maciejewski's avatar
Michal Maciejewski committed
167 168
    "rqd_query = RqCircuitQuery(circuit_type, circuit_names[0], max_executions=28)\n",
    "rqf_query = RqCircuitQuery(circuit_type, circuit_names[1], max_executions=19)\n",
169 170 171 172 173 174 175 176 177 178 179 180
    "\n",
    "with Timer():\n",
    "    # PC\n",
    "    source_timestamp_df = rqd_query.find_source_timestamp_pc(t_start, t_end)\n",
    "    timestamp_fgc_rqd = source_timestamp_df.at[0, 'timestamp']\n",
    "    \n",
    "    source_timestamp_df = rqf_query.find_source_timestamp_pc(t_start, t_end)\n",
    "    timestamp_fgc_rqf = source_timestamp_df.at[0, 'timestamp']\n",
    "    \n",
    "    i_meas_rqd_df, i_a_rqd_df, i_earth_rqd_df, i_earth_pcnt_rqd_df, i_ref_rqd_df = rqd_query.query_pc_pm(timestamp_fgc_rqd, timestamp_fgc_rqd, signal_names=['I_MEAS', 'I_A', 'IEARTH', 'I_EARTH_PCNT', 'I_REF'])\n",
    "    i_meas_rqf_df, i_a_rqf_df, i_earth_rqf_df, i_earth_pcnt_rqf_df, i_ref_rqf_df = rqf_query.query_pc_pm(timestamp_fgc_rqf, timestamp_fgc_rqf, signal_names=['I_MEAS', 'I_A', 'IEARTH', 'I_EARTH_PCNT', 'I_REF'])\n",
    "\n",
181 182 183 184 185
    "    source_timestamp_pc_rqd_ref_df = rqd_query.find_source_timestamp_pc(t_start_ref, t_end_ref)\n",
    "    timestamp_fgc_ref_rqd = source_timestamp_pc_rqd_ref_df.at[0, 'timestamp']\n",
    "    \n",
    "    source_timestamp_pc_rqf_ref_df = rqf_query.find_source_timestamp_pc(t_start_ref, t_end_ref)\n",
    "    timestamp_fgc_ref_rqf = source_timestamp_pc_rqf_ref_df.at[0, 'timestamp']\n",
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
    "\n",
    "    i_meas_ref_rqd_df, i_earth_rqd_ref_df, i_earth_pcnt_rqd_ref_df = rqd_query.query_pc_pm(timestamp_fgc_ref_rqd, timestamp_fgc_ref_rqd, signal_names=['I_MEAS', 'IEARTH', 'I_EARTH_PCNT'])\n",
    "    i_meas_ref_rqf_df, i_earth_rqf_ref_df, i_earth_pcnt_rqf_ref_df = rqf_query.query_pc_pm(timestamp_fgc_ref_rqf, timestamp_fgc_ref_rqf, signal_names=['I_MEAS', 'IEARTH', 'I_EARTH_PCNT'])\n",
    "\n",
    "    # PIC\n",
    "    timestamp_pic_rqd = rqd_query.find_timestamp_pic(timestamp_fgc_rqd, spark=spark)\n",
    "    timestamp_pic_rqf = rqf_query.find_timestamp_pic(timestamp_fgc_rqf, spark=spark)\n",
    "\n",
    "    # EE\n",
    "    source_timestamp_ee_rqd_df = rqd_query.find_source_timestamp_ee(timestamp_fgc_rqd)\n",
    "    timestamp_ee_rqd = source_timestamp_ee_rqd_df.loc[0, 'timestamp']\n",
    "    u_dump_res_rqd_df = rqd_query.query_ee_u_dump_res_pm(timestamp_ee_rqd, timestamp_fgc_rqd, system='EE', signal_names=['U_DUMP_RES'])[0]\n",
    "\n",
    "    source_timestamp_ee_rqf_df = rqf_query.find_source_timestamp_ee(timestamp_fgc_rqf)\n",
    "    timestamp_ee_rqf = source_timestamp_ee_rqf_df.loc[0, 'timestamp']\n",
    "    u_dump_res_rqf_df = rqf_query.query_ee_u_dump_res_pm(timestamp_ee_rqf, timestamp_fgc_rqf, system='EE', signal_names=['U_DUMP_RES'])[0]\n",
    "\n",
    "    t_res_0_rqd_df = rqd_query.query_ee_t_res_pm(source_timestamp_ee_rqd_df.loc[0, 'timestamp'], timestamp_fgc_rqd, system='EE', signal_names=['T_RES'])[0]\n",
204 205 206 207
    "    if len(source_timestamp_ee_rqd_df) > 1:\n",
    "        t_res_1_rqd_df = rqd_query.query_ee_t_res_pm(source_timestamp_ee_rqd_df.loc[1, 'timestamp'], timestamp_fgc_rqd, system='EE', signal_names=['T_RES'])[0]\n",
    "    else:\n",
    "        t_res_1_rqd_df = pd.DataFrame(columns=['T_RES'])\n",
208 209
    "\n",
    "    t_res_0_rqf_df = rqf_query.query_ee_t_res_pm(source_timestamp_ee_rqf_df.loc[0, 'timestamp'], timestamp_fgc_rqf, system='EE', signal_names=['T_RES'])[0]\n",
210 211 212 213
    "    if len(source_timestamp_ee_rqf_df) > 1:\n",
    "        t_res_1_rqf_df = rqf_query.query_ee_t_res_pm(source_timestamp_ee_rqf_df.loc[1, 'timestamp'], timestamp_fgc_rqf, system='EE', signal_names=['T_RES'])[0]\n",
    "    else:\n",
    "        t_res_1_rqf_df = pd.DataFrame(columns=['T_RES'])\n",
214 215
    "\n",
    "    # EE - REF\n",
216 217
    "    source_timestamp_ee_rqd_ref_df = rqd_query.find_source_timestamp_ee(timestamp_fgc_ref_rqd)\n",
    "    source_timestamp_ee_rqf_ref_df = rqf_query.find_source_timestamp_ee(timestamp_fgc_ref_rqf)\n",
218 219
    "\n",
    "    t_res_0_rqd_ref_df = rqd_query.query_ee_t_res_pm(source_timestamp_ee_rqd_ref_df.loc[0, 'timestamp'], timestamp_fgc_ref_rqd, system='EE', signal_names=['T_RES'])[0]\n",
220 221 222 223
    "    if len(source_timestamp_ee_rqd_ref_df) > 1:\n",
    "        t_res_1_rqd_ref_df = rqd_query.query_ee_t_res_pm(source_timestamp_ee_rqd_ref_df.loc[1, 'timestamp'], timestamp_fgc_ref_rqd, system='EE', signal_names=['T_RES'])[0]\n",
    "    else:\n",
    "        t_res_1_rqd_ref_df = pd.DataFrame(columns=['T_RES'])\n",
224 225
    "\n",
    "    t_res_0_rqf_ref_df = rqf_query.query_ee_t_res_pm(source_timestamp_ee_rqf_ref_df.loc[0, 'timestamp'], timestamp_fgc_ref_rqf, system='EE', signal_names=['T_RES'])[0]\n",
226 227 228 229
    "    if len(source_timestamp_ee_rqf_ref_df) > 1:\n",
    "        t_res_1_rqf_ref_df = rqf_query.query_ee_t_res_pm(source_timestamp_ee_rqf_ref_df.loc[1, 'timestamp'], timestamp_fgc_ref_rqf, system='EE', signal_names=['T_RES'])[0]\n",
    "    else:\n",
    "        t_res_1_rqf_ref_df = pd.DataFrame(columns=['T_RES'])\n",
230 231 232
    "\n",
    "    # iQPS\n",
    "    source_timestamp_qds_rq_df = rqd_query.find_source_timestamp_qds(timestamp_fgc_rqd, duration=[(10, 's'), (200, 's')])\n",
233 234
    "    \n",
    "    if Time.to_unix_timestamp(timestamp_fgc_rqd) > 1577833200000000000:\n",
Zinur Charifoulline's avatar
Zinur Charifoulline committed
235
    "        iqps_analog_dfs = rqd_query.query_iqps_analog_pm(source_timestamp_qds_rq_df, signal_names=['U_QS0_INT_A', 'U_QS0_EXT_A'])\n",
236 237 238 239
    "        iqps_digital_dfs = rqd_query.query_iqps_analog_pm(source_timestamp_qds_rq_df, signal_names=['ST_NOLATCH_BR_EXT_A', 'ST_NOLATCH_BR_INT_A', 'ST_NOTRIG_BR_EXT_A', 'ST_NOTRIG_BR_INT_A'])\n",
    "    else:\n",
    "        iqps_analog_dfs = rqd_query.query_iqps_analog_pm(source_timestamp_qds_rq_df, signal_names=['U_QS0_EXT', 'U_QS0_INT', 'U_1_EXT', 'U_2_EXT', 'U_1_INT', 'U_2_INT'])\n",
    "        iqps_digital_dfs = rqd_query.query_iqps_analog_pm(source_timestamp_qds_rq_df, signal_names=['ST_MAGNET_OK', 'ST_MAGNET_OK_INT', 'ST_NQD0_EXT', 'ST_NQD0_INT'])\n",
Zinur Charifoulline's avatar
Zinur Charifoulline committed
240
    "        \n",
241 242 243 244 245 246 247 248
    "    # nQPS\n",
    "    source_timestamp_nqps_rqd_df = rqd_query.find_source_timestamp_nqps(timestamp_fgc_rqd)\n",
    "    source_timestamp_nqps_rqf_df =  rqf_query.find_source_timestamp_nqps(timestamp_fgc_rqf)\n",
    "\n",
    "    u_nqps_rqd_dfs = rqd_query.query_nqps_voltage_pm(source_timestamp_qds_rq_df)\n",
    "    u_nqps_rqf_dfs = rqf_query.query_nqps_voltage_pm(source_timestamp_qds_rq_df)\n",
    "    \n",
    "    # Results table\n",
249
    "    results_table = rqd_query.create_report_analysis_template(source_timestamp_qds_rq_df, source_timestamp_nqps_rqd_df, min(timestamp_fgc_rqd, timestamp_fgc_rqf), min(timestamp_pic_rqd, timestamp_pic_rqf), '../__init__.py', i_meas_rqd_df, i_meas_rqf_df, HwcSearchModuleMediator.get_user())\n",
250 251
    "\n",
    "    # QH\n",
252
    "    source_timestamp_qh_rq_df = rqd_query.find_source_timestamp_qh(timestamp_fgc_rqd, duration=[(10, 's'), (200, 's')])\n",
253
    "    i_hds_rq_dfs = rqd_query.query_qh_pm(source_timestamp_qh_rq_df, signal_names='I_HDS') \n",
254
    "    u_hds_rq_dfs = rqd_query.query_qh_pm(source_timestamp_qh_rq_df, signal_names='U_HDS') \n",
255
    "    i_hds_rq_ref_dfs = rqd_query.query_qh_pm(source_timestamp_qh_rq_df, signal_names='I_HDS', is_ref=True)\n",
256
    "    u_hds_rq_ref_dfs = rqd_query.query_qh_pm(source_timestamp_qh_rq_df, signal_names='U_HDS', is_ref=True)\n",
257 258
    "\n",
    "    # DIODE LEADS\n",
Michal Maciejewski's avatar
Michal Maciejewski committed
259
    "    i_meas_u_diode_u_ref_rqd_pm_dfs = rqd_query.query_current_voltage_diode_leads_pm(timestamp_fgc_rqd, source_timestamp_qds_rq_df)\n",
260
    "    i_meas_u_diode_rqd_nxcals_dfs = rqd_query.query_current_voltage_diode_leads_nxcals(source_timestamp_qds_rq_df, spark=spark)\n",
261
    "\n",
Michal Maciejewski's avatar
Michal Maciejewski committed
262
    "    i_meas_u_diode_u_ref_rqf_pm_dfs = rqf_query.query_current_voltage_diode_leads_pm(timestamp_fgc_rqf, source_timestamp_qds_rq_df)\n",
263
    "    i_meas_u_diode_rqf_nxcals_dfs = rqf_query.query_current_voltage_diode_leads_nxcals(source_timestamp_qds_rq_df, spark=spark)\n",
264 265 266 267 268 269 270 271 272 273 274
    "\n",
    "    # DFB\n",
    "    source_timestamp_leads_rqd_df = rqd_query.find_timestamp_leads(timestamp_fgc_rqd)\n",
    "    u_hts_rqd_dfs = rqd_query.query_leads(timestamp_fgc_rqd, source_timestamp_leads_rqd_df, signal_names=['U_HTS'], spark=spark)\n",
    "    u_res_rqd_dfs = rqd_query.query_leads(timestamp_fgc_rqd, source_timestamp_leads_rqd_df, signal_names=['U_RES'], spark=spark)\n",
    "\n",
    "    source_timestamp_leads_rqf_df = rqf_query.find_timestamp_leads(timestamp_fgc_rqf)\n",
    "    u_hts_rqf_dfs = rqf_query.query_leads(timestamp_fgc_rqf, source_timestamp_leads_rqf_df, signal_names=['U_HTS'], spark=spark)\n",
    "    u_res_rqf_dfs = rqf_query.query_leads(timestamp_fgc_rqf, source_timestamp_leads_rqf_df, signal_names=['U_RES'], spark=spark)\n",
    "\n",
    "    # U_DIODE\n",
275 276
    "    u_diode_rqd_dfs = rqd_query.query_voltage_nxcals('DIODE_RQD', 'U_DIODE_RQD', timestamp_fgc_rqd, spark=spark)\n",
    "    u_diode_rqf_dfs = rqf_query.query_voltage_nxcals('DIODE_RQF', 'U_DIODE_RQF', timestamp_fgc_rqf, spark=spark)\n",
277 278
    "\n",
    "    # U_EARTH\n",
279 280
    "    u_earth_rqd_dfs = rqd_query.query_voltage_nxcals('VF_RQD', 'U_EARTH_RQD', timestamp_fgc_rqd, spark=spark)\n",
    "    u_earth_rqf_dfs = rqf_query.query_voltage_nxcals('VF_RQF', 'U_EARTH_RQF', timestamp_fgc_rqf, spark=spark)\n",
281 282 283 284 285 286
    "\n",
    "    rq_analysis = RqCircuitAnalysis(circuit_type, results_table, is_automatic=is_automatic)"
   ]
  },
  {
   "cell_type": "markdown",
287 288 289
   "metadata": {
    "deletable": false
   },
290
   "source": [
291 292 293 294 295 296
    "# 3. Circuit Parameters Table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
297 298 299
   "metadata": {
    "deletable": false
   },
300 301 302 303 304 305 306
   "outputs": [],
   "source": [
    "rq_analysis.display_parameters_table(circuit_names[0])"
   ]
  },
  {
   "cell_type": "markdown",
307 308 309
   "metadata": {
    "deletable": false
   },
310 311 312
   "source": [
    "# 4. Timestamps\n",
    "## 4.1. FPA\n",
313 314 315
    "Table below provides timestamps ordered achronologically and represents the sequence of events that occurred in the analyzed circuit: PIC_RQD, PIC_RQF, iQPS, nQPS, FGC_RQD, FGC_RQF, EE_RQD, EE_RQF and optionally LEADS_RQD and LEADS_RQF, provided they exist. Note that for iQPS and nQPS only the first timestamp is reported. Tables with all iQPS and NQPS timestamps are presented in the section dedicated to magnet and quench protection analysis. The table also contains time difference in milliseconds from the first event and from the FGC event.\n",
    "\n",
    "In short, the following criteria should be kept:\n",
Zinur Charifoulline's avatar
Zinur Charifoulline committed
316 317
    "- The PC timestamp (51_self) is QPS time stamp +/-40 ms.\n",
    "- Time stamp delay between PIC and EE: 100±15 ms \n",
318 319 320 321 322 323
    "\n",
    "If one or more of these conditions are not fulfilled, then an in-depth analysis has to be performed by the QPS team."
   ]
  },
  {
   "cell_type": "code",
324
   "execution_count": null,
325 326
   "metadata": {
    "deletable": false,
327
    "scrolled": false
328
   },
329
   "outputs": [],
330 331 332 333 334 335 336 337 338 339 340 341
   "source": [
    "timestamp_dct = {'FGC_RQD': timestamp_fgc_rqd, 'FGC_RQF': timestamp_fgc_rqf, \n",
    "                 'PIC_RQD': timestamp_pic_rqd, 'PIC_RQF': timestamp_pic_rqf,\n",
    "                 'EE_RQD': source_timestamp_ee_rqd_df, 'EE_RQF': source_timestamp_ee_rqf_df,\n",
    "                 'iQPS': source_timestamp_qds_rq_df, 'nQPS': source_timestamp_nqps_rqd_df,\n",
    "                 'LEADS_RQD': source_timestamp_leads_rqd_df, 'LEADS_RQF': source_timestamp_leads_rqf_df}\n",
    "\n",
    "rq_analysis.create_timestamp_table(timestamp_dct)"
   ]
  },
  {
   "cell_type": "markdown",
342 343 344
   "metadata": {
    "deletable": false
   },
345
   "source": [
346
    "## 4.2. Reference\n",
347 348 349 350 351
    "Table below contains reference timestamps of signals used for comparison to the analyzed FPA. The reference comes as the last PNO.b3 HWC test with activation of EE systems and no magnets quenching."
   ]
  },
  {
   "cell_type": "code",
352
   "execution_count": null,
353
   "metadata": {
354
    "deletable": false
355
   },
356
   "outputs": [],
357 358 359 360 361 362 363 364 365
   "source": [
    "timestamp_ref_dct = {'FGC_RQD': timestamp_fgc_ref_rqd, 'FGC_RQF': timestamp_fgc_ref_rqf, \n",
    "                     'EE_RQD_first': source_timestamp_ee_rqd_ref_df.loc[0, 'timestamp'], 'EE_RQD_second': source_timestamp_ee_rqd_ref_df.loc[1, 'timestamp'],\n",
    "                     'EE_RQF_first': source_timestamp_ee_rqd_ref_df.loc[0, 'timestamp'], 'EE_RQF_second': source_timestamp_ee_rqd_ref_df.loc[1, 'timestamp']}\n",
    "rq_analysis.create_ref_timestamp_table(timestamp_ref_dct)"
   ]
  },
  {
   "cell_type": "markdown",
366 367 368
   "metadata": {
    "deletable": false
   },
369
   "source": [
370 371
    "# 5. PIC\n",
    "## 5.1. Analysis of the PIC Timestamp\n",
372 373 374 375 376 377 378
    "\n",
    "*CRITERIA*:\n",
    "- Check iff the the difference between RQD and RQF PIC timestamps is less than 1 ms. If yes, then a warning is displayed."
   ]
  },
  {
   "cell_type": "code",
379
   "execution_count": null,
380 381 382 383
   "metadata": {
    "deletable": false,
    "scrolled": true
   },
384
   "outputs": [],
385 386 387 388 389 390
   "source": [
    "rq_analysis.analyze_pic([timestamp_pic_rqd, timestamp_pic_rqf])"
   ]
  },
  {
   "cell_type": "markdown",
391 392 393
   "metadata": {
    "deletable": false
   },
394
   "source": [
395 396
    "# 6. Power Converter\n",
    "## 6.1. Analysis of the Power Converter Main Current\n",
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
    "This analysis module displays the main current of the power converter (I_MEAS), and for comparison, a reference I_MEAS (PNO.b3).\n",
    "\n",
    "*ANALYSIS*:\n",
    "- The evolution of the characteristic time $\\tau$ of an exponential decay $f(t)$ is obtained as\n",
    "\\begin{equation}\n",
    "-\\frac{f(t)}{\\partial_t f(t)} = -\\frac{f_0 e^{-t/\\tilde{\\tau}}}{\\partial_t (f_0 e^{-t/\\tilde{\\tau}})} = -\\frac{f_0 e^{-t/\\tilde{\\tau}}}{-f_0/\\tilde{\\tau} e^{-t/\\tilde{\\tau}}}=-\\frac{1}{-1/\\tau}=\\tau\n",
    "\\end{equation}\n",
    "Naturally, this formula only applies to exponential decayed characterised by a time constant. Nonetheless, for pseudo-exponential decays, this formula gives a notion of the change of the characteristic time $\\tilde{\\tau}$. For a circuit we compute the time-varying characteristic time as\n",
    "\\begin{equation}\n",
    "\\tilde{\\tau} = \\frac{\\partial \\text{I_MEAS}}{\\partial_t}\n",
    "\\end{equation}\n",
    "\n",
    "*CRITERIA*  \n",
    "- Check if the characteristic time of the pseudo-exponential I_MEAS decay from t=1 to 100 s is 25 s< Tau < 35 s\n",
    "\n",
    "*GRAPHS* (one for each circuit):\n",
    "- The main power converter current (reference and actual) on the left axis, I_MEAS\n",
    "- The characteristic pseudo time constant calculated for the main current (reference and actual) on the right axis, -I_MEAS/dI_MEAS  \n",
    "The actual characteristic pseudo time constant contains discrete steps, which indicate a quenching magnet (decreasing L, increasing R); note that for the reference one the steps are not present (no quench). \n",
    "- Timing of PIC abort, FGC timestamps, the maximum currents, and the characteristic times are reported next to the graph.\n",
    "- t = 0 s corresponds to the respective (actual and reference) FGC timestamps.\n"
   ]
  },
  {
   "cell_type": "code",
422
   "execution_count": null,
423
   "metadata": {
424
    "deletable": false,
425 426
    "scrolled": false
   },
427
   "outputs": [],
428 429
   "source": [
    "%matplotlib notebook\n",
430 431 432 433
    "rq_analysis.analyze_i_meas_pc(circuit_names[0], timestamp_fgc_rqd, timestamp_fgc_ref_rqd, timestamp_pic_rqd, i_meas_rqd_df, i_meas_ref_rqd_df)\n",
    "rq_analysis.calculate_current_miits(i_meas_rqd_df, t_quench=0, col_name='MIITS_RQD')\n",
    "rq_analysis.calculate_quench_current(i_meas_rqd_df, t_quench=0, col_name='I_Q_RQD')\n",
    "rq_analysis.calculate_current_slope(i_meas_rqd_df, col_name=['Ramp rate RQD', 'Plateau duration RQD'])"
434 435 436 437
   ]
  },
  {
   "cell_type": "code",
438
   "execution_count": null,
439 440 441
   "metadata": {
    "deletable": false
   },
442
   "outputs": [],
443 444
   "source": [
    "%matplotlib notebook\n",
445 446 447 448
    "rq_analysis.analyze_i_meas_pc(circuit_names[1], timestamp_fgc_rqf, timestamp_fgc_ref_rqf, timestamp_pic_rqf, i_meas_rqf_df, i_meas_ref_rqf_df)\n",
    "rq_analysis.calculate_current_miits(i_meas_rqf_df, t_quench=0, col_name='MIITS_RQF')\n",
    "rq_analysis.calculate_quench_current(i_meas_rqf_df, t_quench=0, col_name='I_Q_RQF')\n",
    "rq_analysis.calculate_current_slope(i_meas_rqf_df, col_name=['Ramp rate RQF', 'Plateau duration RQF'])"
449 450 451 452
   ]
  },
  {
   "cell_type": "markdown",
453 454 455
   "metadata": {
    "deletable": false
   },
456
   "source": [
457
    "## 6.2. Analysis of the Power Converter Earth Current\n",
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472
    "\n",
    "*GRAPHS (one for each circuit)*:  \n",
    "t = 0 s corresponds to respective (actual and reference) FGC PM timestamps\n",
    "\n",
    "First plot (absolute scale, zoom for t = [-0.1, 0.3])\n",
    "- The main power converter current on the left axis, I_A\n",
    "- Actual and reference earth current on the right axis, IEARTH\n",
    "\n",
    "Second plot (percentage scale, for t > 3 s)\n",
    "- The main power converter current on the left axis, I_MEAS\n",
    "- Actual and reference earth current on the right axis, I_EARTH_PCNT\n"
   ]
  },
  {
   "cell_type": "code",
473
   "execution_count": null,
474 475 476
   "metadata": {
    "deletable": false
   },
477
   "outputs": [],
478 479
   "source": [
    "%matplotlib notebook\n",
480 481
    "rq_analysis.analyze_i_earth_pc(circuit_names[0], timestamp_fgc_rqd, i_a_rqd_df, i_earth_rqd_df, i_earth_rqd_ref_df)\n",
    "rq_analysis.calculate_max_i_earth_pc(i_earth_rqd_df, col_name='I_Earth_max_RQD')"
482 483 484 485
   ]
  },
  {
   "cell_type": "code",
486
   "execution_count": null,
487
   "metadata": {
488
    "deletable": false,
489 490
    "scrolled": false
   },
491
   "outputs": [],
492 493
   "source": [
    "%matplotlib notebook\n",
494 495
    "rq_analysis.analyze_i_earth_pc(circuit_names[1], timestamp_fgc_rqf, i_a_rqf_df, i_earth_rqf_df, i_earth_rqf_ref_df)\n",
    "rq_analysis.calculate_max_i_earth_pc(i_earth_rqf_df, col_name='I_Earth_max_RQF')"
496 497 498 499
   ]
  },
  {
   "cell_type": "code",
500
   "execution_count": null,
501 502 503
   "metadata": {
    "deletable": false
   },
504
   "outputs": [],
505 506 507 508 509 510 511
   "source": [
    "%matplotlib notebook\n",
    "rq_analysis.analyze_i_earth_pcnt_pc(circuit_names[0], timestamp_fgc_rqd, i_meas_rqd_df, i_meas_ref_rqd_df, i_earth_pcnt_rqd_df, i_earth_pcnt_rqd_ref_df)"
   ]
  },
  {
   "cell_type": "code",
512
   "execution_count": null,
513 514 515
   "metadata": {
    "deletable": false
   },
516
   "outputs": [],
517 518 519 520 521 522 523
   "source": [
    "%matplotlib notebook\n",
    "rq_analysis.analyze_i_earth_pcnt_pc(circuit_names[1], timestamp_fgc_rqf, i_meas_rqf_df, i_meas_ref_rqf_df, i_earth_pcnt_rqf_df, i_earth_pcnt_rqf_ref_df)"
   ]
  },
  {
   "cell_type": "markdown",
524 525 526
   "metadata": {
    "deletable": false
   },
527
   "source": [
528 529
    "# 7. Energy Extraction System\n",
    "## 7.1. Analysis of the Energy Extraction Voltage\n",
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550
    "\n",
    "*CRITERIA*:\n",
    "- Check if the characteristic time of the pseudo-exponential U_DUMP_RES decay from t=2 to 100 s is 25 s< Tau < 35 s\n",
    "- Check if the timestamp difference between FGC and EE is 100±15 ms \n",
    "\n",
    "*GRAPHS* (one for each circuit):\n",
    "\n",
    "t = 0 s corresponds to the PM timestamp of the FGC\n",
    "\n",
    "First plot (global view):\n",
    "- the power converter converter current on the left axis, I_MEAS\n",
    "- the two energy extraction voltages on the right, U_DUMP_RES\n",
    "\n",
    "Second plot (triggering view):\n",
    "- the power converter current on the left axis, I_MEAS\n",
    "- the power converter reference current on the left axis, STATUS.I_REF (should stop at the moment of the FGC PM timestamp)\n",
    "- the  energy extraction voltage on the right axis, U_DUMP_RES\n"
   ]
  },
  {
   "cell_type": "code",
551
   "execution_count": null,
552 553 554
   "metadata": {
    "deletable": false
   },
555
   "outputs": [],
556 557
   "source": [
    "%matplotlib notebook\n",
558 559
    "rq_analysis.analyze_char_time_u_dump_res_ee(circuit_names[0], timestamp_fgc_rqd, u_dump_res_rqd_df, i_meas_rqd_df)\n",
    "rq_analysis.results_table['U_EE_max_RQD'] = u_dump_res_rqd_df.max()[0]"
560 561 562 563
   ]
  },
  {
   "cell_type": "code",
564
   "execution_count": null,
565
   "metadata": {
566
    "deletable": false,
567 568
    "scrolled": false
   },
569
   "outputs": [],
570 571
   "source": [
    "%matplotlib notebook\n",
572 573
    "rq_analysis.analyze_char_time_u_dump_res_ee(circuit_names[1], timestamp_fgc_rqf, u_dump_res_rqf_df, i_meas_rqf_df)\n",
    "rq_analysis.results_table['U_EE_max_RQF'] = u_dump_res_rqf_df.max()[0]"
574 575 576 577
   ]
  },
  {
   "cell_type": "code",
578
   "execution_count": null,
579 580 581
   "metadata": {
    "deletable": false
   },
582
   "outputs": [],
583 584 585 586 587 588 589
   "source": [
    "%matplotlib notebook\n",
    "rq_analysis.analyze_delay_time_u_dump_res_ee(circuit_names[0], timestamp_fgc_rqd, timestamp_pic_rqd, timestamp_ee_rqd, i_a_rqd_df, i_ref_rqd_df, u_dump_res_rqd_df)"
   ]
  },
  {
   "cell_type": "code",
590
   "execution_count": null,
591 592 593
   "metadata": {
    "deletable": false
   },
594
   "outputs": [],
595 596 597 598 599
   "source": [
    "%matplotlib notebook\n",
    "rq_analysis.analyze_delay_time_u_dump_res_ee(circuit_names[1], timestamp_fgc_rqf, timestamp_pic_rqf, timestamp_ee_rqf, i_a_rqf_df, i_ref_rqf_df, u_dump_res_rqf_df)"
   ]
  },
600
  {
601
   "cell_type": "markdown",
602 603 604
   "metadata": {
    "deletable": false
   },
605
   "source": [
606 607 608 609 610 611 612 613 614 615
    "## 7.2.  Analysis of the Energy Extraction Temperature\n",
    "\n",
    "*CRITERIA*:\n",
    "- Check if each temperature profile is +/-25 K w.r.t. the reference temperature profile\n",
    "\n",
    "*GRAPHS*:\n",
    "\n",
    "- Temperature signals on the left axis, T\n",
    "- A reference signal with an acceptable signal range is also presented on the left axis\n",
    "- t = 0 s corresponds to PM timestamps of each temperature PM entry"
616 617 618 619 620
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
621 622 623
   "metadata": {
    "deletable": false
   },
624 625
   "outputs": [],
   "source": [
626 627
    "%matplotlib notebook\n",
    "rq_analysis.analyze_ee_temp(circuit_names[0], timestamp_ee_rqd, [t_res_0_rqd_df, t_res_1_rqd_df], [t_res_0_rqd_ref_df, t_res_1_rqd_ref_df], abs_margin=25, scaling=1)"
628 629
   ]
  },
630
  {
631 632
   "cell_type": "code",
   "execution_count": null,
633 634 635
   "metadata": {
    "deletable": false
   },
636
   "outputs": [],
637
   "source": [
638 639
    "%matplotlib notebook\n",
    "rq_analysis.analyze_ee_temp(circuit_names[1], timestamp_ee_rqf, [t_res_0_rqf_df, t_res_1_rqf_df], [t_res_0_rqf_ref_df, t_res_1_rqf_ref_df], abs_margin=25, scaling=1)"
640 641 642 643
   ]
  },
  {
   "cell_type": "code",
644
   "execution_count": null,
645 646 647
   "metadata": {
    "deletable": false
   },
648
   "outputs": [],
649
   "source": [
650 651
    "if not is_automatic:\n",
    "    rq_analysis.results_table['EE analysis RQD'] = input('EE analysis RQD comment: ')"
652 653 654 655
   ]
  },
  {
   "cell_type": "code",
656
   "execution_count": null,
657 658 659
   "metadata": {
    "deletable": false
   },
660
   "outputs": [],
661
   "source": [
662 663
    "if not is_automatic:\n",
    "    rq_analysis.results_table['EE analysis RQF'] = input('EE analysis RQF comment: ')"
664 665 666 667
   ]
  },
  {
   "cell_type": "markdown",
668 669 670
   "metadata": {
    "deletable": false
   },
671
   "source": [
672
    "# 8. Quench Protection System\n",
673 674 675 676 677 678 679
    "<img src=\"https://gitlab.cern.ch/LHCData/lhc-sm-hwc/raw/master/figures/rq/RQ_QPS_Signals.png\" width=75%>\n",
    "\n",
    "source: Test Procedure and Acceptance Criteria for the 13 kA Quadrupole (RQD-RQF) Circuits, MP3 Procedure, <a href=\"https://edms.cern.ch/document/874714/5.1\">https://edms.cern.ch/document/874714/5.1</a>"
   ]
  },
  {
   "cell_type": "markdown",
680 681 682
   "metadata": {
    "deletable": false
   },
683
   "source": [
684
    "## 8.1. Plot of Voltage Across All Magnets (U_DIODE_RQx)\n",
685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700
    "\n",
    "*GRAPHS* (one for each circuit):  \n",
    "\n",
    "t = 0 s corresponds to the PM timestamp of the FGC\n",
    "\n",
    "First plot  (global)\n",
    "- the power converter current on the left axis, I_MEAS\n",
    "- diode voltage on the right axis, U_DIODE_RQx\n",
    "\n",
    "Second plot (zoom)\n",
    "- the power converter current on the left axis, I_MEAS\n",
    "- diode voltage on the right axis, U_DIODE_RQx\n"
   ]
  },
  {
   "cell_type": "code",
701
   "execution_count": null,
702
   "metadata": {
703
    "deletable": false,
704 705
    "scrolled": false
   },
706
   "outputs": [],
707
   "source": [
708 709
    "%matplotlib notebook\n",
    "rq_analysis.analyze_u_diode_nqps(circuit_names[0], timestamp_fgc_rqd, i_meas_rqd_df, u_diode_rqd_dfs, 'U_DIODE_RQD', system='DIODE_RQD')"
710 711 712 713
   ]
  },
  {
   "cell_type": "code",
714
   "execution_count": null,
715 716 717
   "metadata": {
    "deletable": false
   },
718
   "outputs": [],
719
   "source": [
720 721
    "%matplotlib notebook\n",
    "rq_analysis.analyze_u_diode_nqps(circuit_names[1], timestamp_fgc_rqf, i_meas_rqf_df, u_diode_rqf_dfs, 'U_DIODE_RQF', system='DIODE_RQF')"
722 723 724 725
   ]
  },
  {
   "cell_type": "markdown",
726 727 728
   "metadata": {
    "deletable": false
   },
729
   "source": [
730
    "## 8.2. Analysis of Quenched Magnets by QDS - PM\n",
731 732 733 734 735 736 737 738 739 740 741 742
    "\n",
    "*QUERY*:\n",
    "\n",
    "- PM for quench detection signals for 1 s before and 400 s after the FGC PM timestamp; if a quench detection signal is present, it means that a magnet quenched. Since there are two QPS boards (so called boards A and B), there are twice as many PM entries as quenched magnets.\n",
    "\n",
    "*ANALYSIS*:\n",
    "- calculates the current at which a quench occured by finding the timestamp of the current dataframe (i_meas_df) closest to the quench time and the curresponding value of current\n",
    "- compute the time difference (in seconds) from the first quench - dt_quench"
   ]
  },
  {
   "cell_type": "code",
743
   "execution_count": null,
744 745 746
   "metadata": {
    "deletable": false
   },
747
   "outputs": [],
748
   "source": [
749
    "rq_analysis.results_table[['Circuit Name', 'Position', 'Date (FGC)', 'Time (FGC)', 'I_Q_MQD', 'I_Q_MQF']]"
750 751 752 753
   ]
  },
  {
   "cell_type": "markdown",
754 755 756
   "metadata": {
    "deletable": false
   },
757
   "source": [
758
    "## 8.3. Analysis of Quench Detection Voltage and Logic Signals for Quenched Magnets\n",
759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796
    "\n",
    "If a quadrupole magnet naturally quenches the QPS system (old or iQPS) records a PM file. This file containts the data from the two quench detectors for RQD and RQF (called INT and EXT). The aperture which quenches first defines the common PM time stamp. The PM data is however recorded by two individual boards. Since there is only one common heater circuit for both apertures, the non-quenching aperture will also be warmed up by the heaters and will quench. This heater induced quench which comes some time after the primary quench which triggered the PM is recorded by its quench detector when it is reaching the 100mV. Since the system has only one absolute time stamp (the one of the primary quench) the secondary, heater induced, quench appears in the PM at the same time as the primary quench despite the fact that it happens later in time. This behaviour is a feature of the system which is foreseen to be fixed in LS2 with the new quadrupole quench detection system.\n",
    "In the following analysis one can see the typical shape of U_QS0 signals (up to LS2). Both reach 100 mV at the same time due to the synchronisation of the data. The non-quenching aperture typically has a spike some 40 ms earlier (due to QH firing) and a faster voltage rise (due to QH induced quench). The quenching aperture has a typical 5-6 V/s slope at nominal current.\n",
    "\n",
    "*ANALYSIS*:\n",
    "Determine aperture with a quenched magnet\n",
    "1. Find a diode signal which is the first to reach 1 V\n",
    "2. Take a circuit name (RQD/RQF) from the diode signal name\n",
    "3. With the circuit name and the magnet name, get the aperture (INT/EXT)\n",
    "4. With the aperture name, choose an appropriate U_QS0 signal and use for du_dt calculation\n",
    "- if |U_QS0| $\\geq$ 100 mV, then find the start time of a quench, t_start_quench, as the moment at which |U_QS0| is 10 mV greater than its initial value. Otherwise, the start time of a quench is set to 0 s\n",
    "- Find U_QS0 value, u_start_quench, at the moment of quench start as u_start_quench = U_QS0(t=t_start_quench)\n",
    "- The slope of the quench detection signals is calculated as du_dt = (u_ST_NQD0 - u_start_quench) / (t_st_nqd0 - t_start_quench)\n",
    "\n",
    "*GRAPHS*:\n",
    "\n",
    "t = 0 s corresponds to the PM timestamp of the QDS\n",
    "\n",
    "Upper left  (iQPS analog signals)\n",
    "- the quench detection voltage on the left axis, U_QS0_INT, U_QS0_EXT\n",
    "- the green box denotes an envelope of the +/- 100 mV quench detection threshold\n",
    "- the orange box denotes an envelope of the rise of the quench signal from its start until reaching the threshold\n",
    "\n",
    "Lower left  (iQPS digital signals)\n",
    "- the quench detection voltage on the left axis, ST_MAGNET_OK, ST_MAGNET_OK_INT, ST_NQD0_INT, ST_NQD0_EXT\n",
    "\n",
    "Upper right (nQPS analog signals)  \n",
    "\n",
    "For PM signals (raw view)\n",
    "- the diode voltages used by the nQPS crate for quench detection on the left axis, U_DIODE_RQx and U_REF_N1 \n",
    "\n",
    "Lower right (nQPS analog signals)  \n",
    "For PM signals  (zoomed view) \n",
    "- the diode voltages used by the nQPS crate for quench detection on the left axis, U_DIODE_RQx and U_REF_N1 \n"
   ]
  },
  {
   "cell_type": "code",
797
   "execution_count": null,
798
   "metadata": {
Zinur Charifoulline's avatar
Zinur Charifoulline committed
799
    "deletable": false
800
   },
801
   "outputs": [],
802 803
   "source": [
    "%matplotlib inline\n",
804
    "if Time.to_unix_timestamp(timestamp_fgc_rqd) > 1577833200000000000:\n",
Zinur Charifoulline's avatar
Zinur Charifoulline committed
805
    "    rq_analysis.analyze_qds_run3(source_timestamp_qds_rq_df, circuit_names, iqps_analog_dfs, iqps_digital_dfs, u_nqps_rqd_dfs, u_nqps_rqf_dfs)\n",
806 807
    "else:\n",
    "    rq_analysis.analyze_qds(source_timestamp_qds_rq_df, circuit_names, iqps_analog_dfs, iqps_digital_dfs, u_nqps_rqd_dfs, u_nqps_rqf_dfs)\n",
808
    "\n",
809
    "rq_analysis.results_table[['Circuit Name', 'Position', 'Delta_t(iQPS-PIC)','I_Q_RQD', 'I_Q_RQF', 'Delta_t(nQPS_RQD-PIC)', 'QDS trigger origin', 'dU_iQPS/dt_RQD', 'dU_iQPS/dt_RQF']]"
810 811 812 813
   ]
  },
  {
   "cell_type": "markdown",
814 815 816
   "metadata": {
    "deletable": false
   },
817
   "source": [
818
    "## 8.4. Analysis of Quench Heater Discharges\n",
819 820 821 822 823 824 825 826 827 828 829 830 831
    "\n",
    "*CRITERIA*:\n",
    "- check if all characteristic times of the pseudo-exponential voltage decays calculated with the 'charge' approach is +/- 3 ms from the reference ones\n",
    "- check if the initial voltage should be between 810 V and 1020 V\n",
    "- check if the final voltage should be between 0 V and 10 V\n",
    "\n",
    "*GRAPHS*:  \n",
    "- the queried and filtered quench heater voltage on the left axis (actual signal continuous, reference dashed), U_HDS\n",
    "- t = 0 s corresponds to the start of the pseudo-exponential decay\n"
   ]
  },
  {
   "cell_type": "code",
832
   "execution_count": null,
833
   "metadata": {
834
    "deletable": false,
835 836
    "scrolled": false
   },
837
   "outputs": [],
838 839
   "source": [
    "%matplotlib inline\n",
840 841
    "if u_hds_rq_dfs:\n",
    "    if Time.to_unix_timestamp(timestamp_fgc_rqd) > 1577833200000000000:\n",
842
    "        rq_analysis.analyze_multi_qh_voltage_current_with_ref(source_timestamp_qh_rq_df, u_hds_rq_dfs, i_hds_rq_dfs, u_hds_rq_ref_dfs, i_hds_rq_ref_dfs, current_offset=0.085)\n",
843 844
    "    else:\n",
    "        rq_analysis.analyze_single_qh_voltage_with_ref(source_timestamp_qds_rq_df, circuit_type, u_hds_rq_dfs, u_hds_rq_ref_dfs)\n",
845
    "\n",
846 847 848
    "    rq_analysis.results_table[['Circuit Name', 'Position', 'Date (FGC)', 'Time (FGC)', 'I_Q_MQD', 'I_Q_MQF', 'QH analysis']]\n",
    "else:\n",
    "    print(f\"No Quench Heater Discharges!\")"
849 850 851 852
   ]
  },
  {
   "cell_type": "markdown",
853 854 855
   "metadata": {
    "deletable": false
   },
856
   "source": [
857
    "## 8.5. Analysis of Diode Lead Resistance\n",
858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891
    "\n",
    "*ANALYSIS*:\n",
    "- calculate diode lead resistance\n",
    "\n",
    "*CRITERIA*\n",
    "- Check if the maximum resistance is above 50 uOhm. If yes, then raise a warning.\n",
    "- Check if the maximum resistance is above 150 uOhm. If yes, then raise an alarm.\n",
    "\n",
    "*GRAPHS*:  \n",
    "\n",
    "t = 0 s corresponds to the PM timestamp of the FGC\n",
    "\n",
    "Upper PM (Input view)  \n",
    "- the main power converter current on the left axis, IAB.I_A\n",
    "- quenched magnet voltage from two boards, U_DIODE_A, U_DIODE_B. The difference between both signals is the diode lead voltage.\n",
    "- reference nQPS board voltage on the right axis, U_REF\n",
    "- diplayed on the left only if a quench occured no later than 2 seconds after the FGC PM timestamp\n",
    "\n",
    "Lower PM (Output view)  \n",
    "- the main power converter current on the left axis, IAB.I_A\n",
    "- the calculated diode lead resistance on the right axis, R_DIODE_LEADS\n",
    "- diplayed on the left only if a quench occured no later than 2 seconds after the FGC PM timestamp\n",
    "\n",
    "Upper CALS (Input view)  \n",
    "- the main power converter current on the left axis, I_MEAS\n",
    "- quenched magnet voltage from two boards is saved as a single signal, U_DIODE_RQx. The two signals are stored by means of value toggling between board A and board B. The difference between both sub-signals is the diode lead voltage.\n",
    "\n",
    "Lower CALS (Output view)  \n",
    "- the main power converter current on the left axis, I_MEAS\n",
    "- the calculated diode lead resistance on the right axis, R_DIODE_LEADS"
   ]
  },
  {
   "cell_type": "code",
892
   "execution_count": null,
893 894 895
   "metadata": {
    "deletable": false
   },
896
   "outputs": [],
897 898
   "source": [
    "%matplotlib inline\n",
899 900
    "if i_meas_u_diode_u_ref_rqd_pm_dfs:\n",
    "    rq_analysis.analyze_diode_leads(source_timestamp_qds_rq_df, timestamp_fgc_rqd, results_table['I_Q_MQD'], circuit_names[0], i_meas_u_diode_u_ref_rqd_pm_dfs, i_meas_u_diode_rqd_nxcals_dfs)"
901 902 903 904
   ]
  },
  {
   "cell_type": "code",
905
   "execution_count": null,
906 907 908
   "metadata": {
    "deletable": false
   },
909
   "outputs": [],
910 911
   "source": [
    "%matplotlib inline\n",
912 913
    "if i_meas_u_diode_u_ref_rqf_pm_dfs:\n",
    "    rq_analysis.analyze_diode_leads(source_timestamp_qds_rq_df, timestamp_fgc_rqf, results_table['I_Q_MQF'], circuit_names[1], i_meas_u_diode_u_ref_rqf_pm_dfs, i_meas_u_diode_rqf_nxcals_dfs)"
914 915 916 917
   ]
  },
  {
   "cell_type": "code",
918
   "execution_count": null,
919 920 921 922
   "metadata": {
    "deletable": false,
    "scrolled": false
   },
923
   "outputs": [],
924
   "source": [
925
    "rq_analysis.results_table[['Circuit Name', 'Position', 'Date (FGC)', 'Time (FGC)', 'I_Q_MQD', 'I_Q_MQF', 'R_DL_max_RQD', 'R_DL_max_RQF', 'I_RQD at R_DL_max_RQD', 'I_RQF at R_DL_max_RQF']]"
926 927 928 929
   ]
  },
  {
   "cell_type": "markdown",
930 931 932
   "metadata": {
    "deletable": false
   },
933
   "source": [
934
    "## 8.6. Plot of Voltage Feelers\n",
935 936 937 938 939 940 941 942 943 944 945 946 947
    "\n",
    "\n",
    "*ANALYSIS*:\n",
    "- Check if the voltage of a voltage feeler is equal to 0 V. If yes, then it means that the corresponding card is disabled.\n",
    "- Check if the voltage of a voltage feeler is equal to -2000 V. If yes, then it means that the corresponding card is not communicating.\n",
    "\n",
    "*GRAPHS* (one for each circuit):  \n",
    "\n",
    "- t = 0 s corresponds to the PM timestamp of the FGC\n"
   ]
  },
  {
   "cell_type": "code",
948
   "execution_count": null,
949
   "metadata": {
950
    "deletable": false,
951 952
    "scrolled": false
   },
953
   "outputs": [],
954
   "source": [
955 956
    "%matplotlib inline\n",
    "rq_analysis.analyze_voltage_feelers(circuit_names[0], timestamp_fgc_rqd, i_meas_rqd_df, u_earth_rqd_dfs, 'U_EARTH_RQD', system='VF_RQD', xlim=(-5, 150), ylim=(-50, 100))"
957 958 959 960
   ]
  },
  {
   "cell_type": "code",
961
   "execution_count": null,
962
   "metadata": {
963
    "deletable": false,
964 965
    "scrolled": false
   },
966
   "outputs": [],
967
   "source": [
968 969
    "%matplotlib inline\n",
    "rq_analysis.analyze_voltage_feelers(circuit_names[1], timestamp_fgc_rqf, i_meas_rqf_df, u_earth_rqf_dfs, 'U_EARTH_RQF', system='VF_RQF', xlim=(-5, 150), ylim=(-50, 100))"
970 971 972 973
   ]
  },
  {
   "cell_type": "markdown",
974 975 976
   "metadata": {
    "deletable": false
   },
977
   "source": [
978
    "## 8.7. Current Leads\n",
979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994
    "\n",
    "Note that **rq** in the table above denotes both RQD and RQF, i.e., there are two signals of each circuit.\n",
    "\n",
    "*CRITERIA*:\n",
    "\n",
    "- Check if the quench detection signal for U_HTS is below the threshold (3 mV)\n",
    "- Check if the quench detection signal for U_RES is below the threshold (100 mV)\n",
    "\n",
    "*GRAPHS*:  \n",
    "\n",
    "- t = 0 s corresponds to the FGC timestamp\n",
    "- dasheded lines, on the U_HTS graph with zoom, represent the EE timestamps"
   ]
  },
  {
   "cell_type": "code",
995
   "execution_count": null,
996
   "metadata": {
997
    "deletable": false,
998 999
    "scrolled": false
   },
1000
   "outputs": [],
1001 1002
   "source": [
    "%matplotlib inline\n",
1003
    "rq_analysis.analyze_leads_voltage(u_hts_rqd_dfs+u_hts_rqf_dfs, circuit_names[0], timestamp_fgc_rqd, signal='U_HTS', value_min=-0.001, value_max=0.001)"
1004 1005 1006 1007
   ]
  },
  {
   "cell_type": "code",
1008
   "execution_count": null,
1009
   "metadata": {
1010
    "deletable": false,
1011 1012
    "scrolled": false
   },
1013
   "outputs": [],
1014 1015 1016 1017 1018 1019 1020
   "source": [
    "%matplotlib inline\n",
    "rq_analysis.plot_leads_voltage_zoom(u_hts_rqd_dfs+u_hts_rqf_dfs, circuit_names[0], timestamp_fgc_rqd, timestamp_ee_rqd, timestamp_ee_rqf, timestamp_ee_rqd, signal='U_HTS')"
   ]
  },
  {
   "cell_type": "code",
1021
   "execution_count": null,
1022 1023 1024
   "metadata": {
    "deletable": false
   },
1025
   "outputs": [],
1026 1027 1028 1029 1030
   "source": [
    "%matplotlib inline\n",
    "rq_analysis.analyze_leads_voltage(u_res_rqd_dfs+u_res_rqf_dfs, circuit_names[0], timestamp_fgc_rqd, signal='U_RES', value_min=-0.1, value_max=0.1)"
   ]
  },
1031 1032 1033
  {
   "cell_type": "code",
   "execution_count": null,
1034 1035 1036
   "metadata": {
    "deletable": false
   },
1037 1038
   "outputs": [],
   "source": [
1039
    "rq_analysis.results_table['FPA Reason'] = get_expert_decision('Reason for FPA: ', ['Heater provoked', 'QPS trip', 'Converter trip', 'EE spurious opening', 'Spurious heater firing', 'Busbar quench', 'Magnet quench', 'HTS current lead quench' ,'RES current lead overvoltage', 'No quench', 'Unknown'])\n",
1040 1041 1042
    "rq_analysis.results_table['QDS trigger origin'] = get_expert_decision('QDS trigger origin: ', ['QPS', 'HTS current lead', 'RES current lead','Busbar', 'No quench'])"
   ]
  },
1043 1044
  {
   "cell_type": "markdown",
1045 1046 1047
   "metadata": {
    "deletable": false
   },
1048
   "source": [
1049
    "# 9. Signature Decision"
1050 1051 1052 1053
   ]
  },
  {
   "cell_type": "code",
1054
   "execution_count": null,
1055 1056 1057
   "metadata": {
    "deletable": false
   },
1058
   "outputs": [],
1059 1060 1061 1062 1063 1064
   "source": [
    "signature = get_expert_decision('Expert Signature Decision: ', ['PASSED', 'FAILED'])"
   ]
  },
  {
   "cell_type": "markdown",
1065 1066 1067
   "metadata": {
    "deletable": false
   },
1068
   "source": [
1069
    "# 10. Final Report"
1070 1071 1072 1073
   ]
  },
  {
   "cell_type": "code",
1074
   "execution_count": null,
1075
   "metadata": {
1076
    "deletable": false,
1077 1078
    "scrolled": false
   },
1079
   "outputs": [],
1080 1081 1082
   "source": [
    "pd.set_option('display.max_columns', None)\n",
    "pd.set_option('display.max_rows', None)\n",
1083
    "analysis_start_time = Time.get_analysis_start_time()\n",
1084
    "date_time_fgc = Time.to_datetime(timestamp_fgc_rqd).strftime(\"%Y-%m-%d-%Hh%M\")\n",
1085
    "circuit_name = rq_analysis.results_table.at[0, 'Circuit Name']\n",
1086 1087 1088
    "!mkdir -p /eos/project/m/mp3/RQ/$circuit_name/$hwc_test\n",
    "file_name = \"{}_FPA-{}-{}_{}\".format(circuit_name, date_time_fgc, analysis_start_time, signature)\n",
    "full_path = '/eos/project/m/mp3/RQ/{}/{}/{}.csv'.format(circuit_name, hwc_test, file_name)\n",
1089
    "mp3_results_table = rq_analysis.create_mp3_results_table(min(timestamp_pic_rqd, timestamp_pic_rqf), min(timestamp_fgc_rqd, timestamp_fgc_rqf))\n",