Skip to content

brahmap.core.separate_map_vectors

Separates the interleaved Stokes parameter maps into distinct components.

The output maps of the GLS solver are typically interleaved in the form \([I_1, Q_1, U_1, I_2, Q_2, U_2, \dots]\). Following standard conventions, this function reshapes and separates the Stokes parameters into individual maps such as \([I_1, I_2, \dots]\), \([Q_1, Q_2, \dots]\), and \([U_1, U_2, \dots]\).

Parameters:

Name Type Description Default
map_vector NDArray[number]

The 1D vector representing the flattened interleaved sky map

required
processed_samples ProcessTimeSamples

The pre-processed time samples object containing pointing and map-making metadata

required

Returns:

Type Description
NDArray[number]

The final separated output maps with masked pathological pixels

Source code in brahmap/core/GLS.py
def separate_map_vectors(
    map_vector: npt.NDArray[np.number],
    processed_samples: ProcessTimeSamples,
) -> npt.NDArray[np.number]:
    r"""Separates the interleaved Stokes parameter maps into distinct components.

    The output maps of the GLS solver are typically interleaved in the form
    $[I_1, Q_1, U_1, I_2, Q_2, U_2, \dots]$. Following standard conventions,
    this function reshapes and separates the Stokes parameters into individual
    maps such as $[I_1, I_2, \dots]$, $[Q_1, Q_2, \dots]$, and $[U_1, U_2, \dots]$.

    Parameters
    ----------
    map_vector : npt.NDArray[np.number]
        The 1D vector representing the flattened interleaved sky map

    processed_samples : ProcessTimeSamples
        The pre-processed time samples object containing pointing and
        map-making metadata

    Returns
    -------
    npt.NDArray[np.number]
        The final separated output maps with masked pathological pixels
    """
    try:
        map_vector = np.reshape(
            map_vector,
            (int(processed_samples.solver_type), processed_samples.new_npix),
            order="F",
        )
    except TypeError:
        # `newshape` parameter has been deprecated since numpy 2.1.0. This part should
        # be removed once the support is dropped for lower version
        map_vector = np.reshape(
            map_vector,
            newshape=(int(processed_samples.solver_type), processed_samples.new_npix),
            order="F",
        )

    output_maps = np.ma.MaskedArray(
        data=np.empty(processed_samples.npix, dtype=processed_samples.dtype_float),
        mask=~processed_samples.pixel_flag,
        fill_value=-1.6375e30,
    )

    output_maps = np.tile(A=output_maps, reps=(int(processed_samples.solver_type), 1))

    for idx in range(int(processed_samples.solver_type)):
        output_maps[idx][~output_maps[idx].mask] = map_vector[idx]

    return output_maps