AN_RQ_PLIS.s2.ipynb 14.9 KB
Newer Older
1
2
3
4
{
 "cells": [
  {
   "cell_type": "markdown",
5
6
7
   "metadata": {
    "deletable": false
   },
8
9
   "source": [
    "<h1><center>Analysis of a PLIS.s2 HWC in an RQ Circuit</center></h1>\n",
10
    "<img src=\"https://gitlab.cern.ch/LHCData/lhc-sm-hwc/raw/master/figures/rq/RQ.png\" width=75%>\n",
11
12
13
    "\n",
    "This test has been inserted (from version 1.1 on) in order to check the status of the splices step-wise while ramping the circuit up and down to I_SM current.\n",
    "\n",
14
    "<img src=\"https://gitlab.cern.ch/LHCData/lhc-sm-hwc/raw/master/figures/rq/PLIS_current.png\" width=75%>\n",
15
16
17
18
19
20
21
    "\n",
    "From I_MIN_OP, the circuit is ramped up to different current level (I_SM_INT_1, I_SM_INT_2, I_SM_INT_3, I_SM_INT_4, I_SM) and maintained constant at each current level during TIME_INTERM_1.\n",
    "\n",
    "The required analysis and signatures are listed below.\n",
    "\n",
    "|Responsible|Type of analysis|Criterion|\n",
    "|-----------|----------------|---------|\n",
22
23
    "|-|Automatic analysis on earth current and error current|I_EARTH_PLIS_S2 < I_EARTH_MAX and I_ERR_PLIS_S2 < I_ERR_MAX|\n",
    "|MP3|Splice signals|R_bus<10 nOhm|\n",
24
    "\n",
25
    "source: Powering Procedure and Acceptance Criteria for the 13 kA Dipole Circuits, MP3 Procedure, <a href=\"https://edms.cern.ch/document/874713\">https://edms.cern.ch/document/874713</a> (Please follow this link for the latest version)"
26
27
28
29
   ]
  },
  {
   "cell_type": "markdown",
30
31
32
   "metadata": {
    "deletable": false
   },
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
   "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"
   ]
  },
  {
   "cell_type": "markdown",
51
52
53
   "metadata": {
    "deletable": false
   },
54
   "source": [
55
    "# 0. Initialise Working Environment"
56
57
58
59
   ]
  },
  {
   "cell_type": "code",
60
   "execution_count": null,
61
62
63
   "metadata": {
    "deletable": false
   },
64
65
   "outputs": [],
   "source": [
66
    "# External libraries\n",
67
    "print('Loading (1/11)'); import sys; import pandas as pd\n",
68
69
70
71
72
73
74
75
76
77
78
79
80
    "print('Loading (2/11)'); from IPython.display import display, Javascript, clear_output\n",
    "\n",
    "# Internal libraries\n",
    "print('Loading (3/11)'); import lhcsmapi\n",
    "print('Loading (4/11)'); from lhcsmapi.Time import Time\n",
    "print('Loading (5/11)'); from lhcsmapi.Timer import Timer\n",
    "print('Loading (6/11)'); from lhcsmapi.analysis.RqCircuitQuery import RqCircuitQuery\n",
    "print('Loading (7/11)'); from lhcsmapi.analysis.RqCircuitAnalysis import RqCircuitAnalysis\n",
    "print('Loading (8/11)'); from lhcsmapi.analysis.report_template import apply_report_template\n",
    "print('Loading (9/11)'); from lhcsmapi.gui.hwc.HwcSearchModuleMediator import HwcSearchModuleMediator\n",
    "print('Loading (10/11)'); from lhcsmapi.pyedsl.PlotBuilder import create_hwc_plot_title_with_circuit_name\n",
    "print('Loading (11/11)'); from lhcsmapi.analysis.expert_input import get_expert_decision\n",
    "\n",
81
82
83
    "pd.set_option('display.max_columns', None) \n",
    "pd.set_option('display.max_rows', None)\n",
    "\n",
84
85
    "clear_output()\n",
    "lhcsmapi.get_lhcsmapi_version()\n",
86
87
    "lhcsmapi.get_lhcsmhwc_version('../__init__.py')\n",
    "print('Analysis performed by %s' % HwcSearchModuleMediator.get_user())"
88
89
90
91
   ]
  },
  {
   "cell_type": "markdown",
92
93
94
   "metadata": {
    "deletable": false
   },
95
   "source": [
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
    "# 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 = 'PLIS.s2'\n",
    "    circuit_name = 'RQD.A12'\n",
    "    campaign = 'HWC_2014'\n",
    "    t_start = '2015-01-19 13:07:38.011'\n",
    "    t_end = '2015-01-19 16:12:25.285'\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 = 'PLIS.s2'\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"
117
118
119
120
   ]
  },
  {
   "cell_type": "code",
Michal Maciejewski's avatar
Michal Maciejewski committed
121
   "execution_count": null,
122
   "metadata": {
123
    "deletable": false
124
   },
Michal Maciejewski's avatar
Michal Maciejewski committed
125
   "outputs": [],
126
   "source": []
127
  },
128
129
130
131
132
133
134
135
136
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print('hwc_test = \\'%s\\'\\ncircuit_name = \\'%s\\'\\ncampaign = \\'%s\\'\\nt_start = \\'%s\\'\\nt_end = \\'%s\\'' % (hwc_test, circuit_name, campaign, t_start, t_end))"
   ]
  },
