From 05015e0973b969f9d8dfdb2863a8863179330cf1 Mon Sep 17 00:00:00 2001 From: Sasha Rahlin Date: Wed, 23 Mar 2022 11:33:18 -0500 Subject: [PATCH 1/5] add ReprojectMaps pipeline module to simplify reprojection of entire map frames --- maps/python/map_modules.py | 71 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/maps/python/map_modules.py b/maps/python/map_modules.py index 437aa637..852e2fe4 100644 --- a/maps/python/map_modules.py +++ b/maps/python/map_modules.py @@ -14,6 +14,7 @@ "InjectMaps", "ReplicateMaps", "CoaddMaps", + "ReprojectMaps", ] @@ -530,3 +531,73 @@ 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. 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 stub maps. Attributes not defined in the stub + map are assumed to be that of the input map. NB: currently rotation of + polarization coordinates is not done properly when changing coordinate + systems. + + 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. + """ + + 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 + + if "Q" in frame and self.stub.coord_ref != frame["Q"].coord_ref: + raise RuntimeError( + "Coordinate rotation of polarized maps is not implemented" + ) + + 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 From f71d97dcf74eef37323dadcc4b56e1e02467688e Mon Sep 17 00:00:00 2001 From: Alexandra Rahlin Date: Wed, 23 Mar 2022 13:17:24 -0500 Subject: [PATCH 2/5] =?UTF-8?q?Don=E2=80=99t=20fail=20if=20input=20is=20a?= =?UTF-8?q?=20dict=20instead=20of=20a=20frame=20object?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- maps/python/map_modules.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maps/python/map_modules.py b/maps/python/map_modules.py index 852e2fe4..f9a17ba4 100644 --- a/maps/python/map_modules.py +++ b/maps/python/map_modules.py @@ -572,7 +572,7 @@ def __init__(self, map_stub=None, rebin=1, interp=False): def __call__(self, frame): - if frame.type != core.G3FrameType.Map: + if isinstance(frame, core.G3Frame) and frame.type != core.G3FrameType.Map: return if "Q" in frame and self.stub.coord_ref != frame["Q"].coord_ref: From f627e9325bdc5f58de6bd8e30cc0aa905e4a374f Mon Sep 17 00:00:00 2001 From: Alexandra Rahlin Date: Thu, 24 Mar 2022 17:09:10 -0600 Subject: [PATCH 3/5] Bug fix --- maps/python/map_modules.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maps/python/map_modules.py b/maps/python/map_modules.py index f9a17ba4..77326596 100644 --- a/maps/python/map_modules.py +++ b/maps/python/map_modules.py @@ -592,7 +592,7 @@ def __call__(self, frame): maps.reproj_map(m, mnew, rebin=self.rebin, interp=self.interp) elif key in ["Wpol", "Wunpol"]: - mnew = core.G3SkyMapWeights(self.stub, key == "Wpol") + mnew = maps.G3SkyMapWeights(self.stub, key == "Wpol") for wkey in mnew.keys(): maps.reproj_map( m[wkey], mnew[wkey], rebin=self.rebin, interp=self.interp From 9de3ac4be3aacd2061a33f87d8b997dc404d9020 Mon Sep 17 00:00:00 2001 From: Alexandra Rahlin Date: Fri, 25 Mar 2022 14:07:51 -0500 Subject: [PATCH 4/5] Clearer docstring --- maps/python/map_modules.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/maps/python/map_modules.py b/maps/python/map_modules.py index 77326596..596cf2d2 100644 --- a/maps/python/map_modules.py +++ b/maps/python/map_modules.py @@ -538,12 +538,12 @@ class ReprojectMaps(object): """ Reproject a map frame into a different projection. Original data are dropped and replaced by reprojected maps in the input frames. 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 stub maps. Attributes not defined in the stub - map are assumed to be that of the input map. NB: currently rotation of - polarization coordinates is not done properly when changing coordinate - systems. + changed between flat sky and healpix pixelizations, rotated between + Equatorial and Galactic coordinates, and/or change polarization convention + between COSMO and IAU, by setting the appropriate attributes of the input + and stub maps. Attributes not defined in the stub map are assumed to be + that of the input map. NB: coordinate rotation of polarized maps is not + currently implemented. Arguments --------- From 148209e5bbcf03a6632ade05c4e6e1cf1b455275 Mon Sep 17 00:00:00 2001 From: Alexandra Rahlin Date: Fri, 25 Mar 2022 14:18:51 -0500 Subject: [PATCH 5/5] docs --- maps/python/map_modules.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/maps/python/map_modules.py b/maps/python/map_modules.py index 596cf2d2..6c896ce6 100644 --- a/maps/python/map_modules.py +++ b/maps/python/map_modules.py @@ -549,6 +549,10 @@ class ReprojectMaps(object): --------- map_stub : G3SkyMap object A stub (empty) sky map object to be used to construct the output maps. + Can be a HealpixSkyMap or FlatSkyMap object. Setting the ``pol_conv`` + and/or ``coord_ref`` attributes to values that differ from those of the + input maps will result in output maps whose polarization convention + and/or reference coordinate system have been changed. 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