SigmaClippedStats#
- class astropy.stats.sigma_clipping.SigmaClippedStats(data: ArrayLike, *, mask: NDArray | None = None, mask_value: float | None = None, sigma: float = 3.0, sigma_lower: float | None = None, sigma_upper: float | None = None, maxiters: int = 5, cenfunc: Literal['median', 'mean'] | Callable = 'median', stdfunc: Literal['std', 'mad_std'] | Callable = 'std', axis: int | tuple[int, ...] | None = None, grow: float | Literal[False] | None = False)[source]#
Bases:
object
Class to calculate sigma-clipped statistics on the provided data.
- Parameters:
- datanumpy:array_like or
MaskedArray
Data array or object that can be converted to an array.
- mask
numpy.ndarray
(bool), optional A boolean mask with the same shape as
data
, where aTrue
value indicates the corresponding element ofdata
is masked. Masked pixels are excluded when computing the statistics.- mask_value
python:float
, optional A data value (e.g.,
0.0
) that is ignored when computing the statistics.mask_value
will be masked in addition to any inputmask
.- sigma
python:float
, optional The number of standard deviations to use for both the lower and upper clipping limit. These limits are overridden by
sigma_lower
andsigma_upper
, if input. The default is 3.- sigma_lower
python:float
orpython:None
, optional The number of standard deviations to use as the lower bound for the clipping limit. If
None
then the value ofsigma
is used. The default isNone
.- sigma_upper
python:float
orpython:None
, optional The number of standard deviations to use as the upper bound for the clipping limit. If
None
then the value ofsigma
is used. The default isNone
.- maxiters
python:int
orpython:None
, optional The maximum number of sigma-clipping iterations to perform or
None
to clip until convergence is achieved (i.e., iterate until the last iteration clips nothing). If convergence is achieved prior tomaxiters
iterations, the clipping iterations will stop. The default is 5.- cenfunc{‘median’, ‘mean’} or
python:callable()
, optional The statistic or callable function/object used to compute the center value for the clipping. If using a callable function/object and the
axis
keyword is used, then it must be able to ignore NaNs (e.g.,numpy.nanmean
) and it must have anaxis
keyword to return an array with axis dimension(s) removed. The default is'median'
.- stdfunc{‘std’, ‘mad_std’} or
python:callable()
, optional The statistic or callable function/object used to compute the standard deviation about the center value. If using a callable function/object and the
axis
keyword is used, then it must be able to ignore NaNs (e.g.,numpy.nanstd
) and it must have anaxis
keyword to return an array with axis dimension(s) removed. The default is'std'
.- axis
python:None
orpython:int
orpython:tuple
ofpython:int
, optional The axis or axes along which to sigma clip the data. If
None
, then the flattened data will be used.axis
is passed to thecenfunc
andstdfunc
. The default isNone
.- grow
python:float
orFalse
, optional Radius within which to mask the neighbouring pixels of those that fall outwith the clipping limits (only applied along
axis
, if specified). As an example, for a 2D image a value of 1 will mask the nearest pixels in a cross pattern around each deviant pixel, while 1.5 will also reject the nearest diagonal neighbours and so on.
- datanumpy:array_like or
See also
Notes
The best performance will typically be obtained by setting
cenfunc
andstdfunc
to one of the built-in functions specified as a string. If one of the options is set to a string while the other has a custom callable, you may in some cases see better performance if you have the bottleneck package installed. To preserve accuracy, bottleneck is only used for float64 computations.Methods Summary
biweight_location
([c, M])Calculate the biweight location of the data.
biweight_scale
([c, M])Calculate the biweight scale of the data.
mad_std
()Calculate the median absolute deviation (MAD) based standard deviation of the data.
max
()Calculate the maximum of the data.
mean
()Calculate the mean of the data.
median
()Calculate the median of the data.
min
()Calculate the minimum of the data.
mode
([median_factor, mean_factor])Calculate the mode of the data using a estimator of the form
(median_factor * median) - (mean_factor * mean)
.std
([ddof])Calculate the standard deviation of the data.
sum
()Calculate the sum of the data.
var
([ddof])Calculate the variance of the data.
Methods Documentation
- biweight_location(c: float = 6.0, M: float | None = None) float | NDArray [source]#
Calculate the biweight location of the data.
NaN values are ignored.
- Parameters:
- c
python:float
, optional Tuning constant for the biweight estimator. Default value is 6.0.
- M
python:float
orpython:None
, optional Initial guess for the biweight location. Default value is
None
.
- c
- Returns:
- biweight_location
python:float
orndarray
The biweight location of the data.
- biweight_location
- biweight_scale(c: float = 6.0, M: float | None = None) float | NDArray [source]#
Calculate the biweight scale of the data.
NaN values are ignored.
- Parameters:
- c
python:float
, optional Tuning constant for the biweight estimator. Default value is 6.0.
- M
python:float
orpython:None
, optional Initial guess for the biweight location. Default value is
None
.
- c
- Returns:
- biweight_scale
python:float
orndarray
The biweight scale of the data.
- biweight_scale
- mad_std() float | NDArray [source]#
Calculate the median absolute deviation (MAD) based standard deviation of the data.
NaN values are ignored.
- Returns:
- mad_std
python:float
orndarray
The MAD-based standard deviation of the data.
- mad_std
- max() float | NDArray [source]#
Calculate the maximum of the data.
NaN values are ignored.
- Returns:
- max
python:float
orndarray
The maximum of the data.
- max
- mean() float | NDArray [source]#
Calculate the mean of the data.
NaN values are ignored.
- Returns:
- mean
python:float
orndarray
The mean of the data.
- mean
- median() float | NDArray [source]#
Calculate the median of the data.
NaN values are ignored.
- Returns:
- median
python:float
orndarray
The median of the data.
- median
- min() float | NDArray [source]#
Calculate the minimum of the data.
NaN values are ignored.
- Returns:
- min
python:float
orndarray
The minimum of the data.
- min
- mode(median_factor: float = 3.0, mean_factor: float = 2.0) float | NDArray [source]#
Calculate the mode of the data using a estimator of the form
(median_factor * median) - (mean_factor * mean)
.NaN values are ignored.
- Parameters:
- median_factor
python:float
, optional The multiplicative factor for the data median. Defaults to 3.
- mean_factor
python:float
, optional The multiplicative factor for the data mean. Defaults to 2.
- median_factor
- Returns:
- mode
python:float
orndarray
The estimated mode of the data.
- mode
- std(ddof: int = 0) float | NDArray [source]#
Calculate the standard deviation of the data.
NaN values are ignored.
- Parameters:
- ddof
python:int
, optional The delta degrees of freedom for the standard deviation calculation. The divisor used in the calculation is
N - ddof
, whereN
represents the number of elements. For a population standard deviation where you have data for the entire population, useddof=0
. For a sample standard deviation where you have a sample of the population, useddof=1
. The default is 0.
- ddof
- Returns:
- std
python:float
orndarray
The standard deviation of the data.
- std
- sum() float | NDArray [source]#
Calculate the sum of the data.
NaN values are ignored.
- Returns:
- sum
python:float
orndarray
The sum of the data.
- sum
- var(ddof: int = 0) float | NDArray [source]#
Calculate the variance of the data.
NaN values are ignored.
- Parameters:
- ddof
python:int
, optional The delta degrees of freedom. The divisor used in the calculation is
N - ddof
, whereN
represents the number of elements. For a population variance where you have data for the entire population, useddof=0
. For a sample variance where you have a sample of the population, useddof=1
. The default is 0.
- ddof
- Returns:
- var
python:float
orndarray
The variance of the data.
- var