find_peaks#
- gammapy.estimators.utils.find_peaks(image, threshold, min_distance=1)[source]#
Find local peaks in an image.
This is a very simple peak finder, that finds local peaks (i.e. maxima) in images above a given
threshold
within a givenmin_distance
around each given pixel.If you get multiple spurious detections near a peak, usually it’s best to smooth the image a bit, or to compute it using a different method in the first place to result in a smooth image. You can also increase the
min_distance
parameter.The output table contains one row per peak and the following columns:
x
andy
are the pixel coordinates (first pixel at zero).ra
anddec
are the RA / DEC sky coordinates (ICRS frame).value
is the pixel value.
It is sorted by peak value, starting with the highest value.
If there are no pixel values above the threshold, an empty table is returned.
There are more featureful peak finding and source detection methods e.g. in the
photutils
orscikit-image
Python packages.- Parameters:
- image
WcsNDMap
Image like Map.
- thresholdfloat or array-like
The data value or pixel-wise data values to be used for the detection threshold. A 2D
threshold
must have the same shape as the mapdata
.- min_distanceint or
Quantity
Minimum distance between peaks. An integer value is interpreted as pixels. Default is 1.
- image
- Returns:
- output
Table
Table with parameters of detected peaks.
- output
Examples
>>> import astropy.units as u >>> from gammapy.datasets import MapDataset >>> from gammapy.estimators import ExcessMapEstimator >>> from gammapy.estimators.utils import find_peaks >>> >>> dataset = MapDataset.read("$GAMMAPY_DATA/cta-1dc-gc/cta-1dc-gc.fits.gz") >>> estimator = ExcessMapEstimator( ... correlation_radius="0.1 deg", energy_edges=[0.1, 10] * u.TeV ... ) >>> maps = estimator.run(dataset) >>> # Find the peaks which are above 5 sigma >>> sources = find_peaks(maps["sqrt_ts"], threshold=5, min_distance="0.25 deg") >>> print(sources) value x y ra dec deg deg ------ --- --- --------- --------- 32.191 161 118 266.41924 -28.98772 18.7 125 124 266.80571 -28.14079 9.4498 257 122 264.86178 -30.97529 9.3784 204 103 266.14201 -30.10041 5.3493 282 150 263.78083 -31.12704