Primary User Interface: ImageStats

Compute desired statistics values for input array objects.

class stsci.imagestats.ImageStats(image, fields='npix,min,max,mean,stddev', lower=None, upper=None, nclip=0, lsig=3.0, usig=3.0, binwidth=0.1)[source]

Class to compute desired statistics from array objects.

Parameters:
imagestr

input image data array.

fieldsstr

comma-separated list of values to be computed. The following are the available fields:

image

image data array

npix

the number of pixels used to do the statistics

mean

the mean of the pixel distribution

midpt

estimate of the median of the pixel distribution

mode

the mode of the pixel distribution

stddev

the standard deviation of the pixel distribution

min

the minimum pixel value

max

the maximum pixel value

WARNING

Only those fields specified upon instantiation will be computed and available as an output value.

lowerfloat

Lowest valid value in the input array to be used for computing the statistical values

upperfloat

Largest valid value in the input array to be used in computing the statistical values

nclipint

Number of clipping iterations to apply in computing the results

lsigfloat

Lower sigma clipping limit (in sigma)

usigfloat

Upper sigma clipping limit (in sigma)

binwidthfloat

Width of bins (in sigma) to use in generating histograms for computing median-related values

Notes

The mean, standard deviation, min and max are computed in a single pass through the image using the expressions listed below. Only the quantities selected by the fields parameter are actually computed.

    mean = sum (x1,...,xN) / N
       y = x - mean
variance = sum (y1 ** 2,...,yN ** 2) / (N-1)
  stddev = sqrt (variance)

The midpoint and mode are computed in two passes through the image. In the first pass the standard deviation of the pixels is calculated and used with the binwidth parameter to compute the resolution of the data histogram. The midpoint is estimated by integrating the histogram and computing by interpolation the data value at which exactly half the pixels are below that data value and half are above it. The mode is computed by locating the maximum of the data histogram and fitting the peak by parabolic interpolation.

Warning

This data will be promoted down to float32 if provided as 64-bit datatype.

Examples

This class can can be instantiated using the following syntax:

>>> import stsci.imagestats as imagestats
>>> i = imagestats.ImageStats(image,
            fields="npix,min,max,mean,stddev",
            nclip=3,
            lsig=3.0,
            usig=3.0,
            binwidth=0.1
            )
>>> i.printStats()
>>> i.mean

The statistical quantities specified by the parameter fields are computed and printed for the input image array. The results are available as attributes of the class object as well.

getCenters()[source]

Compute the array of bin center positions.

printStats()[source]

Print the requested statistics values for those fields specified on input.

stsci.imagestats.computeMean(image, clipmin, clipmax, numGoodPixels, mean, stddev, minValue, maxValue)
class stsci.imagestats.histogram1d(arrayInput, nbins, binWidth, zeroValue)[source]

Populate a 1-dimensional histogram from 1D numpy.nddata array.

Parameters:
arrayInputnumpy.nddata

2D array object

nbinsint

Number of bins in the histogram.

binWidthfloat

Width of 1 bin in desired units

zeroValuefloat

Zero value for the histogram range

property centers

Compute the array of bin center values

property edges

Compute the array of bin center values

getCenters()[source]

Returns histogram’s centers.

get_edges()[source]

Returns histogram’s bin edges (including left edge of the first bin and right edge of the last bin).