Skip to content

Commit 97cc6f4

Browse files
authored
RebinMaps pipeline module (#183)
Useful for consistent rebinning of all maps in a map frame.
1 parent 9da9112 commit 97cc6f4

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

maps/python/map_modules.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"InjectMaps",
1616
"ReplicateMaps",
1717
"CoaddMaps",
18+
"RebinMaps",
1819
"ReprojectMaps",
1920
"coadd_map_files",
2021
]
@@ -835,6 +836,49 @@ def coadd_map_files(
835836
return coadder.coadd_frame
836837

837838

839+
@core.indexmod
840+
def RebinMaps(frame, scale=1, weighted=True, norm=False):
841+
"""
842+
Rebin any maps in the input frame into larger pixels by summing scale-x-scale
843+
blocks of pixels together. Map dimensions must be a multiple of the rebinning
844+
scale.
845+
846+
Arguments
847+
---------
848+
scale : int
849+
Rebinning scale factor, such that scale-x-scale blocks of pixels are summed
850+
into larger pixels. Must divide evenly into all map pixel dimensions.
851+
weighted : bool
852+
If True (default), ensure that maps have had weights applied before
853+
rebinning. Otherwise, rebin maps without checking the weights.
854+
norm : bool
855+
If False (default), sum all of the sub-pixels into each larger output pixel.
856+
If True, normalize the output pixel by the number of sub-pixels each
857+
encloses. Only applies to Stokes parameters T/Q/U, not weights or hits.
858+
"""
859+
if scale <= 1:
860+
return
861+
862+
if weighted:
863+
ApplyWeights(frame)
864+
865+
for k in ["T", "Q", "U", "Wunpol", "Wpol", "H"]:
866+
if k in frame:
867+
m = frame.pop(k)
868+
if k in "TQU":
869+
frame[k] = m.rebin(scale, norm=norm)
870+
elif k == "H":
871+
frame[k] = m.rebin(scale, norm=False)
872+
else:
873+
if weighted and norm:
874+
core.log_warn(
875+
"Rebinning weighted frames with norm=True may result "
876+
"in inconsistent maps and weights",
877+
unit="RebinMaps",
878+
)
879+
frame[k] = m.rebin(scale)
880+
881+
838882
@core.indexmod
839883
class ReprojectMaps(object):
840884
"""

0 commit comments

Comments
 (0)