diff --git a/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb b/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb
index ab82b15ed609e70f36040fac813a5faa64b6a7eb..8ff0d1613d4cc604d6847bde5c8ff0582d45dc60 100644
--- a/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb
+++ b/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb
@@ -19,24 +19,24 @@
      "end_time": "2019-02-21T11:30:06.730220Z",
      "start_time": "2019-02-21T11:30:06.658286Z"
     },
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
     "in_folder = \"/gpfs/exfel/exp/SPB/201930/p900062/raw\" # the folder to read data from, required\n",
-    "run = 330 # runs to process, required\n",
-    "out_folder =  \"/gpfs/exfel/data/scratch/haufs/test\"  # the folder to output to, required\n",
+    "run = 370 # runs to process, required\n",
+    "out_folder =  \"/gpfs/exfel/data/scratch/xcal/test/\"  # the folder to output to, required\n",
     "calfile =  \"/gpfs/exfel/data/scratch/haufs/agipd_on_demand/agipd_store.h5\" # path to calibration file. Leave empty if all data should come from DB\n",
     "sequences =  [-1] # sequences to correct, set to -1 for all, range allowed\n",
     "mem_cells = 0 # number of memory cells used, set to 0 to automatically infer\n",
     "interlaced = False # whether data is in interlaced layout\n",
     "overwrite = True # set to True if existing data should be overwritten\n",
-    "no_relative_gain = True # do not do relative gain correction\n",
+    "no_relative_gain = False # do not do relative gain correction\n",
     "cluster_profile = \"noDB\"\n",
     "max_pulses = 500\n",
     "local_input = False\n",
     "bias_voltage = 300\n",
-    "cal_db_interface = \"tcp://max-exfl016:8015#8025\" # the database interface to use\n",
+    "cal_db_interface = \"tcp://max-exfl016:8020#8025\" # the database interface to use\n",
     "use_dir_creation_date = True # use the creation data of the input dir for database queries\n",
     "sequences_per_node = 2 # number of sequence files per cluster node if run as slurm job, set to 0 to not run SLURM parallel\n",
     "photon_energy = 9.2 # photon energy in keV\n",
@@ -48,15 +48,16 @@
     "match_asics = False # if set, inner ASIC borders are matched to the same signal level\n",
     "corr_asic_diag = False # if set, diagonal drop offs on ASICs are correted \n",
     "melt_snow = \"\" # if set to \"none\" snowy pixels are identified and resolved to NaN, if set to \"interpolate\", the value is interpolated from neighbouring pixels\n",
-    "cal_db_timeout = 300000 # in milli seconds\n",
+    "cal_db_timeout = 30000 # in milliseconds\n",
     "max_cells_db_dark = 0  # set to a value different than 0 to use this value for dark data DB queries\n",
     "max_cells_db = 0 # set to a value different than 0 to use this value for DB queries\n",
-    "chunk_size_idim = 32  # chunking size of imaging dimension, adjust if user software is sensitive to this.\n",
+    "chunk_size_idim = 1  # chunking size of imaging dimension, adjust if user software is sensitive to this.\n",
     "creation_date_offset = \"00:00:00\" # add an offset to creation date, e.g. to get different constants\n",
     "instrument = \"SPB\"  # the instrument the detector is installed at, required\n",
     "force_hg_if_below = 1000 # set to a value other than 0 to force a pixel into high gain if it's high gain offset subtracted value is below this threshold\n",
     "force_mg_if_below = 1000 # set to a value other than 0 to force a pixel into medium gain if it's medium gain offset subtracted value is below this threshold\n",
     "mask_noisy_adc = 0.25 # set to a value other than 0 and below 1 to mask entire ADC if fraction of noisy pixels is above\n",
+    "adjust_mg_baseline = False \n",
     "\n",
     "def balance_sequences(in_folder, run, sequences, sequences_per_node):\n",
     "    import glob\n",
@@ -72,7 +73,7 @@
     "    else:\n",
     "        seq_nums = set(sequences)\n",
     "    nsplits = len(seq_nums)//sequences_per_node+1\n",
-    "    while nsplits > 8:\n",
+    "    while nsplits > 32:\n",
     "        sequences_per_node += 1\n",
     "        nsplits = len(seq_nums)//sequences_per_node+1\n",
     "        print(\"Changed to {} sequences per node to have a maximum of 8 concurrent jobs\".format(sequences_per_node))\n",
