AN_RB_PLI3.d2.ipynb 31.3 KB
Newer Older
1
2
3
4
{
 "cells": [
  {
   "cell_type": "markdown",
5
6
7
   "metadata": {
    "deletable": false
   },
8
9
   "source": [
    "<h1><center>Analysis of PLI3.d2 HWC Test in an RB Circuit</center></h1>\n",
10
    "<img src=\"https://gitlab.cern.ch/LHCData/lhc-sm-hwc/raw/master/figures/rb/RB.png\" width=75%>\n",
11
12
13
14
    "\n",
    "The circuit is powered up to I_INTERM_2. After a short plateau a powering failure is simulated by the power converter. After a minute the EE system is activated by a quench simulation in a current lead.\n",
    "The aim of this test is to verify the correct functionality of the PC when a powering failure is generated.\n",
    "\n",
15
    "<img src=\"https://gitlab.cern.ch/LHCData/lhc-sm-hwc/raw/master/figures/rb/PLI3_current.png\" width=50%>\n",
16
17
18
19
20
    "\n",
    "The required analysis and signatures are listed below.\n",
    "\n",
    "|Responsible|Type of analysis|Criterion|\n",
    "|-----------|----------------|---------|\n",
21
22
23
24
    "|PC|PC voltage check|PC voltage ~ -1.5 V ± 0.5 V, 1 s after the EE activation.  The current decay time constant should be within 20% of Decay_Time_const.  Smooth exponential waveform on the PC voltage and current during the whole decay|\n",
    "|PC|Earth Current Analysis|The maximum earth current <50 mA during EE activation disregarding the peak at the opening of the EE system.|\n",
    "|EE|Energy discharge|Maximum voltage on EE resistance ($R*I$±10%) and maximum temperature of the EE resistance (±10% from theoretical value)|\n",
    "|EE|Energy discharge|Time delay on switch opening (300±50ms at odd point and 600±50ms at even point)|\n",
25
    "\n",
26
    "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>"
27
28
29
30
   ]
  },
  {
   "cell_type": "markdown",
31
32
33
   "metadata": {
    "deletable": false
   },
34
35
   "source": [
    "# Analysis Assumptions\n",
36
37
    "- 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",
38
39
    "\n",
    "# Plot Convention\n",
40
41
    "- 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",
42
    "- 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",
43
44
45
    "- 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",
46
    "- Each plot has an individual time-synchronization mentioned explicitly in the description.\n",
47
    "- If an axis has a single signal, then the color of the label matches the signal's color. Otherwise, the label color is black."
48
49
50
51
   ]
  },
  {
   "cell_type": "markdown",
52
53
54
   "metadata": {
    "deletable": false
   },
55
   "source": [
56
    "# 0. Initialise Working Environment"
57
58
59
60
   ]
  },
  {
   "cell_type": "code",
61
   "execution_count": null,
62
   "metadata": {
63
    "deletable": false,
64
65
66
67
    "scrolled": true
   },
   "outputs": [],
   "source": [
68
    "# External libraries\n",
69
    "print('Loading (1/11)'); import sys; import pandas as pd\n",
70
    "print('Loading (2/11)'); from IPython.display import display, Javascript, clear_output\n",
71
    "\n",
72
    "# Internal libraries\n",
73
74
75
76
77
78
79
80
81
    "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.RbCircuitQuery import RbCircuitQuery\n",
    "print('Loading (7/11)'); from lhcsmapi.analysis.RbCircuitAnalysis import RbCircuitAnalysis\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",
Michal Maciejewski's avatar
Michal Maciejewski committed
82
    "\n",
83
84
    "clear_output()\n",
    "lhcsmapi.get_lhcsmapi_version()\n",
85
86
    "lhcsmapi.get_lhcsmhwc_version('../__init__.py')\n",
    "print('Analysis performed by %s' % HwcSearchModuleMediator.get_user())"
87
88
89
90
   ]
  },
  {
   "cell_type": "markdown",
91
92
93
   "metadata": {
    "deletable": false
   },
94
   "source": [
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
    "# 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 = 'PLI3.d2'\n",
    "    circuit_name = 'RB.A12'\n",
    "    campaign = 'HWC_2017'\n",
    "    t_start = '2017-04-22 13:22:37.202'\n",
    "    t_end = '2017-04-22 14:01:44.575'\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 = 'RB'\n",
    "hwc_test = 'PLI3.d2'\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"
116
117
118
119
   ]
  },
  {
   "cell_type": "code",
Michal Maciejewski's avatar
Michal Maciejewski committed
120
   "execution_count": null,
121
   "metadata": {
122
    "deletable": false,
123
124
    "scrolled": false
   },
Michal Maciejewski's avatar
Michal Maciejewski committed
125
   "outputs": [],
thbuffet's avatar
thbuffet committed
126
127
128
129
130
131
132
   "source": [
    "hwc_test = 'PLI3.d2' \n",
    "circuit_name = 'RB.A34' \n",
    "campaign= 'Recommissioning post LS2' \n",
    "t_start = '2021-03-24 22:19:06.563000000'\n",
    "t_end = '2021-03-24 22:44:23.159000000'"
   ]
133
  },
134
135
136
137
138
139
140
141
142
  {
   "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))"
   ]
  },
143
144
145
146
147
148
149
150
151
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 2. Query All Signals Prior to Analysis"
   ]
  },
  {
   "cell_type": "code",
Michal Maciejewski's avatar
Michal Maciejewski committed
152
   "execution_count": null,
153
   "metadata": {
154
    "deleteable": false,
155
156
157
158
    "scrolled": false,
    "tags": [
     "skip_output"
    ]
159
   },
Michal Maciejewski's avatar
Michal Maciejewski committed
160
   "outputs": [],
161
   "source": [
162
163
164
165
166
167
168
169
170
171
172
173
174
    "circuit_type = 'RB'\n",
    "\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",
    "    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",
    "    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",
    "    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",
thbuffet's avatar
thbuffet committed
175
    "    print(t_start_ref, t_end_ref)\n",
176
177
178
    "    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",
    "\n",
179
180
    "rb_query = RbCircuitQuery(circuit_type, circuit_name, max_executions=30)\n",
    "rb_analysis = RbCircuitAnalysis(circuit_type, results_table=None, is_automatic=is_automatic)\n",
181
182
183
    "\n",
    "with Timer():\n",
    "    # PC\n",
184
185
    "    i_meas_nxcals_df = rb_query.query_signal_nxcals(t_start, t_end, t0=t_start, system='PC', signal_names='I_MEAS', spark=spark)[0] \n",
    "\n",
186
187
188
    "    source_timestamp_pc = rb_query.find_source_timestamp_pc(t_start, t_end)\n",
    "    timestamp_fgc = source_timestamp_pc.at[0, 'timestamp']\n",
    "    \n",
thbuffet's avatar
thbuffet committed
189
190
191
    "    source_timestamp_pc_ref = rb_query.find_source_timestamp_pc(t_start_ref, t_end_ref)\n",
    "    timestamp_fgc_ref = source_timestamp_pc_ref.at[0, 'timestamp']\n",
    "    \n",
192
193
    "    # PIC\n",
    "    timestamp_pic = rb_query.find_timestamp_pic(timestamp_fgc, spark=spark, duration=[(t_end-timestamp_fgc, 'ns')])\n",
thbuffet's avatar
thbuffet committed
194
    "    timestamp_pic_ref = rb_query.find_timestamp_pic(timestamp_fgc_ref, spark=spark, duration=[(t_end_ref-timestamp_fgc_ref, 'ns')])\n",
195
196
197
198
    "    i_a_df, i_ref_df = rb_query.query_pc_pm(timestamp_fgc, timestamp_fgc, signal_names=['I_A', 'I_REF'])\n",
    "    i_meas_df, i_earth_df, i_earth_pcnt_df, v_meas_df = rb_query.query_pc_pm(timestamp_fgc, min(timestamp_pic), signal_names=['I_MEAS', 'I_EARTH', 'I_EARTH_PCNT', 'V_MEAS'])\n",
    "    \n",
    "    # PC Reference\n",
Michal Maciejewski's avatar
Michal Maciejewski committed
199
200
    "    i_meas_nxcals_pic_sync_df = rb_query.query_signal_nxcals(t_start, t_end, t0=min(timestamp_pic), system='PC', signal_names='I_MEAS', spark=spark)[0]\n",
    "    i_meas_nxcals_pic_sync_ref_df = rb_query.query_signal_nxcals(t_start_ref, t_end_ref, t0=min(timestamp_pic_ref), system='PC', signal_names='I_MEAS', spark=spark)[0] \n",
201
202
203
204
205
206
207
    "    if isinstance(t_start_ref, int):\n",
    "        source_timestamp_pc_ref = rb_query.find_source_timestamp_pc(t_start_ref, t_end_ref)\n",
    "        timestamp_fgc_ref = source_timestamp_pc_ref.at[0, 'timestamp']\n",
    "    else:\n",
    "        timestamp_fgc_ref = float('nan')\n",
    "    \n",
    "    # PIC Reference\n",
thbuffet's avatar
thbuffet committed
208
    "    #timestamp_pic_ref = rb_query.find_timestamp_pic(timestamp_fgc_ref, spark=spark, duration=[(t_end_ref-timestamp_fgc_ref, 'ns')])\n",
209
210
    "    i_meas_ref_df = rb_query.query_pc_pm(timestamp_fgc_ref, min(timestamp_pic_ref), signal_names=['I_MEAS'])[0]\n",
    "    \n",
211
    "    # EE Voltage\n",
212
213
214
    "    source_timestamp_ee_odd_df = rb_query.find_source_timestamp_ee(timestamp_fgc, system='EE_ODD')\n",
    "    timestamp_ee_odd = source_timestamp_ee_odd_df.loc[0, 'timestamp']\n",
    "    source_ee_odd = source_timestamp_ee_odd_df.loc[0, 'source']\n",
215
    "    u_dump_res_odd_df = rb_query.query_ee_u_dump_res_pm(timestamp_ee_odd, min(timestamp_pic), system='EE_ODD', signal_names=['U_DUMP_RES'])[0]\n",
216
217
218
219
    "\n",
    "    source_timestamp_ee_even_df = rb_query.find_source_timestamp_ee(timestamp_fgc, system='EE_EVEN')\n",
    "    timestamp_ee_even = source_timestamp_ee_even_df.loc[0, 'timestamp']\n",
    "    source_ee_even = source_timestamp_ee_even_df.loc[0, 'source']\n",
220
    "    u_dump_res_even_df = rb_query.query_ee_u_dump_res_pm(timestamp_ee_even, min(timestamp_pic), system='EE_EVEN', signal_names=['U_DUMP_RES'])[0]\n",
221
    "    \n",
222
    "    # EE Temperature\n",
Michal Maciejewski's avatar
Michal Maciejewski committed
223
    "    t_res_odd_0_df = rb_query.query_ee_t_res_pm(source_timestamp_ee_odd_df.loc[0, 'timestamp'], min(timestamp_pic), signal_names=['T_RES_BODY_1', 'T_RES_BODY_2', 'T_RES_BODY_3'], system='EE_ODD')\n",
224
    "    if len(source_timestamp_ee_odd_df) > 1:\n",
Michal Maciejewski's avatar
Michal Maciejewski committed
225
    "        t_res_odd_1_df = rb_query.query_ee_t_res_pm(source_timestamp_ee_odd_df.loc[1, 'timestamp'], min(timestamp_pic), signal_names=['T_RES_BODY_1', 'T_RES_BODY_2', 'T_RES_BODY_3'], system='EE_ODD')\n",
226
227
    "    else:\n",
    "        t_res_odd_1_df = [pd.DataFrame(columns=['T_RES_BODY_1']), pd.DataFrame(columns=['T_RES_BODY_2']), pd.DataFrame(columns=['T_RES_BODY_3'])]\n",
Michal Maciejewski's avatar
Michal Maciejewski committed
228
229
    "    \n",
    "    t_res_even_0_df = rb_query.query_ee_t_res_pm(source_timestamp_ee_even_df.loc[0, 'timestamp'], min(timestamp_pic), signal_names=['T_RES_BODY_1', 'T_RES_BODY_2', 'T_RES_BODY_3'], system='EE_EVEN')\n",
230
    "    if len(source_timestamp_ee_even_df) > 1:\n",
Michal Maciejewski's avatar
Michal Maciejewski committed
231
    "        t_res_even_1_df = rb_query.query_ee_t_res_pm(source_timestamp_ee_even_df.loc[1, 'timestamp'], min(timestamp_pic), signal_names=['T_RES_BODY_1', 'T_RES_BODY_2', 'T_RES_BODY_3'], system='EE_EVEN')\n",
232
233
    "    else:\n",
    "        t_res_even_1_df = [pd.DataFrame(columns=['T_RES_BODY_1']), pd.DataFrame(columns=['T_RES_BODY_2']), pd.DataFrame(columns=['T_RES_BODY_3'])]\n",
234
235
236
237
238
239
240
241
242
243
244
    "\n",
    "    # EE Voltage Reference\n",
    "    if isinstance(t_start_ref, int):\n",
    "        source_timestamp_ee_odd_ref_df = rb_query.find_source_timestamp_ee(timestamp_fgc_ref, system='EE_ODD')\n",
    "        source_timestamp_ee_even_ref_df = rb_query.find_source_timestamp_ee(timestamp_fgc_ref, system='EE_EVEN')\n",
    "    \n",
    "        u_dump_res_odd_ref_df = rb_query.query_ee_u_dump_res_pm(source_timestamp_ee_odd_ref_df.loc[0, 'timestamp'], min(timestamp_pic_ref), system='EE_ODD', signal_names=['U_DUMP_RES'])[0]\n",
    "\n",
    "        u_dump_res_even_ref_df = rb_query.query_ee_u_dump_res_pm(source_timestamp_ee_even_ref_df.loc[0, 'timestamp'], min(timestamp_pic_ref), system='EE_EVEN', signal_names=['U_DUMP_RES'])[0]\n",
    "\n",
    "        # EE Temperature Reference\n",
Michal Maciejewski's avatar
Michal Maciejewski committed
245
    "        t_res_odd_0_ref_df = rb_query.query_ee_t_res_pm(source_timestamp_ee_odd_ref_df.loc[0, 'timestamp'], min(timestamp_pic_ref), signal_names=['T_RES_BODY_1', 'T_RES_BODY_2', 'T_RES_BODY_3'], system='EE_ODD')\n",
246
    "        if len(source_timestamp_ee_odd_ref_df) > 1:\n",
Michal Maciejewski's avatar
Michal Maciejewski committed
247
    "            t_res_odd_1_ref_df = rb_query.query_ee_t_res_pm(source_timestamp_ee_odd_ref_df.loc[1, 'timestamp'], min(timestamp_pic_ref), signal_names=['T_RES_BODY_1', 'T_RES_BODY_2', 'T_RES_BODY_3'], system='EE_ODD')\n",
248
249
    "        else:\n",
    "            t_res_odd_1_ref_df = [pd.DataFrame(columns=['T_RES_BODY_1']), pd.DataFrame(columns=['T_RES_BODY_2']), pd.DataFrame(columns=['T_RES_BODY_3'])]\n",
Michal Maciejewski's avatar
Michal Maciejewski committed
250
    "        t_res_even_0_ref_df = rb_query.query_ee_t_res_pm(source_timestamp_ee_even_ref_df.loc[0, 'timestamp'], min(timestamp_pic_ref), signal_names=['T_RES_BODY_1', 'T_RES_BODY_2', 'T_RES_BODY_3'], system='EE_EVEN')\n",
251
    "        if len(source_timestamp_ee_even_ref_df) > 1:\n",
Michal Maciejewski's avatar
Michal Maciejewski committed
252
    "            t_res_even_1_ref_df = rb_query.query_ee_t_res_pm(source_timestamp_ee_even_ref_df.loc[1, 'timestamp'], min(timestamp_pic_ref), signal_names=['T_RES_BODY_1', 'T_RES_BODY_2', 'T_RES_BODY_3'], system='EE_EVEN')\n",
253
254
    "        else:\n",
    "            t_res_even_1_ref_df = [pd.DataFrame(columns=['T_RES_BODY_1']), pd.DataFrame(columns=['T_RES_BODY_2']), pd.DataFrame(columns=['T_RES_BODY_3'])]\n",
255
256
257
    "    \n",
    "    # DFB\n",
    "    source_timestamp_leads_odd_df = rb_query.find_timestamp_leads(timestamp_fgc, 'LEADS_ODD')\n",
258
259
260
    "    t0 = t_start if source_timestamp_leads_odd_df.empty else timestamp_fgc\n",
    "    u_hts_odd_dfs = rb_query.query_leads(t0, source_timestamp_leads_odd_df, system='LEADS_ODD', signal_names=['U_HTS'], spark=spark, duration=[(t_end-t_start, 'ns')])\n",
    "    u_res_odd_dfs = rb_query.query_leads(t0, source_timestamp_leads_odd_df, system='LEADS_ODD', signal_names=['U_RES'], spark=spark, duration=[(t_end-t_start, 'ns')])\n",
261
262
    "\n",
    "    source_timestamp_leads_even_df = rb_query.find_timestamp_leads(timestamp_fgc, 'LEADS_EVEN')\n",
263
264
265
266
267
    "    t0 = t_start if source_timestamp_leads_even_df.empty else timestamp_fgc\n",
    "    u_hts_even_dfs = rb_query.query_leads(t_start, source_timestamp_leads_even_df, system='LEADS_EVEN', signal_names=['U_HTS'], spark=spark, duration=[(t_end-t_start, 'ns')])\n",
    "    u_res_even_dfs = rb_query.query_leads(t_start, source_timestamp_leads_even_df, system='LEADS_EVEN', signal_names=['U_RES'], spark=spark, duration=[(t_end-t_start, 'ns')])\n",
    "    \n",
    "    timestamp_dct = {'FGC': timestamp_fgc, 'PIC': min(timestamp_pic), 'EE_EVEN': timestamp_ee_even, 'EE_ODD': timestamp_ee_odd, 'LEADS_ODD': source_timestamp_leads_odd_df, 'LEADS_EVEN': source_timestamp_leads_even_df}"
268
269
270
271
   ]
  },
  {
   "cell_type": "markdown",
272
273
274
   "metadata": {
    "deletable": false
   },
275
276
277
278
279
280
   "source": [
    "# 3. Timestamps"
   ]
  },
  {
   "cell_type": "code",
Michal Maciejewski's avatar
Michal Maciejewski committed
281
   "execution_count": null,
282
   "metadata": {
283
    "deletable": false
284
   },
Michal Maciejewski's avatar
Michal Maciejewski committed
285
   "outputs": [],
286
287
288
289
290
291
   "source": [
    "rb_analysis.create_timestamp_table(timestamp_dct)"
   ]
  },
  {
   "cell_type": "markdown",
292
293
294
   "metadata": {
    "deletable": false
   },
295
296
297
298
   "source": [
    "# 4. Power Converter\n",
    "## 4.1. Plot of the Power Converter Main Current\n",
    "\n",
299
300
    "*GRAPHS*:\n",
    "\n",
301
    "- t = 0 s corresponds to the start of the test"
302
303
304
305
   ]
  },
  {
   "cell_type": "code",
Michal Maciejewski's avatar
Michal Maciejewski committed
306
   "execution_count": null,
307
   "metadata": {
308
    "deletable": false
309
   },
Michal Maciejewski's avatar
Michal Maciejewski committed
310
   "outputs": [],
311
   "source": [
312
313
314
315
316
317
318
319
    "import matplotlib as mpl\n",
    "mpl.rcParams['savefig.dpi'] = 80\n",
    "mpl.rcParams['figure.dpi'] = 80\n",
    "%matplotlib notebook\n",
    "title = create_hwc_plot_title_with_circuit_name(circuit_name=circuit_name, hwc_test=hwc_test, t_start=t_start, t_end=t_end, signal='I_MEAS')\n",
    "rb_analysis.plot_i_meas(i_meas_nxcals_df, title=title)"
   ]
  },
