Commit 81da9bf7 authored by thbuffet's avatar thbuffet
Browse files

SIGMON-224: fix typos on the ntoebooks

parent f6c5b10c
Pipeline #3166184 passed with stage
in 28 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
`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
detailed_circuit_types = {
'RB': ['RB'],
'RQ': ['RQ'],
'IPQ': ['IPQ2', 'IPQ4', 'IPQ8'],
'IPD': ['IPD2', 'IPD2_B1B2'],
'IT': ['IT']
}
start_time = '2021-10-18 07:00:00'
stop_time = '2021-10-20 23:01:00'
```
%% Cell type:code id: tags:
``` python
print('start_time = ', start_time)
print('stop_time = ', stop_time)
```
%%%% Output: stream
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 detailed_circuit_types:
print(f"{circuit_type}")
circuits = SignalMetadata.get_circuit_names(detailed_circuit_types[circuit_type])
if circuit_type == 'RQ':
circuits = circuits[0:7]
for circuit_name in circuits:
meta_circuit_type = circuit_type
if circuit_type == 'IPQ':
print(f"{SignalMetadata.get_circuit_type_for_circuit_name(circuit_name)}")
meta_circuit_type = SignalMetadata.get_circuit_type_for_circuit_name(circuit_name)
elif circuit_type == 'IPD':
print(f"{SignalMetadata.get_circuit_type_for_circuit_name(circuit_name)}")
meta_circuit_type = SignalMetadata.get_circuit_type_for_circuit_name(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_circuit_type(meta_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
circuit_query.circuit_type = RB and RB.A12
circuit_query.circuit_type = RB and RB.A23
source timestamp
0 A28L3 1634542949913000000
1 B29L3 1634542949913000000
2 C28L3 1634542949913000000
circuit_query.circuit_type = RB and RB.A34
circuit_query.circuit_type = RB and RB.A45
circuit_query.circuit_type = RB and RB.A56
source timestamp
0 B15R5 1634605470606000000
1 B15R5 1634607003034000000
2 B15R5 1634646052393000000
circuit_query.circuit_type = RB and RB.A67
circuit_query.circuit_type = RB and RB.A78
circuit_query.circuit_type = RB and RB.A81
RQ
circuit_query.circuit_type = RQ and RQD.A12
circuit_query.circuit_type = RQ and RQD.A23
source timestamp
0 27L3 1634542916538649604
circuit_query.circuit_type = RQ and RQD.A34
circuit_query.circuit_type = RQ and RQD.A45
circuit_query.circuit_type = RQ and RQD.A56
circuit_query.circuit_type = RQ and RQD.A67
circuit_query.circuit_type = RQ and RQD.A78
IPQ
circuit_query.circuit_type = IPQ2 and RQ5.L1
IPQ2
circuit_query.circuit_type = IPQ2 and RQ5.L5
circuit_query.circuit_type = IPQ2 and RQ5.R1
circuit_query.circuit_type = IPQ2 and RQ5.R5
circuit_query.circuit_type = IPQ2 and RQ6.L1
circuit_query.circuit_type = IPQ2 and RQ6.L5
circuit_query.circuit_type = IPQ2 and RQ6.R1
circuit_query.circuit_type = IPQ2 and RQ6.R5
circuit_query.circuit_type = IPQ2 and RQ7.L4
circuit_query.circuit_type = IPQ2 and RQ7.R4
circuit_query.circuit_type = IPQ2 and RQ8.L1
circuit_query.circuit_type = IPQ2 and RQ8.L2
circuit_query.circuit_type = IPQ2 and RQ8.L4
circuit_query.circuit_type = IPQ2 and RQ8.L5
circuit_query.circuit_type = IPQ2 and RQ8.L6
circuit_query.circuit_type = IPQ2 and RQ8.L8
circuit_query.circuit_type = IPQ2 and RQ8.R1
circuit_query.circuit_type = IPQ2 and RQ8.R2
circuit_query.circuit_type = IPQ2 and RQ8.R4
circuit_query.circuit_type = IPQ2 and RQ8.R5
circuit_query.circuit_type = IPQ2 and RQ8.R6
circuit_query.circuit_type = IPQ2 and RQ8.R8
circuit_query.circuit_type = IPQ2 and RQ10.L1
circuit_query.circuit_type = IPQ2 and RQ10.L2
circuit_query.circuit_type = IPQ2 and RQ10.L4
circuit_query.circuit_type = IPQ2 and RQ10.L5
circuit_query.circuit_type = IPQ2 and RQ10.L6
circuit_query.circuit_type = IPQ2 and RQ10.L8
circuit_query.circuit_type = IPQ2 and RQ10.R1
circuit_query.circuit_type = IPQ2 and RQ10.R2
circuit_query.circuit_type = IPQ2 and RQ10.R4
circuit_query.circuit_type = IPQ2 and RQ10.R5
circuit_query.circuit_type = IPQ2 and RQ10.R6
circuit_query.circuit_type = IPQ2 and RQ10.R8
circuit_query.circuit_type = IPQ2 and RQ4.L1
%%%% Output: error
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-60-8508dc5c6ea5> in <module>
24
25
---> 26 source_timestamp_qds_df_i = QueryBuilder().with_pm() \
27 .with_duration(t_start=start_time, t_end=stop_time) \
28 .with_circuit_type(circuit_query.circuit_type) \
/eos/project/l/lhcsm/venv_dev/commons/lhcsmapi/pyedsl/QueryBuilder.py in with_metadata(self, **kwargs)
440 timestamp_query = self.query.t_start if is_t_start else self.query.timestamp
441 self.query.db_query_builder = DbQueryBuilderFactory.create(db, is_timestamp, is_t_start, circuit_type)
--> 442 self.query.db_query_builder.create_query_metadata(kwargs, timestamp_query)
443 self.query.db_query_builder.update_query_metadata(kwargs)
444
/eos/project/l/lhcsm/venv_dev/commons/lhcsmapi/pyedsl/dbquery/DbQueryBuilder.py in create_query_metadata(self, query_metadata_dict, timestamp_query)
306 query_metadata_dict['system'])
307 # get metadata
--> 308 get_db_metadata(self.circuit_type, self._db, self._query_params, timestamp_query)
309
310 self._query_params = explode(self._query_params, 'metadata_source')
/eos/project/l/lhcsm/venv_dev/commons/lhcsmapi/pyedsl/dbquery/DbQueryBuilder.py in get_db_metadata(circuit_type, db, query_params, timestamp_query)
142 system = query_params['system'].values[0]
143 # The method assumes that all systems are the same
--> 144 metadata = SignalMetadata.get_circuit_signal_database_metadata(circuit_type, circuit_name, system, db,
145 timestamp_query)
146 metadata = {k: v for k, v in metadata.items() if k[0].islower()}
/eos/project/l/lhcsm/venv_dev/commons/lhcsmapi/metadata/SignalMetadata.py in get_circuit_signal_database_metadata(circuit_type, circuit_name, system, database, timestamp_query)
302
303 # update the source wildcard
--> 304 circuit_name_metadata = SignalMetadata.get_circuit_name_metadata(circuit_type, circuit_name, timestamp_query)
305 if database == "PM":
306 source = circuit_signal_type_metadata[database]['source']
/eos/project/l/lhcsm/venv_dev/commons/lhcsmapi/metadata/SignalMetadata.py in get_circuit_name_metadata(circuit_type, circuit_name, timestamp_query)
267 return circuit_metadata["CIRCUITS"][circuit_name]
268 else:
--> 269 raise KeyError("Circuit name {} not present in {}.".format(circuit_name, circuit_names))
270
271 @staticmethod
KeyError: "Circuit name RQ4.L1 not present in dict_keys(['RQ5.L1', 'RQ5.L5', 'RQ5.R1', 'RQ5.R5', 'RQ6.L1', 'RQ6.L5', 'RQ6.R1', 'RQ6.R5', 'RQ7.L4', 'RQ7.R4', 'RQ8.L1', 'RQ8.L2', 'RQ8.L4', 'RQ8.L5', 'RQ8.L6', 'RQ8.L8', 'RQ8.R1', 'RQ8.R2', 'RQ8.R4', 'RQ8.R5', 'RQ8.R6', 'RQ8.R8', 'RQ10.L1', 'RQ10.L2', 'RQ10.L4', 'RQ10.L5', 'RQ10.L6', 'RQ10.L8', 'RQ10.R1', 'RQ10.R2', 'RQ10.R4', 'RQ10.R5', 'RQ10.R6', 'RQ10.R8'])."
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"]'
```
......
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