def __init__(
        self,
        map_id,
        map_stub,
        polarized=True,
        weighted=True,
        pol_conv=maps.MapPolConv.IAU,
    ):
        self.map_frame = core.G3Frame(core.G3FrameType.Map)
        self.map_frame["Id"] = map_id

        map_stub = map_stub.clone(False)
        map_stub.weighted = weighted
        map_stub.pol_conv = pol_conv

        T = map_stub.clone(False)
        T.pol_type = maps.MapPolType.T
        self.map_frame["T"] = T
        if polarized:
            Q = map_stub.clone(False)
            Q.pol_type = maps.MapPolType.Q
            self.map_frame["Q"] = Q
            U = map_stub.clone(False)
            U.pol_type = maps.MapPolType.U
            self.map_frame["U"] = U
        if weighted:
            W = maps.G3SkyMapWeights(map_stub, polarized)
            self.map_frame["Wpol" if polarized else "Wunpol"] = W
def MakeMapsPolarized(frame, pol_conv=maps.MapPolConv.IAU):
    """
    Converts individual unpolarized maps to polarized versions of the same map,
    with the given polarization convention

    This module is only a shim that creates null Q and U maps and populates
    a properly invertible Wpol array from the TT Wunpol weights.
    """
    if "Wunpol" not in frame:
        return

    wgt = frame["Wunpol"].TT
    del frame["Wunpol"]

    qmap = frame["T"].clone(False)
    qmap.pol_type = maps.MapPolType.Q
    frame["Q"] = qmap
    umap = frame["T"].clone(False)
    umap.pol_type = maps.MapPolType.U
    umap.pol_conv = pol_conv
    frame["U"] = umap
    mask = maps.get_mask_map(wgt)

    wgt_out = maps.G3SkyMapWeights(frame["T"], polarized=True)
    wgt_out.TT = wgt
    wgt_out.TQ = wgt.clone(False)
    wgt_out.TU = wgt.clone(False)
    wgt_out.QQ = mask
    wgt_out.QU = wgt.clone(False)
    wgt_out.UU = mask.clone(True)

    frame["Wpol"] = wgt_out

    return frame
Exemple #3
0
    def __call__(self, frame):

        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:
            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 = maps.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
def MakeMapsUnpolarized(frame):
    """
    Converts individual polarized maps to temperature-only versions of the same map.
    """
    if "Wpol" not in frame:
        return

    wgt = frame["Wpol"].TT
    del frame["Wpol"]
    del frame["Q"]
    del frame["U"]

    wgt_out = maps.G3SkyMapWeights(frame["T"], polarized=False)
    wgt_out.TT = wgt

    frame["Wunpol"] = wgt_out

    return frame