Last modified: June 2010

Jump to: Description · Examples · See Also

AHELP for CIAO 4.15


Context: contrib


Calculate several basic statistic values for a data array




The simple_stats() routine calculates several simple statistics for the input data (the array argument), such as the mean, median, and standard deviation. For more control over the calculation use the routines in the numpy module.

Loading the routine

The routine can be loaded into a Python session by saying:

from ciao_contrib.utils import *


Name Description
array The array of data used to calculate the statistic values.

The return value

The return value is an object with the following fields:

Field Value
npts The number of elements in the array.
min The minimum value in the array.
max The maximum value in the array.
total The sum of all the array elements.
mean The mean value of the array.
median The median value of the array.
stddev The standard deviation of the array, calculated using the biased estimator (so the mean level is calculated using the number of elements and not "number of elements - 1").


Example 1

>>> x = [0, 1, 2, 3, 2, 3, 4, 2, 1, 5]
>>> s = simple_stats(x)

The return value of s is an object which contains the calculated statistics of the array:

>>> print(s)
npts   = 10
min    = 0
max    = 5
total  = 23
mean   = 2.3
median = 2.0
stddev = 1.41774468788
>>> print("The mean is {0} +- {1}".format(s.mean, s.stddev))
The mean is 2.3 +- 1.4177446878757827

Example 2

>>> img = read_image("emap.fits")
>>> ivals = get_imagevals(img)
>>> ix = numpy.isfinite(ivals)
>>> simg = simple_stats(ivals[ix])

Here we use the Crates read_image() and get_imagevals() to read in the contents of the image "emap.fits". Since it may contain "invalid" numbers, such as NaN and Infinity, we filter out these values before calculating the statistics (simg).

See Also

detilt, dewiggle, symmetrize