Skip to content

brahmap.core.compute_GLS_maps

Computes the Generalized Least Squares (GLS) maps directly from raw pointing information and time-ordered data.

Parameters:

Name Type Description Default
npix int

Number of pixels on which the map-making has to be done (e.g. healpy.nside2npix(nside))

required
pointings NDArray[integer]

A 1-d array of pixel indices pointing to the sky map for each time sample

required
time_ordered_data NDArray[number]

The 1D vector representing the time-ordered data (TOD) streams

required
pointings_flag NDArray[bool_] | None

A 1-d boolean array where True indicates a valid pointing and False flags a bad pointing, by default None. If set as None, all the pointings are considered valid

None
pol_angles NDArray[number] | None

A 1-d array containing the polarization orientation angles of the detectors for each sample, by default None

None
inv_noise_cov_operator DTypeNoiseCov | None

The inverse noise covariance linear operator (\(N^{-1}\)), by default None

None
threshold float

The condition number threshold used to flag degenerate or under-sampled pixels, by default 1.0e-5

1e-05
dtype_float DTypeFloat | None

The data type used for floating-point arrays, by default None

None
update_pointings_inplace bool

Whether to update the pointing arrays in-place, by default True

True
gls_parameters GLSParameters

The parameter configuration dictating the map-making behavior, by default GLSParameters()

GLSParameters()
x0 NDArray[number] | None

Initial guess for the GLS solution in the form of interleaved maps (e.g. \([I_1, Q_1, U_1, I_2, Q_2, U_2, \dots]\)), by default None

None

Returns:

Type Description
GLSResult | tuple[ProcessTimeSamples, GLSResult]

GLSResult The dataclass containing the final output from the GLS map-maker, optionally returning the processed samples container

Source code in brahmap/core/GLS.py
def compute_GLS_maps(
    npix: int,
    pointings: npt.NDArray[np.integer],
    time_ordered_data: npt.NDArray[np.number],
    pointings_flag: npt.NDArray[np.bool_] | None = None,
    pol_angles: npt.NDArray[np.number] | None = None,
    inv_noise_cov_operator: DTypeNoiseCov | None = None,
    threshold: float = 1.0e-5,
    dtype_float: DTypeFloat | None = None,
    update_pointings_inplace: bool = True,
    gls_parameters: GLSParameters = GLSParameters(),
    x0: npt.NDArray[np.number] | None = None,
) -> GLSResult | tuple[ProcessTimeSamples, GLSResult]:
    r"""Computes the Generalized Least Squares (GLS) maps directly from
    raw pointing information and time-ordered data.

    Parameters
    ----------
    npix : int
        Number of pixels on which the map-making has to be done (e.g.
        `healpy.nside2npix(nside)`)
    pointings : npt.NDArray[np.integer]
        A 1-d array of pixel indices pointing to the sky map for each time sample
    time_ordered_data : npt.NDArray[np.number]
        The 1D vector representing the time-ordered data (TOD) streams
    pointings_flag : npt.NDArray[np.bool_] | None, optional
        A 1-d boolean array where `True` indicates a valid pointing and
        `False` flags a bad pointing, by default `None`. If set as `None`,
        all the pointings are considered valid
    pol_angles : npt.NDArray[np.number] | None, optional
        A 1-d array containing the polarization orientation angles of the
        detectors for each sample, by default `None`
    inv_noise_cov_operator : DTypeNoiseCov | None, optional
        The inverse noise covariance linear operator ($N^{-1}$), by default `None`
    threshold : float, optional
        The condition number threshold used to flag degenerate or
        under-sampled pixels, by default `1.0e-5`
    dtype_float : DTypeFloat | None, optional
        The data type used for floating-point arrays, by default `None`
    update_pointings_inplace : bool, optional
        Whether to update the pointing arrays in-place, by default `True`
    gls_parameters : GLSParameters, optional
        The parameter configuration dictating the map-making behavior, by
        default `GLSParameters()`
    x0 : npt.NDArray[np.number] | None, optional
        Initial guess for the GLS solution in the form of interleaved
        maps (e.g. $[I_1, Q_1, U_1, I_2, Q_2, U_2, \dots]$), by default `None`

    Returns
    -------
    GLSResult | tuple[ProcessTimeSamples, GLSResult]
        GLSResult
        The dataclass containing the final output from the GLS map-maker,
        optionally returning the processed samples container
    """
    if dtype_float is None:
        if pol_angles is None:
            dtype_float = time_ordered_data.dtype  # type: ignore
        else:
            dtype_float = np.promote_types(pol_angles.dtype, time_ordered_data.dtype)

    if pol_angles is not None:
        pol_angles = pol_angles.astype(dtype=dtype_float, copy=False)

    if inv_noise_cov_operator is None:
        noise_weights = None
    else:
        noise_weights = inv_noise_cov_operator.diag

    processed_samples = ProcessTimeSamples(
        npix=npix,
        pointings=pointings,
        pointings_flag=pointings_flag,
        solver_type=gls_parameters.solver_type,
        pol_angles=pol_angles,
        noise_weights=noise_weights,
        threshold=threshold,
        dtype_float=dtype_float,
        update_pointings_inplace=update_pointings_inplace,
    )

    gls_result = compute_GLS_maps_from_PTS(
        processed_samples=processed_samples,
        time_ordered_data=time_ordered_data.astype(dtype=dtype_float, copy=False),
        inv_noise_cov_operator=inv_noise_cov_operator,
        gls_parameters=gls_parameters,
        x0=x0,
    )

    if gls_parameters.return_processed_samples:
        return processed_samples, gls_result
    else:
        del processed_samples
        gc.collect()
        return gls_result