Skip to content

Commit 33b6cf1

Browse files
committed
RebinMaps pipeline module
Useful for consistent rebinning of all maps in a map frame.
1 parent 9da9112 commit 33b6cf1

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

maps/python/map_modules.py

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

0 commit comments

Comments
 (0)