Commit 5814b0df authored by Michal Maciejewski's avatar Michal Maciejewski
Browse files

Integrated busbar/magnet resistance query and computation

parent b6e106a4
This diff is collapsed.
This diff is collapsed.
%% Cell type:markdown id: tags:
<h1><center>Analysis of a PNO.D16 HWC Test in an IT Circuit</center></h1>
The main quadrupole magnet circuits of the 8 Inner Triplet (IT) systems in the LHC are composed of four single aperture quadrupole magnets in series and have a particular powering configuration, consisting of three nested power converters (PC), see Figure below.
<img src="https://gitlab.cern.ch/LHCData/lhc-sm-hwc/-/raw/master/figures/it/IT.png" width=75%>
Main quadrupole magnet circuit of the Inner Triplet system for IT’s at points 1 and 5 (left) and IT’s at points 2 and 8 (right).
Note that the configuration for the IT’s in points 1 and 5 is different from the configuration in points 2 and 8. An earth detection system is present at the minus of the RTQX2 converter. Detailed information concerning the converters is given in EDMS 1054483. Note that the currents in the quadrupole magnets are given by:
\begin{equation}
I_\text{Q1} = I_\text{RQX} + I_\text{RTQX1} \\
I_\text{Q2} = I_\text{RQX} + I_\text{RTQX2} \\
I_\text{Q3} = I_\text{RQX} \\
\end{equation}
The two magnets Q1 and Q3 are type MQXA and the two combined magnets Q2a and Q2b are type MQXB. Q1 is located towards the interaction point.
Note that the IT’s at points 2 and 8 have a slightly higher nominal operating current than the IT’s at points 1 and 5, see Table 1.
|Circuit|I\_PNO RQX|I\_PNO RTQX2|I\_PNO RTQX1|
|-------|----------|------------|------------|
|RQX.L2, RQX.R2, RQX.L8, RQX.R8|7180 A| 4780 A|550 A|
|RQX.L1, RQX.R1, RQX.L5, RQX.R5|6800 A| 4600 A|550 A|
### PNO.D16: PC Failure at 90% of I_PNO
The aim of this test is to calculate the splice resistances, check the regulation of the current leads, and verify the correct functionality of the PC when a powering failure is generated. The currents are equal to 90% of the nominal current in the RQX, RTQX1, and RTQX2 converters, see figures below.
<img src="https://gitlab.cern.ch/LHCData/lhc-sm-hwc/-/raw/master/figures/it/PNO.D16_current_pcs.png" width=75%>
<img src="https://gitlab.cern.ch/LHCData/lhc-sm-hwc/-/raw/master/figures/it/PNO.D16_current_magnets.png" width=75%>
<center>Currents vs time for test PNO.D16</center>
The offline analysis is given in the table below:
|Responsible|Type of analysis|Criteria|
|-----------|----------------|--------|
|PC|Verification of the tracking error between I_REF and I_MEAS for the three PC's|I_ERR < 10 ppm|
|~|~|I_EARTH < 10 mA (online checked by the sequencer)|
|MP3|Calculate splice resistances|R_max < 5 nOhm|
|MP3|Check DFB regulation|T_top_HTS (TT891A) = 50 +/- 4K|
|~|~|T_top_Cu (TT893) = 293 +/- 10 K|
|MP3|Check margin between U_RES and the QPS threshold|U_RES < 30 mV for both boards at the start of the PC fault|
source: Test Procedure and Acceptance Criteria for the Inner Triplet Circuits in the LHC, MP3 Procedure, <a href="https://edms.cern.ch/document/874886/2.1">https://edms.cern.ch/document/874886/2.1</a>
%% Cell type:markdown id: tags:
# Analysis Assumptions
- We consider standard analysis scenarios, i.e., all signals can be queried. Depending on what signal is missing, an analysis can raise a warning and continue or an error and abort the analysis.
- In case an analyzed signal can't be queried, a particular analysis is skipped. In other words, all signals have to be available in order to perform an analysis.
- It is recommended to execute each cell one after another. However, since the signals are queried prior to an 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 the square bracket, 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
- Title contains timestamp, circuit name, signal name allowing for re-access the signal.
- The plots assigned to the left scale got 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, change color of the label to match 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
import io
import re
import sys
import pandas as pd
import numpy as np
from datetime import datetime
import time
from IPython.display import display, Javascript
# Spark libraries
from pyspark.sql.functions import udf
from pyspark.sql.types import IntegerType
from lhcsmapi.Time import Time
from lhcsmapi.Timer import Timer
from lhcsmapi.pyedsl.QueryBuilder import QueryBuilder
from lhcsmapi.pyedsl.PlotBuilder import PlotBuilder
import lhcsmapi.pyedsl.SignalTransformationBuilder as SignalTransformationBuilder
from lhcsmapi.pyedsl.AssertionBuilder import AssertionBuilder
from lhcsmapi.analysis.ItCircuitQuery import ItCircuitQuery
from lhcsmapi.analysis.ItCircuitAnalysis import ItCircuitAnalysis
from lhcsmapi.analysis.busbar.BusbarResistanceAnalysis import find_plateau_start_and_end, extract_intersecting_plateaus, find_start_end_of_the_longest_ramp_up
# GUI
from lhcsmapi.gui.hwc.HwcBrowser import HwcBrowser
analysis_start_time = datetime.now().strftime("%Y.%m.%d_%H%M%S.%f")
import lhcsmapi
print('Analysis executed with lhcsmapi version: {}'.format(lhcsmapi.__version__))
with io.open("../__init__.py", "rt", encoding="utf8") as f:
version = re.search(r'__version__ = "(.*?)"', f.read()).group(1)
print('Analysis executed with lhc-sm-hwc notebooks version: {}'.format(version))
```
%% Cell type:markdown id: tags:
# 1. Select HWC Test
%% Cell type:code id: tags:
``` python
circuit_type = 'IT'
hwc_test = 'PNO.D16'
hwc_test_history_df = pd.read_csv('/eos/project/l/lhcsm/hwc/IT/hwc_test_history.csv')
hwcb = HwcBrowser(hwc_test_history_df, circuit_type, hwc_test)
display(hwcb.widget)
```
%% Cell type:markdown id: tags:
# 2. Query All Signals Prior to Analysis
%% Cell type:code id: tags:skip_output
``` python
circuit_name = hwcb.get_circuit_name()
t_start = hwcb.get_start_time()
t_end = hwcb.get_end_time()
author = hwcb.get_author()
is_automatic = hwcb.is_automatic_mode()
it_query = ItCircuitQuery(circuit_type, circuit_name)
it_analysis = ItCircuitAnalysis(circuit_type, results_table=None, is_automatic=is_automatic)
with Timer():
# PC - NXCALS
i_meas_rqx_nxcals_df, i_meas_rtqx1_nxcals_df, i_meas_rtqx2_nxcals_df = QueryBuilder().with_nxcals(spark) \
.with_duration(t_start=t_start, t_end=t_end) \
.with_circuit_type(circuit_type) \
.with_metadata(circuit_name=circuit_name, system='PC', signal='I_MEAS') \
.signal_query() \
.synchronize_time() \
.convert_index_to_sec().dfs
i_meas_rqx_nxcals_df, i_meas_rtqx1_nxcals_df, i_meas_rtqx2_nxcals_df = it_query.query_signal_nxcals(t_start, t_end, system='PC', signal_names='I_MEAS', spark=spark)
i_meas_rqx_nxcals_df.rename(columns={"I_MEAS": "I_MEAS_RQX"}, inplace=True)
i_meas_rtqx1_nxcals_df.rename(columns={"I_MEAS": "I_MEAS_RTQX1"}, inplace=True)
i_meas_rtqx2_nxcals_df.rename(columns={"I_MEAS": "I_MEAS_RTQX2"}, inplace=True)
# I_Q1 = I_RQX + I_RTQX1
i_meas_q1_nxcals_df = SignalTransformationBuilder.add_two_dataframes(i_meas_rqx_nxcals_df, i_meas_rtqx1_nxcals_df, col_name='I_MEAS_Q1')
# I_Q2 = I_RQX + I_RTQX2
i_meas_q2_nxcals_df = SignalTransformationBuilder.add_two_dataframes(i_meas_rqx_nxcals_df, i_meas_rtqx2_nxcals_df, col_name='I_MEAS_Q2')
# I_Q3 = I_RQX
i_meas_q3_nxcals_df = pd.DataFrame(index=i_meas_rqx_nxcals_df.index, data=i_meas_rqx_nxcals_df.values, columns=['I_MEAS_Q3'])
# PC - PM
source_timestamp_fgc_df = QueryBuilder().with_pm() \
.with_duration(t_start=t_start, t_end=t_end) \
.with_circuit_type(circuit_type) \
.with_metadata(circuit_name=circuit_name, system='PC', source='*') \
.event_query().df
timestamp_fgc = min(source_timestamp_fgc_df['timestamp'].values)
# QDS - U_RES
i_meas_raw_dfs = QueryBuilder().with_nxcals(spark) \
.with_duration(t_start=t_start, t_end=t_end) \
.with_circuit_type(circuit_type) \
.with_metadata(circuit_name=circuit_name, system='PC', signal='I_MEAS') \
.signal_query() \
.dfs
plateau_starts = []
plateau_ends = []
for i_meas_raw_df in i_meas_raw_dfs:
if i_meas_raw_df.max().values[0] > 100:
plateau_start, plateau_end = find_plateau_start_and_end(i_meas_raw_df, i_meas_threshold=0,
min_duration_in_sec=10)
plateau_starts.append(plateau_start)
plateau_ends.append(plateau_end)
plateau_start, plateau_end = extract_intersecting_plateaus(plateau_ends, plateau_starts)
plateau_start = np.array(plateau_start)
plateau_end = np.array(plateau_end)
ramp_up_start, ramp_up_end = find_start_end_of_the_longest_ramp_up(plateau_start, plateau_end)
def translate(timestamp):
mask_plateau = (timestamp >= plateau_start) & (timestamp <= plateau_end)
index_plateau = np.where(mask_plateau == True)[0]
if len(index_plateau) > 0:
return int((index_plateau[0]+1))
if (timestamp > ramp_up_start) and (timestamp < ramp_up_end):
return 0
return -1
translate_udf = udf(translate, IntegerType())
u_res_dfs = QueryBuilder().with_nxcals(spark) \
.with_duration(t_start=t_start, t_end=t_end) \
.with_circuit_type(circuit_type) \
.with_metadata(circuit_name=circuit_name, system='QDS', signal=['U_RES_Q1', 'U_RES_Q2', 'U_RES_Q3']) \
.signal_query() \
.synchronize_time() \
.convert_index_to_sec().dfs
i_meas_feature_df = QueryBuilder() \
.with_nxcals(spark) \
.with_duration(t_start=t_start, t_end=t_end) \
.with_circuit_type(circuit_type) \
.with_metadata(circuit_name=circuit_name, system='PC', signal='I_MEAS') \
.feature_query(['mean', 'std'], function=translate_udf) \
.sort_values(by='class') \
.df
u_mag_feature_df = QueryBuilder() \
.with_nxcals(spark) \
.with_duration(t_start=t_start, t_end=t_end) \
.with_circuit_type(circuit_type) \
.with_metadata(circuit_name=circuit_name, system='QDS', signal=['U_RES_Q1', 'U_RES_Q2', 'U_RES_Q3']) \
.feature_query(['mean', 'std'], function=translate_udf) \
.correct_voltage_sign() \
.sort_values(by='class') \
.df
u_res_dfs = it_query.query_signal_nxcals(t_start, t_end, system='QDS', signal_names=['U_RES_Q1', 'U_RES_Q2', 'U_RES_Q3'], spark=spark)
it_analysis = ItCircuitAnalysis(circuit_type, results_table=None, is_automatic=is_automatic)
# Splice resistance
plateau_start, plateau_end = it_query.calculate_current_plateau_start_end(Time.to_unix_timestamp(t_start), Time.to_unix_timestamp(t_end), i_meas_threshold=0, min_duration_in_sec=10, spark=spark)
u_mag_feature_df, i_meas_feature_df = it_query.get_busbar_resistances(Time.to_unix_timestamp(t_start), Time.to_unix_timestamp(t_end), plateau_start, plateau_end,
signal_name=['U_RES_Q1', 'U_RES_Q2', 'U_RES_Q3'], system='QDS', spark=spark)
r_res_df = it_analysis.calculate_resistance(i_meas_feature_df, u_mag_feature_df)
# DFB
tt893_nxcals_dfs = QueryBuilder().with_nxcals(spark) \
.with_duration(t_start=t_start, t_end=t_end) \
.with_circuit_type(circuit_type) \
.with_metadata(circuit_name=circuit_name, system='LEADS_NXCALS_WINCCOA', signal='TT893') \
.signal_query()\
.synchronize_time() \
.convert_index_to_sec() \
.filter_median() \
.dfs
tt893_nxcals_dfs = it_query.query_dfb_signal_nxcals(t_start, t_end, system='LEADS_NXCALS_WINCCOA', signal_names='TT893', spark=spark)
tt891a_nxcals_dfs = it_query.query_dfb_signal_nxcals(t_start, t_end, system='LEADS_NXCALS_WINCCOA', signal_names='TT891A', spark=spark)
cv891_nxcals_dfs = it_query.query_dfb_signal_nxcals(t_start, t_end, system='LEADS_NXCALS_WINCCOA', signal_names='CV891', spark=spark)
tt891a_nxcals_dfs = QueryBuilder().with_nxcals(spark) \
.with_duration(t_start=t_start, t_end=t_end) \
.with_circuit_type(circuit_type) \
.with_metadata(circuit_name=circuit_name, system='LEADS_NXCALS_WINCCOA', signal='TT891A') \
.signal_query() \
.synchronize_time() \
.convert_index_to_sec() \
.filter_median() \
.dfs
u_res_nxcals_dfs = QueryBuilder().with_nxcals(spark) \
.with_duration(t_start=t_start, t_end=t_end) \
.with_circuit_type(circuit_type) \
.with_metadata(circuit_name=circuit_name, system='LEADS', signal='U_RES') \
.signal_query() \
.synchronize_time() \
.convert_index_to_sec() \
.filter_median() \
.dfs
u_hts_nxcals_dfs = QueryBuilder().with_nxcals(spark) \
.with_duration(t_start=t_start, t_end=t_end)\
.with_circuit_type(circuit_type) \
.with_metadata(circuit_name=circuit_name, system='LEADS', signal='U_HTS') \
.signal_query()\
.synchronize_time() \
.convert_index_to_sec() \
.filter_median() \
.dfs
cv891_nxcals_dfs = QueryBuilder().with_nxcals(spark) \
.with_duration(t_start=t_start, t_end=t_end) \
.with_circuit_type(circuit_type) \
.with_metadata(circuit_name=circuit_name, system='LEADS_NXCALS_WINCCOA', signal='CV891') \
.signal_query() \
.synchronize_time() \
.convert_index_to_sec() \
.filter_median() \
.dfs
u_res_nxcals_dfs = it_query.query_signal_nxcals(t_start, t_end, system='LEADS', signal_names='U_RES', spark=spark)
u_hts_nxcals_dfs = it_query.query_signal_nxcals(t_start, t_end, system='LEADS', signal_names='U_HTS', spark=spark)
```
%% Cell type:markdown id: tags:
# 3. PC
## 3.1. Main Current
*QUERY*:
|Variable Name |Variable Type |Variable Unit |Database|Comment
|---------------|---------------|---------------|--------|------|
|i_meas_rq_nxcals_df |DataFrame |A |NXCALS|Main current of a power converter, I_MEAS_RQX, I_MEAS_RTQX1, I_MEAS_RTQX2|
Note that **rq** in the table above denotes RQX, RTQX1, and RTQX2, i.e., there are three signals for each power converter.
*GRAPHS*:
- t = 0 s corresponds to the start time of the test
%% Cell type:code id: tags:
``` python
title = '%s, %s: %s-%s' % (circuit_name, hwc_test, Time.to_string(t_start).split('.')[0], Time.to_string(t_end).split('.')[0])
ax = PlotBuilder().with_signal([i_meas_rqx_nxcals_df, i_meas_rtqx2_nxcals_df], title=title, grid=True) \
.with_ylabel(ylabel='I_MEAS_RQX, I_MEAS_RTQX2, [A]') \
.with_signal(i_meas_rtqx1_nxcals_df) \
.with_ylabel(ylabel='I_MEAS_RTQX1, [A]') \
.with_ylim((0, 600)) \
.plot(show_plot=False).get_axes()[0]
for ps, pe in zip(plateau_start, plateau_end):
ax.axvspan(xmin=(ps-Time.to_unix_timestamp(t_start))/1e9, xmax=(pe-Time.to_unix_timestamp(t_start))/1e9, facecolor='xkcd:orange')
```
%% Cell type:markdown id: tags:
## 3.2. Magnet Current
*QUERY*:
- *No query is needed as the magnet current is calculated from I_MEAS power converter currents*
|Variable Name |Variable Type |Variable Unit |Database|Comment
|---------------|---------------|---------------|--------|------|
|i_meas_q1_df |DataFrame |A |NXCALS|Main current of the Q1 magnet, I_MEAS_Q1|
|i_meas_q2_df |DataFrame |A |NXCALS|Main current of the Q2 magnet, I_MEAS_Q2|
|i_meas_q3_df |DataFrame |A |NXCALS|Main current of the Q3 magnet, I_MEAS_Q3|
*GRAPHS*:
- t = 0 s corresponds to the start of the test
%% Cell type:code id: tags:
``` python
PlotBuilder().with_signal([i_meas_q1_nxcals_df, i_meas_q2_nxcals_df, i_meas_q3_nxcals_df], title=title, grid=True) \
.with_ylabel(ylabel='I, [A]') \
.plot()
```
%% Cell type:markdown id: tags:
# 4. Quench Detection System
The signal names used for quench detection are shown in Figure below (picture from A. Erokhin).
<img src="https://gitlab.cern.ch/LHCData/lhc-sm-hwc/-/raw/master/figures/it/IT_QPS_Signals.png" width=75%>
A quench in the superconducting circuits is detected and all the quench heaters are fired as soon as one of the following signals exceeds the threshold.
\begin{equation}
U_\text{RES,Q1} = U_\text{1,Q1} + U_\text{2,Q1} \\
U_\text{RES,Q2} = U_\text{1,Q2} + U_\text{2,Q2} \\
U_\text{RES,Q3} = U_\text{1,Q3} + U_\text{2,Q3} \\
\end{equation}
More details on the QPS system and the quench heaters can be found on the MP3 web site (https://cern.ch/MP3).
%% Cell type:markdown id: tags:
## 4.1. Resistive Voltage
*QUERY*:
|Variable Name |Variable Type |Variable Unit |Comment
|---------------|---------------|---------------|------|
|u_res_df |DataFrame |V |Resistive voltage of magnets measured with QPS, U_RES|
*CRITERIA*:
- Check if U_RES < 30 mV for both boards at the start of the PC fault
*GRAPHS*:
- t = 0 s corresponds to the start of the test
%% Cell type:code id: tags:
``` python
AssertionBuilder().with_signal(u_res_dfs) \
.for_time_greater_than(t_greater=(timestamp_fgc-Time.to_unix_timestamp(t_start))/1e9) \
.has_min_max_value(value_min=-30e-3, value_max=30e-3) \
.show_plot(ylabel='U_RES, [V]')
```
%% Cell type:markdown id: tags:
## 4.2. Splice Resistance
*QUERY*:
|Variable Name |Variable Type |Variable Unit |Databse|Comment
|---------------|---------------|---------------|-------|------|
|i_meas_features_df |DataFrame| A |NXCALS| Power converter current mean values|
|u_res_features_df |DataFrame| V |NXCALS| U_RES voltage mean values|
*ANALYSIS*:
- Calculate splice resistance values based on power converter currents and QDS voltages
*CRITERIA*
- Check if R_max < 5 nOhm
*GRAPHS*:
- t = 0 s corresponds to the start of the test
%% Cell type:code id: tags:
``` python
for i_q_df, u_res_df in zip([i_meas_q1_nxcals_df, i_meas_q2_nxcals_df, i_meas_q3_nxcals_df], u_res_dfs):
ax = PlotBuilder().with_signal(i_q_df, title=title, grid=True) \
.with_ylabel(ylabel='I_Q, [A]') \
.with_signal(u_res_df) \
.with_ylabel(ylabel='U_RES_Q, [V]') \
.plot(show_plot=False).get_axes()[0]
for ps, pe in zip(plateau_start, plateau_end):
ax.axvspan(xmin=(ps-Time.to_unix_timestamp(t_start))/1e9, xmax=(pe-Time.to_unix_timestamp(t_start))/1e9, facecolor='xkcd:orange')
```
%% Cell type:code id: tags:
``` python
res_outliers_df = AssertionBuilder().with_feature(r_res_df) \
.has_min_max_value(feature='R_RES', min_value=0, max_value=5e-9) \
.show_plot(xlabel='Busbar, [-]', ylabel='R_RES (Calculated), [Ohm]') \
.get_features_outside_range()
```
%% Cell type:markdown id: tags:
## 4.3. DFB Regulation
*QUERY*
|Variable Name |Variable Type |Variable Unit |Database|Comment
|---------------|---------------|---------------|--------|------|
|tt893_nxcals_dfs |list of DataFrames |K |NXCALS|Temperature at the top of the current lead, TT893.TEMPERATURECALC|
|tt891a_nxcals_dfs |list of DataFrames |K |NXCALS|Temperature between the HTS and resistive part of the current lead, TT891A.TEMPERATURECALC|
|u_res_nxcals_dfs |list of DataFrames |V |NXCALS|Voltage of the resistive part of even and odd leads, U_RES|
|u_hts_nxcals_dfs |list of DataFrames |V |NXCALS|Voltage of the HTS part of even and odd leads, U_HTS|
|cv891_nxcals_dfs |list of DataFrames |% |NXCALS|Valve for regulation of TT891A, CV891.POSST|
*CRITERIA*
- Check if the temperatures TT893 at the top of the copper part of the four current leads, which must be over dew point, but not overheated: 285 K < TT893 < 305 K, even without current
- Check if the temperatures TT891A at the top of the HTS part of the four current leads, which must be regulated around 50 K: 46 K < TT891A < 54 K, even without current
- Check if the voltages U_RES over the copper part of the four current leads, which, at constant current, must stay constant (no drift) and ABS(U_RES) < 65 mV at 11.0 kA or 70 mV at 11.8 kA
- Check if the voltages U_HTS over the HTS part of the four current leads,which must stay below 50% of the threshold: ABS(U_HTS) < 0.5 mV
- Check if the valve opening regulating the helium flow along the top of the HTS part of the four current leads, which should never be blocked/saturated at its minimum/maximum.
*GRAPHS*:
- t = 0 s corresponds to the start of the test
%% Cell type:code id: tags:
``` python
AssertionBuilder() \
.with_signal(tt893_nxcals_dfs) \
.has_min_max_value(value_min=285, value_max=305) \
.show_plot(ylabel='TT893.TEMPERATURECALC [K]')
```
%% Cell type:code id: tags:
``` python
AssertionBuilder().with_signal(tt891a_nxcals_dfs) \
.has_min_max_value(value_min=46, value_max=54) \
.show_plot(ylabel='TT891A.TEMPERATURECALC [K]')
```
%% Cell type:code id: tags:
``` python
AssertionBuilder().with_signal(u_res_nxcals_dfs) \
.with_time_range(t_start=(plateau_start-Time.to_unix_timestamp(t_start))/1e9, t_end=(plateau_end-Time.to_unix_timestamp(t_start))/1e9) \
.with_time_range(t_start=(np.array(plateau_start)-Time.to_unix_timestamp(t_start))/1e9, t_end=(np.array(plateau_end)-Time.to_unix_timestamp(t_start))/1e9) \
.has_min_max_slope(slope_min=-2, slope_max=2) \
.show_plot(ylabel='U_RES, [V]')
```
%% Cell type:code id: tags:
``` python
AssertionBuilder() \
.with_signal(u_hts_nxcals_dfs) \
.has_min_max_value(value_min=-0.5e-3, value_max=0.5e-3) \
.show_plot(ylabel='U_HTS, [V]')
```
%% Cell type:code id: tags:
``` python
AssertionBuilder().with_signal(cv891_nxcals_dfs) \
.with_time_range(t_start=(plateau_start-Time.to_unix_timestamp(t_start))/1e9, t_end=(plateau_end-Time.to_unix_timestamp(t_start))/1e9) \
.with_time_range(t_start=(np.array(plateau_start)-Time.to_unix_timestamp(t_start))/1e9, t_end=(np.array(plateau_end)-Time.to_unix_timestamp(t_start))/1e9) \
.has_min_max_variation(variation_min_max=8) \
.show_plot(ylabel='CV891')
```
%% Cell type:markdown id: tags:
# 5. Final Report
## 5.1. Export Notebook as an HTML File
%% Cell type:code id: tags:
``` python
campaign = hwcb.get_campaign()
file_name_html = '{}-{}_report.html'.format(Time.to_datetime(t_start).strftime("%Y.%m.%d_%H%M%S.%f"), Time.to_datetime(t_end).strftime("%Y.%m.%d_%H%M%S.%f"))
full_path = '/eos/project/l/lhcsm/hwc/IT/{}/{}/{}/{}'.format(circuit_name, hwc_test, campaign, file_name_html)
print('Compact notebook report saved to (Windows): ' + '\\\\cernbox-smb' + full_path.replace('/', '\\'))
display(Javascript('IPython.notebook.save_notebook();'))
time.sleep(5)
!mkdir -p /eos/project/l/lhcsm/hwc/IT/$circuit_name/$hwc_test/$campaign
!{sys.executable} -m jupyter nbconvert --to html $'AN_IT_PNO.D16.ipynb' --output /eos/project/l/lhcsm/hwc/IT/$circuit_name/$hwc_test/$campaign/$file_name_html --TemplateExporter.exclude_input=True --TagRemovePreprocessor.remove_all_outputs_tags='["skip_output"]'
```
......
%% Cell type:markdown id: tags:
<h1><center>Analysis of PLI1.a2 HWC Test in an RB Circuit</center></h1>
<img src="https://gitlab.cern.ch/LHCData/lhc-sm-hwc/raw/master/figures/rb/RB.png" width=75%>
A current cycle up and down from I_MIN_OP to I_INJECTION is performed with a short plateau (typically 10 minutes) at highest current. The aim of this test is to check the magnet performance and the QPS calibration at that current level. The current to earth and the current error from the power convertor are checked during the sequence.
<img src="https://gitlab.cern.ch/LHCData/lhc-sm-hwc/raw/master/figures/rb/PLI1_current.png" width=75%>
The required analysis and signatures are listed below.
|Responsible|Type of analysis|Criterion|
|-----------|----------------|---------|
|MP3|Splice signals|U_res < 500$\mu$V if the inductive voltage of the bus-bar segments is compensated|
|-|Automatic analysis on earth current and error current|I_EARTH_PLI1_A2 < I_EARTH_MAX and I_ERR_PLI1_A2 < I_ERR_MAX|
source: Powering Procedure and Acceptance Criteria for the 13 kA Dipole Circuits, MP3 Procedure, <a href="https://edms.cern.ch/document/874713/5.1">https://edms.cern.ch/document/874713/5.1</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.
- In case a signal is not needed for the analysis, a particular analysis is skipped. In other words, all signals have to be available in order to perform an 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
import io
import re
import sys
import time
import pandas as pd
from IPython.display import display, Javascript, HTML
# NXCALS libraries
from cern.nxcals.pyquery.builders import *
# Internal libraries
from lhcsmapi.Time import Time