Michal Maciejewski's avatar
Michal Maciejewski committed
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- t = 0 s corresponds to PIC timestamp\n",
    "\n",
    "Delay between powering failure and EE may be different"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "i_meas_nxcals_pic_sync_df.rename(columns={'I_MEAS': '%s:I_MEAS' % circuit_name}, inplace=True)\n",
    "i_meas_nxcals_pic_sync_ref_df.rename(columns={'I_MEAS': '%s:I_MEAS_REF' % circuit_name}, inplace=True)\n",
    "ax = i_meas_nxcals_pic_sync_df.plot(figsize=(13.5, 6))\n",
    "i_meas_nxcals_pic_sync_ref_df.plot(ax=ax, grid=True, title=title)\n",
    "ax.set_xlabel('Time, [s]', fontsize=15)\n",
    "ax.set_ylabel('I, [A]', fontsize=15)\n",
    "ax.title.set_size(20)\n",
    "ax.tick_params(labelsize=15)"
   ]
  },
347
348
  {
   "cell_type": "markdown",
349
350
351
   "metadata": {
    "deletable": false
   },
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
   "source": [
    "## 4.2. Analysis of the Power Converter Main Current\n",
    "This analysis module displays the main current of the power converter (I_MEAS) compared to the one obtained from the reference FPA (HWC PNO.b2 test with opening of EE systems and without magnet quench).\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{\\text{I_MEAS}}{\\partial_t \\text{I_MEAS}}\n",
    "\\end{equation}\n",
    "\n",
    "*CRITERIA*  \n",
    "- Check if the characteristic time of pseudo-exponential decay of I_MEAS from t=1 to 120 s is 90 s< Tau <110 s\n",
    "\n",
    "*PLOT*:\n",
    "- The main power converter current (analyzed and reference) on the left axis, I_MEAS\n",
    "- The characteristic time calculated for the main current (reference and actual) on the right axis, -I_MEAS/dI_MEAS_dt \n",
    "The actual characteristic time contains steps, which indicate a quenching magnet (decrease of circuit inductance); note that for the reference one the steps are not present. Timing of PIC abort, FGC timestamp, and the maximum current are reported next to the graph.\n",
    "- t = 0 s corresponds to the respective (analyzed and reference) FGC timestamps."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
379
380
381
   "metadata": {
    "deletable": false
   },
382
383
384
385
386
387
388
   "outputs": [],
   "source": [
    "rb_analysis.analyze_i_meas_pc(circuit_name, timestamp_fgc, timestamp_fgc_ref, min(timestamp_pic), i_meas_df, i_meas_ref_df)"
   ]
  },
  {
   "cell_type": "markdown",
389
390
391
   "metadata": {
    "deletable": false
   },
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
   "source": [
    "## 4.3. Analysis of the Power Converter Main Current Smoothness\n",
    "\n",
    "*ANALYSIS*:\n",
    "- The current smoothness is evaluated on the basis of its second derivative. The derivative is calculated as a rolling division of current and time differences. The rolling window is fixed and equal to 10 points; with the sampling time equal to 0.1 s the time difference is equal to $dt=1 s$.\n",
    "\\begin{equation}\n",
    "\\frac{d i(t)}{dt} = \\frac{i(t+dt)-i(t)}{dt}\n",
    "\\end{equation}\n",
    "To obtain the second derivative of the current decay, the formula above is applied twice to the current profile from PM after the second EE opening (for t > 1 s).\n",
    "\n",
    "*CRITERIA*  \n",
    "- Check if the second derivative of the current decay of I_MEAS from t = 1 s is -10 A/s^2< dI_MEAS/dt^2 < 10 A/s^2\n",
    "\n",
    "*PLOT*:\n",
    "- The second derivative of the main power converter current on the left axis, dI_MEAS/dt^2\n",
    "- Green bar denotes the acceptance threshold for the second derivative of the main power converter current\n",
408
    "- t = 0 s corresponds to the PM timestamp of the FGC"
409
410
411
412
413
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
414
   "metadata": {
thbuffet's avatar
thbuffet committed
415
416
    "deletable": false,
    "scrolled": true
417
   },
418
419
420
421
422
423
424
425
   "outputs": [],
   "source": [
    "title = create_hwc_plot_title_with_circuit_name(circuit_name=circuit_name, hwc_test=hwc_test, t_start=t_start, t_end=t_end, signal='I_MEAS smoothness')\n",
    "rb_analysis.plot_i_meas_smoothness(i_meas_df, title=title)"
   ]
  },
  {
   "cell_type": "markdown",
426
427
428
   "metadata": {
    "deletable": false
   },
429
430
431
   "source": [
    "## 4.4. Power Converter Voltage Analysis\n",
    "*CRITERIA*\n",
thbuffet's avatar
thbuffet committed
432
    "- Check if the V_MEAS voltage is within -3.7 +/- 0.5 V range 1 s after the EE timestamp, assuming that I_MEAS = ~9 kA.\n",
433
434
435
436
437
438
439
440
    "\n",
    "*GRAPHS*\n",
    "- t = 0 s corresponds to the PM timestamp of the FGC"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
441
442
443
   "metadata": {
    "deletable": false
   },
444
445
446
   "outputs": [],
   "source": [
    "title = create_hwc_plot_title_with_circuit_name(circuit_name=circuit_name, hwc_test=hwc_test, t_start=t_start, t_end=t_end, signal='V_MEAS')\n",
thbuffet's avatar
thbuffet committed
447
    "rb_analysis.assert_v_meas(timestamp_ee_even, min(timestamp_pic), t_after_ee=1, v_meas_df=v_meas_df, value_min=-4.2, value_max=-3.2, title=title, xmax=15)"
448
449
450
451
   ]
  },
  {
   "cell_type": "markdown",
452
453
454
   "metadata": {
    "deletable": false
   },
455
   "source": [
456
457
    "# 5. Energy Extraction System\n",
    "## 5.1. Analysis of the Energy Extraction Voltage\n",
458
459
460
    "\n",
    "*ANALYSIS*:\n",
    "\n",
461
    "- Calculate U_dump_res (t=0)\n",
462
    "- Calculate the characteristic time of pseudo-exponential current decay with the charge approach\n",
463
    "\n",
464
    "*CRITERIA*:\n",
465
    "\n",
466
    "- Check if U_DUMP_RES (t=0) = (±10%) U_DUMP_RES reference.\n",
467
468
    "- Check if the timestamp difference between FGC and EE an odd point is 100±50 ms  \n",
    "  The opening delay was 300±50 ms prior to YETS 2017/8\n",
469
470
    "- Check if the time stamp difference between FGC and EE an even point: 600±50 ms\n",
    "\n",
471
472
473
    "*WARNING*:\n",
    "- Check if the characteristic time of pseudo-exponential decay of I_MEAS from t=1 to 120 s is 110 s<-Tau <130 s\n",
    "\n",
474
475
    "*GRAPHS*:\n",
    "\n",
476
477
478
479
480
481
482
483
484
485
486
    "- 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, 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 two energy extraction voltages on the right axis, U_DUMP_RES, U_DUMP_RES\n",
    "- the green dashed line denotes the PIC timestamp"
487
488
489
490
   ]
  },
  {
   "cell_type": "code",
Michal Maciejewski's avatar
Michal Maciejewski committed
491
   "execution_count": null,
492
   "metadata": {
493
    "deletable": false
494
   },
Michal Maciejewski's avatar
Michal Maciejewski committed
495
   "outputs": [],
496
497
498
499
   "source": [
    "rb_analysis.analyze_char_time_u_dump_res_ee(circuit_name, timestamp_fgc, [u_dump_res_odd_df, u_dump_res_even_df], i_meas_df)"
   ]
  },
500
501
502
503
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
504
    "deletable": false
505
506
507
   },
   "outputs": [],
   "source": [
508
    "rb_analysis.analyze_delay_time_u_dump_res_ee(circuit_name, min(timestamp_pic), min(timestamp_pic), [timestamp_ee_odd, timestamp_ee_even],\n",
509
510
511
    "                                             i_a_df, i_ref_df, [u_dump_res_odd_df, u_dump_res_even_df])"
   ]
  },
512
513
514
515
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
516
    "deletable": false
517
518
519
520
521
522
523
524
525
   },
   "outputs": [],
   "source": [
    "rb_analysis.compare_max_u_res_dump_to_reference(u_dump_res_odd_df, u_dump_res_odd_ref_df, 'U_DUMP_RES_ODD')\n",
    "rb_analysis.compare_max_u_res_dump_to_reference(u_dump_res_even_df, u_dump_res_even_ref_df, 'U_DUMP_RES_EVEN')"
   ]
  },
  {
   "cell_type": "markdown",
526
527
528
   "metadata": {
    "deletable": false
   },
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
   "source": [
    "## 5.2.  Analysis of the Energy Extraction Temperature\n",
    "\n",
    "*WARNING*\n",
    "- Check if temperature profile is +/-25 K w.r.t. the reference temperature profile\n",
    "\n",
    "*PLOT*:\n",
    "\n",
    "- Temperature signals on the left axis, T\n",
    "- A reference signal with an acceptable signal range is also provided on the left axis\n",
    "- t = 0 s corresponds to PM timestamps of each temperature PM entry"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
545
546
547
   "metadata": {
    "deletable": false
   },
548
549
550
551
552
553
554
555
556
   "outputs": [],
   "source": [
    "rb_analysis.plot_ee_temp(circuit_name + '_EE_ODD', timestamp_ee_odd, t_res_odd_0_df + t_res_odd_1_df, t_res_odd_0_ref_df + t_res_odd_1_ref_df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
Michal Maciejewski's avatar
Michal Maciejewski committed
557
558
    "deletable": false,
    "scrolled": false
559
560
561
562
563
564
565
566
567
   },
   "outputs": [],
   "source": [
    "rb_analysis.analyze_ee_temp(circuit_name + '_EE_ODD', timestamp_ee_odd, t_res_odd_0_df + t_res_odd_1_df, t_res_odd_0_ref_df + t_res_odd_1_ref_df, abs_margin=25, scaling=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
568
569
570
   "metadata": {
    "deletable": false
   },
571
572
573
574
575
576
577
578
579
   "outputs": [],
   "source": [
    "rb_analysis.plot_ee_temp(circuit_name + '_EE_EVEN', timestamp_ee_even, t_res_even_0_df + t_res_even_1_df, t_res_even_0_ref_df + t_res_even_1_ref_df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
580
    "deletable": false
581
582
583
584
585
586
   },
   "outputs": [],
   "source": [
    "rb_analysis.analyze_ee_temp(circuit_name + '_EE_EVEN', timestamp_ee_even, t_res_even_0_df + t_res_even_1_df, t_res_even_0_ref_df + t_res_even_1_ref_df, abs_margin=25, scaling=1)"
   ]
  },
587
588
  {
   "cell_type": "markdown",
589
590
591
   "metadata": {
    "deletable": false
   },
592
   "source": [
593
594
    "# 6. Current Leads\n",
    "## 6.1. Plot of Current Leads\n",
595
    "\n",
596
    "*CRITERIA*:\n",
597
    "\n",
598
599
    "- 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",
600
    "\n",
601
    "*GRAPHS*:\n",
602
    "\n",
603
    "- t = 0 s corresponds to the FGC timestamp"
604
605
606
607
   ]
  },
  {
   "cell_type": "code",
Michal Maciejewski's avatar
Michal Maciejewski committed
608
   "execution_count": null,
609
   "metadata": {
610
    "deletable": false
611
612
613
   },
   "outputs": [],
   "source": [
614
    "timestamp = t_start if source_timestamp_leads_odd_df.empty else source_timestamp_leads_odd_df.loc[0, 'timestamp']\n",
Michal Maciejewski's avatar
Michal Maciejewski committed
615
    "rb_analysis.analyze_leads_voltage(u_hts_odd_dfs, circuit_name, timestamp, signal='U_HTS', value_min=-0.003, value_max=0.003)"
616
617
618
619
620
621
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
622
    "deletable": false
623
624
625
626
   },
   "outputs": [],
   "source": [
    "timestamp = t_start if source_timestamp_leads_even_df.empty else source_timestamp_leads_even_df.loc[0, 'timestamp']\n",
thbuffet's avatar
thbuffet committed
627
    "rb_analysis.analyze_leads_voltage(u_hts_even_dfs, circuit_name, timestamp, signal='U_HTS', value_min=-0.003, value_max=0.003)"
628
629
630
631
632
633
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
634
    "deletable": false
635
636
637
638
639
640
641
642
643
644
645
   },
   "outputs": [],
   "source": [
    "timestamp = t_start if source_timestamp_leads_odd_df.empty else source_timestamp_leads_odd_df.loc[0, 'timestamp']\n",
    "rb_analysis.analyze_leads_voltage(u_res_odd_dfs, circuit_name, timestamp, signal='U_RES', value_min=-0.1, value_max=0.1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
646
    "deletable": false
647
   },
Michal Maciejewski's avatar
Michal Maciejewski committed
648
   "outputs": [],
649
   "source": [
650
651
    "timestamp = t_start if source_timestamp_leads_even_df.empty else source_timestamp_leads_even_df.loc[0, 'timestamp']\n",
    "rb_analysis.analyze_leads_voltage(u_res_even_dfs, circuit_name, timestamp, signal='U_RES', value_min=-0.1, value_max=0.1)"
652
653
654
655
   ]
  },
  {
   "cell_type": "markdown",
656
657
658
   "metadata": {
    "deletable": false
   },
659
   "source": [
660
    "# 7. Signature Decision"
661
662
663
664
   ]
  },
  {
   "cell_type": "code",
Michal Maciejewski's avatar
Michal Maciejewski committed
665
   "execution_count": null,
666
667
668
   "metadata": {
    "deletable": false
   },
669
670
671
672
673
674
675
   "outputs": [],
   "source": [
    "signature = get_expert_decision('Expert Signature Decision: ', ['PASSED', 'FAILED'])"
   ]
  },
  {
   "cell_type": "markdown",
676
677
678
   "metadata": {
    "deletable": false
   },
679
680
681
682
683
684
685
   "source": [
    "# 8. Final Report"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
686
687
688
   "metadata": {
    "deletable": false
   },
Michal Maciejewski's avatar
Michal Maciejewski committed
689
   "outputs": [],
690
   "source": [
691
    "analysis_start_time = Time.get_analysis_start_time()\n",
692
    "apply_report_template()\n",
693
694
695
    "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/RB/{}/{}/{}'.format(circuit_name, hwc_test, file_name_html)\n",
    "!mkdir -p /eos/project/m/mp3/RB/$circuit_name/$hwc_test\n",
696
697
    "print('Compact notebook report saved to (Windows): ' + '\\\\\\\\cernbox-smb' + full_path.replace('/', '\\\\'))\n",
    "display(Javascript('IPython.notebook.save_notebook();'))\n",
698
    "Time.sleep(5)\n",
699
    "!{sys.executable} -m jupyter nbconvert --to html $'AN_RB_PLI3.d2.ipynb' --output /eos/project/m/mp3/RB/$circuit_name/$hwc_test/$file_name_html --TemplateExporter.exclude_input=True --TagRemovePreprocessor.remove_all_outputs_tags='[\"skip_output\"]'"
700
   ]
Michal Maciejewski's avatar
Michal Maciejewski committed
701
702
703
704
705
706
707
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
708
709
710
711
712
713
714
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",
   "version": "3.6.5"
  },
  "sparkconnect": {
   "bundled_options": [
    "NXCALS",
    "SparkMetrics"
   ],
Michal Maciejewski's avatar
Michal Maciejewski committed
733
   "list_of_options": []
734
735
736
737
738
739
740
741
742
743
744
745
746
  },
  "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
747
748
749
750
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
Michal Maciejewski's avatar
Michal Maciejewski committed
751
}