Skip to the navigation links
Last modified: June 2010

URL: http://cxc-newtest.cfa.harvard.edu/ciao4.2/simple_stats.py.html
AHELP for CIAO 4.2

simple_stats

Context: py.ciao_contrib

Synopsis

Calculate several basic statistic values for a data array

Syntax

simple_stats(array)

Description

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 Sherpa by saying:

from ciao_contrib.utils import *

Arguments

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

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

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

chips> print s
npts   = 10
min    = 0
max    = 5
total  = 23
mean   = 2.3
median = 2.0
stddev = 1.41774468788
chips> print "The mean is %g +- %g" % (s.mean, s.stddev)
The mean is 2.3 +- 1.41774

Example 2

chips> img = read_image("emap.fits")
chips> ivals = get_imagevals(img)
chips> ix = numpy.isfinite(ivals)
chips> 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).

CHANGES IN THE JUNE 2010 RELEASE

The version scheme has changed to a date-based system. There should be no changes to the behavior of this routine.

See Also

py.ciao_contrib
simple_hist

Last modified: June 2010