spcal.detection

Functions for detecting and classifying particles.

spcal.detection.accumulate_detections(y: ndarray, limit_accumulation: float | ndarray, limit_detection: float | ndarray, points_required: int = 1, prominence_required: float = 0.2, integrate: bool = False) tuple[ndarray, ndarray]

Returns an array of accumulated detections.

Peak prominence is calculated for all points above the limit_detection, with widths bound by the limit_accumulation. Detections are peaks with at least points_required points above the limit_detection. Peaks with overlapping prominences with at least prominence_required of the maxium height will be split.

Parameters:
  • y – array

  • limit_accumulation – minimum accumulation value(s)

  • limit_detection – minimum detection value(s)

  • points_required – no. points > limit_detection to be detected

  • prominence_required – minimum fraction of max prominence for overlapping peaks

  • integrate – integrate, otherwise sum

Returns:

summed detection regions regions [starts, ends]

spcal.detection.background_mask(regions: ndarray, size: int) ndarray

Create a mask to select background data using regions.

Parameters:
  • regions – regions from accumulate_detections

  • size – size of underlying array, e.g. signals

Returns:

mask of signal background

spcal.detection.combine_regions(regions: list[ndarray], overlap: int) ndarray

Combine regions with an optional allowed overlap.

Regions in regions that overlap by more than overlap are merged.

Parameters:
  • regions – list of regions from accumulate_detections

  • overlap – maximum allowed overlap

Returns:

merged regions

spcal.detection.detection_maxima(y: ndarray, regions: ndarray) ndarray

Calculates the maxima of each region.

Does not work with overlapping regions.

Parameters:
  • y – array

  • regions – regions from accumulate_detections

Returns:

idx of maxima