Commit b03325f9 authored by Thibaud Marie Eric Buffet's avatar Thibaud Marie Eric Buffet
Browse files

add missing resistance calculation update on the multi inheritance

parent de60b051
Pipeline #2584088 passed with stage
in 15 seconds
%% Cell type:markdown id: tags:
<h1><center>Analysis of a PLI2.s1 HWC in an RB Circuit</center></h1>
<img src="https://gitlab.cern.ch/LHCData/lhc-sm-hwc/raw/master/figures/rb/RB.png" width=75%>
The current in the circuit is ramped up from I_MIN_OP to I_INTERM_1, with three current plateaus at intermediate levels (I_INJECTION, I_INTERM_INT_4, I_INTERM_INT_6). The current is maintained constant at each current level during TIME_INTERM_1.
<img src="https://gitlab.cern.ch/LHCData/lhc-sm-hwc/raw/master/figures/rb/PLI2_current.png" width=75%>
This test has been inserted (from version 1.1 on) in order to check the status of the splices and to fine-tune the QPS compensation parameters
The required analysis and signatures are listed below.
|Responsible|Type of analysis|Criterion|
|-----------|----------------|---------|
|-|Automatic analysis on earth current and error current|I_EARTH_PLI2_S1 < I_EARTH_MAX and I_ERR_PLI2_S1 < I_ERR_MAX|
|MP3|Splice signals|R_bus<10 nOhm|
source: Powering Procedure and Acceptance Criteria for the 13 kA Dipole Circuits, MP3 Procedure, <a href="https://edms.cern.ch/document/874713">https://edms.cern.ch/document/874713</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/11)'); import sys; import pandas as pd
print('Loading (2/11)'); from IPython.display import display, Javascript, clear_output
# Internal libraries
print('Loading (3/11)'); import lhcsmapi
print('Loading (4/11)'); from lhcsmapi.Time import Time
print('Loading (5/11)'); from lhcsmapi.Timer import Timer
print('Loading (6/11)'); from lhcsmapi.analysis.RbCircuitQuery import RbCircuitQuery
print('Loading (7/11)'); from lhcsmapi.analysis.RbCircuitAnalysis import RbCircuitAnalysis
print('Loading (8/11)'); from lhcsmapi.analysis.report_template import apply_report_template
print('Loading (9/11)'); from lhcsmapi.gui.hwc.HwcSearchModuleMediator import HwcSearchModuleMediator
print('Loading (10/11)'); from lhcsmapi.pyedsl.PlotBuilder import create_hwc_plot_title_with_circuit_name
print('Loading (11/11)'); from lhcsmapi.analysis.expert_input import get_expert_decision
pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', None)
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.s1'
circuit_name = 'RB.A12'
campaign = 'HWC_2014'
t_start = '2014-12-11 16:49:47.759'
t_end = '2014-12-11 19:02:01.401'
```
2. To analyze a historical test with a browser GUI, copy and execute the following code in the cell below
```
circuit_type = 'RB'
hwc_test = 'PLI2.s1'
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:
``` 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 = 'RB'
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
rb_query = RbCircuitQuery(circuit_type, circuit_name, max_executions=3)
rb_analysis = RbCircuitAnalysis(circuit_type, None, is_automatic=is_automatic)
with Timer():
i_meas_nxcals_df = rb_query.query_signal_nxcals(t_start, t_end, t0=t_start, system='PC', signal_names='I_MEAS', spark=spark)[0]
i_meas_raw_nxcals_df = rb_query.query_raw_signal_nxcals(t_start, t_end, system='PC', signal_names='I_MEAS', spark=spark)[0]
plateau_start, plateau_end = rb_analysis.find_plateau_start_and_end(i_meas_raw_nxcals_df, i_meas_threshold=500, min_duration_in_sec=360, time_shift_in_sec=(240, 60))
u_res_feature_df, i_meas_feature_df = rb_query.get_busbar_resistances(Time.to_unix_timestamp(t_start), Time.to_unix_timestamp(t_end), plateau_start, plateau_end, signal_name='U_RES', spark=spark)
res_busbar_row_df = rb_analysis.calculate_resistance(i_meas_feature_df, u_res_feature_df, 'U_RES', Time.to_unix_timestamp(t_start), circuit_name)
from lhcsmapi.analysis.busbar.BusbarResistanceAnalysis import MultipleBusbarResistanceAnalysis
res_busbar_row_df = MultipleBusbarResistanceAnalysis.calculate_resistance(rb_analysis, i_meas_feature_df, u_res_feature_df, 'U_RES', Time.to_unix_timestamp(t_start), circuit_name)
res_busbar_df = rb_analysis.convert_to_col(res_busbar_row_df, signal_name='U_RES')
```
%% Cell type:markdown id: tags:
# 3. Power Converter
## 3.1. Plot of the Power Converter Main Current
*ANALYSIS*:
- Calculation of the duration of current plateaus
*GRAPHS*:
- t = 0 s corresponds to the start of the test
- Orange box(es) represent period(s) of time with constant current used for calculation of busbar resistance and DFB thresholds
%% Cell type:code id: tags:
``` python
import matplotlib as mpl
mpl.rcParams['savefig.dpi'] = 80
mpl.rcParams['figure.dpi'] = 80
%matplotlib notebook
title = '%s, %s: %s-%s' % (circuit_name, hwc_test, Time.to_string(t_start).split('.')[0], Time.to_string(t_end).split('.')[0])
rb_analysis.plot_i_meas_with_current_plateau(i_meas_nxcals_df, t0=i_meas_raw_nxcals_df.index[0], plateau_start=plateau_start, plateau_end=plateau_end, title=title)
```
%% Cell type:markdown id: tags:
# 4. Busbar
## 4.1. Busbar Resistance
*ANALYSIS*:
- Calculation of the busbar resistance as the slope of a linear fit of U,I curve obtained from the corresponding mean alues of the voltage and current
*CRITERIA*:
- Check if the busbar resistance is below 3 nOhm
*GRAPHS*:
- The busbar resistance, R
- The green box denotes the validity region of the busbar resostance (0, 3] nOhm
%% 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])
res_outliers_df = rb_analysis.analyze_busbar_magnet_resistance(res_busbar_df, signal_name='R_RES', value_max=3e-9, title=title)
```
%% Cell type:code id: tags:
``` python
rb_query.query_and_plot_outlier_voltage(res_outliers_df.reset_index(), t_start, t_end, i_meas_raw_nxcals_df.index[0], plateau_start, plateau_end, spark=spark)
```
%% Cell type:code id: tags:
``` python
busbar_metadata_resistance_df = rb_analysis.merge_busbar_metadata_with_resistance(res_busbar_df, circuit_type, circuit_name)
rb_analysis.display_busbar_metadata_resistance_with_threshold(busbar_metadata_resistance_df, threshold=3e-9)
```
%% Cell type:markdown id: tags:
# 5. Signature Decision
%% Cell type:code id: tags:
``` python
signature = get_expert_decision('Expert Signature Decision: ', ['PASSED', 'FAILED'])
```
%% Cell type:markdown id: tags:
# 6. Final Report
%% Cell type:code id: tags:
``` python
analysis_start_time = Time.get_analysis_start_time()
apply_report_template()
!mkdir -p /eos/project/m/mp3/RB/$circuit_name/$hwc_test
file_name_csv = '{}_{}-{}-{}_{}_BUSBAR_RESISTANCE.csv'.format(circuit_name, hwc_test, Time.to_datetime(t_start).strftime("%Y-%m-%d-%Hh%M"), analysis_start_time, signature)
full_path = '/eos/project/m/mp3/RB/{}/{}/{}'.format(circuit_name, hwc_test, file_name_csv)
busbar_metadata_resistance_df.to_csv(full_path)
print('Busbar resistance table saved to (Windows): ' + '\\\\cernbox-smb' + full_path.replace('/', '\\'))
file_name_html = '{}_{}-{}-{}_{}.html'.format(circuit_name, hwc_test, Time.to_datetime(t_start).strftime("%Y-%m-%d-%Hh%M"), analysis_start_time, signature)
full_path = '/eos/project/m/mp3/RB/{}/{}/{}'.format(circuit_name, hwc_test, 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 $'AN_RB_PLI2.s1.ipynb' --output /eos/project/m/mp3/RB/$circuit_name/$hwc_test/$file_name_html --TemplateExporter.exclude_input=True --TagRemovePreprocessor.remove_all_outputs_tags='["skip_output"]'
```
%% Cell type:code id: tags:
``` python
```
......
%% Cell type:markdown id: tags:
<h1><center>Analysis of a PLI3.a5 HWC in an RB Circuit</center></h1>
<img src="https://gitlab.cern.ch/LHCData/lhc-sm-hwc/raw/master/figures/rb/RB.png" width=75%>
PLI3.A2 is a simple current cycle at I_INTERM_2 during TIME_INTERM_2, while PLI3.A5 is a current cycle with 2 current levels (I_SM, I_INTERM_2) during TIME_INTERM_2 each. PLI3.A5 can be performed with calorimetric measurement (original purpose). In case of calorimetric measurement, the cryogenic cooling must be stable and maintained constant during the whole cycle. The aim of this test is to check the performance of the current leads and also the splices resistance, and, in case of calorimetric measurements, to detect abnormal heating in the magnets environment.
<img src="https://gitlab.cern.ch/LHCData/lhc-sm-hwc/raw/master/figures/rb/PLI3_current.png" width=50%>
The required analysis and signatures are listed below.
|Responsible|Type of analysis|Criterion|
|-----------|----------------|---------|
|-|Automatic analysis on earth current and error current|I_EARTH_PLI2_S1 < I_EARTH_MAX and I_ERR_PLI2_S1 < I_ERR_MAX|
|MP3|Splice signals|From board A and board B separately R_bus_max <3 nOhm. Individual R_splice_max<0.5nOhm R_mag<50 nOhm|
|MP3|Current lead|46 < TT891A < 54K; Abs(U_RES)< 40mV; and no drift Abs(U_HTS) < 0.5mV|
source: Powering Procedure and Acceptance Criteria for the 13 kA Dipole Circuits, MP3 Procedure, <a href="https://edms.cern.ch/document/874713">https://edms.cern.ch/document/874713</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/11)'); import sys; import pandas as pd
print('Loading (2/11)'); from IPython.display import display, Javascript, clear_output
# Internal libraries
print('Loading (3/11)'); import lhcsmapi
print('Loading (4/11)'); from lhcsmapi.Time import Time
print('Loading (5/11)'); from lhcsmapi.Timer import Timer
print('Loading (6/11)'); from lhcsmapi.analysis.RbCircuitQuery import RbCircuitQuery
print('Loading (7/11)'); from lhcsmapi.analysis.RbCircuitAnalysis import RbCircuitAnalysis
print('Loading (8/11)'); from lhcsmapi.analysis.report_template import apply_report_template
print('Loading (9/11)'); from lhcsmapi.gui.hwc.HwcSearchModuleMediator import HwcSearchModuleMediator
print('Loading (10/11)'); from lhcsmapi.pyedsl.PlotBuilder import create_hwc_plot_title_with_circuit_name
print('Loading (11/11)'); from lhcsmapi.analysis.expert_input import get_expert_decision
pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', None)
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 = 'PLI3.a5'
circuit_name = 'RB.A12'
campaign = 'HWC_2017'
t_start = '2017-04-22 08:57:30.399'
t_end = '2017-04-22 11:32:09.824'
```
2. To analyze a historical test with a browser GUI, copy and execute the following code in the cell below
```
circuit_type = 'RB'
hwc_test = 'PLI3.a5'
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:
``` 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 = 'RB'
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
rb_query = RbCircuitQuery(circuit_type, circuit_name, max_executions=6)
rb_analysis = RbCircuitAnalysis(circuit_type, None, is_automatic=is_automatic)
with Timer():
from lhcsmapi.analysis.busbar.BusbarResistanceAnalysis import MultipleBusbarResistanceAnalysis
# PC
i_meas_nxcals_df = rb_query.query_signal_nxcals(t_start, t_end, t0=t_start, system='PC', signal_names='I_MEAS', spark=spark)[0]
i_meas_raw_nxcals_df = rb_query.query_raw_signal_nxcals(t_start, t_end, system='PC', signal_names='I_MEAS', spark=spark)[0]
plateau_start, plateau_end = rb_analysis.find_plateau_start_and_end(i_meas_raw_nxcals_df, i_meas_threshold=0, min_duration_in_sec=360, time_shift_in_sec=(240, 60))
# BUSBAR
u_res_feature_df, i_meas_feature_df = rb_query.get_busbar_resistances(Time.to_unix_timestamp(t_start), Time.to_unix_timestamp(t_end), plateau_start, plateau_end, signal_name='U_RES', spark=spark)
res_busbar_row_df = rb_analysis.calculate_resistance(i_meas_feature_df, u_res_feature_df, 'U_RES', Time.to_unix_timestamp(t_start), circuit_name)
res_busbar_row_df = MultipleBusbarResistanceAnalysis.calculate_resistance(rb_analysis, i_meas_feature_df, u_res_feature_df, 'U_RES', Time.to_unix_timestamp(t_start), circuit_name)
res_busbar_df = rb_analysis.convert_to_col(res_busbar_row_df, signal_name='U_RES')
# MAGNET
u_mag_feature_df, i_meas_feature_df = rb_query.get_busbar_resistances(Time.to_unix_timestamp(t_start), Time.to_unix_timestamp(t_end), plateau_start, plateau_end, signal_name='U_MAG', spark=spark)
res_magnet_row_df = rb_analysis.calculate_resistance(i_meas_feature_df, u_mag_feature_df, 'U_MAG', Time.to_unix_timestamp(t_start), circuit_name)
res_magnet_row_df = MultipleBusbarResistanceAnalysis.calculate_resistance(rb_analysis, i_meas_feature_df, u_mag_feature_df, 'U_MAG', Time.to_unix_timestamp(t_start), circuit_name)
res_magnet_df = rb_analysis.convert_to_col(res_magnet_row_df, signal_name='U_MAG')
# LEADS
u_res_nxcals_dfs = rb_query.query_signal_nxcals(t_start, t_end, t0=t_start, system=['LEADS_EVEN', 'LEADS_ODD'], signal_names='U_RES', spark=spark)
u_hts_nxcals_dfs = rb_query.query_signal_nxcals(t_start, t_end, t0=t_start, system=['LEADS_EVEN', 'LEADS_ODD'], signal_names='U_HTS', spark=spark)
# DFB
tt891a_nxcals_dfs = rb_query.query_dfb_signal_nxcals(t_start, t_end, system=['LEADS_EVEN_WINCCOA', 'LEADS_ODD_WINCCOA'], signal_names='TT891A', spark=spark)
tt893_nxcals_dfs = rb_query.query_dfb_signal_nxcals(t_start, t_end, system=['LEADS_EVEN_WINCCOA', 'LEADS_ODD_WINCCOA'], signal_names='TT893', spark=spark)
cv891_nxcals_dfs = rb_query.query_dfb_signal_nxcals(t_start, t_end, system=['LEADS_EVEN_WINCCOA', 'LEADS_ODD_WINCCOA'], signal_names='CV891', spark=spark)
```
%% Cell type:markdown id: tags:
# 3. Power Converter
## 3.1. Plot of the Power Converter Main Current
*ANALYSIS*:
- Calculation of the duration of current plateaus
*GRAPHS*:
- t = 0 s corresponds to the start of the test
- Orange box(es) represent period(s) of time with constant current used for calculation of busbar resistance and DFB thresholds
%% Cell type:code id: tags:
``` python
import matplotlib as mpl
mpl.rcParams['savefig.dpi'] = 80
mpl.rcParams['figure.dpi'] = 80
%matplotlib notebook
title = '%s, %s: %s-%s' % (circuit_name, hwc_test, Time.to_string(t_start).split('.')[0], Time.to_string(t_end).split('.')[0])
rb_analysis.plot_i_meas_with_current_plateau(i_meas_nxcals_df, t0=i_meas_raw_nxcals_df.index[0], plateau_start=plateau_start, plateau_end=plateau_end, title=title)
```
%% Cell type:markdown id: tags:
# 4. Busbar
## 4.1. Busbar Resistance
*ANALYSIS*:
- Calculation of the busbar resistance as the slope of a linear fit of U,I curve obtained from the corresponding mean values of the voltage and current
*CRITERIA*:
- Check if the busbar resistance is below 3 nOhm
*GRAPHS*:
- The busbar resistance, R
- The green box denotes the validity region of the busbar resostance (0, 3] nOhm
%% 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])
res_busbar_outliers_df = rb_analysis.analyze_busbar_magnet_resistance(res_busbar_df, signal_name='R_RES', value_max=3e-9, title=title)
```
%% Cell type:code id: tags:
``` python
RbCircuitQuery.query_and_plot_outlier_voltage(res_busbar_outliers_df, t_start, t_end, i_meas_raw_nxcals_df.index[0], plateau_start, plateau_end, spark=spark)
```
%% Cell type:code id: tags:
``` python
busbar_metadata_resistance_df = rb_analysis.merge_busbar_metadata_with_resistance(res_busbar_df, circuit_type, circuit_name)
rb_analysis.display_busbar_metadata_resistance_with_threshold(busbar_metadata_resistance_df, threshold=3e-9)
```
%% Cell type:markdown id: tags:
## 4.2. Magnet Resistance
*ANALYSIS*:
- Calculation of the magnet resistance as the slope of a linear fit of U,I curve obtained from the corresponding mean alues of the voltage and current
*CRITERIA*
- Check if the resistance is below 50 nOhm
*GRAPHS*:
- The magnet resistance, R
- The green box denotes the validity region of the magnet resistance (0, 50] nOhm
%% 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])
res_magnet_outliers_df = rb_analysis.analyze_busbar_magnet_resistance(res_magnet_df, signal_name='R_MAG', value_max=50e-9, title=title)
```
%% Cell type:code id: tags:
``` python
RbCircuitQuery.query_and_plot_outlier_voltage(res_magnet_outliers_df.reset_index(), t_start, t_end, i_meas_raw_nxcals_df.index[0], plateau_start, plateau_end, spark=spark)
```
%% Cell type:code id: tags:
``` python
magnet_metadata_resistance_df = rb_analysis.merge_busbar_metadata_with_resistance(res_busbar_df, circuit_type, circuit_name)
rb_analysis.display_busbar_metadata_resistance_with_threshold(magnet_metadata_resistance_df, threshold=50e-9)
```
%% Cell type:markdown id: tags:
# 5. DFB
## 5.1. DFB Voltage - U_RES
*CRITERIA*:
- Check if, at constant current, U_RES is constant (no drift < 2mV/h)
*GRAPHS*:
- t = 0 s corresponds to the start time of the test
%% Cell type:code id: tags:
``` python
RbCircuitAnalysis.assert_u_res_min_max_slope(u_res_nxcals_dfs, plateau_start, plateau_end, Time.to_unix_timestamp(t_start), slope_range=(-2, 2))
```
%% Cell type:markdown id: tags:
## 5.2. DFB Voltage - U_HTS
*CRITERIA*:
- Check if the voltage is below 50% of the threshold -> Abs(U_HTS) < 0.5 mV
*GRAPHS*:
- t = 0 s corresponds to the start time of the test
%% Cell type:code id: tags:
``` python
RbCircuitAnalysis.assert_u_hts_min_max_slope(u_hts_nxcals_dfs, plateau_start, plateau_end, Time.to_unix_timestamp(t_start), slope_range=(-0.5, 0.5))
```
%% Cell type:markdown id: tags:
## 5.3. DFB Temperature - TT893.TEMPERATURECALC
*CRITERIA*:
- Check if the temperature is over the dew point, but not overheated -> 280 K < TT893 < 320 K, even without current
*GRAPHS*:
- Temperature at the top of the current lead on the right axis, TT893.TEMPERATURECALC
- Green box denotes the temperature validity region [280, 320] K of the temperature at the top of the current lead
- t = 0 s corresponds to the start time of the test
%% Cell type:code id: tags:
``` python
RbCircuitAnalysis.assert_tt893_min_max_value(tt893_nxcals_dfs, value_range=(280, 320))
```
%% Cell type:markdown id: tags:
## 5.4. DFB Temperature - TT891A.TEMPERATURECALC
*CRITERIA*:
- Check if the temperature is regulated around 50 K -> 46 K < TT891A < 54 K, even without current
*GRAPHS*:
For odd and even leads
- Main power converter current, I_MEAS
- Temperature between the HTS and resistive part of the current lead on the right axis, TT891A.TEMPERATURECALC
- t = 0 s corresponds to the start time of the test
%% Cell type:code id: tags:
``` python
RbCircuitAnalysis.assert_tt891a_min_max_value(tt891a_nxcals_dfs, value_range=(46, 54))
```
%% Cell type:markdown id: tags:
## 5.5. DFB Valve Regulation - CV891.POSST
*CRITERIA*:
- Check if the valve is opened (>2%), but not fully (<50%)
- Check if the valve variation (defined as difference between the maximum and minimum value) does not exceed 8% at constant current (the ramp of the current is excluded this criterion)
*GRAPHS*:
- Main power converter current, I_MEAS
- Valve for regulation of TT891A, CV891.POSST
- t = 0 s corresponds to the start time of the test
- Green box denotes the valve opening validity region [2, 50] % of the TT891A temperature regulation
%% Cell type:code id: tags:
``` python
RbCircuitAnalysis.assert_cv891_min_max_value(cv891_nxcals_dfs, value_range=(2, 50))
```
%% Cell type:code id: tags:
``` python
RbCircuitAnalysis.assert_cv891_min_max_variation(cv891_nxcals_dfs, 8, plateau_start, plateau_end, Time.to_unix_timestamp(t_start))
```
%% Cell type:markdown id: tags:
# 6. Signature Decision
%% Cell type:code id: tags:
``` python
signature = get_expert_decision('Expert Signature Decision: ', ['PASSED', 'FAILED'])
```
%% Cell type:markdown id: tags:
# 7. Final Report
%% Cell type:code id: tags:
``` python
analysis_start_time = Time.get_analysis_start_time()
apply_report_template()
!mkdir -p /eos/project/m/mp3/RB/$circuit_name/$hwc_test
file_name_csv = '{}_{}-{}-{}_{}_BUSBAR_RESISTANCE.csv'.format(circuit_name, hwc_test, Time.to_datetime(t_start).strftime("%Y-%m-%d-%Hh%M"), analysis_start_time, signature)
full_path = '/eos/project/m/mp3/RB/{}/{}/{}'.format(circuit_name, hwc_test, file_name_csv)
busbar_metadata_resistance_df.to_csv(full_path)
print('Busbar resistance table saved to (Windows): ' + '\\\\cernbox-smb' + full_path.replace('/', '\\'))
file_name_csv = '{}_{}-{}-{}_{}_MAGNET_RESISTANCE.csv'.format(circuit_name, hwc_test, Time.to_datetime(t_start).strftime("%Y-%m-%d-%Hh%M"), analysis_start_time, signature)
full_path = '/eos/project/m/mp3/RB/{}/{}/{}'.format(circuit_name, hwc_test, file_name_csv)
magnet_metadata_resistance_df.to_csv(full_path)
print('Magnet resistance table saved to (Windows): ' + '\\\\cernbox-smb' + full_path.replace('/', '\\'))
file_name_html = '{}_{}-{}-{}_{}.html'.format(circuit_name, hwc_test, Time.to_datetime(t_start).strftime("%Y-%m-%d-%Hh%M"), analysis_start_time, signature)
full_path = '/eos/project/m/mp3/RB/{}/{}/{}'.format(circuit_name, hwc_test, 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 $'AN_RB_PLI3.a5.ipynb' --output /eos/project/m/mp3/RB/$circuit_name/$hwc_test/$file_name_html --TemplateExporter.exclude_input=True --TagRemovePreprocessor.remove_all_outputs_tags='["skip_output"]'
```
%% Cell type:code id: tags:
``` python
```
......
%% Cell type:markdown id: tags:
<h1><center>Analysis of a PNO.b2 HWC in an RB Circuit</center></h1>
<img src="https://gitlab.cern.ch/LHCData/lhc-sm-hwc/raw/master/figures/rb/RB.png" width=75%>
The circuit is powered up to I_PNO + a current margin (I_DELTA). I_PNO is considered as the maximum current which can be used for the operation after the commissioning. During the HWC a current margin will be added for this test. Depending on the I_PNO level, training quenches of the dipole magnets may occur. Even if the test is considered as failed, each system (PC, QPS, magnet...) must be analysed before launching another test run.
After each test resulting in a quench, the MP3 will decide on continuation of the tests, not only taking into account the objective to be reached, but also speed of the training, and the currents reached in the other sectors.
If the I_PNO+I_DELTA current level is reached, an EE is provoked from the plateau.
During this test, the performance of each equipment must be checked
<img src="https://gitlab.cern.ch/LHCData/lhc-sm-hwc/raw/master/figures/rb/PNO_current.png" width=50%>
The required analysis and signatures are listed below.
|Responsible|Type of analysis|Criterion|
|-----------|----------------|---------|
|PC|PC voltage check|PC voltage ~ -1.5 V ± 0.5 V, 1 s after the EE activation. The current decay time constant should be within 20% of Decay_Time_const. Smooth exponential waveform on the PC voltage and current during the whole decay|
|PC|Automatic analysis on earth current and error current|I_EARTH_PNO_B2 < I_EARTH_MAX and I_ERR_ PNO_B2 < I_ERR_MAX|
|EE|Energy discharge|Maximum voltage on EE resistance ($R*I$±10%) and maximum temperature of the EE resistance (±10% from theoretical value)|
|EE|Energy discharge|Time delay on switch opening (300±50ms at odd point and 600±50ms at even point)|
|MP3|Splice signals (if TIME_PNOB2 > 1800s)|From board A and board B separately: R_bus_max <3 nOhm, Individual R_splice_max<0.5nOhm R_mag<30 nOhm|
|MP3|Detection of symmetric quench (if SymQ buffer is triggered at the discharge)|Voltage difference between magnets <80% × high threshold value of sunglass filter × current ratio|
|MP3|Current lead|46 < TT891A < 54K; Abs(U_RES)< 40mV; and no drift Abs(U_HTS) < 0.5mV|
source: Powering Procedure and Acceptance Criteria for the 13 kA Dipole Circuits, MP3 Procedure, <a href="https://edms.cern.ch/document/874713">https://edms.cern.ch/document/874713</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:skip_output
``` python
# External libraries
print('Loading (1/11)'); import sys; import pandas as pd
print('Loading (2/11)'); from IPython.display import display, Javascript, clear_output
# Internal libraries
print('Loading (3/11)'); import lhcsmapi
print('Loading (4/11)'); from lhcsmapi.Time import Time
print('Loading (5/11)'); from lhcsmapi.Timer import Timer
print('Loading (6/11)'); from lhcsmapi.analysis.RbCircuitQuery import RbCircuitQuery
print('Loading (7/11)'); from lhcsmapi.analysis.RbCircuitAnalysis import RbCircuitAnalysis
print('Loading (8/11)'); from lhcsmapi.analysis.report_template import apply_report_template
print('Loading (9/11)'); from lhcsmapi.gui.hwc.HwcSearchModuleMediator import HwcSearchModuleMediator
print('Loading (10/11)'); from lhcsmapi.pyedsl.PlotBuilder import create_hwc_plot_title_with_circuit_name
print('Loading (11/11)'); from lhcsmapi.analysis.expert_input import get_expert_decision
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 = 'PNO.b2'
circuit_name = 'RB.A12'
campaign = 'HWC_2018_1'
t_start = '2018-03-17 11:34:53.954'
t_end = '2018-03-17 16:06:41.537'
```
2. To analyze a historical test with a browser GUI, copy and execute the following code in the cell below
```
circuit_type = 'RB'
hwc_test = 'PNO.b2'
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:
``` 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
import pandas as pd
circuit_type = 'RB'
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())
t_start_ref = Time.to_unix_timestamp(hwcb.get_ref_start_time())
t_end_ref = Time.to_unix_timestamp(hwcb.get_ref_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)
t_start_ref, t_end_ref = HwcSearchModuleMediator.get_last_ref_start_end_time('/eos/project/l/lhcsm/hwc/HWC_Summary.csv', circuit_name, hwc_test, Time.to_string_short(t_start))
t_start_ref, t_end_ref = Time.to_unix_timestamp(t_start_ref), Time.to_unix_timestamp(t_end_ref)
is_automatic = False
t_pnob2 = (t_end - t_start)/1e9
rb_query = RbCircuitQuery(circuit_type, circuit_name, max_executions=30)
rb_analysis = RbCircuitAnalysis(circuit_type, results_table=None, is_automatic=is_automatic)
with Timer():
# PC
i_meas_nxcals_df = rb_query.query_signal_nxcals(t_start, t_end, t0=t_start, system='PC', signal_names='I_MEAS', spark=spark)[0]
i_meas_raw_nxcals_df = rb_query.query_raw_signal_nxcals(t_start, t_end, system='PC', signal_names='I_MEAS', spark=spark)[0]
plateau_start, plateau_end = rb_analysis.find_plateau_start_and_end(i_meas_raw_nxcals_df, i_meas_threshold=0, min_duration_in_sec=360, time_shift_in_sec=(240, 120))
source_timestamp_pc = rb_query.find_source_timestamp_pc(t_start, t_end)
timestamp_fgc = source_timestamp_pc.at[0, 'timestamp']
i_meas_df, i_a_df, i_ref_df, i_earth_df, i_earth_pcnt_df, v_meas_df = rb_query.query_pc_pm(timestamp_fgc, timestamp_fgc, signal_names=['I_MEAS', 'I_A', 'I_REF', 'I_EARTH', 'I_EARTH_PCNT', 'V_MEAS'])
# PC Reference
if isinstance(t_start_ref, int):
source_timestamp_pc_ref = rb_query.find_source_timestamp_pc(t_start_ref, t_end_ref)
timestamp_fgc_ref = source_timestamp_pc_ref.at[0, 'timestamp']
else:
timestamp_fgc_ref = float('nan')
i_meas_ref_df = rb_query.query_pc_pm(timestamp_fgc_ref, timestamp_fgc_ref, signal_names=['I_MEAS'])[0]
# PIC
timestamp_pic = rb_query.find_timestamp_pic(timestamp_fgc, spark=spark)
# EE Voltage
source_timestamp_ee_odd_df = rb_query.find_source_timestamp_ee(timestamp_fgc, system='EE_ODD')
timestamp_ee_odd = source_timestamp_ee_odd_df.loc[0, 'timestamp']
source_ee_odd = source_timestamp_ee_odd_df.loc[0, 'source']
u_dump_res_odd_df = rb_query.query_ee_u_dump_res_pm(timestamp_ee_odd, timestamp_fgc, system='EE_ODD', signal_names=['U_DUMP_RES'])[0]
source_timestamp_ee_even_df = rb_query.find_source_timestamp_ee(timestamp_fgc, system='EE_EVEN')
timestamp_ee_even = source_timestamp_ee_even_df.loc[0, 'timestamp']
source_ee_even = source_timestamp_ee_even_df.loc[0, 'source']
u_dump_res_even_df = rb_query.query_ee_u_dump_res_pm(timestamp_ee_even, timestamp_fgc, system='EE_EVEN', signal_names=['U_DUMP_RES'])[0]
# EE Temperature
t_res_odd_0_df = rb_query.query_ee_t_res_pm(source_timestamp_ee_odd_df.loc[0, 'timestamp'], timestamp_fgc, signal_names=['T_RES_BODY_1', 'T_RES_BODY_2', 'T_RES_BODY_3'], system='EE_ODD')
if len(source_timestamp_ee_odd_df) > 1:
t_res_odd_1_df = rb_query.query_ee_t_res_pm(source_timestamp_ee_odd_df.loc[1, 'timestamp'], timestamp_fgc, signal_names=['T_RES_BODY_1', 'T_RES_BODY_2', 'T_RES_BODY_3'], system='EE_ODD')
else:
t_res_odd_1_df = [pd.DataFrame(columns=['T_RES_BODY_1']), pd.DataFrame(columns=['T_RES_BODY_2']), pd.DataFrame(columns=['T_RES_BODY_3'])]
t_res_even_0_df = rb_query.query_ee_t_res_pm(source_timestamp_ee_even_df.loc[0, 'timestamp'], timestamp_fgc, signal_names=['T_RES_BODY_1', 'T_RES_BODY_2', 'T_RES_BODY_3'], system='EE_EVEN')
if len(source_timestamp_ee_even_df) > 1:
t_res_even_1_df = rb_query.query_ee_t_res_pm(source_timestamp_ee_even_df.loc[1, 'timestamp'], timestamp_fgc, signal_names=['T_RES_BODY_1', 'T_RES_BODY_2', 'T_RES_BODY_3'], system='EE_EVEN')
else:
t_res_even_1_df = [pd.DataFrame(columns=['T_RES_BODY_1']), pd.DataFrame(columns=['T_RES_BODY_2']), pd.DataFrame(columns=['T_RES_BODY_3'])]
# EE Voltage Reference
if isinstance(t_start_ref, int):
source_timestamp_ee_odd_ref_df = rb_query.find_source_timestamp_ee(timestamp_fgc_ref, system='EE_ODD')
source_timestamp_ee_even_ref_df = rb_query.find_source_timestamp_ee(timestamp_fgc_ref, system='EE_EVEN')
u_dump_res_odd_ref_df = rb_query.query_ee_u_dump_res_pm(source_timestamp_ee_odd_ref_df.loc[0, 'timestamp'], timestamp_fgc_ref, system='EE_ODD', signal_names=['U_DUMP_RES'])[0]
u_dump_res_even_ref_df = rb_query.query_ee_u_dump_res_pm(source_timestamp_ee_even_ref_df.loc[0, 'timestamp'], timestamp_fgc_ref, system='EE_EVEN', signal_names=['U_DUMP_RES'])[0]
# EE Temperature Reference
t_res_odd_0_ref_df = rb_query.query_ee_t_res_pm(source_timestamp_ee_odd_ref_df.loc[0, 'timestamp'], timestamp_fgc_ref, signal_names=['T_RES_BODY_1', 'T_RES_BODY_2', 'T_RES_BODY_3'], system='EE_ODD')
if len(source_timestamp_ee_odd_ref_df) > 1:
t_res_odd_1_ref_df = rb_query.query_ee_t_res_pm(source_timestamp_ee_odd_ref_df.loc[1, 'timestamp'], timestamp_fgc_ref, signal_names=['T_RES_BODY_1', 'T_RES_BODY_2', 'T_RES_BODY_3'], system='EE_ODD')
else:
t_res_odd_1_ref_df = [pd.DataFrame(columns=['T_RES_BODY_1']), pd.DataFrame(columns=['T_RES_BODY_2']), pd.DataFrame(columns=['T_RES_BODY_3'])]
t_res_even_0_ref_df = rb_query.query_ee_t_res_pm(source_timestamp_ee_even_ref_df.loc[0, 'timestamp'], timestamp_fgc_ref, signal_names=['T_RES_BODY_1', 'T_RES_BODY_2', 'T_RES_BODY_3'], system='EE_EVEN')
if len(source_timestamp_ee_even_ref_df) > 1:
t_res_even_1_ref_df = rb_query.query_ee_t_res_pm(source_timestamp_ee_even_ref_df.loc[1, 'timestamp'], timestamp_fgc_ref, signal_names=['T_RES_BODY_1', 'T_RES_BODY_2', 'T_RES_BODY_3'], system='EE_EVEN')
else:
t_res_even_1_ref_df = [pd.DataFrame(columns=['T_RES_BODY_1']), pd.DataFrame(columns=['T_RES_BODY_2']), pd.DataFrame(columns=['T_RES_BODY_3'])]
if t_pnob2 > 1800:
# LEADS
u_res_nxcals_dfs = rb_query.query_signal_nxcals(t_start, t_end, t0=t_start, system=['LEADS_EVEN', 'LEADS_ODD'], signal_names='U_RES', spark=spark)
u_hts_nxcals_dfs = rb_query.query_signal_nxcals(t_start, t_end, t0=t_start, system=['LEADS_EVEN', 'LEADS_ODD'], signal_names='U_HTS', spark=spark)
tt891a_nxcals_dfs = rb_query.query_dfb_signal_nxcals(t_start, t_end, system=['LEADS_EVEN_WINCCOA', 'LEADS_ODD_WINCCOA'], signal_names='TT891A', spark=spark)
tt893_nxcals_dfs = rb_query.query_dfb_signal_nxcals(t_start, t_end, system=['LEADS_EVEN_WINCCOA', 'LEADS_ODD_WINCCOA'], signal_names='TT893', spark=spark)
# BUSBAR
if len(plateau_start) > 1:
rb_query.max_executions += 2
# BUSBAR
from lhcsmapi.analysis.busbar.BusbarResistanceAnalysis import MultipleBusbarResistanceAnalysis
u_res_feature_df, i_meas_feature_df = rb_query.get_busbar_resistances(t_start, t_end, plateau_start, plateau_end, signal_name='U_RES', spark=spark)
res_busbar_row_df = rb_analysis.calculate_resistance(i_meas_feature_df, u_res_feature_df, 'U_RES', Time.to_unix_timestamp(t_start), circuit_name)
res_busbar_row_df = MultipleBusbarResistanceAnalysis.calculate_resistance(rb_analysis, i_meas_feature_df, u_res_feature_df, 'U_RES', Time.to_unix_timestamp(t_start), circuit_name)
res_busbar_df = convert_to_col(res_busbar_row_df, signal_name='U_RES')
# MAGNET
u_mag_feature_df, i_meas_feature_df = rb_query.get_busbar_resistances(Time.to_unix_timestamp(t_start), Time.to_unix_timestamp(t_end), plateau_start, plateau_end, signal_name='U_MAG', spark=spark)
res_magnet_row_df = rb_analysis.calculate_resistance(i_meas_feature_df, u_mag_feature_df, 'U_MAG', Time.to_unix_timestamp(t_start), circuit_name)
res_magnet_row_df = MultipleBusbarResistanceAnalysis.calculate_resistance(rb_analysis, i_meas_feature_df, u_mag_feature_df, 'U_MAG', Time.to_unix_timestamp(t_start), circuit_name)
res_magnet_df = convert_to_col(res_magnet_row_df, signal_name='U_MAG')
else:
res_busbar_df = pd.DataFrame()
res_magnet_df = pd.DataFrame()
# nQPS
source_timestamp_nqps_df = rb_query.find_source_timestamp_nqps(timestamp_fgc)
u_nqps_dfs = rb_query.query_voltage_nqps_pm(source_timestamp_nqps_df)
timestamp_dct = {'FGC': timestamp_fgc, 'PIC': min(timestamp_pic), 'EE_EVEN': timestamp_ee_even, 'EE_ODD': timestamp_ee_odd}
```
%% Cell type:markdown id: tags:
# 3. Timestamps
%% Cell type:code id: tags:
``` python
rb_analysis.create_timestamp_table(timestamp_dct)
```
%% Cell type:markdown id: tags:
# 4. Power Converter
## 4.1. Plot of the Power Converter Main Current
*ANALYSIS*:
- Calculation of the duration of current plateaus
*GRAPHS*:
- t = 0 s corresponds to the start of the test
- Orange box(es) represent period(s) of time with constant current used for calculation of busbar resistance and DFB thresholds
%% Cell type:code id: tags:
``` python
import matplotlib as mpl
mpl.rcParams['savefig.dpi'] = 80
mpl.rcParams['figure.dpi'] = 80
%matplotlib notebook
title = '%s, %s: %s-%s' % (circuit_name, hwc_test, Time.to_string(t_start).split('.')[0], Time.to_string(t_end).split('.')[0])
rb_analysis.plot_i_meas_with_current_plateau(i_meas_nxcals_df, t0=i_meas_raw_nxcals_df.index[0], plateau_start=plateau_start, plateau_end=plateau_end, title=title)
```
%% Cell type:markdown id: tags:
## 4.2. Analysis of the Power Converter Main Current
This analysis module displays the main current of the power converter (I_MEAS) compared to the one obtained from the reference FPA (HWC PNO.b2 test with opening of EE systems and without magnet quench).
*ANALYSIS*:
- The evolution of the characteristic time $\tau$ of an exponential decay $f(t)$ is obtained as
\begin{equation}
-\frac{f(t)}{\partial_t f(t)} = -\frac{f_0 e^{-t/\tilde{\tau}}}{\partial_t (f_0 e^{-t/\tilde{\tau}})} = -\frac{f_0 e^{-t/\tilde{\tau}}}{-f_0/\tilde{\tau} e^{-t/\tilde{\tau}}}=-\frac{1}{-1/\tau}=\tau
\end{equation}
Naturally, this formula only applies to exponential decayed characterised by a time constant. Nonetheless, for pseudo-exponential decays, this formula gives a notion of the change of the characteristic time $\tilde{\tau}$. For a circuit we compute the time-varying characteristic time as
\begin{equation}
\tilde{\tau} = - \frac{\text{I_MEAS}}{\partial_t \text{I_MEAS}}
\end{equation}
*CRITERIA*
- Check if the characteristic time of pseudo-exponential decay of I_MEAS from t=1 to 120 s is 90 s< Tau <110 s
*PLOT*:
- The main power converter current (analyzed and reference) on the left axis, I_MEAS
- The characteristic time calculated for the main current (reference and actual) on the right axis, -I_MEAS/dI_MEAS_dt
The actual characteristic time contains steps, which indicate a quenching magnet (decrease of circuit inductance); note that for the reference one the steps are not present. Timing of PIC abort, FGC timestamp, and the maximum current are reported next to the graph.
- t = 0 s corresponds to the respective (analyzed and reference) FGC timestamps.
%% Cell type:code id: tags:
``` python
rb_analysis.analyze_i_meas_pc(circuit_name, timestamp_fgc, timestamp_fgc_ref, min(timestamp_pic), i_meas_df, i_meas_ref_df)
```
%% Cell type:markdown id: tags:
## 4.3. Analysis of the Power Converter Main Current Smoothness
*ANALYSIS*:
- The current smoothness is evaluated on the basis of its second derivative. The derivative is calculated as a rolling division of current and time differences. The rolling window is fixed and equal to 10 points; with the sampling time equal to 0.1 s the time difference is equal to $dt=1 s$.
\begin{equation}
\frac{d i(t)}{dt} = \frac{i(t+dt)-i(t)}{dt}
\end{equation}
To obtain the second derivative of the current decay, the formula above is applied twice to the current profile from PM after the second EE opening (for t > 1 s).
*CRITERIA*
- Check if the second derivative of the current decay of I_MEAS from t = 1 s is -10 A/s^2< dI_MEAS/dt^2 < 10 A/s^2
*PLOT*:
- The second derivative of the main power converter current on the left axis, dI_MEAS/dt^2
- Green bar denotes the acceptance threshold for the second derivative of the main power converter current
- The main power converter current on the right axis, I_MEAS
%% Cell type:code id: tags:
``` python
title = create_hwc_plot_title_with_circuit_name(circuit_name=circuit_name, hwc_test=hwc_test, t_start=t_start, t_end=t_end, signal='I_MEAS smoothness')
rb_analysis.plot_i_meas_smoothness(i_meas_df, title=title)
```
%% Cell type:markdown id: tags:
## 4.4. Power Converter Voltage Analysis
*CRITERIA*
- Check if the V_MEAS voltage is within -1.5 +/- 0.5 V range 1 s after the EE timestamp
*GRAPHS*
- t = 0 s corresponds to the PM timestamp of the FGC
%% Cell type:code id: tags:
``` python
title = create_hwc_plot_title_with_circuit_name(circuit_name=circuit_name, hwc_test=hwc_test, t_start=t_start, t_end=t_end, signal='V_MEAS')
rb_analysis.assert_v_meas(timestamp_ee_even, min(timestamp_pic), t_after_ee=1, v_meas_df=v_meas_df, value_min=-2.0, value_max=-1.0, title=title, xmax=25)
```
%% Cell type:markdown id: tags:
## 4.5. Power Converter Earth Current
*CRITERIA*
- Check if the maximum absolute earth current is below 50 mA
*GRAPHS*:
- t = 0 s corresponds to the PM timestamp of the FGC
%% Cell type:code id: tags:
``` python
rb_analysis.plot_i_earth_pc(circuit_name, timestamp_fgc, i_earth_df)
rb_analysis.calculate_max_i_earth_pc(i_earth_df, col_name='Earth Current')
```
%% Cell type:markdown id: tags:
# 5. Energy Extraction System
## 5.1. Analysis of the Energy Extraction Voltage
*ANALYSIS*:
- Calculate U_dump_res (t=0)
- Calculate the characteristic time of pseudo-exponential current decay with the charge approach
*CRITERIA*:
- Check if U_DUMP_RES (t=0) = (±10%) U_DUMP_RES reference.
- Check if the timestamp difference between FGC and EE an odd point is 100±50 ms
The opening delay was 300±50 ms prior to YETS 2017/8
- Check if the time stamp difference between FGC and EE an even point: 600±50 ms
*WARNING*:
- Check if the characteristic time of pseudo-exponential decay of I_MEAS from t=1 to 120 s is 110 s<-Tau <130 s
*GRAPHS*:
- t = 0 s corresponds to the PM timestamp of the FGC
First plot (global view):
- the power converter converter current on the left axis, I_MEAS
- the two energy extraction voltages on the right, U_DUMP_RES, U_DUMP_RES
Second plot (triggering view):
- the power converter current on the left axis, I_MEAS
- the power converter reference current on the left axis, STATUS.I_REF (should stop at the moment of the FGC PM timestamp)
- the two energy extraction voltages on the right axis, U_DUMP_RES, U_DUMP_RES
- the green dashed line denotes the PIC timestamp
%% Cell type:code id: tags:
``` python
rb_analysis.analyze_char_time_u_dump_res_ee(circuit_name, timestamp_fgc, [u_dump_res_odd_df, u_dump_res_even_df], i_meas_df)
```
%% Cell type:code id: tags:
``` python
rb_analysis.analyze_delay_time_u_dump_res_ee(circuit_name, timestamp_fgc, min(timestamp_pic), [timestamp_ee_odd, timestamp_ee_even],
i_a_df, i_ref_df, [u_dump_res_odd_df, u_dump_res_even_df])
```
%% Cell type:code id: tags:
``` python
rb_analysis.compare_max_u_res_dump_to_reference(u_dump_res_odd_df, u_dump_res_odd_ref_df, 'U_DUMP_RES_ODD')
rb_analysis.compare_max_u_res_dump_to_reference(u_dump_res_even_df, u_dump_res_even_ref_df, 'U_DUMP_RES_EVEN')
```
%% Cell type:markdown id: tags:
## 5.2. Analysis of the Energy Extraction Temperature
*WARNING*
- Check if temperature profile is +/-25 K w.r.t. the reference temperature profile
*PLOT*:
- Temperature signals on the left axis, T
- A reference signal with an acceptable signal range is also provided on the left axis
- t = 0 s corresponds to PM timestamps of each temperature PM entry
%% Cell type:code id: tags:
``` python
rb_analysis.plot_ee_temp(circuit_name + '_EE_ODD', timestamp_ee_odd, t_res_odd_0_df + t_res_odd_1_df, t_res_odd_0_ref_df + t_res_odd_1_ref_df)
```
%% Cell type:code id: tags:
``` python
rb_analysis.analyze_ee_temp(circuit_name + '_EE_ODD', timestamp_ee_odd, t_res_odd_0_df + t_res_odd_1_df, t_res_odd_0_ref_df + t_res_odd_1_ref_df, abs_margin=25, scaling=1)
```
%% Cell type:code id: tags:
``` python
rb_analysis.plot_ee_temp(circuit_name + '_EE_EVEN', timestamp_ee_even, t_res_even_0_df + t_res_even_1_df, t_res_even_0_ref_df + t_res_even_1_ref_df)
```
%% Cell type:code id: tags:
``` python
rb_analysis.analyze_ee_temp(circuit_name + '_EE_EVEN', timestamp_ee_even, t_res_even_0_df + t_res_even_1_df, t_res_even_0_ref_df + t_res_even_1_ref_df, abs_margin=25, scaling=1)
```
%% Cell type:markdown id: tags:
# 6. Busbar
## 6.1. Busbar Resistance
*ANALYSIS*:
- Calculation of the busbar resistance as the slope of a linear fit of U,I curve obtained from the corresponding mean alues of the voltage and current
*CRITERIA*:
- Check if the busbar resistance is below 3 nOhm
*GRAPHS*:
- The busbar resistance, R
- The green box denotes the validity region of the busbar resostance (0, 3] nOhm
%% Cell type:code id: tags:
``` python
if t_pnob2 > 1800 and not res_busbar_df.empty:
res_busbar_outliers_df = rb_analysis.analyze_busbar_magnet_resistance(res_busbar_df, signal_name='R_RES', value_max=3e-9)
else:
res_busbar_outliers_df = pd.DataFrame()
```
%% Cell type:code id: tags:
``` python
if t_pnob2 > 1800 and not res_busbar_outliers_df.empty:
RbCircuitQuery.query_and_plot_outlier_voltage(res_busbar_outliers_df.reset_index(), t_start, t_end, i_meas_raw_nxcals_df.index[0], plateau_start, plateau_end, spark=spark)
```
%% Cell type:markdown id: tags:
## 6.2. Magnet Resistance
*ANALYSIS*:
- Calculation of the magnet resistance as the slope of a linear fit of U,I curve obtained from the corresponding mean alues of the voltage and current
*CRITERIA*:
- Check if the magnet resistance is below 50 nOhm
*GRAPHS*:
- The magnet resistance, R
- The green box denotes the validity region of the magnet resostance (0, 50] nOhm
%% Cell type:code id: tags:
``` python
if t_pnob2 > 1800 and not res_busbar_df.empty:
res_magnet_outliers_df = rb_analysis.analyze_busbar_magnet_resistance(res_magnet_df, signal_name='R_RES', value_max=3e-9)
else:
res_magnet_outliers_df = pd.DataFrame()
```
%% Cell type:code id: tags:
``` python
if t_pnob2 > 1800 and not res_magnet_outliers_df.empty:
RbCircuitQuery.query_and_plot_outlier_voltage(res_magnet_outliers_df.reset_index(), t_start, t_end, i_meas_raw_nxcals_df.index[0], plateau_start, plateau_end, spark=spark)
```
%% Cell type:markdown id: tags:
# 7. Quench Protection System
## 7.1. nQPS Sunglasses Threshold
*CRITERIA*:
- Check if the max/min nQPS (filtered) is below +/- 80%
**Note that this analysis generates 54 plots that will consume a lot of space. This analysis is typically done once. **
%% Cell type:code id: tags:
``` python
%matplotlib inline
source_timestamp_nqps_df = source_timestamp_nqps_df.rename(columns={'source': 'nqps_crate'})
rb_analysis.calc_plot_nqps_sunglass(source_timestamp_nqps_df, u_nqps_dfs, threshold=0.7, scaling=1)
```
%% Cell type:code id: tags:
``` python
import pandas as pd
pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', None)
source_timestamp_nqps_df['datetime_nqps'] = source_timestamp_nqps_df['timestamp'].apply(lambda row: Time.to_string_short(row))
source_timestamp_nqps_df
```
%% Cell type:markdown id: tags:
# 8. DFB
## 8.1. DFB Voltage - U_RES
*CRITERIA*:
- Check if Abs (U_RES) < 65 mV @ 11 kA
*GRAPHS*:
- t = 0 s corresponds to the start time of the test
%% Cell type:code id: tags:
``` python
%matplotlib inline
if t_pnob2 > 1800:
RbCircuitAnalysis.assert_u_res_between_two_references(u_res_nxcals_dfs, first_ref=i_meas_nxcals_df, first_scaling=0.065/11000,
second_ref=i_meas_nxcals_df, second_scaling=-0.065/11000)
```
%% Cell type:markdown id: tags:
## 8.2. DFB Voltage - U_HTS
*CRITERIA*:
- Check if the voltage is below 50% of the threshold: Abs(U_HTS) < 0.5 mV
*GRAPHS*:
- t = 0 s corresponds to the start time of the test
%% Cell type:code id: tags:
``` python
if t_pnob2 > 1800:
RbCircuitAnalysis.assert_u_hts_min_max_slope(u_hts_nxcals_dfs, plateau_start, plateau_end, Time.to_unix_timestamp(t_start), slope_range=(-0.5, 0.5))
```
%% Cell type:markdown id: tags:
## 8.3. DFB Temperature - TT893.TEMPERATURECALC
*CRITERIA*:
- Check if the temperature is over the dew point, but not overheated -> 280 K < TT893 < 320 K, even without current
*GRAPHS*:
- Temperature at the top of the current lead on the right axis, TT893.TEMPERATURECALC
- Green box denotes the temperature validity region [280, 320] K of the temperature at the top of the current lead
- t = 0 s corresponds to the start time of the test
%% Cell type:code id: tags:
``` python
if t_pnob2 > 1800:
RbCircuitAnalysis.assert_tt893_min_max_value(tt893_nxcals_dfs, value_range=(280, 320))
```
%% Cell type:markdown id: tags:
## 8.4. DFB Temperature - TT891A.TEMPERATURECALC
*CRITERIA*:
- Check if the temperature is regulated around 50 K -> 46 K < TT891A < 54 K, even without current
*GRAPHS*:
For odd and even leads
- Main power converter current, I_MEAS
- Temperature between the HTS and resistive part of the current lead on the right axis, TT891A.TEMPERATURECALC
- t = 0 s corresponds to the start time of the test
%% Cell type:code id: tags:
``` python
if t_pnob2 > 1800:
RbCircuitAnalysis.assert_tt891a_min_max_value(tt891a_nxcals_dfs, value_range=(46, 54))
```
%% Cell type:markdown id: tags:
# 9. Signature Decision
%% Cell type:code id: tags:
``` python
signature = get_expert_decision('Expert Signature Decision: ', ['PASSED', 'FAILED'])
```
%% Cell type:markdown id: tags:
# 10. Final Report
%% Cell type:code id: tags:
``` python
analysis_start_time = Time.get_analysis_start_time()
apply_report_template()
file_name_html = '{}_{}-{}-{}_{}.html'.format(circuit_name, hwc_test, Time.to_datetime(t_start).strftime("%Y-%m-%d-%Hh%M"), analysis_start_time, signature)
full_path = '/eos/project/m/mp3/RB/{}/{}/{}'.format(circuit_name, hwc_test, file_name_html)
!mkdir -p /eos/project/m/mp3/RB/$circuit_name/$hwc_test
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 $'AN_RB_PNO.b2.ipynb' --output /eos/project/m/mp3/RB/$circuit_name/$hwc_test/$file_name_html --TemplateExporter.exclude_input=True --TagRemovePreprocessor.remove_all_outputs_tags='["skip_output"]'
```
%% Cell type:code id: tags:
``` python
```
......
%% Cell type:markdown id: tags:
<h1><center>Analysis of PLI3.a5 HWC Test in an RQ Circuit</center></h1>
<img src="https://gitlab.cern.ch/LHCData/lhc-sm-hwc/raw/master/figures/rq/RQ.png" width=75%>
PLI3.A5 is a current cycle with 2 current levels (I_SM, I_INTERM_2) during TIME_INTERM_2 each. PLI3.A5 can be performed with calorimetric measurement (original purpose). In case of calorimetric measurement, the cryogenic cooling must be stable and maintained constant during the whole cycle. The aim of this test is to check the performance of the current leads, and, in case of calorimetric measurements, to detect abnormal heating in the magnets environment.
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/rq/PLI3_current.png" width=75%>
The aim of this test is to check the performance of the QPS and EE systems and the correct current sharing in the different FWD. The current to earth and the current error from the PC are checked during the sequence.
The required analysis and signatures are listed below.
|Responsible|Type of analysis|Criterion|
|-----------|----------------|---------|
|PC|Automatic analysis on earth current and error current|I_EARTH_PLI3_A5 < I_EARTH_MAX and I_ERR_PLI3_A5 < I_ERR_MAX|
|MP3|Splice signals|R_bus<10 nOhm R_mag<50 nOhm|
|MP3|Current lead|46 < TT891A < 54K|
|MP3|Current lead|Abs(U_RES)< 40mV and no drift|
|MP3|Current lead|Abs(U_HTS) < 0.5mV|
source: Powering Procedure and Acceptance Criteria for the 13 kA Quadrupole (RQD-RQF) Circuits, MP3 Procedure, <a href="https://edms.cern.ch/document/874714">https://edms.cern.ch/document/874714</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. Depending on what 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 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
# External libraries
print('Loading (1/11)'); import sys; import pandas as pd
print('Loading (2/11)'); from IPython.display import display, Javascript, clear_output
# Internal libraries
print('Loading (3/11)'); import lhcsmapi
print('Loading (4/11)'); from lhcsmapi.Time import Time
print('Loading (5/11)'); from lhcsmapi.Timer import Timer
print('Loading (6/11)'); from lhcsmapi.analysis.RqCircuitQuery import RqCircuitQuery
print('Loading (7/11)'); from lhcsmapi.analysis.RqCircuitAnalysis import RqCircuitAnalysis
print('Loading (8/11)'); from lhcsmapi.analysis.report_template import apply_report_template
print('Loading (9/11)'); from lhcsmapi.gui.hwc.HwcSearchModuleMediator import HwcSearchModuleMediator
print('Loading (10/11)'); from lhcsmapi.pyedsl.PlotBuilder import create_hwc_plot_title_with_circuit_name
print('Loading (11/11)'); from lhcsmapi.analysis.expert_input import get_expert_decision
pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', None)
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 = 'PLI3.a5'
circuit_name = 'RQD.A12'
campaign = 'HWC_2017'
t_start = '2017-04-24 07:05:31.332'
t_end = '2017-04-24 09:52:28.401'
```
2. To analyze a historical test with a browser GUI, copy and execute the following code in the cell below
```
circuit_type = 'RQ'
hwc_test = 'PLI3.a5'
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:
``` 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 = 'RQ'
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
circuit_names = [circuit_name if 'RQD' in circuit_name else circuit_name.replace('F', 'D'),
circuit_name if 'RQF' in circuit_name else circuit_name.replace('D', 'F')]
rqd_query = RqCircuitQuery(circuit_type, circuit_names[0], max_executions=4)
rqf_query = RqCircuitQuery(circuit_type, circuit_names[1], max_executions=4)
rq_analysis = RqCircuitAnalysis(circuit_type, None, is_automatic=is_automatic)
with Timer():
# PC
i_meas_nxcals_dfs = RqCircuitQuery(circuit_type, circuit_names).query_signal_nxcals(t_start, t_end, t0=t_start, system='PC', signal_names='I_MEAS', spark=spark)
i_meas_raw_nxcals_dfs = RqCircuitQuery(circuit_type, circuit_names).query_raw_signal_nxcals(t_start, t_end, system='PC', signal_names='I_MEAS', spark=spark)
plateau_start, plateau_end = RqCircuitQuery(circuit_type, circuit_names).calculate_current_plateau_start_end(Time.to_unix_timestamp(t_start), Time.to_unix_timestamp(t_end), i_meas_threshold=500, min_duration_in_sec=360, time_shift_in_sec=(240, 60), spark=spark)
# BUSBAR
from lhcsmapi.analysis.busbar.BusbarResistanceAnalysis import MultipleBusbarResistanceAnalysis
# # RQD
u_res_rqd_feature_df, i_meas_rqd_feature_df = rqd_query.get_busbar_resistances(Time.to_unix_timestamp(t_start), Time.to_unix_timestamp(t_end), plateau_start, plateau_end, signal_name='U_RES', spark=spark)
res_busbar_rqd_row_df = rq_analysis.calculate_resistance(i_meas_rqd_feature_df, u_res_rqd_feature_df, 'U_RES', Time.to_unix_timestamp(t_start), circuit_names[0])
res_busbar_rqd_row_df = MultipleBusbarResistanceAnalysis.calculate_resistance(rq_analysis, i_meas_rqd_feature_df, u_res_rqd_feature_df, 'U_RES', Time.to_unix_timestamp(t_start), circuit_names[0])
res_busbar_rqd_df = rq_analysis.convert_to_col(res_busbar_rqd_row_df, signal_name='U_RES')
# # RQF
u_res_rqf_feature_df, i_meas_rqf_feature_df = rqf_query.get_busbar_resistances(Time.to_unix_timestamp(t_start), Time.to_unix_timestamp(t_end), plateau_start, plateau_end, signal_name='U_RES', spark=spark)
res_busbar_rqf_row_df = rq_analysis.calculate_resistance(i_meas_rqf_feature_df, u_res_rqf_feature_df, 'U_RES', Time.to_unix_timestamp(t_start), circuit_names[1])
res_busbar_rqf_row_df = MultipleBusbarResistanceAnalysis.calculate_resistance(rq_analysis, i_meas_rqf_feature_df, u_res_rqf_feature_df, 'U_RES', Time.to_unix_timestamp(t_start), circuit_names[1])
res_busbar_rqf_df = rq_analysis.convert_to_col(res_busbar_rqf_row_df, signal_name='U_RES')
# MAGNET
# # RQD
u_mag_rqd_feature_df, i_meas_rqd_feature_df = rqd_query.get_busbar_resistances(Time.to_unix_timestamp(t_start), Time.to_unix_timestamp(t_end), plateau_start, plateau_end, signal_name='U_MAG', spark=spark)
res_magnet_rqd_row_df = rq_analysis.calculate_resistance(i_meas_rqd_feature_df, u_mag_rqd_feature_df, 'U_MAG', Time.to_unix_timestamp(t_start), circuit_names[0])
res_magnet_rqd_row_df = MultipleBusbarResistanceAnalysis.calculate_resistance(rq_analysis, i_meas_rqd_feature_df, u_mag_rqd_feature_df, 'U_MAG', Time.to_unix_timestamp(t_start), circuit_names[0])
res_magnet_rqd_df = rq_analysis.convert_to_col(res_magnet_rqd_row_df, signal_name='U_MAG')
# # RQF
u_mag_rqf_feature_df, i_meas_rqf_feature_df = rqf_query.get_busbar_resistances(Time.to_unix_timestamp(t_start), Time.to_unix_timestamp(t_end), plateau_start, plateau_end, signal_name='U_MAG', spark=spark)
res_magnet_rqf_row_df = rq_analysis.calculate_resistance(i_meas_rqf_feature_df, u_mag_rqf_feature_df, 'U_MAG', Time.to_unix_timestamp(t_start), circuit_names[1])
res_magnet_rqf_row_df = MultipleBusbarResistanceAnalysis.calculate_resistance(rq_analysis, i_meas_rqf_feature_df, u_mag_rqf_feature_df, 'U_MAG', Time.to_unix_timestamp(t_start), circuit_names[1])
res_magnet_rqf_df = rq_analysis.convert_to_col(res_magnet_rqf_row_df, signal_name='U_MAG')
# DFB
# # RQD
u_res_rqd_nxcals_dfs = rqd_query.query_signal_nxcals(t_start, t_end, t0=t_start, system='LEADS', signal_names='U_RES', spark=spark)
u_hts_rqd_nxcals_dfs = rqd_query.query_signal_nxcals(t_start, t_end, t0=t_start, system='LEADS', signal_names='U_HTS', spark=spark)
tt891a_rqd_nxcals_dfs = rqd_query.query_dfb_signal_nxcals(t_start, t_end, system='LEADS_WINCCOA', signal_names='TT891A', spark=spark)
tt893_rqd_nxcals_dfs = rqd_query.query_dfb_signal_nxcals(t_start, t_end, system='LEADS_WINCCOA', signal_names='TT893', spark=spark)
# # RQF
u_res_rqf_nxcals_dfs = rqf_query.query_signal_nxcals(t_start, t_end, t0=t_start, system='LEADS', signal_names='U_RES', spark=spark)
u_hts_rqf_nxcals_dfs = rqf_query.query_signal_nxcals(t_start, t_end, t0=t_start, system='LEADS', signal_names='U_HTS', spark=spark)
tt891a_rqf_nxcals_dfs = rqf_query.query_dfb_signal_nxcals(t_start, t_end, system='LEADS_WINCCOA', signal_names='TT891A', spark=spark)
tt893_rqf_nxcals_dfs = rqf_query.query_dfb_signal_nxcals(t_start, t_end, system='LEADS_WINCCOA', signal_names='TT893', spark=spark)
```
%% Cell type:markdown id: tags:
# 3. Circuit Parameters Table
%% Cell type:code id: tags:
``` python
rq_analysis.display_parameters_table(circuit_names[0])
```
%% Cell type:markdown id: tags:
# 4. Power Converter
## 4.1. Plot of the Power Converter Main Current
*GRAPHS*:
- t = 0 s corresponds to the start of the test
- Orange box(es) represent period(s) of time with constant current used for calculation of busbar resistance and DFB thresholds
%% Cell type:code id: tags:
``` python
import matplotlib as mpl
mpl.rcParams['savefig.dpi'] = 80
mpl.rcParams['figure.dpi'] = 80
%matplotlib notebook
title = '%s-%s, %s: %s-%s' % (circuit_names[0], circuit_names[1], hwc_test, Time.to_string(t_start).split('.')[0], Time.to_string(t_end).split('.')[0])
i_meas_nxcals_dfs[0] = i_meas_nxcals_dfs[0].rename(columns={i_meas_nxcals_dfs[0].columns[0]: '%s:I_MEAS' % (circuit_names[0])})
i_meas_nxcals_dfs[1] = i_meas_nxcals_dfs[1].rename(columns={i_meas_nxcals_dfs[1].columns[0]: '%s:I_MEAS' % (circuit_names[1])})
rq_analysis.plot_i_meas_with_current_plateau(i_meas_nxcals_dfs, t0=i_meas_raw_nxcals_dfs[0].index[0], plateau_start=plateau_start, plateau_end=plateau_end, title=title)
```
%% Cell type:markdown id: tags:
# 5. Busbar
## 5.1. Busbar Resistance
*ANALYSIS*:
- Calculation of the busbar resistance as the slope of a linear fit of U,I curve obtained from the corresponding mean alues of the voltage and current
*CRITERIA*:
- Check if the busbar resistance is below 10 nOhm
*GRAPHS*:
- The busbar resistance, R
- The green box denotes the validity region of the busbar resostance (0, 10] nOhm
%% Cell type:markdown id: tags:
- RQD
%% Cell type:code id: tags:
``` python
title = '%s, %s: %s-%s' % (circuit_names[0], hwc_test, Time.to_string(t_start).split('.')[0], Time.to_string(t_end).split('.')[0])
res_busbar_rqd_outliers_df = rq_analysis.analyze_busbar_magnet_resistance(res_busbar_rqd_df, signal_name='R_RES', value_max=10e-9, title=title)
```
%% Cell type:code id: tags:
``` python
print('List of not working busbar measurements:')
res_busbar_rqf_df[res_busbar_rqd_df['R_RES'] == 0]
```
%% Cell type:code id: tags:
``` python
RqCircuitQuery.query_and_plot_outlier_voltage(res_busbar_rqd_outliers_df.reset_index(), t_start, t_end, i_meas_raw_nxcals_dfs[0].index[0], plateau_start, plateau_end, spark=spark)
```
%% Cell type:code id: tags:
``` python
rqd_busbar_metadata_resistance_df = rq_analysis.merge_busbar_metadata_with_resistance(res_busbar_rqd_df, circuit_type, circuit_names)
rq_analysis.display_busbar_metadata_resistance_with_threshold(rqd_busbar_metadata_resistance_df, threshold=10e-9)
```
%% Cell type:markdown id: tags:
- RQF
%% Cell type:code id: tags:
``` python
title = '%s, %s: %s-%s' % (circuit_names[1], hwc_test, Time.to_string(t_start).split('.')[0], Time.to_string(t_end).split('.')[0])
res_busbar_rqf_outliers_df = rq_analysis.analyze_busbar_magnet_resistance(res_busbar_rqf_df, signal_name='R_RES', value_max=10e-9, title=title)
```
%% Cell type:code id: tags:
``` python
print('List of not working busbar measurements:')
res_busbar_rqf_df[res_busbar_rqf_df['R_RES'] == 0]
```
%% Cell type:code id: tags:
``` python
RqCircuitQuery.query_and_plot_outlier_voltage(res_busbar_rqf_outliers_df.reset_index(), t_start, t_end, i_meas_raw_nxcals_dfs[0].index[0], plateau_start, plateau_end, spark=spark)
```
%% Cell type:code id: tags:
``` python
rqf_busbar_metadata_resistance_df = rq_analysis.merge_busbar_metadata_with_resistance(res_busbar_rqf_df, circuit_type, circuit_names)
rq_analysis.display_busbar_metadata_resistance_with_threshold(rqf_busbar_metadata_resistance_df, threshold=10e-9)
```
%% Cell type:markdown id: tags:
## 5.2. Magnet Resistance
*ANALYSIS*:
- Calculation of the busbar resistance as the slope of a linear fit of U,I curve obtained from the corresponding mean alues of the voltage and current
*CRITERIA*:
- Check if the busbar resistance is below 50 nOhm
*GRAPHS*:
- The busbar resistance, R
- The green box denotes the validity region of the busbar resostance (0, 50] nOhm
%% Cell type:markdown id: tags:
- RQD
%% Cell type:code id: tags:
``` python
title = '%s, %s: %s-%s' % (circuit_names[0], hwc_test, Time.to_string(t_start).split('.')[0], Time.to_string(t_end).split('.')[0])
res_magnet_rqd_outliers_df = rq_analysis.analyze_busbar_magnet_resistance(res_magnet_rqd_df, signal_name='R_MAG', value_max=50e-9, title=title)
```
%% Cell type:code id: tags:
``` python
print('List of not working busbar measurements:')
res_magnet_rqd_df[res_magnet_rqd_df['R_MAG'] == 0]
```
%% Cell type:code id: tags:
``` python
RqCircuitQuery.query_and_plot_outlier_voltage(res_magnet_rqd_outliers_df.reset_index(), t_start, t_end, i_meas_raw_nxcals_dfs[0].index[0], plateau_start, plateau_end, spark=spark)
```
%% Cell type:code id: tags:
``` python
rqd_magnet_metadata_resistance_df = rq_analysis.merge_busbar_metadata_with_resistance(res_magnet_rqd_df, circuit_type, circuit_names, res_col='R_MAG')
rq_analysis.display_busbar_metadata_resistance_with_threshold(rqd_magnet_metadata_resistance_df, threshold=50e-9, res_col='R_MAG')
```
%% Cell type:markdown id: tags:
- RQF
%% Cell type:code id: tags:
``` python
title = '%s, %s: %s-%s' % (circuit_names[1], hwc_test, Time.to_string(t_start).split('.')[0], Time.to_string(t_end).split('.')[0])
res_magnet_rqf_outliers_df = rq_analysis.analyze_busbar_magnet_resistance(res_magnet_rqf_df, signal_name='R_MAG', value_max=50e-9, title=title)
```
%% Cell type:code id: tags:
``` python
print('List of not working busbar measurements:')
res_magnet_rqf_df[res_magnet_rqf_df['R_MAG'] == 0]
```
%% Cell type:code id: tags:
``` python
RqCircuitQuery.query_and_plot_outlier_voltage(res_magnet_rqf_outliers_df, t_start, t_end, i_meas_raw_nxcals_dfs[0].index[0], plateau_start, plateau_end, spark=spark)
```
%% Cell type:code id: tags:
``` python
rqf_magnet_metadata_resistance_df = rq_analysis.merge_busbar_metadata_with_resistance(res_magnet_rqf_df, circuit_type, circuit_names, res_col='R_MAG')
rq_analysis.display_busbar_metadata_resistance_with_threshold(rqf_magnet_metadata_resistance_df, threshold=50e-9, res_col='R_MAG')
```
%% Cell type:markdown id: tags:
# 6. DFB
## 6.1. DFB Voltage - U_RES
*CRITERIA*:
- Check if, at constant current, U_RES is constant (no drift < 2mV/h)
- Check if U_RES is in [-40, 40] mV
*GRAPHS*:
- t = 0 s corresponds to the FGC timestamp
%% Cell type:code id: tags:
``` python
RqCircuitAnalysis.assert_u_res_min_max_slope(u_res_rqd_nxcals_dfs+u_res_rqf_nxcals_dfs, plateau_start, plateau_end, Time.to_unix_timestamp(t_start), slope_range=(-2, 2));
```
%% Cell type:code id: tags:
``` python
RqCircuitAnalysis.assert_u_res_min_max_value(u_res_rqd_nxcals_dfs+u_res_rqf_nxcals_dfs, value_range=(-40e-3, 40e-3));
```
%% Cell type:markdown id: tags:
## 6.2. DFB Voltage - U_HTS
*CRITERIA*:
- Check if U_HTS is below 50% of the threshold -> U_HTS in [-0.5, 0.5] mV
*GRAPHS*:
- t = 0 s corresponds to the FGC timestamp
%% Cell type:code id: tags:
``` python
RqCircuitAnalysis.assert_u_hts_min_max_value(u_hts_rqd_nxcals_dfs+u_hts_rqf_nxcals_dfs, value_range=(-0.5e-3, 0.5e-3));
```
%% Cell type:markdown id: tags:
## 6.3. DFB Temperature - TT893.TEMPERATURECALC
*CRITERIA*:
- Check if the temperature is over the dew point, but not overheated -> 280 K < TT893 < 320 K, even without current
*GRAPHS*:
- Temperature at the top of the current lead on the right axis, TT893.TEMPERATURECALC
- Green box denotes the temperature validity region [280, 320] K of the temperature at the top of the current lead
- t = 0 s corresponds to the start time of the test
%% Cell type:code id: tags:
``` python
RqCircuitAnalysis.assert_tt893_min_max_value(tt893_rqd_nxcals_dfs+tt893_rqf_nxcals_dfs, value_range=(280, 320));
```
%% Cell type:markdown id: tags:
## 6.4. DFB Temperature - TT891A.TEMPERATURECALC
*CRITERIA*:
- Check if the temperature is regulated around 50 K -> 46 K < TT891A < 54 K, even without current
*GRAPHS*:
- Temperature between the HTS and resistive part of the current lead on the right axis, TT891A.TEMPERATURECALC
- Green box denotes the temperature validity region [46, 54] K of the temperature at the top of the current lead
- t = 0 s corresponds to the start time of the test
%% Cell type:code id: tags:
``` python
RqCircuitAnalysis.assert_tt891a_min_max_value(tt891a_rqd_nxcals_dfs+tt891a_rqf_nxcals_dfs, value_range=(46, 54));
```
%% Cell type:markdown id: tags:
# 7. Signature Decision
%% Cell type:code id: tags:
``` python
signature = get_expert_decision('Expert Signature Decision: ', ['PASSED', 'FAILED'])
```
%% Cell type:markdown id: tags:
# 8. Final Report
%% Cell type:code id: tags:
``` python
analysis_start_time = Time.get_analysis_start_time()
circuit_name = circuit_names[0].replace('D', '')
apply_report_template()
!mkdir -p /eos/project/m/mp3/RQ/$circuit_name/$hwc_test
file_name_csv = '{}_{}-{}-{}_{}_RQD_BUSBAR_RESISTANCE.csv'.format(circuit_name, hwc_test, Time.to_datetime(t_start).strftime("%Y-%m-%d-%Hh%M"), analysis_start_time, signature)
full_path = '/eos/project/m/mp3/RQ/{}/{}/{}'.format(circuit_name, hwc_test, file_name_csv)
rqd_busbar_metadata_resistance_df.to_csv(full_path)
print('RQD busbar resistance table saved to (Windows): ' + '\\\\cernbox-smb' + full_path.replace('/', '\\'))
file_name_csv = '{}_{}-{}-{}_{}_RQF_BUSBAR_RESISTANCE.csv'.format(circuit_name, hwc_test, Time.to_datetime(t_start).strftime("%Y-%m-%d-%Hh%M"), analysis_start_time, signature)
full_path = '/eos/project/m/mp3/RQ/{}/{}/{}'.format(circuit_name, hwc_test, file_name_csv)
rqf_busbar_metadata_resistance_df.to_csv(full_path)
print('RQF busbar resistance table saved to (Windows): ' + '\\\\cernbox-smb' + full_path.replace('/', '\\'))
file_name_csv = '{}_{}-{}-{}_{}_RQD_MAGNET_RESISTANCE.csv'.format(circuit_name, hwc_test, Time.to_datetime(t_start).strftime("%Y-%m-%d-%Hh%M"), analysis_start_time, signature)
full_path = '/eos/project/m/mp3/RQ/{}/{}/{}'.format(circuit_name, hwc_test, file_name_csv)
rqd_magnet_metadata_resistance_df.to_csv(full_path)
print('RQD magnet resistance table saved to (Windows): ' + '\\\\cernbox-smb' + full_path.replace('/', '\\'))
file_name_csv = '{}_{}-{}-{}_{}_RQF_MAGNET_RESISTANCE.csv'.format(circuit_name, hwc_test, Time.to_datetime(t_start).strftime("%Y-%m-%d-%Hh%M"), analysis_start_time, signature)
full_path = '/eos/project/m/mp3/RQ/{}/{}/{}'.format(circuit_name, hwc_test, file_name_csv)
rqf_magnet_metadata_resistance_df.to_csv(full_path)
print('RQF magnet resistance table saved to (Windows): ' + '\\\\cernbox-smb' + full_path.replace('/', '\\'))
file_name_html = '{}_{}-{}-{}_{}.html'.format(circuit_name, hwc_test, Time.to_datetime(t_start).strftime("%Y-%m-%d-%Hh%M"), analysis_start_time, signature)
full_path = '/eos/project/m/mp3/RQ/{}/{}/{}'.format(circuit_name, hwc_test, 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 $'AN_RQ_PLI3.a5.ipynb' --output /eos/project/m/mp3/RQ/$circuit_name/$hwc_test/$file_name_html --TemplateExporter.exclude_input=True --TagRemovePreprocessor.remove_all_outputs_tags='["skip_output"]'
```
%% Cell type:code id: tags:
``` python
```
......
%% Cell type:markdown id: tags:
<h1><center>Analysis of a PLIS.s2 HWC in an RQ Circuit</center></h1>
<img src="https://gitlab.cern.ch/LHCData/lhc-sm-hwc/raw/master/figures/rq/RQ.png" width=75%>
This test has been inserted (from version 1.1 on) in order to check the status of the splices step-wise while ramping the circuit up and down to I_SM current.
<img src="https://gitlab.cern.ch/LHCData/lhc-sm-hwc/raw/master/figures/rq/PLIS_current.png" width=75%>
From I_MIN_OP, the circuit is ramped up to different current level (I_SM_INT_1, I_SM_INT_2, I_SM_INT_3, I_SM_INT_4, I_SM) and maintained constant at each current level during TIME_INTERM_1.
The required analysis and signatures are listed below.
|Responsible|Type of analysis|Criterion|
|-----------|----------------|---------|
|-|Automatic analysis on earth current and error current|I_EARTH_PLIS_S2 < I_EARTH_MAX and I_ERR_PLIS_S2 < I_ERR_MAX|
|MP3|Splice signals|R_bus<10 nOhm|
source: Powering Procedure and Acceptance Criteria for the 13 kA Dipole Circuits, MP3 Procedure, <a href="https://edms.cern.ch/document/874713">https://edms.cern.ch/document/874713</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. Depending on what 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 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
# External libraries
print('Loading (1/11)'); import sys; import pandas as pd
print('Loading (2/11)'); from IPython.display import display, Javascript, clear_output
# Internal libraries
print('Loading (3/11)'); import lhcsmapi
print('Loading (4/11)'); from lhcsmapi.Time import Time
print('Loading (5/11)'); from lhcsmapi.Timer import Timer
print('Loading (6/11)'); from lhcsmapi.analysis.RqCircuitQuery import RqCircuitQuery
print('Loading (7/11)'); from lhcsmapi.analysis.RqCircuitAnalysis import RqCircuitAnalysis
print('Loading (8/11)'); from lhcsmapi.analysis.report_template import apply_report_template
print('Loading (9/11)'); from lhcsmapi.gui.hwc.HwcSearchModuleMediator import HwcSearchModuleMediator
print('Loading (10/11)'); from lhcsmapi.pyedsl.PlotBuilder import create_hwc_plot_title_with_circuit_name
print('Loading (11/11)'); from lhcsmapi.analysis.expert_input import get_expert_decision
pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', None)
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 = 'PLIS.s2'
circuit_name = 'RQD.A12'
campaign = 'HWC_2014'
t_start = '2015-01-19 13:07:38.011'
t_end = '2015-01-19 16:12:25.285'
```
2. To analyze a historical test with a browser GUI, copy and execute the following code in the cell below
```
circuit_type = 'RQ'
hwc_test = 'PLIS.s2'
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:
``` 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 = 'RQ'
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
circuit_names = [circuit_name if 'RQD' in circuit_name else circuit_name.replace('F', 'D'),
circuit_name if 'RQF' in circuit_name else circuit_name.replace('D', 'F')]
rq_query = RqCircuitQuery(circuit_type, circuit_names, max_executions=4)
rq_analysis = RqCircuitAnalysis(circuit_type, None, is_automatic=is_automatic)
with Timer():
# PC
i_meas_nxcals_dfs = rq_query.query_signal_nxcals(t_start, t_end, t0=t_start, system='PC', signal_names='I_MEAS', spark=spark)
i_meas_raw_nxcals_dfs = rq_query.query_raw_signal_nxcals(t_start, t_end, system='PC', signal_names='I_MEAS', spark=spark)
plateau_start, plateau_end = rq_query.calculate_current_plateau_start_end(Time.to_unix_timestamp(t_start), Time.to_unix_timestamp(t_end),
i_meas_threshold=500, min_duration_in_sec=360, time_shift_in_sec=(240, 60), spark=spark)
# BUSBAR
u_res_feature_df, i_meas_feature_df = rq_query.get_busbar_resistances(Time.to_unix_timestamp(t_start), Time.to_unix_timestamp(t_end), plateau_start, plateau_end,
signal_name='U_RES', spark=spark)
res_busbar_row_df = rq_analysis.calculate_resistance(i_meas_feature_df, u_res_feature_df, 'U_RES', Time.to_unix_timestamp(t_start), circuit_names)
from lhcsmapi.analysis.busbar.BusbarResistanceAnalysis import MultipleBusbarResistanceAnalysis
res_busbar_row_df = MultipleBusbarResistanceAnalysis.calculate_resistance(rq_analysis, i_meas_feature_df, u_res_feature_df, 'U_RES', Time.to_unix_timestamp(t_start), circuit_names)
res_busbar_df = rq_analysis.convert_to_col(res_busbar_row_df, signal_name='U_RES')
```
%% Cell type:markdown id: tags:
# 3. Circuit Parameters Table
%% Cell type:code id: tags:
``` python
rq_analysis.display_parameters_table(circuit_names[0])
```
%% Cell type:markdown id: tags:
# 4. Power Converter
## 4.1. Plot of the Power Converter Main Current
*GRAPHS*:
- t = 0 s corresponds to the start of the test
- Orange box(es) represent period(s) of time with constant current used for calculation of busbar resistance and DFB thresholds
%% Cell type:code id: tags:
``` python
import matplotlib as mpl
mpl.rcParams['savefig.dpi'] = 80
mpl.rcParams['figure.dpi'] = 80
%matplotlib notebook
title = '%s-%s, %s: %s-%s' % (circuit_names[0], circuit_names[1], hwc_test, Time.to_string(t_start).split('.')[0], Time.to_string(t_end).split('.')[0])
i_meas_nxcals_dfs[0].rename(columns={'I_MEAS': '%s:I_MEAS' % circuit_names[0]}, inplace=True)
i_meas_nxcals_dfs[1].rename(columns={'I_MEAS': '%s:I_MEAS' % circuit_names[1]}, inplace=True)
rq_analysis.plot_i_meas_with_current_plateau(i_meas_nxcals_dfs, t0=i_meas_raw_nxcals_dfs[0].index[0], plateau_start=plateau_start, plateau_end=plateau_end, title=title)
```
%% Cell type:markdown id: tags:
# 5. Busbar
## 5.1. RQ Busbar Resistance
*ANALYSIS*:
- Calculation of the busbar resistance as the slope of a linear fit of U,I curve obtained from the corresponding mean alues of the voltage and current
*CRITERIA*:
- Check if the busbar resistance is below 10 nOhm
*GRAPHS*:
- The busbar resistance, R
- The green box denotes the validity region of the busbar resostance (0, 10] nOhm
%% Cell type:code id: tags:
``` python
title = '%s-%s, %s: %s-%s' % (circuit_names[0], circuit_names[1], hwc_test, Time.to_string(t_start).split('.')[0], Time.to_string(t_end).split('.')[0])
res_outliers_df = rq_analysis.analyze_busbar_magnet_resistance(res_busbar_df, signal_name='R_RES', value_max=10e-9, title=title)
```
%% Cell type:code id: tags:
``` python
RqCircuitQuery.query_and_plot_outlier_voltage(res_outliers_df.reset_index(), t_start, t_end, i_meas_raw_nxcals_dfs[0].index[0], plateau_start, plateau_end, spark=spark)
```
%% Cell type:code id: tags:
``` python
busbar_metadata_resistance_df = rq_analysis.merge_busbar_metadata_with_resistance(res_busbar_df, circuit_type, circuit_names)
rq_analysis.display_busbar_metadata_resistance_with_threshold(busbar_metadata_resistance_df, threshold=10e-9)
```
%% Cell type:markdown id: tags:
# 6. Signature Decision
%% Cell type:code id: tags:
``` python
signature = get_expert_decision('Expert Signature Decision: ', ['PASSED', 'FAILED'])
```
%% Cell type:markdown id: tags:
# 7. Final Report
%% Cell type:code id: tags:
``` python
analysis_start_time = Time.get_analysis_start_time()
circuit_name = circuit_names[0].replace('D', '')
apply_report_template()
!mkdir -p /eos/project/m/mp3/RQ/$circuit_name/$hwc_test
file_name_csv = '{}_{}-{}-{}_{}_BUSBAR_RESISTANCE.csv'.format(circuit_name, hwc_test, Time.to_datetime(t_start).strftime("%Y-%m-%d-%Hh%M"), analysis_start_time, signature)
full_path = '/eos/project/m/mp3/RQ/{}/{}/{}'.format(circuit_name, hwc_test, file_name_csv)
busbar_metadata_resistance_df.to_csv(full_path)
print('Busbar resistance table saved to (Windows): ' + '\\\\cernbox-smb' + full_path.replace('/', '\\'))
file_name_html = '{}_{}-{}-{}_{}.html'.format(circuit_name, hwc_test, Time.to_datetime(t_start).strftime("%Y-%m-%d-%Hh%M"), analysis_start_time, signature)
full_path = '/eos/project/m/mp3/RQ/{}/{}/{}'.format(circuit_name, hwc_test, 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 $'AN_RQ_PLIS.s2.ipynb' --output /eos/project/m/mp3/RQ/$circuit_name/$hwc_test/$file_name_html --TemplateExporter.exclude_input=True --TagRemovePreprocessor.remove_all_outputs_tags='["skip_output"]'
```
%% Cell type:code id: tags:
``` python
```
......