diff --git a/src/toast/ops/simple_jumpcorrect.py b/src/toast/ops/simple_jumpcorrect.py index 434eac3b5..96d7468a6 100644 --- a/src/toast/ops/simple_jumpcorrect.py +++ b/src/toast/ops/simple_jumpcorrect.py @@ -94,6 +94,12 @@ class SimpleJumpCorrect(Operator): help="Minimum number of good samples in an interval", ) + njump_limit = Int( + 10, + help="If the detector has more than `njump_limit` jumps the detector " + "the detector and time stream will be flagged as invalid.", + ) + @traitlets.validate("det_mask") def _check_det_mask(self, proposal): check = proposal["value"] @@ -115,6 +121,13 @@ def _check_det_flag_mask(self, proposal): raise traitlets.TraitError("Det flag mask should be a positive integer") return check + @traitlets.validate("njump_limit") + def _check_det_flag_mask(self, proposal): + check = proposal["value"] + if check <= 0: + raise traitlets.TraitError("njump limit should be a positive integer") + return check + def __init__(self, **kwargs): super().__init__(**kwargs) self.net_factors = [] @@ -165,7 +178,8 @@ def _find_peaks(self, toi, flag, flag_out, lim=3.0, tol=1e4, sigma_in=None): npeak = np.ma.sum(np.abs(mytoi) > sigma * lim) # Only one jump per iteration - while npeak > 0: + # And skip remaining if find more than `njump_limit` jumps + while (npeak > 0) and (len(peaks) <= self.njump_limit) : imax = np.argmax(np.abs(mytoi)) amplitude = mytoi[imax] significance = np.abs(amplitude) / sigma @@ -271,8 +285,10 @@ def _exec(self, data, detectors=None, **kwargs): njump = len(peaks) if njump == 0: continue - if njump > 10: - raise RuntimeError(f"Found {njump} jumps!") + if njump > self.njump_limit: + ob._detflags[name] |= self.det_mask + det_flags[ind] |= self.det_flag_mask + continue corrected_signal, flag_out = self._remove_jumps( sig_view, bad_view, peaks, self.jump_radius