diff --git a/notebooks/LPD/LPDChar_Darks_NBC.ipynb b/notebooks/LPD/LPDChar_Darks_NBC.ipynb index ed1686ed9c72a2ef7c04631e80c805050f957b93..0e276c4af2ed34076b9275554f932f5457c07a0c 100644 --- a/notebooks/LPD/LPDChar_Darks_NBC.ipynb +++ b/notebooks/LPD/LPDChar_Darks_NBC.ipynb @@ -57,7 +57,7 @@ "\n", "high_res_badpix_3d = False # plot bad-pixel summary in high resolution\n", "test_for_normality = False # permorm normality test\n", - "inject_cell_order = False # Include memory cell order as part of the detector condition\n", + "inject_cell_order = 'auto' # Include memory cell order as part of the detector condition: auto/always/never\n", "operation_mode = '' # Detector operation mode, optional" ] }, @@ -145,6 +145,9 @@ " creation_time = get_dir_creation_date(in_folder, run_high)\n", " print(\"Using {} as creation time\".format(creation_time))\n", "\n", + "if inject_cell_order not in {'auto', 'always', 'never'}:\n", + " raise ValueError(\"inject_cell_order must be auto/always/never\")\n", + "\n", "run, prop, seq = run_prop_seq_from_path(in_folder)\n", "\n", "cal_db_interface = get_random_db_interface(cal_db_interface)\n", @@ -346,6 +349,22 @@ " \"db_module\": \"\"}" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "def make_cell_order_condition(use_param, cellid_pattern)\n", + " if use_param == 'auto':\n", + " # auto -> use cell order if it wraps around (cells not filled monotonically)\n", + " use = len(cellid_pattern) > 2 and (np.diff(cellid_pattern) < 0).any()\n", + " else:\n", + " use = (use_param == 'always')\n", + " \n", + " return (\",\".join([str(c) for c in cellid_pattern]) + \",\") if use else None" + ] + }, { "cell_type": "code", "execution_count": null, @@ -367,16 +386,13 @@ " qm_db = qm_dict[qm]\n", " karabo_da = qm_db[\"karabo_da\"]\n", " cellid_pattern = cellid_patterns_g[qm]\n", - " if inject_cell_order:\n", - " mem_cell_order = \",\".join([str(c) for c in cellid_pattern]) + \",\"\n", - " else:\n", - " mem_cell_order = None\n", "\n", - " condition = Conditions.Dark.LPD(memory_cells=max_cells,\n", - " bias_voltage=bias_voltage,\n", - " capacitor=capacitor_setting_s,\n", - " memory_cell_order=mem_cell_order,\n", - " )\n", + " condition = Conditions.Dark.LPD(\n", + " memory_cells=max_cells,\n", + " bias_voltage=bias_voltage,\n", + " capacitor=cap,\n", + " memory_cell_order=make_cell_order_condition(inject_cell_order, cellid_pattern),\n", + " )\n", " for const in clist:\n", " constant = getattr(Constants.LPD, const)()\n", " if not qm_db[\"db_module\"]:\n", @@ -453,11 +469,9 @@ "\n", " karabo_da = qm_dict[qm][\"karabo_da\"]\n", " db_module = qm_dict[qm][\"db_module\"]\n", - " cellid_pattern = cellid_patterns_g[qm]\n", - " if inject_cell_order:\n", - " mem_cell_order = \",\".join([str(c) for c in cellid_pattern]) + \",\"\n", - " else:\n", - " mem_cell_order = None\n", + " mem_cell_order = make_cell_order_condition(\n", + " inject_cell_order, cellid_patterns_g[qm]\n", + " )\n", "\n", " # Do not store empty constants\n", " # In case of 0 trains data_g is initiated with nans and never refilled.\n",