Skip to content
Snippets Groups Projects

[SIGMON-620] fix pic2 mi notebook

Merged [SIGMON-620] fix pic2 mi notebook
1 unresolved thread
Merged Simon Mazenoux requested to merge SIGMON-620_fix_PIC2_MI_notebook into dev
1 unresolved thread
1 file
+ 4
5
Compare changes
  • Side-by-side
  • Inline
+ 4
5
%% Cell type:markdown id: tags:
# IPQ: PIC2 CIRCUIT QUENCH VIA QPS (MI Analysis Notebook)
```java
public class PicPowerConverterCheckForB2TypeAfterFPA extends AnalysisModule { {
assertThat(ST_FAULTS.from(B1)).forBit(FAST_ABORT).changesOnceTo(true).starting(20, MILLI(SECOND))
.before(PM_EVENT_TRIGGER).ending(40, MILLI(SECOND)).after(PM_EVENT_TRIGGER);
assertThat(ST_UNLATCHED.from(B1)).forBit(PC_DISCH_RQ).isEqualTo(false).starting(20, MILLI(SECOND))
.before(PM_EVENT_TRIGGER).ending(40, MILLI(SECOND)).after(PM_EVENT_TRIGGER);
assertThat(ST_UNLATCHED.from(B1)).forBit(PC_PERMIT).changesOnceTo(false).starting(30, MILLI(SECOND))
.before(PM_EVENT_TRIGGER).ending(40, MILLI(SECOND)).after(PM_EVENT_TRIGGER);
assertThat(ST_FAULTS.from(B2)).forBit(FAST_ABORT).changesOnceTo(true).starting(20, MILLI(SECOND))
.before(PM_EVENT_TRIGGER).ending(40, MILLI(SECOND)).after(PM_EVENT_TRIGGER);
assertThat(ST_UNLATCHED.from(B2)).forBit(PC_DISCH_RQ).isEqualTo(false).starting(20, MILLI(SECOND))
.before(PM_EVENT_TRIGGER).ending(40, MILLI(SECOND)).after(PM_EVENT_TRIGGER);
assertThat(ST_UNLATCHED.from(B2)).forBit(PC_PERMIT).changesOnceTo(false).starting(30, MILLI(SECOND))
.before(PM_EVENT_TRIGGER).ending(40, MILLI(SECOND)).after(PM_EVENT_TRIGGER);
}
} public class PicQuenchViaQpsForB2TypeCircuits extends PicPowerConverterCheckForB2TypeAfterFPA { {
TimeRange cmdPowerPermitchange1 = detectWhere(CMD_POWER_PERMIT_B1_PIC).changesOnceTo(false)
.starting(40, MILLI(SECOND)).before(PM_EVENT_TRIGGER).ending(40, MILLI(SECOND)).after(PM_EVENT_TRIGGER);
TimeRange cmdPowerPermitchange2 = detectWhere(CMD_POWER_PERMIT_B2_PIC).changesOnceTo(false)
.starting(40, MILLI(SECOND)).before(PM_EVENT_TRIGGER).ending(40, MILLI(SECOND)).after(PM_EVENT_TRIGGER);
{
assertThat(ST_ABORT_PIC).changesOnceTo(false).starting(2, MILLI(SECOND))
.before(startOf(cmdPowerPermitchange1)).endingAt(startOf(cmdPowerPermitchange1));
assertThat(CMD_ABORT_PIC).changesTo(false).starting(1, MICRO(SECOND))
.before(startOf(cmdPowerPermitchange1)).ending(1, MICRO(SECOND))
.after(startOf(cmdPowerPermitchange1));
assertThat(ST_ABORT_PIC).changesOnceTo(false).starting(2, MILLI(SECOND))
.before(startOf(cmdPowerPermitchange2)).endingAt(startOf(cmdPowerPermitchange2));
assertThat(CMD_ABORT_PIC).changesTo(false).starting(1, MICRO(SECOND))
.before(startOf(cmdPowerPermitchange2)).ending(1, MICRO(SECOND))
.after(startOf(cmdPowerPermitchange2));
// Worldfip cycle is 200ms. QPS signals can take up to 2 cycles...
assertThat(stat_CIRCUIT_ST_CIRCUIT_OK_QPS_META.from(QpsBoardBufferSource.BOARD_A)).changesTo(false)
.starting(1, MILLI(SECOND)).before(startOf(cmdPowerPermitchange1)).ending(600, MILLI(SECOND))
.after(startOf(cmdPowerPermitchange1));
assertThat(stat_CIRCUIT_ST_CIRCUIT_OK_QPS_META.from(QpsBoardBufferSource.BOARD_B)).changesTo(false)
.starting(1, MILLI(SECOND)).before(startOf(cmdPowerPermitchange1)).ending(600, MILLI(SECOND))
.after(startOf(cmdPowerPermitchange1));
assertThat(stat_CIRCUIT_ST_CIRCUIT_OK_QPS_META.from(QpsBoardBufferSource.BOARD_A)).changesTo(false)
.starting(1, MILLI(SECOND)).before(startOf(cmdPowerPermitchange2)).ending(600, MILLI(SECOND))
.after(startOf(cmdPowerPermitchange2));
assertThat(stat_CIRCUIT_ST_CIRCUIT_OK_QPS_META.from(QpsBoardBufferSource.BOARD_B)).changesTo(false)
.starting(1, MILLI(SECOND)).before(startOf(cmdPowerPermitchange2)).ending(600, MILLI(SECOND))
.after(startOf(cmdPowerPermitchange2));
}}}
```
%% Cell type:code id: tags:
``` python
import getpass
import logging
import sys
from matplotlib import pyplot as plt
import pandas as pd
import numpy as np
from IPython.display import display, Javascript, clear_output
import lhcsmapi
from lhcsmapi.Time import Time
from lhcsmapi.api.analysis import powering
from lhcsmapi.api.analysis.powering import pic2
from lhcsmapi.analysis.expert_input import get_expert_decision
%xmode Minimal
logging.getLogger().setLevel(logging.INFO)
logging.getLogger().addHandler(logging.StreamHandler(sys.stdout))
clear_output()
print(f"Analysis executed with lhc-sm-api version: {lhcsmapi.__version__}")
print(f"Analysis performed by {getpass.getuser()}")
```
%% Cell type:code id: tags:
``` python
if "spark" not in locals() and "spark" not in globals():
from nxcals.spark_session_builder import get_or_create
spark = get_or_create()
```
%% Cell type:markdown id: tags:
## User Input
Copy/Paste from AccTesting
%% Cell type:code id: tags:
``` python
# hwc_test = "PIC2 CIRCUIT QUENCH VIA QPS"
# circuit_name = "RQ5.L8"
# campaign = "Commissioning post ITL8"
# t_start = "2023-08-25 07:31:10.073000000"
# t_end = "2023-08-25 08:03:33.250000000"
```
%% Cell type:code id: tags:
``` python
test_parameters = powering.TestParameterInput.create(hwc_test, circuit_name, campaign, t_start, t_end)
test_parameters
```
%% Cell type:markdown id: tags:
## Query and Analyse
%% Cell type:code id: tags:
``` python
analysis_class = pic2.Pic2CircuitQuenchViaQpsForIPQAnalysisMI("pic2", test_parameters)
analysis_class.set_spark(spark)
```
%% Cell type:code id: tags:
``` python
%%time
analysis_class.query()
```
%% Cell type:code id: tags:
``` python
%%time
analysis_class.analyze()
```
%% Cell type:markdown id: tags:
# Overall Result
%% Cell type:code id: tags:
``` python
%xmode Verbose
print(f"The Overall Analysis output is \033[1m{analysis_class.get_analysis_output()}\033[0m")
```
%% Cell type:markdown id: tags:
## Analyses of PC signals from FGC PMs
%% Cell type:code id: tags:
``` python
%matplotlib inline
# To display plots dynamically run the following line (don't forget to put again inline and run the cell again for the plot to appear in the report)
# %matplotlib widget
st_unlatched_b1_df: pd.DataFrame = analysis_class.get_result("st_unlatched_b1_df").copy()
st_unlatched_b1_df.index = st_unlatched_b1_df.index * 1e-9
st_unlatched_b2_df: pd.DataFrame = analysis_class.get_result("st_unlatched_b2_df").copy()
st_unlatched_b2_df.index = st_unlatched_b2_df.index * 1e-9
st_faults_b1_df: pd.DataFrame = analysis_class.get_result("st_faults_b1_df").copy()
st_faults_b1_df.index = st_faults_b1_df.index * 1e-9
st_faults_b2_df: pd.DataFrame = analysis_class.get_result("st_faults_b2_df").copy()
st_faults_b2_df.index = st_faults_b2_df.index * 1e-9
pm_event_trigger: int = analysis_class.get_result("pm_event_trigger")
pm_event_trigger_sync: int = analysis_class.get_result("pm_event_trigger_sync")
fast_abort_timeslot = powering.pic2.Pic2CircuitQuenchViaQpsForIPQAnalysisMI._FGC_FAST_ABORT_TIMESLOT
fig = plt.figure(figsize=(12, 6))
gs = fig.add_gridspec(6, hspace=0)
axs: list[plt.Axes] = gs.subplots(sharex=True, sharey=True)
fig.suptitle(
f"{circuit_name}, PC Status Signal Analysis (FC PM), PM Event: {Time.to_string_short(pm_event_trigger)}",
fontsize=18,
)
fig.supxlabel("time, [s]", fontsize=12)
fig.supylabel("State (True/False)", fontsize=12)
for ax, df, columm, beam in (
(axs[0], st_faults_b1_df, "FAST_ABORT", "B1"),
(axs[1], st_faults_b2_df, "FAST_ABORT", "B2"),
(axs[2], st_unlatched_b1_df, "PC_PERMIT", "B1"),
(axs[3], st_unlatched_b2_df, "PC_PERMIT", "B2"),
(axs[4], st_unlatched_b1_df, "PC_DISCH_RQ", "B1"),
(axs[5], st_unlatched_b2_df, "PC_DISCH_RQ", "B2"),
):
df[columm].astype(int).plot(ax=ax)
ax.legend([f"{columm}_{beam}"], loc="center left")
# set linestyle to steps-post
for line in ax.get_lines():
line.set_marker("o")
line.set_drawstyle("steps-post")
ax.set_xlim(-0.050, +0.050)
ax.set_ylim(-0.3, +1.3)
ax.set_xticks(np.arange(ax.get_xlim()[0], ax.get_xlim()[1], 0.010))
ax.set_xticks(np.arange(ax.get_xlim()[0], ax.get_xlim()[1]), minor=True)
ax.grid(which="major", alpha=0.5)
ax.grid(which="minor", alpha=0.2)
ax.axvline(x=pm_event_trigger_sync, color="green", linestyle="--", linewidth=2.0)
ax.axvline(
x=pm_event_trigger_sync - fast_abort_timeslot[0] * 1e-9,
color="red",
linestyle="--",
linewidth=1.0,
)
ax.axvline(
x=pm_event_trigger_sync + fast_abort_timeslot[1] * 1e-9,
color="red",
linestyle="--",
linewidth=1.0,
)
plt.yticks([1.0, 0.0], ["True", "False"])
plt.show()
print(f"PC signals checks: {analysis_class.get_result('pc_signal_checks')}")
```
%% Cell type:markdown id: tags:
## Analyses of PIC signals from NXCALS
%% Cell type:code id: tags:
``` python
%matplotlib inline
# To display plots dynamically run the following line (don't forget to put again inline and run the cell again for the plot to appear in the report)
# %matplotlib widget
st_abort_pic_df: pd.DataFrame = analysis_class.get_result("st_abort_pic_df").copy()
st_abort_pic_df.index = st_abort_pic_df.index * 1e-9
cmd_abort_pic_df: pd.DataFrame = analysis_class.get_result("cmd_abort_pic_df").copy()
cmd_abort_pic_df.index = cmd_abort_pic_df.index * 1e-9
cmd_pwr_perm_b1_pic_df: pd.DataFrame = analysis_class.get_result("cmd_pwr_perm_b1_pic_df").copy()
cmd_pwr_perm_b1_pic_df.index = cmd_pwr_perm_b1_pic_df.index * 1e-9
cmd_pwr_perm_b2_pic_df: pd.DataFrame = analysis_class.get_result("cmd_pwr_perm_b2_pic_df").copy()
cmd_pwr_perm_b2_pic_df.index = cmd_pwr_perm_b2_pic_df.index * 1e-9
pm_event_trigger: int = analysis_class.get_result("pm_event_trigger")
fig = plt.figure(figsize=(12, 4))
gs = fig.add_gridspec(4, hspace=0)
axs: list[plt.Axes] = gs.subplots(sharex=True, sharey=True)
fig.suptitle(
f"{circuit_name}, PIC Signal Analysis (NXCALS), PM Event: {Time.to_string_short(pm_event_trigger)}", fontsize=18
)
fig.supxlabel("Time, [s]", fontsize=12)
fig.supylabel("State", fontsize=12)
st_abort_pic_df.plot(ax=axs[0])
cmd_abort_pic_df.plot(ax=axs[1])
cmd_pwr_perm_b1_pic_df.plot(ax=axs[2])
cmd_pwr_perm_b2_pic_df.plot(ax=axs[3])
st_abort_pic_df.astype(int).plot(ax=axs[0])
cmd_abort_pic_df.astype(int).plot(ax=axs[1])
cmd_pwr_perm_b1_pic_df.astype(int).plot(ax=axs[2])
cmd_pwr_perm_b2_pic_df.astype(int).plot(ax=axs[3])
for ax in axs:
# set linestyle to steps-post
for line in ax.get_lines():
line.set_marker("o")
line.set_drawstyle("steps-post")
ax.set_xlim(-0.050, +0.050)
ax.set_ylim(-0.3, +1.3)
ax.set_xticks(np.arange(ax.get_xlim()[0], ax.get_xlim()[1], 0.010))
ax.set_xticks(np.arange(ax.get_xlim()[0], ax.get_xlim()[1], 0.001), minor=True)
ax.grid(which="major", alpha=0.5)
ax.grid(which="minor", alpha=0.2)
ax.axvline(x=pm_event_trigger_sync, color="green", linestyle="--", linewidth=2.0)
plt.yticks([1.0, 0.0], ["True", "False"])
plt.show()
print(f"PIC signals checks: {analysis_class.get_result('pic_signals_checks')}")
```
%% Cell type:markdown id: tags:
## Analyses of QPS_OK signals from QDS PMs
%% Cell type:code id: tags:
``` python
%matplotlib inline
# To display plots dynamically run the following line (don't forget to put again inline and run the cell again for the plot to appear in the report)
# %matplotlib widget
st_circuit_ok_qps_a_df: pd.DataFrame = analysis_class.get_result("st_circuit_ok_qps_a_df").copy()
st_circuit_ok_qps_a_df.index = st_circuit_ok_qps_a_df.index * 1e-9
st_circuit_ok_qps_b_df: pd.DataFrame = analysis_class.get_result("st_circuit_ok_qps_b_df").copy()
st_circuit_ok_qps_b_df.index = st_circuit_ok_qps_b_df.index * 1e-9
cmd_pwr_perm_b1_pic_df: pd.DataFrame = analysis_class.get_result("cmd_pwr_perm_b1_pic_df").copy()
cmd_pwr_perm_b1_pic_df.index = cmd_pwr_perm_b1_pic_df.index * 1e-9
cmd_pwr_perm_b2_pic_df: pd.DataFrame = analysis_class.get_result("cmd_pwr_perm_b2_pic_df").copy()
cmd_pwr_perm_b2_pic_df.index = cmd_pwr_perm_b2_pic_df.index * 1e-9
pm_event_trigger: int = analysis_class.get_result("pm_event_trigger")
fig = plt.figure(figsize=(12, 4))
gs = fig.add_gridspec(4, hspace=0)
axs: list[plt.Axes] = gs.subplots(sharex=True, sharey=True)
fig.suptitle(
f"{circuit_name}, QPS_OK Signal Analysis (QDS PM), PM Event: {Time.to_string_short(pm_event_trigger)}", fontsize=18
)
fig.supxlabel("Time, [s]", fontsize=12)
fig.supylabel("State", fontsize=12)
cmd_pwr_perm_b1_pic_df.astype(int).plot(ax=axs[0])
cmd_pwr_perm_b2_pic_df.astype(int).plot(ax=axs[1])
st_circuit_ok_qps_a_df.astype(int).plot(ax=axs[2])
st_circuit_ok_qps_b_df.astype(int).plot(ax=axs[3])
for ax in axs:
for line in ax.get_lines():
line.set_marker("o")
line.set_drawstyle("steps-post")
ax.set_xlim(-0.30, +0.80)
ax.set_ylim(-0.3, +1.3)
ax.grid(which="major", alpha=0.5)
ax.grid(which="minor", alpha=0.2)
ax.axvline(x=pm_event_trigger_sync, color="green", linestyle="--", linewidth=2.0)
ax.set_xticks(np.arange(ax.get_xlim()[0], ax.get_xlim()[1], 0.10))
ax.set_xticks(np.arange(ax.get_xlim()[0], ax.get_xlim()[1], 0.01), minor=True)
plt.yticks([1.0, 0.0], ["True", "False"])
plt.show()
print(f"QDS signals checks: {analysis_class.get_result('qds_signals_checks')}")
```
%% Cell type:markdown id: tags:
# Acceptance Decision
%% Cell type:code id: tags:
``` python
signature = get_expert_decision("Expert Signature Decision: ", ["PASSED", "FAILED"])
```
%% Cell type:markdown id: tags:
# Final Report
%% Cell type:code id: tags:
``` python
path_to_notebook = "./AN_IPQ_PIC2_MI.ipynb"
report_destination_path_template = "/eos/project/m/mp3/IPQ/{}/{}/{}" # prefix, circuit_name, hwc_test
report_filename_template = "{}_{}_MI-{}-{}_{}" # circuit_name, hwc_test, t_start, analysis_time, signature
#
analysis_start_time = Time.get_analysis_start_time()
prefix_circuit_name = circuit_name.split(".")[0]
hwc_test = hwc_test.split(" ")[0]
#
report_destination_path = report_destination_path_template.format(prefix_circuit_name, circuit_name, hwc_test)
report_filename = report_filename_template.format(
circuit_name,
hwc_test,
Time.to_datetime(t_start).strftime("%Y-%m-%d-%Hh%M"),
analysis_start_time,
signature,
)
#
!mkdir -p $report_destination_path
html_filename = f"{report_filename}.html"
html_path = f"{report_destination_path}/{report_filename}.html"
print("Compact notebook report saved to (Windows): " + "\\\\eosproject-smb" + html_path.replace("/", "\\"))
display(Javascript("IPython.notebook.save_notebook();"))
Time.sleep(5)
!{sys.executable} -m jupyter nbconvert --to html $path_to_notebook --output-dir $report_destination_path --output $html_filename --TemplateExporter.exclude_input=True --TagRemovePreprocessor.remove_all_outputs_tags skip_output
```
%% Cell type:markdown id: tags:
## Additional plots and analyses by MI-experts (optional)
%% Cell type:code id: tags:
``` python
# copy/paste here?
```
Loading