From 738723adabdbc554ced4aba926e18bd1251bfc13 Mon Sep 17 00:00:00 2001
From: karnem <mikhail.karnevskiy@desy.de>
Date: Tue, 24 Sep 2019 13:53:00 +0200
Subject: [PATCH] Show constants without bad pixels

---
 notebooks/AGIPD/PlotFromCalDB_AGIPD_NBC.ipynb | 219 ++++++------------
 notebooks/LPD/PlotFromCalDB_LPD_NBC.ipynb     |  89 ++++---
 .../generic/PlotFromCalDB_Summary_NBC.ipynb   |  34 ++-
 3 files changed, 135 insertions(+), 207 deletions(-)

diff --git a/notebooks/AGIPD/PlotFromCalDB_AGIPD_NBC.ipynb b/notebooks/AGIPD/PlotFromCalDB_AGIPD_NBC.ipynb
index 7f4b500b3..3d9032582 100644
--- a/notebooks/AGIPD/PlotFromCalDB_AGIPD_NBC.ipynb
+++ b/notebooks/AGIPD/PlotFromCalDB_AGIPD_NBC.ipynb
@@ -21,21 +21,21 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 1,
+   "execution_count": null,
    "metadata": {},
    "outputs": [],
    "source": [
     "cluster_profile = \"noDB\"  # The ipcluster profile to use\n",
     "start_date = \"2019-01-01\"  # Date to start investigation interval from\n",
-    "end_date = \"2019-12-12\"  # Date to end investigation interval at, can be \"now\"\n",
+    "end_date = \"NOW\"  # Date to end investigation interval at, can be \"now\"\n",
     "nconstants = 20 # Number of time stamps to plot. If not 0, overcome start_date.\n",
-    "constants = [\"Noise\", \"SlopesFF\", \"SlopesPC\", \"Offset\"]  # Constants to plot\n",
+    "constants = [\"Noise\", \"Offset\", \"SlopesFF\", \"SlopesPC\"]  # Constants to plot\n",
     "modules = [1]  # Modules, set to -1 for all, range allowed\n",
-    "bias_voltages = [300, 500]  # Bias voltage\n",
-    "mem_cells = [128, 176, 202, 250]  # Number of used memory cells. Typically: 4,32,64,128,176.\n",
+    "bias_voltages = [300]  # Bias voltage\n",
+    "mem_cells = [250]  # Number of used memory cells. Typically: 4,32,64,128,176.\n",
     "acquisition_rate = [0.0, 1.1, 2.2, 4.5]\n",
     "photon_energy = 9.2  # Photon energy of the beam\n",
-    "out_folder = \"/gpfs/exfel/data/scratch/karnem/test_AGIPD/\"  # Output folder, required\n",
+    "out_folder = \"/gpfs/exfel/data/scratch/karnem/test_AGIPD55/\"  # Output folder, required\n",
     "use_existing = \"\" # If not empty, constants stored in given folder will be used\n",
     "cal_db_timeout = 120000 # timeout on caldb requests\",\n",
     "adu_to_photon = 33.17 # ADU to photon conversion factor (8000 / 3.6 / 67.)\n",
@@ -50,12 +50,13 @@
     "range_noise_e = [85., 500., 85., 500.] # plotting range for noise in [e-]: high gain l, r, medium gain l, r \n",
     "range_slopesPC = [22.0, 27.0, -0.5, 1.5] # plotting range for slope PC: high gain l, r, medium gain l, r \n",
     "range_slopesFF = [0.8, 1.2, 0.6, 1.2] # plotting range for slope FF: high gain l, r, medium gain l, r \n",
-    "plot_range = 3 # range for plotting in units of median absolute deviations"
+    "plot_range = 3 # range for plotting in units of median absolute deviations\n",
+    "x_labels = ['Acquisition rate', 'Memory cells'] # parameters to be shown on X axis"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 2,
+   "execution_count": null,
    "metadata": {
     "scrolled": true
    },
@@ -79,21 +80,9 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 3,
+   "execution_count": null,
    "metadata": {},
-   "outputs": [
-    {
-     "name": "stdout",
-     "output_type": "stream",
-     "text": [
-      "Bad pixels data:  {'SlopesFF': 'BadPixelsFF', 'SlopesPC': 'BadPixelsPC', 'Noise': 'BadPixelsDark', 'Offset': 'BadPixelsDark'}\n",
-      "CalDB Interface: tcp://max-exfl016:8015#8025\n",
-      "Start time at:  2019-01-01 00:00:00\n",
-      "End time at:  2019-12-12 00:00:00\n",
-      "Modules:  ['Q1M2']\n"
-     ]
-    }
-   ],
+   "outputs": [],
    "source": [
     "# Prepare variables\n",
     "nMem = max(mem_cells) # Number of mem Cells to store\n",
@@ -133,17 +122,9 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 4,
+   "execution_count": null,
    "metadata": {},
-   "outputs": [
-    {
-     "name": "stdout",
-     "output_type": "stream",
-     "text": [
-      "[{'bias_voltage': 300, 'module': 'Q1M2', 'mem_cells': 128, 'acquisition_rate': None}, {'bias_voltage': 300, 'module': 'Q1M2', 'mem_cells': 128, 'acquisition_rate': 1.1}, {'bias_voltage': 300, 'module': 'Q1M2', 'mem_cells': 128, 'acquisition_rate': 2.2}, {'bias_voltage': 300, 'module': 'Q1M2', 'mem_cells': 128, 'acquisition_rate': 4.5}, {'bias_voltage': 300, 'module': 'Q1M2', 'mem_cells': 176, 'acquisition_rate': None}, {'bias_voltage': 300, 'module': 'Q1M2', 'mem_cells': 176, 'acquisition_rate': 1.1}, {'bias_voltage': 300, 'module': 'Q1M2', 'mem_cells': 176, 'acquisition_rate': 2.2}, {'bias_voltage': 300, 'module': 'Q1M2', 'mem_cells': 176, 'acquisition_rate': 4.5}, {'bias_voltage': 300, 'module': 'Q1M2', 'mem_cells': 202, 'acquisition_rate': None}, {'bias_voltage': 300, 'module': 'Q1M2', 'mem_cells': 202, 'acquisition_rate': 1.1}, {'bias_voltage': 300, 'module': 'Q1M2', 'mem_cells': 202, 'acquisition_rate': 2.2}, {'bias_voltage': 300, 'module': 'Q1M2', 'mem_cells': 202, 'acquisition_rate': 4.5}, {'bias_voltage': 300, 'module': 'Q1M2', 'mem_cells': 250, 'acquisition_rate': None}, {'bias_voltage': 300, 'module': 'Q1M2', 'mem_cells': 250, 'acquisition_rate': 1.1}, {'bias_voltage': 300, 'module': 'Q1M2', 'mem_cells': 250, 'acquisition_rate': 2.2}, {'bias_voltage': 300, 'module': 'Q1M2', 'mem_cells': 250, 'acquisition_rate': 4.5}, {'bias_voltage': 500, 'module': 'Q1M2', 'mem_cells': 128, 'acquisition_rate': None}, {'bias_voltage': 500, 'module': 'Q1M2', 'mem_cells': 128, 'acquisition_rate': 1.1}, {'bias_voltage': 500, 'module': 'Q1M2', 'mem_cells': 128, 'acquisition_rate': 2.2}, {'bias_voltage': 500, 'module': 'Q1M2', 'mem_cells': 128, 'acquisition_rate': 4.5}, {'bias_voltage': 500, 'module': 'Q1M2', 'mem_cells': 176, 'acquisition_rate': None}, {'bias_voltage': 500, 'module': 'Q1M2', 'mem_cells': 176, 'acquisition_rate': 1.1}, {'bias_voltage': 500, 'module': 'Q1M2', 'mem_cells': 176, 'acquisition_rate': 2.2}, {'bias_voltage': 500, 'module': 'Q1M2', 'mem_cells': 176, 'acquisition_rate': 4.5}, {'bias_voltage': 500, 'module': 'Q1M2', 'mem_cells': 202, 'acquisition_rate': None}, {'bias_voltage': 500, 'module': 'Q1M2', 'mem_cells': 202, 'acquisition_rate': 1.1}, {'bias_voltage': 500, 'module': 'Q1M2', 'mem_cells': 202, 'acquisition_rate': 2.2}, {'bias_voltage': 500, 'module': 'Q1M2', 'mem_cells': 202, 'acquisition_rate': 4.5}, {'bias_voltage': 500, 'module': 'Q1M2', 'mem_cells': 250, 'acquisition_rate': None}, {'bias_voltage': 500, 'module': 'Q1M2', 'mem_cells': 250, 'acquisition_rate': 1.1}, {'bias_voltage': 500, 'module': 'Q1M2', 'mem_cells': 250, 'acquisition_rate': 2.2}, {'bias_voltage': 500, 'module': 'Q1M2', 'mem_cells': 250, 'acquisition_rate': 4.5}]\n"
-     ]
-    }
-   ],
+   "outputs": [],
    "source": [
     "parameter_list = combine_lists(bias_voltages, modules, mem_cells, acquisition_rate,\n",
     "                               names = ['bias_voltage', 'module', 'mem_cells', 'acquisition_rate'])\n",
@@ -152,91 +133,11 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 5,
+   "execution_count": null,
    "metadata": {
     "scrolled": false
    },
-   "outputs": [
-    {
-     "name": "stdout",
-     "output_type": "stream",
-     "text": [
-      "Request:  Noise with paramters: {'bias_voltage': 300, 'module': 'Q1M2', 'mem_cells': 128, 'acquisition_rate': None}\n",
-      "constantDark: BadPixelsDark\n",
-      "Item:  {'id': 6990, 'name': '20190220_072419_sIdx=0', 'file_name': 'cal.1550647458.8201447.h5', 'path_to_file': 'xfel/cal/agipd-type/agipd_siv1_agipdv11_m315/', 'data_set_name': '/AGIPD_SIV1_AGIPDV11_M315/Noise/0', 'flg_deployed': True, 'flg_good_quality': True, 'begin_validity_at': '2019-02-19T15:54:20.000+01:00', 'end_validity_at': None, 'begin_at': '2019-02-19T15:54:20.000+01:00', 'start_idx': 0, 'end_idx': 0, 'raw_data_location': '', 'description': '', 'calibration_constant': {'id': 913, 'name': 'AGIPD-Type_Noise_AGIPD DefJAwEUE0Km+', 'flg_auto_approve': True, 'flg_available': True, 'description': 'Per-pixel (per-memory cell) noise', 'device_type_id': 2, 'calibration_id': 2, 'condition_id': 271}, 'physical_device': {'id': 58, 'name': 'AGIPD_SIV1_AGIPDV11_M315', 'device_type_id': 2, 'flg_available': True, 'parent_id': None, 'description': ''}}\n",
-      "Found constant Noise: begin at 2019-02-19 15:54:20+01:00\n",
-      "Found bad pixels at 2019-02-19 15:54:20+01:00\n",
-      "Item:  {'id': 5471, 'name': '20181027_075853_sIdx=0', 'file_name': 'cal.1540627132.6379695.h5', 'path_to_file': 'xfel/cal/agipd-type/agipd_siv1_agipdv11_m315/', 'data_set_name': '/AGIPD_SIV1_AGIPDV11_M315/Noise/0', 'flg_deployed': True, 'flg_good_quality': True, 'begin_validity_at': '2018-10-27T09:20:58.000+02:00', 'end_validity_at': None, 'begin_at': '2018-10-27T09:20:58.000+02:00', 'start_idx': 0, 'end_idx': 0, 'raw_data_location': '', 'description': '', 'calibration_constant': {'id': 913, 'name': 'AGIPD-Type_Noise_AGIPD DefJAwEUE0Km+', 'flg_auto_approve': True, 'flg_available': True, 'description': 'Per-pixel (per-memory cell) noise', 'device_type_id': 2, 'calibration_id': 2, 'condition_id': 271}, 'physical_device': {'id': 58, 'name': 'AGIPD_SIV1_AGIPDV11_M315', 'device_type_id': 2, 'flg_available': True, 'parent_id': None, 'description': ''}}\n",
-      "Found constant Noise: begin at 2018-10-27 09:20:58+02:00\n",
-      "Found bad pixels at 2018-10-27 09:20:58+02:00\n",
-      "Item:  {'id': 6791, 'name': '20181213_160158_sIdx=0', 'file_name': 'cal.1544716917.4122818.h5', 'path_to_file': 'xfel/cal/agipd-type/agipd_siv1_agipdv11_m315/', 'data_set_name': '/AGIPD_SIV1_AGIPDV11_M315/Noise/0', 'flg_deployed': True, 'flg_good_quality': True, 'begin_validity_at': '2018-10-22T22:24:16.000+02:00', 'end_validity_at': None, 'begin_at': '2018-10-22T22:24:16.000+02:00', 'start_idx': 0, 'end_idx': 0, 'raw_data_location': '', 'description': '', 'calibration_constant': {'id': 913, 'name': 'AGIPD-Type_Noise_AGIPD DefJAwEUE0Km+', 'flg_auto_approve': True, 'flg_available': True, 'description': 'Per-pixel (per-memory cell) noise', 'device_type_id': 2, 'calibration_id': 2, 'condition_id': 271}, 'physical_device': {'id': 58, 'name': 'AGIPD_SIV1_AGIPDV11_M315', 'device_type_id': 2, 'flg_available': True, 'parent_id': None, 'description': ''}}\n",
-      "Found constant Noise: begin at 2018-10-22 22:24:16+02:00\n",
-      "Found bad pixels at 2018-10-22 22:24:16+02:00\n",
-      "Item:  {'id': 6834, 'name': '20190207_135120_sIdx=0', 'file_name': 'cal.1549547479.2884257.h5', 'path_to_file': 'xfel/cal/agipd-type/agipd_siv1_agipdv11_m315/', 'data_set_name': '/AGIPD_SIV1_AGIPDV11_M315/Noise/0', 'flg_deployed': True, 'flg_good_quality': True, 'begin_validity_at': '2018-10-21T20:55:02.000+02:00', 'end_validity_at': None, 'begin_at': '2018-10-21T20:55:02.000+02:00', 'start_idx': 0, 'end_idx': 0, 'raw_data_location': '', 'description': '', 'calibration_constant': {'id': 913, 'name': 'AGIPD-Type_Noise_AGIPD DefJAwEUE0Km+', 'flg_auto_approve': True, 'flg_available': True, 'description': 'Per-pixel (per-memory cell) noise', 'device_type_id': 2, 'calibration_id': 2, 'condition_id': 271}, 'physical_device': {'id': 58, 'name': 'AGIPD_SIV1_AGIPDV11_M315', 'device_type_id': 2, 'flg_available': True, 'parent_id': None, 'description': ''}}\n",
-      "Found constant Noise: begin at 2018-10-21 20:55:02+02:00\n",
-      "Found bad pixels at 2018-10-21 20:55:02+02:00\n",
-      "Item:  {'id': 4670, 'name': '20180923_021047_sIdx=0', 'file_name': 'cal.1537668646.6458402.h5', 'path_to_file': 'xfel/cal/agipd-type/agipd_siv1_agipdv11_m315/', 'data_set_name': '/AGIPD_SIV1_AGIPDV11_M315/Noise/0', 'flg_deployed': True, 'flg_good_quality': True, 'begin_validity_at': '2018-09-23T04:10:45.000+02:00', 'end_validity_at': None, 'begin_at': '2018-09-23T04:10:45.000+02:00', 'start_idx': 0, 'end_idx': 0, 'raw_data_location': '', 'description': '', 'calibration_constant': {'id': 913, 'name': 'AGIPD-Type_Noise_AGIPD DefJAwEUE0Km+', 'flg_auto_approve': True, 'flg_available': True, 'description': 'Per-pixel (per-memory cell) noise', 'device_type_id': 2, 'calibration_id': 2, 'condition_id': 271}, 'physical_device': {'id': 58, 'name': 'AGIPD_SIV1_AGIPDV11_M315', 'device_type_id': 2, 'flg_available': True, 'parent_id': None, 'description': ''}}\n",
-      "Found constant Noise: begin at 2018-09-23 04:10:45+02:00\n",
-      "Found bad pixels at 2018-09-23 04:10:50+02:00\n",
-      "Item:  {'id': 4546, 'name': '20180923_000251_sIdx=0', 'file_name': 'cal.1537660970.398414.h5', 'path_to_file': 'xfel/cal/agipd-type/agipd_siv1_agipdv11_m315/', 'data_set_name': '/AGIPD_SIV1_AGIPDV11_M315/Noise/0', 'flg_deployed': True, 'flg_good_quality': True, 'begin_validity_at': '2018-09-23T02:02:49.000+02:00', 'end_validity_at': None, 'begin_at': '2018-09-23T02:02:49.000+02:00', 'start_idx': 0, 'end_idx': 0, 'raw_data_location': '', 'description': '', 'calibration_constant': {'id': 913, 'name': 'AGIPD-Type_Noise_AGIPD DefJAwEUE0Km+', 'flg_auto_approve': True, 'flg_available': True, 'description': 'Per-pixel (per-memory cell) noise', 'device_type_id': 2, 'calibration_id': 2, 'condition_id': 271}, 'physical_device': {'id': 58, 'name': 'AGIPD_SIV1_AGIPDV11_M315', 'device_type_id': 2, 'flg_available': True, 'parent_id': None, 'description': ''}}\n",
-      "Found constant Noise: begin at 2018-09-23 02:02:49+02:00\n",
-      "Found bad pixels at 2018-09-23 02:02:57+02:00\n",
-      "Item:  {'id': 4482, 'name': '20180922_235703_sIdx=0', 'file_name': 'cal.1537660622.794079.h5', 'path_to_file': 'xfel/cal/agipd-type/agipd_siv1_agipdv11_m315/', 'data_set_name': '/AGIPD_SIV1_AGIPDV11_M315/Noise/0', 'flg_deployed': True, 'flg_good_quality': True, 'begin_validity_at': '2018-09-23T01:57:01.000+02:00', 'end_validity_at': None, 'begin_at': '2018-09-23T01:57:01.000+02:00', 'start_idx': 0, 'end_idx': 0, 'raw_data_location': '', 'description': '', 'calibration_constant': {'id': 913, 'name': 'AGIPD-Type_Noise_AGIPD DefJAwEUE0Km+', 'flg_auto_approve': True, 'flg_available': True, 'description': 'Per-pixel (per-memory cell) noise', 'device_type_id': 2, 'calibration_id': 2, 'condition_id': 271}, 'physical_device': {'id': 58, 'name': 'AGIPD_SIV1_AGIPDV11_M315', 'device_type_id': 2, 'flg_available': True, 'parent_id': None, 'description': ''}}\n",
-      "Found constant Noise: begin at 2018-09-23 01:57:01+02:00\n",
-      "Found bad pixels at 2018-09-23 01:57:06+02:00\n",
-      "Item:  {'id': 5269, 'name': '20181025_061038_sIdx=0', 'file_name': 'cal.1540447837.275528.h5', 'path_to_file': 'xfel/cal/agipd-type/agipd_siv1_agipdv11_m315/', 'data_set_name': '/AGIPD_SIV1_AGIPDV11_M315/Noise/0', 'flg_deployed': True, 'flg_good_quality': True, 'begin_validity_at': '2018-09-02T16:25:41.000+02:00', 'end_validity_at': None, 'begin_at': '2018-09-02T16:25:41.000+02:00', 'start_idx': 0, 'end_idx': 0, 'raw_data_location': '', 'description': '', 'calibration_constant': {'id': 913, 'name': 'AGIPD-Type_Noise_AGIPD DefJAwEUE0Km+', 'flg_auto_approve': True, 'flg_available': True, 'description': 'Per-pixel (per-memory cell) noise', 'device_type_id': 2, 'calibration_id': 2, 'condition_id': 271}, 'physical_device': {'id': 58, 'name': 'AGIPD_SIV1_AGIPDV11_M315', 'device_type_id': 2, 'flg_available': True, 'parent_id': None, 'description': ''}}\n",
-      "Found constant Noise: begin at 2018-09-02 16:25:41+02:00\n",
-      "Found bad pixels at 2018-09-02 16:25:41+02:00\n",
-      "Item:  {'id': 3431, 'name': '20180901_173920_sIdx=0', 'file_name': 'cal.1535823559.5818477.h5', 'path_to_file': 'xfel/cal/agipd-type/agipd_siv1_agipdv11_m315/', 'data_set_name': '/AGIPD_SIV1_AGIPDV11_M315/Noise/0', 'flg_deployed': True, 'flg_good_quality': True, 'begin_validity_at': '2018-09-01T19:39:13.000+02:00', 'end_validity_at': None, 'begin_at': '2018-09-01T19:39:13.000+02:00', 'start_idx': 0, 'end_idx': 0, 'raw_data_location': '', 'description': '', 'calibration_constant': {'id': 913, 'name': 'AGIPD-Type_Noise_AGIPD DefJAwEUE0Km+', 'flg_auto_approve': True, 'flg_available': True, 'description': 'Per-pixel (per-memory cell) noise', 'device_type_id': 2, 'calibration_id': 2, 'condition_id': 271}, 'physical_device': {'id': 58, 'name': 'AGIPD_SIV1_AGIPDV11_M315', 'device_type_id': 2, 'flg_available': True, 'parent_id': None, 'description': ''}}\n",
-      "Found constant Noise: begin at 2018-09-01 19:39:13+02:00\n",
-      "Found bad pixels at 2018-09-01 19:39:29+02:00\n",
-      "Item:  {'id': 3229, 'name': '20180830_164924_sIdx=0', 'file_name': 'cal.1535647763.2838182.h5', 'path_to_file': 'xfel/cal/agipd-type/agipd_siv1_agipdv11_m315/', 'data_set_name': '/AGIPD_SIV1_AGIPDV11_M315/Noise/0', 'flg_deployed': True, 'flg_good_quality': True, 'begin_validity_at': '2018-08-30T18:49:21.000+02:00', 'end_validity_at': None, 'begin_at': '2018-08-30T18:49:21.000+02:00', 'start_idx': 0, 'end_idx': 0, 'raw_data_location': '', 'description': '', 'calibration_constant': {'id': 913, 'name': 'AGIPD-Type_Noise_AGIPD DefJAwEUE0Km+', 'flg_auto_approve': True, 'flg_available': True, 'description': 'Per-pixel (per-memory cell) noise', 'device_type_id': 2, 'calibration_id': 2, 'condition_id': 271}, 'physical_device': {'id': 58, 'name': 'AGIPD_SIV1_AGIPDV11_M315', 'device_type_id': 2, 'flg_available': True, 'parent_id': None, 'description': ''}}\n",
-      "Found constant Noise: begin at 2018-08-30 18:49:21+02:00\n",
-      "Found bad pixels at 2018-08-30 18:49:26+02:00\n",
-      "Item:  {'id': 6413, 'name': '20181210_082033_sIdx=0', 'file_name': 'cal.1544430032.7715538.h5', 'path_to_file': 'xfel/cal/agipd-type/agipd_siv1_agipdv11_m315/', 'data_set_name': '/AGIPD_SIV1_AGIPDV11_M315/Noise/0', 'flg_deployed': True, 'flg_good_quality': True, 'begin_validity_at': '2018-01-29T17:10:23.000+01:00', 'end_validity_at': None, 'begin_at': '2018-01-29T17:10:23.000+01:00', 'start_idx': 0, 'end_idx': 0, 'raw_data_location': '', 'description': '', 'calibration_constant': {'id': 913, 'name': 'AGIPD-Type_Noise_AGIPD DefJAwEUE0Km+', 'flg_auto_approve': True, 'flg_available': True, 'description': 'Per-pixel (per-memory cell) noise', 'device_type_id': 2, 'calibration_id': 2, 'condition_id': 271}, 'physical_device': {'id': 58, 'name': 'AGIPD_SIV1_AGIPDV11_M315', 'device_type_id': 2, 'flg_available': True, 'parent_id': None, 'description': ''}}\n",
-      "Found constant Noise: begin at 2018-01-29 17:10:23+01:00\n",
-      "Found bad pixels at 2018-01-29 17:10:23+01:00\n",
-      "Item:  {'id': 6348, 'name': '20181210_081739_sIdx=0', 'file_name': 'cal.1544429858.2109814.h5', 'path_to_file': 'xfel/cal/agipd-type/agipd_siv1_agipdv11_m315/', 'data_set_name': '/AGIPD_SIV1_AGIPDV11_M315/Noise/0', 'flg_deployed': True, 'flg_good_quality': True, 'begin_validity_at': '2017-12-04T20:15:40.000+01:00', 'end_validity_at': None, 'begin_at': '2017-12-04T20:15:40.000+01:00', 'start_idx': 0, 'end_idx': 0, 'raw_data_location': '', 'description': '', 'calibration_constant': {'id': 913, 'name': 'AGIPD-Type_Noise_AGIPD DefJAwEUE0Km+', 'flg_auto_approve': True, 'flg_available': True, 'description': 'Per-pixel (per-memory cell) noise', 'device_type_id': 2, 'calibration_id': 2, 'condition_id': 271}, 'physical_device': {'id': 58, 'name': 'AGIPD_SIV1_AGIPDV11_M315', 'device_type_id': 2, 'flg_available': True, 'parent_id': None, 'description': ''}}\n",
-      "Bad pixels are not found!\n",
-      "Item:  {'id': 6590, 'name': '20181210_092654_sIdx=0', 'file_name': 'cal.1544434013.2191806.h5', 'path_to_file': 'xfel/cal/agipd-type/agipd_siv1_agipdv11_m315/', 'data_set_name': '/AGIPD_SIV1_AGIPDV11_M315/Noise/0', 'flg_deployed': True, 'flg_good_quality': True, 'begin_validity_at': '2017-10-10T19:00:34.000+02:00', 'end_validity_at': None, 'begin_at': '2017-10-10T19:00:34.000+02:00', 'start_idx': 0, 'end_idx': 0, 'raw_data_location': '', 'description': '', 'calibration_constant': {'id': 913, 'name': 'AGIPD-Type_Noise_AGIPD DefJAwEUE0Km+', 'flg_auto_approve': True, 'flg_available': True, 'description': 'Per-pixel (per-memory cell) noise', 'device_type_id': 2, 'calibration_id': 2, 'condition_id': 271}, 'physical_device': {'id': 58, 'name': 'AGIPD_SIV1_AGIPDV11_M315', 'device_type_id': 2, 'flg_available': True, 'parent_id': None, 'description': ''}}\n",
-      "Found constant Noise: begin at 2017-10-10 19:00:34+02:00\n",
-      "Found bad pixels at 2017-10-10 19:00:34+02:00\n",
-      "Item:  {'id': 6509, 'name': '20181210_085802_sIdx=0', 'file_name': 'cal.1544432281.1941464.h5', 'path_to_file': 'xfel/cal/agipd-type/agipd_siv1_agipdv11_m315/', 'data_set_name': '/AGIPD_SIV1_AGIPDV11_M315/Noise/0', 'flg_deployed': True, 'flg_good_quality': True, 'begin_validity_at': '2017-09-19T15:10:49.000+02:00', 'end_validity_at': None, 'begin_at': '2017-09-19T15:10:49.000+02:00', 'start_idx': 0, 'end_idx': 0, 'raw_data_location': '', 'description': '', 'calibration_constant': {'id': 913, 'name': 'AGIPD-Type_Noise_AGIPD DefJAwEUE0Km+', 'flg_auto_approve': True, 'flg_available': True, 'description': 'Per-pixel (per-memory cell) noise', 'device_type_id': 2, 'calibration_id': 2, 'condition_id': 271}, 'physical_device': {'id': 58, 'name': 'AGIPD_SIV1_AGIPDV11_M315', 'device_type_id': 2, 'flg_available': True, 'parent_id': None, 'description': ''}}\n",
-      "Found constant Noise: begin at 2017-09-19 15:10:49+02:00\n",
-      "Found bad pixels at 2017-09-19 15:10:49+02:00\n",
-      "Item:  {'id': 6543, 'name': '20181210_085904_sIdx=0', 'file_name': 'cal.1544432342.903418.h5', 'path_to_file': 'xfel/cal/agipd-type/agipd_siv1_agipdv11_m315/', 'data_set_name': '/AGIPD_SIV1_AGIPDV11_M315/Noise/0', 'flg_deployed': True, 'flg_good_quality': True, 'begin_validity_at': '2017-09-15T23:33:29.000+02:00', 'end_validity_at': None, 'begin_at': '2017-09-15T23:33:29.000+02:00', 'start_idx': 0, 'end_idx': 0, 'raw_data_location': '', 'description': '', 'calibration_constant': {'id': 913, 'name': 'AGIPD-Type_Noise_AGIPD DefJAwEUE0Km+', 'flg_auto_approve': True, 'flg_available': True, 'description': 'Per-pixel (per-memory cell) noise', 'device_type_id': 2, 'calibration_id': 2, 'condition_id': 271}, 'physical_device': {'id': 58, 'name': 'AGIPD_SIV1_AGIPDV11_M315', 'device_type_id': 2, 'flg_available': True, 'parent_id': None, 'description': ''}}\n",
-      "Found constant Noise: begin at 2017-09-15 23:33:29+02:00\n",
-      "Found bad pixels at 2017-09-15 23:33:29+02:00\n",
-      "Request:  Noise with paramters: {'bias_voltage': 300, 'module': 'Q1M2', 'mem_cells': 128, 'acquisition_rate': 1.1}\n"
-     ]
-    },
-    {
-     "name": "stdout",
-     "output_type": "stream",
-     "text": [
-      "constantDark: BadPixelsDark\n",
-      "Request:  Noise with paramters: {'bias_voltage': 300, 'module': 'Q1M2', 'mem_cells': 128, 'acquisition_rate': 2.2}\n"
-     ]
-    },
-    {
-     "ename": "KeyboardInterrupt",
-     "evalue": "",
-     "output_type": "error",
-     "traceback": [
-      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
-      "\u001b[0;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
-      "\u001b[0;32m<ipython-input-5-a602d73b9ab9>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m     38\u001b[0m                            \u001b[0mtimeout\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcal_db_timeout\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     39\u001b[0m                            \u001b[0mmeta_only\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 40\u001b[0;31m                            version_info=True)\n\u001b[0m\u001b[1;32m     41\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     42\u001b[0m         \u001b[0;31m# Request BP constant versions\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
-      "\u001b[0;32m/gpfs/exfel/data/scratch/karnem/calibration3/pycalibration/cal_tools/cal_tools/tools.py\u001b[0m in \u001b[0;36mget_from_db\u001b[0;34m(device, constant, condition, empty_constant, cal_db_interface, creation_time, verbosity, timeout, ntries, meta_only, version_info)\u001b[0m\n\u001b[1;32m    512\u001b[0m                 r = metadata.retrieve(this_interface, timeout=timeout,\n\u001b[1;32m    513\u001b[0m                                       \u001b[0mwhen\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mwhen\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmeta_only\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mmeta_only\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 514\u001b[0;31m                                       version_info=version_info)\n\u001b[0m\u001b[1;32m    515\u001b[0m                 \u001b[0;32mif\u001b[0m \u001b[0mversion_info\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    516\u001b[0m                     \u001b[0;32mreturn\u001b[0m \u001b[0mr\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
-      "\u001b[0;32m~/.local/lib/python3.6/site-packages/iCalibrationDB/meta_data.py\u001b[0m in \u001b[0;36mretrieve\u001b[0;34m(self, receiver, when, silent, timeout, meta_only, version_info)\u001b[0m\n\u001b[1;32m    285\u001b[0m             \u001b[0msock\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconnect\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mreceiver\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    286\u001b[0m             \u001b[0msock\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msend_pyobj\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 287\u001b[0;31m             \u001b[0mresp\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0msock\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrecv_pyobj\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    288\u001b[0m         \u001b[0;32mfinally\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    289\u001b[0m             \u001b[0;32mdel\u001b[0m \u001b[0msock\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
-      "\u001b[0;32m/software/anaconda3/5.2/lib/python3.6/site-packages/zmq/sugar/socket.py\u001b[0m in \u001b[0;36mrecv_pyobj\u001b[0;34m(self, flags)\u001b[0m\n\u001b[1;32m    620\u001b[0m             \u001b[0;32mfor\u001b[0m \u001b[0many\u001b[0m \u001b[0mof\u001b[0m \u001b[0mthe\u001b[0m \u001b[0mreasons\u001b[0m \u001b[0;34m:\u001b[0m\u001b[0mfunc\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;31m`\u001b[0m\u001b[0;34m~\u001b[0m\u001b[0mSocket\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrecv\u001b[0m\u001b[0;31m`\u001b[0m \u001b[0mmight\u001b[0m \u001b[0mfail\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    621\u001b[0m         \"\"\"\n\u001b[0;32m--> 622\u001b[0;31m         \u001b[0mmsg\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrecv\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mflags\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    623\u001b[0m         \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_deserialize\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmsg\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mpickle\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mloads\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    624\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
-      "\u001b[0;32mzmq/backend/cython/socket.pyx\u001b[0m in \u001b[0;36mzmq.backend.cython.socket.Socket.recv\u001b[0;34m()\u001b[0m\n",
-      "\u001b[0;32mzmq/backend/cython/socket.pyx\u001b[0m in \u001b[0;36mzmq.backend.cython.socket.Socket.recv\u001b[0;34m()\u001b[0m\n",
-      "\u001b[0;32mzmq/backend/cython/socket.pyx\u001b[0m in \u001b[0;36mzmq.backend.cython.socket._recv_copy\u001b[0;34m()\u001b[0m\n",
-      "\u001b[0;32m/software/anaconda3/5.2/lib/python3.6/site-packages/zmq/backend/cython/checkrc.pxd\u001b[0m in \u001b[0;36mzmq.backend.cython.checkrc._check_rc\u001b[0;34m()\u001b[0m\n",
-      "\u001b[0;31mKeyboardInterrupt\u001b[0m: "
-     ]
-    }
-   ],
+   "outputs": [],
    "source": [
     "# Retrieve list of meta-data\n",
     "constant_versions = []\n",
@@ -274,11 +175,14 @@
     "                           copy.deepcopy(mcond), None,\n",
     "                           cal_db_interface,\n",
     "                           creation_time=start,\n",
-    "                           verbosity=0,\n",
+    "                           verbosity=2,\n",
     "                           timeout=cal_db_timeout,\n",
     "                           meta_only=True,\n",
     "                           version_info=True)\n",
     "\n",
+    "        if not isinstance(data, list):\n",
+    "            continue\n",
+    "        \n",
     "        # Request BP constant versions\n",
     "        print('constantDark:', constantsDark[const], )        \n",
     "        dataBP = get_from_db(getattr(det, pars['module']),\n",
@@ -287,17 +191,13 @@
     "                             copy.deepcopy(mcond), None,\n",
     "                             cal_db_interface,\n",
     "                             creation_time=start,\n",
-    "                             verbosity=0,\n",
+    "                             verbosity=2,\n",
     "                             timeout=cal_db_timeout,\n",
     "                             meta_only=True,\n",
     "                             version_info=True)\n",
     "        \n",
-    "        if not isinstance(data, list) or not isinstance(dataBP, list):\n",
-    "            continue\n",
-    "            \n",
-    "        found_BPmatch = False\n",
     "        for d in data:\n",
-    "            print('Item: ', d)\n",
+    "            # print('Item: ', d)\n",
     "            # Match proper BP constant version\n",
     "            # and get constant version within\n",
     "            # requested time range\n",
@@ -313,6 +213,10 @@
     "                \n",
     "            closest_BP = None\n",
     "            closest_BPtime = None\n",
+    "            found_BPmatch = False\n",
+    "                \n",
+    "            if not isinstance(dataBP, list):\n",
+    "                dataBP = []\n",
     "            \n",
     "            for dBP in dataBP:\n",
     "                if dBP is None:\n",
@@ -349,10 +253,15 @@
     "                    constantBP_versions.append(dBP)\n",
     "                    constant_versions.append(d)\n",
     "                    constant_parameters.append(copy.deepcopy(pars))\n",
-    "                    found_BPmatch = False\n",
     "                    break\n",
     "                    \n",
-    "print('Number of retrieved constants with a bad pixel match is {}'.format(len(constant_versions)))"
+    "            if not found_BPmatch:\n",
+    "                print('Bad pixels are not matched')\n",
+    "                constantBP_versions.append(None)\n",
+    "                constant_versions.append(d)\n",
+    "                constant_parameters.append(copy.deepcopy(pars))\n",
+    "                    \n",
+    "print('Number of retrieved constants {}'.format(len(constant_versions)))"
    ]
   },
   {
@@ -382,6 +291,9 @@
     "            data = data[:, :, :, 0][..., None]\n",
     "        else:\n",
     "            data = data[..., None]\n",
+    "            \n",
+    "        if data.shape[2]<3:\n",
+    "            data = data[:,:,0,None]\n",
     "\n",
     "    if not isBP:\n",
     "        if data.shape[0] != 128:\n",
@@ -405,7 +317,7 @@
     "\n",
     "\n",
     "ret_constants = {}\n",
-    "constand_data = ConstantMetaData()\n",
+    "constant_data = ConstantMetaData()\n",
     "constant_BP = ConstantMetaData()\n",
     "# sort over begin_at\n",
     "idxs, _ = zip(*sorted(enumerate(constant_versions), \n",
@@ -423,41 +335,46 @@
     "    if nconstants>0 and len(ret_constants[const][qm])>=nconstants:\n",
     "        continue\n",
     "            \n",
-    "    constand_data.retrieve_from_version_info(constant_versions[i])\n",
-    "    constant_BP.retrieve_from_version_info(constantBP_versions[i])\n",
-    "    \n",
-    "    cdata = constand_data.calibration_constant.data\n",
-    "    cdataBP = constant_BP.calibration_constant.data\n",
-    "    ctime = constand_data.calibration_constant_version.begin_at  \n",
-    "   \n",
-    "    print(\"constant: {}, module {}, begin_at {}\".format(const, qm, ctime))\n",
     "\n",
+    "    constant_data.retrieve_from_version_info(constant_versions[i])\n",
+    "    cdata = constant_data.calibration_constant.data\n",
+    "    ctime = constant_data.calibration_constant_version.begin_at \n",
     "    cdata = modify_const(const, cdata)\n",
-    "    cdataBP = modify_const(const, cdataBP, True)\n",
+    "    print(\"constant: {}, module {}, begin_at {}\".format(const, qm, ctime))\n",
     "\n",
-    "    if cdataBP.shape != cdata.shape:\n",
-    "        print('Wrong bad pixel shape! {}, expected {}'.format(cdataBP.shape, cdata.shape))\n",
-    "        continue\n",
+    "    if constantBP_versions[i]:\n",
+    "        constant_BP.retrieve_from_version_info(constantBP_versions[i])\n",
+    "        cdataBP = constant_BP.calibration_constant.data\n",
+    "        cdataBP = modify_const(const, cdataBP, True)\n",
     "\n",
-    "    # Apply bad pixel mask\n",
-    "    cdataABP = np.copy(cdata)\n",
-    "    cdataABP[cdataBP > 0] = np.nan\n",
+    "        if cdataBP.shape != cdata.shape:\n",
+    "            print('Wrong bad pixel shape! {}, expected {}'.format(cdataBP.shape, cdata.shape))\n",
+    "            cdataBP = np.full_like(cdata, -1)\n",
     "\n",
-    "    # Create superpixels for constants with BP applied\n",
-    "    cdataABP = get_rebined(cdataABP, spShape)\n",
-    "    toStoreBP = prepare_to_store(np.nanmean(cdataABP, axis=(1, 3)), nMem)\n",
-    "    toStoreBPStd = prepare_to_store(np.nanstd(cdataABP, axis=(1, 3)), nMem)\n",
+    "        # Apply bad pixel mask\n",
+    "        cdataABP = np.copy(cdata)\n",
+    "        cdataABP[cdataBP > 0] = np.nan\n",
     "\n",
-    "    # Prepare number of bad pixels per superpixels\n",
-    "    cdataBP = get_rebined(cdataBP, spShape)\n",
-    "    cdataNBP = prepare_to_store(np.nansum(cdataBP > 0, axis=(1, 3)), nMem)\n",
+    "        # Create superpixels for constants with BP applied\n",
+    "        cdataABP = get_rebined(cdataABP, spShape)\n",
+    "        toStoreBP = prepare_to_store(np.nanmean(cdataABP, axis=(1, 3)), nMem)\n",
+    "        toStoreBPStd = prepare_to_store(np.nanstd(cdataABP, axis=(1, 3)), nMem)\n",
+    "\n",
+    "        # Prepare number of bad pixels per superpixels\n",
+    "        cdataBP = get_rebined(cdataBP, spShape)\n",
+    "        cdataNBP = prepare_to_store(np.nansum(cdataBP > 0, axis=(1, 3)), nMem)\n",
     "\n",
     "    # Create superpixels for constants without BP applied\n",
     "    cdata = get_rebined(cdata, spShape)\n",
     "    toStoreStd = prepare_to_store(np.nanstd(cdata, axis=(1, 3)), nMem)\n",
     "    toStore = prepare_to_store(np.nanmean(cdata, axis=(1, 3)), nMem)\n",
     "    \n",
-    "    dpar = {p.name: p.value for p in constand_data.detector_condition.parameters}\n",
+    "    if not constantBP_versions[i]:\n",
+    "        toStoreBP = np.full_like(toStore, np.nan)\n",
+    "        toStoreBPStd = np.full_like(toStore, np.nan)\n",
+    "        cdataNBP = np.full_like(toStore, np.nan)\n",
+    "    \n",
+    "    dpar = {p.name: p.value for p in constant_data.detector_condition.parameters}\n",
     "\n",
     "    print(\"Store values in dict\", const, qm, ctime)\n",
     "    ret_constants[const][qm].append({'ctime': ctime,\n",
@@ -633,7 +550,7 @@
    "cell_type": "code",
    "execution_count": null,
    "metadata": {
-    "scrolled": true
+    "scrolled": false
    },
    "outputs": [],
    "source": [
@@ -664,7 +581,7 @@
     "                cmdata = np.array(data[\"mdata\"])\n",
     "                for i, tick in enumerate(ctimes_ticks):\n",
     "                    ctimes_ticks[i] = ctimes_ticks[i] + \\\n",
-    "                        ', V={:1.0f}'.format(cmdata[i]['Sensor Bias Voltage']) + \\\n",
+    "                        ', A={}'.format(cmdata[i].get('Acquisition rate', None)) + \\\n",
     "                        ', M={:1.0f}'.format(\n",
     "                        cmdata[i]['Memory cells'])\n",
     "\n",
@@ -700,12 +617,16 @@
     "            # Reshape: ASICs over cells for plotting\n",
     "            pdata = {}\n",
     "            for key in rdata:\n",
+    "                if len(rdata[key].shape)<3:\n",
+    "                    continue\n",
     "                pdata[key] = rdata[key][:, :, :, :nMemToShow].reshape(\n",
     "                    nTimes, nBins).swapaxes(0, 1)\n",
     "\n",
     "            # Summary over ASICs\n",
     "            adata = {}\n",
     "            for key in rdata:\n",
+    "                if len(rdata[key].shape)<3:\n",
+    "                    continue\n",
     "                adata[key] = np.nanmean(rdata[key], axis=(1, 2)).swapaxes(0, 1)\n",
     "\n",
     "            # Plotting\n",
diff --git a/notebooks/LPD/PlotFromCalDB_LPD_NBC.ipynb b/notebooks/LPD/PlotFromCalDB_LPD_NBC.ipynb
index d6eba9461..00c1b59cd 100644
--- a/notebooks/LPD/PlotFromCalDB_LPD_NBC.ipynb
+++ b/notebooks/LPD/PlotFromCalDB_LPD_NBC.ipynb
@@ -26,13 +26,13 @@
    "outputs": [],
    "source": [
     "cluster_profile = \"noDB\"  # The ipcluster profile to use\n",
-    "start_date = \"2018-01-30\"  # Date to start investigation interval from\n",
-    "end_date = \"2018-12-12\"  # Date to end investigation interval at, can be \"now\"\n",
+    "start_date = \"2019-01-30\"  # Date to start investigation interval from\n",
+    "end_date = \"2019-12-12\"  # Date to end investigation interval at, can be \"now\"\n",
     "nconstants = 10 # Number of time stamps to plot. If not 0, overcome start_date.\n",
-    "constants = [\"Offset\", \"Noise\", \"SlopesFF\", \"SlopesCI\"] # constants to plot\n",
+    "constants = [\"Noise\", \"Offset\", \"SlopesFF\", \"SlopesCI\"] # constants to plot\n",
     "modules = [2]  # Modules, set to -1 for all, range allowed\n",
-    "bias_voltages = [250, 500]  # Bias voltage\n",
-    "mem_cells = [128, 256, 512]  # Number of used memory cells.\n",
+    "bias_voltages = [250]  # Bias voltage\n",
+    "mem_cells = [512]  # Number of used memory cells.\n",
     "photon_energy = 9.2  # Photon energy of the beam\n",
     "out_folder = \"/gpfs/exfel/data/scratch/karnem/test_LPD/\"  # Output folder, required\n",
     "use_existing = \"\" # If not empty, constants stored in given folder will be used\n",
@@ -49,7 +49,8 @@
     "range_noise_e = [100., 600., 100., 600.] # plotting range for noise in [e-]: high gain l, r, medium gain l, r \n",
     "range_slopesCI = [0.95, 1.05, 0.0, 0.5] # plotting range for slope CI: high gain l, r, medium gain l, r \n",
     "range_slopesFF = [0.8, 1.2, 0.8, 1.2] # plotting range for slope FF: high gain l, r, medium gain l, r \n",
-    "plot_range = 3 # range for plotting in units of median absolute deviations"
+    "plot_range = 3 # range for plotting in units of median absolute deviations\n",
+    "x_labels = ['Sensor Bias Voltage', 'Memory cells'] # parameters to be shown on X axis"
    ]
   },
   {
@@ -92,7 +93,7 @@
     "modules = [\"Q{}M{}\".format(x // 4 + 1, x % 4 + 1) for x in modules]\n",
     "\n",
     "constantsDark = {\"SlopesFF\": 'BadPixelsFF',\n",
-    "                 'SlopesPC': 'BadPixelsPC',\n",
+    "                 'SlopesCI': 'BadPixelsCI',\n",
     "                 'Noise': 'BadPixelsDark',\n",
     "                 'Offset': 'BadPixelsDark'}\n",
     "print('Bad pixels data: ', constantsDark)\n",
@@ -146,7 +147,7 @@
     "    # Loop over parameters\n",
     "    for pars in parameter_list:\n",
     "    \n",
-    "        if (const in [\"Offset\", \"Noise\", \"SlopesPC\"] or \"DARK\" in const.upper()):\n",
+    "        if (const in [\"Offset\", \"Noise\", \"SlopesCI\"] or \"DARK\" in const.upper()):\n",
     "            dcond = Conditions.Dark\n",
     "            mcond = getattr(dcond, dclass)(\n",
     "                        memory_cells=pars['mem_cells'],\n",
@@ -171,6 +172,9 @@
     "                           meta_only=True,\n",
     "                           version_info=True)\n",
     "\n",
+    "        if not isinstance(data, list):\n",
+    "            continue\n",
+    "            \n",
     "        # Request BP constant versions\n",
     "        print('constantDark:', constantsDark[const], )        \n",
     "        dataBP = get_from_db(getattr(det, pars['module']),\n",
@@ -184,11 +188,9 @@
     "                             meta_only=True,\n",
     "                             version_info=True)\n",
     "        \n",
-    "        if not isinstance(data, list) or not isinstance(dataBP, list):\n",
-    "            continue\n",
     "            \n",
-    "        found_BPmatch = False\n",
     "        for d in data:\n",
+    "            # print('Item: ', d)\n",
     "            # Match proper BP constant version\n",
     "            # and get constant version within\n",
     "            # requested time range\n",
@@ -204,6 +206,10 @@
     "                \n",
     "            closest_BP = None\n",
     "            closest_BPtime = None\n",
+    "            found_BPmatch = False\n",
+    "                \n",
+    "            if not isinstance(dataBP, list):\n",
+    "                dataBP = []\n",
     "            \n",
     "            for dBP in dataBP:\n",
     "                if dBP is None:\n",
@@ -240,10 +246,15 @@
     "                    constantBP_versions.append(dBP)\n",
     "                    constant_versions.append(d)\n",
     "                    constant_parameters.append(copy.deepcopy(pars))\n",
-    "                    found_BPmatch = False\n",
     "                    break\n",
     "                    \n",
-    "print('Number of retrieved constants with a bad pixel match is {}'.format(len(constant_versions)))"
+    "            if not found_BPmatch:\n",
+    "                print('Bad pixels are not matched')\n",
+    "                constantBP_versions.append(None)\n",
+    "                constant_versions.append(d)\n",
+    "                constant_parameters.append(copy.deepcopy(pars))\n",
+    "                    \n",
+    "print('Number of retrieved constants {}'.format(len(constant_versions)))"
    ]
   },
   {
@@ -287,7 +298,7 @@
     "\n",
     "\n",
     "ret_constants = {}\n",
-    "constand_data = ConstantMetaData()\n",
+    "constant_data = ConstantMetaData()\n",
     "constant_BP = ConstantMetaData()\n",
     "\n",
     "# sort over begin_at\n",
@@ -306,41 +317,45 @@
     "    if nconstants>0 and len(ret_constants[const][qm])>=nconstants:\n",
     "        continue\n",
     "        \n",
-    "    constand_data.retrieve_from_version_info(constant_versions[i])\n",
-    "    constant_BP.retrieve_from_version_info(constantBP_versions[i])\n",
-    "    \n",
-    "    cdata = constand_data.calibration_constant.data\n",
-    "    cdataBP = constant_BP.calibration_constant.data\n",
-    "    ctime = constand_data.calibration_constant_version.begin_at  \n",
-    "    \n",
+    "    constant_data.retrieve_from_version_info(constant_versions[i])\n",
+    "    cdata = constant_data.calibration_constant.data\n",
+    "    ctime = constant_data.calibration_constant_version.begin_at \n",
+    "    cdata = modify_const(const, cdata)\n",
     "    print(\"constant: {}, module {}, begin_at {}\".format(const, qm, ctime))\n",
     "\n",
-    "    cdata = modify_const(const, cdata)\n",
-    "    cdataBP = modify_const(const, cdataBP)\n",
+    "    if constantBP_versions[i]:\n",
+    "        constant_BP.retrieve_from_version_info(constantBP_versions[i])\n",
+    "        cdataBP = constant_BP.calibration_constant.data\n",
+    "        cdataBP = modify_const(const, cdataBP)\n",
     "\n",
-    "    if cdataBP.shape != cdata.shape:\n",
-    "        print('Wrong bad pixel shape! {}, expected {}'.format(cdataBP.shape, cdata.shape))\n",
-    "        continue\n",
+    "        if cdataBP.shape != cdata.shape:\n",
+    "            print('Wrong bad pixel shape! {}, expected {}'.format(cdataBP.shape, cdata.shape))\n",
+    "            cdataBP = np.full_like(cdata, -1)\n",
     "\n",
-    "    # Apply bad pixel mask\n",
-    "    cdataABP = np.copy(cdata)\n",
-    "    cdataABP[cdataBP > 0] = np.nan\n",
+    "        # Apply bad pixel mask\n",
+    "        cdataABP = np.copy(cdata)\n",
+    "        cdataABP[cdataBP > 0] = np.nan\n",
     "\n",
-    "    # Create superpixels for constants with BP applied\n",
-    "    cdataABP = get_rebined(cdataABP, spShape)\n",
-    "    toStoreBP = prepare_to_store(np.nanmean(cdataABP, axis=(1, 3)), nMem)\n",
-    "    toStoreBPStd = prepare_to_store(np.nanstd(cdataABP, axis=(1, 3)), nMem)\n",
+    "        # Create superpixels for constants with BP applied\n",
+    "        cdataABP = get_rebined(cdataABP, spShape)\n",
+    "        toStoreBP = prepare_to_store(np.nanmean(cdataABP, axis=(1, 3)), nMem)\n",
+    "        toStoreBPStd = prepare_to_store(np.nanstd(cdataABP, axis=(1, 3)), nMem)\n",
     "\n",
-    "    # Prepare number of bad pixels per superpixels\n",
-    "    cdataBP = get_rebined(cdataBP, spShape)\n",
-    "    cdataNBP = prepare_to_store(np.nansum(cdataBP > 0, axis=(1, 3)), nMem)\n",
+    "        # Prepare number of bad pixels per superpixels\n",
+    "        cdataBP = get_rebined(cdataBP, spShape)\n",
+    "        cdataNBP = prepare_to_store(np.nansum(cdataBP > 0, axis=(1, 3)), nMem)\n",
     "\n",
     "    # Create superpixels for constants without BP applied\n",
     "    cdata = get_rebined(cdata, spShape)\n",
     "    toStoreStd = prepare_to_store(np.nanstd(cdata, axis=(1, 3)), nMem)\n",
     "    toStore = prepare_to_store(np.nanmean(cdata, axis=(1, 3)), nMem)\n",
     "    \n",
-    "    dpar = {p.name: p.value for p in constand_data.detector_condition.parameters}\n",
+    "    if not constantBP_versions[i]:\n",
+    "        toStoreBP = np.full_like(toStore, np.nan)\n",
+    "        toStoreBPStd = np.full_like(toStore, np.nan)\n",
+    "        cdataNBP = np.full_like(toStore, np.nan)\n",
+    "    \n",
+    "    dpar = {p.name: p.value for p in constant_data.detector_condition.parameters}\n",
     "\n",
     "    print(\"Store values in dict\", const, qm, ctime)\n",
     "    ret_constants[const][qm].append({'ctime': ctime,\n",
diff --git a/notebooks/generic/PlotFromCalDB_Summary_NBC.ipynb b/notebooks/generic/PlotFromCalDB_Summary_NBC.ipynb
index 618f01887..e1a45eb72 100644
--- a/notebooks/generic/PlotFromCalDB_Summary_NBC.ipynb
+++ b/notebooks/generic/PlotFromCalDB_Summary_NBC.ipynb
@@ -14,14 +14,12 @@
   {
    "cell_type": "code",
    "execution_count": null,
-   "metadata": {
-    "collapsed": true
-   },
+   "metadata": {},
    "outputs": [],
    "source": [
     "cluster_profile = \"noDB\"  # The ipcluster profile to use\n",
-    "out_folder = \"/gpfs/exfel/data/scratch/karnem/testLPD_11/\"  # Output folder, required\n",
-    "use_existing = \"/gpfs/exfel/data/scratch/karnem/testLPD_10/\" # Input folder\n",
+    "out_folder = \"/gpfs/exfel/data/scratch/karnem/test_LPD/\"  # Output folder, required\n",
+    "use_existing = \"/gpfs/exfel/data/scratch/karnem/test_LPD/\" # Input folder\n",
     "dclass = \"LPD\"  # Detector class\n",
     "nMemToShow = 32 # Number of memory cells to be shown in plots over ASICs\n",
     "range_offset = [4000., 5500, 6500, 8500] # plotting range for offset: high gain l, r, medium gain l, r \n",
@@ -30,7 +28,9 @@
     "range_noise_e = [85., 500., 85., 500.] # plotting range for noise in [e-]: high gain l, r, medium gain l, r \n",
     "range_slopesPC = [22.0, 27.0, -0.5, 1.5] # plotting range for slope PC: high gain l, r, medium gain l, r \n",
     "range_slopesCI = [22.0, 27.0, -0.5, 1.5] # plotting range for slope CI: high gain l, r, medium gain l, r \n",
-    "range_slopesFF = [0.8, 1.2, 0.6, 1.2] # plotting range for slope FF: high gain l, r, medium gain l, r "
+    "range_slopesFF = [0.8, 1.2, 0.6, 1.2] # plotting range for slope FF: high gain l, r, medium gain l, r \n",
+    "plot_range = 3 # range for plotting in units of median absolute deviations\n",
+    "x_labels = ['Acquisition rate', 'Memory cells'] # parameters to be shown on X axis"
    ]
   },
   {
@@ -48,7 +48,7 @@
     "\n",
     "from cal_tools.ana_tools import (load_data_from_hdf5, \n",
     "                                 HMType, multi_union,\n",
-    "                                 hm_combine)"
+    "                                 hm_combine, get_range)"
    ]
   },
   {
@@ -81,9 +81,7 @@
   {
    "cell_type": "code",
    "execution_count": null,
-   "metadata": {
-    "collapsed": true
-   },
+   "metadata": {},
    "outputs": [],
    "source": [
     "# Parameters for plotting\n",
@@ -116,7 +114,7 @@
    "cell_type": "code",
    "execution_count": null,
    "metadata": {
-    "scrolled": true
+    "scrolled": false
    },
    "outputs": [],
    "source": [
@@ -147,10 +145,9 @@
     "            if (\"mdata\" in data):\n",
     "                cmdata = np.array(data[\"mdata\"])\n",
     "                for i, tick in enumerate(ctimes_ticks):\n",
-    "                    ctimes_ticks[i] = ctimes_ticks[i] + \\\n",
-    "                        ', V={:1.0f}'.format(cmdata[i]['Sensor Bias Voltage']) + \\\n",
-    "                        ', M={:1.0f}'.format(\n",
-    "                        cmdata[i]['Memory cells'])\n",
+    "                    for entr in x_labels:\n",
+    "                        ctimes_ticks[i] += ', {}={}'.format(entr[0].upper(), \n",
+    "                                                           cmdata[i].get(entr, None))\n",
     "\n",
     "            sort_ind = np.argsort(ctimes_ticks)\n",
     "            ctimes_ticks = list(np.array(ctimes_ticks)[sort_ind])\n",
@@ -217,15 +214,10 @@
     "        nModules = len(mod_names)\n",
     "        mod_idx = np.argsort(mod_names)\n",
     "        for key in mod_data:\n",
-    "            vmin = None\n",
-    "            vmax = None\n",
+    "            vmin,vmax = get_range(np.array(mod_data[key])[mod_idx][::-1].flatten(), plot_range)\n",
     "            if const in rangevals and key in ['Mean', 'MeanBP']:\n",
     "                vmin = rangevals[const][gain][0]\n",
     "                vmax = rangevals[const][gain][1]\n",
-    "            else:\n",
-    "                vmin = np.nanmin(np.array(mod_data[key]))\n",
-    "                vmax = np.nanmean(\n",
-    "                    np.array(mod_data[key])) + 2*np.nanstd(np.array(mod_data[key]))\n",
     "\n",
     "            htype = None\n",
     "            if const in ['SlopesFF', 'SlopesPC', 'SlopesCI']:\n",
-- 
GitLab