Skip to content
Snippets Groups Projects

[AGIPD][DARK-NB] add summary info over module for dark report

Merged Karim Ahmed requested to merge feat/add_dark_summary_info_overmodules into master
Files
5
@@ -104,41 +104,66 @@ def plot_badpix_3d(data, definitions, title=None, rebin_fac=2, azim=22.5):
if title:
t = ax.set_title(title)
from IPython.display import HTML, display, Markdown, Latex
import tabulate
def create_constant_overview(constant, name, cells, vmin=None, vmax=None, entries=3,
out_folder=None, infix=None):
gmap = {0: 'High', 1: 'Medium', 2: 'Low'}
def create_constant_overview(constant, name, cells, vmin=None, vmax=None,
entries=3, out_folder=None, infix=None,
badpixels=None, gmap=None):
"""
Create a step plot for constant data across memory cells for requested
gain entries
:param constant: dict with constants for each module.
:param name: Name to be used for the x-axis
:param cells: Number of memory cells
:param vmin: plot minumim value boundaries
:param vmax: plot maximum value boundaries
:param entries: (int)number of gain entries.
A tuple specifying the range can also be used.
TODO: remove unused inputs from notebooks.
:param out_folder: out_folder for showing .md table statistics
:param infix: infix for the output png image
:param badpixels: A list of 2 elements.
badpixels[0] has the dict with badpixels constant for each module
and badpixels[1] has the value to apply for bad pixels.
:param gmap: A list with len equal to number of gain entires.
if not supported, a default would be used for 3 entries.
['High gain', 'Medium gain', 'Low gain']
:return:
"""
if gmap is None:
gmap = ['High gain', 'Medium gain', 'Low gain']
fig = plt.figure(figsize=(10, 5))
ax = fig.add_subplot(111)
for g in range(entries):
fig = plt.figure(figsize=(10, 5))
ax = fig.add_subplot(111)
table = []
dbp = None
for qm in constant.keys():
if len(constant[qm].shape) == 4:
d = constant[qm][..., g]
if badpixels is not None and isinstance(badpixels, list):
dbp = np.copy(d)
dbp[badpixels[0][qm][..., g] > 0] = badpixels[1]
else:
# This case was introduced for DSSC dark
# it uses this function but have a constant
# of shape (x, y, z), unlike AGIPD.
# e.g. DSSC
d = constant[qm]
#print("{} {}, gain {:0.2f}: mean: {:0.2f}, median: {:0.2f}, std: {:0.2f}".format(name, qm, g,
# np.nanmean(d),
# np.nanmedian(d),
# np.nanstd(d)))
table.append([name, qm, gmap[g], np.nanmean(d), np.nanmedian(d), np.nanstd(d)])
ax.step(np.arange(cells), np.nanmean(d, axis=(0,1)))
ax.set_xlabel("Memory cell")
ax.set_ylabel(name)
ax.set_title("{} Gain Median per Cell".format(gmap[g]))
if vmin and vmax:
ax.set_ylim(vmin, vmax)
#if out_folder and infix:
# fig.savefig("{}/dark_analysis_{}_{}_per_cell_gain{}.png".format(out_folder,
# infix,
# name, g))
# headers = ["Constant", "Module", "Gain", "Mean", "Median", "Standard dev."]
#md = display(Latex(tabulate.tabulate(table, tablefmt='latex', headers=headers)))
if badpixels is not None and isinstance(badpixels, list):
dbp = np.copy(d)
dbp[badpixels[0][qm] > 0] = badpixels[1]
# TODO: check if not used to remove.
table.append([name, qm, gmap[g], np.nanmean(d), np.nanmedian(d),
np.nanstd(d)])
ax.step(np.arange(cells), np.nanmean(d, axis=(0,1)),
label=f'{gmap[g]}', color=f'C{g}')
# Plotting good pixels only if bad-pixels were given
if dbp is not None:
ax.step(np.arange(cells), np.nanmean(dbp, axis=(0, 1)),
label=f'Good pixels {gmap[g]}', color=f'C{g}',
linestyle='--')
ax.set_xlabel("Memory cell")
ax.set_ylabel(name)
ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))
ax.set_title(f"{name} Median per Cell".format(gmap[g]))
if vmin and vmax:
ax.set_ylim(vmin, vmax)
Loading