Skip to content

Commit

Permalink
add ReprojectMaps pipeline module to simplify reprojection of entire …
Browse files Browse the repository at this point in the history
…map frames
  • Loading branch information
arahlin committed Mar 23, 2022
1 parent 8330fc0 commit 917765d
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions maps/python/map_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"InjectMaps",
"ReplicateMaps",
"CoaddMaps",
"ReprojectMaps",
]


Expand Down Expand Up @@ -530,3 +531,67 @@ def __call__(self, frame):

if not input_weighted:
RemoveWeights(frame)


@core.indexmod
class ReprojectMaps(object):
"""
Reproject a map frame into a different projection. Original data are
dropped and replaced by reprojected maps in the input frames.
Arguments
---------
map_stub : G3SkyMap object
A stub (empty) sky map object to be used to construct the output maps.
rebin : int
If supplied and >1, subdivide the output pixel by n x n with each
sub-pixel taking on the input map values at pixel center (with interp or
nearest neighbor). The output pixel takes on the average of the
sub-pixel values. In the case that the input map has higher resolution
than the output map (and that the input map is not low-pass filtered to
remove information above the Nyquist freq. of the output map pixel),
this reduces aliasing compared with direct sampling. But there would
still be aliased power from the input map from freq above the ouput map
pixel's Nyquist.
interp : bool
If True, use bilinear interpolation to extract values from the input
map. Otherwise, the nearest-neighbor value is used.
Notes
-----
Maps can be rotated between Equatorial and Galactic coordinates, and/or
change polarization convention between COSMO and IAU, by setting the
appropriate attributes of the input and output maps. Attributes not defined
in the output map are assumed to be that of the input map.
"""

def __init__(self, map_stub=None, rebin=1, interp=False):
assert map_stub is not None, "map_stub argument required"
self.stub = map_stub
self.rebin = rebin
self.interp = interp

def __call__(self, frame):

if frame.type != core.G3FrameType.Map:
return

for key in ["T", "Q", "U", "Wpol", "Wunpol"]:

if key not in frame:
continue

m = frame.pop(key)

if key in "TQU":
mnew = self.stub.clone(False)
maps.reproj_map(m, mnew, rebin=self.rebin, interp=self.interp)

elif key in ["Wpol", "Wunpol"]:
mnew = core.G3SkyMapWeights(self.stub, key == "Wpol")
for wkey in mnew.keys():
maps.reproj_map(m[wkey], mnew[wkey], rebin=self.rebin, interp=self.interp)

frame[key] = mnew

return frame

0 comments on commit 917765d

Please sign in to comment.