HWC_IPQ_QHDA.ipynb 9.48 KB
Newer Older
1
2
3
4
5
6
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
7
    "<h1><center>Analysis of a QH discharge in an IPQ Circuit</center></h1>"
8
9
10
11
12
13
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
14
    "# 0. Initialise Working Environment"
15
16
17
18
   ]
  },
  {
   "cell_type": "code",
19
   "execution_count": null,
20
21
22
   "metadata": {},
   "outputs": [],
   "source": [
23
    "# External libraries\n",
Agata Malgorzata Chadaj's avatar
WIP    
Agata Malgorzata Chadaj committed
24
25
26
    "print('Loading (1/16)'); import sys; import pandas as pd\n",
    "print('Loading (2/16)'); from multiprocessing import Pool\n",
    "print('Loading (3/16)'); from IPython.display import display, HTML, Javascript, clear_output\n",
27
    "\n",
28
    "# Internal libraries\n",
Agata Malgorzata Chadaj's avatar
WIP    
Agata Malgorzata Chadaj committed
29
30
31
32
33
34
35
36
37
38
39
40
41
42
    "print('Loading (4/16)'); import lhcsmapi\n",
    "print('Loading (5/16)'); from lhcsmapi.Time import Time\n",
    "print('Loading (6/16)'); from lhcsmapi.Timer import Timer\n",
    "print('Loading (7/16)'); from lhcsmapi.analysis.IpqCircuitQuery import IpqCircuitQuery\n",
    "print('Loading (8/16)'); from lhcsmapi.analysis.IpqCircuitAnalysis import IpqCircuitAnalysis\n",
    "print('Loading (9/16)'); from lhcsmapi.analysis.expert_input import check_show_next, get_expert_decision\n",
    "print('Loading (10/16)'); from lhcsmapi.analysis.qh.QuenchHeaterQuery import QuenchHeaterQuery\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.hwc.HwcSearchModuleMediator import HwcSearchModuleMediator\n",
    "print('Loading (14/16)'); from lhcsmapi.gui.qh.QhPmSearchModuleMediator import QhPmSearchModuleMediator\n",
    "print('Loading (15/16)'); from lhcsmapi.metadata.SignalMetadata import SignalMetadata\n",
    "print('Loading (16/16)'); from lhcsmnb.parameters import are_all_parameters_injected, get_source_timestamp_df, NbType\n",
    "\n",
43
    "\n",
44
45
    "clear_output()\n",
    "lhcsmapi.get_lhcsmapi_version()\n",
46
47
    "lhcsmapi.get_lhcsmhwc_version('../__init__.py')\n",
    "print('Analysis performed by %s' % HwcSearchModuleMediator.get_user())"
48
49
50
51
52
53
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
54
    "# 1. Find QH Post Mortem Entries"
55
56
57
58
   ]
  },
  {
   "cell_type": "code",
59
   "execution_count": null,
Aleksandra Mnich's avatar
Aleksandra Mnich committed
60
61
62
63
64
   "metadata": {
    "tags": [
     "parameters"
    ]
   },
65
   "outputs": [],
66
   "source": [
Agata Malgorzata Chadaj's avatar
WIP    
Agata Malgorzata Chadaj committed
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
    "circuit_type = 'IPQ'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "with Timer():\n",
    "    if not are_all_parameters_injected(NbType.QH, locals()):\n",
    "        qh_pm_search = QhPmSearchModuleMediator(DateTimeBaseModule(start_date_time='2021-01-12 00:00:00+01:00', end_date_time=Time.to_string(Time.now())), circuit_type=circuit_type)\n",
    "    else:\n",
    "        circuit_sub_type = SignalMetadata.get_circuit_type_for_circuit_name(circuit_name)\n",
    "        source_timestamp_df = QuenchHeaterQuery(circuit_sub_type, circuit_name).find_source_timestamp_qh_with_pattern('*', start_time, end_time)\n",
    "        display(HTML(source_timestamp_df.to_html()))"
83
84
85
86
87
88
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
89
    "# 2. Query All Signals Prior to Analysis"
90
91
92
93
   ]
  },
  {
   "cell_type": "code",
94
   "execution_count": null,
95
   "metadata": {},
96
   "outputs": [],
97
   "source": [
98
    "with Timer():\n",
Agata Malgorzata Chadaj's avatar
WIP    
Agata Malgorzata Chadaj committed
99
    "    if not are_all_parameters_injected(NbType.QH, locals()):\n",
Aleksandra Mnich's avatar
Aleksandra Mnich committed
100
101
102
103
104
105
106
107
108
109
    "        circuit_name = qh_pm_search.get_circuit_name()\n",
    "        discharge_level = qh_pm_search.get_discharge_level()\n",
    "        source_timestamp_df = qh_pm_search.source_timestamp_df\n",
    "        is_automatic = qh_pm_search.is_automatic_mode()\n",
    "        \n",
    "    ipq_query = IpqCircuitQuery(circuit_type, circuit_name)\n",
    "    ipq_analysis = IpqCircuitAnalysis(circuit_type, None, circuit_name=circuit_name)\n",
    "        \n",
    "    u_hds_dfss = ipq_query.query_qh_pm(source_timestamp_df, signal_names=['U_HDS'])\n",
    "    u_hds_ref_dfss = ipq_query.query_qh_pm(source_timestamp_df, signal_names=['U_HDS'], is_ref=True)"
110
111
112
113
114
115
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
116
117
118
119
120
121
122
123
124
125
126
127
    "# 3. Quench Heaters\n",
    "\n",
    "*CRITERIA*:\n",
    "- all characteristic times of an exponential decay calculated with the 'charge' approach for voltage is +/- 5 ms from the reference ones\n",
    "- the initial voltage should be between 810 V and 1000 V\n",
    "- the final voltage should be between 0 V and 10 V\n",
    "\n",
    "*GRAPHS*:  \n",
    "- t = 0 s corresponds to the start of the pseudo-exponential decay\n",
    "\n",
    "Voltage view (linear and log)\n",
    "- the queried and filtered quench heater voltage on the left axis (actual signal continuous, reference dashed), U_HDS"
128
129
130
131
   ]
  },
  {
   "cell_type": "code",
132
   "execution_count": null,
133
134
135
   "metadata": {
    "scrolled": false
   },
136
   "outputs": [],
137
   "source": [
138
139
    "index = 0\n",
    "for u_hds_dfs, u_hds_ref_dfs in zip(u_hds_dfss, u_hds_ref_dfss):\n",
Aleksandra Mnich's avatar
Aleksandra Mnich committed
140
    "    print(index, source_timestamp_df.loc[index, 'timestamp'])\n",
141
    "    if u_hds_dfs:\n",
Agata Malgorzata Chadaj's avatar
WIP    
Agata Malgorzata Chadaj committed
142
    "        ipq_analysis.analyze_single_qh_voltage_with_ref(circuit_name, source_timestamp_df.loc[index, 'timestamp'], u_hds_dfs, u_hds_ref_dfs, nominal_voltage=discharge_level)\n",
143
144
    "    else:\n",
    "        print(f\"No Quench Heater Discharges!\")\n",
145
    "    index += 1"
146
147
148
149
   ]
  },
  {
   "cell_type": "markdown",
Aleksandra Mnich's avatar
Aleksandra Mnich committed
150
151
152
153
154
   "metadata": {
    "tags": [
     "ignore"
    ]
   },
155
   "source": [
156
157
158
159
160
    "# 4. Signature Decision"
   ]
  },
  {
   "cell_type": "markdown",
Aleksandra Mnich's avatar
Aleksandra Mnich committed
161
162
163
164
165
   "metadata": {
    "tags": [
     "ignore"
    ]
   },
166
167
   "source": [
    "# 5. Final Report"
168
169
170
171
172
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
Aleksandra Mnich's avatar
Aleksandra Mnich committed
173
174
175
176
177
   "metadata": {
    "tags": [
     "ignore"
    ]
   },
178
179
   "outputs": [],
   "source": [
Aleksandra Mnich's avatar
Aleksandra Mnich committed
180
    "if not source_timestamp_df.empty:\n",
181
    "    analysis_start_time = Time.get_analysis_start_time()\n",
182
    "    prefix_circuit_name = circuit_name.split('.')[0]\n",
Aleksandra Mnich's avatar
Aleksandra Mnich committed
183
    "    date_time_qh = Time.to_datetime(source_timestamp_df.loc[0, 'timestamp']).strftime(\"%Y-%m-%d-%Hh%M\")\n",
184
185
186
    "\n",
    "    apply_report_template()\n",
    "    !mkdir -p /eos/project/m/mp3/IPQ/$prefix_circuit_name/$circuit_name/QHDA\n",
187
    "    file_name_html = \"{}_QHDA-{}-{}_{}.html\".format(circuit_name, date_time_qh, analysis_start_time, signature)\n",
188
189
190
191
192
    "    full_path = '/eos/project/m/mp3/IPQ/{}/{}/QHDA/{}'.format(prefix_circuit_name, circuit_name, file_name_html)\n",
    "    print('Compact notebook report saved to (Windows): ' + '\\\\\\\\cernbox-smb' + full_path.replace('/', '\\\\'))\n",
    "    display(Javascript('IPython.notebook.save_notebook();'))\n",
    "    Time.sleep(5)\n",
    "    !{sys.executable} -m jupyter nbconvert --to html $'HWC_IPQ_QHDA.ipynb' --output /eos/project/m/mp3/IPQ/$prefix_circuit_name/$circuit_name/QHDA/$file_name_html --TemplateExporter.exclude_input=True --TagRemovePreprocessor.remove_all_outputs_tags='[\"skip_output\"]' --TagRemovePreprocessor.remove_cell_tags='[\"skip_cell\"]'"
193
   ]
194
  },
195
196
  {
   "cell_type": "markdown",
Aleksandra Mnich's avatar
Aleksandra Mnich committed
197
198
199
200
201
   "metadata": {
    "tags": [
     "ignore"
    ]
   },
202
203
204
205
   "source": [
    "# 6. Save Timestamps in Reference Format (if update needed)"
   ]
  },
206
207
208
  {
   "cell_type": "code",
   "execution_count": null,
Aleksandra Mnich's avatar
Aleksandra Mnich committed
209
210
211
212
213
   "metadata": {
    "tags": [
     "ignore"
    ]
   },
214
   "outputs": [],
215
   "source": [
Aleksandra Mnich's avatar
Aleksandra Mnich committed
216
    "if not source_timestamp_df.empty:\n",
217
218
219
220
221
    "    analysis_start_time = Time.get_analysis_start_time()\n",
    "    prefix_circuit_name = circuit_name.split('.')[0]\n",
    "    !mkdir -p /eos/project/m/mp3/IPQ/$prefix_circuit_name/$circuit_name/QHDA\n",
    "    file_name = \"{}_QHDA-{}-{}_Reference\".format(circuit_name, date_time_qh, analysis_start_time)\n",
    "    csv_full_path = '/eos/project/m/mp3/IPQ/{}/{}/QHDA/{}.csv'.format(prefix_circuit_name, circuit_name, file_name)\n",
Aleksandra Mnich's avatar
Aleksandra Mnich committed
222
223
224
    "    cell_datetime_timestamp = pd.DataFrame(source_timestamp_df.rename(columns={'source': 'Cell'})['Cell'])\n",
    "    cell_datetime_timestamp['Timestamp String'] = source_timestamp_df['timestamp'].apply(lambda col: Time.to_string_short(col, n_dec_digits=9))\n",
    "    cell_datetime_timestamp['Timestamp'] = source_timestamp_df['timestamp']\n",
225
226
    "    cell_datetime_timestamp.to_csv(csv_full_path, index=False)\n",
    "    print('Reference timestamp table saved to (Windows): ' + '\\\\\\\\cernbox-smb' + csv_full_path.replace('/', '\\\\'))"
227
   ]
Agata Malgorzata Chadaj's avatar
WIP    
Agata Malgorzata Chadaj committed
228
  },
Agata Malgorzata Chadaj's avatar
wip    
Agata Malgorzata Chadaj committed
229
230
231
232
233
234
235
236
237
238
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": [
     "result"
    ]
   },
   "outputs": [],
   "source": [
Agata Malgorzata Chadaj's avatar
wip    
Agata Malgorzata Chadaj committed
239
    "ipq_analysis.get_status()"
Agata Malgorzata Chadaj's avatar
wip    
Agata Malgorzata Chadaj committed
240
241
   ]
  },
Agata Malgorzata Chadaj's avatar
WIP    
Agata Malgorzata Chadaj committed
242
243
244
245
246
247
248
249
250
251
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": [
     "result"
    ]
   },
   "outputs": [],
   "source": [
Agata Malgorzata Chadaj's avatar
WIP    
Agata Malgorzata Chadaj committed
252
    "ipq_analysis.get_analysis_result()"
Agata Malgorzata Chadaj's avatar
WIP    
Agata Malgorzata Chadaj committed
253
   ]
254
255
256
  }
 ],
 "metadata": {
Agata Malgorzata Chadaj's avatar
WIP    
Agata Malgorzata Chadaj committed
257
  "celltoolbar": "Tags",
258
  "kernelspec": {
259
   "display_name": "Python 3",
260
261
262
263
264
265
266
267
268
269
270
271
272
   "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",
Agata Malgorzata Chadaj's avatar
WIP    
Agata Malgorzata Chadaj committed
273
   "version": "3.8.6"
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
  },
  "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
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}