Skip to content

Commit

Permalink
Update preproc split method to match demod mapmaker.
Browse files Browse the repository at this point in the history
  • Loading branch information
msilvafe committed Dec 11, 2024
1 parent bfb4c80 commit 36c4bb8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 66 deletions.
5 changes: 2 additions & 3 deletions sotodlib/mapmaking/demod_mapmaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,9 @@ def add_obs(self, id, obs, nmat, Nd, pmap=None, split_labels=None):
else: rot = None
if self.Nsplits == 1:
# this is the case with no splits
flagnames = ['glitch_flags']
cuts = obs.glitch_flags
else:
flagnames = ['glitch_flags', split_labels[n_split]]
cuts = get_flags(obs, flagnames)
cuts = obs.glitch_flags + obs.preprocess.split_flags.cuts[split_labels[n_split]]
if self.pix_scheme == "rectpix":
threads='domdir'
geom = self.rhs.geometry
Expand Down
44 changes: 0 additions & 44 deletions sotodlib/mapmaking/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,50 +527,6 @@ def downsample_obs(obs, down):
# doesn't matter anyway
return res

def get_flags(obs, flagnames):
from sotodlib.core import FlagManager

"""Parse detector-set splits"""
cuts_out = None
fm = FlagManager.for_tod(obs)
if flagnames is None:
return fm.get_zeros()
det_splits = ['det_left','det_right','det_in','det_out','det_upper','det_lower']
for flagname in flagnames:
if flagname in det_splits:
# Remember that the detectors you want to keep must be False here
if flagname == 'det_left':
fm.wrap_dets('det_left', obs.preprocess.split_flags.right_focal_plane_flag)
cuts = fm.det_left
elif flagname == 'det_right':
fm.wrap_dets('det_right', ~obs.preprocess.split_flags.right_focal_plane_flag)
cuts = fm.det_right
elif flagname == 'det_in':
fm.wrap_dets('det_in', ~obs.preprocess.split_flags.central_pixels_flag)
cuts = fm.det_in
elif flagname == 'det_out':
fm.wrap_dets('det_out', obs.preprocess.split_flags.central_pixels_flag)
cuts = fm.det_out
elif flagname == 'det_upper':
fm.wrap_dets('det_upper', ~obs.preprocess.split_flags.top_focal_plane_flag)
cuts = fm.det_upper
elif flagname == 'det_lower':
fm.wrap_dets('det_lower', obs.preprocess.split_flags.top_focal_plane_flag)
cuts = fm.det_lower
elif flagname == 'scan_left':
cuts = obs.flags.left_scan
elif flagname == 'scan_right':
cuts = obs.flags.right_scan
else:
cuts = getattr(obs.flags, flagname) # obs.flags.flagname

## Add to the output matrix
if cuts_out is None:
cuts_out = cuts
else:
cuts_out += cuts
return cuts_out