@@ -88,7 +89,7 @@
      "end_time": "2019-02-21T11:30:07.086286Z",
      "start_time": "2019-02-21T11:30:06.929722Z"
     },
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
@@ -240,7 +241,7 @@
      "end_time": "2019-02-21T11:30:07.974174Z",
      "start_time": "2019-02-21T11:30:07.914832Z"
     },
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
@@ -307,7 +308,7 @@
      "end_time": "2019-02-21T11:30:08.870802Z",
      "start_time": "2019-02-21T11:30:08.826285Z"
     },
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
@@ -341,7 +342,7 @@
      "end_time": "2019-02-21T11:30:16.057429Z",
      "start_time": "2019-02-21T11:30:10.082114Z"
     },
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
@@ -351,7 +352,7 @@
     "                   bins_gain_vs_signal, bins_signal_low_range, bins_signal_high_range,\n",
     "                   bins_dig_gain_vs_signal, max_pulses, dbparms, fileparms, nodb, chunk_size_idim,\n",
     "                   special_opts, il_mode, loc, dinstance, force_hg_if_below, force_mg_if_below,\n",
-    "                   mask_noisy_adc, inp):\n",
+    "                   mask_noisy_adc, adjust_mg_baseline, inp):\n",
     "    import numpy as np\n",
     "    import copy\n",
     "    import h5py\n",
@@ -402,6 +403,7 @@
     "    signal_edges = None\n",
     "    dig_signal_edges = None\n",
     "    gain_stats = 0\n",
+    "    when = None\n",
     "    try:\n",
     "        start = datetime.now()\n",
     "        success = True\n",
@@ -431,7 +433,8 @@
     "                                      h5_data_path=\"INSTRUMENT/{}/DET/{{}}CH0:xtdf/\".format(loc),\n",
     "                                      h5_index_path=\"INDEX/{}/DET/{{}}CH0:xtdf/\".format(loc),\n",
     "                                      cal_det_instance=dinstance, force_hg_if_below=force_hg_if_below,\n",
-    "                                      force_mg_if_below=force_mg_if_below, mask_noisy_adc=mask_noisy_adc)\n",
+    "                                      force_mg_if_below=force_mg_if_below, mask_noisy_adc=mask_noisy_adc,\n",
+    "                                      adjust_mg_baseline=adjust_mg_baseline)\n",
     "        \n",
     "        blc_noise, blc_noise_threshold, blc_hist, match_asics, corr_asic_diag, melt_snow = special_opts\n",
     "        agipd_corr.baseline_corr_using_noise = blc_noise\n",
@@ -445,7 +448,7 @@
     "        except IOError:\n",
     "            return\n",
     "        if not nodb:\n",
-    "            agipd_corr.initialize_from_db(dbparms, qm, only_dark=(fileparms != \"\"))\n",
+    "            when = agipd_corr.initialize_from_db(dbparms, qm, only_dark=(fileparms != \"\"))            \n",
     "        if fileparms != \"\":\n",
     "            agipd_corr.initialize_from_file(fileparms, qm, with_dark=nodb)\n",
     "        print(\"Initialized constants\")\n",
@@ -475,10 +478,10 @@
     "        sequence = re.findall(r'.*S([0-9]{5}).*', filename)[0]\n",
     "        filesize = os.path.getsize(filename)\n",
     "        duration = (datetime.now()-start).total_seconds()\n",
-    "        influx = create_influx_entry(run, proposal, qm, sequence, filesize, CHUNK_SIZE, total_sequences, success, duration, reason)\n",
-    "        client.write_points([influx])\n",
+    "        #influx = create_influx_entry(run, proposal, qm, sequence, filesize, CHUNK_SIZE, total_sequences, success, duration, reason)\n",
+    "        #client.write_points([influx])\n",
     "    return (hists_signal_low, hists_signal_high, hists_gain_vs_signal, hists_dig_gain_vs_signal,\n",
-    "            low_edges, high_edges, signal_edges, dig_signal_edges, gain_stats, max_cells)\n",
+    "            low_edges, high_edges, signal_edges, dig_signal_edges, gain_stats, max_cells, when)\n",
     "    \n",
     "done = False\n",
     "first_files = []\n",
@@ -500,6 +503,7 @@
     "           photon_energy, max_cells_db_dark, cal_db_timeout]\n",
     "fileparms = calfile\n",
     "all_cells = []\n",
+    "whens = []\n",
     "while not done:\n",
     "    \n",
     "    dones = []\n",
@@ -524,7 +528,7 @@
     "                    sequences_qm, bins_gain_vs_signal, bins_signal_low_range, bins_signal_high_range,\n",
     "                    bins_dig_gain_vs_signal, max_pulses, dbparms, fileparms, nodb, chunk_size_idim,\n",
     "                    special_opts, il_mode, loc, dinstance, force_hg_if_below, force_mg_if_below,\n",
