About Chandra Archive Proposer Instruments & Calibration Newsletters Data Analysis HelpDesk Calibration Database NASA Archives & Centers Chandra Science Links

Skip the navigation links
Last modified: August 2009

URL: http://cxc.harvard.edu/ciao4.1/simple_stats.py.html
AHELP for CIAO 4.1

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).

See Also

py.ciao_contrib
simple_hist
Last modified: August 2009



The Chandra X-Ray Center (CXC) is operated for NASA by the Smithsonian Astrophysical Observatory.
60 Garden Street, Cambridge, MA 02138 USA.    Email: cxcweb@head.cfa.harvard.edu
Smithsonian Institution, Copyright © 1998-2004. All rights reserved.