diff --git a/notebooks/Jungfrau/Jungfrau_Gain_Correct_and_Verify_NBC.ipynb b/notebooks/Jungfrau/Jungfrau_Gain_Correct_and_Verify_NBC.ipynb index 2ab8799a3819cb0f5e69c31e708a6a22dc1b8a7f..6ad98afe263a6e64f95e37979c2dd77f5d0c1f72 100644 --- a/notebooks/Jungfrau/Jungfrau_Gain_Correct_and_Verify_NBC.ipynb +++ b/notebooks/Jungfrau/Jungfrau_Gain_Correct_and_Verify_NBC.ipynb @@ -87,6 +87,7 @@ "from cal_tools.tools import (\n", " get_constant_from_db_and_time,\n", " get_dir_creation_date,\n", + " get_pdu_from_db,\n", " map_seq_files,\n", " write_compressed_frames,\n", ")\n", @@ -226,7 +227,6 @@ " gain_mode=gain_mode,\n", ")\n", "\n", - "\n", "def get_constants_for_module(karabo_da: str):\n", " \"\"\" Get calibration constants for given module of Jungfrau\n", "\n", @@ -554,7 +554,22 @@ "metadata": {}, "outputs": [], "source": [ - "for mod in rim_data: \n", + "db_modules = get_pdu_from_db(\n", + " karabo_id=karabo_id,\n", + " karabo_da=karabo_da,\n", + " constant=Constants.jungfrau.Offset(),\n", + " condition=condition,\n", + " cal_db_interface=cal_db_interface,\n", + " snapshot_at=creation_time)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "for pdu, mod in zip(db_modules, karabo_da):\n", " h, ex, ey = np.histogram2d(\n", " rim_data[mod].flatten(),\n", " gim_data[mod].flatten(),\n", @@ -565,7 +580,7 @@ " h, (ex, ey),\n", " \"Signal (ADU)\",\n", " \"Gain Bit Value (high gain=0[00], medium gain=1[01], low gain=3[11])\",\n", - " f\"Module {mod}\")" + " f\"Module {mod} ({pdu})\")" ] }, { @@ -583,7 +598,7 @@ "metadata": {}, "outputs": [], "source": [ - "for mod in rim_data: \n", + "for pdu, mod in zip(db_modules, karabo_da):\n", " fig = plt.figure(figsize=(20, 10))\n", " ax = fig.add_subplot(111)\n", "\n", @@ -593,7 +608,7 @@ " vmax=max(1.5*np.median(rim_data[mod][rim_data[mod] > 0]), 16000),\n", " cmap=\"jet\")\n", "\n", - " ax.set_title(f'Module {mod}')\n", + " ax.set_title(f'Module {mod} ({pdu})')\n", " cb = fig.colorbar(im, ax=ax)" ] }, @@ -612,7 +627,7 @@ "metadata": {}, "outputs": [], "source": [ - "for mod in rim_data: \n", + "for pdu, mod in zip(db_modules, karabo_da):\n", " fig = plt.figure(figsize=(20, 10))\n", " ax = fig.add_subplot(111)\n", "\n", @@ -622,7 +637,7 @@ " vmax=max(2.*np.median(fim_data[mod][fim_data[mod] > 0]), 100),\n", " cmap=\"jet\")\n", "\n", - " ax.set_title(f'Module {mod}', size=18)\n", + " ax.set_title(f'Module {mod} ({pdu})', size=18)\n", " cb = fig.colorbar(im, ax=ax)" ] }, @@ -641,7 +656,7 @@ "metadata": {}, "outputs": [], "source": [ - "for mod in rim_data: \n", + "for pdu, mod in zip(db_modules, karabo_da):\n", " fig = plt.figure(figsize=(20, 10))\n", " ax = fig.add_subplot(111)\n", "\n", @@ -651,7 +666,7 @@ " vmax=max(2.*np.median(fim_data[mod][0, ...]), 100),\n", " cmap=\"jet\")\n", "\n", - " ax.set_title(f'Module {mod}', size=18)\n", + " ax.set_title(f'Module {mod} ({pdu})', size=18)\n", " cb = fig.colorbar(im, ax=ax)" ] }, @@ -668,7 +683,7 @@ "metadata": {}, "outputs": [], "source": [ - "for mod in rim_data: \n", + "for pdu, mod in zip(db_modules, karabo_da):\n", " fig = plt.figure(figsize=(20,10))\n", " ax = fig.add_subplot(211)\n", " h = ax.hist(\n", @@ -679,7 +694,7 @@ " )\n", " l = ax.set_xlabel(\"Signal (keV)\")\n", " l = ax.set_ylabel(\"Counts\")\n", - " _ = ax.set_title(f'Module {mod}')\n", + " _ = ax.set_title(f'Module {mod} ({pdu})')\n", "\n", " ax = fig.add_subplot(212)\n", " h = ax.hist(\n", @@ -690,7 +705,7 @@ " )\n", " l = ax.set_xlabel(\"Signal (keV)\")\n", " l = ax.set_ylabel(\"Counts\")\n", - " _ = ax.set_title(f'Module {mod}')" + " _ = ax.set_title(f'Module {mod} ({pdu})')" ] }, { @@ -708,13 +723,13 @@ "metadata": {}, "outputs": [], "source": [ - "for mod in rim_data: \n", + "for pdu, mod in zip(db_modules, karabo_da):\n", " fig = plt.figure(figsize=(20, 10))\n", " ax = fig.add_subplot(111)\n", " im = ax.imshow(\n", " np.max(gim_data[mod], axis=0),\n", " vmin=0, vmax=3, cmap=\"jet\")\n", - " ax.set_title(f'Module {mod}', size=18)\n", + " ax.set_title(f'Module {mod} ({pdu})', size=18)\n", " cb = fig.colorbar(im, ax=ax)" ] }, @@ -756,13 +771,13 @@ "metadata": {}, "outputs": [], "source": [ - "for mod in rim_data: \n", + "for pdu, mod in zip(db_modules, karabo_da):\n", " fig = plt.figure(figsize=(20, 10))\n", " ax = fig.add_subplot(111)\n", " im = ax.imshow(\n", " np.log2(msk_data[mod][0,...]),\n", " vmin=0, vmax=32, cmap=\"jet\")\n", - " ax.set_title(f'Module {mod}', size=18)\n", + " ax.set_title(f'Module {mod} ({pdu})', size=18)\n", " cb = fig.colorbar(im, ax=ax)" ] } 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 356e75e8c3cb178838724491f697259d22c64add..5139fd9aea156fa79f0171bf6e63f09eca532755 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 @@ -56,10 +56,7 @@ "\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\n", - "\n", - "# TODO: Remove\n", - "db_module = [\"\"] # ID of module in calibration database. TODO: remove from calibration_configurations." + "operation_mode = 'ADAPTIVE_GAIN' # Detector operation mode, optional" ] }, { @@ -215,6 +212,30 @@ "step_timer.done_step(f'Reading control data.')" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# set the operating condition\n", + "condition = Conditions.Dark.jungfrau(\n", + " memory_cells=memory_cells,\n", + " bias_voltage=bias_voltage,\n", + " integration_time=integration_time,\n", + " gain_setting=gain_setting,\n", + " gain_mode=gain_mode,\n", + ")\n", + "\n", + "db_modules = get_pdu_from_db(\n", + " karabo_id=karabo_id,\n", + " karabo_da=karabo_da,\n", + " constant=Constants.jungfrau.Offset(),\n", + " condition=condition,\n", + " cal_db_interface=cal_db_interface,\n", + " snapshot_at=creation_time)" + ] + }, { "cell_type": "code", "execution_count": null, @@ -366,7 +387,7 @@ "source": [ "# TODO: Fix plots arrangment and speed for Jungfrau burst mode.\n", "step_timer.start()\n", - "for mod in karabo_da:\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", @@ -377,7 +398,7 @@ " 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}')\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", @@ -390,7 +411,7 @@ "\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}',\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", @@ -403,7 +424,7 @@ " 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}\",\n", + " title=f\"RMS noise {g_name[g_idx]} - Cell {cell:02d} - Module {mod} ({pdu})\",\n", " )\n", "\n", " fn0, ax_n0 = plt.subplots()\n", @@ -418,7 +439,7 @@ "\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}',\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", @@ -478,8 +499,8 @@ "source": [ "step_timer.start()\n", "\n", - "for mod in karabo_da:\n", - " display(Markdown(f\"### Badpixels for module {mod}:\"))\n", + "for pdu, mod in zip(db_modules, karabo_da):\n", + " display(Markdown(f\"### Badpixels for module {mod} ({pdu}):\"))\n", " offset_abs_threshold = np.array(offset_abs_threshold)\n", "\n", " bad_pixels_map[mod][eval_bpidx(offset_map[mod])] |= BadPixels.OFFSET_OUT_OF_THRESHOLD.value\n", @@ -502,34 +523,10 @@ " 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}')\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 and plotting it for a module.')" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# set the operating condition\n", - "condition = Conditions.Dark.jungfrau(\n", - " memory_cells=memory_cells,\n", - " bias_voltage=bias_voltage,\n", - " integration_time=integration_time,\n", - " gain_setting=gain_setting,\n", - " gain_mode=gain_mode,\n", - ")\n", - "\n", - "db_modules = get_pdu_from_db(\n", - " karabo_id=karabo_id,\n", - " karabo_da=karabo_da,\n", - " constant=Constants.jungfrau.Offset(),\n", - " condition=condition,\n", - " cal_db_interface=cal_db_interface,\n", - " snapshot_at=creation_time)" - ] - }, { "cell_type": "markdown", "metadata": {},