From 8db4c0c68ebc1c17a5c4aecbae2d61cfba626cff Mon Sep 17 00:00:00 2001 From: ahmedk <karim.ahmed@xfel.eu> Date: Thu, 27 Oct 2022 13:46:37 +0200 Subject: [PATCH] MR comments, styling and refactors --- ...rk_analysis_all_gains_burst_mode_NBC.ipynb | 6 +-- .../Jungfrau/Jungfrau_darks_Summary_NBC.ipynb | 42 +++++++++---------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/notebooks/Jungfrau/Jungfrau_dark_analysis_all_gains_burst_mode_NBC.ipynb b/notebooks/Jungfrau/Jungfrau_dark_analysis_all_gains_burst_mode_NBC.ipynb index c394e0c86..05bda3f95 100644 --- a/notebooks/Jungfrau/Jungfrau_dark_analysis_all_gains_burst_mode_NBC.ipynb +++ b/notebooks/Jungfrau/Jungfrau_dark_analysis_all_gains_burst_mode_NBC.ipynb @@ -34,7 +34,7 @@ "\n", "# Parameters for calibration database and storing constants.\n", "use_dir_creation_date = True # use dir creation date\n", - "cal_db_interface = 'tcp://max-exfl016:8016' # calibrate db interface to connect to\n", + "cal_db_interface = 'tcp://max-exfl016:8016#8045' # calibrate db interface to connect to\n", "cal_db_timeout = 300000 # timeout on caldb requests\n", "local_output = True # output constants locally\n", "db_output = False # output constants to database\n", @@ -262,7 +262,7 @@ " condition=condition,\n", " empty_constant=None,\n", " cal_db_interface=cal_db_interface,\n", - " creation_time=creation_time-timedelta(seconds=2) if creation_time else None,\n", + " creation_time=creation_time-timedelta(seconds=60) if creation_time else None,\n", " strategy=\"pdu_prior_in_time\",\n", " verbosity=1,\n", " timeout=cal_db_timeout\n", @@ -693,7 +693,7 @@ " for const in consts:\n", " display(Markdown(f\" - {const} at {consts[const]['timestamp']}\"))\n", " # saving locations of old constants for summary notebook\n", - " with open(f\"{metadata_folder}/module_metadata_{mod}.yml\", \"w\") as fd:\n", + " with open(f\"{metadata_folder or out_folder}/module_metadata_{mod}.yml\", \"w\") as fd:\n", " yaml.safe_dump(\n", " {\n", " \"module\": mod,\n", diff --git a/notebooks/Jungfrau/Jungfrau_darks_Summary_NBC.ipynb b/notebooks/Jungfrau/Jungfrau_darks_Summary_NBC.ipynb index 5568147b7..55269def4 100644 --- a/notebooks/Jungfrau/Jungfrau_darks_Summary_NBC.ipynb +++ b/notebooks/Jungfrau/Jungfrau_darks_Summary_NBC.ipynb @@ -127,7 +127,7 @@ "curr_constants = { c: initial_stacked_constants.copy() for c in dark_constants}\n", "prev_constants = { c: initial_stacked_constants.copy() for c in dark_constants}\n", "\n", - "execulded_constants = [] # constants excluded from comparison plots.\n", + "exculded_constants = [] # constants excluded from comparison plots.\n", "\n", "# Loop over modules\n", "for cname in dark_constants:\n", @@ -160,7 +160,7 @@ " # Exclude constants from comparison plots, if the corresponding\n", " # previous constants are not available for all modules.\n", " if len(excluded_modules) == nmods:\n", - " execulded_constants.append(cname)\n", + " exculded_constants.append(cname)\n", " print(f\"No comparison plots for {cname}.\\n\")" ] }, @@ -205,10 +205,11 @@ " \"Noise\": [(0., 5.), (0., 5.), (0., 5.)],\n", " \"BadPixelsDark\": [(0., 5.), (0., 5.), (0., 5.)],\n", "}\n", - "\n", + "percentage_range = (0, 100)\n", + "perc_const_range = {c: [percentage_range]*3 for c in dark_constants}\n", "gs = gridspec.GridSpec(2, 4)\n", "\n", - "axis = OrderedDict({\n", + "axes = {\n", " \"ax0\": {\n", " \"gs\": gs[0, 1:3],\n", " \"shrink\": 0.7,\n", @@ -216,6 +217,7 @@ " \"label\": \"ADCu\",\n", " \"title\": \"{}\",\n", " \"location\": \"right\",\n", + " \"range\": const_range,\n", " },\n", " \"ax1\": {\n", " \"gs\": gs[1, :2],\n", @@ -224,6 +226,7 @@ " \"label\": \"ADCu\",\n", " \"location\": \"left\",\n", " \"title\": \"Difference with previous {}\",\n", + " \"range\": diff_const_range,\n", " },\n", " \"ax2\": {\n", " \"gs\": gs[1, 2:],\n", @@ -231,8 +234,10 @@ " \"pad\": 0.02,\n", " \"label\": \"%\",\n", " \"location\": \"right\",\n", - " \"title\": \"Difference with previous {} %\"},\n", - " })" + " \"title\": \"Difference with previous {} %\",\n", + " \"range\": perc_const_range,\n", + " },\n", + " }" ] }, { @@ -273,20 +278,14 @@ " else:\n", " fig = plt.figure(figsize=(20, 10))\n", " \n", - " for axname, axv in axis.items():\n", - " # Add the min and max plot values for each axis.\n", - " if axname == \"ax0\":\n", - " vmin, vmax = const_range[cname][gain]\n", - " elif axname == \"ax2\":\n", - " vmin, vmax = 0, 100\n", - " else:\n", - " vmin, vmax = diff_const_range[cname][gain]\n", + " for axname, axv in axes.items():\n", + "\n", " # Avoid difference plots if previous constants\n", " # are missing for the detector.\n", - " if cname in execulded_constants and axname != \"ax0\":\n", + " if cname in exculded_constants and axname != \"ax0\":\n", " break\n", " ax = fig.add_subplot(axv[\"gs\"])\n", - "\n", + " vmin, vmax = axv[\"range\"][cname][gain]\n", " geom.plot_data(\n", " data_to_plot[axname],\n", " vmin=vmin, vmax=vmax, ax=ax, \n", @@ -323,9 +322,10 @@ "outputs": [], "source": [ "if curr_constants[\"Offset\"].shape[-2] > 1:\n", - " display(Markdown(\"## ## Summary across pixels per memory cells\"))\n", + " display(Markdown(\"## Summary across pixels per memory cells\"))\n", "\n", - " # Loop over modules and constants\n", + " # Plot mean and std of memcells for each module, gain, and constant\n", + " # across trains.\n", " for const_name, const in curr_constants.items():\n", " display(Markdown(f'### {const_name}'))\n", "\n", @@ -341,7 +341,7 @@ " figsize=(15, 6),\n", " tight_layout={'pad': 0.2, 'w_pad': 1.3, 'h_pad': 1.3})\n", " label = 'Fraction of bad pixels'\n", - " ax = fig.add_subplot(111)\n", + " ax = fig.add_subplot(1, 1, 1)\n", "\n", " else:\n", " datamean = np.nanmean(data, axis=(1, 2))\n", @@ -349,7 +349,7 @@ " figsize=(15, 6),\n", " tight_layout={'pad': 0.2, 'w_pad': 1.3, 'h_pad': 1.3})\n", " label = f'{const_name} value [ADU], good pixels only'\n", - " ax = fig.add_subplot(121)\n", + " ax = fig.add_subplot(1, 2, 1)\n", "\n", " d = []\n", " for i, mod in enumerate(datamean):\n", @@ -374,7 +374,7 @@ "\n", " # Extra Sigma plot for Offset and Noise constants.\n", " if const_name != 'BadPixelsDark':\n", - " ax = fig.add_subplot(122)\n", + " ax = fig.add_subplot(1, 2, 2)\n", " label = f'$\\sigma$ {const_name} [ADU], good pixels only'\n", " d = []\n", " for i, mod in enumerate(np.nanstd(data, axis=(1, 2))):\n", -- GitLab