Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ops.SimpleJumpCorrect: Flag detector invalid if too many jumps. #798

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
ops.SimpleJumpCorrect: Flag detector invalid if too many jumps.
Add input option `njump_limit`. If there are more than `njump_limit`
jumps in one detector data, then flag the detector and time stream as invalid.
Bai-Chiang committed Nov 4, 2024
commit 9d2cb4236d64d24e6adff7e39ebd1c37e3849de3
22 changes: 19 additions & 3 deletions src/toast/ops/simple_jumpcorrect.py
Original file line number Diff line number Diff line change
@@ -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