Skip to content

brahmap.lbsim.LBSimProcessTimeSamples

Bases: ProcessTimeSamples

A data container to store the pre-processed and pre-computed arrays and metadata from litebird_sim observations.

Similar to ProcessTimeSamples, this container object can be used to create pointing operators, block-diagonal preconditioners, etc. as required for map-making.

Parameters:

Name Type Description Default
nside int

The HEALPix \(N_{side}\) resolution parameter defining the number of pixels

required
observations Observation | List[Observation]

An instance of the Observation class or a list of the same

required
pointings NDArray[number] | List[NDArray[number]] | None

Array of detector pointing indices mapping time samples to observed sky pixels, by default None

None
hwp HWP | None

The Half-Wave Plate (HWP) angles or configuration, by default None

None
pointings_flag NDArray[bool_] | None

Boolean array indicating valid pointing samples, by default None. The True value indicates a valid pointing, and the False value indicates a bad pointing. If set as None, all the pointings are considered valid

None
solver_type SolverType

The level of map-making solver to construct (\(I\), \(QU\), or \(IQU\)), by default SolverType.IQU

IQU
noise_weights NDArray[number] | None

Array of noise inverse noise variance for each time sample, by default None. If set as None, inverse noise variance is set to 1 for each time sample

None
output_coordinate_system CoordinateSystem

The celestial coordinate system to use for the generated output maps, by default lbs.CoordinateSystem.Galactic

Galactic
threshold float

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

1e-05
dtype_float DTypeFloat

The data type to use for floating point arrays, by default np.float64

float64

Methods:

Name Description
get_hit_counts

Returns hit counts of the pixel indices.

Attributes:

Name Type Description
npix int

Number of pixels on which the map-making has to be done.

pointings NDArray[integer]

A 1-d array of pixel indices pointing to the observed sky pixel

pointings_flag NDArray[bool_] | None

A 1-d boolean array where True indicates a valid pointing and

nsamples int

The number of time samples processed by the current MPI rank

nsamples_global int

The total number of time samples across all MPI ranks

solver_type SolverType

The current map-making solver configuration (\(I\), \(QU\), or \(IQU\))

threshold float

The condition number threshold used to flag bad pixels

dtype_float DTypeFloat

The inferred or specified data type for floating point arrays

observed_pixels NDArray[integer]

A 1-d array containing the original indices of the pixels that

pixel_flag NDArray[bool_]

A 1-d boolean array of size npix where True indicates a bad

bad_pixels NDArray[integer]

A 1-d array that contains all the pixel indices that will be excluded

old2new_pixel NDArray[integer]

A 1-d array mapping old pixel indices to new pixel indices

weighted_counts NDArray[number]

A 1-d array accumulating the inverse noise weights per valid pixel

sin2phi NDArray[number]

A 1-d array containing \(\sin(2\phi)\) evaluated at the valid time samples

cos2phi NDArray[number]

A 1-d array containing \(\cos(2\phi)\) evaluated at the valid time samples

weighted_sin NDArray[number]

A 1-d array accumulating the noise-weighted \(\sin(2\phi)\) sum

weighted_cos NDArray[number]

A 1-d array accumulating the noise-weighted \(\cos(2\phi)\) sum

weighted_sin_sq NDArray[number]

A 1-d array accumulating the noise-weighted \(\sin^2(2\phi)\) sum

weighted_cos_sq NDArray[number]

A 1-d array accumulating the noise-weighted \(\cos^2(2\phi)\) sum

weighted_sincos NDArray[number]

A 1-d array accumulating the noise-weighted \(\sin(2\phi)\cos(2\phi)\)

one_over_determinant NDArray[number]

A 1-d array containing the inverse determinant of the

new_npix int

The number of pixels on which the map-making will be done

obs_list list[Observation]

A list of the parsed litebird_sim observations.

nside int

The HEALPix resolution parameter.

coordinate_system CoordinateSystem

