NDDataStats

class astroimtools.stats.NDDataStats(nddata, sigma_clip=None, lower_bound=None, upper_bound=None, mask_value=None, mask_invalid=True)[source]

Bases: object

Class to calculate (sigma-clipped) image statistics on NDData objects.

Set the sigma_clip keyword to perform sigma clipping.

Parameters:
nddataNDData

NDData object containing the data array (and an optional mask) on which to calculate statistics. Masked pixels are excluded when computing the image statistics.

sigma_clipastropy.stats.SigmaClip instance, optional

A SigmaClip object that defines the sigma clipping parameters. If None then no sigma clipping will be performed (default).

lower_boundfloat, optional

The minimum data value to include in the statistics. All pixel values less than lower_bound will be ignored. None means that no lower bound is applied (default).

upper_boundfloat, optional

The maximum data value to include in the statistics. All pixel values greater than upper_bound will be ignored. None means that no upper bound is applied (default).

mask_valuefloat, optional

A data value (e.g., 0.0) to be masked. mask_value will be masked in addition to any input mask.

mask_invalidbool, optional

If True (the default), then any unmasked invalid values (e.g. NaN, inf) will be masked.

Examples

>>> import numpy as np
>>> from astropy.nddata import NDData
>>> from astroimtools import NDDataStats
>>> data = np.arange(10)
>>> data[0] = 100.
>>> nddata = NDData(data)
>>> stats = NDDataStats(nddata)
>>> stats.mean
14.5
>>> stats.std  
28.605069480775605
>>> stats.mad_std  
3.706505546264005
>>> from astropy.stats import SigmaClip
>>> sigclip = SigmaClip(sigma=2.5)
>>> stats = NDDataStats(nddata, sigma_clip=sigclip)
>>> stats.mean
5.0
>>> stats.std  
2.581988897471611
>>> stats.mad_std  
2.965204437011204

Attributes Summary

biweight_location

The biweight location of the pixel values.

biweight_midvariance

The biweight midvariance of the pixel values.

kurtosis

The kurtosis of the pixel values.

mad_std

A robust standard deviation using the median absolute deviation (MAD).

max

The maximum pixel value.

mean

The mean of pixel values.

median

The median of the pixel values.

min

The minimum pixel value.

mode

The mode of the pixel values.

npixels

The number of good (unmasked/unclipped) pixels.

nrejected

The number of rejected (masked/clipped) pixels.

skew

The skew of the pixel values.

std

The standard deviation of the pixel values.

Attributes Documentation

biweight_location

The biweight location of the pixel values.

biweight_midvariance

The biweight midvariance of the pixel values.

kurtosis

The kurtosis of the pixel values.

mad_std

A robust standard deviation using the median absolute deviation (MAD). The MAD is defined as median(abs(a - median(a))).

The standard deviation estimator is given by:

\[\sigma \approx \frac{\textrm{MAD}}{\Phi^{-1}(3/4)} \approx 1.4826 \ \textrm{MAD}\]

where \(\Phi^{-1}(P)\) is the normal inverse cumulative distribution function evaluated at probability \(P = 3/4\).

max

The maximum pixel value.

mean

The mean of pixel values.

median

The median of the pixel values.

min

The minimum pixel value.

mode

The mode of the pixel values.

The mode is estimated simply as (3 * median) - (2 * mean).

npixels

The number of good (unmasked/unclipped) pixels.

nrejected

The number of rejected (masked/clipped) pixels.

skew

The skew of the pixel values.

std

The standard deviation of the pixel values.