From 0936bd51f4628849e0a3659df3a7e37c022ee4c9 Mon Sep 17 00:00:00 2001 From: ahmedk <karim.ahmed@xfel.eu> Date: Tue, 25 Apr 2023 09:28:47 +0200 Subject: [PATCH] revert back uneeded plotting changes --- ...Jungfrau_Gain_Correct_and_Verify_NBC.ipynb | 42 +++++++++---------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/notebooks/Jungfrau/Jungfrau_Gain_Correct_and_Verify_NBC.ipynb b/notebooks/Jungfrau/Jungfrau_Gain_Correct_and_Verify_NBC.ipynb index 7c73286e3..c2b26937b 100644 --- a/notebooks/Jungfrau/Jungfrau_Gain_Correct_and_Verify_NBC.ipynb +++ b/notebooks/Jungfrau/Jungfrau_Gain_Correct_and_Verify_NBC.ipynb @@ -707,7 +707,7 @@ " # Reading CORR data for plotting.\n", " jf_corr = components.JUNGFRAU(\n", " corr_dc,\n", - " detector_name=karabo_id, n_modules=nmods, st_modno=st_modno,\n", + " detector_name=karabo_id,\n", " ).select_trains(np.s_[:plot_trains])\n", " tid, jf_corr_data = next(iter(jf_corr.trains(require_all=True)))\n", "\n", @@ -715,31 +715,32 @@ "# TODO: Fix the case if not all modules were requested to be corrected.\n", "# For example if only one modules was corrected. An assertion error is expected\n", "# at `geom.plot_data_fast`, while plotting corrected images.\n", - "corrected = jf_corr.get_array(\"data.adc\")[:, :, cell_idx_preview, ...]\n", + "corrected = jf_corr.get_array(\"data.adc\")[:, :, cell_idx_preview, ...].values\n", "corrected_train = jf_corr_data[\"data.adc\"][\n", " :, cell_idx_preview, ...\n", - "] # loose the train axis.\n", + "].values # loose the train axis.\n", "\n", - "mask = jf_corr.get_array(\"data.mask\")[:, :, cell_idx_preview, ...]\n", - "mask_train = jf_corr_data[\"data.mask\"][:, cell_idx_preview, ...]\n", + "mask = jf_corr.get_array(\"data.mask\")[:, :, cell_idx_preview, ...].values\n", + "mask_train = jf_corr_data[\"data.mask\"][:, cell_idx_preview, ...].values\n", "\n", "with RunDirectory(f\"{in_folder}/r{run:04d}/\", f\"*S{first_seq:05d}*\", _use_voview=False) as raw_dc:\n", "\n", " # Reading RAW data for plotting.\n", " jf_raw = components.JUNGFRAU(\n", - " raw_dc, detector_name=karabo_id, n_modules=nmods, st_modno=st_modno).select_trains(\n", + " raw_dc, detector_name=karabo_id).select_trains(\n", " np.s_[:plot_trains]\n", " )\n", "\n", - "raw = jf_raw.get_array(\"data.adc\")[:, :, cell_idx_preview, ...]\n", + "raw = jf_raw.get_array(\"data.adc\")[:, :, cell_idx_preview, ...].values\n", "raw_train = (\n", " jf_raw.select_trains(by_id[[tid]])\n", " .get_array(\"data.adc\")[:, 0, cell_idx_preview, ...]\n", + " .values\n", ")\n", "\n", - "gain = jf_raw.get_array(\"data.gain\")[:, :, cell_idx_preview, ...]\n", + "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\")[:, :, :, ...]\n", + " jf_raw.select_trains(by_id[[tid]]).get_array(\"data.gain\")[:, :, :, ...].values\n", ")" ] }, @@ -760,13 +761,12 @@ "\n", "fig, ax = plt.subplots(figsize=(18, 10))\n", "raw_mean = np.mean(raw, axis=1)\n", - "raw_mean_arr = raw_mean.values\n", "\n", "geom.plot_data_fast(\n", " raw_mean,\n", " ax=ax,\n", - " vmin=min(0.75*np.median(raw_mean_arr[raw_mean_arr > 0]), 2000),\n", - " vmax=max(1.5*np.median(raw_mean_arr[raw_mean_arr > 0]), 16000),\n", + " vmin=min(0.75*np.median(raw_mean[raw_mean > 0]), 2000),\n", + " vmax=max(1.5*np.median(raw_mean[raw_mean > 0]), 16000),\n", " cmap=\"jet\",\n", " colorbar={'shrink': 1, 'pad': 0.01},\n", ")\n", @@ -791,9 +791,8 @@ "\n", "fig, ax = plt.subplots(figsize=(18, 10))\n", "corrected_mean = np.mean(corrected, axis=1)\n", - "corrected_mean_arr = corrected_mean.values\n", - "_corrected_vmin = min(0.75*np.median(corrected_mean_arr[corrected_mean_arr > 0]), -0.5)\n", - "_corrected_vmax = max(2.*np.median(corrected_mean_arr[corrected_mean_arr > 0]), 100)\n", + "_corrected_vmin = min(0.75*np.median(corrected_mean[corrected_mean > 0]), -0.5)\n", + "_corrected_vmax = max(2.*np.median(corrected_mean[corrected_mean > 0]), 100)\n", "\n", "mean_plot_kwargs = dict(\n", " vmin=_corrected_vmin, vmax=_corrected_vmax, cmap=\"jet\"\n", @@ -822,7 +821,7 @@ "source": [ "fig, ax = plt.subplots(figsize=(18, 10))\n", "corrected_masked = corrected.copy()\n", - "corrected_masked_mean = corrected_masked.where(mask == 0).mean(dim=\"train\", skipna=False)\n", + "corrected_masked_mean = np.nanmean(corrected_masked, axis=1)\n", "del corrected_masked\n", "\n", "if not strixel_sensor:\n", @@ -849,10 +848,9 @@ "display(Markdown((f\"#### A single image from train {tid}\")))\n", "\n", "fig, ax = plt.subplots(figsize=(18, 10))\n", - "median_corr_train = np.median(corrected_train.values[corrected_train.values > 0])\n", "single_plot_kwargs = dict(\n", - " vmin=min(0.75 * median_corr_train, -0.5),\n", - " vmax=max(2.0 * median_corr_train, 100),\n", + " vmin=min(0.75 * np.median(corrected_train[corrected_train > 0]), -0.5),\n", + " vmax=max(2.0 * np.median(corrected_train[corrected_train > 0]), 100),\n", " cmap=\"jet\"\n", ")\n", "\n", @@ -916,8 +914,8 @@ "for i, mod in enumerate(karabo_da):\n", " pdu = da_to_pdu[mod]\n", " h, ex, ey = np.histogram2d(\n", - " raw[i].values.flatten(),\n", - " gain[i].values.flatten(),\n", + " raw[i].flatten(),\n", + " gain[i].flatten(),\n", " bins=[100, 4],\n", " range=[[0, 10000], [0, 4]],\n", " )\n", @@ -946,7 +944,7 @@ "for i, mod in enumerate(karabo_da):\n", " pdu = da_to_pdu[mod]\n", " fig, axs = plt.subplots(nrows=2, ncols=1, figsize=(18, 10))\n", - " corrected_flatten = corrected[i].values.flatten()\n", + " corrected_flatten = corrected[i].flatten()\n", " for ax, hist_range in zip(axs, [(-100, 1000), (-1000, 10000)]):\n", " h = ax.hist(\n", " corrected_flatten,\n", -- GitLab