From 8e25f14e900f8e64d27d47158d405f77751bc027 Mon Sep 17 00:00:00 2001
From: ahmedk <karim.ahmed@xfel.eu>
Date: Thu, 13 Oct 2022 16:01:00 +0200
Subject: [PATCH] put back detailed imaged as requested and add detailed report
 flag

---
 ...rk_analysis_all_gains_burst_mode_NBC.ipynb | 94 ++++++++++++++++++-
 1 file changed, 90 insertions(+), 4 deletions(-)

diff --git a/notebooks/Jungfrau/Jungfrau_dark_analysis_all_gains_burst_mode_NBC.ipynb b/notebooks/Jungfrau/Jungfrau_dark_analysis_all_gains_burst_mode_NBC.ipynb
index e10de8c4e..a98cb8230 100644
--- a/notebooks/Jungfrau/Jungfrau_dark_analysis_all_gains_burst_mode_NBC.ipynb
+++ b/notebooks/Jungfrau/Jungfrau_dark_analysis_all_gains_burst_mode_NBC.ipynb
@@ -55,6 +55,9 @@
     "bias_voltage = 90  # sensor bias voltage in V, will be overwritten by value in file\n",
     "memory_cells = 16  # number of memory cells\n",
     "\n",
+    "# Parameters used for plotting\n",
+    "detailed_report = False\n",
+    "\n",
     "# TODO: this is used for only Warning check at AGIPD dark.\n",
     "# Need to rethink if it makes sense to use it here as well.\n",
     "operation_mode = 'ADAPTIVE_GAIN'  # Detector operation mode, optional"
@@ -415,12 +418,82 @@
    ]
   },
   {
-   "cell_type": "markdown",
+   "cell_type": "code",
+   "execution_count": null,
    "metadata": {},
+   "outputs": [],
    "source": [
-    "## Offset and Noise Maps ##\n",
-    "\n",
-    "Below offset and noise maps for the high ($g_0$) gain stage are shown, alongside the distribution of these values. One expects block-like structures mapping to the ASICs of the detector"
+    "if detailed_report:\n",
+    "    display(Markdown(\"## Offset and Noise Maps:\"))\n",
+    "    display(Markdown(\n",
+    "        \"Below offset and noise maps for the high ($g_0$) gain stage are shown, \"\n",
+    "        \"alongside the distribution of these values. One expects block-like \"\n",
+    "        \"structures mapping to the ASICs of the detector\"))\n",
+    "    g_name = ['G0', 'G1', 'G2']\n",
+    "    g_range = [(0, 8000), (8000, 16000), (8000, 16000)]\n",
+    "    n_range = [(0., 50.), (0., 50.), (0., 50.)]\n",
+    "\n",
+    "    unit = '[ADCu]'\n",
+    "    # TODO: Fix plots arrangment and speed for Jungfrau burst mode.\n",
+    "    step_timer.start()\n",
+    "    for pdu, mod in zip(db_modules, karabo_da):\n",
+    "        for g_idx in gains:\n",
+    "            for cell in range(0, memory_cells):\n",
+    "                f_o0 = heatmapPlot(\n",
+    "                    np.swapaxes(offset_map[mod][..., cell, g_idx], 0, 1),\n",
+    "                    y_label=\"Row\",\n",
+    "                    x_label=\"Column\",\n",
+    "                    lut_label=unit,\n",
+    "                    aspect=1.,\n",
+    "                    vmin=g_range[g_idx][0],\n",
+    "                    vmax=g_range[g_idx][1],\n",
+    "                    title=f'Pedestal {g_name[g_idx]} - Cell {cell:02d} - Module {mod} ({pdu})')\n",
+    "\n",
+    "                fo0, ax_o0 = plt.subplots()\n",
+    "                res_o0 = histPlot(\n",
+    "                    ax_o0, offset_map[mod][..., cell, g_idx],\n",
+    "                    bins=800,\n",
+    "                    range=g_range[g_idx],\n",
+    "                    facecolor='b',\n",
+    "                    histotype='stepfilled',\n",
+    "                )\n",
+    "\n",
+    "                ax_o0.tick_params(axis='both',which='major',labelsize=15)\n",
+    "                ax_o0.set_title(\n",
+    "                    f'Module pedestal distribution - Cell {cell:02d} - Module {mod} ({pdu})',\n",
+    "                    fontsize=15)\n",
+    "                ax_o0.set_xlabel(f'Pedestal {g_name[g_idx]} {unit}',fontsize=15)\n",
+    "                ax_o0.set_yscale('log')\n",
+    "\n",
+    "                f_n0 = heatmapPlot(\n",
+    "                    np.swapaxes(noise_map[mod][..., cell, g_idx], 0, 1),\n",
+    "                    y_label=\"Row\",\n",
+    "                    x_label=\"Column\",\n",
+    "                    lut_label= unit,\n",
+    "                    aspect=1.,\n",
+    "                    vmin=n_range[g_idx][0],\n",
+    "                    vmax=n_range[g_idx][1],\n",
+    "                    title=f\"RMS noise {g_name[g_idx]} - Cell {cell:02d} - Module {mod} ({pdu})\",\n",
+    "                )\n",
+    "\n",
+    "                fn0, ax_n0 = plt.subplots()\n",
+    "                res_n0 = histPlot(\n",
+    "                    ax_n0,\n",
+    "                    noise_map[mod][..., cell, g_idx],\n",
+    "                    bins=100,\n",
+    "                    range=n_range[g_idx],\n",
+    "                    facecolor='b',\n",
+    "                    histotype='stepfilled',\n",
+    "                )\n",
+    "\n",
+    "                ax_n0.tick_params(axis='both', which='major', labelsize=15)\n",
+    "                ax_n0.set_title(\n",
+    "                    f'Module noise distribution - Cell {cell:02d} - Module {mod} ({pdu})',\n",
+    "                    fontsize=15)\n",
+    "                ax_n0.set_xlabel(\n",
+    "                    f'RMS noise {g_name[g_idx]} ' + unit, fontsize=15)\n",
+    "                plt.show()\n",
+    "    step_timer.done_step(f'Plotting offset and noise maps.')"
    ]
   },
   {
@@ -489,6 +562,19 @@
     "\n",
     "    bad_pixels_map[mod][(offset_map[mod] < offset_abs_threshold[0][None, None, None, :]) | (offset_map[mod] > offset_abs_threshold[1][None, None, None, :])] |= BadPixels.OFFSET_OUT_OF_THRESHOLD.value  # noqa\n",
     "\n",
+    "    if detailed_report:\n",
+    "\n",
+    "        for g_idx in gains:\n",
+    "            for cell in range(memory_cells):\n",
+    "                bad_pixels = bad_pixels_map[mod][:, :, cell, g_idx]\n",
+    "                fn_0 = heatmapPlot(\n",
+    "                    np.swapaxes(bad_pixels, 0, 1),\n",
+    "                    y_label=\"Row\",\n",
+    "                    x_label=\"Column\",\n",
+    "                    lut_label=f\"Badpixels {g_name[g_idx]} [ADCu]\",\n",
+    "                    aspect=1.,\n",
+    "                    vmin=0, vmax=5,\n",
+    "                    title=f'G{g_idx} Bad pixel map - Cell {cell:02d} - Module {mod} ({pdu})')\n",
     "step_timer.done_step(f'Creating bad pixels constant')"
    ]
   },
-- 
GitLab