nddata_stats¶
- astroimtools.stats.nddata_stats(nddata, sigma_clip=None, columns=None, lower_bound=None, upper_bound=None, mask_value=None, mask_invalid=True)[source]¶
Calculate various statistics on the input data.
Set the
sigma_clip
keyword to perform sigma clipping.- Parameters:
- nddata
NDData
or list ofNDData
NDData
object containing the data array and optional mask on which to calculate statistics. Masked pixels are excluded when computing the image statistics.- sigma_clip
astropy.stats.SigmaClip
instance, optional A
SigmaClip
object that defines the sigma clipping parameters. IfNone
then no sigma clipping will be performed (default).- columnsstr or list of str, optional
The names of columns, in order, to include in the output
Table
. The column names can include any of the following statistic names: ‘biweight_location’, ‘biweight_midvariance’, ‘kurtosis’, ‘mad_std’, ‘max’, ‘mean’, ‘median’, ‘min’, ‘mode’, ‘npixels’, ‘nrejected’, ‘skew’, or ‘std’. The column names can also include a name of a key in theastropy.nddata.NDData.meta
dictionary. The default is['npixels', 'mean', 'std', 'min', 'max']
.- 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 inputmask
.- mask_invalidbool, optional
If
True
(the default), then any unmasked invalid values (e.g. NaN, inf) will be masked.
- nddata
- Returns:
Examples
>>> import numpy as np >>> from astropy.nddata import NDData >>> from astroimtools import nddata_stats >>> data = np.arange(10) >>> data[0] = 100. >>> nddata = NDData(data) >>> columns = ['mean', 'median', 'mode', 'std', 'mad_std', 'min', 'max'] >>> tbl = nddata_stats(nddata, columns=columns) >>> for col in tbl.colnames: ... tbl[col].info.format = '%.8g' # for consistent table output >>> print(tbl) mean median mode std mad_std min max ---- ------ ----- --------- --------- --- --- 14.5 5.5 -12.5 28.605069 3.7065055 1 100 >>> from astropy.stats import SigmaClip >>> sigclip = SigmaClip(sigma=2.5) >>> tbl = nddata_stats(nddata, sigma_clip=sigclip, columns=columns) >>> for col in tbl.colnames: ... tbl[col].info.format = '%.8g' # for consistent table output >>> print(tbl) mean median mode std mad_std min max ---- ------ ---- --------- --------- --- --- 5 5 5 2.5819889 2.9652044 1 9