Skip to content

pyhiperta.leakage

Leakage (image outer rings' charge) computation.

Functions:

Name Description
leakage

Compute the leakage 1 and 2, and their intensity.

leakage

leakage(waveforms, intensity, leakage_mask)

Compute the leakage 1 and 2, and their intensity.

The leakage 1, respectively 2, is the number of pixels that are not 0 after cleaning on the outermost, respectively 2nd outermost, ring of the camera. The leakage intensity is the charge of the leakage pixels, so leakage 1, resp. 2, intensity is the sum of the signal in all pixels of the outermost, resp. 2nd outermost, ring of the camera.

Parameters:

Name Type Description Default
waveforms ndarray

1D shower image(s). If a single image is provided the shape must be (N_pixels,). If a batch of images is provided, the shape should be (N_batch, N_pixels). Shape: ([N_batch,] N_pixels)

required
intensity ndarray

Total charge of each waveform. Shape: ([B_batch,] 1)

required
leakage_mask ndarray

Boolean array with value True for pixels on the outermost rings of the camera, False otherwise. leakage_mask[0, :] selects the outermost ring (leakage 1) while leakage_mask[1, :] selects the second outermost ring (leakage 2). Shape: (2, N_pixels)

required

Returns:

Type Description
ndarray

Leakage array. This is a 1D array with shape (4,) if a single image was provided, or a 2D array with shape (N_batch, 4) if a batch of images was provided. The parameters are ordered like so: leakage[..., 0]: leakage 1: number of pixels with signal on the outermost ring of the camera, normalized by the number of pixels with signal. leakage[..., 1]: leakage 2: number of pixels with signal on the 1st and 2nd outermost ring of the camera, normalized by the number of pixels with signal. leakage[..., 3]: leakage 1 intensity: Waveform charge contained in the outermost ring of the camera, normalized by the total charge in the camera leakage[..., 4]: leakage 2 intensity: Waveform charge contained in the 1st and 2nd outermost ring of the camera, normalized by the total charge in the camera

Source code in src/pyhiperta/leakage.py
def leakage(waveforms: np.ndarray, intensity: np.ndarray, leakage_mask: np.ndarray) -> np.ndarray:
    """Compute the leakage 1 and 2, and their intensity.

    The leakage 1, respectively 2, is the number of pixels that are not 0 after cleaning on the outermost,
    respectively 2nd outermost, ring of the camera.
    The leakage intensity is the charge of the leakage pixels, so leakage 1, resp. 2, intensity is the sum of the signal
    in all pixels of the outermost, resp. 2nd outermost, ring of the camera.

    Parameters
    ----------
    waveforms : np.ndarray
        1D shower image(s). If a single image is provided the shape must be (N_pixels,). If a
        batch of images is provided, the shape should be (N_batch, N_pixels).
        Shape: ([N_batch,] N_pixels)
    intensity : np.ndarray
        Total charge of each waveform.
        Shape: ([B_batch,] 1)
    leakage_mask : np.ndarray
        Boolean array with value True for pixels on the outermost rings of the camera, False otherwise.
        leakage_mask[0, :] selects the outermost ring (leakage 1) while leakage_mask[1, :] selects the
        second outermost ring (leakage 2).
        Shape: (2, N_pixels)

    Returns
    -------
    np.ndarray
        Leakage array. This is a 1D array with shape (4,) if a single image was
        provided, or a 2D array with shape (N_batch, 4) if a batch of images was provided. The
        parameters are ordered like so:
        leakage[..., 0]: leakage 1: number of pixels with signal on the outermost ring of the camera, normalized by
                         the number of pixels with signal.
        leakage[..., 1]: leakage 2: number of pixels with signal on the 1st and 2nd outermost ring of
                         the camera, normalized by the number of pixels with signal.
        leakage[..., 3]: leakage 1 intensity: Waveform charge contained in the outermost ring of the camera,
                         normalized by the total charge in the camera
        leakage[..., 4]: leakage 2 intensity: Waveform charge contained in the 1st and 2nd outermost ring of the camera,
                         normalized by the total charge in the camera
    """
    # number of pixels for normalization
    nb_pixels = np.count_nonzero(waveforms, axis=-1, keepdims=True).astype(np.float32)
    # apply leakage mask (both leakage 1 and leakage 2 with broadcasting)
    leakage_charge = waveforms[..., np.newaxis, :] * leakage_mask
    # normalized number of pixels with signal in leakage for both leakages
    leakage = np.count_nonzero(leakage_charge, axis=-1).astype(np.float32) / nb_pixels
    # normalized leakage intensity for both leakage (add axis to intensity for broadcasting!)
    leakage_intensity = leakage_charge.sum(axis=-1, dtype=np.float32) / intensity[..., np.newaxis]
    return np.concatenate([leakage, leakage_intensity], axis=-1)