Skip to content

Commit afa70bf

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

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
@@ -835,6 +835,50 @@ def coadd_map_files(
835835
return coadder.coadd_frame
836836

837837

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

0 commit comments

Comments
 (0)