def import_optional(module_name):
try:
module = importlib.import_module(module_name)
Expand Down
64 changes: 45 additions & 19 deletions sotodlib/obs_ops/splits.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ def get_split_flags(aman, proc_aman=None, split_cfg=None):
-------
split_aman: AxisManager
Axis manager containing splitting flags.
``cuts`` field is a FlagManager containing the detector and subscan based splits used in the mapmaker.
``<split_name>_threshold`` fields contain the threshold used for the split.
Other fields conatain info for obs-level splits.
'''
if proc_aman is None:
try:
Expand All @@ -101,36 +104,59 @@ def get_split_flags(aman, proc_aman=None, split_cfg=None):
split_cfg = default_cfg

split_aman = AxisManager(aman.dets)
fm = FlagManager.for_tod(aman)
# If provided split config doesn't include all of the splits in default
for k in default_cfg.keys():
if not k in split_cfg:
split_cfg[k] = default_cfg[k]
split_aman.wrap(f'{k}_threshold', split_cfg[k])

split_aman.wrap('high_gain_flag', aman.det_cal.phase_to_pW > split_cfg['high_gain'],
[(0, 'dets')])
# Gain split
fm.wrap_dets('high_gain', aman.det_cal.phase_to_pW > split_cfg['high_gain'])
fm.wrap_dets('low_gain', aman.det_cal.phase_to_pW <= split_cfg['high_gain'])
split_aman.wrap('gain_avg', np.nanmean(aman.det_cal.phase_to_pW))
split_aman.wrap('high_noise_flag', proc_aman.noiseQ_fit.fit[:,1] > split_cfg['high_noise'],
[(0, 'dets')])
# Noise split
fm.wrap_dets('high_noise', proc_aman.noiseQ_fit.fit[:,1] > split_cfg['high_noise'])
fm.wrap_dets('low_noise', proc_aman.noiseQ_fit.fit[:,1] <= split_cfg['high_noise'])
split_aman.wrap('noise_avg', np.nanmean(proc_aman.noiseQ_fit.fit[:,1]))
split_aman.wrap('high_tau_flag', aman.det_cal.tau_eff > split_cfg['high_tau'],
[(0, 'dets')])
# Time constant split
fm.wrap_dets('high_tau', aman.det_cal.tau_eff > split_cfg['high_tau'])
fm.wrap_dets('low_tau', aman.det_cal.tau_eff <= split_cfg['high_tau'])
split_aman.wrap('tau_avg', np.nanmean(aman.det_cal.tau_eff))
split_aman.wrap('det_A_flag', aman.det_info.wafer.pol <= split_cfg['det_A'],
[(0, 'dets')])
split_aman.wrap('pol_angle_flag', aman.det_info.wafer.angle > split_cfg['pol_angle'],
[(0, 'dets')])
split_aman.wrap('det_top_flag', aman.det_info.wafer.crossover > split_cfg['det_top'],
[(0, 'dets')])
split_aman.wrap('high_leakage_flag', np.sqrt(proc_aman.t2p.lamQ**2 + proc_aman.t2p.lamU**2) > split_cfg['high_leakage'],
[(0, 'dets')])
# detAB split
fm.wrap_dets('det_A', aman.det_info.wafer.pol <= split_cfg['det_A'])
fm.wrap_dets('det_B', aman.det_info.wafer.pol > split_cfg['det_A'])
# def pol split
fm.wrap_dets('high_pol_angle', aman.det_info.wafer.angle > split_cfg['pol_angle'])
fm.wrap_dets('low_pol_angle', aman.det_info.wafer.angle <= split_cfg['pol_angle'])
# det top/bottom split
fm.wrap_dets('det_type_top', aman.det_info.wafer.crossover > split_cfg['det_top'])
fm.wrap_dets('det_type_bottom', aman.det_info.wafer.crossover <= split_cfg['det_top'])
# T2P Leakage split
fm.wrap_dets('high_leakage', np.sqrt(proc_aman.t2p.lamQ**2 + proc_aman.t2p.lamU**2) > split_cfg['high_leakage'])
fm.wrap_dets('low_leakage', np.sqrt(proc_aman.t2p.lamQ**2 + proc_aman.t2p.lamU**2) <= split_cfg['high_leakage'])
split_aman.wrap('leakage_avg', np.nanmean(np.sqrt(proc_aman.t2p.lamQ**2 + proc_aman.t2p.lamU**2)),
[(0, 'dets')])
# High 2f amplitude split
a2 = aman.det_cal.phase_to_pW*np.sqrt(proc_aman.hwpss_stats.coeffs[:,2]**2 + proc_aman.hwpss_stats.coeffs[:,3]**2)
split_aman.wrap('high_2f_flag', a2 > split_cfg['high_2f'], [(0, 'dets')])
fm.wrap_dets('high_2f', a2 > split_cfg['high_2f'])
fm.wrap_dets('low_2f', a2 <= split_cfg['high_2f'])
split_aman.wrap('2f_avg', np.nanmean(a2), [(0, 'dets')])
split_aman.wrap('right_focal_plane_flag', aman.focal_plane.xi > split_cfg['right_focal_plane'], [(0, 'dets')])
split_aman.wrap('top_focal_plane_flag', aman.focal_plane.eta > split_cfg['top_focal_plane'], [(0, 'dets')])
split_aman.wrap('central_pixels_flag', np.sqrt(aman.focal_plane.xi**2 + aman.focal_plane.eta**2) < split_cfg['central_pixels'],
[(0, 'dets')])
# Right/left focal plane split
fm.wrap_dets('det_right', aman.focal_plane.xi > split_cfg['right_focal_plane'])
fm.wrap_dets('det_left', aman.focal_plane.xi <= split_cfg['right_focal_plane'])
# Top/bottom focal plane split
fm.wrap_dets('det_upper', aman.focal_plane.eta > split_cfg['top_focal_plane'])
fm.wrap_dets('det_lower', aman.focal_plane.eta <= split_cfg['top_focal_plane'])
# Inner/outter pixel split
r = np.sqrt(aman.focal_plane.xi**2 + aman.focal_plane.eta**2)
fm.wrap_dets('det_in', r < split_cfg['central_pixels'])
fm.wrap_dets('det_out', r >= split_cfg['central_pixels'])
# Left/right subscans
if 'turnaround_flags' in proc_aman:
fm.wrap('scan_left', proc_aman.turnaround_flags.left_scan)
fm.wrap('scan_right', proc_aman.turnaround_flags.right_scan)

split_aman.wrap('cuts', fm)

return split_aman

0 comments on commit 36c4bb8

Please sign in to comment.