The output celestial coordinate system used in data processing.

Source code in brahmap/lbsim/lbsim_process_time_samples.py
class LBSimProcessTimeSamples(ProcessTimeSamples):
    """A data container to store the pre-processed and pre-computed arrays and
    metadata from `litebird_sim` observations.

    Similar to [`ProcessTimeSamples`][brahmap.core.ProcessTimeSamples],
    this container object can be used to create pointing operators,
    block-diagonal preconditioners, etc. as required for map-making.

    Parameters
    ----------
    nside : int
        The HEALPix $N_{side}$ resolution parameter defining the number of pixels
    observations : lbs.Observation | List[lbs.Observation]
        An instance of the `Observation` class or a list of the same
    pointings : npt.NDArray[np.number] | List[npt.NDArray[np.number]] | None, optional
        Array of detector pointing indices mapping time samples to observed sky pixels,
        by default `None`
    hwp : lbs.HWP | None, optional
        The Half-Wave Plate (HWP) angles or configuration, by default `None`
    pointings_flag : npt.NDArray[np.bool_] | None, optional
        Boolean array indicating valid pointing samples, by default `None`.
        The `True` value indicates a valid pointing, and the `False`
        value indicates a bad pointing. If set as `None`, all the
        pointings are considered valid
    solver_type : SolverType, optional
        The level of map-making solver to construct ($I$, $QU$, or
        $IQU$), by default `SolverType.IQU`
    noise_weights : npt.NDArray[np.number] | None, optional
        Array of noise inverse noise variance for each time sample, by
        default `None`. If set as `None`, inverse noise variance is set to 1 for each
        time sample
    output_coordinate_system : lbs.CoordinateSystem, optional
        The celestial coordinate system to use for the generated output maps, by
        default `lbs.CoordinateSystem.Galactic`
    threshold : float, optional
        The condition number threshold used to flag degenerate or under-sampled
        pixels, by default `1.0e-5`
    dtype_float : DTypeFloat, optional
        The data type to use for floating point arrays, by default
        `np.float64`
    """

    def __init__(
        self,
        nside: int,
        observations: lbs.Observation | List[lbs.Observation],
        pointings: npt.NDArray[np.number] | List[npt.NDArray[np.number]] | None = None,
        hwp: lbs.HWP | None = None,
        pointings_flag: npt.NDArray[np.bool_] | None = None,
        solver_type: SolverType = SolverType.IQU,
        noise_weights: npt.NDArray[np.number] | None = None,
        output_coordinate_system: lbs.CoordinateSystem = lbs.CoordinateSystem.Galactic,
        threshold: float = 1.0e-5,
        dtype_float: DTypeFloat = np.float64,
    ) -> None:
        self.__nside = nside
        self.__coordinate_system = output_coordinate_system
        npix = hp.nside2npix(self.nside)

        (
            self.__obs_list,
            ptg_list,
        ) = lbs.pointings_in_obs._normalize_observations_and_pointings(
            observations=observations, pointings=pointings
        )

        num_total_samples = 0
        for obs in self.obs_list:
            num_total_samples += obs.n_detectors * obs.n_samples

        pix_indices = np.empty(num_total_samples, dtype=int)
        pol_angles = np.empty(num_total_samples, dtype=dtype_float)

        start_idx = 0
        end_idx = 0
        for obs_idx, (obs, curr_pointings) in enumerate(zip(self.obs_list, ptg_list)):
            if hwp is None:
                hwp_angle = None
            else:
                hwp_angle = lbs.pointings_in_obs._get_hwp_angle(
                    obs=obs, hwp=hwp, pointing_dtype=dtype_float
                )

            curr_pointings_det: Any = None

            for det_idx in range(obs.n_detectors):
                (
                    curr_pointings_det,
                    hwp_angle,
                ) = lbs.pointings_in_obs._get_pointings_array(
                    detector_idx=det_idx,
                    pointings=curr_pointings,
                    hwp_angle=hwp_angle,
                    output_coordinate_system=output_coordinate_system,
                    pointings_dtype=dtype_float,
                )

                end_idx += obs.n_samples

                pol_angles[start_idx:end_idx] = lbs.pointings_in_obs._get_pol_angle(
                    curr_pointings_det=curr_pointings_det,
                    hwp_angle=hwp_angle,
                    pol_angle_detectors=obs.pol_angle_rad[det_idx],
                )

                pix_indices[start_idx:end_idx] = hp.ang2pix(
                    nside, curr_pointings_det[:, 0], curr_pointings_det[:, 1]
                )

                start_idx = end_idx

            del hwp_angle, curr_pointings_det

        del curr_pointings

        super().__init__(
            npix=npix,
            pointings=pix_indices,
            pointings_flag=pointings_flag,
            solver_type=solver_type,
            pol_angles=pol_angles,
            noise_weights=noise_weights,
            threshold=threshold,
            dtype_float=dtype_float,
            update_pointings_inplace=True,
        )

    @property
    def obs_list(self) -> List[lbs.Observation]:
        """A list of the parsed `litebird_sim` observations.

        Returns
        -------
        List[lbs.Observation]
            The list of observations
        """
        return self.__obs_list

    @property
    def nside(self) -> int:
        """The HEALPix resolution parameter.

        Returns
        -------
        int
            The $N_{side}$ parameter
        """
        return self.__nside

    @property
    def coordinate_system(self) -> lbs.CoordinateSystem:
        """The output celestial coordinate system used in data processing.

        Returns
        -------
        lbs.CoordinateSystem
            The configured coordinate system
        """
        return self.__coordinate_system

