From fb33fa3538dc7738be2a7cd994af29d7a2484543 Mon Sep 17 00:00:00 2001 From: Marko Mecina <marko.mecina@univie.ac.at> Date: Thu, 21 Mar 2024 13:02:07 +0100 Subject: [PATCH] update BadPixelMask class --- Ccs/calibrations_SMILE.py | 52 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/Ccs/calibrations_SMILE.py b/Ccs/calibrations_SMILE.py index b607d78..3fff33d 100644 --- a/Ccs/calibrations_SMILE.py +++ b/Ccs/calibrations_SMILE.py @@ -716,7 +716,7 @@ def calibrate_ext(adu, signal, exception=False): # return adu if not exception else None -class BadPixelMask: +class _BadPixelMask2: """ Convenience functions for handling the SMILE SXI bad pixel mask stored in MRAM """ @@ -724,6 +724,9 @@ class BadPixelMask: NROWS = 639 NCOLS = 384 + CCD2_MASK_ADDR = 0x40654C00 + CCD4_MASK_ADDR = 0x4065CC00 + @classmethod def from_bytes(cls, buffer): return np.unpackbits(bytearray(buffer)).reshape((cls.NROWS, cls.NCOLS)) @@ -743,6 +746,53 @@ class BadPixelMask: return np.zeros((cls.NROWS, cls.NCOLS), dtype=int) +class BadPixelMask: + + NROWS = 639 + NCOLS = 384 + + CCD2_MASK_ADDR = 0x40654C00 + CCD4_MASK_ADDR = 0x4065CC00 + + def __init__(self): + self._bin_len = int((self.NROWS * self.NCOLS) / 8) + self._bin = bytes(self._bin_len) + + @property + def binary(self): + return self._bin + + @binary.setter + def binary(self, data: bytes): + + assert isinstance(data, bytes) + assert len(data) == self._bin_len + + self._bin = data + + @property + def array(self): + return np.unpackbits(bytearray(self._bin)).reshape((self.NROWS, self.NCOLS)) + + @array.setter + def array(self, arr: np.ndarray): + + assert isinstance(arr, np.ndarray) + assert arr.shape == (self.NROWS, self.NCOLS) + + self._bin = bytes(np.packbits(arr)) + + def mask_pixel(self, row, col): + mask = self.array + mask[row, col] = 1 + self.array = mask + + def unmask_pixel(self, row, col): + mask = self.array + mask[row, col] = 0 + self.array = mask + + if __name__ == '__main__': import matplotlib.pyplot as plt -- GitLab