Skip to content

Commit

Permalink
Option to drop empty G3Maps in SplitByProperty
Browse files Browse the repository at this point in the history
  • Loading branch information
arahlin committed Oct 24, 2023
1 parent b02c746 commit fffbd29
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions calibration/python/bolopropertiesutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SplitByProperty(object):
G3TimestreamMap, G3MapInt, etc.
'''
def __init__(self, input='CalTimestreams', property=None, property_list=None,
output_root=None, bpm='BolometerProperties'):
output_root=None, bpm='BolometerProperties', drop_empty=False):
'''
Split the input map given by input into several output
maps named output_root + key (e.g. CalTimestreams + str(property)) with
Expand All @@ -40,6 +40,8 @@ def __init__(self, input='CalTimestreams', property=None, property_list=None,
bpm : str
The key name of the BolometerPropertiesMap from which to extract
the requested `property` for splitting the input map.
drop_empty : bool
If True, drop output maps that don't contain any bolometers.
'''
if property is None:
core.log_fatal("Property is a required argument")
Expand All @@ -54,6 +56,7 @@ def __init__(self, input='CalTimestreams', property=None, property_list=None,
self.props = None
self.bpmkey = bpm
self.bpm = None
self.drop_empty = drop_empty

@staticmethod
def converter(prop):
Expand Down Expand Up @@ -94,8 +97,10 @@ def __call__(self, frame):
continue
out[prop][b] = inmap[b]

for prop in out.keys():
frame['%s%s' % (self.output_root, prop)] = out[prop]
for prop, outmap in out.items():
if not len(outmap.keys()) and self.drop_empty:
continue
frame['%s%s' % (self.output_root, prop)] = outmap


@core.indexmod
Expand All @@ -108,7 +113,7 @@ class SplitByBand(SplitByProperty):
G3TimestreamMap, G3MapInt, etc.
'''
def __init__(self, input='CalTimestreams', output_root=None,
bands=None, bpm='BolometerProperties'):
bands=None, bpm='BolometerProperties', drop_empty=False):
'''
Split the input map given by input into several output
maps named output_root + band + GHz (e.g. CalTimestreams150GHz with
Expand All @@ -120,7 +125,7 @@ def __init__(self, input='CalTimestreams', output_root=None,
'''
super(SplitByBand, self).__init__(
input=input, output_root=output_root, property_list=bands,
bpm=bpm, property='band')
bpm=bpm, property='band', drop_empty=drop_empty)

@staticmethod
def converter(band):
Expand All @@ -137,10 +142,10 @@ def converter(band):
class SplitTimestreamsByBand(SplitByBand):

def __init__(self, input='CalTimestreams', output_root=None,
bands=None, bpm='BolometerProperties'):
bands=None, bpm='BolometerProperties', drop_empty=False):
core.log_warn("SplitTimestreamsByBand is deprecated, use SplitByBand instead")
super(SplitTimestreamsByBand, self).__init__(
input=input, output_root=output_root, bands=bands, bpm=bpm)
input=input, output_root=output_root, bands=bands, bpm=bpm, drop_empty=drop_empty)


@core.indexmod
Expand All @@ -153,7 +158,7 @@ class SplitByWafer(SplitByProperty):
G3TimestreamMap, G3MapInt, etc.
'''
def __init__(self, input='CalTimestreams', output_root=None,
wafers=None, bpm='BolometerProperties'):
wafers=None, bpm='BolometerProperties', drop_empty=False):
'''
Split the input map given by input into several output
maps named output_root + wafer (e.g. CalTimestreamsW172 with
Expand All @@ -165,7 +170,7 @@ def __init__(self, input='CalTimestreams', output_root=None,
'''
super(SplitByWafer, self).__init__(
input=input, output_root=output_root, property_list=wafers,
bpm=bpm, property='wafer_id')
bpm=bpm, property='wafer_id', drop_empty=drop_empty)

@staticmethod
def converter(wafer):
Expand All @@ -184,7 +189,7 @@ class SplitByPixelType(SplitByProperty):
G3TimestreamMap, G3MapInt, etc.
'''
def __init__(self, input='CalTimestreams', output_root=None,
types=None, bpm='BolometerProperties'):
types=None, bpm='BolometerProperties', drop_empty=False):
'''
Split the input map given by input into several output
maps named output_root + wafer (e.g. CalTimestreamsW172 with
Expand All @@ -196,7 +201,7 @@ def __init__(self, input='CalTimestreams', output_root=None,
'''
super(SplitByPixelType, self).__init__(
input=input, output_root=output_root, property_list=types,
bpm=bpm, property='pixel_type')
bpm=bpm, property='pixel_type', drop_empty=drop_empty)

@staticmethod
def converter(pixel_type):
Expand Down

0 comments on commit fffbd29

Please sign in to comment.