lenspack.peaks module

PEAKS MODULE

This module contains functions for detecting and counting peaks (local maxima) in images. Peak counts in weak-lensing maps are a useful statistic for constraining cosmological models.

lenspack.peaks.find_peaks2d(image, threshold=None, ordered=True, mask=None, include_border=False)[source]

Identify peaks in an image (2D array) above a given threshold.

A peak, or local maximum, is defined as a pixel of larger value than its eight neighbors. A mask may be provided to exclude certain regions from the search. The border is excluded by default.

Parameters
  • image (array_like) – Two-dimensional input image.

  • threshold (float, optional) – Minimum pixel amplitude to be considered as a peak. If not provided, the default value is set to the minimum of image.

  • ordered (bool, optional) – If True, return peaks in decreasing order according to height.

  • mask (array_like (same shape as image), optional) – Boolean array identifying which pixels of image to consider/exclude in finding peaks. A numerical array will be converted to binary, where only zero values are considered masked.

  • include_border (bool, optional) – If True, include peaks found on the border of the image. Default is False.

Returns

X, Y, heights – Pixel indices of peak positions and their associated heights.

Return type

tuple of 1D numpy arrays

Notes

The basic idea for this algorithm was provided by Chieh-An Lin.

Examples

lenspack.peaks.peaks_histogram(image, bins=None, mask=None)[source]

Compute a histogram of peaks in an image.

Parameters
  • image (array_like) – Two-dimensional input image.

  • bins (int or array_like (1D), optional) – Specification of bin edges or the number of bins to use for the histogram. If not provided, a default of 10 bins linearly spaced between the image minimum and maximum (inclusive) is used.

  • mask (array_like (same shape as image), optional) – Boolean array identifying which pixels of image to consider/exclude in finding peaks. A numerical array will be converted to binary, where only zero values are considered masked.

Returns

counts, bin_edges – Histogram and bin boundary values.

Return type

tuple of 1D numpy arrays

Notes

This function calls find_peaks2d and then uses numpy to compute the histogram. If the returned counts has N values, bin_edges will have N + 1 values.

Examples