-    "                    mask_noisy_adc)\n",
+    "                    mask_noisy_adc, adjust_mg_baseline)\n",
     "         \n",
     "        r = view.map_sync(p, inp)\n",
     "        \n",
@@ -534,8 +538,9 @@
     "        \n",
     "        for rr in r:\n",
     "            if rr is not None:\n",
-    "                hl, hh, hg, hdg, low_edges, high_edges, signal_edges, dig_signal_edges, gs, cells = rr\n",
+    "                hl, hh, hg, hdg, low_edges, high_edges, signal_edges, dig_signal_edges, gs, cells, when = rr\n",
     "                all_cells.append(cells)\n",
+    "                whens.append(when)\n",
     "                if hl is not None:  # any one being None will also make the others None\n",
     "                    hists_signal_low += hl.astype(np.float64)\n",
     "                    hists_signal_high += hh.astype(np.float64)\n",
@@ -546,7 +551,22 @@
     "    done = all(dones)\n",
     "all_cells = np.array(all_cells)\n",
     "mem_cells = np.min(all_cells[all_cells != 0])\n",
-    "max_cells = mem_cells"
+    "max_cells = mem_cells\n"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {
+    "collapsed": true
+   },
+   "outputs": [],
+   "source": [
+    "\n",
+    "print(\"Offset where injected on: \")\n",
+    "for i, when in enumerate(whens):\n",
+    "    qm = \"Q{}M{}\".format((i%16)//4 + 1, i%4 +1)\n",
+    "    print(\"{}: {}\".format(qm, when))"
    ]
   },
   {
@@ -557,7 +577,7 @@
      "end_time": "2019-02-18T17:28:51.765030Z",
      "start_time": "2019-02-18T17:28:51.714783Z"
     },
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
@@ -603,7 +623,7 @@
      "end_time": "2019-02-18T17:28:52.857960Z",
      "start_time": "2019-02-18T17:28:51.767217Z"
     },
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
@@ -618,7 +638,7 @@
      "end_time": "2019-02-18T17:28:53.690522Z",
      "start_time": "2019-02-18T17:28:52.860143Z"
     },
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
@@ -654,7 +674,7 @@
      "end_time": "2019-02-18T17:28:54.370559Z",
      "start_time": "2019-02-18T17:28:53.691959Z"
     },
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
@@ -669,7 +689,7 @@
      "end_time": "2019-02-18T17:31:51.668096Z",
      "start_time": "2019-02-18T17:31:51.529158Z"
     },
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
@@ -696,7 +716,7 @@
      "end_time": "2019-02-18T17:28:57.327702Z",
      "start_time": "2019-02-18T17:28:54.377061Z"
     },
-    "collapsed": false,
+    "collapsed": true,
     "scrolled": false
    },
    "outputs": [],
@@ -715,7 +735,7 @@
      "end_time": "2019-02-18T17:29:20.634480Z",
      "start_time": "2019-02-18T17:28:57.329231Z"
     },
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
@@ -726,66 +746,37 @@
     "mask = []\n",
     "cell_fac = 1\n",
     "first_idx = 0\n",
-    "last_idx = cell_fac*mem_cells+first_idx\n",
+    "last_idx = cell_fac*176+first_idx\n",
     "pulse_ids = []\n",
     "train_ids = []\n",
-    "for i, ff in enumerate(first_files):\n",
+    "for i, ff in enumerate(first_files[:16]):\n",
     "    try:\n",
+    "\n",
     "        rf, cf = ff\n",
-    "        #print(cf, i)\n",
     "        if rf is None:\n",
     "            raise Exception(\"File not present\")\n",
+    "        \n",
     "        infile = h5py.File(rf, \"r\")\n",
-    "        raw.append(np.array(infile[\"/INSTRUMENT/SPB_DET_AGIPD1M-1/DET/{}CH0:xtdf/image/data\".format(i)][first_idx:last_idx,0,...]))\n",
+    "        raw.append(np.array(infile[\"/INSTRUMENT/{}_DET_AGIPD1M-1/DET/{}CH0:xtdf/image/data\".format(instrument, i)][first_idx:last_idx,0,...]))\n",
     "        infile.close()\n",
     "        \n",
     "        infile = h5py.File(cf, \"r\")\n",
