Commit ea4553d0 authored by Agata Malgorzata Chadaj's avatar Agata Malgorzata Chadaj
Browse files

Merge branch 'dev' of https://gitlab.cern.ch/LHCData/lhc-sm-hwc into...

Merge branch 'dev' of https://gitlab.cern.ch/LHCData/lhc-sm-hwc into SIGMON-150_execute_notebooks_on_jenkins
parents 8e2430b0 9fbedc59
%% Cell type:markdown id: tags:
<h1><center>Analysis of an FPA in an 600A Circuit - with/without Energy Extraction</center></h1>
Figure 1 shows a generic circuit diagram, equipped with EE and parallel resistor, as well as lead resistances and a quench resistance.
<img src="https://gitlab.cern.ch/LHCData/lhc-sm-hwc/-/raw/master/figures/600A/600A.png" width=75%>
source: Test Procedure and Acceptance Criteria for the 600 A Circuits, MP3 Procedure, <a href="https://edms.cern.ch/document/874716">https://edms.cern.ch/document/874716</a>
%% Cell type:markdown id: tags:
# Analysis Assumptions
- We consider standard analysis scenarios, i.e., all signals can be queried. If a signal is missing, an analysis can raise a warning and continue or an error and abort the analysis.
- It is recommended to execute each cell one after another. However, since the signals are queried prior to analysis, any order of execution is allowed. In case an analysis cell is aborted, the following ones may not be executed (e.g. I\_MEAS not present).
# Plot Convention
- Scales are labeled with signal name followed by a comma and a unit in square brackets, e.g., I_MEAS, [A].
- If a reference signal is present, it is represented with a dashed line.
- If the main current is present, its axis is on the left. Remaining signals are attached to the axis on the right. The legend of these signals is located on the lower left and upper right, respectively.
- The grid comes from the left axis.
- The title contains timestamp, circuit name, and signal name allowing to re-access the signal.
- The plots assigned to the left scale have colors: blue (C0) and orange (C1). Plots presented on the right have colors red (C2) and green (C3).
- Each plot has an individual time-synchronization mentioned explicitly in the description.
- If an axis has a single signal, then the color of the label matches the signal's color. Otherwise, the label color is black.
%% Cell type:markdown id: tags:
# 0. Initialise Working Environment
%% Cell type:code id: tags:
``` python
# External libraries
print('Loading (1/16)'); import pandas as pd
print('Loading (2/16)'); import numpy as np
print('Loading (3/16)'); import sys
print('Loading (4/16)'); from IPython.display import display, Javascript, clear_output, HTML
# Internal libraries
print('Loading (5/16)'); import lhcsmapi
print('Loading (6/16)'); from lhcsmapi.Time import Time
print('Loading (7/16)'); from lhcsmapi.Timer import Timer
print('Loading (8/16)'); from lhcsmapi.analysis.R600ACircuitQuery import R600ACircuitQuery
print('Loading (9/16)'); from lhcsmapi.analysis.R600ACircuitAnalysis import R600ACircuitAnalysis
print('Loading (10/16)'); from lhcsmapi.analysis.expert_input import get_expert_decision
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.pc.FgcPmSearchModuleMediator import FgcPmSearchModuleMediator
print('Loading (14/16)'); from lhcsmapi.metadata.SignalMetadata import SignalMetadata
print('Loading (15/16)'); from lhcsmnb.parameters import are_all_parameters_injected, NbType
print('Loading (16/16)'); import lhcsmnb.utils
clear_output()
lhcsmapi.get_lhcsmapi_version()
lhcsmapi.get_lhcsmhwc_version('../__init__.py')
```
%% Cell type:markdown id: tags:
# 1. Select FGC Post Mortem Entry
%% Cell type:markdown id: tags:skip_cell
In order to perform the analysis of a FPA in an 600A circuit with/without EE please:
1. Select circuit family (e.g., RCS)
2. Choose start and end time
3. Choose analysis mode (Automatic by default)
Once these inputs are provided, click 'Find FGC PM' button entries'. This will trigger a search of the PM database in order to provide a list of timestamps of FGC events associated with the selected circuit name for the provided period of time. Select one timestamp from the 'FGC PM Entries' list to be processed by the following cells.
**Note that 24 hours is the maximum duration of a single PM query for an event. To avoid delays in querying events, please restrict your query duration as much as possible.**
%% Cell type:code id: tags:parameters
``` python
circuit_type = '600A'
fgc_pm_search = FgcPmSearchModuleMediator(DateTimeBaseModule(start_date_time='2021-01-26 00:00:00+01:00',
end_date_time='2021-01-31 00:00:00+01:00'), circuit_type=circuit_type)
```
%% Cell type:markdown id: tags:
# 2. Query All Signals Prior to Analysis
%% Cell type:code id: tags:skip_output
``` python
with Timer():
if not are_all_parameters_injected(NbType.FGC, locals()):
author = fgc_pm_search.get_author()
is_automatic = fgc_pm_search.is_automatic_mode()
timestamp_fgc = fgc_pm_search.get_fgc_timestamp()
circuit_name = fgc_pm_search.get_fgc_circuit()
query = R600ACircuitQuery(circuit_type, circuit_name, max_executions=10)
i_meas_df, i_a_df, i_ref_df, i_earth_df = query.query_pc_pm(timestamp_fgc, timestamp_fgc, signal_names=['I_MEAS', 'I_A', 'I_REF', 'I_EARTH'])
events_action_df, events_symbol_df = query.query_pc_pm_events(timestamp_fgc, signal_names=['ACTION', 'SYMBOL'])
# Create results table
results_table = query.create_report_analysis_template(timestamp_fgc, init_file_path='../__init__.py', author=author)
# PIC
timestamp_pic = query.find_timestamp_pic(timestamp_fgc, spark=spark)
# EE
if 'EE' in SignalMetadata.get_system_types_per_circuit_name(circuit_type, circuit_name):
query.max_executions += 2
source_timestamp_ee_df = query.find_source_timestamp_ee(timestamp_fgc)
timestamp_ee = lhcsmnb.utils.get_at(source_timestamp_ee_df, 0, 'timestamp')
u_dump_res_df = query.query_ee_u_dump_res_pm(timestamp_ee, timestamp_fgc, system='EE', signal_names=['U_DUMP_RES'])[0]
else:
source_timestamp_ee_df = pd.DataFrame()
# QDS
# To check if there was any drift of QDS cards prior to the trigger
i_meas_nxcals_df = query.query_pc_nxcals(timestamp_fgc, signal_names=['I_MEAS'], spark=spark)[0]
u_res_nxcals_df = query.query_iqps_nxcals(timestamp_fgc, signal_names=['U_RES'], spark=spark)[0]
source_timestamp_qds_df = query.find_source_timestamp_qds_board_ab(timestamp_fgc, duration=[(2, 's'), (2, 's')])
timestamp_qds = lhcsmnb.utils.get_at(source_timestamp_qds_df, 0, 'timestamp', default=np.nan)
i_dcct_df, i_didt_df, u_res_df, u_diff_df = query.query_qds_pm(timestamp_qds, timestamp_qds, signal_names=['I_DCCT', 'I_DIDT', 'U_RES', 'U_DIFF'])
# LEADS
leads_name = [x for x in SignalMetadata.get_system_types_per_circuit_name(circuit_type, circuit_name) if 'LEADS' in x][0]
source_timestamp_leads_df = query.find_timestamp_leads(timestamp_fgc, leads_name)
u_hts_leads_dfs = query.query_leads(timestamp_fgc, source_timestamp_leads_df, system=leads_name, signal_names=['U_HTS'], spark=spark, duration=[(300, 's'), (900, 's')])
u_res_leads_dfs = query.query_leads(timestamp_fgc, source_timestamp_leads_df, system=leads_name, signal_names=['U_RES'], spark=spark, duration=[(300, 's'), (900, 's')])
analysis = R600ACircuitAnalysis(circuit_type, results_table, is_automatic=is_automatic)
timestamp_dct = {'FGC': timestamp_fgc, 'PIC': timestamp_pic,
'QDS_A': lhcsmnb.utils.get_at(source_timestamp_qds_df, 0, 'timestamp', default=np.nan),
'QDS_B': slhcsmnb.utils.get_at(source_timestamp_qds_df, 1, 'timestamp', default=np.nan)}
'QDS_B': lhcsmnb.utils.get_at(source_timestamp_qds_df, 1, 'timestamp', default=np.nan)}
if 'EE' in SignalMetadata.get_system_types_per_circuit_name(circuit_type, circuit_name):
timestamp_dct['EE'] = lhcsmnb.utils.get_at(source_timestamp_ee_df, 0, 'timestamp', default=np.nan)
```
%% Cell type:markdown id: tags:
# 3. Timestamps
The analysis for MP3 consists of checking the existence of PM file and of consistency of the PM timestamps (PC, QPS, EE if applicable). The criterion of passing this test described in detail in 600APIC2.
In short the following criteria should be checked:
- 2 PM DQAMGNA (A+B) files and 1 PM EE file should be generated for 600 A circuits with EE
- Difference between QPS board A and B timestamp = 1 ms
- PC timestamp is QPS timestamp +/- 20 ms
- EE timestamp is +/-20 ms from the QPS timestamp
If one or more of these conditions are not fulfilled, then an in-depth analysis has to be performed by the QPS team.
%% Cell type:code id: tags:
``` python
analysis.create_timestamp_table(timestamp_dct, circuit_name)
```
%% Cell type:markdown id: tags:
# 4. PC
## 4.1. Main Current
*ANALYSIS*:
- determination of the source of an FPA trigger based on EVENTS.SYMBOL and EVENTS.ACTION signals
- detection of the start of a quench as a deviation of I_A and I_REF
- calculation of the MIITs
- calculation of the quench current
- calculation of the duration of a plateau / the ramp rate before a quench
**You may manually adjust the automatically calculated quench start by clicking the right button on a mouse of a plot with current zoom.**
*GRAPHS*:
- dashed blue line denotes the start of a quench (I_A starts to deviate from I_REF)
- t = 0 s corresponds to the FGC timestamp
%% Cell type:code id: tags:
``` python
import matplotlib as mpl
mpl.rcParams['savefig.dpi'] = 80
mpl.rcParams['figure.dpi'] = 80
%matplotlib notebook
analysis.plot_i_meas_pc(circuit_name, timestamp_fgc, [i_meas_df, i_a_df, i_ref_df])
```
%% Cell type:code id: tags:
``` python
t_quench = analysis.estimate_quench_start_from_i_ref_i_a(i_ref_df, i_a_df)
t_quench = 0 if t_quench is None else t_quench
t_quench_correction = analysis.plot_i_meas_pc_with_cursor(circuit_name, timestamp_fgc, [i_meas_df, i_a_df, i_ref_df], t_quench)
```
%% Cell type:code id: tags:
``` python
analysis.analyze_i_meas_pc_trigger(timestamp_fgc, events_action_df, events_symbol_df)
t_quench = analysis.choose_quench_time_from_auto_or_manual(t_quench_correction)
analysis.calculate_current_miits_i_meas_i_a(i_meas_df, i_a_df, t_quench, col_name='MIITS_circ')
analysis.calculate_quench_current(i_meas_df, t_quench, col_name='I_Q_circ')
analysis.calculate_current_slope(i_meas_df, col_name=['Ramp rate', 'Plateau duration'])
```
%% Cell type:markdown id: tags:
## 4.2. Earth Current
*ANALYSIS*:
- calculation of the maximum absolute earth current (maintaining the sign)
*PLOT*:
- t = 0 s corresponds to the FGC timestamp
%% Cell type:code id: tags:
``` python
analysis.plot_i_earth_pc(circuit_name, timestamp_fgc, i_earth_df)
analysis.calculate_max_i_earth_pc(i_earth_df, col_name='I_Earth_max')
```
%% Cell type:markdown id: tags:
# 5. EE
The analysis is only performed for circuits with an EE system.
*ANALYSIS*:
- calculation of the maximum voltage over the energy extraction system
*GRAPHS*:
- t = 0 s corresponds to the FGC timestamp
%% Cell type:code id: tags:
``` python
if 'EE' in SignalMetadata.get_system_types_per_circuit_name(circuit_type, circuit_name):
analysis.analyze_u_dump_res_ee(circuit_name, timestamp_fgc, i_meas_df, u_dump_res_df, col_name='U_EE_max')
else:
print('Circuit %s does not contain an EE system, analysis skipped.' % circuit_name)
```
%% Cell type:code id: tags:
``` python
if 'EE' in SignalMetadata.get_system_types_per_circuit_name(circuit_type, circuit_name):
analysis.results_table['EE analysis'] = get_expert_decision('EE analysis: ', ['PASS', 'FAIL'])
else:
analysis.results_table['EE analysis'] = 'No EE'
```
%% Cell type:markdown id: tags:
# 6. QDS
The quench voltage U_RES is calculated according to the following formula:
\begin{equation}
U_{\text{RES}} = U_{\text{DIFF}} + L d/dt (I+U_{\text{DIFF}}/R).
\end{equation}
Note that I_DCCT is the QPS signal name, even though the current is actually measured not with a DCCT, but with a LEM detector, hence the poorer quality w.r.t. to the FGC I_A/B/MEAS signals that are measured with a DCCT.
It can be seen from the sign convention in the figure below that a resistive voltage always has opposite sign to the measured current.
<img src="https://gitlab.cern.ch/LHCData/lhc-sm-hwc/-/raw/master/figures/600A/600A.png" width=75%>
As U_DIFF contributes directly to U_RES, the resolution of U_RES is, at least partially, limited by that of U_DIFF. Moreover, U_RES is affected by the noisy time derivative of the current signal.
The QPS signals that are communicated to the post-mortem system have only 12 bit resolution.
%% Cell type:markdown id: tags:
## 6.1. Resistive Voltage
*ANALYSIS*:
- Check if the U_RES signal before a quench is increasing for at least one board, which would indicate a QPS trip
- Calculate the initial voltage slope of U_RES signal. The slope is calculated as a ratio of the voltage change from 50 to 200 mV and the corresponding time change.
*GRAPHS*:
First plot (U_RES and I_MEAS prior to a quench)
- t = 0 s corresponds to the FGC timestamp
Second plot (U_RES and the initial slope of U_RES)
- t = 0 s corresponds to the QPS timestamp
%% Cell type:code id: tags:
``` python
analysis.plot_u_res(circuit_name, timestamp_qds, u_res_nxcals_df, i_meas_nxcals_df)
```
%% Cell type:code id: tags:
``` python
u_res_slope_df = analysis.calculate_u_res_slope(u_res_df, col_name='dU_QPS/dt')
analysis.plot_u_res_slope(circuit_name, timestamp_qds, u_res_df, u_res_slope_df)
```
%% Cell type:markdown id: tags:
## 6.2. I_DCCT, I_DIDT Currents; U_RES, U_DIFF Voltages
*ANALYSIS*
- Check the integrity of all four signals (U_DIFF, I_DCCT, I_DIDT and U_RES). If one of the signals (especially U_DIFF or I_DCCT) stays at zero or shows wrong values the cabling of this quench detector could have issues. Compare U_DIFF (measured signal) to U_REF (signal compensated for inductive voltage).
*CRITERIA*
- U_RES < 0.7*100 mV
- **noise of U_RES on the plateaus < 20mV**
*GRAPHS*:
- t = 0 s corresponds to the QPS timestamp
%% Cell type:code id: tags:
``` python
analysis.plot_qds(circuit_name, timestamp_qds, i_dcct_df, i_didt_df, u_diff_df, u_res_df)
```
%% Cell type:markdown id: tags:
## 6.3. LEADS
*ANALYSIS*:
- check if U_HTS for 2 consecutive datapoints is above the threshold 3 mV
- check if U_RES for 2 consecutive datapoints is above the threshold 100 mV
*GRAPHS*:
- t = 0 s corresponds to the FGC timestamp
%% Cell type:code id: tags:
``` python
analysis.analyze_leads_voltage(u_hts_leads_dfs, circuit_name, timestamp_fgc, signal='U_HTS', value_min=-0.003, value_max=0.003)
```
%% Cell type:code id: tags:
``` python
analysis.analyze_leads_voltage(u_res_leads_dfs, circuit_name, timestamp_fgc, signal='U_RES', value_min=-0.1, value_max=0.1)
```
%% Cell type:code id: tags:
``` python
if not is_automatic:
analysis.results_table['FPA Reason'] = get_expert_decision('Reason for FPA: ', ['QPS trip', 'Converter trip', 'EE spurious opening', 'Spurious heater firing', 'Busbar quench', 'Magnet quench', 'HTS current lead quench' ,'RES current lead overvoltage', 'No quench', 'Unknown'])
analysis.results_table['Type of Quench'] = get_expert_decision('Type of Quench: ', ['Training', 'Heater-provoked', 'Beam-induced', 'GHe propagation', 'QPS crate reset', 'Single Event Upset' ,'Short-to-ground', 'EM disturbance', 'No quench', 'Unknown'])
analysis.results_table['QDS trigger origin'] = get_expert_decision('QDS trigger origin: ', ['QPS', 'HTS current lead', 'RES current lead', 'Busbar', 'No quench'])
```
%% Cell type:markdown id: tags:
# 7. Analysis Comment
%% Cell type:code id: tags:
``` python
if not is_automatic:
analysis.results_table['Comment'] = input('Comment: ')
```
%% Cell type:markdown id: tags:ignore
# 8. Final Report
%% Cell type:code id: tags:ignore
``` python
pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', None)
analysis_start_time = Time.get_analysis_start_time()
date_time_fgc = Time.to_datetime(timestamp_fgc).strftime("%Y-%m-%d-%Hh%M")
prefix_circuit_name = SignalMetadata.parse_600A_circuit_name_to_family_name(circuit_name)
!mkdir -p /eos/project/m/mp3/600A/$prefix_circuit_name/$circuit_name/FPA
file_name = "{}_FPA-{}-{}".format(circuit_name, date_time_fgc, analysis_start_time)
full_path = '/eos/project/m/mp3/600A/{}/{}/FPA/{}.csv'.format(prefix_circuit_name, circuit_name, file_name)
mp3_results_table = analysis.create_mp3_results_table()
display(HTML(mp3_results_table.T.to_html()))
mp3_results_table.to_csv(full_path, index=False)
print('MP3 results table saved to (Windows): ' + '\\\\cernbox-smb' + full_path.replace('/', '\\'))
apply_report_template()
full_path = '/eos/project/m/mp3/600A/{}/{}/FPA/{}.html'.format(prefix_circuit_name, circuit_name, file_name)
print('Compact notebook report saved to (Windows): ' + '\\\\cernbox-smb' + full_path.replace('/', '\\'))
display(Javascript('IPython.notebook.save_notebook();'))
Time.sleep(5)
file_name_html = file_name + '.html'
!{sys.executable} -m jupyter nbconvert --to html $'AN_600A_with_without_EE_FPA.ipynb' --output /eos/project/m/mp3/600A/$prefix_circuit_name/$circuit_name/FPA/$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
```
......
%% Cell type:markdown id: tags:
<h1><center>Analysis of a PLI2.e3 HWC Test in an IPQ Circuit</center></h1>
The Individually Powered Quadrupole magnets (IPQs) in the LHC are located on both sides of the Interaction Regions (IR), in the matching sector and in the dispersion suppressor. The IPQ circuits RQ4 to RQ7 are part of the matching sector, and the IPQ circuits RQ8 to RQ10 are part of the dispersion suppressor. The magnets Q4 to Q6 are operated at
4.5 K, whereas the magnets Q7 to Q10 are operated at 1.9 K.
The MQM quadrupole consists of two individually powered apertures assembled in a common yoke structure.
The MQY wide-aperture quadrupole consists of two individually powered apertures assembled in a common yoke structure.
### PLI2.E3 - SPLICE MAPPING AND UNBALANCED SLOW POWER ABORT
For the HWC 2014, this test has been modified to include splice mapping. By increasing the current level from I\_INTERM\_1 to I\_INTERM\_2, the difference in maximum current between this test and next test at I\_PNO is reduced. In addition a plateau at I\_INJECTION is added to serve the splice mapping.
The aim of this test is to verify the response of both power converters in case of Slow Power Abort with unbalanced currents and to perform splice mapping.
<img src="https://gitlab.cern.ch/LHCData/lhc-sm-hwc/-/raw/master/figures/ipq/PLI2.E3_current.png" width=50%>
<center>Current during PLI2.E3 for tests starting from 2014 HWC. The actual values of current may deviate from the values shown above.</center>
Offline analyses are listed below:
|Responsible|Type of Analysis|Criteria|
|-----------|----------------|--------|
|PC|Verify acceleration and ramp rate of the PCs||
|PC|PC voltage and current||
|MP3|Check if QPS tripped (it is not expected).||
| |Check if PM file was created (it is not expected).||
| |Calculate splice resistances (**not possible due to limited logging resolution**)||
| |Check DFB regulation|T_top_HTS = 50 +/- 4 K|
| ||T_top_Cu = temperature at 0 A current +/- 10 K|
source: Test Procedure for the Individually Powered 4-6 kA Quadrupole-Circuits in the LHC Insertions, MP3 Procedure, <a href="https://edms.cern.ch/document/874884">https://edms.cern.ch/document/874884</a> (Please follow this link for the latest version)
%% Cell type:markdown id: tags:
# Analysis Assumptions
- We consider standard analysis scenarios, i.e., all signals can be queried. If a signal is missing, an analysis can raise a warning and continue or an error and abort the analysis.
- It is recommended to execute each cell one after another. However, since the signals are queried prior to analysis, any order of execution is allowed. In case an analysis cell is aborted, the following ones may not be executed (e.g. I\_MEAS not present).
# Plot Convention
- Scales are labeled with signal name followed by a comma and a unit in square brackets, e.g., I_MEAS, [A].
- If a reference signal is present, it is represented with a dashed line.
- If the main current is present, its axis is on the left. Remaining signals are attached to the axis on the right. The legend of these signals is located on the lower left and upper right, respectively.
- The grid comes from the left axis.
- The title contains timestamp, circuit name, and signal name allowing to re-access the signal.
- The plots assigned to the left scale have colors: blue (C0) and orange (C1). Plots presented on the right have colors red (C2) and green (C3).
- Each plot has an individual time-synchronization mentioned explicitly in the description.
- If an axis has a single signal, then the color of the label matches the signal's color. Otherwise, the label color is black.
%% Cell type:markdown id: tags:
# 0. Initialise Working Environment
%% Cell type:code id: tags:
``` python
# External libraries
print('Loading (1/13)'); import sys
print('Loading (2/13)'); import pandas as pd
print('Loading (3/13)'); import numpy as np
print('Loading (4/13)'); from IPython.display import display, Javascript, clear_output
print('Loading (1/14)'); import sys
print('Loading (2/14)'); import pandas as pd
print('Loading (3/14)'); import numpy as np
print('Loading (4/14)'); from IPython.display import display, Javascript, clear_output
# Internal libraries
print('Loading (5/13)'); import lhcsmapi
print('Loading (6/13)'); from lhcsmapi.Time import Time
print('Loading (7/13)'); from lhcsmapi.Timer import Timer
print('Loading (8/13)'); from lhcsmapi.analysis.IpqCircuitQuery import IpqCircuitQuery
print('Loading (9/13)'); from lhcsmapi.analysis.IpqCircuitAnalysis import IpqCircuitAnalysis
print('Loading (10/13)'); from lhcsmapi.analysis.report_template import apply_report_template
print('Loading (11/13)'); from lhcsmapi.gui.hwc.HwcSearchModuleMediator import HwcSearchModuleMediator
print('Loading (12/13)'); from lhcsmapi.pyedsl.PlotBuilder import create_hwc_plot_title_with_circuit_name
print('Loading (13/13)'); from lhcsmapi.analysis.expert_input import get_expert_decision
print('Loading (5/14)'); import lhcsmapi
print('Loading (6/14)'); from lhcsmapi.Time import Time
print('Loading (7/14)'); from lhcsmapi.Timer import Timer
print('Loading (8/14)'); from lhcsmapi.analysis.IpqCircuitQuery import IpqCircuitQuery
print('Loading (9/14)'); from lhcsmapi.analysis.IpqCircuitAnalysis import IpqCircuitAnalysis
print('Loading (10/14)'); from lhcsmapi.analysis.report_template import apply_report_template
print('Loading (11/14)'); from lhcsmapi.gui.hwc.HwcSearchModuleMediator import HwcSearchModuleMediator
print('Loading (12/14)'); from lhcsmapi.pyedsl.PlotBuilder import create_hwc_plot_title_with_circuit_name
print('Loading (13/14)'); from lhcsmapi.analysis.expert_input import get_expert_decision
print('Loading (14/14)'); import lhcsmnb.utils
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. User Input
1. Copy code from AccTesting and paste into an empty cell below
<img src="https://gitlab.cern.ch/LHCData/lhc-sm-hwc/-/raw/master/figures/swan-manual-acctesting-integration.png">
- If you only want to test the notebook only for the copy&paste feature (without opening the AccTesting), please copy and execute the code below
```
hwc_test = 'PLI2.e3'
circuit_name = 'RQ10.L2'
campaign = 'HWC_2017'
t_start = '2017-04-21 17:28:45.861'
t_end = '2017-04-21 17:54:39.795'
```
2. To analyze a historical test with a browser GUI, copy and execute the following code in the cell below
```
circuit_type = 'IPQ'
hwc_test = 'PLI2.e3'
hwcb = HwcSearchModuleMediator(circuit_type=circuit_type, hwc_test=hwc_test, hwc_summary_path='/eos/project/l/lhcsm/hwc/HWC_Summary.csv')
```
- After opening the browser GUI, choose a circuit name in order to display HWC test with, campaign name as well as start and end time
%% Cell type:code id: tags:parameters
``` python
```
%% Cell type:code id: tags:
``` python
print('hwc_test = \'%s\'\ncircuit_name = \'%s\'\ncampaign = \'%s\'\nt_start = \'%s\'\nt_end = \'%s\'' % (hwc_test, circuit_name, campaign, t_start, t_end))
```
%% Cell type:markdown id: tags:
# 2. Query All Signals Prior to Analysis
%% Cell type:code id: tags:skip_output
``` python
circuit_type = 'IPQ'
if 'hwcb' in locals():
circuit_name = hwcb.get_circuit_name()
t_start = Time.to_unix_timestamp(hwcb.get_start_time())
t_end = Time.to_unix_timestamp(hwcb.get_end_time())
is_automatic = hwcb.is_automatic_mode()
else:
t_start = Time.to_unix_timestamp(t_start)
t_end = Time.to_unix_timestamp(t_end)
is_automatic = False
ipq_query = IpqCircuitQuery(circuit_type, circuit_name, max_executions=5)
ipq_analysis = IpqCircuitAnalysis(circuit_type, pd.DataFrame(), circuit_name=circuit_name)
with Timer():
# PIC
dt = Time.to_unix_timestamp(t_end)-Time.to_unix_timestamp(t_start)
timestamp_pic = ipq_query.find_timestamp_pic(t_start, duration=(dt, 'ns'), spark=spark)
# PC
i_meas_b1_df, i_meas_b2_df = ipq_query.query_signal_nxcals(t_start, t_end, t0=t_start, system='PC', signal_names='I_MEAS', spark=spark)
source_timestamp_fgc_df = ipq_query.find_source_timestamp_pc(t_start, t_end)
if not source_timestamp_fgc_df.empty:
source_fgc_b1, timestamp_fgc_b1 = ipq_query.split_source_timestamp_fgc(source_timestamp_fgc_df, 'B1')
source_fgc_b2, timestamp_fgc_b2 = ipq_query.split_source_timestamp_fgc(source_timestamp_fgc_df, 'B2')
else:
timestamp_fgc_b1, timestamp_fgc_b2 = np.nan, np.nan
# QDS
if not source_timestamp_fgc_df.empty:
source_timestamp_qds_df = ipq_query.find_source_timestamp_qds_board_ab(timestamp_fgc_b1, duration=[(2, 's'), (2, 's')])
else:
source_timestamp_qds_df = pd.DataFrame()
# Splice resistance
u_res_b1_raw_df, u_res_b2_raw_df = ipq_query.query_raw_signal_nxcals(t_start, t_end, system='QDS', signal_names=['U_RES_B1', 'U_RES_B2'], spark=spark)
# LEADS
tt893_nxcals_b1_dfs = ipq_query.query_dfb_signal_nxcals(t_start, t_end, system='LEADS_B1_NXCALS_WINCCOA', signal_names='TT893', spark=spark)
tt891a_nxcals_b1_dfs = ipq_query.query_dfb_signal_nxcals(t_start, t_end, system='LEADS_B1_NXCALS_WINCCOA', signal_names='TT891A', spark=spark)
# DFB
tt893_nxcals_b2_dfs = ipq_query.query_dfb_signal_nxcals(t_start, t_end, system='LEADS_B2_NXCALS_WINCCOA', signal_names='TT893', spark=spark)
tt891a_nxcals_b2_dfs = ipq_query.query_dfb_signal_nxcals(t_start, t_end, system='LEADS_B2_NXCALS_WINCCOA', signal_names='TT891A', spark=spark)
timestamp_dct = {'FGC_B1': timestamp_fgc_b1, 'FGC_B2': timestamp_fgc_b2, 'PIC': timestamp_pic,
'QDS_A':lhcsmnb.utils.get_at(source_timestamp_qds_df, 0, 'timestamp', default=np.nan),
'QDS_B':lhcsmnb.utils.get_at(source_timestamp_qds_df, 1, 'timestamp', deafult=np.nan)}
'QDS_B':lhcsmnb.utils.get_at(source_timestamp_qds_df, 1, 'timestamp', default=np.nan)}
```
%% Cell type:markdown id: tags:
# 3. Timestamps
It is expected that neither the PC nor QPS PM files were created.
In case the QPS tripped, the analysis for MP3 consists of checking the existence of PM file and of consistency of the PM timestamps (PC, QPS).
In short the following criteria should be checked:
- The PC timestamp (51_self) is QPS timestamp +-20 ms.
- The difference between QPS board A and B timestamp = 1ms.
If one or more of these conditions are not fulfilled, then an in-depth analysis has to be performed by the QPS team.
%% Cell type:code id: tags:
``` python
ipq_analysis.create_timestamp_table(timestamp_dct)
```
%% Cell type:markdown id: tags:
# 4. PC
## 4.1. Main Current
*GRAPHS*:
- t = 0 s corresponds to the start of the test
- one plot for each power converter
- orange boxes denote current plateaus
%% Cell type:code id: tags:
``` python
import matplotlib as mpl