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

Remove unnecessary flag bits #732

Merged
merged 4 commits into from
Jan 31, 2024
Merged
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
8 changes: 2 additions & 6 deletions src/toast/observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,8 @@ def set_default_values(values=None):
#
# ground-specific flag masks
#
"shared_mask_turnaround": 2,
"shared_mask_elnod": 4,
"shared_mask_scan_leftright": 8,
"shared_mask_scan_rightleft": 16,
"shared_mask_sun_up": 32,
"shared_mask_sun_close": 64,
"shared_mask_sun_up": 16,
"shared_mask_sun_close": 32,
#
# ground-specific interval names
#
Expand Down
27 changes: 15 additions & 12 deletions src/toast/ops/filterbin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2015-2023 by the parties listed in the AUTHORS file.
# Copyright (c) 2015-2024 by the parties listed in the AUTHORS file.
# All rights reserved. Use of this source code is governed by
# a BSD-style license that can be found in the LICENSE file.

Expand Down Expand Up @@ -534,14 +534,14 @@ class FilterBin(Operator):
False, help="Apply a different template for left and right scans"
)

leftright_mask = Int(
defaults.shared_mask_scan_leftright,
help="Bit mask value for left-to-right scans",
leftright_interval = Unicode(
defaults.throw_leftright_interval,
help="Intervals for left-to-right scans",
)

rightleft_mask = Int(
defaults.shared_mask_scan_rightleft,
help="Bit mask value for right-to-left scans",
rightleft_interval = Unicode(
defaults.throw_rightleft_interval,
help="Intervals for right-to-left scans",
)

poly_filter_order = Int(1, allow_none=True, help="Polynomial order")
Expand Down Expand Up @@ -1006,13 +1006,16 @@ def _add_ground_templates(self, obs, templates):
if not self.split_ground_template:
legendre_filter = legendre_templates
else:
# Separate ground filter by scan direction. These bit masks are
# hard-coded in sim_ground.py
# Separate ground filter by scan direction.
legendre_filter = []
mask1 = (shared_flags & self.leftright_mask) != 0
mask2 = (shared_flags & self.rightleft_mask) != 0
masks = []
for name in self.leftright_interval, self.rightleft_interval:
mask = np.zeros(phase.size, dtype=bool)
for ival in obs.intervals[name]:
mask[ival.first : ival.last + 1] = True
masks.append(mask)
for template in legendre_templates:
for mask in mask1, mask2:
for mask in masks:
temp = template.copy()
temp[mask] = 0
legendre_filter.append(temp)
Expand Down
24 changes: 14 additions & 10 deletions src/toast/ops/groundfilter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2015-2020 by the parties listed in the AUTHORS file.
# Copyright (c) 2015-2024 by the parties listed in the AUTHORS file.
# All rights reserved. Use of this source code is governed by
# a BSD-style license that can be found in the LICENSE file.

Expand Down Expand Up @@ -131,14 +131,14 @@ class GroundFilter(Operator):
False, help="Apply a different template for left and right scans"
)

leftright_mask = Int(
defaults.shared_mask_scan_leftright,
help="Bit mask value for left-to-right scans",
leftright_interval = Unicode(
defaults.throw_leftright_interval,
help="Intervals for left-to-right scans",
)

rightleft_mask = Int(
defaults.shared_mask_scan_rightleft,
help="Bit mask value for right-to-left scans",
rightleft_interval = Unicode(
defaults.throw_rightleft_interval,
help="Intervals for right-to-left scans",
)

@traitlets.validate("det_mask")
Expand Down Expand Up @@ -226,10 +226,14 @@ def build_templates(self, obs):
# Create separate templates for alternating scans
common_flags = obs.shared[self.shared_flags].data
legendre_filter = []
mask1 = (common_flags & self.rightleft_mask) == 0
mask2 = (common_flags & self.leftright_mask) == 0
masks = []
for name in self.leftright_interval, self.rightleft_interval:
mask = np.zeros(phase.size, dtype=bool)
for ival in obs.intervals[name]:
mask[ival.first : ival.last + 1] = True
masks.append(mask)
for template in legendre_templates:
for mask in mask1, mask2:
for mask in masks:
temp = template.copy()
temp[mask] = 0
legendre_filter.append(temp)
Expand Down
2 changes: 1 addition & 1 deletion src/toast/ops/polyfilter/polyfilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ class PolyFilter(Operator):
)

shared_flag_mask = Int(
defaults.shared_mask_invalid | defaults.shared_mask_turnaround,
defaults.shared_mask_nonscience,
help="Bit mask value for optional shared flagging",
)

Expand Down
18 changes: 4 additions & 14 deletions src/toast/ops/sim_ground.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,17 +298,8 @@ class SimGround(Operator):
)

turnaround_mask = Int(
defaults.shared_mask_turnaround, help="Bit mask to raise turnaround flags with"
)

leftright_mask = Int(
defaults.shared_mask_scan_leftright,
help="Bit mask to raise left-to-right flags with",
)

rightleft_mask = Int(
defaults.shared_mask_scan_rightleft,
help="Bit mask to raise right-to-left flags with",
defaults.shared_mask_unstable_scanrate,
help="Bit mask to raise turnaround flags with"
)

sun_up_mask = Int(
Expand All @@ -320,7 +311,8 @@ class SimGround(Operator):
)

elnod_mask = Int(
defaults.shared_mask_elnod, help="Bit mask to raise elevation nod flags with"
defaults.shared_mask_irregular,
help="Bit mask to raise elevation nod flags with",
)

@traitlets.validate("telescope")
Expand Down Expand Up @@ -809,8 +801,6 @@ def _exec(self, data, detectors=None, **kwargs):
shared_flag_bytes=1,
view_mask=[
(self.turnaround_interval, self.turnaround_mask),
(self.throw_leftright_interval, self.leftright_mask),
(self.throw_rightleft_interval, self.rightleft_mask),
(self.sun_up_interval, self.sun_up_mask),
(self.sun_close_interval, self.sun_close_mask),
(self.elnod_interval, self.elnod_mask),
Expand Down
13 changes: 8 additions & 5 deletions src/toast/tests/ops_groundfilter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2015-2020 by the parties listed in the AUTHORS file.
# Copyright (c) 2015-2024 by the parties listed in the AUTHORS file.
# All rights reserved. Use of this source code is governed by
# a BSD-style license that can be found in the LICENSE file.

Expand All @@ -23,7 +23,7 @@ def setUp(self):
fixture_name = os.path.splitext(os.path.basename(__file__))[0]
self.outdir = create_outdir(self.comm, fixture_name)
np.random.seed(123456)
self.shared_flag_mask = 1
self.shared_flag_mask = defaults.shared_mask_invalid

def test_groundfilter(self):
# Create a fake ground data set for testing
Expand Down Expand Up @@ -102,10 +102,13 @@ def test_groundfilter_split(self):

rms = dict()
for ob in data.obs:
shared_flags = ob.shared[defaults.shared_flags].data
rightgoing = (shared_flags & defaults.shared_mask_scan_leftright) != 0
leftgoing = (shared_flags & defaults.shared_mask_scan_rightleft) != 0
az = ob.shared[defaults.azimuth].data * 100
rightgoing = np.zeros(az.size, dtype=bool)
for ival in ob.intervals[defaults.throw_leftright_interval]:
rightgoing[ival.first : ival.last + 1] = True
leftgoing = np.zeros(az.size, dtype=bool)
for ival in ob.intervals[defaults.throw_rightleft_interval]:
leftgoing[ival.first : ival.last + 1] = True
rms[ob.name] = dict()
for det in ob.select_local_detectors(flagmask=defaults.det_mask_invalid):
flags = ob.shared[defaults.shared_flags].data & self.shared_flag_mask
Expand Down
20 changes: 8 additions & 12 deletions src/toast/tests/ops_sim_ground.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2015-2020 by the parties listed in the AUTHORS file.
# Copyright (c) 2015-2024 by the parties listed in the AUTHORS file.
# All rights reserved. Use of this source code is governed by
# a BSD-style license that can be found in the LICENSE file.

Expand Down Expand Up @@ -235,19 +235,15 @@ def test_phase(self):

assert np.std(az1 - az2) > 1e-10

# Verify that the flags still identify left-right scans correctly
# Verify that the intervals still identify left-right scans correctly

flags1 = data1.obs[0].shared["flags"][:]
flags2 = data2.obs[0].shared["flags"][:]
good1 = np.zeros(az1.size, dtype=bool)
good2 = np.zeros(az2.size, dtype=bool)

good1 = np.logical_and(
(flags1 & sim_ground.leftright_mask) != 0,
(flags1 & sim_ground.turnaround_mask) == 0,
)
good2 = np.logical_and(
(flags2 & sim_ground.leftright_mask) != 0,
(flags2 & sim_ground.turnaround_mask) == 0,
)
for ival in data1.obs[0].intervals[defaults.scan_leftright_interval]:
good1[ival.first : ival.last + 1] = True
for ival in data2.obs[0].intervals[defaults.scan_leftright_interval]:
good2[ival.first : ival.last + 1] = True

step1 = np.median(np.diff(az1[good1]))
step2 = np.median(np.diff(az2[good2]))
Expand Down
Loading