From bb74fbfff043fcd0ca69e16e33fa7fcf0f7275ff Mon Sep 17 00:00:00 2001
From: ahmedk <karim.ahmed@xfel.eu>
Date: Fri, 9 Feb 2024 12:34:23 +0100
Subject: [PATCH] Avoid nan disturbance for correction plots

---
 .../Jungfrau_Gain_Correct_and_Verify_NBC.ipynb         | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/notebooks/Jungfrau/Jungfrau_Gain_Correct_and_Verify_NBC.ipynb b/notebooks/Jungfrau/Jungfrau_Gain_Correct_and_Verify_NBC.ipynb
index 15131bdc5..ee81b4a8d 100644
--- a/notebooks/Jungfrau/Jungfrau_Gain_Correct_and_Verify_NBC.ipynb
+++ b/notebooks/Jungfrau/Jungfrau_Gain_Correct_and_Verify_NBC.ipynb
@@ -775,6 +775,7 @@
    "metadata": {},
    "outputs": [],
    "source": [
+    "step_timer.start()\n",
     "first_seq = 0 if sequences == [-1] else sequences[0]\n",
     "\n",
     "corrected_files = [\n",
@@ -817,7 +818,8 @@
     "gain = jf_raw.get_array(\"data.gain\")[:, :, cell_idx_preview, ...].values\n",
     "gain_train_cells = (\n",
     "    jf_raw.select_trains(by_id[[tid]]).get_array(\"data.gain\")[:, :, :, ...].values\n",
-    ")"
+    ")\n",
+    "step_timer.done_step(\"Prepared data for plotting\")"
    ]
   },
   {
@@ -865,8 +867,8 @@
     "print(f\"The per pixel mean of the first {corrected.shape[1]} trains of the first sequence file\")\n",
     "\n",
     "fig, ax = plt.subplots(figsize=(18, 10))\n",
-    "corrected_mean = np.mean(corrected, axis=1)\n",
-    "vmin, vmax = np.percentile(corrected_mean, [5, 95])\n",
+    "corrected_mean = np.nanmean(corrected, axis=1)\n",
+    "vmin, vmax = np.nanpercentile(corrected_mean, [5, 95])\n",
     "\n",
     "mean_plot_kwargs = dict(vmin=vmin, vmax=vmax)\n",
     "\n",
@@ -929,7 +931,7 @@
     "display(Markdown((f\"#### A single image from train {tid}\")))\n",
     "\n",
     "fig, ax = plt.subplots(figsize=(18, 10))\n",
-    "vmin, vmax = np.percentile(corrected_train, [5, 95])\n",
+    "vmin, vmax = np.nanpercentile(corrected_train, [5, 95])\n",
     "\n",
     "single_plot_kwargs = dict(\n",
     "    vmin=vmin,\n",
-- 
GitLab