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
1 unresolved thread
Files
5
@@ -104,41 +104,56 @@ 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):
def create_constant_overview(constant, name, cells, vmin=None, vmax=None,
entries=3, out_folder=None, infix=None, badpixels=None):
"""
Create a step plot for constant data across memory cells for requested
gain entries
:param constant:
: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: number of gain entries
TODO: remove unused inputs from notebooks.
:param out_folder: out_folder for showing .md table statistics
:param infix: infix for the output png image
:return:
"""
gmap = {0: 'High', 1: 'Medium', 2: 'Low'}
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:
dbp = np.copy(d)
dbp[badpixels[qm][..., g] > 0] = np.nan
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:
dbp = np.copy(d)
dbp[badpixels[qm] > 0] = np.nan
# 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]}-Gain', 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]}-Gain', color=f'C{g}',
linestyle='--')
ax.set_xlabel("Memory cell")
ax.set_ylabel(name)
ax.legend()
ax.set_title(f"{name} Median per Cell".format(gmap[g]))
if vmin and vmax:
ax.set_ylim(vmin, vmax)
Loading