-    "        #print(\"/INSTRUMENT/SPB_DET_AGIPD1M-1/DET/{}CH0:xtdf/image/data\".format(i))\n",
-    "        corrected.append(np.array(infile[\"/INSTRUMENT/SPB_DET_AGIPD1M-1/DET/{}CH0:xtdf/image/data\".format(i)][first_idx:last_idx,...]))\n",
-    "        gains.append(np.array(infile[\"/INSTRUMENT/SPB_DET_AGIPD1M-1/DET/{}CH0:xtdf/image/gain\".format(i)][first_idx:last_idx,...]))\n",
-    "        mask.append(np.array(infile[\"/INSTRUMENT/SPB_DET_AGIPD1M-1/DET/{}CH0:xtdf/image/mask\".format(i)][first_idx:last_idx,...]))\n",
-    "        pulse_ids.append(np.squeeze(infile[\"/INSTRUMENT/SPB_DET_AGIPD1M-1/DET/{}CH0:xtdf/image/pulseId\".format(i)][first_idx:last_idx,...]))\n",
-    "        train_ids.append(np.squeeze(infile[\"/INSTRUMENT/SPB_DET_AGIPD1M-1/DET/{}CH0:xtdf/image/trainId\".format(i)][first_idx:last_idx,...]))\n",
-    "        \n",
+    "        corrected.append(np.array(infile[\"/INSTRUMENT/{}_DET_AGIPD1M-1/DET/{}CH0:xtdf/image/data\".format(instrument, i)][first_idx:last_idx,...]))\n",
+    "        gains.append(np.array(infile[\"/INSTRUMENT/{}_DET_AGIPD1M-1/DET/{}CH0:xtdf/image/gain\".format(instrument, i)][first_idx:last_idx,...]))\n",
+    "        mask.append(np.array(infile[\"/INSTRUMENT/{}_DET_AGIPD1M-1/DET/{}CH0:xtdf/image/mask\".format(instrument, i)][first_idx:last_idx,...]))\n",
+    "        pulse_ids.append(np.squeeze(infile[\"/INSTRUMENT/{}_DET_AGIPD1M-1/DET/{}CH0:xtdf/image/pulseId\".format(instrument, i)][first_idx:last_idx,...]))\n",
+    "        train_ids.append(np.squeeze(infile[\"/INSTRUMENT/{}_DET_AGIPD1M-1/DET/{}CH0:xtdf/image/trainId\".format(instrument, i)][first_idx:last_idx,...]))\n",
     "        infile.close()\n",
     "        \n",
     "    except Exception as e:\n",
     "        print(e)\n",
-    "        corrected.append(np.zeros((max_cells, 512, 128)))\n",
-    "        gains.append(np.zeros((max_cells, 512, 128)))\n",
-    "        mask.append(np.zeros((max_cells, 512, 128)))\n",
-    "        raw.append(np.zeros((max_cells, 512, 128)))\n",
+    "        corrected.append(np.zeros((last_idx-first_idx, 512, 128)))\n",
+    "        gains.append(np.zeros((last_idx-first_idx, 512, 128)))\n",
+    "        mask.append(np.zeros((last_idx-first_idx, 512, 128)))\n",
+    "        raw.append(np.zeros((last_idx-first_idx, 512, 128)))\n",
     "\n"
    ]
   },
-  {
-   "cell_type": "code",
-   "execution_count": null,
-   "metadata": {
-    "ExecuteTime": {
-     "end_time": "2019-02-18T17:29:20.640288Z",
-     "start_time": "2019-02-18T17:29:20.636429Z"
-    },
-    "collapsed": false
-   },
-   "outputs": [],
-   "source": [
-    "#import XFELDetAna.xfelpycaltools as xcal\n",
-    "#corr_pclas = []\n",
-    "#pats = []\n",
-    "#for i in range(16):\n",
-    "#    d = corrected[i]\n",
-    "#    d = np.moveaxis(d, 0, 2)[...,:128]\n",
-    "#    n = np.array(noises[i])\n",
-    "#    n = np.squeeze(n[:,:,:128,0])\n",
-    "    \n",
-    "#    pCal = xcal.PatternClassifier([512, 128], n, 7, 5., 50000, nCells=176, dType=np.float32)\n",
-    "    \n",
-    "#    d, p = pCal.classify(d)\n",
-    "#    corr_pclas.append(np.moveaxis(d, 2, 0))\n",
-    "#    pats.append(np.moveaxis(p, 2, 0))"
-   ]
-  },
   {
    "cell_type": "code",
    "execution_count": null,
@@ -794,20 +785,20 @@
      "end_time": "2019-02-18T17:29:27.025667Z",
      "start_time": "2019-02-18T17:29:20.642029Z"
     },
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
-    "domask = True\n",
+    "domask = False\n",
     "if domask:\n",
     "    for i, c in enumerate(corrected):\n",
     "        c[mask[i] != 0] = 0\n",
     "        #c[pats[i] < 200]  = 0\n",
     "        #c[np.abs(pats[i]) == 1000] = np.abs(c[np.abs(pats[i]) == 1000])\n",
-    "combined = combine_stack(corrected, corrected[0].shape[0])\n",
-    "combined_raw = combine_stack(raw, raw[0].shape[0])\n",
-    "combined_g = combine_stack(gains, gains[0].shape[0])\n",
-    "combined_mask = combine_stack(mask, mask[0].shape[0])"
+    "combined = combine_stack(corrected, last_idx-first_idx)\n",
+    "combined_raw = combine_stack(raw, last_idx-first_idx)\n",
+    "combined_g = combine_stack(gains, last_idx-first_idx)\n",
+    "combined_mask = combine_stack(mask, last_idx-first_idx)"
    ]
   },
   {
@@ -827,7 +818,7 @@
      "end_time": "2019-02-18T17:29:33.226396Z",
      "start_time": "2019-02-18T17:29:27.027758Z"
     },
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
@@ -858,7 +849,7 @@
      "end_time": "2019-02-18T17:29:33.761015Z",
      "start_time": "2019-02-18T17:29:33.227922Z"
     },
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
@@ -879,14 +870,13 @@
      "end_time": "2019-02-18T17:29:35.903487Z",
      "start_time": "2019-02-18T17:29:33.762568Z"
     },
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
     "fig = plt.figure(figsize=(20,10))\n",
     "ax = fig.add_subplot(111)\n",
-    "h = ax.hist(dim.flatten(), bins=1000, range=(0\n",
-    "                                             , 2000))\n"
+    "h = ax.hist(dim.flatten(), bins=1000, range=(0, 2000))\n"
    ]
   },
   {
@@ -906,7 +896,7 @@
      "end_time": "2019-02-18T17:29:39.369686Z",
      "start_time": "2019-02-18T17:29:35.905152Z"
     },
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
@@ -927,7 +917,7 @@
      "end_time": "2019-02-18T17:29:49.217848Z",
      "start_time": "2019-02-18T17:29:39.371232Z"
     },
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
@@ -937,21 +927,6 @@
     "h = ax.hist(combined.flatten(), bins=1000, range=(-50, 1000), log=True)\n"
    ]
   },
-  {
-   "cell_type": "code",
-   "execution_count": null,
-   "metadata": {
-    "ExecuteTime": {
-     "end_time": "2019-02-18T17:29:49.222484Z",
-     "start_time": "2019-02-18T17:29:49.219933Z"
-    },
-    "collapsed": false
-   },
-   "outputs": [],
-   "source": [
-    "#np.save('/gpfs/exfel/data/scratch/haufs/agipd_hist/prop_off_pcor_splits.npy', h)"
-   ]
-  },
   {
    "cell_type": "markdown",
    "metadata": {},
@@ -969,7 +944,7 @@
      "end_time": "2019-02-18T17:29:49.641675Z",
      "start_time": "2019-02-18T17:29:49.224167Z"
     },
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
@@ -999,7 +974,7 @@
      "end_time": "2019-02-18T17:29:49.651913Z",
      "start_time": "2019-02-18T17:29:49.643556Z"
     },
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
@@ -1029,7 +1004,7 @@
      "end_time": "2019-02-18T17:29:50.086169Z",
      "start_time": "2019-02-18T17:29:49.653391Z"
     },
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
@@ -1057,7 +1032,7 @@
      "end_time": "2019-02-18T17:29:51.686562Z",
      "start_time": "2019-02-18T17:29:50.088883Z"
     },
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
@@ -1083,7 +1058,7 @@
      "end_time": "2019-02-18T17:29:53.662423Z",
      "start_time": "2019-02-18T17:29:51.688376Z"
     },
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
@@ -1102,7 +1077,7 @@
      "end_time": "2019-02-18T17:29:55.483270Z",
      "start_time": "2019-02-18T17:29:53.664226Z"
     },
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
@@ -1115,52 +1090,6 @@
     "               vmax=32, cmap=\"jet\")\n",
     "cb = fig.colorbar(im, ax=ax)"
    ]
-  },
-  {
-   "cell_type": "code",
-   "execution_count": null,
-   "metadata": {
-    "ExecuteTime": {
-     "end_time": "2019-02-18T17:29:55.487334Z",
-     "start_time": "2019-02-18T17:29:55.484992Z"
-    },
-    "collapsed": true
-   },
-   "outputs": [],
-   "source": [
-    "### Full Train Bad Pixels - Only Dark Char. Related, By BP Val ###"
-   ]
-  },
-  {
-   "cell_type": "code",
-   "execution_count": null,
-   "metadata": {
-    "ExecuteTime": {
-     "end_time": "2019-02-18T17:29:55.495110Z",
-     "start_time": "2019-02-18T17:29:55.489164Z"
-    },
-    "collapsed": false
-   },
-   "outputs": [],
-   "source": [
-    "#for bpval in BadPixels:\n",
-    "#    fig = plt.figure(figsize=(20,10))\n",
-    "#    ax = fig.add_subplot(111)\n",
-    "#    cm = combined_mask[:,:1300,400:1600].astype(np.uint32) & np.array(BadPixels.NO_DARK_DATA.value).astype(np.uint32)\n",
-    "#    im = ax.imshow(np.log2(np.max(cm, axis=0)), vmin=0,\n",
-    "#                   vmax=32, cmap=\"jet\")\n",
-    "#    cb = fig.colorbar(im, ax=ax)\n",
-    "    "
-   ]
-  },
-  {
-   "cell_type": "code",
-   "execution_count": null,
-   "metadata": {
-    "collapsed": true
-   },
-   "outputs": [],
-   "source": []
   }
  ],
  "metadata": {
diff --git a/notebooks/AGIPD/Characterize_AGIPD_Gain_Darks_NBC.ipynb b/notebooks/AGIPD/Characterize_AGIPD_Gain_Darks_NBC.ipynb
index 7b38aa63b70a13ccb268294115ea5a91bbaf32e7..38ff18abae06abbae1de8fdb24a60a8cf5f1599e 100644
--- a/notebooks/AGIPD/Characterize_AGIPD_Gain_Darks_NBC.ipynb
+++ b/notebooks/AGIPD/Characterize_AGIPD_Gain_Darks_NBC.ipynb
@@ -21,7 +21,7 @@
      "end_time": "2019-02-20T12:42:51.255184Z",
      "start_time": "2019-02-20T12:42:51.225500Z"
     },
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
@@ -62,7 +62,7 @@
      "end_time": "2019-02-20T12:42:52.599660Z",
      "start_time": "2019-02-20T12:42:51.472138Z"
     },
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
@@ -137,7 +137,7 @@
      "end_time": "2019-02-20T12:42:52.608214Z",
      "start_time": "2019-02-20T12:42:52.601257Z"
     },
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
@@ -168,7 +168,7 @@
      "end_time": "2019-02-20T12:42:54.024731Z",
      "start_time": "2019-02-20T12:42:53.901555Z"
     },
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
@@ -199,7 +199,7 @@
      "end_time": "2019-02-20T10:50:55.839958Z",
      "start_time": "2019-02-20T10:50:55.468134Z"
     },
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
@@ -392,14 +392,14 @@
     "               }\n",
     "    \n",
     "if local_output:\n",
-    "    ofile = \"{}/agipd_offset_store_{}.h5\".format(out_folder, \"_\".join(offset_runs.values()))\n",
-    "    store_file = h5py.File(ofile, \"w\")\n",
     "    for qm in offset_g.keys():\n",
+    "        ofile = \"{}/agipd_offset_store_{}_{}.h5\".format(out_folder, \"_\".join(offset_runs.values()), qm)\n",
+    "        store_file = h5py.File(ofile, \"w\")\n",
     "        store_file[\"{}/Offset/0/data\".format(qm)] = offset_g[qm]\n",
     "        store_file[\"{}/Noise/0/data\".format(qm)] = noise_g[qm]\n",
     "        store_file[\"{}/Threshold/0/data\".format(qm)] = thresholds_g[qm]\n",
     "        store_file[\"{}/BadPixels/0/data\".format(qm)] = badpix_g[qm]\n",
-    "    store_file.close()"
+    "        store_file.close()"
    ]
   },
   {
@@ -410,7 +410,7 @@
      "end_time": "2018-12-06T09:49:32.449330Z",
      "start_time": "2018-12-06T09:49:20.231607Z"
     },
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
@@ -422,7 +422,7 @@
     "        metadata.calibration_constant = offset\n",
     "\n",
     "        # set the operating condition\n",
-    "        condition = Conditions.Dark.AGIPD(memory_cells=mem_cells, bias_voltage=bias_voltage)\n",
+    "        condition = Conditions.Dark.AGIPD(memory_cells=max_cells, bias_voltage=bias_voltage)\n",
     "        detinst = getattr(Detectors, dinstance)\n",
     "        device = getattr(detinst, qm)\n",
     "        \n",
@@ -433,7 +433,7 @@
     "            metadata.calibration_constant_version = Versions.Now(device=device)\n",
     "        else:\n",
     "            metadata.calibration_constant_version = Versions.Timespan(device=device, start=creation_time)\n",
-    "        metadata.send(cal_db_interface)\n",
+    "        metadata.send(cal_db_interface, timeout=3000000)\n",
     "        \n",
     "        \n",
     "        metadata = ConstantMetaData()\n",
@@ -442,7 +442,7 @@
     "        metadata.calibration_constant = noise\n",
     "\n",
     "        # set the operating condition\n",
-    "        condition = Conditions.Dark.AGIPD(memory_cells=mem_cells, bias_voltage=bias_voltage)\n",
+    "        condition = Conditions.Dark.AGIPD(memory_cells=max_cells, bias_voltage=bias_voltage)\n",
     "        metadata.detector_condition = condition\n",
     "\n",
     "        # specify the a version for this constant\n",
@@ -450,7 +450,7 @@
     "            metadata.calibration_constant_version = Versions.Now(device=device)\n",
     "        else:\n",
     "            metadata.calibration_constant_version = Versions.Timespan(device=device, start=creation_time)\n",
-    "        metadata.send(cal_db_interface)\n",
+    "        metadata.send(cal_db_interface, timeout=3000000)\n",
     "        \n",
     "        metadata = ConstantMetaData()\n",
     "        thresholds = Constants.AGIPD.ThresholdsDark()\n",
@@ -458,7 +458,7 @@
     "        metadata.calibration_constant = thresholds\n",
     "\n",
     "        # set the operating condition\n",
-    "        condition = Conditions.Dark.AGIPD(memory_cells=mem_cells, bias_voltage=bias_voltage)\n",
+    "        condition = Conditions.Dark.AGIPD(memory_cells=max_cells, bias_voltage=bias_voltage)\n",
     "        metadata.detector_condition = condition\n",
     "\n",
     "        # specify the a version for this constant\n",
@@ -466,7 +466,7 @@
     "            metadata.calibration_constant_version = Versions.Now(device=device)\n",
     "        else:\n",
     "            metadata.calibration_constant_version = Versions.Timespan(device=device, start=creation_time)\n",
-    "        metadata.send(cal_db_interface)\n",
+    "        metadata.send(cal_db_interface, timeout=3000000)\n",
     "        \n",
     "        metadata = ConstantMetaData()\n",
     "        badpixels = Constants.AGIPD.BadPixelsDark()\n",
@@ -474,7 +474,7 @@
     "        metadata.calibration_constant = badpixels\n",
     "\n",
     "        # set the operating condition\n",
-    "        condition = Conditions.Dark.AGIPD(memory_cells=mem_cells, bias_voltage=bias_voltage)\n",
+    "        condition = Conditions.Dark.AGIPD(memory_cells=max_cells, bias_voltage=bias_voltage)\n",
     "        metadata.detector_condition = condition\n",
     "\n",
     "        # specify the a version for this constant\n",
@@ -482,7 +482,7 @@
     "            metadata.calibration_constant_version = Versions.Now(device=device)\n",
     "        else:\n",
     "            metadata.calibration_constant_version = Versions.Timespan(device=device, start=creation_time)\n",
-    "        metadata.send(cal_db_interface)"
+    "        metadata.send(cal_db_interface, timeout=3000000)"
    ]
   },
   {
@@ -509,12 +509,12 @@
      "end_time": "2018-12-06T09:49:14.540552Z",
      "start_time": "2018-12-06T09:49:13.009674Z"
     },
