From 60bbbe4258938da6bf4f63f98db341caf949ca0e Mon Sep 17 00:00:00 2001
From: ahmedk <karim.ahmed@xfel.eu>
Date: Mon, 12 Feb 2024 11:22:00 +0100
Subject: [PATCH] add title to Signal-Pulse ID plots and try different scale
 for corrected data

---
 .../AGIPD/AGIPD_Correct_and_Verify.ipynb      | 23 ++++++++++++-------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb b/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb
index 0da892794..7ca70a974 100644
--- a/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb
+++ b/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb
@@ -911,7 +911,7 @@
    "metadata": {},
    "outputs": [],
    "source": [
-    "def do_2d_plot(data, edges, y_axis, x_axis):\n",
+    "def do_2d_plot(data, edges, y_axis, x_axis, title=\"\"):\n",
     "    fig = plt.figure(figsize=(10, 10))\n",
     "    ax = fig.add_subplot(111)\n",
     "    extent = [np.min(edges[1]), np.max(edges[1]),\n",
@@ -920,6 +920,7 @@
     "                   norm=LogNorm(vmin=1, vmax=max(10, np.max(data))))\n",
     "    ax.set_xlabel(x_axis)\n",
     "    ax.set_ylabel(y_axis)\n",
+    "    ax.set_title(title)\n",
     "    cb = fig.colorbar(im)\n",
     "    cb.set_label(\"Counts\")"
    ]
@@ -1105,7 +1106,8 @@
     "    bins=(100, int(pulse_range[1])),\n",
     "    range=[[clamp(vmin, -50, -0.2), min(vmax, 1000)], pulse_range],\n",
     ")\n",
-    "do_2d_plot(hist, (bins_x, bins_y), \"Signal (ADU)\", \"Pulse id\")\n",
+    "do_2d_plot(hist, (bins_x, bins_y), \"Signal (ADU)\", \"Pulse id\", title=\"Signal-Pulse ID\")\n",
+    "\n",
     "if vmax > 1000:  # a zoom out plot.\n",
     "    hist, bins_x, bins_y = calgs.histogram2d(\n",
     "        mean_data.flatten().astype(np.float32),\n",
@@ -1113,7 +1115,7 @@
     "        bins=(100,  int(pulse_range[1])),\n",
     "        range=[[clamp(vmin, -50, -0.2), min(vmax, 20000)], pulse_range]\n",
     "    )\n",
-    "    do_2d_plot(hist, (bins_x, bins_y), \"Signal (ADU)\", \"Pulse id\")"
+    "    do_2d_plot(hist, (bins_x, bins_y), \"Signal (ADU)\", \"Pulse id\", title=\"Signal-Pulse ID (Extended View)\")"
    ]
   },
   {
@@ -1216,9 +1218,9 @@
     "    display(Markdown(f'A mean across train: {tid}\\n'))\n",
     "    fig = plt.figure(figsize=(20, 10))\n",
     "    ax = fig.add_subplot(111)\n",
-    "    data = np.nanmean(corrected, axis=0)\n",
-    "    vmin, vmax = np.nanpercentile(data, [5, 99.9])\n",
-    "    ax = geom.plot_data_fast(data, ax=ax, vmin=vmin, vmax=vmax, cmap=cmap)\n",
+    "    data = np.mean(corrected, axis=0)\n",
+    "    vmax = np.nanpercentile(data, 99.8)\n",
+    "    ax = geom.plot_data_fast(data, ax=ax, vmin=max(-50, np.nanmin(data)), vmax=vmax, cmap=cmap)\n",
     "    pass\n",
     "else:\n",
     "    print(\"Skipping mean CORRECTED preview for single memory cell, \"\n",
@@ -1234,9 +1236,14 @@
     "display(Markdown(f'A single shot of the CORRECTED image from cell {cell_id_preview} \\n'))\n",
     "fig = plt.figure(figsize=(20, 10))\n",
     "ax = fig.add_subplot(111)\n",
-    "vmin, vmax = np.nanpercentile(corrected[cell_idx_preview], [5, 99.9])\n",
+    "vmax = np.nanpercentile(corrected[cell_idx_preview], 99.8)\n",
     "ax = geom.plot_data_fast(\n",
-    "    corrected[cell_idx_preview], ax=ax, vmin=vmin, vmax=vmax, cmap=cmap)\n",
+    "    corrected[cell_idx_preview],\n",
+    "    ax=ax,\n",
+    "    vmin=max(-50, np.nanmin(corrected[cell_idx_preview])),\n",
+    "    vmax=vmax,\n",
+    "    cmap=cmap,\n",
+    ")\n",
     "pass"
    ]
   },
-- 
GitLab