Skip to content

Commit 3a56103

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

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

maps/python/map_modules.py

Lines changed: 46 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,51 @@ 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+
ApplyWeights(frame)
866+
867+
for k in ["T", "Q", "U", "Wunpol", "Wpol", "H"]:
868+
if k in frame:
869+
m = frame.pop(k)
870+
if k in "TQU":
871+
frame[k] = m.rebin(scale, norm=norm)
872+
elif k == "H":
873+
frame[k] = m.rebin(scale, norm=False)
874+
else:
875+
if weighted and norm:
876+
core.log_warn(
877+
"Rebinning weighted frames with norm=True may result "
878+
"in inconsistent maps and weights",
879+
unit="RebinMaps",
880+
)
881+
frame[k] = m.rebin(scale)
882+
883+
838884
@core.indexmod
839885
class ReprojectMaps(object):
840886
"""

0 commit comments

Comments
 (0)