137
138
139
140
141
142
143
144
145
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 2. Query All Signals Prior to Analysis"
   ]
  },
  {
   "cell_type": "code",
Michal Maciejewski's avatar
Michal Maciejewski committed
146
   "execution_count": null,
147
   "metadata": {
148
    "deleteable": false,
149
150
151
152
    "tags": [
     "skip_output"
    ]
   },
Michal Maciejewski's avatar
Michal Maciejewski committed
153
   "outputs": [],
154
   "source": [
155
156
157
158
159
160
161
162
163
164
165
    "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",
    "    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",
    "    is_automatic = False\n",
    "\n",
166
167
168
    "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",
    "\n",
169
    "rq_query = RqCircuitQuery(circuit_type, circuit_names, max_executions=4)\n",
170
    "rq_analysis = RqCircuitAnalysis(circuit_type, None, is_automatic=is_automatic)\n",
171
172
    "\n",
    "with Timer():\n",
173
    "    # PC\n",
Michal Maciejewski's avatar
Michal Maciejewski committed
174
    "    i_meas_nxcals_dfs = rq_query.query_signal_nxcals(t_start, t_end, t0=t_start, system='PC', signal_names='I_MEAS', spark=spark)\n",
175
176
    "    i_meas_raw_nxcals_dfs =  rq_query.query_raw_signal_nxcals(t_start, t_end, system='PC', signal_names='I_MEAS', spark=spark)\n",
    "    plateau_start, plateau_end = rq_query.calculate_current_plateau_start_end(Time.to_unix_timestamp(t_start), Time.to_unix_timestamp(t_end), \n",
Michal Maciejewski's avatar
Michal Maciejewski committed
177
    "                                                                              i_meas_threshold=500, min_duration_in_sec=360, time_shift_in_sec=(240, 60), spark=spark)\n",
178
179
    "\n",
    "    # BUSBAR\n",
180
181
    "    u_res_feature_df, i_meas_feature_df = rq_query.get_busbar_resistances(Time.to_unix_timestamp(t_start), Time.to_unix_timestamp(t_end), plateau_start, plateau_end, \n",
    "                                                                          signal_name='U_RES', spark=spark)\n",
182
183
184
    "    \n",
    "    from lhcsmapi.analysis.busbar.BusbarResistanceAnalysis import MultipleBusbarResistanceAnalysis\n",
    "    res_busbar_row_df = MultipleBusbarResistanceAnalysis.calculate_resistance(rq_analysis, i_meas_feature_df, u_res_feature_df, 'U_RES', Time.to_unix_timestamp(t_start), circuit_names)\n",
185
    "    res_busbar_df = rq_analysis.convert_to_col(res_busbar_row_df, signal_name='U_RES')"
186
187
188
189
   ]
  },
  {
   "cell_type": "markdown",
190
191
192
   "metadata": {
    "deletable": false
   },
193
   "source": [
194
195
196
197
198
199
    "# 3. Circuit Parameters Table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
200
201
202
   "metadata": {
    "deletable": false
   },
203
204
205
206
207
208
209
   "outputs": [],
   "source": [
    "rq_analysis.display_parameters_table(circuit_names[0])"
   ]
  },
  {
   "cell_type": "markdown",
210
211
212
   "metadata": {
    "deletable": false
   },
213
214
215
   "source": [
    "# 4. Power Converter\n",
    "## 4.1. Plot of the Power Converter Main Current\n",
216
    "\n",
217
    "*GRAPHS*:\n",
218
    "\n",
219
220
    "- t = 0 s corresponds to the start of the test\n",
    "- Orange box(es) represent period(s) of time with constant current used for calculation of busbar resistance and DFB thresholds"
221
222
223
224
   ]
  },
  {
   "cell_type": "code",
Michal Maciejewski's avatar
Michal Maciejewski committed
225
   "execution_count": null,
226
227
228
   "metadata": {
    "deletable": false
   },
Michal Maciejewski's avatar
Michal Maciejewski committed
229
   "outputs": [],
230
   "source": [
231
232
233
234
    "import matplotlib as mpl\n",
    "mpl.rcParams['savefig.dpi'] = 80\n",
    "mpl.rcParams['figure.dpi'] = 80\n",
    "%matplotlib notebook\n",
235
236
237
    "title = '%s-%s, %s: %s-%s' % (circuit_names[0], circuit_names[1], hwc_test, Time.to_string(t_start).split('.')[0], Time.to_string(t_end).split('.')[0])\n",
    "i_meas_nxcals_dfs[0].rename(columns={'I_MEAS': '%s:I_MEAS' % circuit_names[0]}, inplace=True)\n",
    "i_meas_nxcals_dfs[1].rename(columns={'I_MEAS': '%s:I_MEAS' % circuit_names[1]}, inplace=True)\n",
238
    "rq_analysis.plot_i_meas_with_current_plateau(i_meas_nxcals_dfs, t0=i_meas_raw_nxcals_dfs[0].index[0], plateau_start=plateau_start, plateau_end=plateau_end, title=title)"
239
240
241
242
   ]
  },
  {
   "cell_type": "markdown",
243
244
245
   "metadata": {
    "deletable": false
   },
246
   "source": [
247
248
    "# 5. Busbar\n",
    "## 5.1. RQ Busbar Resistance\n",
249
250
    "\n",
    "*ANALYSIS*:\n",
251
    "\n",
252
253
    "- Calculation of the busbar resistance as the slope of a linear fit of U,I curve obtained from the corresponding mean alues of the voltage and current\n",
    "\n",
254
255
256
    "*CRITERIA*:\n",
    "\n",
    "- Check if the busbar resistance is below 10 nOhm\n",
257
    "\n",
258
    "*GRAPHS*:\n",
259
    "\n",
260
261
    "- The busbar resistance, R\n",
    "- The green box denotes the validity region of the busbar resostance (0, 10] nOhm"
262
263
264
265
   ]
  },
  {
   "cell_type": "code",
Michal Maciejewski's avatar
Michal Maciejewski committed
266
   "execution_count": null,
267
268
269
   "metadata": {
    "deletable": false
   },
Michal Maciejewski's avatar
Michal Maciejewski committed
270
   "outputs": [],
271
   "source": [
272
273
    "title = '%s-%s, %s: %s-%s' % (circuit_names[0], circuit_names[1], hwc_test, Time.to_string(t_start).split('.')[0], Time.to_string(t_end).split('.')[0])\n",
    "res_outliers_df = rq_analysis.analyze_busbar_magnet_resistance(res_busbar_df, signal_name='R_RES', value_max=10e-9, title=title)"
274
275
276
277
   ]
  },
  {
   "cell_type": "code",
Michal Maciejewski's avatar
Michal Maciejewski committed
278
   "execution_count": null,
279
280
281
   "metadata": {
    "deletable": false
   },
282
283
   "outputs": [],
   "source": [
284
285
286
    "RqCircuitQuery.query_and_plot_outlier_voltage(res_outliers_df.reset_index(), t_start, t_end, i_meas_raw_nxcals_dfs[0].index[0], plateau_start, plateau_end, spark=spark)"
   ]
  },
287
288
289
290
291
292
293
294
295
296
297
298
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "busbar_metadata_resistance_df = rq_analysis.merge_busbar_metadata_with_resistance(res_busbar_df, circuit_type, circuit_names)\n",
    "rq_analysis.display_busbar_metadata_resistance_with_threshold(busbar_metadata_resistance_df, threshold=10e-9)"
   ]
  },
