diff --git a/cal_tools/cal_tools/agipdlib.py b/cal_tools/cal_tools/agipdlib.py index 212e5c64eb6231f042baf157281fff6db76e220a..e65d4952f21b66c143006f910b46ac17bf25db56 100644 --- a/cal_tools/cal_tools/agipdlib.py +++ b/cal_tools/cal_tools/agipdlib.py @@ -458,7 +458,7 @@ class AgipdCorrections: for c in cells: std = np.nanstd(data[cellid == c, ...], axis=0) - mask_std[:, c, std == 0] |= BadPixels.DATA_STD_IS_ZERO.value + mask_std[:, c, std == 0] |= BadPixels.DATA_STD_IS_ZERO def offset_correction(self, i_proc: int, first: int, last: int): """ @@ -659,7 +659,7 @@ class AgipdCorrections: if self.corr_bools.get("zero_nans"): bidx = ~np.isfinite(data) data[bidx] = 0 - msk[bidx] |= BadPixels.VALUE_IS_NAN.value + msk[bidx] |= BadPixels.VALUE_IS_NAN del bidx # Add pixels with unrealistically high and low values to the mask. @@ -667,7 +667,7 @@ class AgipdCorrections: if self.corr_bools.get("zero_orange"): bidx = (data < -1e7) | (data > 1e7) data[bidx] = 0 - msk[bidx] |= BadPixels.VALUE_OUT_OF_RANGE.value + msk[bidx] |= BadPixels.VALUE_OUT_OF_RANGE del bidx # Mask entire ADC if they are noise above a threshold diff --git a/cal_tools/cal_tools/agipdutils.py b/cal_tools/cal_tools/agipdutils.py index 347198785c517a8c4e6621466fa374de351ec3b6..d1ff0755f75bcebe94e03e96e2cf3dc2542f0ad0 100644 --- a/cal_tools/cal_tools/agipdutils.py +++ b/cal_tools/cal_tools/agipdutils.py @@ -426,8 +426,8 @@ def make_noisy_adc_mask(bmask, noise_threshold): """ Mask entire ADC if they are noise above a relative threshold """ msk = np.count_nonzero( - ((bmask & BadPixels.NOISE_OUT_OF_THRESHOLD.value != 0) - | (bmask & BadPixels.OFFSET_NOISE_EVAL_ERROR.value != 0)).astype( + ((bmask & BadPixels.NOISE_OUT_OF_THRESHOLD != 0) + | (bmask & BadPixels.OFFSET_NOISE_EVAL_ERROR != 0)).astype( np.int), axis=0) fmask = np.zeros_like(msk).astype(np.uint32) @@ -440,7 +440,7 @@ def make_noisy_adc_mask(bmask, noise_threshold): bmask.shape[0] // 32) if adc_cnt / (adc_i * adc_j) >= noise_threshold: fmask[i * adc_i:(i + 1) * adc_i, - j * adc_j:(j + 1) * adc_j] = BadPixels.NOISY_ADC.value + j * adc_j:(j + 1) * adc_j] = BadPixels.NOISY_ADC return fmask @@ -630,7 +630,7 @@ def melt_snowy_pixels(raw, im, gain, rgain, resolution=None): mim[labels == implabel] = mimb[labels == implabel] mimg[labels == implabel] = 0 # identify these pixels in a bad pixel mask - mmsk[labels == implabel] = BadPixels.INTERPOLATED.value + mmsk[labels == implabel] = BadPixels.INTERPOLATED # now set back to data asic[fidx] = mim diff --git a/cal_tools/cal_tools/agipdutils_ff.py b/cal_tools/cal_tools/agipdutils_ff.py index 97d38ce87718cc5759ac807fd5a506decdffa02d..4cae853275d5683c9760ca5565472d019ea56763 100644 --- a/cal_tools/cal_tools/agipdutils_ff.py +++ b/cal_tools/cal_tools/agipdutils_ff.py @@ -204,7 +204,7 @@ def get_mask(fit_summary: Dict[str, Any], :return: Bad pixel mask """ if not fit_summary['is_valid']: - return BadPixelsFF.FIT_FAILED.value + return BadPixelsFF.FIT_FAILED m0 = fit_summary['g0mean'] s0 = fit_summary['g0sigma'] @@ -215,19 +215,19 @@ def get_mask(fit_summary: Dict[str, Any], mask = 0 if not fit_summary['is_valid']: - mask |= BadPixelsFF.FIT_FAILED.value + mask |= BadPixelsFF.FIT_FAILED if not fit_summary['has_accurate_covar']: - mask |= BadPixelsFF.ACCURATE_COVAR.value + mask |= BadPixelsFF.ACCURATE_COVAR if not peak_lim[0] <= m0 <= peak_lim[1]: - mask |= BadPixelsFF.NOISE_PEAK_THRESHOLD.value + mask |= BadPixelsFF.NOISE_PEAK_THRESHOLD if not d0_lim[0] <= d01 <= d0_lim[1]: - mask |= BadPixelsFF.GAIN_THRESHOLD.value + mask |= BadPixelsFF.GAIN_THRESHOLD if not chi2_lim[0] <= chi2_ndof <= chi2_lim[1]: - mask |= BadPixelsFF.CHI2_THRESHOLD.value + mask |= BadPixelsFF.CHI2_THRESHOLD width_lim = peak_width_lim[0] * s0 inside_s1 = width_lim[0] <= s1 <= width_lim[1] @@ -236,6 +236,6 @@ def get_mask(fit_summary: Dict[str, Any], inside_s2 = width_lim[0] <= s2 <= width_lim[1] if not inside_s1 and inside_s2: - mask |= BadPixelsFF.PEAK_WIDTH_THRESHOLD.value + mask |= BadPixelsFF.PEAK_WIDTH_THRESHOLD return mask diff --git a/cal_tools/cal_tools/enums.py b/cal_tools/cal_tools/enums.py index 19420caeacf38580e808ee0da4a76c508e29e464..4abafdc10b646d7d81c92de9912f8b29f27f1e13 100644 --- a/cal_tools/cal_tools/enums.py +++ b/cal_tools/cal_tools/enums.py @@ -1,7 +1,7 @@ -from enum import Enum +from enum import Enum, IntFlag -class BadPixels(Enum): +class BadPixels(IntFlag): """ The European XFEL Bad Pixel Encoding """ @@ -28,7 +28,7 @@ class BadPixels(Enum): NON_LIN_RESPONSE_REGION = 0b100000000000000000000 # bit 21 -class BadPixelsFF(Enum): +class BadPixelsFF(IntFlag): """ The SLopesFF Bad Pixel Encoding """ diff --git a/cal_tools/cal_tools/lpdlib.py b/cal_tools/cal_tools/lpdlib.py index 716637a5261cbfddeb752758290644c0c1707c0c..34193b6ef96787f7d971d722ab26fd2f8289da03 100644 --- a/cal_tools/cal_tools/lpdlib.py +++ b/cal_tools/cal_tools/lpdlib.py @@ -267,7 +267,7 @@ class LpdCorrections: for gl, lr in enumerate(self.linear_between): midx = (gain == gl) & ((im < lr[0]) | (im > lr[1])) - msk[midx] = BadPixels.NON_LIN_RESPONSE_REGION.value + msk[midx] = BadPixels.NON_LIN_RESPONSE_REGION numnonlin = np.count_nonzero(midx, axis=(1,2)) nlf += numnonlin nlf = nlf/float(im.shape[0] * im.shape[1]) @@ -314,12 +314,12 @@ class LpdCorrections: # create bad pixels masks, here non-finite values bidx = ~np.isfinite(im) im[bidx] = 0 - msk[bidx] = BadPixels.VALUE_IS_NAN.value + msk[bidx] = BadPixels.VALUE_IS_NAN # values which are unphysically large or small bidx = (im < -1e7) | (im > 1e7) im[bidx] = 0 - msk[bidx] = BadPixels.VALUE_OUT_OF_RANGE.value + msk[bidx] = BadPixels.VALUE_OUT_OF_RANGE # on first iteration we create histograms for the report if cidx == 0: