Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
20 changes: 18 additions & 2 deletions sotodlib/tod_ops/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ def get_det_bias_flags(aman, detcal=None, rfrac_range=(0.1, 0.7),
def get_turnaround_flags(aman, az=None, method='scanspeed', name='turnarounds',
merge=True, merge_lr=True, overwrite=True,
t_buffer=2., kernel_size=400, peak_threshold=0.1, rel_distance_peaks=0.3,
truncate=False, qlim=1, merge_subscans=True, turnarounds_in_subscan=False):
truncate=False, qlim=1, merge_subscans=True, turnarounds_in_subscan=False,
az_throw_threshold=None):
"""
Compute turnaround flags for a dataset.

Expand Down Expand Up @@ -195,15 +196,30 @@ def get_turnaround_flags(aman, az=None, method='scanspeed', name='turnarounds',
(Optional). Also merge an AxisManager with subscan information.
turnarounds_in_subscan : bool
(Optional). Turnarounds are included as part of a subscan.
az_throw_threshold : float
Minimum azimuth throw required to attempt turnaround flagging. If ``aman.obs_info.az_throw`` falls below this value,
the obs is treated as stationary or incomplete and a ``ValueError`` is raised instead.

Returns
-------
Ranges : RangesMatrix
The turnaround flags as a Ranges object.
"""
if az_throw_threshold is None:
raise ValueError(
"`az_throw_threshold` is required and cannot be None"
)

if az is None :
az = aman.boresight.az


# Check that telescope was scanning.
if aman.obs_info.az_throw < az_throw_threshold:
raise ValueError(
f"""Azimuth motion {aman.obs_info.az_throw} is too small compared to threshold {az_throw_threshold}
to compute turnaround flags"""
)

if method not in ['az', 'scanspeed']:
raise ValueError('Unsupported method. Supported methods are `az` or `scanspeed`')

Expand Down
4 changes: 2 additions & 2 deletions sotodlib/tod_ops/sub_polyf.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def subscan_polyfilter(aman, degree, signal_name="signal", exclude_turnarounds=F
if exclude_turnarounds:
if ("left_scan" not in aman.flags) or ("turnarounds" not in aman.flags):
logger.warning('aman does not have left/right scan or turnarounds flag. `sotodlib.flags.get_turnaround_flags` will be ran with default parameters')
_ = flags.get_turnaround_flags(aman,truncate=True)
_ = flags.get_turnaround_flags(aman,az_throw_threshold=0.,truncate=True)
ls_mask = aman.flags["left_scan"].mask()
rs_mask = aman.flags["right_scan"].mask()
ta_mask = aman.flags["turnarounds"].mask()
Expand All @@ -60,7 +60,7 @@ def subscan_polyfilter(aman, degree, signal_name="signal", exclude_turnarounds=F
else:
if ("left_scan" not in aman.flags):
logger.warning('aman does not have left/right scan. `sotodlib.flags.get_turnaround_flags` will be ran with default parameters')
_ = flags.get_turnaround_flags(aman,truncate=True)
_ = flags.get_turnaround_flags(aman,az_throw_threshold=0.,truncate=True)

ls_mask = aman.flags["left_scan"].mask()
rs_mask = aman.flags["right_scan"].mask()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_psd.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def test_wn_debias(self):
boresight.wrap("az", az, [(0, "samps")])
aman.wrap('boresight', boresight)
aman.wrap('flags', core.AxisManager(aman.dets, aman.samps))
get_turnaround_flags(aman)
get_turnaround_flags(aman, az_throw_threshold = 0.1)

# test default arguments, this is biased
calc_psd(aman, merge=True, nperseg=2**18)
Expand Down
Loading