From d862aab80ed7b94e8a0a1d32ea90bdc833973f13 Mon Sep 17 00:00:00 2001 From: karnem <mikhail.karnevskiy@desy.de> Date: Sun, 29 Dec 2019 16:40:51 +0100 Subject: [PATCH] comparison with constants in summary --- notebooks/LPD/LPDChar_Darks_NBC.ipynb | 46 +++++++-------------------- 1 file changed, 12 insertions(+), 34 deletions(-) diff --git a/notebooks/LPD/LPDChar_Darks_NBC.ipynb b/notebooks/LPD/LPDChar_Darks_NBC.ipynb index 09826cea8..0e878db3a 100644 --- a/notebooks/LPD/LPDChar_Darks_NBC.ipynb +++ b/notebooks/LPD/LPDChar_Darks_NBC.ipynb @@ -68,7 +68,7 @@ "\n", "mem_cells = 512 # number of memory cells used\n", "local_output = True # output constants locally\n", - "db_output = True # output constants to database\n", + "db_output = False # output constants to database\n", "bias_voltage = 250 # detector bias voltage\n", "cal_db_interface = \"tcp://max-exfl016:8015#8025\" # the database interface to use\n", "cal_db_timeout = 300000 # timeout on caldb requests\"\n", @@ -192,8 +192,7 @@ "outputs": [], "source": [ "# set everything up filewise\n", - "if not os.path.exists(out_folder):\n", - " os.makedirs(out_folder)\n", + "os.makedirs(out_folder, exist_ok=True)\n", "\n", "gmf = gain_map_files(in_folder, gain_runs, sequences, DET_FILE_INSET, QUADRANTS, MODULES_PER_QUAD)\n", "gain_mapped_files, total_sequences, total_file_size = gmf" @@ -359,30 +358,6 @@ "logger.send()" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# save everything to file.\n", - "if local_output:\n", - " for cap in capacitor_settings:\n", - " runs = [v for k, v in gain_runs.items() if cap in k]\n", - " ofile = \"{}/lpd_offset_store_{}_{}_{}.h5\".format(out_folder, \n", - " \"_\".join(runs), \n", - " cap, \n", - " \"_\".join([str(m) for m in modules]))\n", - " store_file = h5py.File(ofile, \"w\")\n", - " for qm in offset_g[cap].keys():\n", - " store_file[\"{}/Offset/0/data\".format(qm)] = offset_g[cap][qm]\n", - " store_file[\"{}/Noise/0/data\".format(qm)] = noise_g[cap][qm]\n", - " store_file[\"{}/BadPixelsDark/0/data\".format(qm)\n", - " ] = badpix_g[cap][qm]\n", - " store_file.close()\n", - " print('Constants are stored to {}'.format(ofile))" - ] - }, { "cell_type": "code", "execution_count": null, @@ -414,6 +389,8 @@ " if mdata is not None and data is not None:\n", " time = mdata.calibration_constant_version.begin_at\n", " old_mdata[const] = time.isoformat()\n", + " os.makedirs('{}/old/'.format(out_folder), exist_ok=True)\n", + " save_const_to_h5(mdata, '{}/old/'.format(out_folder))\n", " else:\n", " old_mdata[const] = \"Not found\"" ] @@ -455,6 +432,10 @@ "# Save constants in the calibration DB\n", "for cap in capacitor_settings:\n", " for qm in res[cap]:\n", + " # Do not store empty constants\n", + " # In case of 0 trains data_g is initiated with nans and never refilled.\n", + " if np.count_nonzero(~np.isnan(data_g[cap][qm]))==0:\n", + " continue\n", " for const in res[cap][qm]:\n", "\n", " metadata = ConstantMetaData()\n", @@ -577,7 +558,7 @@ "for cap in capacitor_settings:\n", " for i in modules:\n", " qm = \"Q{}M{}\".format(i//4+1, i % 4+1)\n", - " if data_g[cap][qm].shape[0] == 0:\n", + " if np.count_nonzero(~np.isnan(data_g[cap][qm])) == 0:\n", " break\n", " for gain in range(3):\n", " data = data_g[cap][qm][:, gain]\n", @@ -743,11 +724,11 @@ " display(\n", " Markdown('### Cell-12 overview - {} gain'.format(gain_names[gain])))\n", "\n", - " fig = plt.figure(figsize=(15, 12) , tight_layout={'pad': 0.1, 'w_pad': 0.1})\n", + " fig = plt.figure(figsize=(18, 22) , tight_layout={'pad': 0.1, 'w_pad': 0.1})\n", " for qm in res[cap]:\n", " for iconst, const in enumerate(['Offset', 'Noise', 'BadPixelsDark']):\n", "\n", - " ax = fig.add_subplot(221+iconst)\n", + " ax = fig.add_subplot(321+iconst)\n", "\n", " data = res[cap][qm][const][:, :, 12, gain]\n", " vmax = 1.5 * np.nanmedian(res[cap][qm][const][:, :, 12, gain])\n", @@ -779,9 +760,6 @@ " use_axis=ax,\n", " title='{}'.format(title))\n", "\n", - " #show_overview(res[cap], cell, gain, out_folder=out_folder, infix=\"_\".join(gain_runs.values()))\n", - "\n", - " fig = plt.figure(figsize=(10, 5))\n", " for qm in res[cap]:\n", " for iconst, const in enumerate(['Offset', 'Noise']):\n", " data = res[cap][qm][const]\n", @@ -805,7 +783,7 @@ " },\n", " ]\n", "\n", - " ax = fig.add_subplot(121+iconst)\n", + " ax = fig.add_subplot(325+iconst)\n", " _ = simplePlot(d, figsize=(5, 7), aspect=1,\n", " x_label=\"{} value [ADU]\".format(const),\n", " y_label=\"# of occurance\",\n", -- GitLab