Attributes

npix: int property

Number of pixels on which the map-making has to be done.

Returns:

Type Description
int

Number of pixels on which the map-making has to be done

pointings: npt.NDArray[np.integer] property

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

Returns:

Type Description
NDArray[integer]

A 1-d array of pixel pointing indices for each time sample

pointings_flag: npt.NDArray[np.bool_] | None property

A 1-d boolean array where True indicates a valid pointing and False flags a bad pointing

Returns:

Type Description
NDArray[bool_]

The 1-d array of flags indicating valid (True) or discarded

(`False`) time samples

nsamples: int property

The number of time samples processed by the current MPI rank

Returns:

Type Description
int

Number of samples on current MPI rank

nsamples_global: int property

The total number of time samples across all MPI ranks

Returns:

Type Description
int

Global number of samples

solver_type: SolverType property

The current map-making solver configuration (\(I\), \(QU\), or \(IQU\))

Returns:

Type Description
SolverType

Level of map-making: \(I\), \(QU\), or \(IQU\)

threshold: float property

The condition number threshold used to flag bad pixels

Returns:

Type Description
float

Threshold to used for flagging the pixels in the sky

dtype_float: DTypeFloat property

The inferred or specified data type for floating point arrays

Returns:

Type Description
DTypeFloat

dtype of the floating point arrays

observed_pixels: npt.NDArray[np.integer] property

A 1-d array containing the original indices of the pixels that are fully valid for map-making

Returns:

Type Description
NDArray[integer]

A 1-d array that contains all the pixel indices that are considered valid for map-making

pixel_flag: npt.NDArray[np.bool_] property

A 1-d boolean array of size npix where True indicates a bad pixel and False flags a valid pixel

Returns:

Type Description
NDArray[bool_]

A 1-d boolean array of size npix where True indicates a dropped or pathological pixel

bad_pixels: npt.NDArray[np.integer] property

A 1-d array that contains all the pixel indices that will be excluded in map-making.

Returns:

Type Description
NDArray[integer]

A 1-d array that contains all the pixel indices that will be excluded in map-making

old2new_pixel: npt.NDArray[np.integer] property

A 1-d array mapping old pixel indices to new pixel indices

Returns:

Type Description
NDArray[integer]

A 1-d array mapping old pixel indices to new pixel indices

weighted_counts: npt.NDArray[np.number] property

A 1-d array accumulating the inverse noise weights per valid pixel

Returns:

Type Description
NDArray[number]

A 1-d array accumulating the inverse noise weights per valid pixel

sin2phi: npt.NDArray[np.number] property

A 1-d array containing \(\sin(2\phi)\) evaluated at the valid time samples

Returns:

Type Description
NDArray[number]

A 1-d array containing \(\sin(2\phi)\) evaluated at the valid time samples

cos2phi: npt.NDArray[np.number] property

A 1-d array containing \(\cos(2\phi)\) evaluated at the valid time samples

Returns:

Type Description
NDArray[number]

A 1-d array containing \(\cos(2\phi)\) evaluated at the valid time samples

weighted_sin: npt.NDArray[np.number] property

A 1-d array accumulating the noise-weighted \(\sin(2\phi)\) sum per valid pixel

Returns:

Type Description
NDArray[number]

A 1-d array accumulating the noise-weighted \(\sin(2\phi)\) sum per valid pixel

weighted_cos: npt.NDArray[np.number] property

A 1-d array accumulating the noise-weighted \(\cos(2\phi)\) sum per valid pixel

Returns:

Type Description
NDArray[number]

A 1-d array accumulating the noise-weighted \(\cos(2\phi)\) sum per valid pixel

weighted_sin_sq: npt.NDArray[np.number] property

A 1-d array accumulating the noise-weighted \(\sin^2(2\phi)\) sum per valid pixel

Returns:

Type Description
NDArray[number]

A 1-d array accumulating the noise-weighted \(\sin^2(2\phi)\) sum per valid pixel

weighted_cos_sq: npt.NDArray[np.number] property

A 1-d array accumulating the noise-weighted \(\cos^2(2\phi)\) sum per valid pixel

Returns:

Type Description
NDArray[number]

A 1-d array accumulating the noise-weighted \(\cos^2(2\phi)\) sum per valid pixel

weighted_sincos: npt.NDArray[np.number] property

A 1-d array accumulating the noise-weighted \(\sin(2\phi)\cos(2\phi)\) sum per valid pixel

Returns:

Type Description
NDArray[number]

A 1-d array accumulating the noise-weighted \(\sin(2\phi)\cos(2\phi)\) sum per valid pixel

one_over_determinant: npt.NDArray[np.number] property

A 1-d array containing the inverse determinant of the block-diagonal operator \(P^T diag(N)^{-1} P\)

Returns:

Type Description
NDArray[number]

A 1-d array containing the inverse determinant of the block-diagonal operator \(P^T diag(N)^{-1} P\)

new_npix: int property

The number of pixels on which the map-making will be done

Returns:

Type Description
int

Number of pixels on which the map-making will be done

obs_list: List[lbs.Observation] property

A list of the parsed litebird_sim observations.

Returns:

Type Description
list[Observation]

The list of observations

nside: int property

The HEALPix resolution parameter.

Returns:

Type Description
int

The \(N_{side}\) parameter

coordinate_system: lbs.CoordinateSystem property

The output celestial coordinate system used in data processing.

Returns:

Type Description
CoordinateSystem

The configured coordinate system

Functions

get_hit_counts() -> npt.NDArray[np.integer]

Returns hit counts of the pixel indices.

Returns:

Type Description
NDArray[integer]

Hit counts of the pixel indices

Source code in brahmap/core/process_time_samples.py
def get_hit_counts(self) -> npt.NDArray[np.integer]:
    """Returns hit counts of the pixel indices.

    Returns
    -------
    npt.NDArray[np.integer]
        Hit counts of the pixel indices
    """
    hit_counts = np.ma.masked_array(
        data=np.zeros(self.npix),
        mask=np.logical_not(self.__pixel_flag),
        fill_value=-1.6375e30,
    )

    hit_counts[~hit_counts.mask] = self.__hit_counts
    return hit_counts