diff --git a/ipd/AN_IPD_PIC2.ipynb b/ipd/AN_IPD_PIC2.ipynb index 1035a4d4e55b24df0c197b8b6090f080b366a88d..f862fc15de1cf28c0c208f90c66d7f539e1f92ca 100644 --- a/ipd/AN_IPD_PIC2.ipynb +++ b/ipd/AN_IPD_PIC2.ipynb @@ -5,7 +5,21 @@ "id": "53016448", "metadata": {}, "source": [ - "# PIC2 IPD" + "# IPD: PIC2 CIRCUIT QUENCH VIA QPS (MP3 Analysis Notebook)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ce1d9aa3", + "metadata": {}, + "outputs": [], + "source": [ + "from IPython.display import display, Markdown, HTML\n", + "import importlib.resources\n", + "with open(importlib.resources.files('lhcsmapi.api.analysis.powering.pic2') / 'README.md', 'r') as f:\n", + " long_description = f.read()\n", + "display(Markdown(long_description))" ] }, { @@ -15,70 +29,120 @@ "metadata": {}, "outputs": [], "source": [ + "import getpass\n", + "import logging\n", "import sys\n", + "\n", + "from matplotlib import pyplot as plt\n", + "import pandas as pd\n", + "from IPython.display import display, Javascript, clear_output\n", + "\n", + "import lhcsmapi\n", + "from lhcsmapi.Time import Time\n", "from lhcsmapi.api.analysis import powering\n", - "from lhcsmapi.api.analysis.powering import pic2\n", - "# from nxcals.spark_session_builder import get_or_create\n", "from lhcsmapi.api.analysis.output.qh import quench_heater_voltage_output as qh_output\n", + "from lhcsmapi.api.analysis.output.powering import create_timestamp_table\n", + "from lhcsmapi.api.analysis.powering import pic2\n", + "from lhcsmapi.metadata import signal_metadata\n", + "from lhcsmapi.analysis.expert_input import get_expert_decision\n", "from lhcsmnb import utils as notebook_utils\n", "\n", - "import logging\n", + "%xmode Minimal\n", "logging.getLogger().setLevel(logging.INFO)\n", - "logging.getLogger().addHandler(logging.StreamHandler(sys.stdout))" + "logging.getLogger().addHandler(logging.StreamHandler(sys.stdout))\n", + "\n", + "clear_output()\n", + "print(f'Analysis executed with lhc-sm-api version: {lhcsmapi.__version__}')\n", + "print(f'Analysis performed by {getpass.getuser()}')" ] }, { "cell_type": "code", "execution_count": null, - "id": "23f44c09", + "id": "97daea54", + "metadata": {}, + "outputs": [], + "source": [ + "if 'spark' not in locals() and 'spark' not in globals():\n", + " from nxcals.spark_session_builder import get_or_create, Flavor\n", + " spark = get_or_create(flavor=Flavor.YARN_LARGE)" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "id": "a4b1ee38", "metadata": {}, + "source": [ + "# User Input\n", + "Copy/Paste from AccTesting" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "78334274", + "metadata": { + "tags": [] + }, "outputs": [], "source": [ - "hwc_test = 'PIC2 CIRCUIT QUENCH VIA QPS'\n", - "circuit_name = 'RD2.L1'\n", - "campaign = 'Recommissioning 2022/2023'\n", - "t_start = '2023-03-17 20:38:55.008000000'\n", - "t_end = '2023-03-17 21:13:35.949000000'" + "# hwc_test = 'PIC2 CIRCUIT QUENCH VIA QPS'\n", + "# circuit_name = 'RD2.L1'\n", + "# campaign = 'Recommissioning 2022/2023'\n", + "# t_start = '2023-03-17 20:38:55.008000000'\n", + "# t_end = '2023-03-17 21:13:35.949000000'" ] }, { "cell_type": "code", "execution_count": null, - "id": "d5ac3465", + "id": "61abbe7c", "metadata": {}, "outputs": [], "source": [ - "print('hwc_test = \\'%s\\'\\ncircuit_name = \\'%s\\'\\ncampaign = \\'%s\\'\\nt_start = \\'%s\\'\\nt_end = \\'%s\\'' % (hwc_test, circuit_name, campaign, t_start, t_end))" + "test_parameters = powering.TestParameterInput.create(hwc_test, circuit_name, campaign, t_start, t_end)\n", + "test_parameters" ] }, { "cell_type": "markdown", - "id": "7b37695e", + "id": "b7becfe5", "metadata": {}, "source": [ - "# Query and Analyse" + "# Acceptance criteria" ] }, { "cell_type": "code", "execution_count": null, - "id": "02af0ee8", + "id": "37588249", "metadata": {}, "outputs": [], "source": [ - "input_ = powering.TestParameterInput.create(hwc_test, circuit_name, campaign, t_start, t_end)" + "print(f\"Expected PM & PIC time window = {(pic2._EXPECTED_PM_WINDOW_IN_NANOS*1e-6):n} ms\")\n", + "print(f\"QPS A&B PM time difference = {(pic2._QPS_A_B_DIFF_IN_NANOS*1e-6):n} ms\")\n", + "print(f\"QDS Current Lead quench detection level = {(pic2._MIN_QUENCH_DETECTION_LEVEL_VOLTAGE*1e+3):n} mV\")\n", + "print(f\"QDS Quench detection window w.r.t. FGC time = {(pic2._QUENCH_DETECTION_WINDOW_WITH_RESPECT_TO_FGC_IN_S*1e+3):n} ms\")\n", + "print(\"+QH discharge analysis with default criteria\")" + ] + }, + { + "cell_type": "markdown", + "id": "7b37695e", + "metadata": {}, + "source": [ + "# Query and Analyse" ] }, { "cell_type": "code", "execution_count": null, - "id": "be8d8551", + "id": "02af0ee8", "metadata": {}, "outputs": [], "source": [ - "analysis = powering.Pic2Analysis('', input_)\n", - "\n", - "# spark = get_or_create()\n", + "analysis = powering.Pic2Analysis('', test_parameters)\n", "analysis.set_spark(spark)" ] }, @@ -90,7 +154,10 @@ "outputs": [], "source": [ "%%time\n", - "analysis.query()" + "try:\n", + " analysis.query()\n", + "except Exception:\n", + " print('\\nWarning: Analysis Raised an Exception!\\n')" ] }, { @@ -103,7 +170,10 @@ "outputs": [], "source": [ "%%time\n", - "analysis.analyze()" + "try:\n", + " analysis.analyze()\n", + "except Exception:\n", + " print('\\nWarning: Analysis Raised an Exception!\\n')" ] }, { @@ -111,26 +181,23 @@ "id": "2713228d", "metadata": {}, "source": [ - "# PM Timestamps" + "# 1. PM Timestamps" ] }, { "cell_type": "code", "execution_count": null, - "id": "759f17ec", - "metadata": {}, - "outputs": [], - "source": [ - "print(analysis.get_result('pm_timestamps'))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "eb367488", + "id": "e7340397", "metadata": {}, "outputs": [], "source": [ + "try:\n", + " timestamps = analysis.get_result('timestamps')\n", + " timestamp_dct = {'FGC': timestamps.fgc, 'PIC': timestamps.pic, 'QDS_A': timestamps.qds_a, 'QDS_B': timestamps.qds_b}\n", + " display(HTML(create_timestamp_table(timestamp_dct).to_html()))\n", + "except Exception:\n", + " print('\\nWarning: Analysis Raised an Exception!\\n')\n", + "\n", "print(f'Timestamp check: {analysis.get_result(\"timestamps_check\")}')" ] }, @@ -139,7 +206,7 @@ "id": "0a9f9e20", "metadata": {}, "source": [ - "# Quench Heaters" + "# 2. Quench Heaters" ] }, { @@ -151,9 +218,12 @@ "source": [ "%%time\n", "%%capture\n", - "import matplotlib\n", "%matplotlib inline\n", - "complete_output = qh_output.get_output(analysis._manager.get_analysis(\"Quench Heaters\"))" + "try:\n", + " complete_output = []\n", + " complete_output = qh_output.get_output(analysis._manager.get_analysis(\"Quench Heaters\"))\n", + "except Exception:\n", + " print('\\nWarning: Analysis Raised an Exception!\\n')" ] }, { @@ -165,7 +235,6 @@ }, "outputs": [], "source": [ - "%%time\n", "notebook_utils.display_output(complete_output)" ] }, @@ -174,7 +243,7 @@ "id": "af7dcd00", "metadata": {}, "source": [ - "# LD1 artificial linear ramp" + "# 3. QDS: LD1 artificial linear ramp check" ] }, { @@ -184,14 +253,33 @@ "metadata": {}, "outputs": [], "source": [ - "from matplotlib import pyplot as plt\n", "%matplotlib widget\n", - "plt.rcParams[\"figure.figsize\"] = [15, 7]\n", - "\n", + "try:\n", + " ld1_u_hts: pd.DataFrame = analysis.get_result('ld1_u_hts')\n", + " title = f\"{test_parameters.circuit_name}, {test_parameters.hwc_test}, {Time.to_string_short(timestamp_dct.get('FGC_B1'))}\"\n", + " \n", + " fig, ax = plt.subplots(figsize=(15, 7))\n", + " ld1_u_hts.plot(ax=ax, style='-o')\n", + " ax.set_title(title, loc='left', fontsize = 20)\n", + " ax.axhline(y = pic2._MIN_QUENCH_DETECTION_LEVEL_VOLTAGE, color = 'red', linestyle='dashed')\n", + " ax.axvline(x = +pic2._QUENCH_DETECTION_WINDOW_WITH_RESPECT_TO_FGC_IN_S, color = 'red', linestyle='dashed')\n", + " ax.axvline(x = -pic2._QUENCH_DETECTION_WINDOW_WITH_RESPECT_TO_FGC_IN_S, color = 'red', linestyle='dashed')\n", + " ax.set_xlabel('time, s', fontsize=18)\n", + " ax.set_ylabel(\"Voltage, V\", fontsize=18)\n", + " ax.grid(True)\n", + " plt.show()\n", + "except Exception:\n", + " print('\\nWarning: Analysis Raised an Exception!\\n')\n", "\n", - "ld1_u_hts = analysis.get_result('ld1_u_hts')\n", - "ld1_u_hts.plot(grid=True, title=f'PIC2 circuit quench via QPS')\n", - "plt.show()" + "print(f'LD1 Quench Check: {analysis.get_result(\"linear_ramp_check\")}')" + ] + }, + { + "cell_type": "markdown", + "id": "67cb94f2", + "metadata": {}, + "source": [ + "# Overall Result" ] }, { @@ -204,6 +292,14 @@ "print(f'LD1 Quench Check: {analysis.get_result(\"linear_ramp_check\")}')" ] }, + { + "cell_type": "markdown", + "id": "79f62be5", + "metadata": {}, + "source": [ + "# Acceptance Decision" + ] + }, { "cell_type": "code", "execution_count": null, @@ -211,7 +307,42 @@ "metadata": {}, "outputs": [], "source": [ - " print(f'The analysis output is \\033[1m{analysis.get_analysis_output()}\\033[0m')" + "signature = get_expert_decision('Expert Signature Decision: ', ['PASSED', 'FAILED'])" + ] + }, + { + "cell_type": "markdown", + "id": "ba08bfb3", + "metadata": {}, + "source": [ + "# Final Report" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "21a1e7b5", + "metadata": {}, + "outputs": [], + "source": [ + "path_to_notebook = './AN_IPD_PIC2.ipynb'\n", + "report_destination_path_template = '/eos/project/m/mp3/IPD/{}/{}/{}' # prefix, circuit_name, hwc_test\n", + "report_filename_template = '{}_{}-{}-{}_{}' # circuit_name, hwc_test, t_start, analysis_time, signature\n", + "#\n", + "analysis_start_time = Time.get_analysis_start_time()\n", + "prefix_circuit_name = circuit_name.split('.')[0]\n", + "hwc_test = hwc_test.split(' ')[0]\n", + "#\n", + "report_destination_path = report_destination_path_template.format(prefix_circuit_name, circuit_name, hwc_test)\n", + "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)\n", + "#\n", + "!mkdir -p $report_destination_path\n", + "html_filename = f'{report_filename}.html'\n", + "html_path = f'{report_destination_path}/{report_filename}.html'\n", + "print('Compact notebook report saved to (Windows): ' + '\\\\\\\\eosproject-smb' + html_path.replace('/', '\\\\'))\n", + "display(Javascript('IPython.notebook.save_notebook();'))\n", + "Time.sleep(5)\n", + "!{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" ] }, { @@ -219,7 +350,7 @@ "id": "25059fa2", "metadata": {}, "source": [ - "# Quench Heaters additional plots - see qh notebook " + "# Additional plots and analyses by MP3-experts (optional) " ] }, { @@ -235,7 +366,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -250,6 +381,12 @@ "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.18" + }, + "sparkconnect": { + "bundled_options": [ + "NXCALS" + ], + "list_of_options": [] } }, "nbformat": 4, diff --git a/ipq/AN_IPQ_PIC2.ipynb b/ipq/AN_IPQ_PIC2.ipynb index 59bcf061637fb36db3b059ad5e41c523b959a917..7df876eaa912f93b22752e3f8e1e2868e206a25d 100644 --- a/ipq/AN_IPQ_PIC2.ipynb +++ b/ipq/AN_IPQ_PIC2.ipynb @@ -5,7 +5,23 @@ "id": "c0efc070", "metadata": {}, "source": [ - "# PIC2 IPQ" + "# IPQ: PIC2 CIRCUIT QUENCH VIA QPS (MP3 Analysis Notebook)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "53ae34d2", + "metadata": { + "scrolled": false + }, + "outputs": [], + "source": [ + "from IPython.display import display, Markdown, HTML\n", + "import importlib.resources\n", + "with open(importlib.resources.files('lhcsmapi.api.analysis.powering.pic2') / 'README.md', 'r') as f:\n", + " long_description = f.read()\n", + "display(Markdown(long_description))" ] }, { @@ -15,16 +31,52 @@ "metadata": {}, "outputs": [], "source": [ + "import getpass\n", + "import logging\n", "import sys\n", + "\n", + "from matplotlib import pyplot as plt\n", + "import pandas as pd\n", + "from IPython.display import display, Javascript, clear_output\n", + "\n", + "import lhcsmapi\n", + "from lhcsmapi.Time import Time\n", "from lhcsmapi.api.analysis import powering\n", - "from lhcsmapi.api.analysis.powering import pic2\n", - "# from nxcals.spark_session_builder import get_or_create\n", + "from lhcsmapi.api.analysis.output.powering import create_timestamp_table\n", "from lhcsmapi.api.analysis.output.qh import quench_heater_voltage_output as qh_output\n", + "from lhcsmapi.api.analysis.powering import pic2\n", + "from lhcsmapi.metadata import signal_metadata\n", + "from lhcsmapi.analysis.expert_input import get_expert_decision\n", "from lhcsmnb import utils as notebook_utils\n", "\n", - "import logging\n", + "%xmode Minimal\n", "logging.getLogger().setLevel(logging.INFO)\n", - "logging.getLogger().addHandler(logging.StreamHandler(sys.stdout))" + "logging.getLogger().addHandler(logging.StreamHandler(sys.stdout))\n", + "\n", + "clear_output()\n", + "print(f'Analysis executed with lhc-sm-api version: {lhcsmapi.__version__}')\n", + "print(f'Analysis performed by {getpass.getuser()}')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ec9af145", + "metadata": {}, + "outputs": [], + "source": [ + "if 'spark' not in locals() and 'spark' not in globals():\n", + " from nxcals.spark_session_builder import get_or_create, Flavor\n", + " spark = get_or_create(flavor=Flavor.YARN_LARGE)" + ] + }, + { + "cell_type": "markdown", + "id": "f9f7e1df", + "metadata": {}, + "source": [ + "# User Input\n", + "Copy/Paste from AccTesting" ] }, { @@ -34,11 +86,11 @@ "metadata": {}, "outputs": [], "source": [ - "hwc_test = 'PIC2 CIRCUIT QUENCH VIA QPS' \n", - "circuit_name = 'RQ5.L8' \n", - "campaign= 'Commissioning post ITL8' \n", - "t_start = '2023-08-25 07:31:10.073000000'\n", - "t_end = '2023-08-25 08:03:33.250000000'" + "# hwc_test = 'PIC2 CIRCUIT QUENCH VIA QPS' \n", + "# circuit_name = 'RQ5.L8' \n", + "# campaign= 'Commissioning post ITL8' \n", + "# t_start = '2023-08-25 07:31:10.073000000'\n", + "# t_end = '2023-08-25 08:03:33.250000000'" ] }, { @@ -48,25 +100,38 @@ "metadata": {}, "outputs": [], "source": [ - "print('hwc_test = \\'%s\\'\\ncircuit_name = \\'%s\\'\\ncampaign = \\'%s\\'\\nt_start = \\'%s\\'\\nt_end = \\'%s\\'' % (hwc_test, circuit_name, campaign, t_start, t_end))" + "test_parameters = powering.TestParameterInput.create(hwc_test, circuit_name, campaign, t_start, t_end)\n", + "test_parameters" ] }, { "cell_type": "markdown", - "id": "7b37695e", + "id": "8be1d729", "metadata": {}, "source": [ - "# Query and Analyse" + "# Acceptance criteria" ] }, { "cell_type": "code", "execution_count": null, - "id": "02af0ee8", + "id": "3335a047", "metadata": {}, "outputs": [], "source": [ - "input_ = powering.TestParameterInput.create(hwc_test, circuit_name, campaign, t_start, t_end)" + "print(f\"Expected PM & PIC time window = {(pic2._EXPECTED_PM_WINDOW_IN_NANOS*1e-6):n} ms\")\n", + "print(f\"QPS A&B PM time difference = {(pic2._QPS_A_B_DIFF_IN_NANOS*1e-6):n} ms\")\n", + "print(f\"QDS Current Lead quench detection level = {(pic2._MIN_QUENCH_DETECTION_LEVEL_VOLTAGE*1e+3):n} mV\")\n", + "print(f\"QDS Quench detection window w.r.t. FGC time = {(pic2._QUENCH_DETECTION_WINDOW_WITH_RESPECT_TO_FGC_IN_S*1e+3):n} ms\")\n", + "print(\"+QH discharge analysis with default criteria\")" + ] + }, + { + "cell_type": "markdown", + "id": "7b37695e", + "metadata": {}, + "source": [ + "# Query and Analyse" ] }, { @@ -76,9 +141,7 @@ "metadata": {}, "outputs": [], "source": [ - "analysis = pic2.Pic2Analysis('pic2', input_)\n", - "\n", - "# spark = get_or_create()\n", + "analysis = pic2.Pic2Analysis('pic2', test_parameters)\n", "analysis.set_spark(spark)" ] }, @@ -111,26 +174,20 @@ "id": "2713228d", "metadata": {}, "source": [ - "# Timestamps" + "# 1. PM & PIC Timestamps" ] }, { "cell_type": "code", "execution_count": null, - "id": "cacf647d", - "metadata": {}, - "outputs": [], - "source": [ - "print(analysis.get_result('timestamps'))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "ba630e39", + "id": "26412b1e", "metadata": {}, "outputs": [], "source": [ + "timestamps = analysis.get_result('timestamps')\n", + "timestamp_dct = {'FGC_B1': timestamps.fgc_b1, 'FGC_B2': timestamps.fgc_b2, 'PIC': timestamps.pic, 'QDS_A': timestamps.qds_a, 'QDS_B': timestamps.qds_b}\n", + "display(HTML(create_timestamp_table(timestamp_dct).to_html()))\n", + "\n", "print(f'Timestamp check: {analysis.get_result(\"timestamps_check\")}')" ] }, @@ -139,7 +196,7 @@ "id": "0cde92d0", "metadata": {}, "source": [ - "# Quench Heaters" + "# 2. Quench Heaters" ] }, { @@ -149,23 +206,20 @@ "metadata": {}, "outputs": [], "source": [ - "%%time\n", "%%capture\n", - "import matplotlib\n", "%matplotlib inline\n", - "complete_output = qh_output.get_output(analysis._manager.get_analysis(\"Quench Heaters\"))" + "\n", + "complete_output = qh_output.get_output(analysis._manager.get_analysis(\"Quench Heaters\"))\n" ] }, { "cell_type": "code", "execution_count": null, - "id": "ec1029f0", - "metadata": { - "scrolled": false - }, + "id": "9160783b", + "metadata": {}, "outputs": [], "source": [ - "%%time\n", + "\n", "notebook_utils.display_output(complete_output)" ] }, @@ -174,44 +228,107 @@ "id": "7e6324a5", "metadata": {}, "source": [ - "# LD1 artificial linear ramp" + "# 3. QDS: LD1 artificial linear ramp check" ] }, { "cell_type": "code", "execution_count": null, "id": "d4b7aaad", - "metadata": {}, + "metadata": { + "scrolled": false + }, "outputs": [], "source": [ - "from matplotlib import pyplot as plt\n", "%matplotlib widget\n", - "plt.rcParams[\"figure.figsize\"] = [15, 7]\n", "\n", + "ld1_u_hts: pd.DataFrame = analysis.get_result('ld1_u_hts')\n", + "title = f\"{test_parameters.circuit_name}, {test_parameters.hwc_test}, {Time.to_string_short(timestamp_dct.get('FGC_B1'))}\"\n", "\n", - "ld1_u_hts = analysis.get_result('ld1_u_hts')\n", - "ld1_u_hts.plot(grid=True, title=f'PIC2 circuit quench via QPS')\n", - "plt.show()" + "fig, ax = plt.subplots(figsize=(15, 7))\n", + "ld1_u_hts.plot(ax=ax, style='-o')\n", + "ax.set_title(title, loc='left', fontsize = 20)\n", + "ax.axhline(y = pic2._MIN_QUENCH_DETECTION_LEVEL_VOLTAGE, color = 'red', linestyle='dashed')\n", + "ax.axvline(x = +pic2._QUENCH_DETECTION_WINDOW_WITH_RESPECT_TO_FGC_IN_S, color = 'red', linestyle='dashed')\n", + "ax.axvline(x = -pic2._QUENCH_DETECTION_WINDOW_WITH_RESPECT_TO_FGC_IN_S, color = 'red', linestyle='dashed')\n", + "ax.set_xlabel('time, s', fontsize=18)\n", + "ax.set_ylabel(\"Voltage, V\", fontsize=18)\n", + "ax.grid(True)\n", + "plt.show()\n", + "\n", + "\n", + "print(f'LD1 Quench Check: {analysis.get_result(\"linear_ramp_check\")}')" + ] + }, + { + "cell_type": "markdown", + "id": "b5a9a199", + "metadata": {}, + "source": [ + "# Overall Result" ] }, { "cell_type": "code", "execution_count": null, - "id": "973d6b82", + "id": "2eb4ca28", "metadata": {}, "outputs": [], "source": [ - "print(f'LD1 Quench Check: {analysis.get_result(\"linear_ramp_check\")}')" + "print(f'The Overall Analysis output is \\033[1m{analysis.get_analysis_output()}\\033[0m')" + ] + }, + { + "cell_type": "markdown", + "id": "fccff0c7", + "metadata": {}, + "source": [ + "# Acceptance Decision" ] }, { "cell_type": "code", "execution_count": null, - "id": "2eb4ca28", + "id": "81225991", "metadata": {}, "outputs": [], "source": [ - "print(f'The analysis output is \\033[1m{analysis.get_analysis_output()}\\033[0m')" + "signature = get_expert_decision('Expert Signature Decision: ', ['PASSED', 'FAILED'])" + ] + }, + { + "cell_type": "markdown", + "id": "64692ae5", + "metadata": {}, + "source": [ + "# Final Report" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7039c8fb", + "metadata": {}, + "outputs": [], + "source": [ + "path_to_notebook = './AN_IPQ_PIC2.ipynb'\n", + "report_destination_path_template = '/eos/project/m/mp3/IPQ/{}/{}/{}' # prefix, circuit_name, hwc_test\n", + "report_filename_template = '{}_{}-{}-{}_{}' # circuit_name, hwc_test, t_start, analysis_time, signature\n", + "#\n", + "analysis_start_time = Time.get_analysis_start_time()\n", + "prefix_circuit_name = circuit_name.split('.')[0]\n", + "hwc_test = hwc_test.split(' ')[0]\n", + "#\n", + "report_destination_path = report_destination_path_template.format(prefix_circuit_name, circuit_name, hwc_test)\n", + "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)\n", + "#\n", + "!mkdir -p $report_destination_path\n", + "html_filename = f'{report_filename}.html'\n", + "html_path = f'{report_destination_path}/{report_filename}.html'\n", + "print('Compact notebook report saved to (Windows): ' + '\\\\\\\\eosproject-smb' + html_path.replace('/', '\\\\'))\n", + "display(Javascript('IPython.notebook.save_notebook();'))\n", + "Time.sleep(5)\n", + "!{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" ] }, { @@ -219,23 +336,64 @@ "id": "5e7a9413", "metadata": {}, "source": [ - "# Quench Heaters additional plots - see qh notebook " + "# Additional plots and analyses by MP3-experts (optional) " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9887ca36", + "metadata": {}, + "outputs": [], + "source": [ + "%matplotlib widget\n", + "\n", + "v_events = analysis.get_result('voltage_events')\n", + "\n", + "fig, ax = plt.subplots(figsize=(15, 7))\n", + "v_events[0].u_hds[1].plot(ax=ax, style='-o')\n", + "v_events[0].u_hds_ref[1].plot(ax=ax, style='-o')\n", + "ax.set_title(f\"{test_parameters.circuit_name}, {test_parameters.hwc_test}, {Time.to_string_short(timestamp_dct.get('FGC_B1'))}\", loc='left', fontsize = 20)\n", + "ax.set_xlabel('Time, s', fontsize=18)\n", + "ax.set_xlim(-1, +1)\n", + "ax.grid(True)\n", + "fig.show()" ] }, { "cell_type": "code", "execution_count": null, - "id": "d3ed24f7", + "id": "f966ceab", "metadata": {}, "outputs": [], "source": [ - "# copy here?" + "%matplotlib widget\n", + "\n", + "l_event: pd.DataFrame = analysis.get_result('ld1_u_hts')\n", + "\n", + "title = f\"{test_parameters.circuit_name}, {test_parameters.hwc_test}, {Time.to_string_short(timestamp_dct.get('FGC_B1'))}\"\n", + "fig, ax1 = plt.subplots(figsize=(15, 7))\n", + "v_events[0].u_hds[1].plot(ax=ax1)\n", + "v_events[0].u_hds_ref[1].plot(ax=ax1)\n", + "ax1.set_title(title, loc='left', fontsize = 20)\n", + "ax1.grid(True)\n", + "ax1.set_xlabel('Time, s', fontsize=18)\n", + "ax1.set_ylabel('U_HDS, V', fontsize=18, color='blue')\n", + "ax1.set_xlim(-10, +10)\n", + "ax1.legend(loc='lower left')\n", + "\n", + "ax2 = ax1.twinx()\n", + "l_event.plot(ax=ax2, color='green')\n", + "ax2.set_ylabel('LD1:U_HTS, V', fontsize=18, color='green')\n", + "ax2.legend(loc='upper right')\n", + "\n", + "fig.show()" ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -250,6 +408,12 @@ "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.18" + }, + "sparkconnect": { + "bundled_options": [ + "NXCALS" + ], + "list_of_options": [] } }, "nbformat": 4,