From c0fb8ab86b5a2b6c9c59f6ed7c469f6256f98db5 Mon Sep 17 00:00:00 2001 From: Sven Augustin Date: Sun, 15 Feb 2026 14:56:31 +0100 Subject: [PATCH] added a "new" reason mapping; added some CLI switches --- pixel_mask_analysis.py | 52 +++++++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/pixel_mask_analysis.py b/pixel_mask_analysis.py index 5669ba7..efc007b 100755 --- a/pixel_mask_analysis.py +++ b/pixel_mask_analysis.py @@ -24,14 +24,15 @@ def calc_square_plots(n_plots): return nrows, ncols -def make_reasons(): - # this should not be needed, but there is overlap in the reasons - class Trict(dict): - def __setitem__(self, key, value): - if key not in self: - super().__setitem__(key, []) - super().__getitem__(key).append(value) +# this should not be needed, but there is overlap in the old reasons +class Trict(dict): + def __setitem__(self, key, value): + if key not in self: + super().__setitem__(key, []) + super().__getitem__(key).append(value) + +def make_reasons_old(): reasons = Trict() reasons[5] = "additional pixel mask" @@ -51,6 +52,26 @@ def make_reasons(): return res +def make_reasons_new(): + reasons = Trict() + + reasons[0] = "additional pixel mask" + + for gain in range(4): + reasons[gain + 9] = f"std dev of gain {gain}" + + for hg0 in (False, True): + for gain in range(4): + reasons[gain + 4 * hg0 + 1] = f"wrong gain ({gain=})" if not hg0 else f"wrong gain ({gain=}, hg0)" + + res = {} + for k, v in sorted(reasons.items()): + v = " / ".join(v) # this should not be needed + res[1 << k] = v + + return res + + def print_dict(d): for i, (k, v) in enumerate(sorted(d.items())): print(i, k, v, sep="\t") @@ -61,6 +82,8 @@ def print_dict(d): parser = argparse.ArgumentParser(description="Analyse the pixel mask of a pedestal file") parser.add_argument("fname", help="Path to a pedestal file") +parser.add_argument("-o", "--old", action="store_true", help="Use old reasons mapping") +parser.add_argument("-p", "--plot", action="store_true", help="Show plots") clargs = parser.parse_args() @@ -70,7 +93,8 @@ with h5py.File(clargs.fname) as f: data = image[image != 0].flatten() plt.hist(data, bins=np.arange(min(data), max(data)+2)-0.5) -plt.show() +if clargs.plot: + plt.show() values = get_bit_values(image) @@ -92,11 +116,12 @@ plot(image, "raw") mask = image.astype(bool) plot(mask, "mask") +make_reasons = make_reasons_old if clargs.old else make_reasons_new reasons = make_reasons() for val in values: selected = (image & val) != 0 - reason = reasons[val] + reason = reasons.get(val) plot(selected, f"{val} | {val:b} | {reason}") @@ -108,10 +133,11 @@ for ax in axs: ax.set_visible(False) plt.tight_layout() -try: - plt.show() -except KeyboardInterrupt: - pass +if clargs.plot: + try: + plt.show() + except KeyboardInterrupt: + pass