Skip to content

Commit 1a3e114

Browse files
committed
InvertMaps pipeline module
1 parent fabac22 commit 1a3e114

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

maps/python/map_modules.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"InjectMapStub",
1515
"InjectMaps",
1616
"ReplicateMaps",
17+
"InvertMaps",
1718
"CoaddMaps",
1819
"RebinMaps",
1920
"ReprojectMaps",
@@ -581,6 +582,38 @@ def ReplicateMaps(frame, input_map_id, output_map_ids, copy_weights=False):
581582
return frames
582583

583584

585+
@core.indexmod
586+
class InvertMaps:
587+
"""
588+
Invert T, Q, U maps in input map frames.
589+
590+
Arguments
591+
---------
592+
alternate: bool
593+
If True, invert every other map in the pipeline. Otherwise, invert
594+
every input map.
595+
"""
596+
def __init__(self, alternate=False):
597+
self.alternate = alternate
598+
self.flip = False if alternate else True
599+
600+
def __call__(self, frame):
601+
if frame.type != core.G3FrameType.Map:
602+
return
603+
604+
if self.flip:
605+
for k in "TQU":
606+
if k in frame:
607+
m = frame.pop(k)
608+
m *= -1.0
609+
frame[k] = m
610+
611+
if self.alternate:
612+
self.flip = not self.flip
613+
614+
return frame
615+
616+
584617
@core.indexmod
585618
class CoaddMaps(object):
586619
"""

0 commit comments

Comments
 (0)