Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
LHCData
lhc-sm-hwc
Commits
74842030
Commit
74842030
authored
Oct 26, 2021
by
Agata Malgorzata Chadaj
Browse files
WIP
parent
bab3a14f
Pipeline
#3166654
passed with stage
in 25 seconds
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
qh/HWC_IPD_QHDA.ipynb
View file @
74842030
...
...
@@ -21,22 +21,24 @@
"outputs": [],
"source": [
"# External libraries\n",
"print('Loading (1/1
4
)'); import sys; import pandas as pd\n",
"print('Loading (2/1
4
)'); from multiprocessing import Pool\n",
"print('Loading (3/1
4
)'); from IPython.display import display, HTML, Javascript, clear_output\n",
"print('Loading (1/1
6
)'); import sys; import pandas as pd\n",
"print('Loading (2/1
6
)'); from multiprocessing import Pool\n",
"print('Loading (3/1
6
)'); from IPython.display import display, HTML, Javascript, clear_output\n",
"\n",
"# Internal libraries\n",
"print('Loading (4/14)'); import lhcsmapi\n",
"print('Loading (5/14)'); from lhcsmapi.Time import Time\n",
"print('Loading (6/14)'); from lhcsmapi.Timer import Timer\n",
"print('Loading (7/14)'); from lhcsmapi.analysis.IpdCircuitQuery import IpdCircuitQuery\n",
"print('Loading (8/14)'); from lhcsmapi.analysis.IpdCircuitAnalysis import IpdCircuitAnalysis\n",
"print('Loading (9/14)'); from lhcsmapi.analysis.expert_input import check_show_next, get_expert_decision\n",
"print('Loading (10/14)'); from lhcsmapi.analysis.report_template import apply_report_template\n",
"print('Loading (11/14)'); from lhcsmapi.gui.DateTimeBaseModule import DateTimeBaseModule\n",
"print('Loading (12/14)'); from lhcsmapi.gui.qh.QhPmSearchModuleMediator import QhPmSearchModuleMediator\n",
"print('Loading (13/14)'); from lhcsmapi.gui.hwc.HwcSearchModuleMediator import HwcSearchModuleMediator\n",
"print('Loading (14/14)'); from lhcsmnb.parameters import are_all_parameters_injected, get_source_timestamp_df, NbType\n",
"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.IpdCircuitQuery import IpdCircuitQuery\n",
"print('Loading (8/16)'); from lhcsmapi.analysis.IpdCircuitAnalysis import IpdCircuitAnalysis\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.qh.QhPmSearchModuleMediator import QhPmSearchModuleMediator\n",
"print('Loading (14/16)'); from lhcsmapi.gui.hwc.HwcSearchModuleMediator import HwcSearchModuleMediator\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",
"clear_output()\n",
"lhcsmapi.get_lhcsmapi_version()\n",
...
...
@@ -61,8 +63,22 @@
},
"outputs": [],
"source": [
"circuit_type = 'IPD'\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)"
"circuit_type='IPD'"
]
},
{
"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()))"
]
},
{
...
...
@@ -81,9 +97,7 @@
"outputs": [],
"source": [
"with Timer():\n",
" if are_all_parameters_injected(NbType.QH, locals()):\n",
" source_timestamp_df = get_source_timestamp_df(sources, timestamps)\n",
" else:\n",
" if not are_all_parameters_injected(NbType.QH, locals()):\n",
" 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",
...
...
@@ -227,6 +241,7 @@
}
],
"metadata": {
"celltoolbar": "Tags",
"kernelspec": {
"display_name": "Python 3",
"language": "python",
...
...
@@ -242,7 +257,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.
10
"
"version": "3.8.
6
"
},
"sparkconnect": {
"bundled_options": [],
...
...
%% Cell type:markdown id: tags:
<h1><center>
Analysis of a QH discharge in an IPD Circuit
</center></h1>
%% Cell type:markdown id: tags:
# 0. Initialise Working Environment
%% Cell type:code id: tags:
```
python
# External libraries
print
(
'Loading (1/1
4
)'
);
import
sys
;
import
pandas
as
pd
print
(
'Loading (2/1
4
)'
);
from
multiprocessing
import
Pool
print
(
'Loading (3/1
4
)'
);
from
IPython.display
import
display
,
HTML
,
Javascript
,
clear_output
print
(
'Loading (1/1
6
)'
);
import
sys
;
import
pandas
as
pd
print
(
'Loading (2/1
6
)'
);
from
multiprocessing
import
Pool
print
(
'Loading (3/1
6
)'
);
from
IPython.display
import
display
,
HTML
,
Javascript
,
clear_output
# Internal libraries
print
(
'Loading (4/14)'
);
import
lhcsmapi
print
(
'Loading (5/14)'
);
from
lhcsmapi.Time
import
Time
print
(
'Loading (6/14)'
);
from
lhcsmapi.Timer
import
Timer
print
(
'Loading (7/14)'
);
from
lhcsmapi.analysis.IpdCircuitQuery
import
IpdCircuitQuery
print
(
'Loading (8/14)'
);
from
lhcsmapi.analysis.IpdCircuitAnalysis
import
IpdCircuitAnalysis
print
(
'Loading (9/14)'
);
from
lhcsmapi.analysis.expert_input
import
check_show_next
,
get_expert_decision
print
(
'Loading (10/14)'
);
from
lhcsmapi.analysis.report_template
import
apply_report_template
print
(
'Loading (11/14)'
);
from
lhcsmapi.gui.DateTimeBaseModule
import
DateTimeBaseModule
print
(
'Loading (12/14)'
);
from
lhcsmapi.gui.qh.QhPmSearchModuleMediator
import
QhPmSearchModuleMediator
print
(
'Loading (13/14)'
);
from
lhcsmapi.gui.hwc.HwcSearchModuleMediator
import
HwcSearchModuleMediator
print
(
'Loading (14/14)'
);
from
lhcsmnb.parameters
import
are_all_parameters_injected
,
get_source_timestamp_df
,
NbType
print
(
'Loading (4/16)'
);
import
lhcsmapi
print
(
'Loading (5/16)'
);
from
lhcsmapi.Time
import
Time
print
(
'Loading (6/16)'
);
from
lhcsmapi.Timer
import
Timer
print
(
'Loading (7/16)'
);
from
lhcsmapi.analysis.IpdCircuitQuery
import
IpdCircuitQuery
print
(
'Loading (8/16)'
);
from
lhcsmapi.analysis.IpdCircuitAnalysis
import
IpdCircuitAnalysis
print
(
'Loading (9/16)'
);
from
lhcsmapi.analysis.expert_input
import
check_show_next
,
get_expert_decision
print
(
'Loading (10/16)'
);
from
lhcsmapi.analysis.qh.QuenchHeaterQuery
import
QuenchHeaterQuery
print
(
'Loading (11/16)'
);
from
lhcsmapi.analysis.report_template
import
apply_report_template
print
(
'Loading (12/16)'
);
from
lhcsmapi.gui.DateTimeBaseModule
import
DateTimeBaseModule
print
(
'Loading (13/16)'
);
from
lhcsmapi.gui.qh.QhPmSearchModuleMediator
import
QhPmSearchModuleMediator
print
(
'Loading (14/16)'
);
from
lhcsmapi.gui.hwc.HwcSearchModuleMediator
import
HwcSearchModuleMediator
print
(
'Loading (15/16)'
);
from
lhcsmapi.metadata.SignalMetadata
import
SignalMetadata
print
(
'Loading (16/16)'
);
from
lhcsmnb.parameters
import
are_all_parameters_injected
,
get_source_timestamp_df
,
NbType
clear_output
()
lhcsmapi
.
get_lhcsmapi_version
()
lhcsmapi
.
get_lhcsmhwc_version
(
'../__init__.py'
)
print
(
'Analysis performed by %s'
%
HwcSearchModuleMediator
.
get_user
())
```
%% Cell type:markdown id: tags:
# 1. Find QH Post Mortem Entries
%% Cell type:code id: tags:parameters
```
python
circuit_type
=
'IPD'
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
)
circuit_type
=
'IPD'
```
%% Cell type:code id: tags:
```
python
with
Timer
():
if
not
are_all_parameters_injected
(
NbType
.
QH
,
locals
()):
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
)
else
:
circuit_sub_type
=
SignalMetadata
.
get_circuit_type_for_circuit_name
(
circuit_name
)
source_timestamp_df
=
QuenchHeaterQuery
(
circuit_sub_type
,
circuit_name
).
find_source_timestamp_qh_with_pattern
(
'*'
,
start_time
,
end_time
)
display
(
HTML
(
source_timestamp_df
.
to_html
()))
```
%% Cell type:markdown id: tags:
# 2. Query All Signals Prior to Analysis
%% Cell type:code id: tags:
```
python
with
Timer
():
if
are_all_parameters_injected
(
NbType
.
QH
,
locals
()):
source_timestamp_df
=
get_source_timestamp_df
(
sources
,
timestamps
)
else
:
if
not
are_all_parameters_injected
(
NbType
.
QH
,
locals
()):
circuit_name
=
qh_pm_search
.
get_circuit_name
()
discharge_level
=
qh_pm_search
.
get_discharge_level
()
source_timestamp_df
=
qh_pm_search
.
source_timestamp_df
is_automatic
=
qh_pm_search
.
is_automatic_mode
()
ipd_query
=
IpdCircuitQuery
(
circuit_type
,
circuit_name
)
ipd_analysis
=
IpdCircuitAnalysis
(
ipd_query
.
circuit_type
)
u_hds_dfss
=
ipd_query
.
query_qh_pm
(
source_timestamp_df
,
signal_names
=
[
'U_HDS'
])
u_hds_ref_dfss
=
ipd_query
.
query_qh_pm
(
source_timestamp_df
,
signal_names
=
[
'U_HDS'
],
is_ref
=
True
)
```
%% Cell type:markdown id: tags:
# 3. Quench Heaters
*CRITERIA*
:
-
all characteristic times of an exponential decay calculated with the 'charge' approach for voltage is +/- 5 ms from the reference ones
-
the initial voltage should be between 810 V and 1000 V
-
the final voltage should be between 0 V and 10 V
*GRAPHS*
:
-
t = 0 s corresponds to the start of the pseudo-exponential decay
Voltage view (linear and log)
-
the queried and filtered quench heater voltage on the left axis (actual signal continuous, reference dashed), U_HDS
%% Cell type:code id: tags:
```
python
index
=
0
for
u_hds_dfs
,
u_hds_ref_dfs
in
zip
(
u_hds_dfss
,
u_hds_ref_dfss
):
print
(
index
,
source_timestamp_df
.
loc
[
index
,
'timestamp'
])
if
u_hds_dfs
:
ipd_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
)
else
:
print
(
f
"No Quench Heater Discharges !"
)
index
+=
1
```
%% Cell type:markdown id: tags:ignore
# 4. Signature Decision
%% Cell type:code id: tags:ignore
```
python
signature
=
get_expert_decision
(
'Expert Signature Decision: '
,
[
'PASSED'
,
'FAILED'
])
```
%% Cell type:markdown id: tags:ignore
# 5. Final Report
%% Cell type:code id: tags:ignore
```
python
if
not
source_timestamp_df
.
empty
:
analysis_start_time
=
Time
.
get_analysis_start_time
()
date_time_qh
=
Time
.
to_datetime
(
source_timestamp_df
.
loc
[
0
,
'timestamp'
]).
strftime
(
"%Y-%m-%d-%Hh%M"
)
file_name_html
=
"{}_QHDA-{}-{}_{}.html"
.
format
(
circuit_name
,
date_time_qh
,
analysis_start_time
,
signature
)
apply_report_template
()
!
mkdir
-
p
/
eos
/
project
/
m
/
mp3
/
IPD
/
$
circuit_name
/
QHDA
full_path
=
'/eos/project/m/mp3/IPD/{}/QHDA/{}'
.
format
(
circuit_name
,
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_IPD_QHDA.ipynb'
--
output
/
eos
/
project
/
m
/
mp3
/
IPD
/
$
circuit_name
/
QHDA
/
$
file_name_html
--
TemplateExporter
.
exclude_input
=
True
--
TagRemovePreprocessor
.
remove_all_outputs_tags
=
'["skip_output"]'
--
TagRemovePreprocessor
.
remove_cell_tags
=
'["skip_cell"]'
```
%% Cell type:markdown id: tags:ignore
# 6. Save Timestamps in Reference Format (if update needed)
%% Cell type:code id: tags:ignore
```
python
if
not
source_timestamp_df
.
empty
:
!
mkdir
-
p
/
eos
/
project
/
m
/
mp3
/
IPD
/
$
circuit_name
/
QHDA
file_name
=
"{}_QHDA-{}-{}_Reference"
.
format
(
circuit_name
,
date_time_qh
,
analysis_start_time
)
csv_full_path
=
'/eos/project/m/mp3/IPD/{}/QHDA/{}.csv'
.
format
(
circuit_name
,
file_name
)
cell_datetime_timestamp
=
pd
.
DataFrame
(
source_timestamp_df
.
rename
(
columns
=
{
'source'
:
'Cell'
})[
'Cell'
])
cell_datetime_timestamp
[
'Timestamp String'
]
=
source_timestamp_df
[
'timestamp'
].
apply
(
lambda
col
:
Time
.
to_string_short
(
col
,
n_dec_digits
=
9
))
cell_datetime_timestamp
[
'Timestamp'
]
=
source_timestamp_df
[
'timestamp'
]
cell_datetime_timestamp
.
to_csv
(
csv_full_path
,
index
=
False
)
print
(
'Reference timestamp table saved to (Windows): '
+
'
\\\\
cernbox-smb'
+
csv_full_path
.
replace
(
'/'
,
'
\\
'
))
```
...
...
qh/HWC_IPQ_QHDA.ipynb
View file @
74842030
...
...
@@ -21,22 +21,25 @@
"outputs": [],
"source": [
"# External libraries\n",
"print('Loading (1/1
4
)'); import sys; import pandas as pd\n",
"print('Loading (2/1
4
)'); from multiprocessing import Pool\n",
"print('Loading (3/1
4
)'); from IPython.display import display, HTML, Javascript, clear_output\n",
"print('Loading (1/1
6
)'); import sys; import pandas as pd\n",
"print('Loading (2/1
6
)'); from multiprocessing import Pool\n",
"print('Loading (3/1
6
)'); from IPython.display import display, HTML, Javascript, clear_output\n",
"\n",
"# Internal libraries\n",
"print('Loading (4/14)'); import lhcsmapi\n",
"print('Loading (5/14)'); from lhcsmapi.Time import Time\n",
"print('Loading (6/14)'); from lhcsmapi.Timer import Timer\n",
"print('Loading (7/14)'); from lhcsmapi.analysis.IpqCircuitQuery import IpqCircuitQuery\n",
"print('Loading (8/14)'); from lhcsmapi.analysis.IpqCircuitAnalysis import IpqCircuitAnalysis\n",
"print('Loading (9/14)'); from lhcsmapi.analysis.expert_input import check_show_next, get_expert_decision\n",
"print('Loading (10/14)'); from lhcsmapi.analysis.report_template import apply_report_template\n",
"print('Loading (11/14)'); from lhcsmapi.gui.DateTimeBaseModule import DateTimeBaseModule\n",
"print('Loading (12/14)'); from lhcsmapi.gui.qh.QhPmSearchModuleMediator import QhPmSearchModuleMediator\n",
"print('Loading (13/14)'); from lhcsmapi.gui.hwc.HwcSearchModuleMediator import HwcSearchModuleMediator\n",
"print('Loading (14/14)'); from lhcsmnb.parameters import are_all_parameters_injected, get_source_timestamp_df, NbType\n",
"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",
"\n",
"clear_output()\n",
"lhcsmapi.get_lhcsmapi_version()\n",
...
...
@@ -61,8 +64,22 @@
},
"outputs": [],
"source": [
"circuit_type = 'IPQ'\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)"
"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()))"
]
},
{
...
...
@@ -79,9 +96,7 @@
"outputs": [],
"source": [
"with Timer():\n",
" if are_all_parameters_injected(NbType.QH, locals()):\n",
" source_timestamp_df = get_source_timestamp_df(sources, timestamps)\n",
" else:\n",
" if not are_all_parameters_injected(NbType.QH, locals()):\n",
" 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",
...
...
@@ -124,7 +139,7 @@
"for u_hds_dfs, u_hds_ref_dfs in zip(u_hds_dfss, u_hds_ref_dfss):\n",
" print(index, source_timestamp_df.loc[index, 'timestamp'])\n",
" if u_hds_dfs:\n",
" 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=
qh_pm_search.get_
discharge_level
()
)\n",
" 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",
" else:\n",
" print(f\"No Quench Heater Discharges!\")\n",
" index += 1"
...
...
@@ -141,19 +156,6 @@
"# 4. Signature Decision"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"ignore"
]
},
"outputs": [],
"source": [
"signature = get_expert_decision('Expert Signature Decision: ', ['PASSED', 'FAILED'])"
]
},
{
"cell_type": "markdown",
"metadata": {
...
...
@@ -223,9 +225,23 @@
" cell_datetime_timestamp.to_csv(csv_full_path, index=False)\n",
" print('Reference timestamp table saved to (Windows): ' + '\\\\\\\\cernbox-smb' + csv_full_path.replace('/', '\\\\'))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"result"
]
},
"outputs": [],
"source": [
"ipq_analysis.get_notebook_result()"
]
}
],
"metadata": {
"celltoolbar": "Tags",
"kernelspec": {
"display_name": "Python 3",
"language": "python",
...
...
@@ -241,7 +257,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.
10
"
"version": "3.8.
6
"
},
"toc": {
"base_numbering": 1,
...
...
%% Cell type:markdown id: tags:
<h1><center>
Analysis of a QH discharge in an IPQ Circuit
</center></h1>
%% Cell type:markdown id: tags:
# 0. Initialise Working Environment
%% Cell type:code id: tags:
```
python
# External libraries
print
(
'Loading (1/1
4
)'
);
import
sys
;
import
pandas
as
pd
print
(
'Loading (2/1
4
)'
);
from
multiprocessing
import
Pool
print
(
'Loading (3/1
4
)'
);
from
IPython.display
import
display
,
HTML
,
Javascript
,
clear_output
print
(
'Loading (1/1
6
)'
);
import
sys
;
import
pandas
as
pd
print
(
'Loading (2/1
6
)'
);
from
multiprocessing
import
Pool
print
(
'Loading (3/1
6
)'
);
from
IPython.display
import
display
,
HTML
,
Javascript
,
clear_output
# Internal libraries
print
(
'Loading (4/14)'
);
import
lhcsmapi
print
(
'Loading (5/14)'
);
from
lhcsmapi.Time
import
Time
print
(
'Loading (6/14)'
);
from
lhcsmapi.Timer
import
Timer
print
(
'Loading (7/14)'
);
from
lhcsmapi.analysis.IpqCircuitQuery
import
IpqCircuitQuery
print
(
'Loading (8/14)'
);
from
lhcsmapi.analysis.IpqCircuitAnalysis
import
IpqCircuitAnalysis
print
(
'Loading (9/14)'
);
from
lhcsmapi.analysis.expert_input
import
check_show_next
,
get_expert_decision
print
(
'Loading (10/14)'
);
from
lhcsmapi.analysis.report_template
import
apply_report_template
print
(
'Loading (11/14)'
);
from
lhcsmapi.gui.DateTimeBaseModule
import
DateTimeBaseModule
print
(
'Loading (12/14)'
);
from
lhcsmapi.gui.qh.QhPmSearchModuleMediator
import
QhPmSearchModuleMediator
print
(
'Loading (13/14)'
);
from
lhcsmapi.gui.hwc.HwcSearchModuleMediator
import
HwcSearchModuleMediator
print
(
'Loading (14/14)'
);
from
lhcsmnb.parameters
import
are_all_parameters_injected
,
get_source_timestamp_df
,
NbType
print
(
'Loading (4/16)'
);
import
lhcsmapi
print
(
'Loading (5/16)'
);
from
lhcsmapi.Time
import
Time
print
(
'Loading (6/16)'
);
from
lhcsmapi.Timer
import
Timer
print
(
'Loading (7/16)'
);
from
lhcsmapi.analysis.IpqCircuitQuery
import
IpqCircuitQuery
print
(
'Loading (8/16)'
);
from
lhcsmapi.analysis.IpqCircuitAnalysis
import
IpqCircuitAnalysis
print
(
'Loading (9/16)'
);
from
lhcsmapi.analysis.expert_input
import
check_show_next
,
get_expert_decision
print
(
'Loading (10/16)'
);
from
lhcsmapi.analysis.qh.QuenchHeaterQuery
import
QuenchHeaterQuery
print
(
'Loading (11/16)'
);
from
lhcsmapi.analysis.report_template
import
apply_report_template
print
(
'Loading (12/16)'
);
from
lhcsmapi.gui.DateTimeBaseModule
import
DateTimeBaseModule
print
(
'Loading (13/16)'
);
from
lhcsmapi.gui.hwc.HwcSearchModuleMediator
import
HwcSearchModuleMediator
print
(
'Loading (14/16)'
);
from
lhcsmapi.gui.qh.QhPmSearchModuleMediator
import
QhPmSearchModuleMediator
print
(
'Loading (15/16)'
);
from
lhcsmapi.metadata.SignalMetadata
import
SignalMetadata
print
(
'Loading (16/16)'
);
from
lhcsmnb.parameters
import
are_all_parameters_injected
,
get_source_timestamp_df
,
NbType
clear_output
()
lhcsmapi
.
get_lhcsmapi_version
()
lhcsmapi
.
get_lhcsmhwc_version
(
'../__init__.py'
)
print
(
'Analysis performed by %s'
%
HwcSearchModuleMediator
.
get_user
())
```
%% Cell type:markdown id: tags:
# 1. Find QH Post Mortem Entries
%% Cell type:code id: tags:parameters
```
python
circuit_type
=
'IPQ'
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
)
```
%% Cell type:code id: tags:
```
python
with
Timer
():
if
not
are_all_parameters_injected
(
NbType
.
QH
,
locals
()):
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
)
else
:
circuit_sub_type
=
SignalMetadata
.
get_circuit_type_for_circuit_name
(
circuit_name
)
source_timestamp_df
=
QuenchHeaterQuery
(
circuit_sub_type
,
circuit_name
).
find_source_timestamp_qh_with_pattern
(
'*'
,
start_time
,
end_time
)
display
(
HTML
(
source_timestamp_df
.
to_html
()))
```
%% Cell type:markdown id: tags:
# 2. Query All Signals Prior to Analysis
%% Cell type:code id: tags:
```
python
with
Timer
():
if
are_all_parameters_injected
(
NbType
.
QH
,
locals
()):
source_timestamp_df
=
get_source_timestamp_df
(
sources
,
timestamps
)
else
:
if
not
are_all_parameters_injected
(
NbType
.
QH
,
locals
()):
circuit_name
=
qh_pm_search
.
get_circuit_name
()
discharge_level
=
qh_pm_search
.
get_discharge_level
()
source_timestamp_df
=
qh_pm_search
.
source_timestamp_df
is_automatic
=
qh_pm_search
.
is_automatic_mode
()
ipq_query
=
IpqCircuitQuery
(
circuit_type
,
circuit_name
)
ipq_analysis
=
IpqCircuitAnalysis
(
circuit_type
,
None
,
circuit_name
=
circuit_name
)
u_hds_dfss
=
ipq_query
.
query_qh_pm
(
source_timestamp_df
,
signal_names
=
[
'U_HDS'
])
u_hds_ref_dfss
=
ipq_query
.
query_qh_pm
(
source_timestamp_df
,
signal_names
=
[
'U_HDS'
],
is_ref
=
True
)
```
%% Cell type:markdown id: tags:
# 3. Quench Heaters
*CRITERIA*
:
-
all characteristic times of an exponential decay calculated with the 'charge' approach for voltage is +/- 5 ms from the reference ones
-
the initial voltage should be between 810 V and 1000 V
-
the final voltage should be between 0 V and 10 V
*GRAPHS*
:
-
t = 0 s corresponds to the start of the pseudo-exponential decay
Voltage view (linear and log)
-
the queried and filtered quench heater voltage on the left axis (actual signal continuous, reference dashed), U_HDS
%% Cell type:code id: tags:
```
python
index
=
0
for
u_hds_dfs
,
u_hds_ref_dfs
in
zip
(
u_hds_dfss
,
u_hds_ref_dfss
):
print
(
index
,
source_timestamp_df
.
loc
[
index
,
'timestamp'
])
if
u_hds_dfs
:
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
=
qh_pm_search
.
get_
discharge_level
()
)
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
)
else
:
print
(
f
"No Quench Heater Discharges!"
)
index
+=
1
```
%% Cell type:markdown id: tags:ignore
# 4. Signature Decision
%% Cell type:code id: tags:ignore
```
python
signature
=
get_expert_decision
(
'Expert Signature Decision: '
,
[
'PASSED'
,
'FAILED'
])
```
%% Cell type:markdown id: tags:ignore
# 5. Final Report
%% Cell type:code id: tags:ignore
```
python
if
not
source_timestamp_df
.
empty
:
analysis_start_time
=
Time
.
get_analysis_start_time
()
prefix_circuit_name
=
circuit_name
.
split
(
'.'
)[
0
]
date_time_qh
=
Time
.
to_datetime
(
source_timestamp_df
.
loc
[
0
,
'timestamp'
]).
strftime
(
"%Y-%m-%d-%Hh%M"
)
apply_report_template
()
!
mkdir
-
p
/
eos
/
project
/
m
/
mp3
/
IPQ
/
$
prefix_circuit_name
/
$
circuit_name
/
QHDA
file_name_html
=
"{}_QHDA-{}-{}_{}.html"
.
format
(
circuit_name
,
date_time_qh
,
analysis_start_time
,
signature
)
full_path
=
'/eos/project/m/mp3/IPQ/{}/{}/QHDA/{}'
.
format
(
prefix_circuit_name
,
circuit_name
,
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_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"]'
```
%% Cell type:markdown id: tags:ignore
# 6. Save Timestamps in Reference Format (if update needed)
%% Cell type:code id: tags:ignore
```
python
if
not
source_timestamp_df
.
empty
:
analysis_start_time
=
Time
.
get_analysis_start_time
()
prefix_circuit_name
=
circuit_name
.
split
(
'.'
)[
0
]
!
mkdir
-
p
/
eos
/
project
/
m
/
mp3
/
IPQ
/
$
prefix_circuit_name
/
$
circuit_name
/
QHDA
file_name
=
"{}_QHDA-{}-{}_Reference"
.
format
(
circuit_name
,
date_time_qh
,
analysis_start_time
)
csv_full_path
=
'/eos/project/m/mp3/IPQ/{}/{}/QHDA/{}.csv'
.
format
(
prefix_circuit_name
,
circuit_name
,
file_name
)
cell_datetime_timestamp
=
pd
.
DataFrame
(
source_timestamp_df
.
rename
(
columns
=
{
'source'
:
'Cell'
})[
'Cell'
])
cell_datetime_timestamp
[
'Timestamp String'
]
=
source_timestamp_df
[
'timestamp'
].
apply
(
lambda
col
:
Time
.
to_string_short
(
col
,
n_dec_digits
=
9
))
cell_datetime_timestamp
[
'Timestamp'
]
=
source_timestamp_df
[
'timestamp'
]
cell_datetime_timestamp
.
to_csv
(
csv_full_path
,
index
=
False
)
print
(
'Reference timestamp table saved to (Windows): '
+
'
\\\\
cernbox-smb'
+
csv_full_path
.
replace
(
'/'
,
'
\\
'
))
```
%% Cell type:code id: tags:result
```
python
ipq_analysis
.
get_notebook_result
()
```
...
...
qh/HWC_IPQ_QHDA_new.ipynb
deleted
100644 → 0
View file @
bab3a14f
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h1><center>Analysis of a QH discharge in an IPQ Circuit</center></h1>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 0. Initialise Working Environment"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# External libraries\n",
"print('Loading (1/14)'); import sys; import pandas as pd\n",
"print('Loading (2/14)'); from multiprocessing import Pool\n",
"print('Loading (3/14)'); from IPython.display import display, HTML, Javascript, clear_output\n",
"\n",
"# Internal libraries\n",
"print('Loading (4/14)'); import lhcsmapi\n",
"print('Loading (5/14)'); from lhcsmapi.Time import Time\n",
"print('Loading (6/14)'); from lhcsmapi.Timer import Timer\n",
"print('Loading (7/14)'); from lhcsmapi.analysis.IpqCircuitQuery import IpqCircuitQuery\n",
"print('Loading (8/14)'); from lhcsmapi.analysis.IpqCircuitAnalysis import IpqCircuitAnalysis\n",
"print('Loading (9/14)'); from lhcsmapi.analysis.expert_input import check_show_next, get_expert_decision\n",
"print('Loading (10/14)'); from lhcsmapi.analysis.report_template import apply_report_template\n",
"print('Loading (11/14)'); from lhcsmapi.metadata.SignalMetadata import SignalMetadata\n",
"print('Loading (12/14)'); from lhcsmapi.analysis.qh.QuenchHeaterQuery import QuenchHeaterQuery\n",
"print('Loading (13/14)'); from lhcsmapi.gui.hwc.HwcSearchModuleMediator import HwcSearchModuleMediator\n",
"print('Loading (14/14)'); from lhcsmnb.parameters import are_all_parameters_injected, get_source_timestamp_df, NbType\n",
"\n",
"\n",
"clear_output()\n",
"lhcsmapi.get_lhcsmapi_version()\n",
"lhcsmapi.get_lhcsmhwc_version('../__init__.py')\n",
"print('Analysis performed by %s' % HwcSearchModuleMediator.get_user())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 1. Find QH Post Mortem Entries"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"parameters"
]
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 2. Query All Signals Prior to Analysis"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"with Timer():\n",
" if are_all_parameters_injected(NbType.NEW, locals()):\n",
" new_circuit_type = SignalMetadata.get_circuit_type_for_circuit_name(circuit_name)\n",
" source_timestamp_df = QuenchHeaterQuery(new_circuit_type, circuit_name).find_source_timestamp_qh_with_pattern('*', start_time, end_time)\n",
" else:\n",
" circuit_type = 'IPQ'\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",
" 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)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 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"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"index = 0\n",
"for u_hds_dfs, u_hds_ref_dfs in zip(u_hds_dfss, u_hds_ref_dfss):\n",
" print(index, source_timestamp_df.loc[index, 'timestamp'])\n",
" if u_hds_dfs:\n",
" 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",
" else:\n",
" print(f\"No Quench Heater Discharges!\")\n",
" index += 1"
]
},
{
"cell_type": "markdown",
"metadata": {
"tags": [
"ignore"
]
},
"source": [
"# 4. Signature Decision"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"result"
]
},
"outputs": [],
"source": [
"ipq_analysis.get_analysis_result()"
]
},
{
"cell_type": "markdown",
"metadata": {
"tags": [
"ignore"
]
},
"source": [
"# 5. Final Report"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"ignore"
]
},
"outputs": [],
"source": [
"if not source_timestamp_df.empty:\n",
" analysis_start_time = Time.get_analysis_start_time()\n",
" prefix_circuit_name = circuit_name.split('.')[0]\n",
" date_time_qh = Time.to_datetime(source_timestamp_df.loc[0, 'timestamp']).strftime(\"%Y-%m-%d-%Hh%M\")\n",
"\n",
" apply_report_template()\n",
" !mkdir -p /eos/project/m/mp3/IPQ/$prefix_circuit_name/$circuit_name/QHDA\n",
" file_name_html = \"{}_QHDA-{}-{}_{}.html\".format(circuit_name, date_time_qh, analysis_start_time, signature)\n",
" 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\"]'"
]
},
{
"cell_type": "markdown",
"metadata": {
"tags": [
"ignore"
]
},
"source": [
"# 6. Save Timestamps in Reference Format (if update needed)"
]