Commit 6503d1c6 authored by thbuffet's avatar thbuffet
Browse files

adapt notebook for QHD PM list

parent 02dfa58f
Pipeline #3153541 passed with stage
in 32 seconds
%% Cell type:markdown id: tags:
# Notebook to list QHD PM timestamps by circuit type and time range
%% Cell type:markdown id: tags:
# 0. Initialise Working Environment
%% Cell type:code id: tags:
``` python
import os, sys, warnings
import pandas as pd
from IPython.display import display, HTML, Javascript, clear_output, Markdown
#
import lhcsmapi
from lhcsmapi.Time import Time
from lhcsmapi.Timer import Timer
from lhcsmapi.pyedsl.QueryBuilder import QueryBuilder
from lhcsmapi.analysis.RbCircuitQuery import RbCircuitQuery
from lhcsmapi.analysis.RqCircuitQuery import RqCircuitQuery
from lhcsmapi.analysis.IpqCircuitQuery import IpqCircuitQuery
from lhcsmapi.analysis.IpdCircuitQuery import IpdCircuitQuery
from lhcsmapi.analysis.ItCircuitQuery import ItCircuitQuery
from lhcsmapi.metadata.SignalMetadata import SignalMetadata
from lhcsmapi.analysis.report_template import apply_report_template
analysis_start_time = Time.get_analysis_start_time()
lhcsmapi.get_lhcsmapi_version()
lhcsmapi.get_lhcsmhwc_version('../__init__.py')
```
%%%% Output: stream
/eos/project/l/lhcsm/venv_dev/commons/lhcsmapi/pyedsl/QueryBuilder.py:293: SyntaxWarning: "is not" with a literal. Did you mean "!="?
if self.query.db is not 'AFT':
/eos/project/l/lhcsm/venv_dev/commons/lhcsmapi/pyedsl/QueryBuilder.py:381: SyntaxWarning: "is not" with a literal. Did you mean "!="?
if self.query.db is not 'AFT':
`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.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
`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.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
`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.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
`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.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
`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.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
`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.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
`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.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
`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.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
`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.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
%%%% Output: stream
Analysis executed with lhc-sm-api version: 1.5.17
Analysis executed with lhc-sm-hwc notebooks version: 1.5.65
%% Cell type:markdown id: tags:
# 1. User Input (circuit types: RB, RQ, IPQ, IPD, IT)
%% Cell type:code id: tags:
``` python
#
circuit_types = ['RB', 'RQ', 'IPQ', 'IPD', 'IT']
#
start_time = '2021-10-18 07:00:00'
stop_time = '2021-10-20 23:01:00'
#
```
%% Cell type:code id: tags:
``` python
print('Selected circuits = ', circuit_types)
print('start_time = ', start_time)
print('stop_time = ', stop_time)
```
%%%% Output: stream
Selected circuits = ['RB', 'RQ', 'IPQ', 'IPD', 'IT']
start_time = 2021-10-18 07:00:00
stop_time = 2021-10-20 23:01:00
%% Cell type:markdown id: tags:
# 2. Search for PMs
%% Cell type:code id: tags:
``` python
#
source_timestamp_qds_df = pd.DataFrame()
#
for circuit_type in circuit_types:
print(circuit_type)
if circuit_type == 'RB':
circuits = SignalMetadata.get_circuit_names(circuit_type='RB')
elif circuit_type == 'RQ':
circuits = SignalMetadata.get_circuit_names(circuit_type='RQ')
circuits = circuits[0:7]
elif circuit_type == 'IPQ':
circuits = SignalMetadata.get_circuit_names(circuit_type='IPQ2')
circuits.extend(SignalMetadata.get_circuit_names(circuit_type='IPQ4'))
circuits.extend(SignalMetadata.get_circuit_names(circuit_type='IPQ8'))
elif circuit_type == 'IPD':
circuits = SignalMetadata.get_circuit_names(circuit_type='IPD2')
circuits.extend(SignalMetadata.get_circuit_names(circuit_type='IPD2_B1B2'))
elif circuit_type == 'IT':
circuits = SignalMetadata.get_circuit_names(circuit_type='IT')
#
#print(circuits)
for circuit_name in circuits:
#print(circuit_name)
if circuit_type == 'RB': circuit_query = RbCircuitQuery(circuit_type, circuit_name)
elif circuit_type == 'RQ': circuit_query = RqCircuitQuery(circuit_type, circuit_name)
elif circuit_type == 'IPQ': circuit_query = IpqCircuitQuery(circuit_type, circuit_name)
elif circuit_type == 'IPD': circuit_query = IpdCircuitQuery(circuit_type, circuit_name)
elif circuit_type == 'IT': circuit_query = ItCircuitQuery(circuit_type, circuit_name)
source_timestamp_qds_df_i = QueryBuilder().with_pm() \
.with_duration(t_start=start_time, t_end=stop_time) \
.with_circuit_type(circuit_query.circuit_type) \
.with_metadata(circuit_name=circuit_name, system='QH', source='*') \
.event_query() \
.filter_source(circuit_name, 'QH') \
.sort_values(by='timestamp').df
#
if source_timestamp_qds_df_i.empty == False:
print(source_timestamp_qds_df_i)
source_timestamp_qds_df_i['circuit_type'] = source_timestamp_qds_df_i.apply(lambda row: circuit_type, axis=1)
source_timestamp_qds_df = pd.concat([source_timestamp_qds_df, source_timestamp_qds_df_i], ignore_index=True)
#
if source_timestamp_qds_df.empty == False:
source_timestamp_qds_df['datetime'] = source_timestamp_qds_df.apply(lambda row: Time.to_string(row['timestamp']), axis=1)
#
```
%%%% Output: stream
RB
source timestamp
0 A28L3 1634542949913000000
1 B29L3 1634542949913000000
2 C28L3 1634542949913000000
source timestamp
0 B15R5 1634605470606000000
1 B15R5 1634607003034000000
2 B15R5 1634646052393000000
RQ
source timestamp
0 27L3 1634542916538649604
IPQ
IPD
IT
%% Cell type:markdown id: tags:
# 3. The list of QHD PM Timestamps, if any
%% Cell type:code id: tags:
``` python
if source_timestamp_qds_df.empty == False:
display(source_timestamp_qds_df)
warnings.warn('WARNINIG: To be checked that QH discharges has been accepted by QHDA-notebooks!', stacklevel=2)
else:
print('There were no QH discharges on selected time range!')
```
%%%% Output: display_data
%%%% Output: stream
WARNINIG: To be checked that QH discharges has been accepted by QHDA-notebooks!
%% Cell type:markdown id: tags:
# 4. Save html-report
%% Cell type:code id: tags:
``` python
if source_timestamp_qds_df.empty == False:
# pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', None)
analysis_start_time = Time.get_analysis_start_time()
date_time_qhd_pm_list = Time.to_datetime(start_time).strftime("%Y-%m-%d-%Hh%M")
!mkdir -p /eos/project/m/mp3/LHC_QHs
file_name = "LHC_QHD_PM_LIST-{}-{}".format(date_time_qhd_pm_list, analysis_start_time)
apply_report_template()
file_name_html = file_name + '.html'
full_path = '/eos/project/m/mp3/LHC_QHs/{}'.format(file_name_html)
print('Compact notebook report saved to (Windows): ' + '\\\\cernbox-smb' + full_path.replace('/', '\\'))
display(Javascript('IPython.notebook.save_notebook();'))
Time.sleep(5)
!{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"]'
```
%% Cell type:code id: tags:
``` python
```
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment