Commit 3493e3a7 authored by Michal Maciejewski's avatar Michal Maciejewski
Browse files

Created AN_IT_FPA

parent 57f6a45f
......@@ -44,6 +44,20 @@ deploy_production_eos_600A:
before_script: []
after_script: []
deploy_production_eos_it:
stage: deploy
variables:
"EOS_PATH": "/eos/project/l/lhcsm/hwc/lhc-sm-hwc/it"
"CI_OUTPUT_DIR": "it"
# Only when the pushed with tags
only:
- tags
image: gitlab-registry.cern.ch/ci-tools/ci-web-deployer
script:
- deploy-eos
before_script: []
after_script: []
variables:
KRB5CCNAME: "/tmp/krb5cc"
NAME: "gitlab-registry.cern.ch/pkothuri/spark-pipelines/sparknotebook"
......
%% Cell type:markdown id: tags:
<h1><center>Analysis of an FPA in an 600A Circuit - RCBX Family</center></h1>
Figure below shows a generic circuit diagram, equipped with EE and parallel resistor, as well as lead resistances and a quench resistance.
<img src="https://gitlab.cern.ch/LHCData/lhc-sm-hwc/-/raw/master/figures/600A/600A_without_EE.png" width=75%>
source: Test Procedure and Acceptance Criteria for the 600 A Circuits, MP3 Procedure, <a href="https://edms.cern.ch/document/874716/5.3">https://edms.cern.ch/document/874716/5.3</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:
- What signal is used to calculate quench current (I_MEAS/I_DCCT)?
- How is the I_DCCT MIITs calculated (definition of start of decay)?
- How is the dU_RES/dt calculated?
- What is analysed for each system?
- What are the circuit families for different tabs in Excel files?
- How do we get circuit family?
- What timestamp is reported in the table? (QPS vs FGC)?
%% Cell type:markdown id: tags:
# 0. Initialise Working Environment
## 0.1. Import Necessary Packages
%% Cell type:code id: tags:
``` python
import io
import re
import sys
import pandas as pd
import numpy as np
from datetime import datetime
# lhc-sm-api
from lhcsmapi.Time import Time
from lhcsmapi.Timer import Timer
from lhcsmapi.pyedsl.QueryBuilder import QueryBuilder
from lhcsmapi.analysis.R600ACircuitQuery import R600ACircuitQuery
from lhcsmapi.analysis.R600ACircuitAnalysis import R600ACircuitAnalysis
from lhcsmapi.metadata.SignalMetadata import SignalMetadata
# GUI
from lhcsmapi.gui.qh.DateTimeBaseModule import DateTimeBaseModule
from lhcsmapi.gui.pc.FgcPmSearchModuleMediator import FgcPmSearchModuleMediator
from lhcsmapi.gui.pc.R600AFgcPmSearchBaseModule import R600ARcbxhvFgcPmSearchBaseModule
analysis_start_time = datetime.now().strftime("%Y.%m.%d_%H%M%S.%f")
```
%% Cell type:markdown id: tags:
## 0.2. LHCSMAPI Version
%% Cell type:code id: tags:
``` python
import lhcsmapi
print('Analysis executed with lhcsmapi version: {}'.format(lhcsmapi.__version__))
```
%% Cell type:markdown id: tags:
## 0.3. Notebook Version
%% Cell type:code id: tags:
``` python
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 FGC Post Mortem Entry
%% Cell type:code id: tags:
``` python
fgc_pm_search = FgcPmSearchModuleMediator(DateTimeBaseModule(start_date_time='2017-04-26 00:00:00+01:00',
end_date_time='2017-04-28 00:00:00+01:00'), R600ARcbxhvFgcPmSearchBaseModule(), circuit_type='600A_RCBXHV')
display(fgc_pm_search.widget)
```
%% Cell type:markdown id: tags:
# 2. Query All Signals Prior to Analysis
%% Cell type:code id: tags:
``` python
with Timer():
author = fgc_pm_search.get_author()
is_automatic = fgc_pm_search.is_automatic_mode()
circuit_type = '600A'
circuit_names = fgc_pm_search.get_fgc_circuit()
timestamp_fgc_rcbxh, timestamp_fgc_rcbxv = fgc_pm_search.get_fgc_timestamp()
query_rcbxh = R600ACircuitQuery(circuit_type, circuit_names[0])
query_rcbxv = R600ACircuitQuery(circuit_type, circuit_names[1])
# RCBXH
i_meas_rcbxh_df, i_a_rcbxh_df, i_ref_rcbxh_df, i_earth_rcbxh_df = query_rcbxh.query_pc_pm(timestamp_fgc_rcbxh, timestamp_fgc_rcbxh,
signal_names=['I_MEAS', 'I_A', 'I_REF', 'I_EARTH'])
events_action_rcbxh_df, events_symbol_rcbxh_df = query_rcbxh.query_pc_pm_events(timestamp_fgc_rcbxh, signal_names=['ACTION', 'SYMBOL'])
# RCBXV
i_meas_rcbxv_df, i_a_rcbxv_df, i_ref_rcbxv_df, i_earth_rcbxv_df = query_rcbxv.query_pc_pm(timestamp_fgc_rcbxv, timestamp_fgc_rcbxv,
signal_names=['I_MEAS', 'I_A', 'I_REF', 'I_EARTH'])
events_action_rcbxv_df, events_symbol_rcbxv_df = query_rcbxv.query_pc_pm_events(timestamp_fgc_rcbxv, signal_names=['ACTION', 'SYMBOL'])
# PIC
# # RCBXH
timestamp_pic_rcbxh = query_rcbxh.find_timestamp_pic(timestamp_fgc_rcbxh, spark=spark)
# # RCBXV
timestamp_pic_rcbxv = query_rcbxv.find_timestamp_pic(timestamp_fgc_rcbxv, spark=spark)
# QDS NXCALS - To check if there was any drift of QDS cards prior to the trigger
# # RCBXH
u_res_nxcals_rcbxh_df = query_rcbxh.query_iqps_nxcals(timestamp_fgc_rcbxh, signal_names=['U_RES'], spark=spark)[0]
# # RCBXV
u_res_nxcals_rcbxv_df = query_rcbxv.query_iqps_nxcals(timestamp_fgc_rcbxv, signal_names=['U_RES'], spark=spark)[0]
# QDS PM
# # RCBXH
source_timestamp_qds_rcbxh_df = query_rcbxh.find_source_timestamp_qds(timestamp_fgc_rcbxh, duration=[(2, 's'), (2, 's')])
timestamp_qds_rcbxh = np.nan if source_timestamp_qds_rcbxh_df.empty else source_timestamp_qds_rcbxh_df.loc[0, 'timestamp']
i_dcct_rcbxh_df, i_didt_rcbxh_df, u_res_rcbxh_df, u_diff_rcbxh_df = query_rcbxh.query_qds_pm(timestamp_qds_rcbxh, timestamp_qds_rcbxh,
signal_names=['I_DCCT', 'I_DIDT', 'U_RES', 'U_DIFF'])
# # RCBXV
source_timestamp_qds_rcbxv_df = query_rcbxv.find_source_timestamp_qds(timestamp_fgc_rcbxv, duration=[(2, 's'), (2, 's')])
timestamp_qds_rcbxv = np.nan if source_timestamp_qds_rcbxv_df.empty else source_timestamp_qds_rcbxv_df.loc[0, 'timestamp']
i_dcct_rcbxv_df, i_didt_rcbxv_df, u_res_rcbxv_df, u_diff_rcbxv_df = query_rcbxv.query_qds_pm(timestamp_qds_rcbxv, timestamp_qds_rcbxv,
signal_names=['I_DCCT', 'I_DIDT', 'U_RES', 'U_DIFF'])
# LEADS
# # RCBXH
leads_name = [x for x in SignalMetadata.get_system_types_per_circuit_name(circuit_type, circuit_names[0]) if 'LEADS' in x][0]
source_timestamp_leads_rcbxh_df = query_rcbxh.find_timestamp_leads(timestamp_fgc_rcbxh, leads_name)
u_hts_rcbxh_dfs = query_rcbxh.query_leads(timestamp_fgc_rcbxh, source_timestamp_leads_rcbxh_df, system=leads_name, signal_names=['U_HTS'], spark=spark, duration=[(300, 's'), (900, 's')])
u_res_rcbxh_dfs = query_rcbxh.query_leads(timestamp_fgc_rcbxh, source_timestamp_leads_rcbxh_df, system=leads_name, signal_names=['U_RES'], spark=spark, duration=[(300, 's'), (900, 's')])
# # RCBXV
leads_name = [x for x in SignalMetadata.get_system_types_per_circuit_name(circuit_type, circuit_names[1]) if 'LEADS' in x][0]
source_timestamp_leads_rcbxv_df = query_rcbxv.find_timestamp_leads(timestamp_fgc_rcbxv, leads_name)
u_hts_rcbxv_dfs = query_rcbxv.query_leads(timestamp_fgc_rcbxv, source_timestamp_leads_rcbxv_df, system=leads_name, signal_names=['U_HTS'], spark=spark, duration=[(300, 's'), (900, 's')])
u_res_rcbxv_dfs = query_rcbxv.query_leads(timestamp_fgc_rcbxv, source_timestamp_leads_rcbxv_df, system=leads_name, signal_names=['U_RES'], spark=spark, duration=[(300, 's'), (900, 's')])
# Create results table - RCBXH/V
results_table = query_rcbxh.create_report_analysis_template_rcbx(timestamp_fgc_rcbxh, timestamp_fgc_rcbxv, circuit_names, author=author)
analysis_rcbxh = R600ACircuitAnalysis(circuit_type, results_table, is_automatic=is_automatic)
analysis_rcbxv = R600ACircuitAnalysis(circuit_type, results_table, is_automatic=is_automatic)
```
%% Cell type:markdown id: tags:
# 3. Timestamps
The analysis for MP3 consists of checking the existence of PM file and of consistency of the PM time stamps (PC, QPS, EE if applicable). The criterion of passing this test described in detail in 600APIC2.
In short the following criteria should be checked:
- 2 PM DQAMGNA (A+B) files should be generated for 600 A circuits without EE
- Difference between QPS board A and B timestamp = 1 ms
- PC time stamp is QPS time stamp plus-minus 20 ms
- EE time stamp can be plus-minus 20 ms from the QPS time stamp.
If this is not the case, an in-depth analysis has to be performed by the QPS team.
%% Cell type:code id: tags:
``` python
timestamp_dct = {'FGC_RCBXH': timestamp_fgc_rcbxh, 'FGC_RCBXV': timestamp_fgc_rcbxv,
'PIC_RCBXH': timestamp_pic_rcbxh, 'PIC_RCBXV': timestamp_pic_rcbxv,
'QDS_A_RCBXH':source_timestamp_qds_rcbxh_df.loc[0, 'timestamp'] if len(source_timestamp_qds_rcbxh_df) > 0 else np.nan,
'QDS_B_RCBXH':source_timestamp_qds_rcbxh_df.loc[1, 'timestamp'] if len(source_timestamp_qds_rcbxh_df) > 1 else np.nan,
'QDS_A_RCBXV':source_timestamp_qds_rcbxv_df.loc[0, 'timestamp'] if len(source_timestamp_qds_rcbxv_df) > 0 else np.nan,
'QDS_B_RCBXV':source_timestamp_qds_rcbxv_df.loc[1, 'timestamp'] if len(source_timestamp_qds_rcbxv_df) > 1 else np.nan}
analysis_rcbxh.create_timestamp_table(timestamp_dct, circuit_name=circuit_names[0])
```
%% Cell type:markdown id: tags:
# 4. PC
## 4.1. Main Current
*QUERY*:
- PM for the main current of the power converter, I_MEAS
*INPUT*:
|Variable Name |Variable Type |Variable Unit |Comment
|---------------|---------------|---------------|------|
|circuit_type |str |- |Type of the analyzed circuit, e.g., '600A'|
|circuit_name |str |- |Name of the analyzed circuit, e.g., 'RQTL9.L7B2'|
|i_meas_df |DataFrame |A |Main current of the power converter, I_MEAS|
*ANALYSIS*:
- calculation of the ramp rate
- calculation of the duration of a plateau prior to a quench
*PLOT*:
- current of the power converter on the left axis, I_MEAS
- t = 0 s corresponds to the FGC timestamp.
*OUTPUT*:
- *No output is generated*
%% Cell type:code id: tags:
``` python
t_quench = analysis_rcbxh.find_time_of_quench(i_ref_rcbxh_df, i_a_rcbxh_df)
analysis_rcbxh.plot_i_meas_pc(circuit_names[0], timestamp_fgc_rcbxh, i_meas_rcbxh_df, i_ref_rcbxh_df, i_a_rcbxh_df, xlim=(t_quench-0.1, t_quench+0.1))
analysis_rcbxh.plot_i_meas_pc_zoom(circuit_names[0], timestamp_fgc_rcbxh, t_quench, i_meas_rcbxh_df, i_ref_rcbxh_df, i_a_rcbxh_df, xlim=(t_quench-0.1, t_quench+0.1))
analysis_rcbxh.plot_i_meas_pc(circuit_names[0], timestamp_fgc_rcbxh, [i_meas_rcbxh_df, i_ref_rcbxh_df, i_a_rcbxh_df], xlim=(t_quench-0.1, t_quench+0.1))
analysis_rcbxh.plot_i_meas_pc_zoom(circuit_names[0], timestamp_fgc_rcbxh, t_quench, [i_meas_rcbxh_df, i_ref_rcbxh_df, i_a_rcbxh_df], xlim=(t_quench-0.1, t_quench+0.1))
analysis_rcbxh.analyze_i_meas_pc_trigger(timestamp_fgc_rcbxh, events_action_rcbxh_df, events_symbol_rcbxh_df)
analysis_rcbxh.calculate_current_miits(i_meas_rcbxh_df, t_quench, col_name='I_MEAS MIITs H')
analysis_rcbxh.calculate_quench_current(i_meas_rcbxh_df, t_quench, col_name='I_Q_H')
analysis_rcbxh.calculate_current_slope(i_meas_rcbxh_df, col_name='Ramp Rate H')
t_quench = analysis_rcbxv.find_time_of_quench(i_ref_rcbxv_df, i_a_rcbxv_df)
analysis_rcbxv.plot_i_meas_pc(circuit_names[1], timestamp_fgc_rcbxv, i_meas_rcbxv_df, i_ref_rcbxv_df, i_a_rcbxv_df, xlim=(t_quench-1, t_quench+1))
analysis_rcbxv.plot_i_meas_pc_zoom(circuit_names[1], timestamp_fgc_rcbxv, t_quench, i_meas_rcbxv_df, i_ref_rcbxv_df, i_a_rcbxv_df, xlim=(t_quench-0.1, t_quench+0.1))
analysis_rcbxv.plot_i_meas_pc(circuit_names[1], timestamp_fgc_rcbxv, [i_meas_rcbxv_df, i_ref_rcbxv_df, i_a_rcbxv_df], xlim=(t_quench-1, t_quench+1))
analysis_rcbxv.plot_i_meas_pc_zoom(circuit_names[1], timestamp_fgc_rcbxv, t_quench, [i_meas_rcbxv_df, i_ref_rcbxv_df, i_a_rcbxv_df], xlim=(t_quench-0.1, t_quench+0.1))
analysis_rcbxv.analyze_i_meas_pc_trigger(timestamp_fgc_rcbxv, events_action_rcbxv_df, events_symbol_rcbxv_df)
analysis_rcbxv.calculate_current_miits(i_meas_rcbxv_df, t_quench, col_name='I_MEAS MIITs V')
analysis_rcbxv.calculate_quench_current(i_meas_rcbxv_df, t_quench, col_name='I_Q_V')
analysis_rcbxv.calculate_current_slope(i_meas_rcbxv_df, col_name='Ramp Rate V')
analysis_rcbxh.results_table[['Circuit Name', 'Date', 'Time', 'I_Q_H', 'I_Q_V', 'I_MEAS MIITs H', 'I_MEAS MIITs V', 'Ramp Rate H', 'Ramp Rate V', 'Plateau Duration']]
```
%% Cell type:markdown id: tags:
## 4.2. Earth Current
*QUERY*:
- PM for the earth current of power converter, I_EARTH
*INPUT*:
|Variable Name |Variable Type |Variable Unit |Comment
|---------------|---------------|---------------|------|
|circuit_type |str |- |Type of the analyzed circuit, e.g., '600A'|
|circuit_name |str |- |Name of the analyzed circuit, e.g., 'RQTL9.L7B2'|
|i_earth_df |DataFrame |A |Earth current of the power converter, I_EARTH|
*ANALYSIS*:
- calculation of the maximum earth current
*PLOT*:
- current of the power converter on the left axis, I_EARTH
- t = 0 s corresponds to the FGC timestamp.
*OUTPUT*:
- *No output is generated*
%% Cell type:code id: tags:
``` python
analysis_rcbxh.plot_i_earth_pc(circuit_names[0], timestamp_fgc_rcbxh, i_earth_rcbxh_df)
analysis_rcbxh.calculate_max_i_earth_pc(i_earth_rcbxh_df, col_name='Earth Current H')
analysis_rcbxv.plot_i_earth_pc(circuit_names[1], timestamp_fgc_rcbxv, i_earth_rcbxv_df)
analysis_rcbxv.calculate_max_i_earth_pc(i_earth_rcbxv_df, col_name='Earth Current V')
```
%% Cell type:markdown id: tags:
# 5. QDS
## 5.1. Resistive Voltage
*QUERY*:
- PM for the resistive voltage of magnets measured with QPS, U_RES
*INPUT*:
|Variable Name |Variable Type |Variable Unit |Comment
|---------------|---------------|---------------|------|
|circuit_type |str |- |Type of the analyzed circuit, e.g., '600A'|
|circuit_name |str |- |Name of the analyzed circuit, e.g., 'RQTL9.L7B2'|
|u_res_df |DataFrame |V |Resistive voltage of magnets measured with QPS, U_RES|
*ANALYSIS*:
- Initial voltage rise of U_RES signal, calculting by dividing the detection threshold voltage by the time it took for U_RES to rise to the threshold (from 50 to 250 mV).
- **Warning in case the slope of U_RES differs from history.**
- The quench voltage U_RES is calculated according to the following formula:
\begin{equation}
U_{\text{RES}} = U_{\text{DIFF}} + L d/dt (I+U_{\text{DIFF}}/R),
\end{equation}
where I = I_DCCT is heavily filtered over 1.3 s to make the calculation stable. It can be seen from the sign convention in Fig. 1 that a resistive voltage always has the opposite sign than the measured current. Note that I_DCCT is the QPS signal name, even though the current is actually measured not with a DCCT, but with a LEM detector, hence the poorer quality w.r.t. to the FGC I_A/B/MEAS signals that are measured with a DCCT.
*PLOT*:
- resistive voltage of magnets measured with QPS on the left axis, U_RES
- t = 0 s corresponds to the FGC timestamp.
*OUTPUT*:
- *No output is generated*
%% Cell type:code id: tags:
``` python
analysis_rcbxh.plot_u_res(circuit_names[0], timestamp_qds_rcbxh, u_res_nxcals_rcbxh_df)
u_res_rcbxh_slope_df = analysis_rcbxh.calculate_u_res_slope(u_res_rcbxh_df, col_name='dUres/dt H')
analysis_rcbxh.plot_u_res_slope(circuit_names[0], timestamp_qds_rcbxh, u_res_rcbxh_df, u_res_rcbxh_slope_df)
analysis_rcbxv.plot_u_res(circuit_names[1], timestamp_qds_rcbxv, u_res_nxcals_rcbxv_df)
u_res_rcbxv_slope_df = analysis_rcbxv.calculate_u_res_slope(u_res_rcbxv_df, col_name='dUres/dt V')
analysis_rcbxv.plot_u_res_slope(circuit_names[1], timestamp_qds_rcbxv, u_res_rcbxv_df, u_res_rcbxv_slope_df)
analysis_rcbxh.results_table[['Circuit Name', 'Date', 'Time', 'dUres/dt H', 'dUres/dt V']]
```
%% Cell type:markdown id: tags:
## 5.2. I_DCCT, I_DIDT Currents; U_RES, U_DIFF Voltages
*QUERY*:
- PM for the DC current leads of QPS, I_DCCT
- PM for the didt current leads of QPS, I_DIDT
- PM for the diffrential voltage of QPS, U_DIFF
- PM for the resistive voltage of QPS, U_REF
*INPUT*:
|Variable Name |Variable Type |Variable Unit |Comment
|---------------|---------------|---------------|------|
|circuit_type |str |- |Type of the analyzed circuit, e.g., '600A'|
|circuit_name |str |- |Name of the analyzed circuit, e.g., 'RQTL9.L7B2'|
|i_dcct_df |DataFrame |A |DC current leads of QPS, I_DCCT|
*ANALYSIS*:
- *No analysis is performed*
*PLOT*:
- current of the DC current leads of QPS on the left axis, I_DCCT
- didt current leads of QPS on the left axis, I_DIDT
- diffrential voltage of QPS on the right axis, U_DIFF
- resistive voltage of QPS on the right axis, U_RES
- t = 0 s corresponds to the QPS timestamp.
*OUTPUT*:
- *No output is generated*
%% Cell type:code id: tags:
``` python
analysis_rcbxh.analyze_qds(circuit_names[0], timestamp_qds_rcbxh, i_dcct_rcbxh_df, i_didt_rcbxh_df, u_diff_rcbxh_df, u_res_rcbxh_df, col_names=['Reason H', 'Quench Origin H'])
analysis_rcbxv.analyze_qds(circuit_names[1], timestamp_qds_rcbxv, i_dcct_rcbxv_df, i_didt_rcbxv_df, u_diff_rcbxv_df, u_res_rcbxv_df, col_names=['Reason V', 'Quench Origin V'])
```
%% Cell type:markdown id: tags:
# 6. LEADS
## 6.1. Plot of Current Leads
*QUERY*:
- PM for leads voltage, U_HTS, U_RES
*INPUT*:
|Variable Name |Variable Type |Variable Unit |Comment
|---------------|---------------|---------------|------|
|circuit_type |str |- |Type of the analyzed circuit, e.g., '600A'|
|circuit_name |str |- |Name of the analyzed circuit, e.g., 'RQTL9.L7B2'|
|u_leads_df |DataFrame |V |Leads voltage, U_HTS, U_RES|
*ANALYSIS*:
- quench detection for U_HTS for 2 consecutive datapoints above the threshold **(3 mV)**
- detection for U_RES for 2 consecutive datapoints above the threshold **(100 mV)**
*PLOT*:
- voltage of the normal conducting leads on the left axis, U_RES
- voltage of the HTS leads on the left axis, U_HTS
- t = 0 s corresponds to the LEADS timestamp.
*OUTPUT*:
- *No output is generated*
%% Cell type:code id: tags:
``` python
analysis_rcbxh.analyze_leads_voltage(u_hts_rcbxh_dfs, circuit_names[0], timestamp_fgc_rcbxh, signal='U_HTS', value_min=-0.003, value_max=0.003)
analysis_rcbxh.analyze_leads_voltage(u_res_rcbxh_dfs, circuit_names[0], timestamp_fgc_rcbxh, signal='U_RES', value_min=-0.1, value_max=0.1)
analysis_rcbxv.analyze_leads_voltage(u_hts_rcbxv_dfs, circuit_names[1], timestamp_fgc_rcbxv, signal='U_HTS', value_min=-0.003, value_max=0.003)
analysis_rcbxv.analyze_leads_voltage(u_res_rcbxv_dfs, circuit_names[1], timestamp_fgc_rcbxv, signal='U_RES', value_min=-0.1, value_max=0.1)
```
%% Cell type:markdown id: tags:
# 7. Final Report
## 7.1. Display Results Table
%% Cell type:code id: tags:
``` python
pd.set_option('display.max_columns', None)
analysis_rcbxh.results_table
```
%% Cell type:markdown id: tags:
## 7.2. Write Results Table to CSV
%% Cell type:code id: tags:
``` python
timestamp_fgc = timestamp_fgc_rcbxh if not np.isnan(timestamp_fgc_rcbxh) else timestamp_fgc_rcbxv
file_name = "{}-{}-PM_600A_RCBX_FPA".format(Time.to_datetime(timestamp_fgc).strftime("%Y.%m.%d_%H%M%S.%f"), analysis_start_time)
```
%% Cell type:code id: tags:
``` python
# Create folder for circuit_name
circuit_name = circuit_names[0]
!mkdir -p /eos/project/l/lhcsm/operation/600A/$circuit_name
analysis_rcbxh.results_table.to_csv('/eos/project/l/lhcsm/operation/600A/{}/{}_results_table.csv'.format(circuit_name, file_name))
```
%% Cell type:markdown id: tags:
## 7.3. Display MP3 Results Table
%% Cell type:code id: tags:
``` python
mp3_results_table = analysis_rcbxh.create_mp3_results_table_rcbxhv()
mp3_results_table
```
%% Cell type:markdown id: tags:
## 7.4. Write MP3 Quench Database Table to CSV
%% Cell type:code id: tags:
``` python
# Create folder for circuit_name
circuit_name = circuit_names[0]
!mkdir -p /eos/project/l/lhcsm/operation/600A/$circuit_name
mp3_results_table.to_csv('/eos/project/l/lhcsm/operation/600A/{}/{}_mp3_results_table.csv'.format(circuit_name, file_name))
```
%% Cell type:markdown id: tags:
## 7.5. Export Notebook as an HTML File
%% Cell type:code id: tags:
``` python
file_name_html = file_name + '_report.html'
!mkdir -p /eos/project/l/lhcsm/operation/600A/$circuit_name
!{sys.executable} -m jupyter nbconvert --to html $'AN_600A_RCBXHV_FPA.ipynb' --output /eos/project/l/lhcsm/operation/600A/$circuit_name/$file_name_html
```
%% Cell type:code id: tags:
``` python
```
......
%% Cell type:markdown id: tags:
<h1><center>Analysis of an FPA in an 600A Circuit - RCD-RCO Family</center></h1>
Figure below shows a generic circuit diagram, equipped with EE and parallel resistor, as well as lead resistances and a quench resistance.
<img src="https://gitlab.cern.ch/LHCData/lhc-sm-hwc/-/raw/master/figures/600A/600A_without_EE.png" width=75%>
source: Test Procedure and Acceptance Criteria for the 600 A Circuits, MP3 Procedure, <a href="https://edms.cern.ch/document/874716/5.3">https://edms.cern.ch/document/874716/5.3</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
## 0.1. Import Necessary Packages
%% Cell type:code id: tags:
``` python
import io
import re
import sys
import pandas as pd
import numpy as np
from datetime import datetime
# lhc-sm-api
from lhcsmapi.Time import Time
from lhcsmapi.Timer import Timer
from lhcsmapi.pyedsl.QueryBuilder import QueryBuilder
from lhcsmapi.analysis.R600ACircuitQuery import R600ACircuitQuery
from lhcsmapi.analysis.R600ACircuitAnalysis import R600ACircuitAnalysis
from lhcsmapi.metadata.SignalMetadata import SignalMetadata
# GUI
from lhcsmapi.gui.qh.DateTimeBaseModule import DateTimeBaseModule
from lhcsmapi.gui.pc.FgcPmSearchModuleMediator import FgcPmSearchModuleMediator
from lhcsmapi.gui.pc.R600AFgcPmSearchBaseModule import R600ARcdoFgcPmSearchBaseModule
analysis_start_time = datetime.now().strftime("%Y.%m.%d_%H%M%S.%f")
```
%% Cell type:markdown id: tags:
## 0.2. LHCSMAPI Version
%% Cell type:code id: tags:
``` python
import lhcsmapi
print('Analysis executed with lhcsmapi version: {}'.format(lhcsmapi.__version__))
```
%% Cell type:markdown id: tags:
## 0.3. Notebook Version
%% Cell type:code id: tags:
``` python
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 FGC Post Mortem Entry
%% Cell type:code id: tags:
``` python
fgc_pm_search = FgcPmSearchModuleMediator(DateTimeBaseModule(start_date_time='2018-03-19 00:00:00+01:00',
end_date_time='2018-03-20 00:00:00+01:00'), R600ARcdoFgcPmSearchBaseModule(), circuit_type='600A_RCDO')
display(fgc_pm_search.widget)
```
%% Cell type:markdown id: tags:
# 2. Query All Signals Prior to Analysis
%% Cell type:code id: tags:
``` python
with Timer():
author = fgc_pm_search.get_author()
is_automatic = fgc_pm_search.is_automatic_mode()
circuit_type = '600A'
circuit_names = fgc_pm_search.get_fgc_circuit()
timestamp_fgc_rcd, timestamp_fgc_rco = fgc_pm_search.get_fgc_timestamp()
query_rcd = R600ACircuitQuery(circuit_type, circuit_names[0])
query_rco = R600ACircuitQuery(circuit_type, circuit_names[1])
# RCD
i_meas_rcd_df, i_a_rcd_df, i_ref_rcd_df, i_earth_rcd_df = query_rcd.query_pc_pm(timestamp_fgc_rcd, timestamp_fgc_rcd,
signal_names=['I_MEAS', 'I_A', 'I_REF', 'I_EARTH'])
events_action_rcd_df, events_symbol_rcd_df = query_rcd.query_pc_pm_events(timestamp_fgc_rcd, signal_names=['ACTION', 'SYMBOL'])
# RCO
i_meas_rco_df, i_a_rco_df, i_ref_rco_df, i_earth_rco_df = query_rco.query_pc_pm(timestamp_fgc_rco, timestamp_fgc_rco,
signal_names=['I_MEAS', 'I_A', 'I_REF', 'I_EARTH'])
events_action_rco_df, events_symbol_rco_df = query_rco.query_pc_pm_events(timestamp_fgc_rco, signal_names=['ACTION', 'SYMBOL'])
# PIC
# # RCD
timestamp_pic_rcd = query_rcd.find_timestamp_pic(timestamp_fgc_rcd, spark=spark)
# # RCO
timestamp_pic_rco = query_rco.find_timestamp_pic(timestamp_fgc_rco, spark=spark)
# QDS NXCALS - To check if there was any drift of QDS cards prior to the trigger
# # RCD
u_res_nxcals_rcd_df = query_rcd.query_iqps_nxcals(timestamp_fgc_rcd, signal_names=['U_RES'], spark=spark)[0]
# # RCO
u_res_nxcals_rco_df = query_rco.query_iqps_nxcals(timestamp_fgc_rco, signal_names=['U_RES'], spark=spark)[0]
# QDS PM
# # RCD
source_timestamp_qds_rcd_df = query_rcd.find_source_timestamp_qds(timestamp_fgc_rcd, duration=[(2, 's'), (2, 's')])
timestamp_qds_rcd = np.nan if source_timestamp_qds_rcd_df.empty else source_timestamp_qds_rcd_df.loc[0, 'timestamp']
i_dcct_rcd_df, i_didt_rcd_df, u_res_rcd_df, u_diff_rcd_df = query_rcd.query_qds_pm(timestamp_qds_rcd, timestamp_qds_rcd,
signal_names=['I_DCCT', 'I_DIDT', 'U_RES', 'U_DIFF'])
# # RCO
source_timestamp_qds_rco_df = query_rco.find_source_timestamp_qds(timestamp_fgc_rco, duration=[(2, 's'), (2, 's')])
timestamp_qds_rco = np.nan if source_timestamp_qds_rco_df.empty else source_timestamp_qds_rco_df.loc[0, 'timestamp']
i_dcct_rco_df, i_didt_rco_df, u_res_rco_df, u_diff_rco_df = query_rco.query_qds_pm(timestamp_qds_rco, timestamp_qds_rco,
signal_names=['I_DCCT', 'I_DIDT', 'U_RES', 'U_DIFF'])
# LEADS
# # RCD
leads_name = [x for x in SignalMetadata.get_system_types_per_circuit_name(circuit_type, circuit_names[0]) if 'LEADS' in x][0]
source_timestamp_leads_rcd_df = query_rcd.find_timestamp_leads(timestamp_fgc_rcd, leads_name)
u_hts_rcd_dfs = query_rcd.query_leads(timestamp_fgc_rcd, source_timestamp_leads_rcd_df, system=leads_name, signal_names=['U_HTS'], spark=spark, duration=[(300, 's'), (900, 's')])
u_res_rcd_dfs = query_rcd.query_leads(timestamp_fgc_rcd, source_timestamp_leads_rcd_df, system=leads_name, signal_names=['U_RES'], spark=spark, duration=[(300, 's'), (900, 's')])
# # RCO
leads_name = [x for x in SignalMetadata.get_system_types_per_circuit_name(circuit_type, circuit_names[1]) if 'LEADS' in x][0]
source_timestamp_leads_rco_df = query_rco.find_timestamp_leads(timestamp_fgc_rco, leads_name)
u_hts_rco_dfs = query_rco.query_leads(timestamp_fgc_rco, source_timestamp_leads_rco_df, system=leads_name, signal_names=['U_HTS'], spark=spark, duration=[(300, 's'), (900, 's')])
u_res_rco_dfs = query_rco.query_leads(timestamp_fgc_rco, source_timestamp_leads_rco_df, system=leads_name, signal_names=['U_RES'], spark=spark, duration=[(300, 's'), (900, 's')])
# Create results table - RCD/O
results_table = query_rcd.create_report_analysis_template_rcd(timestamp_fgc_rcd, timestamp_fgc_rco, circuit_names, author=author)
analysis_rcd = R600ACircuitAnalysis(circuit_type, results_table, is_automatic=is_automatic)
analysis_rco = R600ACircuitAnalysis(circuit_type, results_table, is_automatic=is_automatic)
```
%% Cell type:markdown id: tags:
# 3. Timestamps
The analysis for MP3 consists of checking the existence of PM file and of consistency of the PM time stamps (PC, QPS, EE if applicable). The criterion of passing this test described in detail in 600APIC2.
In short the following criteria should be checked:
- 2 PM DQAMGNA (A+B) files should be generated for 600 A circuits without EE
- Difference between QPS board A and B timestamp = 1 ms
- PC time stamp is QPS time stamp plus-minus 20 ms
- EE time stamp can be plus-minus 20 ms from the QPS time stamp.
If this is not the case, an in-depth analysis has to be performed by the QPS team.
%% Cell type:code id: tags:
``` python
timestamp_dct = {'FGC_RCD': timestamp_fgc_rcd, 'FGC_RCO': timestamp_fgc_rco,
'PIC_RCD': timestamp_pic_rcd, 'PIC_RCO': timestamp_pic_rco,
'QDS_A_RCD':source_timestamp_qds_rcd_df.loc[0, 'timestamp'] if len(source_timestamp_qds_rcd_df) > 0 else np.nan,
'QDS_B_RCD':source_timestamp_qds_rcd_df.loc[1, 'timestamp'] if len(source_timestamp_qds_rcd_df) > 1 else np.nan,
'QDS_A_RCO':source_timestamp_qds_rco_df.loc[0, 'timestamp'] if len(source_timestamp_qds_rco_df) > 0 else np.nan,
'QDS_B_RCO':source_timestamp_qds_rco_df.loc[1, 'timestamp'] if len(source_timestamp_qds_rco_df) > 1 else np.nan}
analysis_rcd.create_timestamp_table(timestamp_dct, circuit_names[0])
```
%% Cell type:markdown id: tags:
# 4. PC
## 4.1. Main Current
*QUERY*:
- PM for the main current of the power converter, I_MEAS
*INPUT*:
|Variable Name |Variable Type |Variable Unit |Comment
|---------------|---------------|---------------|------|
|circuit_type |str |- |Type of the analyzed circuit, e.g., '600A'|
|circuit_name |str |- |Name of the analyzed circuit, e.g., 'RQTL9.L7B2'|
|i_meas_df |DataFrame |A |Main current of the power converter, I_MEAS|
*ANALYSIS*:
- calculation of the ramp rate
- **calculation of the duration of a plateau prior to a quench**
*PLOT*:
- current of the power converter on the left axis, I_MEAS
- t = 0 s corresponds to the FGC timestamp.
*OUTPUT*:
- *No output is generated*
%% Cell type:code id: tags:
``` python
t_quench = analysis_rcd.find_time_of_quench(i_ref_rcd_df, i_a_rcd_df)
analysis_rcd.plot_i_meas_pc(circuit_names[0], timestamp_fgc_rcd, i_meas_rcd_df, i_ref_rcd_df, i_a_rcd_df, xlim=(t_quench-0.1, t_quench+0.1))
analysis_rcd.plot_i_meas_pc_zoom(circuit_names[0], timestamp_fgc_rcd, t_quench, i_meas_rcd_df, i_ref_rcd_df, i_a_rcd_df, xlim=(t_quench-0.1, t_quench+0.1))
analysis_rcd.plot_i_meas_pc(circuit_names[0], timestamp_fgc_rcd, [i_meas_rcd_df, i_ref_rcd_df, i_a_rcd_df], xlim=(t_quench-0.1, t_quench+0.1))
analysis_rcd.plot_i_meas_pc_zoom(circuit_names[0], timestamp_fgc_rcd, t_quench, [i_meas_rcd_df, i_ref_rcd_df, i_a_rcd_df], xlim=(t_quench-0.1, t_quench+0.1))
analysis_rcd.analyze_i_meas_pc_trigger(timestamp_fgc_rcd, events_action_rcd_df, events_symbol_rcd_df)
analysis_rcd.calculate_current_miits(i_meas_rcd_df, t_quench, col_name='I_MEAS MIITs RCD')
analysis_rcd.calculate_quench_current(i_meas_rcd_df, t_quench, col_name='I_Q_RCD')
analysis_rcd.calculate_current_slope(i_meas_rcd_df, col_name='Ramp Rate RCD')
t_quench = analysis_rco.find_time_of_quench(i_ref_rco_df, i_a_rco_df)
analysis_rco.plot_i_meas_pc(circuit_names[1], timestamp_fgc_rco, i_meas_rco_df, i_ref_rco_df, i_a_rco_df, xlim=(t_quench-1, t_quench+1))
analysis_rco.plot_i_meas_pc_zoom(circuit_names[1], timestamp_fgc_rco, t_quench, i_meas_rco_df, i_ref_rco_df, i_a_rco_df, xlim=(t_quench-0.1, t_quench+0.1))
analysis_rco.plot_i_meas_pc(circuit_names[1], timestamp_fgc_rco, [i_meas_rco_df, i_ref_rco_df, i_a_rco_df], xlim=(t_quench-1, t_quench+1))
analysis_rco.plot_i_meas_pc_zoom(circuit_names[1], timestamp_fgc_rco, t_quench, [i_meas_rco_df, i_ref_rco_df, i_a_rco_df], xlim=(t_quench-0.1, t_quench+0.1))
analysis_rco.analyze_i_meas_pc_trigger(timestamp_fgc_rco, events_action_rco_df, events_symbol_rco_df)
analysis_rco.calculate_current_miits(i_meas_rco_df, t_quench, col_name='I_MEAS MIITs RCO')
analysis_rco.calculate_quench_current(i_meas_rco_df, t_quench, col_name='I_Q_RCO')
analysis_rco.calculate_current_slope(i_meas_rco_df, col_name='Ramp Rate RCO')
analysis_rcd.results_table[['Circuit Name', 'Date', 'Time', 'I_Q_RCD', 'I_Q_RCO', 'I_MEAS MIITs RCD', 'I_MEAS MIITs RCO', 'Ramp Rate RCD', 'Ramp Rate RCO', 'Plateau Duration']]
```
%% Cell type:markdown id: tags:
## 4.2. Earth Current
*QUERY*:
- PM for the earth current of power converter, I_EARTH
*INPUT*:
|Variable Name |Variable Type |Variable Unit |Comment
|---------------|---------------|---------------|------|
|circuit_type |str |- |Type of the analyzed circuit, e.g., '600A'|
|circuit_name |str |- |Name of the analyzed circuit, e.g., 'RQTL9.L7B2'|
|i_earth_df |DataFrame |A |Earth current of the power converter, I_EARTH|
*ANALYSIS*:
- calculation of the maximum earth current
*PLOT*:
- current of the power converter on the left axis, I_EARTH
- t = 0 s corresponds to the FGC timestamp.
*OUTPUT*:
- *No output is generated*
%% Cell type:code id: tags:
``` python
analysis_rcd.plot_i_earth_pc(circuit_names[0], timestamp_fgc_rcd, i_earth_rcd_df)
analysis_rcd.calculate_max_i_earth_pc(i_earth_rcd_df, col_name='Earth Current RCD')
analysis_rco.plot_i_earth_pc(circuit_names[0], timestamp_fgc_rco, i_earth_rco_df)
analysis_rco.calculate_max_i_earth_pc(i_earth_rco_df, col_name='Earth Current RCO')
```
%% Cell type:markdown id: tags:
# 5. QDS
## 5.1. Resistive Voltage
*QUERY*:
- PM for the resistive voltage of magnets measured with QPS, U_RES
*INPUT*:
|Variable Name |Variable Type |Variable Unit |Comment
|---------------|---------------|---------------|------|
|circuit_type |str |- |Type of the analyzed circuit, e.g., '600A'|
|circuit_name |str |- |Name of the analyzed circuit, e.g., 'RQTL9.L7B2'|
|u_res_df |DataFrame |V |Resistive voltage of magnets measured with QPS, U_RES|
*ANALYSIS*:
- Initial voltage rise of U_RES signal, calculting by dividing the detection threshold voltage by the time it took for U_RES to rise to the threshold (from 50 to 250 mV).
- **Warning in case the slope of U_RES differs from history.**
- The quench voltage U_RES is calculated according to the following formula:
\begin{equation}
U_{\text{RES}} = U_{\text{DIFF}} + L d/dt (I+U_{\text{DIFF}}/R),
\end{equation}
where I = I_DCCT is heavily filtered over 1.3 s to make the calculation stable. It can be seen from the sign convention in Fig. 1 that a resistive voltage always has the opposite sign than the measured current. Note that I_DCCT is the QPS signal name, even though the current is actually measured not with a DCCT, but with a LEM detector, hence the poorer quality w.r.t. to the FGC I_A/B/MEAS signals that are measured with a DCCT.
*PLOT*:
- resistive voltage of magnets measured with QPS on the left axis, U_RES
- t = 0 s corresponds to the FGC timestamp.
*OUTPUT*:
- *No output is generated*
%% Cell type:code id: tags:
``` python
analysis_rcd.plot_u_res(circuit_names[0], timestamp_qds_rcd, u_res_nxcals_rcd_df)
u_res_rcd_slope_df = analysis_rcd.calculate_u_res_slope(u_res_rcd_df, col_name='dUres/dt RCD')
analysis_rcd.plot_u_res_slope(circuit_names[0], timestamp_qds_rcd, u_res_rcd_df, u_res_rcd_slope_df)
analysis_rco.plot_u_res(circuit_names[1], timestamp_qds_rco, u_res_nxcals_rco_df)
u_res_rco_slope_df = analysis_rco.calculate_u_res_slope(u_res_rco_df, col_name='dUres/dt RCO')
analysis_rco.plot_u_res_slope(circuit_names[1], timestamp_qds_rco, u_res_rco_df, u_res_rco_slope_df)
analysis_rcd.results_table[['Circuit Name', 'Date', 'Time', 'dUres/dt RCD', 'dUres/dt RCO']]
```
%% Cell type:markdown id: tags:
## 5.2. I_DCCT, I_DIDT Currents; U_RES, U_DIFF Voltages
*QUERY*:
- PM for the DC current leads of QPS, I_DCCT
- PM for the didt current leads of QPS, I_DIDT
- PM for the diffrential voltage of QPS, U_DIFF
- PM for the resistive voltage of QPS, U_REF
*INPUT*:
|Variable Name |Variable Type |Variable Unit |Comment
|---------------|---------------|---------------|------|
|circuit_type |str |- |Type of the analyzed circuit, e.g., '600A'|
|circuit_name |str |- |Name of the analyzed circuit, e.g., 'RQTL9.L7B2'|
|i_dcct_df |DataFrame |A |DC current leads of QPS, I_DCCT|
*ANALYSIS*:
- *No analysis is performed*
*PLOT*:
- current of the DC current leads of QPS on the left axis, I_DCCT
- didt current leads of QPS on the left axis, I_DIDT
- diffrential voltage of QPS on the right axis, U_DIFF
- resistive voltage of QPS on the right axis, U_RES
- t = 0 s corresponds to the QPS timestamp.
*OUTPUT*:
- *No output is generated*
%% Cell type:code id: tags:
``` python
analysis_rcd.analyze_qds(circuit_names[0], timestamp_qds_rcd, i_dcct_rcd_df, i_didt_rcd_df, u_diff_rcd_df, u_res_rcd_df, col_names=['Reason RCD', 'Quench Origin RCD'])
analysis_rco.analyze_qds(circuit_names[1], timestamp_qds_rco, i_dcct_rco_df, i_didt_rco_df, u_diff_rco_df, u_res_rco_df, col_names=['Reason RCO', 'Quench Origin RCO'])
```
%% Cell type:markdown id: tags:
# 6. LEADS
## 6.1. Plot of Current Leads
*QUERY*:
- PM for leads voltage, U_HTS, U_RES
*INPUT*:
|Variable Name |Variable Type |Variable Unit |Comment
|---------------|---------------|---------------|------|
|circuit_type |str |- |Type of the analyzed circuit, e.g., '600A'|
|circuit_name |str |- |Name of the analyzed circuit, e.g., 'RQTL9.L7B2'|
|u_leads_df |DataFrame |V |Leads voltage, U_HTS, U_RES|
*ANALYSIS*:
- quench detection for U_HTS for 2 consecutive datapoints above the threshold **(3 mV)**
- detection for U_RES for 2 consecutive datapoints above the threshold **(100 mV)**
*PLOT*:
- voltage of the normal conducting leads on the left axis, U_RES
- voltage of the HTS leads on the left axis, U_HTS
- t = 0 s corresponds to the LEADS timestamp.
*OUTPUT*:
- *No output is generated*
%% Cell type:code id: tags:
``` python
analysis_rcd.analyze_leads_voltage(u_hts_rcd_dfs, circuit_names[0], timestamp_fgc_rcd, signal='U_HTS', value_min=-0.003, value_max=0.003)
analysis_rcd.analyze_leads_voltage(u_res_rcd_dfs, circuit_names[0], timestamp_fgc_rcd, signal='U_RES', value_min=-0.1, value_max=0.1)
analysis_rco.analyze_leads_voltage(u_hts_rco_dfs, circuit_names[1], timestamp_fgc_rco, signal='U_HTS', value_min=-0.003, value_max=0.003)
analysis_rco.analyze_leads_voltage(u_res_rco_dfs, circuit_names[1], timestamp_fgc_rco, signal='U_RES', value_min=-0.1, value_max=0.1)
```
%% Cell type:markdown id: tags:
# 7. Final Report
## 7.1. Display Results Table
%% Cell type:code id: tags:
``` python
pd.set_option('display.max_columns', None)
analysis_rcd.results_table
```
%% Cell type:markdown id: tags:
## 7.2. Write Results Table to CSV
%% Cell type:code id: tags:
``` python
timestamp_fgc = timestamp_fgc_rcd if not np.isnan(timestamp_fgc_rcd) else timestamp_fgc_rco
file_name = "{}-{}-PM_600A_RCD-RCO_FPA".format(Time.to_datetime(timestamp_fgc).strftime("%Y.%m.%d_%H%M%S.%f"), analysis_start_time)
```
%% Cell type:code id: tags:
``` python
# Create folder for circuit_name
circuit_name = circuit_names[0]
!mkdir -p /eos/project/l/lhcsm/operation/600A/$circuit_name
analysis_rcd.results_table.to_csv('/eos/project/l/lhcsm/operation/600A/{}/{}_results_table.csv'.format(circuit_name, file_name))
```
%% Cell type:markdown id: tags:
## 7.3. Display MP3 Results Table
%% Cell type:code id: tags:
``` python
mp3_results_table = analysis_rcd.create_mp3_results_table_rcdo()
mp3_results_table
```
%% Cell type:markdown id: tags:
## 7.4. Write MP3 Quench Database Table to CSV
%% Cell type:code id: tags:
``` python
# Create folder for circuit_name
circuit_name = circuit_names[0]
!mkdir -p /eos/project/l/lhcsm/operation/600A/$circuit_name
mp3_results_table.to_csv('/eos/project/l/lhcsm/operation/600A/{}/{}_mp3_results_table.csv'.format(circuit_name, file_name))
```
%% Cell type:markdown id: tags:
## 7.5. Export Notebook as an HTML File
%% Cell type:code id: tags:
``` python
file_name_html = file_name + '_report.html'
!mkdir -p /eos/project/l/lhcsm/operation/600A/$circuit_name
!{sys.executable} -m jupyter nbconvert --to html $'AN_600A_RCDO_FPA.ipynb' --output /eos/project/l/lhcsm/operation/600A/$circuit_name/$file_name_html
```
......
%% Cell type:markdown id: tags:
<h1><center>Analysis of an FPA in an 600A Circuit - with Energy Extraction</center></h1>
Figure 1 shows a generic circuit diagram, equipped with EE and parallel resistor, as well as lead resistances and a quench resistance.
<img src="https://gitlab.cern.ch/LHCData/lhc-sm-hwc/-/raw/master/figures/600A/600A.png" width=75%>
source: Test Procedure and Acceptance Criteria for the 600 A Circuits, MP3 Procedure, <a href="https://edms.cern.ch/document/874716/5.3">https://edms.cern.ch/document/874716/5.3</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
## 0.1. Import Necessary Packages
%% 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 matplotlib.pyplot as plt
# lhc-sm-api
from lhcsmapi.Time import Time
from lhcsmapi.Timer import Timer
from lhcsmapi.pyedsl.QueryBuilder import QueryBuilder
from lhcsmapi.analysis.R600ACircuitQuery import R600ACircuitQuery
from lhcsmapi.analysis.R600ACircuitAnalysis import R600ACircuitAnalysis
from lhcsmapi.metadata.SignalMetadata import SignalMetadata
# GUI
from lhcsmapi.gui.qh.DateTimeBaseModule import DateTimeBaseModule
from lhcsmapi.gui.pc.FgcPmSearchModuleMediator import FgcPmSearchModuleMediator
from lhcsmapi.gui.pc.R600AFgcPmSearchBaseModule import R600AFgcPmSearchBaseModule
analysis_start_time = datetime.now().strftime("%Y.%m.%d_%H%M%S.%f")
```
%% Cell type:markdown id: tags:
## 0.2. LHCSMAPI Version
%% Cell type:code id: tags:
``` python
import lhcsmapi
print('Analysis executed with lhcsmapi version: {}'.format(lhcsmapi.__version__))
```
%% Cell type:markdown id: tags:
## 0.3. Notebook Version
%% Cell type:code id: tags:
``` python
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 FGC Post Mortem Entry
%% Cell type:code id: tags:
``` python
circuit_type = '600A'
fgc_pm_search = FgcPmSearchModuleMediator(DateTimeBaseModule(start_date_time='2018-12-06 00:00:00+01:00',
end_date_time='2018-12-07 00:00:00+01:00'), R600AFgcPmSearchBaseModule(), circuit_type=circuit_type)
display(fgc_pm_search.widget)
```
%% Cell type:markdown id: tags:
# 2. Query All Signals Prior to Analysis
%% Cell type:code id: tags:
``` python
with Timer():
author = fgc_pm_search.get_author()
is_automatic = fgc_pm_search.is_automatic_mode()
timestamp_fgc = fgc_pm_search.get_fgc_timestamp()
circuit_name = fgc_pm_search.get_fgc_circuit()
query = R600ACircuitQuery(circuit_type, circuit_name)
i_meas_df, i_a_df, i_ref_df, i_earth_df = query.query_pc_pm(timestamp_fgc, timestamp_fgc, signal_names=['I_MEAS', 'I_A', 'I_REF', 'I_EARTH'])
events_action_df, events_symbol_df = query.query_pc_pm_events(timestamp_fgc, signal_names=['ACTION', 'SYMBOL'])
# Create results table
results_table = query.create_report_analysis_template(timestamp_fgc, author=author)
# PIC
timestamp_pic = query.find_timestamp_pic(timestamp_fgc, spark=spark)
# EE
if 'EE' in SignalMetadata.get_system_types_per_circuit_name(circuit_type, circuit_name):
source_timestamp_ee_df = query.find_source_timestamp_ee(timestamp_fgc)
if not source_timestamp_ee_df.empty:
u_dump_res_df = query.query_ee_u_dump_res_pm(source_timestamp_ee_df.loc[0, 'timestamp'], timestamp_fgc, system='EE', signal_names=['U_DUMP_RES'])[0]
else:
u_dump_res_df = pd.DataFrame()
else:
source_timestamp_ee_df = pd.DataFrame()
results_table['EE max voltage'] = 'No EE'
# QDS
# To check if there was any drift of QDS cards prior to the trigger
u_res_nxcals_df = query.query_iqps_nxcals(timestamp_fgc, signal_names=['U_RES'], spark=spark)[0]
source_timestamp_qds_df = query.find_source_timestamp_qds(timestamp_fgc, duration=[(2, 's'), (2, 's')])
timestamp_qds = np.nan if source_timestamp_qds_df.empty else source_timestamp_qds_df.loc[0, 'timestamp']
i_dcct_df, i_didt_df, u_res_df, u_diff_df = query.query_qds_pm(timestamp_qds, timestamp_qds, signal_names=['I_DCCT', 'I_DIDT', 'U_RES', 'U_DIFF'])
# LEADS
leads_name = [x for x in SignalMetadata.get_system_types_per_circuit_name(circuit_type, circuit_name) if 'LEADS' in x][0]
source_timestamp_leads_df = query.find_timestamp_leads(timestamp_fgc, leads_name)
u_hts_dfs = query.query_leads(timestamp_fgc, source_timestamp_leads_df, system=leads_name, signal_names=['U_HTS'], spark=spark, duration=[(300, 's'), (900, 's')])
u_res_dfs = query.query_leads(timestamp_fgc, source_timestamp_leads_df, system=leads_name, signal_names=['U_RES'], spark=spark, duration=[(300, 's'), (900, 's')])
analysis = R600ACircuitAnalysis(circuit_type, results_table, is_automatic=is_automatic)
```
%% Cell type:markdown id: tags:
# 3. Timestamps
The analysis for MP3 consists of checking the existence of PM file and of consistency of the PM time stamps (PC, QPS, EE if applicable). The criterion of passing this test described in detail in 600APIC2.
In short the following criteria should be checked:
- 2 PM DQAMGNA (A+B) files and 1 PM EE file should be generated for 600 A circuits with EE
- Difference between QPS board A and B timestamp = 1 ms
- PC time stamp is QPS time stamp plus-minus 20 ms
- EE time stamp can be plus-minus 20 ms from the QPS time stamp.
If this is not the case, an in -depth analysis has to be performed by the QPS team.
%% Cell type:code id: tags:
``` python
timestamp_dct = {'FGC': timestamp_fgc, 'PIC': timestamp_pic,
'EE': source_timestamp_ee_df.loc[0, 'timestamp'] if len(source_timestamp_ee_df) > 0 else np.nan,
'QDS_A': source_timestamp_qds_df.loc[0, 'timestamp'] if len(source_timestamp_qds_df) > 0 else np.nan,
'QDS_B': source_timestamp_qds_df.loc[1, 'timestamp'] if len(source_timestamp_qds_df) > 1 else np.nan}
timestamp_table_df = analysis.create_timestamp_table(timestamp_dct, circuit_name)
timestamp_table_df
```
%% Cell type:markdown id: tags:
# 4. PC
## 4.1. Main Current
*QUERY*:
- PM for currents of the power converter, I_MEAS, I_A, I_REF
*INPUT*:
|Variable Name |Variable Type |Variable Unit |Comment
|---------------|---------------|---------------|------|
|circuit_type |str |- |Type of the analyzed circuit, e.g., '600A'|
|circuit_name |str |- |Name of the analyzed circuit, e.g., 'RQTL9.L7B2'|
|i_meas_df |DataFrame |A |Main current of the power converter, I_MEAS|
|i_ref_df |DataFrame |A |Main current of the power converter, I_REF|
|i_a_df |DataFrame |A |Main current of the power converter, I_A|
*ANALYSIS*:
- calculation of the ramp rate
- calculation of the duration of a plateau prior to a quench
- calculation of the quench current as the value of I_MEAS at FGC timestamp
- calculation of I_MEAS MIITs with the starting point based on deviation between I_A and I_REF
*PLOT*:
- currents of the power converter on the left axis, I_MEAS, I_REF, I_A
- zoom of the same plot around FGC timestamp, -0.25 s before and 1 s after
- t = 0 s corresponds to the FGC timestamp.
*OUTPUT*:
- *No output is generated*
%% Cell type:code id: tags:
``` python
t_quench = analysis.find_time_of_quench(i_ref_df, i_a_df)
analysis.plot_i_meas_pc(circuit_name, timestamp_fgc, i_meas_df, i_ref_df, i_a_df, xlim=(t_quench-0.1, t_quench+0.1))
analysis.plot_i_meas_pc_zoom(circuit_name, timestamp_fgc, t_quench, i_meas_df, i_ref_df, i_a_df, xlim=(t_quench-0.1, t_quench+0.1))
analysis.plot_i_meas_pc(circuit_name, timestamp_fgc, [i_meas_df, i_ref_df, i_a_df], xlim=(t_quench-0.1, t_quench+0.1))
analysis.plot_i_meas_pc_zoom(circuit_name, timestamp_fgc, t_quench, [i_meas_df, i_ref_df, i_a_df], xlim=(t_quench-0.1, t_quench+0.1))
analysis.analyze_i_meas_pc_trigger(timestamp_fgc, events_action_df, events_symbol_df)
analysis.calculate_current_miits(i_meas_df, t_quench)
analysis.calculate_quench_current(i_meas_df, t_quench)
analysis.calculate_current_slope(i_meas_df)
```
%% Cell type:markdown id: tags:
## 4.2. Earth Current
*QUERY*:
- PM for the earth current of power converter, I_EARTH
*INPUT*:
|Variable Name |Variable Type |Variable Unit |Comment
|---------------|---------------|---------------|------|
|circuit_type |str |- |Type of the analyzed circuit, e.g., '600A'|
|circuit_name |str |- |Name of the analyzed circuit, e.g., 'RQTL9.L7B2'|
|i_earth_df |DataFrame |A |Earth current of the power converter, I_EARTH|
*ANALYSIS*:
- calculation of the maximum earth current
*PLOT*:
- current of the power converter on the left axis, I_EARTH
- t = 0 s corresponds to the FGC timestamp.
*OUTPUT*:
- *No output is generated*
%% Cell type:code id: tags:
``` python
analysis.plot_i_earth_pc(circuit_name, timestamp_fgc, i_earth_df)
analysis.calculate_max_i_earth_pc(i_earth_df)
```
%% Cell type:markdown id: tags:
# 5. EE
## 5.1. Voltage
*QUERY*:
- PM for the voltage of energy extraction system, U_DUMP_RES
*INPUT*:
|Variable Name |Variable Type |Variable Unit |Comment
|---------------|---------------|---------------|------|
|circuit_type |str |- |Type of the analyzed circuit, e.g., '600A'|
|circuit_name |str |- |Name of the analyzed circuit, e.g., 'RQTL9.L7B2'|
|u_dump_res_df |DataFrame |V |Voltage of the energy extraction system, U_DUMP_RES|
*ANALYSIS*:
- calculation of the maximum voltage of energy extraction
*PLOT*:
- voltage of the energy extraction system on the left axis, U_DUMP_RES
- t = 0 s corresponds to the FGC timestamp.
*OUTPUT*:
- *No output is generated*
%% Cell type:code id: tags:
``` python
if 'EE' in SignalMetadata.get_system_types_per_circuit_name(circuit_type, circuit_name):
analysis.analyze_u_dump_res_ee(circuit_name, timestamp_fgc, i_meas_df, u_dump_res_df)
```
%% Cell type:markdown id: tags:
# 6. QDS
## 6.1. Resistive Voltage
*QUERY*:
- PM for the resistive voltage of magnets measured with QPS, U_RES
*INPUT*:
|Variable Name |Variable Type |Variable Unit |Comment
|---------------|---------------|---------------|------|
|circuit_type |str |- |Type of the analyzed circuit, e.g., '600A'|
|circuit_name |str |- |Name of the analyzed circuit, e.g., 'RQTL9.L7B2'|
|u_res_df |DataFrame |V |Resistive voltage of magnets measured with QPS, U_RES|
*ANALYSIS*:
- Initial voltage rise of U_RES signal, calculting by dividing the detection threshold voltage by the time it took for U_RES to rise to the threshold (from 50 to 250 mV).
- **Warning in case the slope of U_RES differs from history.**
- The quench voltage U_RES is calculated according to the following formula:
\begin{equation}
U_{\text{RES}} = U_{\text{DIFF}} + L d/dt (I+U_{\text{DIFF}}/R),
\end{equation}
where I = I_DCCT is heavily filtered over 1.3 s to make the calculation stable. It can be seen from the sign convention in Fig. 1 that a resistive voltage always has the opposite sign than the measured current. Note that I_DCCT is the QPS signal name, even though the current is actually measured not with a DCCT, but with a LEM detector, hence the poorer quality w.r.t. to the FGC I_A/B/MEAS signals that are measured with a DCCT.
*PLOT*:
- resistive voltage of magnets measured with QPS on the left axis, U_RES
- t = 0 s corresponds to the FGC timestamp.
*OUTPUT*:
- *No output is generated*
%% Cell type:code id: tags:
``` python
analysis.plot_u_res(circuit_name, timestamp_qds, u_res_nxcals_df)
u_res_slope_df = analysis.calculate_u_res_slope(u_res_df)
analysis.plot_u_res_slope(circuit_name, timestamp_qds, u_res_df, u_res_slope_df)
```
%% Cell type:markdown id: tags:
## 6.2. I_DCCT, I_DIDT Currents; U_RES, U_DIFF Voltages
*QUERY*:
- PM for the DC current leads of QPS, I_DCCT
- PM for the didt current leads of QPS, I_DIDT
- PM for the diffrential voltage of QPS, U_DIFF
- PM for the resistive voltage of QPS, U_REF
*INPUT*:
|Variable Name |Variable Type |Variable Unit |Comment
|---------------|---------------|---------------|------|
|circuit_type |str |- |Type of the analyzed circuit, e.g., '600A'|
|circuit_name |str |- |Name of the analyzed circuit, e.g., 'RQTL9.L7B2'|
|i_dcct_df |DataFrame |A |DC current leads of QPS, I_DCCT|
*ANALYSIS*:
- *No analysis is performed*
*PLOT*:
- current of the DC current leads of QPS on the left axis, I_DCCT
- didt current leads of QPS on the left axis, I_DIDT
- diffrential voltage of QPS on the right axis, U_DIFF
- resistive voltage of QPS on the right axis, U_RES
- t = 0 s corresponds to the QPS timestamp.
*OUTPUT*:
- *No output is generated*
%% Cell type:code id: tags:
``` python
analysis.analyze_qds(circuit_name, timestamp_qds, i_dcct_df, i_didt_df, u_diff_df, u_res_df)
```
%% Cell type:markdown id: tags:
# 7. LEADS
## 7.1. Plot of Current Leads
*QUERY*:
- PM for leads voltage, U_HTS, U_RES
*INPUT*:
|Variable Name |Variable Type |Variable Unit |Comment
|---------------|---------------|---------------|------|
|circuit_type |str |- |Type of the analyzed circuit, e.g., '600A'|
|circuit_name |str |- |Name of the analyzed circuit, e.g., 'RQTL9.L7B2'|
|u_leads_df |DataFrame |V |Leads voltage, U_HTS, U_RES|
*ANALYSIS*:
- quench detection for U_HTS for 2 consecutive datapoints above the threshold **(3 mV)**
- detection for U_RES for 2 consecutive datapoints above the threshold **(100 mV)**
*PLOT*:
- voltage of the normal conducting leads on the left axis, U_RES
- voltage of the HTS leads on the left axis, U_HTS
- t = 0 s corresponds to the LEADS timestamp.
*OUTPUT*:
- *No output is generated*
%% Cell type:code id: tags:
``` python
analysis.analyze_leads_voltage(u_hts_dfs, circuit_name, timestamp_fgc, signal='U_HTS', value_min=-0.003, value_max=0.003)
analysis.analyze_leads_voltage(u_res_dfs, circuit_name, timestamp_fgc, signal='U_RES', value_min=-0.1, value_max=0.1)
```
%% Cell type:markdown id: tags:
# 8. Final Report
## 8.1. Display Results Table
%% Cell type:code id: tags:
``` python
pd.set_option('display.max_columns', None)
analysis.results_table
```
%% Cell type:markdown id: tags:
## 8.2. Write Results Table to CSV
%% Cell type:code id: tags:
``` python
file_name = "{}-{}-PM_600A_with_without_EE_FPA".format(Time.to_datetime(timestamp_fgc).strftime("%Y.%m.%d_%H%M%S.%f"), analysis_start_time)
# Create folder for circuit_name
!mkdir -p /eos/project/l/lhcsm/operation/600A/$circuit_name
analysis.create_mp3_results_table().to_csv('/eos/project/l/lhcsm/operation/600A/{}/{}_mp3_results_table.csv'.format(circuit_name, file_name))
```
%% Cell type:markdown id: tags:
## 8.3. Display MP3 Quench Database Table
%% Cell type:code id: tags:
``` python
mp3_results_table = analysis.create_mp3_results_table()
mp3_results_table
```
%% Cell type:markdown id: tags:
## 8.4. Write MP3 Quench Database Table to CSV
%% Cell type:code id: tags:
``` python
mp3_results_table.to_csv('/eos/project/l/lhcsm/operation/600A/{}/{}_mp3_results_table.csv'.format(circuit_name, file_name))
```
%% Cell type:markdown id: tags:
## 8.5. Export Notebook as an HTML File
%% Cell type:code id: tags:
``` python
file_name_html = file_name + '_report.html'
!{sys.executable} -m jupyter nbconvert --to html $'AN_600A_with_without_EE_FPA.ipynb' --output /eos/project/l/lhcsm/operation/600A/$circuit_name/$file_name_html
```
......
%% Cell type:markdown id: tags:
<h1><center>Analysis of an FPA 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|
Nominal operating currents for 7 TeV of the three PC’s as given in the LHC design report volume I. For the nominal current during HWC see EDMS 1375861.
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
## 0.1. Import Necessary Packages
%% Cell type:code id: tags:
``` python
import io
import re
import sys
import pandas as pd
import numpy as np
from datetime import datetime
from lhcsmapi.Time import Time
from lhcsmapi.Timer import Timer
from lhcsmapi.pyedsl.QueryBuilder import QueryBuilder
from lhcsmapi.analysis.ItCircuitQuery import ItCircuitQuery
from lhcsmapi.analysis.ItCircuitAnalysis import ItCircuitAnalysis
# GUI
from lhcsmapi.gui.qh.DateTimeBaseModule import DateTimeBaseModule
from lhcsmapi.gui.pc.FgcPmSearchModuleMediator import FgcPmSearchModuleMediator
from lhcsmapi.gui.pc.ItFgcPmSearchBaseModule import ItFgcPmSearchBaseModule
analysis_start_time = datetime.now().strftime("%Y.%m.%d_%H%M%S.%f")
```
%% Cell type:markdown id: tags:
## 0.2. LHCSMAPI Version
%% Cell type:code id: tags:
``` python
import lhcsmapi
print('Analysis executed with lhcsmapi version: {}'.format(lhcsmapi.__version__))
```
%% Cell type:markdown id: tags:
## 0.3. Notebook Version
%% Cell type:code id: tags:
``` python
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 FGC Post Mortem Entry
%% Cell type:code id: tags:
``` python
circuit_type = 'IT'
fgc_pm_search = FgcPmSearchModuleMediator(DateTimeBaseModule(start_date_time='2018-08-29 00:00:00+01:00',
end_date_time='2018-08-31 00:00:00+01:00'), ItFgcPmSearchBaseModule(), circuit_type=circuit_type)
display(fgc_pm_search.widget)
```
%% Cell type:markdown id: tags:
# 2. Query All Signals Prior to Analysis
%% Cell type:code id: tags:
``` python
circuit_name = fgc_pm_search.get_circuit_name()
timestamp_fgc = fgc_pm_search.get_fgc_timestamp()
author = fgc_pm_search.get_author()
is_automatic = fgc_pm_search.is_automatic_mode()
it_query = ItCircuitQuery(circuit_type, circuit_name)
with Timer():
# PIC
timestamp_pic = it_query.find_timestamp_pic(timestamp_fgc, spark=spark)
# PC
source_timestamp_fgc_df = QueryBuilder().with_pm() \
.with_duration(t_start=timestamp_fgc, duration=[(1, 's'), (1, 's')]) \
.with_circuit_type(circuit_type) \
.with_metadata(circuit_name=circuit_name, system='PC', source='*') \
.event_query().df
source_fgc_rqx, timestamp_fgc_rqx = it_query.split_source_timestamp_fgc(source_timestamp_fgc_df, 'RQX')
source_fgc_rtqx1, timestamp_fgc_rtqx1 = it_query.split_source_timestamp_fgc(source_timestamp_fgc_df, 'RTQX1')
source_fgc_rtqx2, timestamp_fgc_rtqx2 = it_query.split_source_timestamp_fgc(source_timestamp_fgc_df, 'RTQX2')
i_meas_rqx_df, i_ref_rqx_df, i_a_rqx_df, i_earth_rqx_df = it_query.query_pc_pm_with_source(timestamp_fgc_rqx, timestamp_fgc_rqx,
source_fgc_rqx, signal_names=['I_MEAS', 'I_REF', 'I_A', 'I_EARTH'])
i_meas_rtqx1_df, i_ref_rtqx1_df, i_a_rtqx1_df, i_earth_rtqx1_df = it_query.query_pc_pm_with_source(timestamp_fgc_rtqx1, timestamp_fgc_rtqx1,
source_fgc_rtqx1, signal_names=['I_MEAS', 'I_REF', 'I_A', 'I_EARTH'])
i_meas_rtqx2_df, i_ref_rtqx2_df, i_a_rtqx2_df, i_earth_rtqx2_df = it_query.query_pc_pm_with_source(timestamp_fgc_rtqx2, timestamp_fgc_rtqx2,
source_fgc_rtqx2, signal_names=['I_MEAS', 'I_REF', 'I_A', 'I_EARTH'])
i_meas_q1_df = pd.DataFrame(index=i_meas_rqx_df.index, data=i_meas_rqx_df.values + i_meas_rtqx1_df.values, columns=['I_MEAS_Q1'])
i_meas_q2_df = pd.DataFrame(index=i_meas_rqx_df.index, data=i_meas_rqx_df.values + i_meas_rtqx2_df.values, columns=['I_MEAS_Q2'])
i_meas_q3_df = pd.DataFrame(index=i_meas_rqx_df.index, data=i_meas_rqx_df.values, columns=['I_MEAS_Q3'])
# QDS
source_timestamp_qds_df = it_query.find_source_timestamp_qds(timestamp_fgc_rqx, duration=[(2, 's'), (2, 's')])
timestamp_qds = np.nan if source_timestamp_qds_df.empty else source_timestamp_qds_df.loc[0, 'timestamp']
u_res_q1_df, u_res_q2_df, u_res_q3_df = it_query.query_qds_pm(timestamp_qds, timestamp_qds, signal_names=['U_RES_Q1', 'U_RES_Q2', 'U_RES_Q3'])
u_1_q1_df, u_1_q2_df, u_1_q3_df = it_query.query_qds_pm(timestamp_qds, timestamp_qds, signal_names=['U_1_Q1', 'U_1_Q2', 'U_1_Q3'])
u_2_q1_df, u_2_q2_df, u_2_q3_df = it_query.query_qds_pm(timestamp_qds, timestamp_qds, signal_names=['U_2_Q1', 'U_2_Q2', 'U_2_Q3'])
# QH
u_hds_dfss = it_query.query_qh_pm(source_timestamp_qds_df, signal_names=['U_HDS'])
u_hds_dfs = u_hds_dfss[0] if u_hds_dfss else []
# # Reference
u_hds_ref_dfss = it_query.query_qh_pm(source_timestamp_qds_df, signal_names=['U_HDS'], is_ref=True)
u_hds_ref_dfs = u_hds_ref_dfss[0] if u_hds_ref_dfss else []
# LEADS
u_hts_dfs = it_query.query_leads(timestamp_fgc, source_timestamp_qds_df, system='LEADS', signal_names=['U_HTS'], spark=spark, duration=[(300, 's'), (900, 's')])
u_res_dfs = it_query.query_leads(timestamp_fgc, source_timestamp_qds_df, system='LEADS', signal_names=['U_RES'], spark=spark, duration=[(300, 's'), (900, 's')])
# Results Table
results_table = it_query.create_report_analysis_template(timestamp_fgc=timestamp_fgc, author=author)
it_analysis = ItCircuitAnalysis(circuit_type, results_table, is_automatic=is_automatic)
```
%% Cell type:markdown id: tags:
# 3. Timestamps
The PC time stamp (51_self) is QPS time stamp +-20 ms. The difference between QPS board A and B timestamp = 1ms.
%% Cell type:code id: tags:
``` python
timestamp_dct = {'FGC_RQX': timestamp_fgc_rqx, 'FGC_RTQX1': timestamp_fgc_rtqx1, 'FGC_RTQX2': timestamp_fgc_rtqx2,
'PIC': timestamp_pic,
'QDS_A':source_timestamp_qds_df.loc[0, 'timestamp'] if len(source_timestamp_qds_df) > 0 else np.nan,
'QDS_B':source_timestamp_qds_df.loc[1, 'timestamp'] if len(source_timestamp_qds_df) > 1 else np.nan}
it_analysis.create_timestamp_table(timestamp_dct)
```
%% Cell type:markdown id: tags:
# 4. PC
## 4.1. Main Current
*QUERY*:
- PM for the power converter currents, I_MEAS, I_A, I_REF
*INPUT*:
|Variable Name |Variable Type |Variable Unit |Comment
|---------------|---------------|---------------|------|
|circuit_type |str |- |Type of the analyzed circuit, 'IT|
|circuit_name |str |- |Name of the analyzed circuit, e.g., 'RQX.R1'|
|i_meas_rqx_df |DataFrame |A |Main current of the RQX power converter, I_MEAS_RQX|
|i_meas_rtqx1_df |DataFrame |A |Main current of the RTQX1 power converter, I_MEAS_RTQX1|
|i_meas_rtqx2_df |DataFrame |A |Main current of the RTQX2 power converter, I_MEAS_RTQX2|
|i_a_rqx_df |DataFrame |A |Actual current of the RQX power converter, I_A_RQX|
|i_a_rtqx1_df |DataFrame |A |Actual current of the RTQX1 power converter, I_A_RTQX1|
|i_a_rtqx2_df |DataFrame |A |Actual current of the RTQX2 power converter, I_A_RTQX2|
|i_ref_rqx_df |DataFrame |A |Reference current of the RQX power converter, I_REF_RQX|
|i_ref_rtqx1_df |DataFrame |A |Reference current of the RTQX1 power converter, I_REF_RTQX1|
|i_ref_rtqx2_df |DataFrame |A |Reference current of the RTQX2 power converter, I_REF_RTQX2|
*ANALYSIS*:
- calculation of the ramp rate
- calculation of the duration of a plateau prior to a quench
- calculation of DCCT MIIts
*PLOT*:
- current of the power converter on the left axis, I_MEAS, I_A, I_REF
- t = 0 s corresponds to the FGC timestamp
- one plot for each power converter
*OUTPUT*:
- *No output is generated*
%% Cell type:code id: tags:
``` python
it_analysis.plot_i_meas_pc(circuit_name, timestamp_fgc_rqx, i_meas_rqx_df, i_ref_rqx_df, i_meas_rtqx1_df, i_ref_rtqx1_df, i_meas_rtqx2_df, i_ref_rtqx2_df, xlim=(-0.1, 0.5))
it_analysis.plot_i_meas_pc(circuit_name, timestamp_fgc_rqx, [i_meas_rqx_df, i_ref_rqx_df, i_meas_rtqx1_df, i_ref_rtqx1_df, i_meas_rtqx2_df, i_ref_rtqx2_df], xlim=(-0.1, 0.5))
```
%% Cell type:code id: tags:
``` python
t_quench = it_analysis.find_time_of_quench(i_ref_rqx_df)
it_analysis.plot_i_meas_pc(circuit_name, timestamp_fgc_rqx, i_meas_rqx_df, i_ref_rqx_df, i_a_rqx_df,
it_analysis.plot_i_meas_pc(circuit_name, timestamp_fgc_rqx, [i_meas_rqx_df, i_ref_rqx_df, i_a_rqx_df],
xlim=(-0.1, 0.2), ylim=(i_meas_rqx_df.max().values[0]-1500, i_meas_rqx_df.max().values[0]+500))
it_analysis.calculate_current_slope(i_meas_rqx_df.rename(columns={'STATUS.I_MEAS_RQX': 'STATUS.I_MEAS'}))
it_analysis.calculate_current_miits(i_meas_rqx_df, t_quench, col_name='MITTs_DCCT_RQX')
it_analysis.calculate_quench_current(i_meas_rqx_df, t_quench, col_name='I_RQX')
```
%% Cell type:code id: tags:
``` python
it_analysis.plot_i_meas_pc(circuit_name.replace('RQX', 'RTQX1'), timestamp_fgc_rqx, i_meas_rtqx1_df, i_ref_rtqx1_df, i_a_rtqx1_df,
it_analysis.plot_i_meas_pc(circuit_name.replace('RQX', 'RTQX1'), timestamp_fgc_rqx, [i_meas_rtqx1_df, i_ref_rtqx1_df, i_a_rtqx1_df],
xlim=(-0.1, 0.2), ylim=(i_meas_rtqx1_df.max().values[0] - 250, i_meas_rtqx1_df.max().values[0] + 250))
it_analysis.calculate_current_slope(i_meas_rtqx1_df.rename(columns={'STATUS.I_MEAS_RTQX1': 'STATUS.I_MEAS'}))
it_analysis.calculate_current_miits(i_meas_rtqx1_df, t_quench, col_name='MITTs_DCCT_RTQX1')
it_analysis.calculate_quench_current(i_meas_rtqx1_df, t_quench, col_name='I_RTQX1')
```
%% Cell type:code id: tags:
``` python
it_analysis.plot_i_meas_pc(circuit_name.replace('RQX', 'RTQX2'), timestamp_fgc_rqx, i_meas_rtqx2_df, i_ref_rtqx2_df, i_a_rtqx2_df,
it_analysis.plot_i_meas_pc(circuit_name.replace('RQX', 'RTQX2'), timestamp_fgc_rqx, [i_meas_rtqx2_df, i_ref_rtqx2_df, i_a_rtqx2_df],