Commit 02dfa58f authored by thbuffet's avatar thbuffet
Browse files

SIGMON-224: integrate the HWC_QHD_PM_LIST.ipynb

parent 586d5e86
Pipeline #3146066 passed with stage
in 30 seconds
%% Cell type:markdown id: tags:
# Notebook to list QHD PMs by circuit type and time range
# Notebook to list QHD PM timestamps by circuit type and time range
%% Cell type:markdown id: tags:
## Import Functions
# 0. Initialise Working Environment
%% Cell type:code id: tags:
``` python
import sys
from IPython.display import display, HTML, Javascript, clear_output
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')
```
%% Cell type:markdown id: tags:
## User Input (circuit types: IPQ, IPD, IT)
# 1. User Input (circuit types: RB, RQ, IPQ, IPD, IT)
%% Cell type:code id: tags:
``` python
#
circuit_type = 'IPQ'
circuit_types = ['RB', 'RQ', 'IPQ', 'IPD', 'IT']
#
start_time = '2021-01-15 12:00:00'
stop_time = '2021-01-15 18:00:00'
start_time = '2021-10-18 07:00:00'
stop_time = '2021-10-20 23:01:00'
#
```
%% Cell type:code id: tags:
``` python
import pandas as pd
print('Selected circuits = ', circuit_types)
print('start_time = ', start_time)
print('stop_time = ', stop_time)
```
%% Cell type:markdown id: tags:
# 2. Search for PMs
%% Cell type:code id: tags:
``` python
#
source_timestamp_qds_df = pd.DataFrame()
#
if 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')
#
for circuit_name in circuits:
if 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().df
if source_timestamp_qds_df_i.empty == False: source_timestamp_qds_df = pd.concat([source_timestamp_qds_df, source_timestamp_qds_df_i], ignore_index=True)
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)
#
```
source_timestamp_qds_df['datetime'] = source_timestamp_qds_df.apply(lambda row: Time.to_string_short(row['timestamp']), axis=1)
source_timestamp_qds_df
%% 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!')
```
%% Cell type:markdown id: tags:
## To do
Table: It would be nice to add QPS ClassName column after source (zinur)
# 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