Skip to content

Commit

Permalink
Merge pull request #798 from Bai-Chiang/jump_finder_fix
Browse files Browse the repository at this point in the history
ops.SimpleJumpCorrect: Flag detector invalid if too many jumps.
  • Loading branch information
Bai-Chiang authored Nov 4, 2024
2 parents 884808a + 9d2cb42 commit defcf34
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/toast/ops/simple_jumpcorrect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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 = []
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit defcf34

Please sign in to comment.