AN_600A_RCBXHV_FPA.ipynb 29 KB
Newer Older
1
2
3
4
{
 "cells": [
  {
   "cell_type": "markdown",
5
6
7
   "metadata": {
    "deletable": false
   },
8
   "source": [
9
    "<h1><center>Analysis of an FPA in an 600A Circuit - RCBX Family</center></h1>\n",
10
    "\n",
11
    "Figure below shows a generic circuit diagram, equipped with EE and parallel resistor, as well as lead resistances and a quench resistance.\n",
12
    "\n",
13
    "<img src=\"https://gitlab.cern.ch/LHCData/lhc-sm-hwc/-/raw/master/figures/600A/600A_without_EE.png\" width=75%>\n",
14
    "source: Test Procedure and Acceptance Criteria for the 600 A Circuits, MP3 Procedure, <a href=\"https://edms.cern.ch/document/874716\">https://edms.cern.ch/document/874716</a>"
15
16
17
18
   ]
  },
  {
   "cell_type": "markdown",
19
20
21
   "metadata": {
    "deletable": false
   },
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
   "source": [
    "# Analysis Assumptions\n",
    "- We consider standard analysis scenarios, i.e., all signals can be queried. Depending on what 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 an 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 the square bracket, 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",
    "- Title contains timestamp, circuit name, signal name allowing for re-access the signal.\n",
    "- The plots assigned to the left scale got 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, change color of the label to match the signal's color. Otherwise, the label color is black.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
41
42
43
   "metadata": {
    "deletable": false
   },
44
   "source": [
45
    "# 0. Initialise Working Environment"
46
47
48
49
   ]
  },
  {
   "cell_type": "code",
thbuffet's avatar
thbuffet committed
50
   "execution_count": null,
51
   "metadata": {
52
    "deletable": false,
53
    "scrolled": true
54
   },
thbuffet's avatar
thbuffet committed
55
   "outputs": [],
56
57
   "source": [
    "# External libraries\n",
58
59
60
61
    "print('Loading (1/16)'); import pandas as pd\n",
    "print('Loading (2/16)'); import numpy as np\n",
    "print('Loading (3/16)'); import sys\n",
    "print('Loading (4/16)'); from IPython.display import display, Javascript, clear_output, HTML\n",
62
63
    "\n",
    "# Internal libraries\n",
64
65
66
67
68
69
70
71
72
73
74
75
    "print('Loading (5/16)'); import lhcsmapi\n",
    "print('Loading (6/16)'); from lhcsmapi.Time import Time\n",
    "print('Loading (7/16)'); from lhcsmapi.Timer import Timer\n",
    "print('Loading (8/16)'); from lhcsmapi.analysis.R600ACircuitQuery import R600ACircuitQuery\n",
    "print('Loading (9/16)'); from lhcsmapi.analysis.R600ACircuitAnalysis import R600ACircuitAnalysis\n",
    "print('Loading (10/16)'); from lhcsmapi.analysis.expert_input import get_expert_decision\n",
    "print('Loading (11/16)'); from lhcsmapi.analysis.report_template import apply_report_template\n",
    "print('Loading (12/16)'); from lhcsmapi.gui.DateTimeBaseModule import DateTimeBaseModule\n",
    "print('Loading (13/16)'); from lhcsmapi.gui.pc.FgcPmSearchModuleMediator import FgcPmSearchModuleMediator\n",
    "print('Loading (14/16)'); from lhcsmapi.metadata.SignalMetadata import SignalMetadata\n",
    "print('Loading (15/16)'); from lhcsmnb.parameters import are_all_parameters_injected, NbType\n",
    "print('Loading (16/16)'); import lhcsmnb.utils\n",
76
77
78
79
    "\n",
    "clear_output()\n",
    "lhcsmapi.get_lhcsmapi_version()\n",
    "lhcsmapi.get_lhcsmhwc_version('../__init__.py')"
Michal Maciejewski's avatar
Michal Maciejewski committed
80
81
   ]
  },
82
83
  {
   "cell_type": "markdown",
84
85
86
   "metadata": {
    "deletable": false
   },
87
88
89
90
   "source": [
    "# 1. Select FGC Post Mortem Entry"
   ]
  },
91
92
93
94
95
96
97
98
99
100
101
102
103
  {
   "cell_type": "markdown",
   "metadata": {
    "tags": [
     "skip_cell"
    ]
   },
   "source": [
    "In order to perform the analysis of a FPA in an RCD/O 600A circuit please:\n",
    "1. Select circuit name (e.g., RC.A12B1)\n",
    "2. Choose start and end time\n",
    "3. Choose analysis mode (Automatic by default)\n",
    "\n",
104
105
106
    "Once these inputs are provided, click 'Find FGC PM entries' button. This will trigger a search of the PM database in order to provide a list of timestamps of FGC events associated with the selected circuit name for the provided period of time. Select one timestamp from the 'FGC PM Entries' list to be processed by the following cells.\n",
    "\n",
    "**Note that 24 hours is the maximum duration of a single PM query for an event. To avoid delays in querying events, please restrict your query duration as much as possible.**"
107
108
   ]
  },
109
110
  {
   "cell_type": "code",
thbuffet's avatar
thbuffet committed
111
   "execution_count": null,
112
   "metadata": {
113
    "deletable": false,
Aleksandra Mnich's avatar
Aleksandra Mnich committed
114
115
116
    "tags": [
     "parameters"
    ]
117
   },
thbuffet's avatar
thbuffet committed
118
   "outputs": [],
119
   "source": [
120
    "fgc_pm_search = FgcPmSearchModuleMediator(DateTimeBaseModule(start_date_time='2021-01-26 00:00:00+01:00',\n",
121
    "                                                             end_date_time='2021-01-31 00:00:00+01:00'), circuit_type='600A_RCBXHV')"
122
123
   ]
  },
124
125
126
127
128
129
130
131
132
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 2. Query All Signals Prior to Analysis"
   ]
  },
  {
   "cell_type": "code",
thbuffet's avatar
thbuffet committed
133
   "execution_count": null,
134
   "metadata": {
135
    "deletable": false,
136
137
138
139
    "tags": [
     "skip_output"
    ]
   },
thbuffet's avatar
thbuffet committed
140
   "outputs": [],
141
   "source": [
Michal Maciejewski's avatar
Michal Maciejewski committed
142
    "with Timer():\n",
143
    "    if not are_all_parameters_injected(NbType.FGC2, locals()):\n",
Aleksandra Mnich's avatar
Aleksandra Mnich committed
144
145
146
147
    "        author = fgc_pm_search.get_author()\n",
    "        is_automatic = fgc_pm_search.is_automatic_mode()\n",
    "        circuit_type = '600A'\n",
    "        circuit_names = fgc_pm_search.get_fgc_circuit()\n",
148
    "        timestamps_fgc = fgc_pm_search.get_fgc_timestamp()\n",
Aleksandra Mnich's avatar
Aleksandra Mnich committed
149
    "    \n",
150
    "    timestamp_fgc_rcbxh, timestamp_fgc_rcbxv = timestamps_fgc\n",
151
    "    \n",
152
153
    "    query_rcbxh = R600ACircuitQuery(circuit_type, circuit_names[0], max_executions=9)\n",
    "    query_rcbxv = R600ACircuitQuery(circuit_type, circuit_names[1], max_executions=9)\n",
Michal Maciejewski's avatar
Michal Maciejewski committed
154
155
    "\n",
    "    # RCBXH\n",
156
    "    i_meas_rcbxh_df, i_a_rcbxh_df, i_ref_rcbxh_df, i_earth_rcbxh_df = query_rcbxh.query_pc_pm(timestamp_fgc_rcbxh, timestamp_fgc_rcbxh, signal_names=['I_MEAS', 'I_A', 'I_REF', 'I_EARTH'])\n",
Michal Maciejewski's avatar
Michal Maciejewski committed
157
158
    "    events_action_rcbxh_df, events_symbol_rcbxh_df = query_rcbxh.query_pc_pm_events(timestamp_fgc_rcbxh, signal_names=['ACTION', 'SYMBOL'])\n",
    "    # RCBXV\n",
159
    "    i_meas_rcbxv_df, i_a_rcbxv_df, i_ref_rcbxv_df, i_earth_rcbxv_df = query_rcbxv.query_pc_pm(timestamp_fgc_rcbxv, timestamp_fgc_rcbxv, signal_names=['I_MEAS', 'I_A', 'I_REF', 'I_EARTH'])\n",
Michal Maciejewski's avatar
Michal Maciejewski committed
160
161
162
163
164
165
166
167
168
169
    "    events_action_rcbxv_df, events_symbol_rcbxv_df = query_rcbxv.query_pc_pm_events(timestamp_fgc_rcbxv, signal_names=['ACTION', 'SYMBOL'])\n",
    "\n",
    "    # PIC\n",
    "    # # RCBXH\n",
    "    timestamp_pic_rcbxh = query_rcbxh.find_timestamp_pic(timestamp_fgc_rcbxh, spark=spark)\n",
    "    # # RCBXV\n",
    "    timestamp_pic_rcbxv = query_rcbxv.find_timestamp_pic(timestamp_fgc_rcbxv, spark=spark)\n",
    "\n",
    "    # QDS NXCALS - To check if there was any drift of QDS cards prior to the trigger\n",
    "    # # RCBXH\n",
170
    "    i_meas_nxcals_rcbxh_df = query_rcbxh.query_pc_nxcals(timestamp_fgc_rcbxh, signal_names=['I_MEAS'], spark=spark)[0]\n",
Michal Maciejewski's avatar
Michal Maciejewski committed
171
172
    "    u_res_nxcals_rcbxh_df = query_rcbxh.query_iqps_nxcals(timestamp_fgc_rcbxh, signal_names=['U_RES'], spark=spark)[0]\n",
    "    # # RCBXV\n",
173
    "    i_meas_nxcals_rcbxv_df = query_rcbxv.query_pc_nxcals(timestamp_fgc_rcbxv, signal_names=['I_MEAS'], spark=spark)[0]\n",
Michal Maciejewski's avatar
Michal Maciejewski committed
174
175
176
177
    "    u_res_nxcals_rcbxv_df = query_rcbxv.query_iqps_nxcals(timestamp_fgc_rcbxv, signal_names=['U_RES'], spark=spark)[0]\n",
    "\n",
    "    # QDS PM\n",
    "    # # RCBXH\n",
178
    "    source_timestamp_qds_rcbxh_df = query_rcbxh.find_source_timestamp_qds_board_ab(timestamp_fgc_rcbxh, duration=[(2, 's'), (2, 's')])\n",
179
    "    timestamp_qds_rcbxh = lhcsmnb.utils.get_at(source_timestamp_qds_rcbxh_df, 0, 'timestamp', default=np.nan)\n",
180
    "    i_dcct_rcbxh_df, i_didt_rcbxh_df, u_res_rcbxh_df, u_diff_rcbxh_df = query_rcbxh.query_qds_pm(timestamp_qds_rcbxh, timestamp_qds_rcbxh, signal_names=['I_DCCT', 'I_DIDT', 'U_RES', 'U_DIFF'])\n",
Michal Maciejewski's avatar
Michal Maciejewski committed
181
    "    # # RCBXV\n",
182
    "    source_timestamp_qds_rcbxv_df = query_rcbxv.find_source_timestamp_qds_board_ab(timestamp_fgc_rcbxv, duration=[(2, 's'), (2, 's')])\n",
183
    "    timestamp_qds_rcbxv = lhcsmnb.utils.get_at(source_timestamp_qds_rcbxv_df, 0, 'timestamp', default=np.nan)\n",
184
    "    i_dcct_rcbxv_df, i_didt_rcbxv_df, u_res_rcbxv_df, u_diff_rcbxv_df = query_rcbxv.query_qds_pm(timestamp_qds_rcbxv, timestamp_qds_rcbxv, signal_names=['I_DCCT', 'I_DIDT', 'U_RES', 'U_DIFF'])\n",
Michal Maciejewski's avatar
Michal Maciejewski committed
185
186
187
188
189
    "    # LEADS\n",
    "    # # RCBXH\n",
    "    leads_name = [x for x in SignalMetadata.get_system_types_per_circuit_name(circuit_type, circuit_names[0]) if 'LEADS' in x][0]\n",
    "    source_timestamp_leads_rcbxh_df = query_rcbxh.find_timestamp_leads(timestamp_fgc_rcbxh, leads_name)\n",
    "\n",
190
191
    "    u_hts_leads_rcbxh_dfs = query_rcbxh.query_leads(timestamp_fgc_rcbxh, source_timestamp_leads_rcbxh_df, system=leads_name, signal_names=['U_HTS'], spark=spark, duration=[(300, 's'), (900, 's')])\n",
    "    u_res_leads_rcbxh_dfs = query_rcbxh.query_leads(timestamp_fgc_rcbxh, source_timestamp_leads_rcbxh_df, system=leads_name, signal_names=['U_RES'], spark=spark, duration=[(300, 's'), (900, 's')])\n",
Michal Maciejewski's avatar
Michal Maciejewski committed
192
193
194
195
196
    "\n",
    "    # # RCBXV\n",
    "    leads_name = [x for x in SignalMetadata.get_system_types_per_circuit_name(circuit_type, circuit_names[1]) if 'LEADS' in x][0]\n",
    "    source_timestamp_leads_rcbxv_df = query_rcbxv.find_timestamp_leads(timestamp_fgc_rcbxv, leads_name)\n",
    "\n",
197
198
    "    u_hts_leads_rcbxv_dfs = query_rcbxv.query_leads(timestamp_fgc_rcbxv, source_timestamp_leads_rcbxv_df, system=leads_name, signal_names=['U_HTS'], spark=spark, duration=[(300, 's'), (900, 's')])\n",
    "    u_res_leads_rcbxv_dfs = query_rcbxv.query_leads(timestamp_fgc_rcbxv, source_timestamp_leads_rcbxv_df, system=leads_name, signal_names=['U_RES'], spark=spark, duration=[(300, 's'), (900, 's')])\n",
199
    "\n",
200
    "# Create results table - RCBXH/V\n",
201
    "results_table = query_rcbxh.create_report_analysis_template_rcbx(timestamp_fgc_rcbxh, timestamp_fgc_rcbxv, '../__init__.py', circuit_names, author=author)\n",
Michal Maciejewski's avatar
Michal Maciejewski committed
202
203
    "analysis_rcbxh = R600ACircuitAnalysis(circuit_type, results_table, is_automatic=is_automatic)\n",
    "analysis_rcbxv = R600ACircuitAnalysis(circuit_type, results_table, is_automatic=is_automatic)"
204
205
206
207
   ]
  },
  {
   "cell_type": "markdown",
208
209
210
   "metadata": {
    "deletable": false
   },
211
212
213
   "source": [
    "# 3. Timestamps\n",
    "\n",
214
    "The analysis for MP3 consists of checking the existence of PM file and of consistency of the PM timestamps (PC, QPS). The criterion of passing this test described in detail in 600APIC2.\n",
215
216
    "In short the following criteria should be checked:\n",
    "\n",
217
    "- 2 PM DQAMGNA (A+B) files and 1 PM EE file should be generated for 600 A circuits with EE\n",
218
    "- Difference between QPS board A and B timestamp = 1 ms\n",
219
    "- PC timestamp is QPS timestamp +/- 20 ms\n",
220
    "\n",
221
    "If one or more of these conditions are not fulfilled, then an in-depth analysis has to be performed by the QPS team."
222
223
224
225
   ]
  },
  {
   "cell_type": "code",
226
   "execution_count": null,
227
   "metadata": {
228
    "deletable": false
229
   },
230
   "outputs": [],
231
   "source": [
232
233
    "timestamp_dct = {'FGC_RCBXH': timestamp_fgc_rcbxh, 'FGC_RCBXV': timestamp_fgc_rcbxv, \n",
    "                 'PIC_RCBXH': timestamp_pic_rcbxh, 'PIC_RCBXV': timestamp_pic_rcbxv, \n",
234
235
236
237
    "                 'QDS_A_RCBXH':lhcsmnb.utils.get_at(source_timestamp_qds_rcbxh_df, 0, 'timestamp', default=np.nan), \n",
    "                 'QDS_B_RCBXH':lhcsmnb.utils.get_at(source_timestamp_qds_rcbxh_df, 1, 'timestamp', default=np.nan),\n",
    "                 'QDS_A_RCBXV':lhcsmnb.utils.get_at(source_timestamp_qds_rcbxv_df, 0, 'timestamp', default=np.nan), \n",
    "                 'QDS_B_RCBXV':lhcsmnb.utils.get_at(source_timestamp_qds_rcbxv_df, 1, 'timestamp', default=np.nan)}\n",
Michal Maciejewski's avatar
Michal Maciejewski committed
238
    "\n",
239
    "analysis_rcbxh.create_timestamp_table(timestamp_dct, circuit_name=circuit_names[0])"
240
241
242
243
   ]
  },
  {
   "cell_type": "markdown",
244
245
246
   "metadata": {
    "deletable": false
   },
247
   "source": [
Michal Maciejewski's avatar
Michal Maciejewski committed
248
249
250
    "# 4. PC\n",
    "## 4.1. Main Current\n",
    "\n",
251
252
253
254
255
256
    "*ANALYSIS*:\n",
    "- determination of the source of an FPA trigger based on EVENTS.SYMBOL and EVENTS.ACTION signals\n",
    "- detection of the start of a quench as a deviation of I_A and I_REF\n",
    "- calculation of the MIITs\n",
    "- calculation of the quench current\n",
    "- calculation of the duration of a plateau / the ramp rate before a quench (based on PM event buffer)\n",
Michal Maciejewski's avatar
Michal Maciejewski committed
257
    "\n",
258
    "**You may manually adjust the automatically calculated quench start by clicking the right button on a mouse of a plot with current zoom.**\n",
259
    "\n",
260
261
262
    "*GRAPHS*:\n",
    "- dashed blue line denotes the start of a quench (I_A starts to deviate from I_REF)\n",
    "- t = 0 s corresponds to the FGC timestamp"
263
264
   ]
  },
265
266
  {
   "cell_type": "code",
thbuffet's avatar
thbuffet committed
267
   "execution_count": null,
thbuffet's avatar
thbuffet committed
268
   "metadata": {},
thbuffet's avatar
thbuffet committed
269
   "outputs": [],
270
   "source": [
271
272
273
274
    "import matplotlib as mpl\n",
    "mpl.rcParams['savefig.dpi'] = 80\n",
    "mpl.rcParams['figure.dpi'] = 80\n",
    "%matplotlib notebook\n",
275
276
277
278
279
280
281
282
283
284
285
    "analysis_rcbxh.plot_coupled_circuit_current(i_meas_rcbxh_df, i_ref_rcbxh_df, i_meas_rcbxv_df, i_ref_rcbxv_df, timestamp_fgc_rcbxh, timestamp_fgc_rcbxv, circuit_names)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false
   },
   "outputs": [],
   "source": [
286
287
288
289
290
291
    "analysis_rcbxh.plot_i_meas_pc(circuit_names[0], timestamp_fgc_rcbxh, [i_meas_rcbxh_df, i_a_rcbxh_df, i_ref_rcbxh_df])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
292
293
294
   "metadata": {
    "deletable": false
   },
295
296
   "outputs": [],
   "source": [
297
    "t_quench = analysis_rcbxh.estimate_quench_start_from_i_ref_i_a(i_ref_rcbxh_df, i_a_rcbxh_df)\n",
298
    "t_quench = 0 if t_quench is None else t_quench\n",
299
    "t_quench_correction = analysis_rcbxh.plot_i_meas_pc_with_cursor(circuit_names[0], timestamp_fgc_rcbxh, [i_meas_rcbxh_df, i_a_rcbxh_df, i_ref_rcbxh_df], t_quench)"
300
301
302
303
   ]
  },
  {
   "cell_type": "code",
304
   "execution_count": null,
305
   "metadata": {
306
    "deletable": false,
307
    "scrolled": false
308
   },
309
   "outputs": [],
310
   "source": [
311
    "t_quench = analysis_rcbxh.choose_quench_time_from_auto_or_manual(t_quench_correction)\n",
312
    "analysis_rcbxh.analyze_i_meas_pc_trigger(timestamp_fgc_rcbxh, events_action_rcbxh_df, events_symbol_rcbxh_df)\n",
313
    "analysis_rcbxh.calculate_current_miits_i_meas_i_a(i_meas_rcbxh_df, i_a_rcbxh_df, t_quench, col_name='MIITS_H')\n",
Michal Maciejewski's avatar
Michal Maciejewski committed
314
    "analysis_rcbxh.calculate_quench_current(i_meas_rcbxh_df, t_quench, col_name='I_Q_H')\n",
315
    "analysis_rcbxh.calculate_current_slope(i_meas_rcbxh_df, col_name=['Ramp rate H', 'Plateau duration H'])"
316
317
   ]
  },
318
319
320
  {
   "cell_type": "code",
   "execution_count": null,
321
322
323
   "metadata": {
    "deletable": false
   },
324
325
326
327
328
   "outputs": [],
   "source": [
    "analysis_rcbxv.plot_i_meas_pc(circuit_names[1], timestamp_fgc_rcbxv, [i_meas_rcbxv_df, i_a_rcbxv_df, i_ref_rcbxv_df])"
   ]
  },
329
330
  {
   "cell_type": "code",
331
   "execution_count": null,
332
333
334
   "metadata": {
    "deletable": false
   },
335
   "outputs": [],
336
   "source": [
337
    "t_quench = analysis_rcbxv.estimate_quench_start_from_i_ref_i_a(i_ref_rcbxv_df, i_a_rcbxv_df)\n",
338
    "t_quench = 0 if t_quench is None else t_quench\n",
339
    "t_quench_correction = analysis_rcbxv.plot_i_meas_pc_with_cursor(circuit_names[1], timestamp_fgc_rcbxv, [i_meas_rcbxv_df, i_a_rcbxv_df, i_ref_rcbxv_df], t_quench)"
340
341
342
343
   ]
  },
  {
   "cell_type": "code",
344
   "execution_count": null,
345
   "metadata": {
346
    "deletable": false,
347
348
    "scrolled": false
   },
349
   "outputs": [],
350
   "source": [
351
    "t_quench = analysis_rcbxv.choose_quench_time_from_auto_or_manual(t_quench_correction)\n",
352
    "analysis_rcbxv.analyze_i_meas_pc_trigger(timestamp_fgc_rcbxv, events_action_rcbxv_df, events_symbol_rcbxv_df)\n",
353
    "analysis_rcbxv.calculate_current_miits_i_meas_i_a(i_meas_rcbxv_df, i_a_rcbxv_df, t_quench, col_name='MIITS_V')\n",
Michal Maciejewski's avatar
Michal Maciejewski committed
354
    "analysis_rcbxv.calculate_quench_current(i_meas_rcbxv_df, t_quench, col_name='I_Q_V')\n",
355
    "analysis_rcbxv.calculate_current_slope(i_meas_rcbxv_df, col_name=['Ramp rate V', 'Plateau duration V'])"
356
357
358
359
   ]
  },
  {
   "cell_type": "code",
360
   "execution_count": null,
361
362
363
   "metadata": {
    "deletable": false
   },
364
   "outputs": [],
365
   "source": [
366
    "analysis_rcbxh.results_table[['Circuit Name', 'Date (FGC)', 'Time (FGC)', 'I_Q_H', 'I_Q_V', 'MIITS_H', 'MIITS_V', 'Ramp rate H', 'Ramp rate V', 'Plateau duration H', 'Plateau duration V']]"
367
368
   ]
  },
thbuffet's avatar
thbuffet committed
369
  {
thbuffet's avatar
thbuffet committed
370
   "cell_type": "markdown",
thbuffet's avatar
thbuffet committed
371
372
373
   "metadata": {
    "scrolled": true
   },
thbuffet's avatar
thbuffet committed
374
375
376
377
378
379
380
381
   "source": [
    "### 4.1.1 Angle Calculation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
thbuffet's avatar
thbuffet committed
382
383
384
385
386
   "outputs": [],
   "source": [
    "analysis_rcbxv.compute_and_print_current_angle_for_combined_powering()"
   ]
  },
387
388
  {
   "cell_type": "markdown",
389
390
391
   "metadata": {
    "deletable": false
   },
392
   "source": [
Michal Maciejewski's avatar
Michal Maciejewski committed
393
394
    "## 4.2. Earth Current\n",
    "\n",
395
396
    "*ANALYSIS*:\n",
    "- calculation of the maximum absolute earth current (maintaining the sign)\n",
Michal Maciejewski's avatar
Michal Maciejewski committed
397
    "\n",
398
399
    "*GRAPHS*:\n",
    "- t = 0 s corresponds to the FGC timestamp"
400
401
402
403
   ]
  },
  {
   "cell_type": "code",
404
   "execution_count": null,
405
406
407
   "metadata": {
    "deletable": false
   },
408
   "outputs": [],
409
   "source": [
Michal Maciejewski's avatar
Michal Maciejewski committed
410
    "analysis_rcbxh.plot_i_earth_pc(circuit_names[0], timestamp_fgc_rcbxh, i_earth_rcbxh_df)\n",
411
    "analysis_rcbxh.calculate_max_i_earth_pc(i_earth_rcbxh_df, col_name='I_Earth_max_H')"
412
413
414
415
   ]
  },
  {
   "cell_type": "code",
416
   "execution_count": null,
417
418
419
   "metadata": {
    "deletable": false
   },
420
   "outputs": [],
421
   "source": [
Michal Maciejewski's avatar
Michal Maciejewski committed
422
    "analysis_rcbxv.plot_i_earth_pc(circuit_names[1], timestamp_fgc_rcbxv, i_earth_rcbxv_df)\n",
423
    "analysis_rcbxv.calculate_max_i_earth_pc(i_earth_rcbxv_df, col_name='I_Earth_max_V')"
424
425
426
427
   ]
  },
  {
   "cell_type": "markdown",
428
429
430
   "metadata": {
    "deletable": false
   },
431
   "source": [
432
    "# 5. QDS\n",
433
    "The quench voltage U_RES is calculated according to the following formula:\n",
Michal Maciejewski's avatar
Michal Maciejewski committed
434
    "\n",
435
436
437
    "\\begin{equation}\n",
    "U_{\\text{RES}} = U_{\\text{DIFF}} + L d/dt (I+U_{\\text{DIFF}}/R).\n",
    "\\end{equation}\n",
Michal Maciejewski's avatar
Michal Maciejewski committed
438
    "\n",
439
440
    "Note that I_DCCT is the QPS signal name, even though the current is actually measured not with a DCCT, but with a LEM detector, hence the poorer quality w.r.t. to the FGC I_A/B/MEAS signals that are measured with a DCCT.\n",
    "It can be seen from the sign convention in the figure below that a resistive voltage always has opposite sign to the measured current.\n",
Michal Maciejewski's avatar
Michal Maciejewski committed
441
    "\n",
442
    "<img src=\"https://gitlab.cern.ch/LHCData/lhc-sm-hwc/-/raw/master/figures/600A/600A_without_EE.png\" width=75%>\n",
Michal Maciejewski's avatar
Michal Maciejewski committed
443
    "\n",
444
445
    "As U_DIFF contributes directly to U_RES, the resolution of U_RES is, at least partially, limited by that of U_DIFF. Moreover, U_RES is affected by the noisy time derivative of the current signal.\n",
    "The QPS signals that are communicated to the post-mortem system have only 12 bit resolution.\n",
446
    "\n",
447
448
449
450
451
    "## 5.1. Resistive Voltage\n",
    "\n",
    "*ANALYSIS*:\n",
    "- Check if the U_RES signal before a quench is increasing for at least one board, which would indicate a QPS trip\n",
    "- Calculate the initial voltage slope of U_RES signal. The slope is calculated as a ratio of the voltage change from 50 to 200 mV and the corresponding time change.\n",
Michal Maciejewski's avatar
Michal Maciejewski committed
452
    "\n",
453
454
455
    "*GRAPHS*:\n",
    "First plot (U_RES and I_MEAS prior to a quench)\n",
    "- t = 0 s corresponds to the FGC timestamp\n",
Michal Maciejewski's avatar
Michal Maciejewski committed
456
    "\n",
457
458
    "Second plot (U_RES and the initial slope of U_RES)\n",
    "- t = 0 s corresponds to the QPS timestamp"
459
460
461
462
   ]
  },
  {
   "cell_type": "code",
463
   "execution_count": null,
464
   "metadata": {
465
    "deletable": false
466
   },
467
   "outputs": [],
468
469
470
471
472
473
   "source": [
    "analysis_rcbxh.plot_u_res(circuit_names[0], timestamp_qds_rcbxh, u_res_nxcals_rcbxh_df, i_meas_nxcals_rcbxh_df)"
   ]
  },
  {
   "cell_type": "code",
474
   "execution_count": null,
475
476
477
   "metadata": {
    "deletable": false
   },
478
   "outputs": [],
479
   "source": [
480
    "u_res_rcbxh_slope_df = analysis_rcbxh.calculate_u_res_slope(u_res_rcbxh_df, col_name='dU_QPS/dt_H')\n",
481
482
483
484
485
    "analysis_rcbxh.plot_u_res_slope(circuit_names[0], timestamp_qds_rcbxh, u_res_rcbxh_df, u_res_rcbxh_slope_df)"
   ]
  },
  {
   "cell_type": "code",
486
   "execution_count": null,
487
   "metadata": {
488
    "deletable": false
489
   },
490
   "outputs": [],
491
492
493
494
495
496
   "source": [
    "analysis_rcbxv.plot_u_res(circuit_names[1], timestamp_qds_rcbxv, u_res_nxcals_rcbxv_df, i_meas_nxcals_rcbxv_df)"
   ]
  },
  {
   "cell_type": "code",
497
   "execution_count": null,
498
499
500
   "metadata": {
    "deletable": false
   },
501
   "outputs": [],
502
   "source": [
503
    "u_res_rcbxv_slope_df = analysis_rcbxv.calculate_u_res_slope(u_res_rcbxv_df, col_name='dU_QPS/dt_V')\n",
504
505
506
507
508
    "analysis_rcbxv.plot_u_res_slope(circuit_names[1], timestamp_qds_rcbxv, u_res_rcbxv_df, u_res_rcbxv_slope_df)"
   ]
  },
  {
   "cell_type": "code",
509
   "execution_count": null,
510
511
512
   "metadata": {
    "deletable": false
   },
513
   "outputs": [],
514
   "source": [
515
    "analysis_rcbxh.results_table[['Circuit Name', 'Date (FGC)', 'Time (FGC)', 'dU_QPS/dt_H', 'dU_QPS/dt_V']]"
516
517
518
519
   ]
  },
  {
   "cell_type": "markdown",
520
521
522
   "metadata": {
    "deletable": false
   },
523
   "source": [
524
    "## 5.2. I_DCCT, I_DIDT Currents; U_RES, U_DIFF Voltages\n",
Michal Maciejewski's avatar
Michal Maciejewski committed
525
    "\n",
526
527
    "*ANALYSIS*\n",
    "- Check the integrity of all four signals (U_DIFF, I_DCCT, I_DIDT and U_RES). If one of the signals (especially U_DIFF or I_DCCT) stays at zero or shows wrong values the cabling of this quench detector could have issues. Compare U_DIFF (measured signal) to U_REF (signal compensated for inductive voltage).\n",
Michal Maciejewski's avatar
Michal Maciejewski committed
528
    "\n",
529
    "*CRITERIA*\n",
530
531
    "- U_RES < 0.7*100 mV\n",
    "- noise of U_RES on the plateaus < 20mV\n",
Michal Maciejewski's avatar
Michal Maciejewski committed
532
    "\n",
533
534
    "*GRAPHS*:\n",
    "- t = 0 s corresponds to the QPS timestamp"
535
536
537
538
   ]
  },
  {
   "cell_type": "code",
539
   "execution_count": null,
540
   "metadata": {
541
    "deletable": false
542
   },
543
   "outputs": [],
544
545
546
547
548
549
   "source": [
    "analysis_rcbxh.plot_qds(circuit_names[0], timestamp_qds_rcbxh, i_dcct_rcbxh_df, i_didt_rcbxh_df, u_diff_rcbxh_df, u_res_rcbxh_df)"
   ]
  },
  {
   "cell_type": "code",
550
   "execution_count": null,
551
   "metadata": {
552
    "deletable": false
553
   },
554
   "outputs": [],
555
   "source": [
556
    "analysis_rcbxv.plot_qds(circuit_names[1], timestamp_qds_rcbxv, i_dcct_rcbxv_df, i_didt_rcbxv_df, u_diff_rcbxv_df, u_res_rcbxv_df)"
557
558
559
560
   ]
  },
  {
   "cell_type": "markdown",
561
562
563
   "metadata": {
    "deletable": false
   },
564
   "source": [
565
    "## 5.3. LEADS\n",
566
    "\n",
567
568
    "*ANALYSIS*:\n",
    "- check if U_HTS for 2 consecutive datapoints is above the threshold 3 mV\n",
569
    "- check if U_RES for 2 consecutive datapoints is above the threshold 160 mV\n",
570
    "\n",
571
    "*GRAPHS*:\n",
572
    "- t = 0 s corresponds to the FGC timestamp\n"
573
574
575
576
   ]
  },
  {
   "cell_type": "code",
577
   "execution_count": null,
578
   "metadata": {
579
    "deletable": false
580
   },
581
   "outputs": [],
582
583
584
585
586
587
   "source": [
    "analysis_rcbxh.analyze_leads_voltage(u_hts_leads_rcbxh_dfs, circuit_names[0], timestamp_fgc_rcbxh, signal='U_HTS', value_min=-0.003, value_max=0.003)"
   ]
  },
  {
   "cell_type": "code",
588
   "execution_count": null,
589
590
591
   "metadata": {
    "deletable": false
   },
592
   "outputs": [],
593
   "source": [
594
    "analysis_rcbxh.analyze_leads_voltage(u_res_leads_rcbxh_dfs, circuit_names[0], timestamp_fgc_rcbxh, signal='U_RES', value_min=-0.16, value_max=0.16)"
595
596
597
598
   ]
  },
  {
   "cell_type": "code",
599
   "execution_count": null,
600
   "metadata": {
601
    "deletable": false
602
   },
603
   "outputs": [],
604
605
   "source": [
    "analysis_rcbxv.analyze_leads_voltage(u_hts_leads_rcbxv_dfs, circuit_names[1], timestamp_fgc_rcbxv, signal='U_HTS', value_min=-0.003, value_max=0.003)"
606
607
608
609
   ]
  },
  {
   "cell_type": "code",
610
   "execution_count": null,
611
612
613
   "metadata": {
    "scrolled": false
   },
614
   "outputs": [],
615
   "source": [
616
    "analysis_rcbxv.analyze_leads_voltage(u_res_leads_rcbxv_dfs, circuit_names[1], timestamp_fgc_rcbxv, signal='U_RES', value_min=-0.16, value_max=0.16)"
617
618
619
620
   ]
  },
  {
   "cell_type": "code",
621
   "execution_count": null,
622
623
624
   "metadata": {
    "deletable": false
   },
625
   "outputs": [],
626
   "source": [
Aleksandra Mnich's avatar
Aleksandra Mnich committed
627
    "if not is_automatic:\n",
628
629
    "    analysis_rcbxh.results_table['FPA Reason'] = get_expert_decision('Reason for FPA: ', ['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",
    "    analysis_rcbxh.results_table['Type of Quench'] = get_expert_decision('Type of Quench: ', ['Training', 'Heater-provoked', 'Beam-induced', 'GHe propagation', 'QPS crate reset', 'Single Event Upset' ,'Short-to-ground', 'EM disturbance', 'No quench', 'Unknown'])\n",
630
631
    "    analysis_rcbxh.results_table['QDS trigger origin'] = get_expert_decision('QDS trigger origin: ', ['QPS', 'HTS current lead', 'RES current lead', 'Busbar', 'No quench'])\n",
    "    analysis_rcbxh.results_table['Quench origin'] = get_expert_decision('Quench origin: ', ['H', 'V'])"
632
633
634
635
   ]
  },
  {
   "cell_type": "markdown",
636
637
638
   "metadata": {
    "deletable": false
   },
639
   "source": [
640
    "# 6. Analysis Comment"
641
642
643
644
   ]
  },
  {
   "cell_type": "code",
645
   "execution_count": null,
646
647
648
   "metadata": {
    "deletable": false
   },
649
   "outputs": [],
650
   "source": [
Aleksandra Mnich's avatar
Aleksandra Mnich committed
651
652
    "if not is_automatic:\n",
    "    analysis_rcbxh.results_table['Comment'] = input('Comment: ')"
653
654
655
656
   ]
  },
  {
   "cell_type": "markdown",
657
   "metadata": {
Aleksandra Mnich's avatar
Aleksandra Mnich committed
658
659
660
661
    "deletable": false,
    "tags": [
     "ignore"
    ]
662
   },
663
664
665
666
667
668
   "source": [
    "# 7. Final Report"
   ]
  },
  {
   "cell_type": "code",
669
   "execution_count": null,
670
   "metadata": {
671
    "deletable": false,
Aleksandra Mnich's avatar
Aleksandra Mnich committed
672
673
674
675
    "scrolled": false,
    "tags": [
     "ignore"
    ]
676
   },
677
   "outputs": [],
678
   "source": [
679
680
    "pd.set_option('display.max_columns', None)\n",
    "pd.set_option('display.max_rows', None)\n",
681
    "circuit_name = circuit_names[0]\n",
682
683
    "\n",
    "analysis_start_time = Time.get_analysis_start_time()\n",
684
    "timestamp_fgc = timestamp_fgc_rcbxh if not np.isnan(timestamp_fgc_rcbxh) else timestamp_fgc_rcbxv\n",
685
686
    "date_time_fgc = Time.to_datetime(timestamp_fgc).strftime(\"%Y-%m-%d-%Hh%M\")\n",
    "prefix_circuit_name = SignalMetadata.parse_600A_circuit_name_to_family_name(circuit_name)\n",
687
688
    "circuit_name_rcbx = circuit_name.replace('RCBXH', 'RCBX') if 'RCBXH' in circuit_name else circuit_name.replace('RCBXV', 'RCBX')\n",
    "!mkdir -p /eos/project/m/mp3/600A/$prefix_circuit_name/$circuit_name_rcbx/FPA\n",
689
    "\n",
690
691
    "file_name = \"{}_FPA-{}-{}\".format(circuit_name_rcbx, date_time_fgc, analysis_start_time)\n",
    "full_path = '/eos/project/m/mp3/600A/{}/{}/FPA/{}.csv'.format(prefix_circuit_name, circuit_name_rcbx, file_name)\n",
692
693
694
    "\n",
    "mp3_results_table = analysis_rcbxh.create_mp3_results_table_rcbxhv()\n",
    "display(HTML(mp3_results_table.T.to_html()))\n",
695
    "mp3_results_table.to_csv(full_path, index=False)\n",
696
697
    "print('MP3 results table saved to (Windows): ' + '\\\\\\\\cernbox-smb' + full_path.replace('/', '\\\\'))\n",
    "\n",
698
    "apply_report_template()\n",
699
    "\n",
700
    "full_path = '/eos/project/m/mp3/600A/{}/{}/FPA/{}.html'.format(prefix_circuit_name, circuit_name_rcbx, file_name)\n",
701
    "print('Compact notebook report saved to (Windows): ' + '\\\\\\\\cernbox-smb' + full_path.replace('/', '\\\\'))\n",
702
    "\n",
703
    "display(Javascript('IPython.notebook.save_notebook();'))\n",
704
705
    "Time.sleep(5)\n",
    "file_name_html = file_name + '.html'\n",
706
    "!{sys.executable} -m jupyter nbconvert --to html $'AN_600A_RCBXHV_FPA.ipynb' --output /eos/project/m/mp3/600A/$prefix_circuit_name/$circuit_name_rcbx/FPA/$file_name_html --TemplateExporter.exclude_input=True --TagRemovePreprocessor.remove_all_outputs_tags='[\"skip_output\"]' --TagRemovePreprocessor.remove_cell_tags='[\"skip_cell\"]'"
707
   ]
708
709
710
711
712
713
714
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
733
   "version": "3.8.10"
734
735
736
737
738
739
740
  },
  "sparkconnect": {
   "bundled_options": [
    "NXCALS",
    "SparkMetrics"
   ],
   "list_of_options": []
741
742
743
744
745
746
747
748
749
750
751
752
753
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": false,
   "sideBar": false,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
754
755
756
757
758
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}