-    "collapsed": false,
+    "collapsed": true,
     "scrolled": false
    },
    "outputs": [],
    "source": [
-    "cell = 12\n",
+    "cell = 3\n",
     "gain = 0\n",
     "out_folder = None\n",
     "show_overview(res, cell, gain, out_folder=out_folder, infix=\"_\".join(offset_runs.values()))"
@@ -531,12 +531,12 @@
    "cell_type": "code",
    "execution_count": null,
    "metadata": {
-    "collapsed": false,
+    "collapsed": true,
     "scrolled": false
    },
    "outputs": [],
    "source": [
-    "cell = 12\n",
+    "cell = 3\n",
     "gain = 1\n",
     "show_overview(res, cell, gain, out_folder=out_folder, infix=\"_\".join(offset_runs.values()))"
    ]
@@ -552,12 +552,12 @@
    "cell_type": "code",
    "execution_count": null,
    "metadata": {
-    "collapsed": false,
+    "collapsed": true,
     "scrolled": true
    },
    "outputs": [],
    "source": [
-    "cell = 12\n",
+    "cell = 3\n",
     "gain = 2\n",
     "show_overview(res, cell, gain, out_folder=out_folder, infix=\"_\".join(offset_runs.values()))"
    ]
@@ -582,7 +582,7 @@
    "cell_type": "code",
    "execution_count": null,
    "metadata": {
-    "collapsed": false,
+    "collapsed": true,
     "scrolled": false
    },
    "outputs": [],
@@ -610,7 +610,7 @@
    "cell_type": "code",
    "execution_count": null,
    "metadata": {
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
@@ -630,7 +630,7 @@
    "cell_type": "code",
    "execution_count": null,
    "metadata": {
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
@@ -641,9 +641,7 @@
   },
   {
    "cell_type": "markdown",
-   "metadata": {
-    "collapsed": false
-   },
+   "metadata": {},
    "source": [
     "## Aggregate values, and per Cell behaviour ##\n",
     "\n",
@@ -654,7 +652,7 @@
    "cell_type": "code",
    "execution_count": null,
    "metadata": {
-    "collapsed": false,
+    "collapsed": true,
     "scrolled": false
    },
    "outputs": [],
@@ -667,7 +665,7 @@
    "cell_type": "code",
    "execution_count": null,
    "metadata": {
-    "collapsed": false,
+    "collapsed": true,
     "scrolled": false
    },
    "outputs": [],
@@ -680,7 +678,7 @@
    "cell_type": "code",
    "execution_count": null,
    "metadata": {
-    "collapsed": false,
+    "collapsed": true,
     "scrolled": false
    },
    "outputs": [],
@@ -693,7 +691,7 @@
    "cell_type": "code",
    "execution_count": null,
    "metadata": {
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
diff --git a/notebooks/AGIPD/Characterize_AGIPD_Gain_FlatFields_NBC.ipynb b/notebooks/AGIPD/Characterize_AGIPD_Gain_FlatFields_NBC.ipynb
index 9b1354ba3a1a145f4785e93d83cffcd2d8d7481c..ab7a4513602b4aa1b479a186af84c30f74bece0c 100644
--- a/notebooks/AGIPD/Characterize_AGIPD_Gain_FlatFields_NBC.ipynb
+++ b/notebooks/AGIPD/Characterize_AGIPD_Gain_FlatFields_NBC.ipynb
@@ -23,7 +23,7 @@
    "cell_type": "code",
    "execution_count": null,
    "metadata": {
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
@@ -226,7 +226,7 @@
    "cell_type": "code",
    "execution_count": null,
    "metadata": {
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
@@ -390,7 +390,7 @@
    "cell_type": "code",
    "execution_count": null,
    "metadata": {
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
@@ -500,9 +500,7 @@
   },
   {
    "cell_type": "markdown",
-   "metadata": {
-    "collapsed": false
-   },
+   "metadata": {},
    "source": [
     "Finally, we inspect the results, by plotting the number of entries, peak locations and resulting gain maps for each peak. In the course of doing so, we identify bad pixels by either having 0 entries for a peak, or having `nan` values for the peak location."
    ]
@@ -511,7 +509,7 @@
    "cell_type": "code",
    "execution_count": null,
    "metadata": {
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
@@ -781,7 +779,7 @@
    "cell_type": "code",
    "execution_count": null,
    "metadata": {
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
@@ -808,7 +806,7 @@
    "cell_type": "code",
    "execution_count": null,
    "metadata": {
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
@@ -869,7 +867,7 @@
    "cell_type": "code",
    "execution_count": null,
    "metadata": {
-    "collapsed": false,
+    "collapsed": true,
     "scrolled": true
    },
    "outputs": [],
@@ -983,7 +981,7 @@
    "cell_type": "code",
    "execution_count": null,
    "metadata": {
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
diff --git a/notebooks/AGIPD/Chracterize_AGIPD_Gain_PC_NBC.ipynb b/notebooks/AGIPD/Chracterize_AGIPD_Gain_PC_NBC.ipynb
index a3f42957e45b58419e517bf2b0c7cc9e7aeaa8c3..44adaee3e0db05c95d50116fd835785c10c71ea8 100644
--- a/notebooks/AGIPD/Chracterize_AGIPD_Gain_PC_NBC.ipynb
+++ b/notebooks/AGIPD/Chracterize_AGIPD_Gain_PC_NBC.ipynb
@@ -147,7 +147,7 @@
    "cell_type": "code",
    "execution_count": null,
    "metadata": {
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
@@ -300,7 +300,7 @@
    "cell_type": "code",
    "execution_count": null,
    "metadata": {
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
@@ -724,7 +724,7 @@
    "cell_type": "code",
    "execution_count": null,
    "metadata": {
-    "collapsed": false,
+    "collapsed": true,
     "scrolled": true
    },
    "outputs": [],
@@ -1052,7 +1052,7 @@
    "cell_type": "code",
    "execution_count": null,
    "metadata": {
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
@@ -1071,7 +1071,7 @@
    "cell_type": "code",
    "execution_count": null,
    "metadata": {
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
@@ -1091,7 +1091,7 @@
    "cell_type": "code",
    "execution_count": null,
    "metadata": {
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
@@ -1288,7 +1288,7 @@
    "cell_type": "code",
    "execution_count": null,
    "metadata": {
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [