HWC_QHD_PM_LIST.ipynb 14.8 KB
Newer Older
1
2
3
4
5
6
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
7
    "# Notebook to list QHD PM timestamps by circuit type and time range"
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": 1,
20
   "metadata": {},
thbuffet's avatar
thbuffet committed
21
   "outputs": [
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "`np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.\n",
      "Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n",
      "`np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.\n",
      "Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n",
      "`np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.\n",
      "Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n",
      "`np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.\n",
      "Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n",
      "`np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.\n",
      "Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n",
      "`np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.\n",
      "Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n",
      "`np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.\n",
      "Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n",
      "`np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.\n",
      "Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n",
      "`np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.\n",
      "Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n"
     ]
    },
thbuffet's avatar
thbuffet committed
46
47
48
49
50
51
52
53
54
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Analysis executed with lhc-sm-api version: 1.5.17\n",
      "Analysis executed with lhc-sm-hwc notebooks version: 1.5.65\n"
     ]
    }
   ],
55
   "source": [
56
57
58
59
    "import os, sys, warnings\n",
    "import pandas as pd\n",
    "from IPython.display import display, HTML, Javascript, clear_output, Markdown\n",
    "#\n",
60
61
62
63
    "import lhcsmapi\n",
    "from lhcsmapi.Time import Time\n",
    "from lhcsmapi.Timer import Timer\n",
    "from lhcsmapi.pyedsl.QueryBuilder import QueryBuilder\n",
64
65
    "from lhcsmapi.analysis.RbCircuitQuery import RbCircuitQuery\n",
    "from lhcsmapi.analysis.RqCircuitQuery import RqCircuitQuery\n",
66
67
68
69
    "from lhcsmapi.analysis.IpqCircuitQuery import IpqCircuitQuery\n",
    "from lhcsmapi.analysis.IpdCircuitQuery import IpdCircuitQuery\n",
    "from lhcsmapi.analysis.ItCircuitQuery import ItCircuitQuery\n",
    "from lhcsmapi.metadata.SignalMetadata import SignalMetadata\n",
70
    "from lhcsmapi.analysis.report_template import apply_report_template\n",
71
72
73
74
75
76
77
78
79
80
    "\n",
    "analysis_start_time = Time.get_analysis_start_time()\n",
    "lhcsmapi.get_lhcsmapi_version()\n",
    "lhcsmapi.get_lhcsmhwc_version('../__init__.py')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
81
    "# 1.  User Input (circuit types: RB, RQ, IPQ, IPD, IT)"
82
83
84
85
   ]
  },
  {
   "cell_type": "code",
86
   "execution_count": 2,
87
88
89
   "metadata": {},
   "outputs": [],
   "source": [
thbuffet's avatar
thbuffet committed
90
91
92
93
94
95
96
97
    "detailed_circuit_types = {\n",
    "    'RB': ['RB'],\n",
    "    'RQ': ['RQ'],\n",
    "    'IPQ': ['IPQ2', 'IPQ4', 'IPQ8'],\n",
    "    'IPD': ['IPD2', 'IPD2_B1B2'],\n",
    "    'IT': ['IT']\n",
    "}\n",
    "\n",
98
    "start_time = '2021-10-18 07:00:00'\n",
thbuffet's avatar
thbuffet committed
99
    "stop_time  = '2021-10-20 23:01:00'\n"
100
101
102
103
   ]
  },
  {
   "cell_type": "code",
104
   "execution_count": 3,
105
   "metadata": {},
thbuffet's avatar
thbuffet committed
106
107
108
109
110
111
112
113
114
115
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "start_time =  2021-10-18 07:00:00\n",
      "stop_time =  2021-10-20 23:01:00\n"
     ]
    }
   ],
116
   "source": [
117
118
119
120
121
122
123
124
125
126
127
128
129
    "print('start_time = ', start_time)\n",
    "print('stop_time = ', stop_time)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 2.  Search for PMs"
   ]
  },
  {
   "cell_type": "code",
130
   "execution_count": 6,
131
132
133
   "metadata": {
    "scrolled": false
   },
thbuffet's avatar
thbuffet committed
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "RB\n",
      "  source            timestamp\n",
      "0  A28L3  1634542949913000000\n",
      "1  B29L3  1634542949913000000\n",
      "2  C28L3  1634542949913000000\n",
      "  source            timestamp\n",
      "0  B15R5  1634605470606000000\n",
      "1  B15R5  1634607003034000000\n",
      "2  B15R5  1634646052393000000\n",
      "RQ\n",
      "  source            timestamp\n",
      "0   27L3  1634542916538649604\n",
      "IPQ\n",
152
153
      "IPD\n",
      "IT\n"
thbuffet's avatar
thbuffet committed
154
155
156
     ]
    }
   ],
157
   "source": [
158
    "source_timestamp_qds_df = pd.DataFrame()\n",
thbuffet's avatar
thbuffet committed
159
160
161
162
163
    "\n",
    "for circuit_type in detailed_circuit_types:\n",
    "    print(f\"{circuit_type}\")\n",
    "    circuits = SignalMetadata.get_circuit_names(detailed_circuit_types[circuit_type])\n",
    "    if circuit_type == 'RQ':\n",
164
    "        circuits = circuits[0:7]\n",
thbuffet's avatar
thbuffet committed
165
    "\n",
166
    "    for circuit_name in circuits:\n",
thbuffet's avatar
thbuffet committed
167
168
169
170
171
172
    "        meta_circuit_type = circuit_type\n",
    "        if circuit_type == 'IPQ': \n",
    "            meta_circuit_type = SignalMetadata.get_circuit_type_for_circuit_name(circuit_name)\n",
    "        elif circuit_type == 'IPD': \n",
    "            meta_circuit_type = SignalMetadata.get_circuit_type_for_circuit_name(circuit_name)\n",
    "            \n",
173
174
    "        source_timestamp_qds_df_i = QueryBuilder().with_pm() \\\n",
    "            .with_duration(t_start=start_time, t_end=stop_time) \\\n",
175
    "            .with_circuit_type(meta_circuit_type) \\\n",
176
177
178
179
    "            .with_metadata(circuit_name=circuit_name, system='QH', source='*') \\\n",
    "            .event_query() \\\n",
    "            .filter_source(circuit_name, 'QH') \\\n",
    "            .sort_values(by='timestamp').df\n",
thbuffet's avatar
thbuffet committed
180
    "\n",
181
182
183
184
    "        if source_timestamp_qds_df_i.empty == False:\n",
    "            print(source_timestamp_qds_df_i)\n",
    "            source_timestamp_qds_df_i['circuit_type'] = source_timestamp_qds_df_i.apply(lambda row: circuit_type, axis=1)\n",
    "            source_timestamp_qds_df = pd.concat([source_timestamp_qds_df, source_timestamp_qds_df_i], ignore_index=True)\n",
thbuffet's avatar
thbuffet committed
185
    "\n",
186
    "if source_timestamp_qds_df.empty == False:\n",
thbuffet's avatar
thbuffet committed
187
    "    source_timestamp_qds_df['datetime'] = source_timestamp_qds_df.apply(lambda row: Time.to_string(row['timestamp']), axis=1)"
188
189
190
191
192
193
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
194
195
196
197
198
    "# 3. The list of QHD PM Timestamps, if any"
   ]
  },
  {
   "cell_type": "code",
199
   "execution_count": 7,
200
   "metadata": {},
thbuffet's avatar
thbuffet committed
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>source</th>\n",
       "      <th>timestamp</th>\n",
       "      <th>circuit_type</th>\n",
       "      <th>datetime</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
232
233
234
235
       "      <td>A28L3</td>\n",
       "      <td>1634542949913000000</td>\n",
       "      <td>RB</td>\n",
       "      <td>2021-10-18 09:42:29.913000+02:00</td>\n",
thbuffet's avatar
thbuffet committed
236
237
238
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
239
240
241
242
       "      <td>B29L3</td>\n",
       "      <td>1634542949913000000</td>\n",
       "      <td>RB</td>\n",
       "      <td>2021-10-18 09:42:29.913000+02:00</td>\n",
thbuffet's avatar
thbuffet committed
243
244
245
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
246
247
248
249
       "      <td>C28L3</td>\n",
       "      <td>1634542949913000000</td>\n",
       "      <td>RB</td>\n",
       "      <td>2021-10-18 09:42:29.913000+02:00</td>\n",
thbuffet's avatar
thbuffet committed
250
251
252
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
253
254
255
256
       "      <td>B15R5</td>\n",
       "      <td>1634605470606000000</td>\n",
       "      <td>RB</td>\n",
       "      <td>2021-10-19 03:04:30.606000+02:00</td>\n",
thbuffet's avatar
thbuffet committed
257
258
259
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
260
261
262
263
       "      <td>B15R5</td>\n",
       "      <td>1634607003034000000</td>\n",
       "      <td>RB</td>\n",
       "      <td>2021-10-19 03:30:03.034000+02:00</td>\n",
thbuffet's avatar
thbuffet committed
264
265
266
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
267
268
269
270
       "      <td>B15R5</td>\n",
       "      <td>1634646052393000000</td>\n",
       "      <td>RB</td>\n",
       "      <td>2021-10-19 14:20:52.393000+02:00</td>\n",
thbuffet's avatar
thbuffet committed
271
272
273
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
274
275
276
277
       "      <td>27L3</td>\n",
       "      <td>1634542916538649604</td>\n",
       "      <td>RQ</td>\n",
       "      <td>2021-10-18 09:41:56.538649604+02:00</td>\n",
thbuffet's avatar
thbuffet committed
278
279
280
281
282
283
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
       "  source            timestamp circuit_type  \\\n",
       "0  A28L3  1634542949913000000           RB   \n",
       "1  B29L3  1634542949913000000           RB   \n",
       "2  C28L3  1634542949913000000           RB   \n",
       "3  B15R5  1634605470606000000           RB   \n",
       "4  B15R5  1634607003034000000           RB   \n",
       "5  B15R5  1634646052393000000           RB   \n",
       "6   27L3  1634542916538649604           RQ   \n",
       "\n",
       "                              datetime  \n",
       "0     2021-10-18 09:42:29.913000+02:00  \n",
       "1     2021-10-18 09:42:29.913000+02:00  \n",
       "2     2021-10-18 09:42:29.913000+02:00  \n",
       "3     2021-10-19 03:04:30.606000+02:00  \n",
       "4     2021-10-19 03:30:03.034000+02:00  \n",
       "5     2021-10-19 14:20:52.393000+02:00  \n",
       "6  2021-10-18 09:41:56.538649604+02:00  "
thbuffet's avatar
thbuffet committed
301
302
303
304
305
306
307
308
309
310
311
312
313
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "WARNINIG: To be checked that QH discharges has been accepted by QHDA-notebooks!\n"
     ]
    }
   ],
314
315
316
317
318
319
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
347
348
349
350
   "source": [
    "if source_timestamp_qds_df.empty == False:\n",
    "    display(source_timestamp_qds_df)\n",
    "    warnings.warn('WARNINIG: To be checked that QH discharges has been accepted by QHDA-notebooks!', stacklevel=2)\n",
    "else:\n",
    "    print('There were no QH discharges on selected time range!')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 4. Save html-report"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "if source_timestamp_qds_df.empty == False:\n",
    "    # pd.set_option('display.max_columns', None)\n",
    "    pd.set_option('display.max_rows', None)\n",
    "    analysis_start_time = Time.get_analysis_start_time()\n",
    "    date_time_qhd_pm_list = Time.to_datetime(start_time).strftime(\"%Y-%m-%d-%Hh%M\")\n",
    "    !mkdir -p /eos/project/m/mp3/LHC_QHs\n",
    "\n",
    "    file_name = \"LHC_QHD_PM_LIST-{}-{}\".format(date_time_qhd_pm_list, analysis_start_time)\n",
    "    \n",
    "    apply_report_template()\n",
    "    file_name_html = file_name + '.html'\n",
    "    full_path = '/eos/project/m/mp3/LHC_QHs/{}'.format(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_QHD_PM_LIST.ipynb' --output /eos/project/m/mp3/LHC_QHs/$file_name_html --TemplateExporter.exclude_input=True --TagRemovePreprocessor.remove_all_outputs_tags='[\"skip_output\"]' --TagRemovePreprocessor.remove_cell_tags='[\"skip_cell\"]'"
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
   ]
  }
 ],
 "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",
Aleksandra Mnich's avatar
Aleksandra Mnich committed
370
   "version": "3.8.6"
371
  },
thbuffet's avatar
thbuffet committed
372
373
374
375
  "sparkconnect": {
   "bundled_options": [],
   "list_of_options": []
  },
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
  "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
thbuffet's avatar
thbuffet committed
392
}