299
300
  {
   "cell_type": "markdown",
301
302
303
   "metadata": {
    "deletable": false
   },
304
   "source": [
305
    "# 6. Signature Decision"
306
307
308
309
310
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
311
312
313
   "metadata": {
    "deletable": false
   },
314
315
316
   "outputs": [],
   "source": [
    "signature = get_expert_decision('Expert Signature Decision: ', ['PASSED', 'FAILED'])"
317
318
319
320
321
322
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
323
    "# 7. Final Report"
324
325
326
327
   ]
  },
  {
   "cell_type": "code",
Michal Maciejewski's avatar
Michal Maciejewski committed
328
   "execution_count": null,
329
330
331
   "metadata": {
    "deletable": false
   },
Michal Maciejewski's avatar
Michal Maciejewski committed
332
   "outputs": [],
333
   "source": [
334
    "analysis_start_time = Time.get_analysis_start_time()\n",
335
336
    "circuit_name = circuit_names[0].replace('D', '')\n",
    "apply_report_template()\n",
337
    "\n",
338
339
    "!mkdir -p /eos/project/m/mp3/RQ/$circuit_name/$hwc_test\n",
    "\n",
340
341
342
343
344
    "file_name_csv = '{}_{}-{}-{}_{}_BUSBAR_RESISTANCE.csv'.format(circuit_name, hwc_test, Time.to_datetime(t_start).strftime(\"%Y-%m-%d-%Hh%M\"), analysis_start_time, signature)\n",
    "full_path = '/eos/project/m/mp3/RQ/{}/{}/{}'.format(circuit_name, hwc_test, file_name_csv)\n",
    "busbar_metadata_resistance_df.to_csv(full_path)\n",
    "print('Busbar resistance table saved to (Windows): ' + '\\\\\\\\cernbox-smb' + full_path.replace('/', '\\\\'))\n",
    "\n",
345
346
    "file_name_html = '{}_{}-{}-{}_{}.html'.format(circuit_name, hwc_test, Time.to_datetime(t_start).strftime(\"%Y-%m-%d-%Hh%M\"), analysis_start_time, signature)\n",
    "full_path = '/eos/project/m/mp3/RQ/{}/{}/{}'.format(circuit_name, hwc_test, file_name_html)\n",
347
348
    "print('Compact notebook report saved to (Windows): ' + '\\\\\\\\cernbox-smb' + full_path.replace('/', '\\\\'))\n",
    "display(Javascript('IPython.notebook.save_notebook();'))\n",
349
350
    "Time.sleep(5)\n",
    "!{sys.executable} -m jupyter nbconvert --to html $'AN_RQ_PLIS.s2.ipynb' --output /eos/project/m/mp3/RQ/$circuit_name/$hwc_test/$file_name_html --TemplateExporter.exclude_input=True --TagRemovePreprocessor.remove_all_outputs_tags='[\"skip_output\"]'"
351
   ]
352
353
354
355
356
357
358
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
  }
 ],
 "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",
   "version": "3.6.5"
  },
  "sparkconnect": {
   "bundled_options": [
    "NXCALS",
    "SparkMetrics"
   ],
Michal Maciejewski's avatar
Michal Maciejewski committed
384
   "list_of_options": []
385
386
387
388
389
390
391
392
393
394
395
396
397
  },
  "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
398
399
400
401
402
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}