detect_threshold#

photutils.segmentation.detect_threshold(data, n_sigma, *, background=None, error=None, mask=None, sigma_clip=<default: SigmaClip(sigma=3.0, maxiters=10)>)[source]#

Calculate a pixel-wise threshold image that can be used to detect sources.

This is a simple convenience function that uses sigma-clipped statistics to compute a scalar background and noise estimate. In general, one should perform more sophisticated estimates, e.g., using Background2D.

Parameters:
data2D ndarray

The 2D array of the image.

n_sigmafloat

The number of standard deviations per pixel above the background for which to consider a pixel as possibly being part of a source.

backgroundfloat or 2D ndarray, optional

The background value(s) of the input data. background may either be a scalar value or a 2D array with the same shape as the input data. If the input data has been background-subtracted, then set background to 0.0 (this should be typical). If None, then a scalar background value will be estimated as the sigma-clipped image mean. If data is a Quantity array, then background must have the same units as data.

errorfloat or 2D ndarray, optional

The Gaussian 1-sigma standard deviation of the background noise in data. error should include all sources of “background” error, but exclude the Poisson error of the sources. If error is a 2D image, then it should represent the 1-sigma background error in each pixel of data. If None, then a scalar background rms value will be estimated as the sigma-clipped image standard deviation. If data is a Quantity array, then error must have the same units as data.

mask2D bool ndarray, optional

A boolean mask with the same shape as data, where a True value indicates the corresponding element of data is masked. Masked pixels are ignored when computing the image background statistics.

sigma_clipastropy.stats.SigmaClip or None, optional

A SigmaClip object that defines the sigma clipping parameters. The default is a SigmaClip with sigma=3.0 and maxiters=10. If None then no sigma clipping will be performed.

Returns:
threshold2D ndarray

A 2D image with the same shape (and units) as data containing the pixel-wise threshold values.

Notes

The mask and sigma_clip inputs are used only if it is necessary to estimate background or error using sigma-clipped background statistics. If background and error are both input, then mask and sigma_clip are ignored.

If background or error is estimated and the unmasked data contain nonfinite values (NaN or inf), then an AstropyUserWarning is emitted and the nonfinite values are excluded from the statistics, with or without sigma clipping.