From 6c02cdd8abf51913f7c69e901ece32e684619b98 Mon Sep 17 00:00:00 2001 From: ahmedk <karim.ahmed@xfel.eu> Date: Thu, 8 Feb 2024 14:49:08 +0100 Subject: [PATCH] remove unneeded flatten operations an data conversions --- .../AGIPD/AGIPD_Correct_and_Verify.ipynb | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb b/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb index 29f40ffe8..32f9b4aa7 100644 --- a/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb +++ b/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb @@ -1015,13 +1015,16 @@ "metadata": {}, "outputs": [], "source": [ + "raw_float = raw.astype(np.float32)\n", + "signal = raw[:, 0, ...]\n", + "gain = raw[:, 1, ...]\n", "hist, bins_x, bins_y = calgs.histogram2d(\n", - " raw[:,0,...].flatten().astype(np.float32),\n", - " raw[:,1,...].flatten().astype(np.float32),\n", + " signal.flatten().astype(np.float32),\n", + " gain.flatten().astype(np.float32),\n", " bins=(100, 100),\n", " range=[\n", - " np.percentile(raw[:, 0, ...].astype(np.float32), [0.02, 99.8]),\n", - " np.percentile(raw[:, 1, ...].astype(np.float32), [0.02, 99.8]),\n", + " np.percentile(signal, [0.02, 99.8]),\n", + " np.percentile(gain, [0.02, 99.8]),\n", " ],\n", " )\n", "do_2d_plot(hist, (bins_x, bins_y), \"Signal (ADU)\", \"Analogue gain (ADU)\")" @@ -1046,7 +1049,7 @@ " corrected.flatten().astype(np.float32),\n", " gains.flatten().astype(np.float32), bins=(100, 3),\n", " range=[\n", - " np.percentile(corrected.flatten().astype(np.float32), [0, 100]),\n", + " np.percentile(corrected, [0, 100]),\n", " [0, 3]\n", " ],\n", " )\n", @@ -1080,7 +1083,8 @@ "metadata": {}, "outputs": [], "source": [ - "pulse_range = np.percentile(pulseId.astype(np.float32), [0, 100])\n", + "pulse_range = [np.min(pulseId[pulseId>=0]), np.max(pulseId[pulseId>=0])]\n", + "\n", "# Modify pulse_range, if only one pulse is selected.\n", "if pulse_range[0] == pulse_range[1]:\n", " pulse_range = [0, pulse_range[1]+int(acq_rate)]\n", @@ -1090,12 +1094,15 @@ " mean_data.flatten().astype(np.float32),\n", " pulseId.flatten().astype(np.float32),\n", " bins=(100, int(pulse_range[1])),\n", - " range=[\n", - " np.percentile(mean_data.astype(np.float32), [0, 100]),\n", - " pulse_range\n", - " ],\n", + " range=[[-50, 1000], pulse_range],\n", + ")\n", + "do_2d_plot(hist, (bins_x, bins_y), \"Signal (ADU)\", \"Pulse id\")\n", + "hist, bins_x, bins_y = calgs.histogram2d(\n", + " mean_data.flatten().astype(np.float32),\n", + " pulseId.flatten().astype(np.float32),\n", + " bins=(100, int(pulse_range[1])),\n", + " range=[[-50, 200000], pulse_range]\n", ")\n", - "\n", "do_2d_plot(hist, (bins_x, bins_y), \"Signal (ADU)\", \"Pulse id\")" ] }, @@ -1131,7 +1138,7 @@ "fig = plt.figure(figsize=(10, 10))\n", "corrected_ave = np.nansum(corrected, axis=(2, 3))\n", "plt.scatter(corrected_ave.flatten()/10**6, blshift.flatten(), s=0.9)\n", - "plt.xlim(np.percentile(corrected_ave.flatten()/10**6, [2, 98]))\n", + "plt.xlim(np.percentile(corrected_ave/10**6, [2, 98]))\n", "plt.grid()\n", "plt.xlabel('Illuminated corrected [MADU] ')\n", "_ = plt.ylabel('Estimated baseline shift [ADU]')" @@ -1200,7 +1207,7 @@ " fig = plt.figure(figsize=(20, 10))\n", " ax = fig.add_subplot(111)\n", " data = np.mean(corrected, axis=0)\n", - " vmin, vmax = np.percentile(data, [5, 99.9])\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", " pass\n", "else:\n", @@ -1217,7 +1224,7 @@ "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.percentile(corrected[cell_idx_preview], [5, 99.9])\n", + "vmin, vmax = np.nanpercentile(corrected[cell_idx_preview], [5, 99.9])\n", "ax = geom.plot_data_fast(\n", " corrected[cell_idx_preview], ax=ax, vmin=vmin, vmax=vmax, cmap=cmap)\n", "pass" @@ -1231,7 +1238,7 @@ "source": [ "fig = plt.figure(figsize=(20, 10))\n", "ax = fig.add_subplot(111)\n", - "vmin, vmax = np.percentile(corrected[cell_idx_preview], [5, 100])\n", + "vmin, vmax = np.nanpercentile(corrected[cell_idx_preview], [5, 100])\n", "nbins = int((vmax + 50) / 2)\n", "h = ax.hist(corrected[cell_idx_preview].flatten(),\n", " bins=nbins, range=(vmin, vmax),\n", -- GitLab