Skip to content
Open
Show file tree
Hide file tree
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
16 changes: 15 additions & 1 deletion sotodlib/preprocess/processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1510,7 +1510,8 @@ def calc_and_save(self, aman, proc_aman):
calc_aman.wrap('turnarounds', ta, [(0, 'dets'), (1, 'samps')])

if ('merge_subscans' not in self.calc_cfgs) or (self.calc_cfgs['merge_subscans']):
calc_aman.wrap('subscan_info', aman.subscan_info)
if hasattr(aman, 'subscan_info'):
calc_aman.wrap('subscan_info', aman.subscan_info)

self.save(proc_aman, calc_aman)
return aman, proc_aman
Expand All @@ -1526,6 +1527,19 @@ def process(self, aman, proc_aman, sim=False, data_aman=None):
raise NotImplementedError("No support for using data AxisManager in process")
tod_ops.flags.get_turnaround_flags(aman, **self.process_cfgs)
return aman, proc_aman

def select(self, meta, proc_aman=None, in_place=True):
if self.select_cfgs is None:
return meta
if proc_aman is None:
proc_aman = meta.preprocess

ta = proc_aman[self.save_name].turnarounds

if np.all(count_cuts(ta) == 0):
meta.restrict('dets', meta.dets.vals[:0])

return meta

class SubPolyf(_Preprocess):
"""Fit TOD in each subscan with polynominal of given order and subtract it.
Expand Down
19 changes: 17 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=0.):
"""
Compute turnaround flags for a dataset.

Expand Down Expand Up @@ -195,6 +196,8 @@ 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
(Optional). Minimum azimuth throw required to attempt turnaround flagging. Returns no turnarounds if below threshold.

Returns
-------
Expand All @@ -203,6 +206,18 @@ def get_turnaround_flags(aman, az=None, method='scanspeed', name='turnarounds',
"""
if az is None :
az = aman.boresight.az

# Get the throw (convert to degrees).
az_throw = np.ptp(az) * 90 / np.pi

# If the throw is below the threshold, just output empty flags
if az_throw < az_throw_threshold:
ta_flag = Ranges.from_bitmask(np.zeros(aman.samps.count, dtype=bool))
ta_exp = RangesMatrix([ta_flag for i in range(aman.dets.count)])
if method == 'scanspeed':
return ta_exp, ta_exp, ta_exp
return ta_exp


if method not in ['az', 'scanspeed']:
raise ValueError('Unsupported method. Supported methods are `az` or `scanspeed`')
Expand Down Expand Up @@ -1237,4 +1252,4 @@ def get_good_distribution_flags(aman, param_name='wn_signal',
det_mask[aman[param_name] >= np.nanmax(distributions)] = False
else:
det_mask[aman[param_name] <= np.nanmin(distributions)] = False
return det_mask
return det_mask