clip_to_background

jwst.clean_flicker_noise.clean_flicker_noise.clip_to_background(image, mask, sigma_lower=3.0, sigma_upper=2.0, fit_histogram=False, lower_half_only=False, verbose=False)[source]

Flag signal and bad pixels in the image mask.

Given an image, estimate the background level and a sigma value for the mean background.

The center and sigma may be calculated from a simple sigma-clipped median and standard deviation, or may be refined by fitting a Gaussian to a histogram of the values. In that case, the center is the Gaussian mean and the sigma is the Gaussian width.

Pixels above the center + sigma_upper * sigma are assumed to have signal; those below this level are assumed to be background pixels.

Pixels less than center - sigma_lower * sigma are also excluded as bad values.

The input mask is updated in place.

Parameters:
imagendarray of float

2D image containing signal and background values.

maskndarray of bool

2D input mask to be updated. True indicates background pixels to be used. Regions containing signal or outliers will be set to False.

sigma_lowerfloat, optional

The number of standard deviations to use as the lower bound for the clipping limit. Values below this limit are marked False in the mask.

sigma_upperfloat, optional

The number of standard deviations to use as the upper bound for the clipping limit. Values above this limit are marked False in the mask.

fit_histogrambool, optional

If set, the center value and standard deviation used with sigma_lower and sigma_upper for clipping outliers is derived from a Gaussian fit to a histogram of values. Otherwise, the center and standard deviation are derived from a simple iterative sigma clipping.

lower_half_onlybool, optional

If set, the data used to compute the center and standard deviation for clipping is the lower half of the distribution only. Values below the median are mirrored around the median value to simulate a symmetric distribution. This is intended to account for asymmetrical value distributions, with long tails in the upper half of the distribution, due to diffuse emission, for example.

verbosebool, optional

If set, DEBUG level messages are issued with details on the computed statistics.