SciPy

scipy.stats.sigmaclip

scipy.stats.sigmaclip(a, low=4.0, high=4.0)[source]

Iterative sigma-clipping of array elements.

The output array contains only those elements of the input array c that satisfy the conditions

mean(c) - std(c)*low < c < mean(c) + std(c)*high

Starting from the full sample, all elements outside the critical range are removed. The iteration continues with a new critical range until no elements are outside the range.

Parameters :

a : array_like

Data array, will be raveled if not 1-D.

low : float, optional

Lower bound factor of sigma clipping. Default is 4.

high : float, optional

Upper bound factor of sigma clipping. Default is 4.

Returns :

c : ndarray

Input array with clipped elements removed.

critlower : float

Lower threshold value use for clipping.

critlupper : float

Upper threshold value use for clipping.

Examples

>>> a = np.concatenate((np.linspace(9.5,10.5,31), np.linspace(0,20,5)))
>>> fact = 1.5
>>> c, low, upp = sigmaclip(a, fact, fact)
>>> c
array([  9.96666667,  10.        ,  10.03333333,  10.        ])
>>> c.var(), c.std()
(0.00055555555555555165, 0.023570226039551501)
>>> low, c.mean() - fact*c.std(), c.min()
(9.9646446609406727, 9.9646446609406727, 9.9666666666666668)
>>> upp, c.mean() + fact*c.std(), c.max()
(10.035355339059327, 10.035355339059327, 10.033333333333333)
>>> a = np.concatenate((np.linspace(9.5,10.5,11),
    np.linspace(-100,-50,3)))
>>> c, low, upp = sigmaclip(a, 1.8, 1.8)
>>> (c == np.linspace(9.5,10.5,11)).all()
True

Previous topic

scipy.stats.zscore

Next topic

scipy.stats.threshold